Dotclear

source: inc/core/class.dc.utils.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 2.5 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14/**
15@ingroup DC_CORE
16@brief Dotclear helper methods
17
18Provides some Dotclear helpers
19*/
20class dcUtils
21{
22     /**
23     Static function that returns user's common name given to his
24     <var>user_id</var>, <var>user_name</var>, <var>user_firstname</var> and
25     <var>user_displayname</var>.
26
27     @param    user_id             <b>string</b>  User ID
28     @param    user_name           <b>string</b>  User's name
29     @param    user_firstname      <b>string</b>  User's first name
30     @param    user_displayname    <b>string</b>  User's display name
31     @return   <b>string</b>
32     */
33     public static function getUserCN($user_id, $user_name, $user_firstname, $user_displayname)
34     {
35          if (!empty($user_displayname)) {
36               return $user_displayname;
37          }
38
39          if (!empty($user_name)) {
40               if (!empty($user_firstname)) {
41                    return $user_firstname.' '.$user_name;
42               } else {
43                    return $user_name;
44               }
45          } elseif (!empty($user_firstname)) {
46               return $user_firstname;
47          }
48
49          return $user_id;
50     }
51
52     /**
53     Cleanup a list of IDs
54
55     @param    ids            <b>mixed</b>   ID(s)
56     @return   <b>array</b>
57     */
58     public static function cleanIds($ids)
59     {
60          $clean_ids = array();
61
62          if (!is_array($ids)) {
63               $ids = array($ids);
64          }
65
66          foreach($ids as $id)
67          {
68               $id = abs((integer) $id);
69
70               if (!empty($id)) {
71                    $clean_ids[] = $id;
72               }
73          }
74          return $clean_ids;
75     }
76
77     /**
78      * Compare two versions with option of using only main numbers.
79      *
80      * @param  string   $current_version    Current version
81      * @param  string   $required_version   Required version
82      * @param  string   $operator           Comparison operand
83      * @param  boolean  $strict                  Use full version
84      * @return boolean  True if comparison success
85      */
86     public static function versionsCompare($current_version, $required_version, $operator='>=', $strict=true)
87     {
88          if ($strict) {
89               $current_version = preg_replace('!-r(\d+)$!', '-p$1', $current_version);
90               $required_version = preg_replace('!-r(\d+)$!', '-p$1', $required_version);
91          }
92          else {
93               $current_version = preg_replace('/^([0-9\.]+)(.*?)$/', '$1', $current_version);
94               $required_version = preg_replace('/^([0-9\.]+)(.*?)$/', '$1', $required_version);
95          }
96
97          return (boolean) version_compare($current_version, $required_version, $operator);
98     }
99}
Note: See TracBrowser for help on using the repository browser.

Sites map