powered by ANIga gallery -- your version is -- the latest version is -- © Michael Naab 2006
_fp_timeout = 4; if (@$client->fetch('http://www.animalbeach.net/public/ANIga/version.txt') === false) { return $no_version; } $remote = $client->results; if (!$remote || strlen($remote) > 50 ) { return $no_version; } return $remote; } else return $no_version; } // File and Zip functions //######################################################################## class anigal_file { var $image_quality; var $image_type; var $fname; var $msg_out; function handle_file($file, $path, $filename, $image_type, $size, $rename = false, $alt_img = false, $msg_out = true, $skip = false ) { global $aniga_lang; $this->image_quality = get_option('anigal_resize_qual'); // resulting image type (1 = GIF, 2 = JPG, 3 = PNG) // enter code of the image type if you want override it // or set it to -1 to determine automatically $this->image_type = $image_type; $this->fname = $filename; $this->msg_out = $msg_out; switch ($size): case "thumb": $max_x = get_option('anigal_thumb_size'); $max_y = get_option('anigal_thumb_size'); break; case "normal": $max_x = get_option('anigal_norm_size'); $max_y = get_option('anigal_norm_size'); break; case "catalb": $max_x = get_option('anigal_caimg_size'); $max_y = get_option('anigal_caimg_size'); break; default: $max_x = get_option('anigal_thumb_size'); $max_y = get_option('anigal_thumb_size'); endswitch; if ($alt_img && $file == '') $file = ABSPATH . 'wp-content/plugins/ANIga/noimage.jpg'; elseif (!$alt_img && $file == '') { if ($this->msg_out) return "

" . $aniga_lang['misc_no_read'] . "

"; else return; } if ($rename && is_file($path.$this->fname)) { for ($i = 1; is_file($path.$this->fname); $i++) { $this->fname = $this->rename_file($this->fname, $i); } } // generate if (get_option('anigal_resize') == 'yes' && $_POST['noresize'] != 'yes') return $this->GenerateThumbFile($file, $path, $max_x, $max_y); elseif ($skip) return; else return $this->upload_file($file, $path, $this->fname, false); } function upload_file($file, $path, $filename, $rename = false) { // move uploaded to directory global $aniga_lang; if ($rename && is_file($path.$filename)) { for ($i = 1; is_file($path.$filename); $i++) { $filename = $this->rename_file($filename, $i); } } $this->fname = $filename; if(move_uploaded_file($file, $path.$this->fname)) { chmod($path.$this->fname, 0644); if ($this->msg_out) return "

" . $aniga_lang['picture'] . " $this->fname " . $aniga_lang['misc_upld'] . "

"; else return; } else { if ($this->msg_out) return "

" . $aniga_lang['picture'] . " $this->fname " . $aniga_lang['misc_no_upld'] . "

"; else return; } } function rename_file($filename, $nr) { // rename files if necessary $pos = strrpos($filename, "."); $name = substr($filename, 0, $pos); $ext = substr($filename, $pos, strlen($filename)-$pos); if(ereg("[0-9]", substr($name, -1) )) $string = substr($name, 0, strlen($name)-1) . "$nr" . "$ext"; else $string = "$name" . "_$nr" . "$ext"; return $string; } function GenerateThumbFile($file, $path, $max_x, $max_y) { // generate thumb from image and save it global $aniga_lang; $to_file = $path.$this->fname; $msg = ''; // get source image size (width/height/type) // orig_img_type 1 = GIF, 2 = JPG, 3 = PNG list($orig_x, $orig_y, $orig_img_type, $img_sizes) = GetImageSize($file); // should we override thumb image type? $image_type = ($this->image_type != -1 ? $this->image_type : $orig_img_type); // check for allowed image types if ($orig_img_type < 1 or $orig_img_type > 3) { $trans = array("%type%" => $orig_img_type, "%file%" => $this->fname); $msg .= "

" . strtr($aniga_lang['misc_imgtyp'], $trans) . "

"; if ($this->msg_out) return $msg; else return; } if ($orig_x > $max_x or $orig_y > $max_y) { // resize $per_x = $orig_x / $max_x; $per_y = $orig_y / $max_y; if ($per_y > $per_x) { $max_x = $orig_x / $per_y; } else { $max_y = $orig_y / $per_x; } } else { // keep original sizes, i.e. just copy if (@copy($file, $to_file)) $msg .= "

