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_stylesheet_operations.php
100644 217 lines (194 sloc) 5.699 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
<?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 stylesheets.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsStylesheetOperations 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 CmsStylesheetOperations The instance of the singleton object.
   * @author Ted Kulp
   **/
  static public function get_instance()
  {
    if (self::$instance == NULL)
    {
      self::$instance = new CmsStylesheetOperations();
    }
    return self::$instance;
  }
 
  /**
   * Returns all of the stylesheets in the system, ordered by name.
   *
   * @return array All of the stylesheets in the system
   * @author Ted Kulp
   **/
  public static function load_stylesheets()
  {
    return cmsms()->stylesheet->find_all(array('order' => 'name'));
  }
  
  /**
   * @deprecated Deprecated. Use load_stylesheets instead.
   **/
  function LoadStylesheets()
  {
    return CmsStylesheetOperations::load_stylesheets();
  }
 
  /**
   * Assocates a stylesheet to the a template.
   *
   * @param integer The stylesheet to attach
   * @param integer The template to attach it to
   * @return bool Whether or not the attachment was successful
   * @author Ted Kulp
   **/
  function associate_stylesheet_to_template($stylesheet_id, $template_id)
  {
    $db = cms_db();
 
    $time = $db->DBTimeStamp(time());
    $query = 'INSERT INTO '.cms_db_prefix().'css_assoc VALUES (?,?,?,'.$time.','.$time.')';
    $dbresult = $db->Execute( $query, array( $template_id, $stylesheet_id, 'template'));
 
    return ($dbresult != false);
  }
  
  /**
   * @deprecated Deprecated. Use associate_stylesheet_to_template instead.
   **/
  function AssociateStylesheetToTemplate($stylesheetid, $templateid)
  {
    return CmsStylesheetOperations::AssociateStylesheetToTemplate($stylesheetid, $templateid);
  }
 
  function get_stylesheets_associated_to_template($template_id)
  {
    $result = false;
 
    $db = cms_db();
 
    $query = 'SELECT assoc_css_id FROM '.cms_db_prefix().'css_assoc WHERE
     assoc_type = ? AND assoc_to_id = ?';
    $dbresult = $db->Execute($query, array('template', $templateid));
 
    $result = array();
    while ($dbresult && $row = $dbresult->FetchRow())
    {
      $result[] = $row['assoc_css_id'];
    }
 
    return $result;
  }
  
  /**
   * @deprecated Deprecated. Use get_stylesheets_associated_to_template instead.
   **/
  function GetTemplateAssociatedStylesheets($templateid)
  {
    return CmsStylesheetOperations::get_stylesheets_associated_to_template($templateid);
  }
 
  /**
   * Loads a stylesheet by stylesheet id.
   *
   * @param integer The stylesheet id to load
   * @return mixed If successful, the filled Stylesheet object. If it fails, it returns null.
   * @author Ted Kulp
   **/
  function load_stylesheet_by_id($id)
  {
    return cmsms()->stylesheet->find_by_id($id);
  }
  
  /**
   * @deprecated Deprecated. Use load_stylesheet_by_id instead.
   **/
  function LoadStylesheetByID($id)
  {
    return CmsStylesheetOperations::load_stylesheet_by_id($id);
  }
 
  /**
   * Saves a new stylesheet to the database.
   *
   * @deprecated Deprecated. User $stylesheet->save() instead.
   *
   * @param mixed Stylesheet object to save
   *
   * @return mixed The new stylesheet id. If it fails, it returns -1.
   * @since 0.6.1
   */
  function InsertStylesheet($stylesheet)
  {
    return $stylesheet->save();
  }
 
  /**
   * Updates an existing stylesheet in the database.
   *
   * @deprecated Deprecated. User $stylesheet->save() instead.
   *
   * @param mixed Stylesheet object to save
   *
   * @return mixed If successful, true. If it fails, false.
   * @since 0.6.1
   */
  function UpdateStylesheet($stylesheet)
  {
    return $stylesheet->save();
  }
 
  /**
   * Deletes an existing user from the database.
   *
   * @deprecated Deprecated. Use cmsms()->stylesheet->delete($id) instead.
   *
   * @param mixed Id of the stylesheet to delete
   *
   * @return mixed If successful, true. If it fails, false.
   * @since 0.6.1
   */
  function DeleteStylesheetByID($id)
  {
    return cmsms()->stylesheet->delete($id);
  }
 
  /**
   * Checks to see if a stylesheet name is in use already.
   *
   * @param string The name of the stylesheet to look up
   * @return bool Whether or not that name is in use already
   * @author Ted Kulp
   **/
  function check_existing_stylesheet_name($name)
  {
    return cmsms()->stylesheet->find_count_by_name($name) > 0 ? true : false;
  }
  
  /**
   * @deprecated Deprecated. Use check_existing_stylesheet_name instead.
   **/
  function CheckExistingStylesheetName($name)
  {
    return CmsStylesheetOperations::check_existing_stylesheet_name($name);
  }
}
 
# vim:ts=4 sw=4 noet
?>