" . $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)."" . 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() { ?>| pic_link; ?> |
" . $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"); ?>