public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / lib / classes / class.cms_user_tag_operations.php
100644 174 lines (149 sloc) 3.842 kb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (tedkulp@users.sf.net)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#BUT withOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* Static methods for handling user defined tags.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsUserTagOperations extends CmsObject
{
  static private $instance = NULL;
  
  function __construct()
  {
    parent::__construct();
  }
  
  /**
   * Get an instance of this object, though most people should be using
   * the static methods instead. This is more for compatibility than
   * anything else.
   *
   * @return CmsUserTagOperations The instance of the singleton object.
   * @author Ted Kulp
   **/
  static public function get_instance()
  {
    if (self::$instance == NULL)
    {
      self::$instance = new CmsUserTagOperations();
    }
    return self::$instance;
  }
  
  /**
   * Retrieve the body of a user defined tag
   *
   * @params string $name User defined tag name
   *
   * @returns mixed If successfull, the body of the user tag (string). If it fails, false
   */
  function get_user_tag_code($name)
  {
    $user_tag = cms_orm('CmsUserTag')->find_by_name($name);
    if ($user_tag != null)
    {
      return $user_tag->code;
    }
 
    return false;
  }
 
  function GetUserTag( $name )
  {
    return self::get_user_tag_code($name);
  }
 
 
  /**
   * Add or update a named user defined tag into the database
   *
   * @params string $name User defined tag name
   * @params string $text Body of user defined tag
   *
   * @returns mixed If successful, true. If it fails, false.
   */
  function set_user_tag( $name, $text )
  {
    $user_tag = cms_orm('CmsUserTag')->find_by_name($name);
    if ($user_tag == null)
    {
      $user_tag = new CmsUserTag();
      $user_tag->name = $name;
    }
    
    $user_tag->code = $text;
    
    return $user_tag->save();
  }
  
  function SetUserTag( $name, $text )
  {
    return self::set_user_tag($name, $text);
  }
 
 
  /**
   * Remove a named user defined tag from the database
   *
   * @params string $name User defined tag name
   *
   * @returns mixed If successful, true. If it fails, false.
   */
  function remove_user_tag( $name )
  {
    $user_tag = cms_orm('CmsUserTag')->find_by_name($name);
    if ($user_tag != null)
    {
      return $user_tag->delete();
    }
    
    return false;
  }
  
  function RemoveUserTag( $name )
  {
    return self::remove_user_tag($name);
  }
 
 
   /**
   * Return a list (suitable for use in a pulldown) of user tags.
   *
   * @returns mixed If successful, an array. If it fails, false.
   */
  function list_user_tags_for_dropdown()
  {
    cms_orm('CmsUserTag')->find_all(array('order' => 'name asc'));
  }
  
  function ListUserTags()
  {
    return self::list_user_tags_for_dropdown();
  }
  
  function call_user_tag($name, &$params)
  {
    $user_tag = cms_orm('CmsUserTag')->find_by_name($name);
    if ($user_tag != null)
    {
      return $user_tag->call($params);
    }
 
    return null;
  }
  
  function CallUserTag($name, &$params)
  {
    return self::call_user_tag($name, $params);
  }
 
} // class
 
/**
* @deprecated Deprecated. Use CmsUserTagOperations instead.
**/
class UserTags extends CmsUserTagOperations
{}
 
# vim:ts=4 sw=4 noet
?>