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_global_content_operations.php
100644 230 lines (197 sloc) 5.711 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#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 global content blocks.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsGlobalContentOperations 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 CmsGlobalContentOperations The instance of the singleton object.
   * @author Ted Kulp
   **/
  static public function get_instance()
  {
    if (self::$instance == NULL)
    {
      self::$instance = new CmsGlobalContentOperations();
    }
    return self::$instance;
  }
 
  /**
   * Prepares an array with the list of the html blobs $userid is an author of
   *
   * @return array An array in whose elements are the IDs of the blobs
   * @since 0.11
   */
  public static function get_global_content_by_author_id($userid)
  {
    $gCms = cmsms();
    $db = cms_db();
   $variables = &$gCms->variables;
    if (!isset($variables['authorblobs']))
    {
      $variables['authorblobs'] = array();
 
      $query = "SELECT htmlblob_id FROM ".cms_db_prefix()."additional_htmlblob_users WHERE user_id = ?";
      $result = &$db->Execute($query, array($userid));
 
      while ($result && !$result->EOF)
      {
        $variables['authorblobs'][] = $result->fields['htmlblob_id'];
        $result->MoveNext();
      }
    }
 
    return $variables['authorblobs'];
  }
  
  /**
   * @deprecated Deprecated. Use CmsGlobalContentOperations::get_global_content_by_author_id instead.
   **/
  function AuthorBlobs($userid)
  {
    return CmsGlobalContentOperations::get_global_content_by_author_id($userid);
  }
 
  /**
   * @deprecated Deprecated. Use cmsms()->global_content->find_all() instead.
   **/
  function LoadHtmlBlobs()
  {
    return cmsms()->global_content->find_all(array('order' => 'htmlblob_name ASC'));
  }
 
  /**
   * @deprecated Deprecated. Use cmsms()->global_content->find_by_id($id) instead.
   **/
  function LoadHtmlBlobByID($id)
  {
    return cmsms()->global_content->find_by_id($id);
  }
 
  /**
   * @deprecated Deprecated. Use cmsms()->global_content->find_by_name($name) instead.
   **/
  function &LoadHtmlBlobByName($name)
  {
    return cmsms()->global_content->find_by_name($name);
  }
 
  /**
   * @deprecated Deprecated. Use $obj->save() instead.
   **/
  function InsertHtmlBlob($htmlblob)
  {
    return $htmlblob->save();
  }
 
  /**
   * @deprecated Deprecated. Use $obj->save() instead.
   **/
  function UpdateHtmlBlob($htmlblob)
  {
    return $htmlblob->save();
  }
 
  /**
   * @deprecated Deprecated. Use cmsms->global_content->delete($id) instead.
   **/
  function DeleteHtmlBlobByID($id)
  {
    return cmsms()->global_content->delete($id);
  }
 
  /**
   * Checks to see if an global content block already has the given name.
   *
   * @param string Name of the block to look for
   * @return bool Whether or not the block name exists
   * @author Ted Kulp
   **/
  public static function check_existing_name($name)
  {
    return cmsms()->global_content->find_count_by_name($name) > 0;
  }
  
  /**
   * @deprecated Deprecated. Use CmsGlobalContentOperations::check_existing_name($name) instead.
   **/
  function CheckExistingHtmlBlobName($name)
  {
    return CmsGlobalContentOperations::check_existing_name($name);
  }
 
  function CheckOwnership($id, $user_id)
  {
    $result = false;
 
    global $gCms;
    $db = &$gCms->GetDb();
 
    $query = "SELECT htmlblob_id FROM ".cms_db_prefix()."htmlblobs WHERE htmlblob_id = ? AND owner = ?";
    $row = &$db->GetRow($query, array($id, $user_id));
 
    if ($row)
    {
      $result = true;
    }
 
    return $result;
  }
 
  function CheckAuthorship($id, $user_id)
  {    
    global $gCms;
    $db = &$gCms->GetDb();
    $result = false;
 
    $query = "SELECT id FROM ".cms_db_prefix()."additional_htmlblob_users WHERE htmlblob_id = ? AND user_id = ?";
    $row = &$db->GetRow($query, array($id, $user_id));
 
    if ($row)
    {
      $result = true;
    }
 
    return $result;
  }
 
  function ClearAdditionalEditors($id)
  {
    global $gCms;
    $db = &$gCms->GetDb();
 
    $query = "DELETE FROM ".cms_db_prefix()."additional_htmlblob_users WHERE htmlblob_id = ?";
 
    $dbresult = $db->Execute($query, array($id));
  }
 
  function InsertAdditionalEditors($id, $user_id)
  {
    global $gCms;
    $db = &$gCms->GetDb();
 
    $query = "INSERT INTO ".cms_db_prefix()."additional_htmlblob_users (id, htmlblob_id, user_id) VALUES (?,?,?)";
    $dbresult = $db->Execute($query, array($new_id, $id, $user_id));
  }
}
 
/**
* @deprecated Deprecated. Use CmsGlobalContentOperations instead.
**/
class GlobalContentOperations extends CmsGlobalContentOperations
{
}
 
/**
* @deprecated Deprecated. Use CmsGlobalContentOperations instead.
**/
class HtmlBlobOperations extends CmsGlobalContentOperations
{
}
 
?>