" . str_replace("%file%", "'". $this->fname . "'", $aniga_lang['misc_no_res']) . "

"; else $msg .= "

'$this->fname' " . $aniga_lang['misc_no_upld'] . "

"; if ($this->msg_out) return $msg; else return; } if ($image_type == 1) { // should use this function for gifs (gifs are palette images) $ni = imagecreate($max_x, $max_y); } else { // Create a new true color image $ni = ImageCreateTrueColor($max_x,$max_y); } // Fill image with white background (255,255,255) $white = imagecolorallocate($ni, 255, 255, 255); imagefilledrectangle( $ni, 0, 0, $max_x, $max_y, $white); // Create a new image from source file $im = $this->ImageCreateFromType($orig_img_type,$file); // Copy the palette from one image to another imagepalettecopy($ni,$im); // Copy and resize part of an image with resampling imagecopyresampled( $ni, $im, // destination, source 0, 0, 0, 0, // dstX, dstY, srcX, srcY $max_x, $max_y, // dstW, dstH $orig_x, $orig_y); // srcW, srcH // save thumb file $this->SaveImage($image_type, $ni, $to_file, $this->image_quality); $msg .= "

" . $aniga_lang['picture'] . " $this->fname " . $aniga_lang['misc_added'] . "

"; if ($this->msg_out) return $msg; else return; } function SaveImage($type, $im, $filename, $quality) { $res = null; // ImageGIF is not included into some GD2 releases, so it might not work // output png if gifs are not supported if(!function_exists('imagegif')) $type = 3; switch ($type) { case 1: $res = ImageGIF($im,$filename); break; case 2: $res = ImageJPEG($im,$filename,$quality); break; case 3: $res = ImagePNG($im,$filename); break; } return $res; } function ImageCreateFromType($type,$filename) { $im = null; switch ($type) { case 1: $im = ImageCreateFromGif($filename); break; case 2: $im = ImageCreateFromJpeg($filename); break; case 3: $im = ImageCreateFromPNG($filename); break; } return $im; } } function okfiletype($filename, $allowed) { // check if filetype is ok for($i = 0; $i < count($allowed); $i++) { if(strtolower($allowed[$i]) == strtolower(substr($filename, -3)) || strtolower($allowed[$i]) == strtolower(substr($filename, -4))) return true; } return false; } function anigal_calc_gallery() { // calculate the albums and pictures and update the db global $wpdb; $calc_alb_req = "SELECT * FROM $wpdb->anigal_alb"; $calc_alb_ret = $wpdb->get_results($calc_alb_req); if ($calc_alb_ret){ foreach ($calc_alb_ret as $calc_alb) { $count = 0; $count_pic_req = "SELECT * FROM $wpdb->anigal_pic WHERE alb_id = $calc_alb->alb_id"; $count_pic_ret = $wpdb->get_results($count_pic_req); $count = $wpdb->num_rows; $update_alb = mysql_query("UPDATE $wpdb->anigal_alb SET count_pics = '$count' WHERE alb_id = $calc_alb->alb_id"); } } $calc_cat_req = "SELECT * FROM $wpdb->anigal_cat"; $calc_cat_ret = $wpdb->get_results($calc_cat_req); if ($calc_cat_ret){ foreach ($calc_cat_ret as $calc_cat) { $count = 0; $count_albs = 0; $count_alb_req = "SELECT * FROM $wpdb->anigal_alb WHERE cat_wp_id = $calc_cat->wp_id"; $count_alb_ret = $wpdb->get_results($count_alb_req); if ($count_alb_ret) { foreach ($count_alb_ret as $count_alb) { $count = $count + $count_alb->count_pics; $count_albs++; } } $update_cat = mysql_query("UPDATE $wpdb->anigal_cat SET count_pics = '$count', count_albs = '$count_albs' WHERE wp_id = $calc_cat->wp_id"); } } } function anigal_zip_upload($dir, $file_org, $file_tmp, $db_path) { // upload and unzip archives with php zip library global $aniga_lang; $file = $dir."/".$file_org; $msgf = ""; if(move_uploaded_file($file_tmp, $file)) { $zip = zip_open($file); $i = 0; if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $fp = fopen($dir."/".zip_entry_name($zip_entry),"w"); fwrite($fp,$buf); //$msgf .= zip_entry_name($zip_entry)."
"; zip_entry_close($zip_entry); $i++; } } zip_close($zip); $msgf .= "

