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