We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: I'll be modifying the CMS Made Simple Comments module for a community review website. I'll plan on pushing my changes here.
Clone URL: git://github.com/elijahlofgren/cmsms-comments-elijahlofgren.git
cmsms-comments-elijahlofgren / Comments.module.php
100755 271 lines (231 sloc) 7.752 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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: Comments.module.php 2114 2005-11-04 21:51:13Z wishy $
 
class Comments extends CMSModule
{
  function GetName()
  {
    return 'Comments';
  }
 
  function GetVersion()
  {
    return '1.8.3';
  }
 
  function GetHelp($lang = 'en_US')
  {
    return $this->Lang('help');
  }
 
  function GetAuthor()
  {
    return 'Ted Kulp';
  }
 
  function GetAuthorEmail()
  {
    return 'ted@cmsmadesimple.org';
  }
 
  function Install()
  {
    $db = $this->cms->db;
    $dict = NewDataDictionary($db);
    $flds = "
      comment_id I KEY,
      comment_data X,
      comment_date ".CMS_ADODB_DT.",
      comment_author C(255),
      author_email C(255),
      author_website C(255),
      page_id C(255),
      module_name C(50),
      active I1,
      create_date DT,
      modified_date DT,
      comment_title C(255)
    ";
    $taboptarray = array('mysql' => 'TYPE=MyISAM');
    $sqlarray = $dict->CreateTableSQL(cms_db_prefix()."module_comments", $flds, $taboptarray);
    $dict->ExecuteSQLArray($sqlarray);
 
    $db->CreateSequence(cms_db_prefix()."module_comments_seq");
    
    $this->CreatePermission('Manage Comments', 'Manage Comments');
 
    # Install template
    $this->SetTemplate('default_display', $this->GetTemplateFromFile('default_display'));
    
    $this->SetPreference('moderate', ''); // Spam protect off by default
    $this->SetPreference('spamprotect', '');
    $this->SetPreference('disable_html', 1); // Disable HTML for everyone by default
    $this->SetPreference('akismet_check',0);//Disable spam checking
 
  }
 
  function InstallPostMessage()
  {
    return $this->Lang('postinstall');
  }
 
  function Upgrade($oldversion, $newversion)
  {
    $current_version = $oldversion;
    switch($current_version)
    {
      case "1.0":
      case "1.1":
      case "1.2":
      case "1.3":
        $this->CreatePermission('Manage Comments', 'Manage Comments');
        $current_version = '1.4';
      case "1.4":
        $db =& $this->GetDb();
        $dict = NewDataDictionary($db);
        $flds = "
          author_email C(255),
          author_website C(255)
        ";
                $sqlarray = $dict->AddcolumnSQL(cms_db_prefix()."module_comments", $flds);
        $dict->ExecuteSQLArray( $sqlarray );
 
        $current_version = '1.5';
      case "1.5":
        $db =& $this->GetDb();
 
        $dict = NewDataDictionary($db);
        $flds = "
          module_name C(50),
          active I1
        ";
                $sqlarray = $dict->AddcolumnSQL(cms_db_prefix()."module_comments", $flds);
        $dict->ExecuteSQLArray( $sqlarray );
 
        $db->Execute("UPDATE ".cms_db_prefix()."module_comments SET module_name = ''");
        $db->Execute("UPDATE ".cms_db_prefix()."module_comments SET active = 1");
        $current_version = '1.6';  
                 case "1.6":
                                # Install template
                    $this->SetTemplate('default_display', $this->GetTemplateFromFile('default_display'));
                 case "1.8.2":
        # Add title field
        $db =& $this->GetDb();
        $dict = NewDataDictionary($db);
        $flds = "
          comment_title C(255)
        ";
    }
    // Disable HTML for upgrades from all version previous to 1.8.0
    if ($current_version < '1.8.0')
    {
      $this->SetPreference('disable_html', 1); // Disable HTML for everyone by default  
      $this->SetPreference('akismet_check',0);//Disable spam checking
    }
  }
  
