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 static function callback_Create_Album(){ GLOBAL $i18n_domain; $music = new Music; /* $music->insert($_POST['artist_id'], $_POST['artist_name'], $_POST['album_name'], $music->formatDateTime($_POST['album_day'], $_POST['album_month'], $_POST['album_year']), $_POST['artist_url'], $_POST['picture_url'], $_POST['store_url'], $_POST['download_id'], (strcmp($_POST['free_download_enabled'], NULL)) ? TRUE : FALSE, (strcmp($_POST['featured'], NULL)) ? TRUE : FALSE, $_POST['description'], (strcmp($_POST['enabled'], NULL)) ? TRUE : FALSE); */ if ($music->getTotalRows() <= 0) { _e("Failure...", $i18n_domain); // failed } else { echo "1"; // success } unset($music); die; } public static function callback_Delete_Album(){ GLOBAL $i18n_domain; $album_id = $_POST['album_id']; $music = new Music; $music->deleteById($album_id); $discography = new Discography; $discography->deleteByAlbumId($album_id); if ($music->getTotalRows() > 0) { echo "1"; // success } else { echo sprintf(__("Failed: Unable to Delete Album id: %u", $i18n_domain), $album_id); // failed } unset($music); die; } // [artistography_display_enabled_albums cols="4"] public static function shortCodeDisplayEnabledAlbums( $atts ) { extract( shortcode_atts( array( 'cols' => '1', 'size' => '175' ), $atts ) ); $music = new Music; $html = "
\n" . " \n"; $num = $music->loadAllEnabled('album_date DESC')->getTotalRows(); if ($num <= 0) { $html .= " \n"; } else { $rows = ((int)($num / esc_attr($cols)) < (float)($num / esc_attr($cols))) ? (int)($num / esc_attr($cols)) + 1 : (int)($num / esc_attr($cols)); $width = esc_attr($size). "px"; $height = esc_attr($size). "px"; for ($i = 0; $i < $rows; $i++) { $html .= " \n"; for ($j = 0; $j < $cols AND ((($cols * ($i)) + ($j+1)) <= $num); $j++) { $music->loadByNode(($i * $cols) + $j); $html .= " \n"; } for ($j; $j < $cols; $j++) { $html .= "\n"; } $html .= " \n"; if ($i < ($rows-1)) { $html .= "\n"; } } } $html .= "
" .__("No Music Available in the Database!", $i18n_domain). "
\n" . "
\n" . "
\n" . " " .$music->artist_name. "
\n" . " " .$music->album_name. "
\n" . " Released: " .$music->album_month.".".$music->album_day.".".$music->album_year. "
\n" . "
\n"; if ($music->download_id > 0) { $html .= " \n"; } else { $html .= "
 
\n"; } $html .= "
\n" . "
\n" . "
 

\n" . "
\n"; unset($music); return $html; } // [artistography_display_album id="1"] public static function shortCodeDisplayAlbum ( $atts ) { extract( shortcode_atts( array( 'id' => '0' ), $atts ) ); $music = new Music; $music->loadById(esc_attr($id)); $html = "Artist: $music->artist_name
\n" . "Album: $music->album_name
\n" . "Release Date: " .$music->album_month .".". $music->album_day .".". $music->album_year; unset($music); return $html; } // [artistography_display_album_tracklist id="1"] public static function shortCodeDisplayAlbumTracklist ( $atts ) { extract( shortcode_atts( array( 'id' => '0' ), $atts ) ); $music = new Music; $music->loadById(esc_attr($id)); $html = $music->description; unset($music); return $html; } // [artistography_display_album_artist id="1"] public static function shortCodeDisplayAlbumArtist( $atts ) { extract( shortcode_atts( array( 'id' => '0' ), $atts ) ); $music = new Music; $html = $music->loadById(esc_attr($id))->album_year . " - " .$music->loadById(esc_attr($id))->artist_name. " - " .$music->loadById(esc_attr($id))->album_name; unset($music); return $html; } public function __construct() { GLOBAL $wpdb, $TABLE_NAME; self::$artistTable = $wpdb->prefix . $TABLE_NAME[TABLE_ARTISTS]; self::$musicTable = $wpdb->prefix . $TABLE_NAME[TABLE_ARTIST_MUSIC_ALBUMS]; $this->loadAll(); $this->artist = new Artist; } public function __destruct() { unset($this->artist); } 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->album_name = stripslashes($this->query_result->album_name); $this->artist_name = stripslashes($this->query_result->artist_name); $this->artist_id = $this->query_result->artist_id; $this->artist_url = stripslashes($this->query_result->artist_url); $this->picture_url = stripslashes($this->query_result->picture_url); $this->description = stripslashes($this->query_result->description); $this->store_url = stripslashes($this->query_result->store_url); $this->album_date = $this->query_result->album_date; $this->album_year = date("Y", strtotime($this->album_date)); $this->album_month = date("m", strtotime($this->album_date)); $this->album_day = date("d", strtotime($this->album_date)); $this->enabled = $this->query_result->enabled; // if ($this->enabled AND // ($this->album_year > date("Y") OR // ($this->album_year >= date("Y") AND $this->album_month > date("m")) OR // ($this->album_year >= date("Y") AND $this->album_month >= date("m") AND $this->album_day > date("d"))) ) { // $this->enabled = false; // } $this->download_id = $this->query_result->download_id; $this->free_download_enabled = $this->query_result->free_download_enabled; $this->featured = $this->query_result->featured; if($this->artist_id != 0) { $this->artist->loadById($this->artist_id); } } return $this; } 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"; } 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::$musicTable. " 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 &loadAll ($order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = "SELECT * FROM " .self::$musicTable. " 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 &loadAllEnabled ($order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = "SELECT * FROM " .self::$musicTable. " WHERE enabled = true 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 &loadAllDisabled ($order_by = 'id') { GLOBAL $wpdb, $i18n_domain; $this->query = "SELECT * FROM " .self::$musicTable. " WHERE enabled = false 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 incrementPageViewsById ($id) { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare( "UPDATE " .self::$musicTable. " SET page_views = page_views + 1 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) ); } else { // was entered successfully into database return $this->getTotalRows(); } } public function deleteById ($id) { GLOBAL $wpdb, $i18n_domain; $this->query = $wpdb->prepare( "DELETE FROM " .self::$musicTable. " 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(); } // update music album entry public function updateById ($music_id, $artist_id, $artist_name, $album_name, $album_date, $artist_url, $picture_url, $store_url, $download_id, $free_download_enabled, $featured, $description, $enabled) { GLOBAL $wpdb, $i18n_domain, $current_user; get_currentuserinfo(); $this->query = $wpdb->prepare( "UPDATE " .self::$musicTable. " SET update_date = now(), artist_id = %u, artist_name = %s, album_name = %s, album_date = %s, artist_url = %s, picture_url = %s, store_url = %s, download_id = %u, free_download_enabled = %b, featured = %b, description = %s, enabled = %b, last_updated_by_id = %u WHERE id = %u", $artist_id, $artist_name, $album_name, $album_date, $artist_url, $picture_url, $store_url, $download_id, $free_download_enabled, $featured, $description, $enabled, $current_user->ID, $music_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, $artist_name, $album_name, $album_date, $artist_url, $picture_url, $store_url, $download_id, $free_download_enabled, $featured, $description, $enabled) { GLOBAL $wpdb, $i18n_domain, $current_user; get_currentuserinfo(); $this->query = $wpdb->prepare( "INSERT INTO " .(string)self::$musicTable. " (create_date, update_date, poster_id, last_updated_by_id, artist_id, artist_name, album_name, album_date, artist_url, picture_url, store_url, download_id, free_download_enabled, featured, description, enabled) VALUES (now(), now(), %u, %u, %u, %s, %s, %s, %s, %s, %s, %u, %b, %b, %s, %b)", $current_user->ID, $current_user->ID, $artist_id, $artist_name, $album_name, $album_date, $artist_url, $picture_url, $store_url, $download_id, $free_download_enabled, $featured, $description, $enabled); $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; } } public function display_manage_music_form ($music_id = 0, $init_artist = '', $init_album = '', $init_day = 0, $init_month = 0, $init_year = 0, $init_picture_url = '/', $init_artist_url = '/artists/', $init_store_url = '/products/', $init_download_id = 0, $init_free_download = 1, $init_featured = 1, $init_description = '', $init_enabled = 1, $new = 1) { GLOBAL $wpdb, $TABLE_NAME, $i18n_domain; if ($init_day == 0) $init_day = (int)date("d"); if ($init_month == 0) $init_month = (int)date("m"); if ($init_year == 0) $init_year = (int)date("Y"); $text_width = "400px"; if ($new) { $fmusic = 'fmusic'; } else { $fmusic = 'fupdatemusic'; } echo "
\n"; echo "\n"; echo "\n"; if ($new) { echo "\n"; } else { echo "\n"; } echo "
Artist:
Album:
Release Date: \n  \n 
" .__("Album Art (Front) Hot Link (URL)", $i18n_domain). ":
" .__("Store URL", $i18n_domain). ":
" .__("Artist URL", $i18n_domain). ":
" .__("Download ID", $i18n_domain). ":
" .__("Free Download", $i18n_domain). ":
" .__("Featured", $i18n_domain). ":
" .__("Enabled", $i18n_domain). ":
" .__("Description", $i18n_domain). ":
\n"; } } /* end class Music */ ?>