query_total_rows = $rows; } protected function setCurrNode ($node) { $this->query_curr_node = $node; } // get funcs (public) public function getTotalRows () { return $this->query_total_rows; } public function getCurrNode () { return $this->query_curr_node; } public function getQueryResult () { return $this->query_result; } public function __construct() { GLOBAL $wpdb, $TABLE_NAME; self::$musicTable = $wpdb->prefix . $TABLE_NAME[TABLE_ARTIST_MUSIC_ALBUMS]; self::$discographyTable = $wpdb->prefix . $TABLE_NAME[TABLE_ARTIST_ALBUM_LINKER]; $this->loadAll(); $this->artist = new Artist; $this->album = new Music; } public function __destruct() { unset($this->artist); unset($this->album); } public static function callback_Connect_Artist_to_Album(){ GLOBAL $i18n_domain; $artist_id = $_POST['artist_id']; $album_id = $_POST['album_id']; $discography = new Discography; $discography->loadAllByArtistAlbum($artist_id, $album_id); if ($discography->getTotalRows() > 0) { _e("The Artist is already attached to that album.", $i18n_domain); // failed } else { $discography->insert($artist_id, $album_id); echo "1"; // success } unset($discography); die; } public static function callback_Disconnect_Artist_from_Album(){ GLOBAL $i18n_domain; $artist_id = $_POST['artist_id']; $album_id = $_POST['album_id']; $discography = new Discography; $discography->loadAllByArtistAlbum($artist_id, $album_id); if ($discography->getTotalRows() > 0) { $discography->deleteById($discography->id); echo "1"; // success } else { _e("Failed to Disconnect Artist from Album as it appears there currently is no connection between them on the server. " . "It's possible another administrator may be using this feature at the same time.", $i18n_domain); // failed } unset($discography); die; } public static function conditionally_add_scripts_and_styles($posts){ GLOBAL $artistography_plugin_dir; // scripts are already being loaded on every page if (true == get_option('wp_artistography_ajax_loader')) return $posts; if (empty($posts)) return $posts; $shortcode_found = false; // use this flag to see if styles and scripts need to be enqueued foreach ($posts as $the_post) { if (FALSE !== stripos($the_post->post_content, '[artistography_display_artist_page')) { $shortcode_found = true; // bingo! break; } } if ($shortcode_found) { // enqueue here artistography_enqueue_style_and_scripts(); } return $posts; } // [artistography_album_art id=""] public static function shortCodeAlbumArt( $atts, $content=null, $code="") { extract( shortcode_atts( array( 'id' => '0' ), $atts ) ); GLOBAL $i18n_domain; $id = esc_attr($id); $album = new Music; $album->loadById($id); $html = ""; $html = "[caption align=\"alignleft\" width=\"300\" caption=\"$album->artist_name - $album->album_name\"]picture_url\">artist_name - $album->album_name\" src=\"$album->picture_url\" alt=\"\" width=\"300\" height=\"300\" />[/caption]\n"; unset($album); return do_shortcode($html); } // [artistography_album_download_link id=""] public static function shortCodeAlbumDownloadLink( $atts, $content=null, $code="") { extract( shortcode_atts( array( 'id' => '0' ), $atts ) ); GLOBAL $i18n_domain, $transparent_pixel_url, $download_icon_width, $download_icon_height; $id = esc_attr($id); $album = new Music; $orders = new Orders; $html = ""; $album->loadById($id); /* Is it even linked right now? */ if ($album->download_id > 0) { if ($album->price == "0.00") { $html .= self::show_download($album->download_id); } else { if (is_user_logged_in()) { $orders->loadByUserId(wp_get_current_user()->ID); $order_processed = $orders->locateOrderMusicDownloadId($id); if($order_processed) { $html .= self::show_download($album->download_id); } else { $html .= self::show_add_to_cart($id, $album->price); } } else { $html .= self::show_add_to_cart($id, $album->price); } } } else { $html .= ""; } unset($album); unset($orders); return $html; } public static function show_download($download_id) { GLOBAL $download_icon_url, $download_icon_width, $download_icon_height; $html = ""; $html .= "
"; return $html; } public static function show_add_to_cart($album_id, $price) { GLOBAL $add_to_cart_icon_url, $add_to_cart_icon_width, $add_to_cart_icon_height; $html = ""; $html .= "Price: " .CURRENCY. "$price
\n