  function Uninstall()
  {
    $db = $this->cms->db;
    $dict = NewDataDictionary($db);
    $sqlarray = $dict->DropTableSQL(cms_db_prefix()."module_comments");
    $dict->ExecuteSQLArray($sqlarray);
 
    $db->DropSequence(cms_db_prefix()."module_comments_seq");
 
    $this->RemovePermission('Manage Comments');
  }
 
  function GetChangeLog()
  {
    return "1.8.3 March 2008 (updates by Elijah Lofgren<br />
      Added title field.
      1.8.1 August 2007 (updates by Elijah Lofgren<br />
      CMSMS 1.1 compatibility and various little fixes.
      1.8: December 2006 (updates by Elijah Lofgren)<br />
      Various little fixes.
      Offload Capcha capability to the Captcha module. Disable Captcha by default since it requires a another module.
      Add ability to disable HTML in comments and turn it on by default and for upgrades to prevent XSS vulnerabilities.
      1.7: June 2006 (updates by Elijah Lofgren)<br />
      Made comment form be shown on the same page as the comments and shown/hidden with the startExpandCollapse tag.
      Combined templates into 1 template and made it be stored in a separate file.
      1.6: May 2006 (updates by Ted/wishy)<br />
      Added moderate functionaltiy/active flags
      Added ability to work from modules, though it's not automated
      1.5: April 2006 (updates by Katon)<br />
      Added mass delete functionality<br />
      Added author email and author website fields<br />
      1.4: April 2006 (updates by Katon)<br />
      Actions moved in separate files<br />
      Added admin management panel<br />
      Added mailing functionality<br />
      Added spamprotect functionality<br />
      1.3: Module API changes<br />
      1.2: Oct 13, 2004<br />
      Added newline parsing (kickthedonkey)<br />
      Removed a rogue div (kickthedonkey)<br />
      1.1: Sep 28, 2004<br />
      Added <em>number</em> and <em>dateformat</em> options, plus little cosmetic changes.<br />
      1.0: Initial Release
    ";
  }
 
  function SetParameters()
  {
   // Make it possible to include HTML in comments by disabling HTML cleaning.    
   // The "Disable HTML" option can still be used to disable HTML and prevent issue with that..
   $this->SetParameterType('content', CLEAN_NONE);
   $this->SetParameterType('redirecturl',CLEAN_NONE);
 
    $this->CreateParameter('dateformat', '', $this->lang('helpdateformat'));
    $this->CreateParameter('localedateformat', '', $this->lang('helplocaledateformat'));
    
    $this->CreateParameter('number', '5', $this->lang('helpnumber'));
  }
 
    function isValidURL($url)
    {
        return preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
    }
  
    function isValidEmail($email)
    {
        return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $email);
    }
 
  /**
   * Should always get this page url even when using internal pretty urls
   */
  function selfURL()
  {
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
    $protocol = $this->strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
     $s = $protocol."://".$_SERVER['SERVER_NAME'].$port;
 
    global $gCms;
    $config =& $gCms->GetConfig();
    return $s.$_SERVER['REQUEST_URI'];
     //return $config['root_url'].$_SERVER['REQUEST_URI'];
  }
 
  function strleft($s1, $s2)
  {
    return substr($s1, 0, strpos($s1, $s2));
  }
  
 
  
 
    function IsPluginModule()
  {
    return true;
  }
 
  function HasAdmin()
  {
    return true;
  }
 
    function VisibleToAdminUser()
    {
      return $this->CheckPermission('Manage Comments');
    }
 
  function MinimumCMSVersion()
  {
    return '1.1';
  }
 
  function GetAdminDescription()
  {
    return $this->Lang('description');
  }
 
  function GetAdminSection()
  {
    return 'content';
  }
  
}
 
# vim:ts=4 sw=4 noet
?>