" . str_replace("%file%", "'". basename($file_org). "'", $aniga_lang['misc_the_file']) . " '$db_path'

"; } else $msgf .= "

" . $aniga_lang['misc_no_read_z'] . "

"; unlink($file); } else $msgf .= "

" . $aniga_lang['misc_no_move_z'] . " '$db_path'

"; return $msgf; } //GALLERY TEMPLATE CLASSES //######################################################################## class anigal_index { // print categories var $path; var $alg = 'gallery_alignleft'; function heading() { ?>

user = $aniga->user(); $this->heading(); // print heading $this->path = get_option('anigal_dirpath').'00-gfx/cat_'; $get_cat = $aniga->getcategories(); if ($get_cat) { foreach ($get_cat as $cat) { $this->loop_html($cat->wp_id, $cat->cat_id, $cat->description, $cat->name); if ('gallery_alignleft' == $this->alg) $this->alg = 'gallery_alignright'; else $this->alg = 'gallery_alignleft'; } $this->meta(); // print meta information } else echo ''; } } class anigal_category { // print albums for category var $path; var $alg = 'gallery_alignleft'; function heading() { global $aniga; $aniga->nav_cat(); //NAVIGATION ?>

user = $aniga->user(); $this->heading(); // print heading $this->path = get_option('anigal_dirpath').'00-gfx/album_'; switch ($aniga->checkcat($id)): case 1: $get_alb = $aniga->getalbums($id); if ($get_alb) { foreach ($get_alb as $album) { $this->loop_html($album->wp_id, $album->alb_id, $album->description, $album->name); if ('gallery_alignleft' == $this->alg) $this->alg = 'gallery_alignright'; else $this->alg = 'gallery_alignleft'; } $this->meta($id); // print meta information } else echo ''; break; case 2: echo ''; break; case 3: echo ''; break; endswitch; } } class anigal_picture { // print thumbnails or picture var $pid; var $id; var $alb_id; var $cat_wp_id; var $album = array(); var $page = array(); var $pic = array(); var $pic_link; function slideshow_js() { include ("slideshow.php"); } function slideshow() { global $aniga, $aniga_lang; $album = $this->album; $first = $aniga->getfirstpic($album->alb_id); $this->navthumb(); ?> navthumb(); $this->calcpage(); if ($this->page['page_max'] >= $this->page['page']) { // show thumbnails if pages are ok ?> thumbmeta(); } else echo ''; } function navthumb() { global $aniga, $aniga_lang; $album = $this->album; $aniga->nav_thumb($album->cat_wp_id); // NAVIGATION ?>

