File: class.dc.utils.php

package info (click to toggle)
dotclear 2.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 8,420 kB
  • sloc: php: 54,270; sql: 1,290; sh: 213; xml: 173; makefile: 158
file content (99 lines) | stat: -rw-r--r-- 2,543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_RC_PATH')) { return; }

/**
@ingroup DC_CORE
@brief Dotclear helper methods

Provides some Dotclear helpers
*/
class dcUtils
{
	/**
	Static function that returns user's common name given to his
	<var>user_id</var>, <var>user_name</var>, <var>user_firstname</var> and
	<var>user_displayname</var>.

	@param	user_id			<b>string</b>	User ID
	@param	user_name			<b>string</b>	User's name
	@param	user_firstname		<b>string</b>	User's first name
	@param	user_displayname	<b>string</b>	User's display name
	@return	<b>string</b>
	*/
	public static function getUserCN($user_id, $user_name, $user_firstname, $user_displayname)
	{
		if (!empty($user_displayname)) {
			return $user_displayname;
		}

		if (!empty($user_name)) {
			if (!empty($user_firstname)) {
				return $user_firstname.' '.$user_name;
			} else {
				return $user_name;
			}
		} elseif (!empty($user_firstname)) {
			return $user_firstname;
		}

		return $user_id;
	}

	/**
	Cleanup a list of IDs

	@param	ids			<b>mixed</b>	ID(s)
	@return	<b>array</b>
	*/
	public static function cleanIds($ids)
	{
		$clean_ids = array();

		if (!is_array($ids)) {
			$ids = array($ids);
		}

		foreach($ids as $id)
		{
			$id = abs((integer) $id);

			if (!empty($id)) {
				$clean_ids[] = $id;
			}
		}
		return $clean_ids;
	}

	/**
	 * Compare two versions with option of using only main numbers.
	 *
	 * @param  string	$current_version	Current version
	 * @param  string	$required_version	Required version
	 * @param  string	$operator			Comparison operand
	 * @param  boolean	$strict				Use full version
	 * @return boolean	True if comparison success
	 */
	public static function versionsCompare($current_version, $required_version, $operator='>=', $strict=true)
	{
		if ($strict) {
			$current_version = preg_replace('!-r(\d+)$!', '-p$1', $current_version);
			$required_version = preg_replace('!-r(\d+)$!', '-p$1', $required_version);
		}
		else {
			$current_version = preg_replace('/^([0-9\.]+)(.*?)$/', '$1', $current_version);
			$required_version = preg_replace('/^([0-9\.]+)(.*?)$/', '$1', $required_version);
		}

		return (boolean) version_compare($current_version, $required_version, $operator);
	}
}