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