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