* removed the microtime_float function, microtime can do it
[vsc.git] / _res / _libs / tdoposts.class.php
blob11872e821414ce8b5cfab335c410a6777866a6c7
1 <?php
2 /**
3 * class representing the posts table
4 */
5 class tdoPosts extends tdoAbstract{
6 protected $fields = array (
7 'post_id',
8 'post_time',
9 'post_title',
10 'post_author',
11 'post_body',
12 'post_active',
13 'post_private'
16 public function __construct(&$db) {
17 $this->name = 'posts';
19 parent::__construct ($db);
20 // $this->setIndex($this->fields['post_id']);
21 // $this->buildTable($tableDefinition);
24 // public function __set ($key, $value) {
25 // if (stristr($key, 'body'))
26 // $this->clean($value);
27 //
28 // return parent::__set($key, $value);
29 // }
31 public function getBody (){
32 $this->set_post_body(stripslashes($this->post_body->getValue()));
33 return $this->post_body;
36 public function clean (&$var) {
37 // here we might need to strip certain tags to avoid javascript injection
38 // then again... since we strip with smarty the posts the <script> something </script> will become
39 // <script type="text/javascript"> //<![CDATA[ something; //]]> </script> ... so it's commented out :D = Brilliant!! <- sarcasm
40 $var = stripslashes ($var);
41 // if (extension_loaded('tidy')){
42 // $config = array (
43 // 'output-xhtml' => true,
44 // 'enclose-text' => false,
45 // 'show-body-only'=> true,
46 // 'fix-uri' => false,
47 // 'fix-backslash' => false,
48 // 'merge-divs' => true,
49 // 'merge-spans' => true,
50 // 'break-before-br'=> true,
51 // 'wrap' => false,
52 // );
53 //
54 // $var = tidy_repair_string ($var, $config, "utf8");
55 // }
58 function isPrivate () {
59 if ($this->post_flags & P_PRIVATE == P_PRIVATE)
60 return true;
61 else
62 return false;
65 public function getPostsCategories (){
66 $this->buildInherentWheres();
67 $cat = new tdoCategories($this->db);
68 $cp = new tdoCategoriesPosts($this->db);
70 $cat->set_FieldModifier('GROUP_CONCAT(DISTINCT(%s))', $cat->category_name); // mySql
72 $cp->joinWith('INNER', $cp->category_id, $cat, $cat->category_id);
74 $this->joinWith ('INNER', $this->post_id, $cp, $cp->post_id);
76 $this->addGroup($this->post_id);
78 return $this->getArray();
81 /**
82 * cleaning the fields' contents before updating
83 * TODO: this can be equaly achieved, with less hassle, by modifying the $this->escape() method :D
85 * @param int $id
87 public function update ($id = null) {
88 $this->clean ($this->post_title,false);
89 $this->clean ($this->post_body);
91 return parent::update ($id);
94 /**
95 * cleaning the fields' contents before inserting into the db
97 public function insert () {
98 $this->clean ($this->post_title,false);
99 $this->clean ($this->post_body);
101 return parent::insert ();