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