" . sprintf(__('Picture %s uploaded.', 'aniga'), $this->fname) . "
"; } else { return "" . sprintf(__('Picture %s could not be uploaded.', 'aniga'), $this->fname) . "
"; } } 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 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 aniga_zip_upload($dir, $file_org, $file_tmp, $db_path) { // upload and unzip archives with php zip library $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)."" . sprintf(__('The file \'%s\' has been un-zipped to:', 'aniga'), basename($file_org)) . " '$db_path'
"; } else $msgf .= "" . __('could not read zip file', 'aniga') . "
"; unlink($file); } else $msgf .= "" . __('could not move zip file to', 'aniga') . " '$db_path'
"; return $msgf; } //GALLERY TEMPLATE CLASSES //######################################################################## class aniga_index { // print gallery index page var $path; var $alg = 'gallery_alignleft'; var $talg = 'gallery_talignleft'; function heading() { include("templates/index.heading.inc.php"); } function loop_html($id, $name, $description) { global $aniga; $meta = $aniga->getchildren_c_all($id, true, true, true); include("templates/index.albums.inc.php"); } function meta() { global $aniga; $meta = $aniga->getchildren_c_all(get_option('aniga_base-id'), true, true, true); include("templates/index.meta.inc.php"); } function loop() { global $aniga; //$aniga->user = $aniga->user(); $this->path = get_option('aniga_dirpath').'00-gfx/album_'; $aniga->getchildren(get_option('aniga_base-id'), ' ', false); if ($aniga->child_array) { foreach ($aniga->child_array as $i => $val) { $this->loop_html($i, $val['name'], $val['desc']); if ('gallery_alignleft' == $this->alg) { $this->alg = 'gallery_alignright'; $this->talg = 'gallery_talignright'; } else { $this->alg = 'gallery_alignleft'; $this->talg = 'gallery_talignleft'; } } } else echo '" . __('WARNING: your absolute path must end with \'/\' !', 'aniga') . "
"; else { if ( is_dir( get_option('aniga_abspath') ) ) { if ( !is_writable( get_option('aniga_abspath') ) ) $msg .= "" . __('WARNING: your Gallery Directory is not writeable!', 'aniga') . "
"; if ( !is_dir( get_option('aniga_abspath')."00-gfx" ) ) $msg .= "" . __('WARNING: your \'00-gfx\' Directory does not exist!', 'aniga') . "
"; elseif ( !is_writable( get_option('aniga_abspath')."00-gfx" ) ) $msg .= "" . __('WARNING: your \'00-gfx\' Directory is not writeable!', 'aniga') . "
"; if ( !is_dir( get_option('aniga_abspath')."00-single" ) ) $msg .= "" . __('WARNING: your \'00-single\' Directory does not exist!', 'aniga') . "
"; elseif ( !is_writable( get_option('aniga_abspath')."00-single" ) ) $msg .= "" . __('WARNING: your \'00-single\' Directory is not writeable!', 'aniga') . "
"; } else $msg .= "" . __('WARNING: your Gallery Directory does not exist or your Settings are incorrect!', 'aniga') . "
"; } if (substr( get_option('aniga_dirpath'), -1) != '/') $msg .= "" . __('WARNING: your http url must end with \'/\' !', 'aniga') . "
"; return $msg; } // #### RETURN DATA FUNCTIONS ### -------------------------------------- function getparents($id, $allparents = true) { global $wpdb; $base_id = get_option('aniga_base-id'); //needs tweaking! $rel_req = "SELECT {$wpdb->aniga_rel}.id, {$wpdb->aniga_rel}.parent_id, {$wpdb->aniga_alb}.name, {$wpdb->aniga_alb}.desc, {$wpdb->aniga_alb}.level, {$wpdb->aniga_alb}.order FROM $wpdb->aniga_rel, $wpdb->aniga_alb WHERE {$wpdb->aniga_rel}.id = {$wpdb->aniga_alb}.id AND {$wpdb->aniga_rel}.id = $id "; $rel_ret = $wpdb->get_results($rel_req); foreach ($rel_ret as $relation) { if ($relation->id != $base_id) { $this->parent_array[$relation->id] = array('id' => $relation->id, 'name' => $relation->name, 'lvl' => $relation->level, 'desc' => $relation->desc); if ($allparents) $this->getparents($relation->parent_id, true); } } } function getchildren($parent_id, $counter, $allchildren = true) { global $wpdb; $base_id = get_option('aniga_base-id'); //needs tweaking! $rel_req = "SELECT {$wpdb->aniga_rel}.id, {$wpdb->aniga_rel}.parent_id, {$wpdb->aniga_alb}.name, {$wpdb->aniga_alb}.desc, {$wpdb->aniga_alb}.level, {$wpdb->aniga_alb}.order FROM $wpdb->aniga_rel, $wpdb->aniga_alb WHERE {$wpdb->aniga_rel}.id = {$wpdb->aniga_alb}.id AND {$wpdb->aniga_rel}.parent_id = $parent_id ".$this->query("AND.alb")." ORDER BY {$wpdb->aniga_alb}.order DESC"; $rel_ret = $wpdb->get_results($rel_req); foreach ($rel_ret as $relation) { if ($parent_id != $relation->id) $this->child_array[$relation->id] = array('name' => $relation->name, 'lvl' => $relation->level, 'sep' => $counter, 'desc' => $relation->desc, 'order' => $relation->order, 'parent_id' => $relation->parent_id); if ($relation->parent_id != $base_id) $this->child_array[$relation->parent_id]['has_child'] = true; $new_counter = '--'.$counter; if ($allchildren) $this->getchildren($relation->id,$new_counter); } //return $gal_cat_ret; } function getchildren_c_pic($parent_id) { global $wpdb; $this->sum_pics = 0; $this->getchildren_query($parent_id); return $this->sum_pics; } function getchildren_c_all($parent_id) { global $wpdb; $this->sum_pics = $this->sum = $this->sum_hits = $this->sum_com = 0; $this->getchildren_query($parent_id, true, true , true); $all_pics = $this->sum_pics + $this->c_alb_pic($parent_id); $all_hits = $this->sum_hits + $this->c_alb_view($parent_id); $all_com = $this->sum_com + $this->c_alb_com($parent_id); $result = array("albums" => $this->sum, "pics" => $this->sum_pics, "all_pics" => $all_pics, "hits" => $this->sum_hits, "all_hits" => $all_hits, "comments" => $this->sum_com, "all_comments" => $all_com); return $result; } function getchildren_query($parent_id, $albs = false, $hits = false, $com = false) { global $wpdb; $rel_req = "SELECT {$wpdb->aniga_rel}.id, {$wpdb->aniga_rel}.parent_id FROM $wpdb->aniga_rel, $wpdb->aniga_alb WHERE {$wpdb->aniga_rel}.id = {$wpdb->aniga_alb}.id AND {$wpdb->aniga_rel}.parent_id = $parent_id ".$this->query("AND.alb")." ORDER BY {$wpdb->aniga_alb}.order DESC"; $rel_ret = $wpdb->get_results($rel_req); if ($albs) $this->sum = $this->sum + $wpdb->num_rows; foreach ($rel_ret as $relation) { $gal_count_req = "SELECT pid, hits FROM $wpdb->aniga_pic WHERE parent_id = $relation->id ".$this->query("AND"); $gal_count_ret = $wpdb->get_results($gal_count_req); $this->sum_pics = $this->sum_pics + $wpdb->num_rows; if ($hits) { foreach ($gal_count_ret as $pic) { $this->sum_hits = $this->sum_hits + $pic->hits; } } if ($com) { $this->sum_com = $this->sum_com + $this->c_alb_com($relation->id); } $this->getchildren_query($relation->id, $albs, $hits, $com); } } function getchildren_wo_self($parent_id, $counter, $id) { global $wpdb; $rel_req = "SELECT {$wpdb->aniga_rel}.id, {$wpdb->aniga_rel}.parent_id, {$wpdb->aniga_alb}.name, {$wpdb->aniga_alb}.desc, {$wpdb->aniga_alb}.level, {$wpdb->aniga_alb}.order FROM $wpdb->aniga_rel, $wpdb->aniga_alb WHERE {$wpdb->aniga_rel}.id = {$wpdb->aniga_alb}.id AND {$wpdb->aniga_rel}.parent_id = $parent_id ".$this->query("AND.alb")." ORDER BY {$wpdb->aniga_alb}.order DESC"; $rel_ret = $wpdb->get_results($rel_req); foreach ($rel_ret as $relation) { if ($relation->id != $id) { $this->child_array[$relation->id] = array('name' => $relation->name, 'lvl' => $relation->level, 'sep' => $counter, 'desc' => $relation->desc, 'order' => $relation->order, 'parent_id' => $relation->parent_id); $new_counter = '--'.$counter; $this->getchildren_wo_self($relation->id,$new_counter, $id); } } //return $gal_cat_ret; } function getparentalbum($id) { global $wpdb; $rel = $wpdb->get_row("SELECT parent_id FROM $wpdb->aniga_rel WHERE id=$id"); return $rel->parent_id; } function getalbum($id) { //return specific album-information from db global $wpdb; $album = $wpdb->get_row("SELECT * FROM $wpdb->aniga_alb WHERE id = $id"); return $album; } function getfirstpic($alb_id, $order, $sort) { // return specific picture from db global $wpdb; $picture = $wpdb->get_row("SELECT * FROM $wpdb->aniga_pic WHERE parent_id=$alb_id ".$this->query("AND")." ORDER BY $order $sort LIMIT 1"); return $picture; } function getpic($pid) { // return specific picture from db global $wpdb; $picture = $wpdb->get_row("SELECT * FROM $wpdb->aniga_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->aniga_pic WHERE parent_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, $order, $sort) { // return pictures for an album from db global $wpdb; $gal_nav_req = "SELECT * FROM $wpdb->aniga_pic WHERE parent_id=$alb_id ".$this->query("AND")." ORDER BY $order $sort"; $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('aniga_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_alb_view($alb_id) { // return Picture Views per one Album global $wpdb; $sum_view = 0; $gal_count_req = "SELECT hits FROM $wpdb->aniga_pic WHERE parent_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($id) { // return Pictures per one Album global $wpdb; $gal_count_req = "SELECT pid FROM $wpdb->aniga_pic WHERE parent_id=$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 one Album global $wpdb; $gal_count_req = "SELECT ".$wpdb->aniga_pic.".pid FROM ".$wpdb->comments.", ".$wpdb->aniga_pic." WHERE ".$wpdb->aniga_pic.".parent_id = $alb_id AND ".$wpdb->aniga_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->aniga_pic SET hits = '$hits' WHERE pid = $pid"); return $hits; } function nav_thumb($id) { // print navigation for thumbnail and picture page global $wpdb; echo '