DataObjects/Cms_comments.php
[Pman.Cms] / DataObjects / Cms_comments.php
1 <?php
2 /**
3  * Table Definition for cms_comments
4  */
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
6
7 class Pman_Cms_DataObjects_Cms_comments extends DB_DataObject 
8 {
9     
10     // it would be nice to concatinate this... so it's no so huge...
11     static public $_regex = array( 
12         '\.biz$',
13         '\[url\=',
14         'href\=',
15         'gucci',
16         'guessverkauft',
17         'topash',
18         'watches',
19         'outlet',
20         'asstraffic',
21         'pharmacy',
22         'poker',
23         'mature',
24         'sex',
25         '4444',
26         'thispot',
27         'finance',
28         'morgage',
29         'loans',
30         'commerce',
31         'casino',
32         'diet',
33         'viagra',
34         'phentermine',
35         'spyware',
36         'essay',
37         'duraxoregi', // known spammer
38         'thereturnman',
39         'norton',
40         'writers',
41         'dissertation',
42         
43     );
44     
45     
46     
47      
48
49     ###START_AUTOCODE
50     /* the code below is auto generated do not remove the above tag */
51
52     var $__table = 'cms_comments';                        // table name
53     var $id;                              // int(11)  not_null primary_key auto_increment
54     var $entry_id;                        // int(10)  not_null unsigned
55     var $ontable;                        // text  not_null
56     var $posted;                       // int(10)  unsigned
57     var $title;                           // string(150)  
58     var $author;                          // string(80)  
59     var $email;                           // string(200)  
60     var $url;                             // string(200)  
61     var $ip;                              // string(15)  
62     var $body;                            // blob(65535)  multiple_key blob
63     var $type;                            // string(100)  
64     var $wikifile;                        // varchar(128)
65     var $subscribed;                      // string(5)  not_null enum
66
67     
68     /* the code above is auto generated do not remove the tag below */
69     ###END_AUTOCODE
70     
71     function sendToEntryAuthor($template = 'blogemail.txt')
72     {
73         $a = DB_DataObject::factory('core_person');
74         if ($this->entry_id) {
75             $e = DB_DataObject::factory('cms_page');
76             $e->get($this->entry_id);
77             $this->entry = $e;
78             $a->get($e->author_id);
79         } else {
80             $a->get('email','alan@akbkhome.com');
81         }
82         
83         
84         
85         //return $a->sendComment($this,$template);
86     
87     }
88     
89     function getBody() 
90     {
91         
92         
93         $p = htmlspecialchars($this->body);
94         $lr = "#((http://|https://|mailto:)[^\s\[\]\'\"\)]+)#";
95         $p = preg_replace($lr,'<a target="_new" href="\1">\1</a>', $p);
96         if ($this->title == "Example Code") {
97             
98             return "<code class=\"phpcode\">" . nl2br($p)  . "</code>";
99         }
100         return nl2br($p);
101     
102     }
103     
104     function getDate()
105     {
106         return date("d M Y, H:i",$this->timestamp);
107     
108     }
109     
110     
111     function url()
112     {
113         if (!strlen(trim($this->url))) {
114             return '#';
115         }
116         if (preg_match('#^http://#',$this->url)) {
117             return $this->url;
118         }
119         return 'http://' . $this->url;
120        
121     }
122     
123     
124     function setTitle($str)
125     {
126         if (preg_match('/('.implode('|', self::$_regex). ')/i',$str)) {
127             return false;
128         }
129         $this->title = $str;
130         return true;
131         
132     }
133     function setURL($str) {
134          
135         if (preg_match('/('.implode('|', self::$_regex). ')/i',$str)) {
136             return false;
137         }
138         $this->url = $str;
139         return true;
140     }
141     function setBody($str)
142     {
143         
144         
145         if (preg_match('/('.implode('|', self::$_regex). ')/i',$str)) {
146             return false;
147         }
148         $x = explode('http://', $str);
149         if (count($x) > 5) {
150             return false;
151         }
152         
153         $this->body = $str;
154         return true;
155     }
156     
157     function posted($format = 'd/M/Y')
158     {
159         return date($format, strtotime($this->posted));
160     }
161     
162     function replace($find = ' ', $replace = '-', $field)
163     {
164         if(empty($this->{$field})){
165             return '';
166         }
167         return str_replace($find, $replace, $this->{$field});
168     }
169     
170     function addPoints($type, $person, $roo)
171     {
172         
173         $enum = DB_DataObject::factory('core_enum');
174         $enum->setFrom(array(
175             'etype'     => 'social_points_reason',
176             'name'      => $type,
177             'active'    => 1,
178         ));
179         if(!$enum->find(true)){
180             $roo->jerr("Missing type - {$type}?!");
181         }
182         
183         $social_points = DB_DataObject::factory('social_points');
184         $social_points->_join .= "
185             LEFT JOIN
186                     cms_comments AS join_cms_comments
187             ON
188                     join_cms_comments.id = social_points.onid
189         ";
190                     
191         $social_points->setFrom(array(
192             'person_id' => $person->id,
193             'reason_id' => $enum->id,
194         ));
195         
196         $social_points->whereAdd("
197             join_cms_comments.entry_id = $this->entry_id
198         ");
199         
200         if($social_points->find(true)){
201             return;
202         }
203         
204         $points = (int) array_pop(explode('_', $enum->name));
205         
206         $social_points->onid = $this->id;
207         $social_points->points = $points;
208         $social_points->act_when = $social_points->sqlValue("NOW()");
209         
210         $social_points->insert();
211         
212         $social_points->onInsert(array(), $roo);
213         
214     }
215     
216     function author()
217     {
218         $person = DB_DataObject::factory('core_person');
219         if(!$person->get('email', $this->email)){
220             return false;
221         }
222         
223         return $person;
224     }
225 }