Esempio n. 1
0
 function _construct()
 {
     $prefix = !CONFIG::download_filename_prefix ? null : CONFIG::download_filename_prefix . ' ';
     $abmd5 = substr($this->md5, 0, 2);
     if ($this->id) {
         $row = DB::select_row("u.name AS author, GROUP_CONCAT(CONCAT(t.name,':',t.tag_type) SEPARATOR ' ') AS cached_tags\n        FROM posts p\n        JOIN posts_tags pt ON p.id = pt.post_id\n        JOIN tags t ON pt.tag_id = t.id\n        JOIN users u ON p.user_id = u.id\n        WHERE pt.post_id = " . $this->id);
         $this->cached_tags = $row['cached_tags'];
         $this->author = $row['author'];
     }
     $this->parsed_cached_tags = $this->parse_cached_tags();
     $this->tags = $this->tag_names();
     $this->parent_id = $this->parent_id ? (int) $this->parent_id : null;
     $this->file_url = $this->file_url();
     $this->jpeg_url = $this->jpeg_url();
     $this->sample_url = $this->sample_url();
     $this->preview_url = $this->preview_url();
     if ($this->source == null) {
         $this->source = '';
     }
     $bools = array('is_held', 'has_children', 'is_shown_in_index');
     foreach ($bools as $bool) {
         isset($this->{$bool}) && ($this->{$bool} = (bool) $this->{$bool});
     }
     foreach ($this as $n => $p) {
         if (is_numeric($p)) {
             $this->{$n} = (int) $p;
         }
     }
     # For /post/browse
     !$this->sample_width && ($this->sample_width = $this->width);
     !$this->sample_height && ($this->sample_height = $this->height);
     !$this->jpeg_width && ($this->jpeg_width = $this->width);
     !$this->jpeg_height && ($this->jpeg_height = $this->height);
 }
 static function with_implied($tags)
 {
     if (!$tags) {
         return array();
     }
     $all = array();
     foreach ($tags as $tag) {
         $all[] = $tag;
         $results = array($tag);
         foreach (range(1, 10) as $i) {
             // $results = DB::select_values(sanitize_sql([<<-SQL, results]))
             // SELECT t1.name
             // FROM tags t1, tags t2, tag_implications ti
             // WHERE ti.predicate_id = t2.id
             // AND ti.consequent_id = t1.id
             // AND t2.name IN (?)
             // AND ti.is_pending = FALSE
             // SQL
             // DB::show_query();
             // vd($results);
             $results = DB::select_row('
       t1.name 
       FROM tags t1, tags t2, tag_implications ti 
       WHERE ti.predicate_id = t2.id 
       AND ti.consequent_id = t1.id 
       AND t2.name IN (??)
       AND ti.is_pending = FALSE
     ', $results);
             if (is_array($results)) {
                 $results = array_values($results);
                 $all = array_merge($all, $results);
             } else {
                 break;
             }
         }
     }
     return $all;
 }