album; $this->page['page'] = $_GET['page']; if (empty($this->page['page']) || $this->page['page'] < 1) $this->page['page'] = 1; $this->page['max_pic'] = $aniga->c_alb_pic($album->alb_id); if (empty($_COOKIE["gal_page" . COOKIEHASH])) $this->page['pt'] = 5 * get_option('anigal_colums'); // first value from array! else $this->page['pt'] = $_COOKIE["gal_page" . COOKIEHASH]; $this->page['page_start'] = ($this->page['page'] * $this->page['pt']) - $this->page['pt']; $this->page['page_end'] = $this->page['pt']; $this->page['prev_page'] = $this->page['page'] - 1; $this->page['next_page'] = $this->page['page'] + 1; if (is_int($this->page['max_pic']/$this->page['pt'])) $this->page['page_max'] = $this->page['max_pic']/$this->page['pt']; else $this->page['page_max'] = floor($this->page['max_pic']/$this->page['pt']) + 1; } function thumbmenu() { global $aniga, $aniga_lang; ?>
thumbselect($this->id); ?> |
$thumbs . ' ' . $aniga_lang['thumbnails'], 2*$thumbs => 2*$thumbs . ' ' . $aniga_lang['thumbnails'], 5*$thumbs => 5*$thumbs . ' ' . $aniga_lang['thumbnails'], 10*$thumbs => 10*$thumbs . ' ' . $aniga_lang['thumbnails'], 999 => $aniga_lang['thumbnails_all']); return $thumbs_count; } function thumbselect($id) { // print the thumbnail-number select-box ?> « »
thumbpages($this->page['page'], $this->page['prev_page'], $this->page['next_page'], $this->page['page_max'], $this->id); ?>
album; $col = 1; $col_count = get_option('anigal_colums'); $thumbs = $aniga->getthumbs($album->alb_id, $this->page['page_start'], $this->page['page_end']); foreach ($thumbs as $pic) { if ($col == 1) : ?> <?php echo $pic->filename; ?> c_pic_com($pic->pid); switch ($com): case 0: ?>
 

1
1): ?>
album; ?>
page['max_pic']; ?> | c_alb_com($album->alb_id); ?> | c_alb_view($album->alb_id); ?> |
album; $aniga->nav_thumb($album->cat_wp_id); // NAVIGATION ?>

pic; $src = '' . $picture->filename . ''; $after = ''; switch (get_option("anigal_img_mode")): case "link": $link = ''; break; case "js": ?> path . $picture->filename . "')\" >"; break; case "lightbox": $link = ''; break; case "none": $link = ''; $after = ''; break; endswitch; $this->pic_link = $link.$src.$after; } function picture_html_pic($current_pic, $hits, $cur_page) { global $aniga, $aniga_lang; $picture = $this->pic; $this->picture_link(); ?> pic; if ($picture->caption): ?>
<? echo $aniga_lang['previous']; ?> <? echo $aniga_lang['next']; ?>
album; $this->pic = $aniga->getpic($this->pid); $picture = $this->pic; if (empty($this->pid)) { //some checks, to verify that the picture is ok echo ''; } elseif ($picture->alb_id != $album->alb_id){ echo ''; } else { // picture is ok: switch ($aniga->checkpic($picture->level)): // check user level case 1: $hits = $aniga->updatehits($picture->hits, $picture->pid); // update picture hits // do the picture navigation // ############################################################## $gallery_nav = $aniga->getpics($picture->alb_id); $nav_i = 1; $nav_j = 1; unset($current_pic); unset($prev_id); unset($prev_path); unset($prev_filename); unset($next_id); unset($next_path); unset($next_filename); foreach ($gallery_nav as $gal_nav_array) { if ($gal_nav_array->pid == $this->pid) $current_pic = $nav_i; $nav_i++; } foreach ($gallery_nav as $gal_nav_pic) { if($nav_j == ($current_pic - 1)){ $prev_id = $gal_nav_pic->pid; $prev_path = $gal_nav_pic->path; $prev_filename = $gal_nav_pic->filename; } else if($nav_j == ($current_pic + 1)){ $next_id = $gal_nav_pic->pid; $next_path = $gal_nav_pic->path; $next_filename = $gal_nav_pic->filename; } $nav_j++; } $cur_page = $aniga->getcurrentpage($current_pic); // ############################################################## $this->navpic($cur_page); $this->picture_html_pic($current_pic, $hits, $cur_page); $this->picture_html_nav($prev_id, $prev_path, $prev_filename, $next_id, $next_path, $next_filename); $this->picture_html_caption(); $this->comments_templ("/gallery-comments.php"); break; case 2: $this->navthumb(); echo ''; break; case 3: $this->navthumb(); echo ''; break; endswitch; } } function comments_templ( $file = '/gallery-comments.php' ) { // copy from comments_template() to show only comments with the right PID global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; if ( ! (is_single() || is_page() || $withcomments) ) return; $req = get_settings('require_name_email'); // make backwards compatible to prior versions if (function_exists('wp_get_current_commenter')) { $commenter = wp_get_current_commenter(); extract($commenter); } else { $comment_author = ''; if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { $comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]); $comment_author = stripslashes($comment_author); $comment_author = wp_specialchars($comment_author, true); } $comment_author_email = ''; if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); $comment_author_email = stripslashes($comment_author_email); $comment_author_email = wp_specialchars($comment_author_email, true); } $comment_author_url = ''; if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) ) { $comment_author_url = apply_filters('pre_comment_author_url', $_COOKIE['comment_author_url_'.COOKIEHASH]); $comment_author_url = stripslashes($comment_author_url); $comment_author_url = wp_specialchars($comment_author_url, true); } } // TODO: Use API instead of SELECTs. if ( empty($comment_author) ) { $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' AND comment_pid_ID = '$this->pid' ORDER BY comment_date"); } else { $author_db = $wpdb->escape($comment_author); $email_db = $wpdb->escape($comment_author_email); $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_pid_ID = '$this->pid' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date"); } define('COMMENTS_TEMPLATE', true); $include = apply_filters('comments_template', TEMPLATEPATH . $file ); if ( file_exists( $include ) ) require( $include ); else require( ABSPATH . 'wp-content/themes/default/comments.php'); } function show($id) { global $aniga, $aniga_lang; $aniga->user = $aniga->user(); $this->pid = $_GET['pid']; $this->id = $id; $this->album = $aniga->getalbum($this->id); switch ($aniga->checkalb($this->id)): case 1: if ($_GET['slideshow'] == 'start' && $_GET['ssid'] == $this->id) { // show slideshow $this->slideshow(); } elseif (empty($this->pid)) { // no pid => show thumbnails $this->thumbnails(); } else { // there is a pid => show the picture with navigation and comments. $this->picture(); } break; case 2: $this->navthumb(); echo ''; break; case 3: $this->navthumb(); echo ''; break; endswitch; } } class anigal_db { var $user = '0'; var $allowed_zip = array("zip"); var $allowed_pic = array("jpg", "jpeg", "gif", "png"); function user() { $user = anigal_get_userinfo(); return $user; } function query($what) { global $wpdb; $level = $this->user; switch ($what): case "WHERE": return "WHERE level <= $level"; case "AND": return "AND level <= $level"; case "AND.pic": return "AND {$wpdb->anigal_pic}.level <= $level"; case "AND.alb": return "AND {$wpdb->anigal_alb}.level <= $level"; endswitch; } function checkcat($id) { global $wpdb; $cat = $wpdb->get_row("SELECT level FROM $wpdb->anigal_cat WHERE wp_id = $id"); if ($cat->level <= $this->user) return 1; elseif ($this->user == '0') return 2; elseif ($this->user >> '0') return 3; } function checkalb($id) { global $wpdb; $alb = $wpdb->get_row("SELECT level, cat_wp_id from $wpdb->anigal_alb WHERE wp_id = $id"); $cat = $this->checkcat($alb->cat_wp_id); if ($alb->level <= $this->user && $cat == 1) return 1; elseif ($this->user == '0') return 2; elseif ($this->user >> '0') return 3; } function checkpic($level) { if ($level <= $this->user) return 1; elseif ($this->user == '0') return 2; elseif ($this->user >> '0') return 3; } function checkpath() { global $aniga_lang; $msg = ''; if (substr( get_option('anigal_abspath'), -1) != '/') $msg .= "

" . $aniga_lang['misc_w_1'] . "

"; else { if ( is_dir( get_option('anigal_abspath') ) ) { if ( !is_writable( get_option('anigal_abspath') ) ) $msg .= "

" . $aniga_lang['misc_w_2'] . "

"; if ( !is_dir( get_option('anigal_abspath')."00-gfx" ) ) $msg .= "

" . $aniga_lang['misc_w_3'] . "

"; elseif ( !is_writable( get_option('anigal_abspath')."00-gfx" ) ) $msg .= "

" . $aniga_lang['misc_w_4'] . "

"; if ( !is_dir( get_option('anigal_abspath')."00-single" ) ) $msg .= "

" . $aniga_lang['misc_w_5'] . "

"; elseif ( !is_writable( get_option('anigal_abspath')."00-single" ) ) $msg .= "

" . $aniga_lang['misc_w_6'] . "

"; } else $msg .= "

" . $aniga_lang['misc_w_7'] . "

"; } if (substr( get_option('anigal_dirpath'), -1) != '/') $msg .= "

" . $aniga_lang['misc_w_8'] . "

"; return $msg; } // #### RETURN DATA FUNCTIONS ### -------------------------------------- function getcategory($id) { // return specific categorie-information from db global $wpdb; $category = $wpdb->get_row("SELECT * FROM $wpdb->anigal_cat WHERE wp_id=$id"); return $category; } function getcategories() { // get all categories global $wpdb; $gal_cat_req = "SELECT * FROM $wpdb->anigal_cat ".$this->query("WHERE")." ORDER BY cat_id ASC"; $gal_cat_ret = $wpdb->get_results($gal_cat_req); return $gal_cat_ret; } function getcategoryname($cat_id) { // return category name from db global $wpdb; $cat = $wpdb->get_row("SELECT description FROM $wpdb->anigal_cat WHERE wp_id=$cat_id"); return $cat->description; } function getallalbums() { // return all albums from db global $wpdb; $gal_cat_req = "SELECT description, wp_id, alb_id, name, count_pics FROM $wpdb->anigal_alb ORDER BY alb_id DESC"; $gal_cat_ret = $wpdb->get_results($gal_cat_req); return $gal_cat_ret; } function getalbums($id) { // get all albums for category global $wpdb; $gal_cat_req = "SELECT * FROM $wpdb->anigal_alb WHERE cat_wp_id = $id ".$this->query("AND")." ORDER BY alb_id DESC"; $gal_cat_ret = $wpdb->get_results($gal_cat_req); return $gal_cat_ret; } function getalbum($id) { //return specific album-information from db global $wpdb; $album = $wpdb->get_row("SELECT * FROM $wpdb->anigal_alb WHERE wp_id = $id"); return $album; } function getfirstpic($alb_id) { // return specific picture from db global $wpdb; $picture = $wpdb->get_row("SELECT * FROM $wpdb->anigal_pic WHERE alb_id=$alb_id ".$this->query("AND")." ORDER BY filename LIMIT 1"); return $picture; } function getpic($pid) { // return specific picture from db global $wpdb; $picture = $wpdb->get_row("SELECT * FROM $wpdb->anigal_pic WHERE pid=$pid"); return $picture; } function getthumbs($alb_id, $page_start, $page_end) { // return thumbnails from db global $wpdb; $gal_thumbs_req = "SELECT pid, path, filename FROM $wpdb->anigal_pic WHERE alb_id=$alb_id ".$this->query("AND")." ORDER BY filename LIMIT $page_start,$page_end"; $gal_thumbs = $wpdb->get_results($gal_thumbs_req); return $gal_thumbs; } function getpics($alb_id) { // return pictures for an album from db global $wpdb; $gal_nav_req = "SELECT * FROM $wpdb->anigal_pic WHERE alb_id=$alb_id ".$this->query("AND")." ORDER BY filename"; $gal_nav_ret = $wpdb->get_results($gal_nav_req); return $gal_nav_ret; } function getcurrentpage($current_pic) { // return current page acc. to cookie if (empty($_COOKIE["gal_page" . COOKIEHASH])) $pt = 5 * get_option('anigal_colums'); else $pt = $_COOKIE["gal_page" . COOKIEHASH]; if (is_int($current_pic/$pt)) $cur_page = $current_pic/$pt; else $cur_page = floor($current_pic/$pt) + 1; return $cur_page; } function getupdatedpost($id) { // return updated post from db global $wpdb; $upd_post = $wpdb->get_row("SELECT post_title, post_content, comment_count, comment_status FROM $wpdb->posts WHERE ID = $id"); return $upd_post; } function getpostparent($id) { // return parent posts for an ID from db global $wpdb; $check_cat_req = "SELECT * FROM $wpdb->posts WHERE post_parent = $id"; $check_cat_ret = $wpdb->get_results($check_cat_req); $count = $wpdb->num_rows; return $count; } // #### COUNT FUNCTIONS ### -------------------------------------------- function c_all_alb() { // return total number of albums global $wpdb; $gal_count_req = "SELECT alb_id FROM $wpdb->anigal_alb ".$this->query("WHERE"); $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_all_pic() { // return total number of pictures global $wpdb; $gal_count_req = "SELECT pid FROM $wpdb->anigal_pic ".$this->query("WHERE"); $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_all_com() { // return total number of comments for pictures global $wpdb; $gal_count_req = "SELECT ".$wpdb->comments.".comment_ID FROM ".$wpdb->comments.", $wpdb->anigal_pic WHERE ".$wpdb->comments.".comment_pid_ID=".$wpdb->anigal_pic.".pid ".$this->query("AND.pic")." AND ".$wpdb->comments.".comment_approved='1'"; $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_all_view() { // return total number of picture views global $wpdb; $sum_view = 0; $gal_count_req = "SELECT hits FROM $wpdb->anigal_pic ".$this->query("WHERE"); $gal_count_ret = $wpdb->get_results($gal_count_req); if (!empty($gal_count_ret)){ foreach ($gal_count_ret as $gal_count) { $sum_view = $sum_view + $gal_count->hits; } } return $sum_view; } function c_cat_alb($wp_id) { // return Albums per Category global $wpdb; $gal_count_req = "SELECT alb_id FROM $wpdb->anigal_alb WHERE cat_wp_id=$wp_id ".$this->query("AND"); $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_cat_pic($wp_id) { // return Pictures per Category global $wpdb; $gal_count_req = "SELECT ".$wpdb->anigal_pic.".pid FROM $wpdb->anigal_pic, $wpdb->anigal_alb WHERE ".$wpdb->anigal_alb.".cat_wp_id=$wp_id AND ".$wpdb->anigal_pic.".alb_id = ".$wpdb->anigal_alb.".alb_id ".$this->query("AND.pic"); $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_cat_com($wp_id) { // return Comments per Category global $wpdb; $count = 0; $gal_counta_req = 'SELECT DISTINCT '.$wpdb->anigal_alb.'.alb_id FROM '.$wpdb->anigal_alb.', '.$wpdb->anigal_cat.' WHERE '.$wpdb->anigal_alb.'.cat_wp_id=' . $wp_id." ".$this->query("AND.alb"); $gal_counta_ret = $wpdb->get_results($gal_counta_req); if (!empty($gal_counta_ret)){ foreach ($gal_counta_ret as $gal_counta) { $gal_countb_req = 'SELECT '.$wpdb->anigal_pic.'.pid FROM '.$wpdb->comments.', '.$wpdb->anigal_pic.' WHERE '.$wpdb->anigal_pic.'.alb_id = ' . $gal_counta->alb_id . ' AND '.$wpdb->anigal_pic.'.pid = '.$wpdb->comments.'.comment_pid_ID '.$this->query("AND.pic").' AND '.$wpdb->comments.'.comment_approved="1"'; $gal_countb_ret = $wpdb->get_results($gal_countb_req); $count = $count + $wpdb->num_rows; } } return $count; } function c_cat_view($wp_id) { // return Picture Views per Category global $wpdb; $sum_view = 0; $gal_count_req = "SELECT ".$wpdb->anigal_pic.".hits FROM $wpdb->anigal_pic, $wpdb->anigal_alb WHERE ".$wpdb->anigal_pic.".alb_id = ".$wpdb->anigal_alb.".alb_id ".$this->query("AND.pic")." AND ".$wpdb->anigal_alb.".cat_wp_id=$wp_id"; $gal_count_ret = $wpdb->get_results($gal_count_req); if (!empty($gal_count_ret)){ foreach ($gal_count_ret as $gal_count) { $sum_view = $sum_view + $gal_count->hits; } } return $sum_view; } function c_alb_view($alb_id) { // return Picture Views per Album global $wpdb; $sum_view = 0; $gal_count_req = "SELECT hits FROM $wpdb->anigal_pic WHERE alb_id=$alb_id ".$this->query("AND"); $gal_count_ret = $wpdb->get_results($gal_count_req); if (!empty($gal_count_ret)){ foreach ($gal_count_ret as $gal_count) { $sum_view = $sum_view + $gal_count->hits; } } return $sum_view; } function c_alb_pic($alb_id) { // return Pictures per Album global $wpdb; $gal_count_req = "SELECT pid FROM $wpdb->anigal_pic WHERE alb_id=$alb_id ".$this->query("AND"); $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_alb_com($alb_id) { // return Comments per Album global $wpdb; $gal_count_req = "SELECT ".$wpdb->anigal_pic.".pid FROM ".$wpdb->comments.", ".$wpdb->anigal_pic." WHERE ".$wpdb->anigal_pic.".alb_id = $alb_id AND ".$wpdb->anigal_pic.".pid = ".$wpdb->comments.".comment_pid_ID ".$this->query("AND.pic")." AND ".$wpdb->comments.".comment_approved='1'"; $gal_count_ret = $wpdb->get_results($gal_count_req); return $wpdb->num_rows; } function c_pic_com($pic_id) { // return Comments Count for specific Picture global $wpdb; $gal_give_req = "SELECT comment_ID FROM $wpdb->comments WHERE comment_pid_ID=$pic_id AND comment_approved='1'"; $gal_give_ret = $wpdb->get_results($gal_give_req); return $wpdb->num_rows; } // #### MISC FUNCTIONS ### --------------------------------------------- function updatehits($hits, $pid) { // update hits for a picture global $wpdb; $hits = $hits + 1; $update_hits = $wpdb->query("UPDATE $wpdb->anigal_pic SET hits = '$hits' WHERE pid = $pid"); return $hits; } function nav_cat() { // print navigation for category page global $wpdb; if ($permalink_wpid = get_option('anigal_base-id')) { $gal_title = $wpdb->get_row("SELECT post_title FROM $wpdb->posts WHERE ID=$permalink_wpid"); ?> get_row("SELECT post_title FROM $wpdb->posts WHERE ID=$permalink_wpid"); ?>