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         'apartmentcleanings',
43         'health',
44         'coldfusion',
45         'garmin',
46         'essay',
47         
48     );
49     
50     
51     
52      
53
54     ###START_AUTOCODE
55     /* the code below is auto generated do not remove the above tag */
56
57     var $__table = 'cms_comments';                        // table name
58     var $id;                              // int(11)  not_null primary_key auto_increment
59     var $entry_id;                        // int(10)  not_null unsigned
60     var $ontable;                        // text  not_null
61     var $posted;                       // int(10)  unsigned
62     var $title;                           // string(150)  
63     var $author;                          // string(80)  
64     var $email;                           // string(200)  
65     var $url;                             // string(200)  
66     var $ip;                              // string(15)  
67     var $body;                            // blob(65535)  multiple_key blob
68     var $type;                            // string(100)  
69     var $wikifile;                        // varchar(128)
70     var $subscribed;                      // string(5)  not_null enum
71
72     
73     /* the code above is auto generated do not remove the tag below */
74     ###END_AUTOCODE
75     
76     function sendToEntryAuthor($template = 'blogemail.txt')
77     {
78         $a = DB_DataObject::factory('core_person');
79         if ($this->entry_id) {
80             $e = DB_DataObject::factory('cms_page');
81             $e->get($this->entry_id);
82             $this->entry = $e;
83             $a->get($e->author_id);
84         } else {
85             $a->get('email','alan@akbkhome.com');
86         }
87         
88         
89         
90         //return $a->sendComment($this,$template);
91     
92     }
93     
94     function getBody() 
95     {
96         
97         
98         $p = htmlspecialchars($this->body);
99         $lr = "#((http://|https://|mailto:)[^\s\[\]\'\"\)]+)#";
100         $p = preg_replace($lr,'<a target="_new" href="\1">\1</a>', $p);
101         if ($this->title == "Example Code") {
102             
103             return "<code class=\"phpcode\">" . nl2br($p)  . "</code>";
104         }
105         return nl2br($p);
106     
107     }
108     
109     function getDate()
110     {
111         return date("d M Y, H:i",$this->timestamp);
112     
113     }
114     
115     
116     function url()
117     {
118         if (!strlen(trim($this->url))) {
119             return '#';
120         }
121         if (preg_match('#^http://#',$this->url)) {
122             return $this->url;
123         }
124         return 'http://' . $this->url;
125        
126     }
127     
128     
129     function setTitle($str)
130     {
131         if (preg_match('/('.implode('|', self::$_regex). ')/i',$str)) {
132             return false;
133         }
134         $this->title = $str;
135         return true;
136         
137     }
138     function setURL($str) {
139          
140         if (preg_match('/('.implode('|', self::$_regex). ')/i',$str)) {
141             return false;
142         }
143         $this->url = $str;
144         return true;
145     }
146     function setBody($str)
147     {
148         
149         
150         if (preg_match('/('.implode('|', self::$_regex). ')/i',$str)) {
151             return false;
152         }
153         $x = explode('http://', $str);
154         if (count($x) > 5) {
155             return false;
156         }
157         
158         $this->body = $str;
159         return true;
160     }
161     
162     function posted($format = 'd/M/Y')
163     {
164         return date($format, strtotime($this->posted));
165     }
166     
167     function replace($find = ' ', $replace = '-', $field)
168     {
169         if(empty($this->{$field})){
170             return '';
171         }
172         return str_replace($find, $replace, $this->{$field});
173     }
174     
175     function addPoints($type, $person, $roo)
176     {
177         
178         $enum = DB_DataObject::factory('core_enum');
179         $enum->setFrom(array(
180             'etype'     => 'social_points_reason',
181             'name'      => $type,
182             'active'    => 1,
183         ));
184         if(!$enum->find(true)){
185             $roo->jerr("Missing type - {$type}?!");
186         }
187         
188         $social_points = DB_DataObject::factory('social_points');
189         $social_points->_join .= "
190             LEFT JOIN
191                     cms_comments AS join_cms_comments
192             ON
193                     join_cms_comments.id = social_points.onid
194         ";
195                     
196         $social_points->setFrom(array(
197             'person_id' => $person->id,
198             'reason_id' => $enum->id,
199         ));
200         
201         $social_points->whereAdd("
202             join_cms_comments.entry_id = $this->entry_id
203         ");
204         
205         if($social_points->find(true)){
206             return;
207         }
208         
209         $points = (int) array_pop(explode('_', $enum->name));
210         
211         $social_points->onid = $this->id;
212         $social_points->points = $points;
213         $social_points->act_when = $social_points->sqlValue("NOW()");
214         
215         $social_points->insert();
216         
217         $social_points->onInsert(array(), $roo);
218         
219     }
220     
221     function author()
222     {
223         $person = DB_DataObject::factory('core_person');
224         if(!$person->get('email', $this->email)){
225             return false;
226         }
227         
228         return $person;
229     }
230 }