"; return $html; } // [artistography_display_artist_page id="4" gid="1"] public static function shortCodeDisplayArtistPage( $atts, $content=null, $code="") { extract( shortcode_atts( array( 'id' => '0', 'gid' => '0' ), $atts ) ); GLOBAL $i18n_domain, $download_icon_url, $download_icon_width, $download_icon_height; GLOBAL $add_to_cart_icon_url, $add_to_cart_icon_width, $add_to_cart_icon_height; $id = esc_attr($id); $gid = esc_attr($gid); $discography = new Discography; $artist = new Artist; $album = new Music; $gallery = new Gallery; $html = ""; if ($artist->loadById($id)->getTotalRows() > 0) { $artist->incrementPageViewsById($id); $discography->loadMusicByArtistId($id); $num = $discography->getTotalRows(); $video_postslist = $artist->getVideoPosts(); $gallery->loadByArtistId($id); $related_postslist = $artist->getRelatedPosts(); $html .= "\n"; } else if ($id == '0') { $html .= __('Error: Artist ID specified in Artistography shortcode not found in database. First artist is always id=1 not id=0.', $i18n_domain); } else { $html .= __('Error: Artist ID specified in Artistography shortcode not found in database.', $i18n_domain); } unset($gallery); unset($discography); unset($album); unset($artist); return do_shortcode($html); } public function formatDateTime($day, $month, $year, $hour = 0, $min = 0, $sec = 0) { // "YYYY-MM-DD HH:mm:SS"; if(strlen($month) < 2) $month = "0$month"; if(strlen($day) < 2) $day = "0$day"; if(strlen($hour) < 2) $hour = "0$hour"; if(strlen($min) < 2) $min = "0$min"; if(strlen($sec) < 2) $sec = "0$sec"; return "$year-$month-$day $hour:$min:$sec"; } protected function &loadCurrNodeValues () { GLOBAL $wpdb; if ($this->getTotalRows() > 0) { $this->query_result = $wpdb->get_row($this->query, OBJECT, $this->getCurrNode()); // meta data info update $this->id = $this->query_result->id; $this->poster_id = $this->query_result->poster_id; $this->last_updated_by_id = $this->query_result->last_updated_by_id; $this->create_date = $this->query_result->create_date; $this->update_date = $this->query_result->update_date; $this->artist_id = $this->query_result->artist_id; $this->album_id = $this->query_result->album_id; if($this->artist_id > 0) { // $this->artist->loadById($this->artist_id); } if($this->album_id > 0) { // $this->album->loadById($this->album_id); } } else { $this->query_result = $this->id = $this->poster_id = $this->last_updated_by_id = $this->create_date = $this->update_date = $this->artist_id = $this->album_id = 0; } return $this; } public function &getNodeNext () { // when this function is used, it's assumed that a query was already run // meant to simply load the nth item in the query through a for loop // assumes query, query_curr_node, and query_total_rows is set if (($this->query_curr_node + 1) < $this->getTotalRows()) { $this->query_curr_node += 1; $this->loadCurrNodeValues(); } return $this; } public function &getNodePrev () { // when this function is used, it's assumed that a query was already run // meant to simply load the nth item in the query through a for loop // assumes query, query_curr_node, and query_total_rows is set if (($this->query_curr_node - 1) >= 0 AND $this->getTotalRows() > 0) { $this->query_curr_node -= 1; $this->loadCurrNodeValues(); } return $this; } public function &loadByNode ($node) { // when this function is used, it's assumed that a query was already run // meant to simply load the nth item in the query through a for loop if ($node < $this->getTotalRows() AND $node >= 0 AND $this->getTotalRows() > 0) { $this->setCurrNode($node); $this->loadCurrNodeValues(); } return $this; } public function &loadById ($id) { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " WHERE id = %u", $id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadByArtistId ($artist_id, $order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " WHERE artist_id = %u ORDER BY $order_by", $artist_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadMusicByArtistId ($artist_id, $order_by = 'mt.album_date DESC') { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " dt RIGHT JOIN " .self::$musicTable. " mt ON dt.album_id = mt.id WHERE dt.artist_id = %u ORDER BY $order_by", $artist_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadByAlbumId ($album_id, $order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " WHERE album_id = %u ORDER BY $order_by", $album_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadAllByArtistAlbum ($artist_id, $album_id, $order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " WHERE artist_id = %u AND album_id = %u ORDER BY $order_by", $artist_id, $album_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadDisabledByArtistAlbum ($artist_id, $album_id, $order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " WHERE enabled = false AND artist_id = %u AND album_id = %u ORDER BY $order_by", $artist_id, $album_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadEnabledByArtistAlbum ($artist_id, $album_id, $order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare("SELECT * FROM " .self::$discographyTable. " WHERE enabled = true AND artist_id = %u AND album_id = %u ORDER BY $order_by", $artist_id, $album_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function &loadAll ($order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = "SELECT * FROM " .self::$discographyTable. " ORDER BY $order_by"; $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); $this->setCurrNode(0); // set to first node return $this->loadCurrNodeValues(); } public function deleteById ($id) { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare( "DELETE FROM " .self::$discographyTable. " WHERE id = %u", $id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) { wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); } return $this->getTotalRows(); } public function deleteByArtistId ($id) { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare( "DELETE FROM " .self::$discographyTable. " WHERE artist_id = %u", $id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) { wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); } return $this->getTotalRows(); } public function deleteByAlbumId ($id) { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare( "DELETE FROM " .self::$discographyTable. " WHERE album_id = %u", $id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) { wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); } return $this->getTotalRows(); } // update music album entry public function updateById ($discography_id, $artist_id, $album_id) { GLOBAL $wpdb, $i18n_domain, $current_user; get_currentuserinfo(); $this->query = $wpdb->prepare( "UPDATE " .self::$discographyTable. " SET update_date = now(), artist_id = %u, album_id = %u, last_updated_by_id = %u WHERE id = %u", $artist_id, $album_id, $current_user->ID, $discography_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === FALSE) { wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); } else { // was entered successfully into database return $this->getTotalRows(); } } public function insert ($artist_id, $album_id) { GLOBAL $wpdb, $i18n_domain, $current_user; get_currentuserinfo(); $this->query = $wpdb->prepare( "INSERT INTO " .(string)self::$discographyTable. " (create_date, update_date, poster_id, last_updated_by_id, artist_id, album_id) VALUES (now(), now(), %u, %u, %u, %u)", $current_user->ID, $current_user->ID, $artist_id, $album_id); $this->setTotalRows($wpdb->query($this->query)); if ($this->getTotalRows() === 0 OR $this->getTotalRows() === FALSE) { wp_die( sprintf(__('An error occurred while trying to perform a query: "%s"', $i18n_domain), $this->query) ); } else { // was entered successfully into database return true; } } } /* end class Discography */ ?>