Ejemplo n.º 1
0
 public function albums($atts = null, $content = null, $code = "")
 {
     global $wpdb, $_wt_options;
     require_once WT_PLUGIN_PATH . 'admin/template.php';
     require_once WT_PLUGIN_PATH . 'admin/handlers.php';
     require_once WT_PLUGIN_PATH . 'dwoo/dwooAutoload.php';
     $dwoo = new Dwoo();
     # CONFIG PARAMS
     $attr = shortcode_atts(self::$album_default, $atts);
     # TEMPLATE
     $theme_file_name = empty($attr["theme_file_name"]) ? 0 : $attr["theme_file_name"];
     #ARTIST
     $artists_to_show = empty($attr["artist"]) ? 0 : explode(",", $attr["artist"]);
     #ALBUMS
     $albums_to_show = empty($attr["album"]) ? 0 : explode(",", $attr["album"]);
     #EXCLUDE ALBUMS
     $albums_to_hide = empty($attr["exclude"]) ? 0 : explode(",", $attr["exclude"]);
     #GENRE
     $genre_to_show = empty($attr["genre"]) ? 0 : explode(",", $attr["genre"]);
     #ORDER
     $order = strtolower($attr["order_by"]) == "order" ? "album_order" : "album_title";
     #DIRECTION
     $direction = strtoupper($attr["direction"]) == "ASC" ? "ASC" : "DESC";
     #START WITH
     $start_with = $attr["start_with"];
     #TYPE
     $album_type = !empty($attr["type"]) ? $attr["type"] : 0;
     #TYPE
     $album_genre = !empty($attr["genre"]) ? $attr["genre"] : 0;
     #LIMIT
     $limit = $attr["limit"] && is_numeric($attr["limit"]) ? " LIMIT {$attr['limit']} " : "";
     $albums = 0;
     # GET RESULTS
     $conds = array();
     $conds_str = "";
     if (!empty($start_with)) {
         $conds[] = "UPPER(album.album_title) LIKE UPPER('{$start_with}%')";
     }
     if ($albums_to_show) {
         $conds[] = $this->columns_sql("album.album_id", $albums_to_show);
     }
     if ($albums_to_hide) {
         $conds[] = $this->columns_sql("album.album_id", $albums_to_hide, null, "!=");
     }
     if ($artists_to_show) {
         $conds[] = $this->columns_sql("album.album_artist_id", $artists_to_show);
     }
     if ($album_type) {
         $conds[] = "album.album_type='{$album_type}'";
     }
     if ($album_genre) {
         $conds_str .= " JOIN wp_wtr_attachment AS att ON album.album_id = att.attachment_target_id";
         $conds[] = "att.attachment_target='album'";
         $conds[] = "att.attachment_type='genre'";
         $conds[] = $this->columns_sql("att.attachment_info", $genre_to_show);
     }
     if (count($conds) > 0) {
         $conds_str .= " WHERE " . implode(" AND ", $conds);
     }
     $albums = $wpdb->get_results("SELECT * FROM " . WORDTOUR_ALBUMS . " as album LEFT JOIN " . WORDTOUR_ARTISTS . " as artist ON artist.artist_id=album.album_artist_id {$conds_str} GROUP BY album.album_id ORDER BY {$order} {$direction} {$limit}", "ARRAY_A");
     //$this->result_unique("album_id",$albums);
     # SET TEMPLATE
     $tpl = array();
     if ($albums) {
         $albumObj = new WT_Album();
         foreach ($albums as $album) {
             $albumObj->id = $album["album_id"];
             $tpl["data"][] = $albumObj->template($album);
         }
     } else {
         $tpl["data"] = array();
     }
     include WT_PLUGIN_PATH . 'theme/layout.renderer.php';
     return $html;
 }
Ejemplo n.º 2
0
 public function similar($data = 0)
 {
     global $wpdb;
     $result = array();
     try {
         if (!$data) {
             $data = $this->data["album_genre"];
         }
         $artist_id = $this->data["album_artist_id"];
         $album_id = $this->data["album_id"];
         if ($data) {
             $genres = array();
             foreach ($data as $genre) {
                 $genres[] = "att.attachment_info='{$genre['0']}'";
             }
             if (count($genres)) {
                 $genre_sql = "(" . implode(" OR ", $genres) . ")";
                 $sql = "SELECT * FROM " . WORDTOUR_ALBUMS . " as album \n\t\t\t\t\t\t\tJOIN " . WORDTOUR_ATTACHMENT . " AS att ON album.album_id = att.attachment_target_id \n\t\t\t\t\t\t\tAND att.attachment_target='album' AND att.attachment_type='genre' AND album.album_id != {$album_id} \n\t\t\t\t\t\t\tAND {$genre_sql} GROUP BY album.album_id ORDER BY album.album_title LIMIT 5";
                 $albums = $wpdb->get_results($sql, "ARRAY_A");
                 $albums_obj = new WT_Album();
                 foreach ($albums as $album) {
                     $albums_obj->id = $album["album_id"];
                     $albums_obj->retrieve();
                     $result[] = $albums_obj->template();
                 }
             }
         }
     } catch (Exception $e) {
         return array();
     }
     return $result;
 }