Example #1
0
 private function getAlbum()
 {
     Module::dependencies(isset($_POST['albumID'], $_POST['password']));
     $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
     if ($album->getPublic()) {
         # Album public
         if ($album->checkPassword($_POST['password'])) {
             echo json_encode($album->get());
         } else {
             echo 'Warning: Wrong password!';
         }
     } else {
         # Album private
         echo 'Warning: Album private!';
     }
 }
Example #2
0
function checkAlbumParentid($albumname, $id)
{
    global $gallery;
    $album = new Album($gallery, $albumname);
    $oldid = $album->get('parentid');
    if ($oldid !== $id) {
        $album->set('parentid', $id);
        $album->save();
        if (is_null($oldid)) {
            $oldid = '<em>NULL</em>';
        }
        if (is_null($id)) {
            $id = '<em>NULL</em>';
        }
        printf('Fixed album <strong>%1$s</strong>: parentid was %2$s should have been %3$s<br />', $albumname, $oldid, $id);
    }
    $id = $album->id;
    $albums = $album->getSubalbums();
    foreach ($albums as $albumname) {
        checkAlbumParentid($albumname, $id);
    }
}
Example #3
0
mysql_query("SET NAMES 'UTF8'");
$r = json_decode(trim(file_get_contents('php://input')), 1);
$url = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1);
list($url, $params) = explode('?', $url, 2);
$method = $_SERVER['REQUEST_METHOD'];
list($script, $section, $id, $action) = explode('/', $url, 4);
//Находим объект и тип действия
try {
    switch ($section) {
        case 'files':
            //Создаем и инициализируем экземпляр класса для работы с файлами
            $sql = new Sql('fotorama');
            $album = new Album($_REQUEST, array('tableName' => 'fotorama', 'files' => array(array('field' => 'full', 'dir' => 'files_original/', 'fit' => true, 'width' => 1200, 'height' => 1200, 'ext' => 'jpg'), array('field' => 'img', 'dir' => 'files_image/', 'fit' => 'contain', 'width' => 800, 'height' => 800, 'ext' => 'jpg'), array('field' => 'thumb', 'dir' => 'files_thumb/', 'fit' => 'cover', 'width' => 160, 'height' => 160, 'ext' => 'png')), 'maxSize' => '4M', 'maxSpace' => '100M', 'maxNumberOfFiles' => 100, 'allowedType' => array('jpeg', 'jpg', 'png', 'gif', 'bmp', 'psd', 'psp', 'ai', 'eps', 'cdr', 'mp3', 'mp4', 'wav', 'aac', 'aiff', 'midi', 'avi', 'mov', 'mpg', 'flv', 'mpa', 'pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'djvu', 'djv', 'bat', 'cmd', 'dll', 'inf', 'ini', 'ocx', 'sys', 'htm', 'html', 'write', 'none', 'zip', 'rar', 'dmg', 'sitx')));
            switch ($method) {
                case 'GET':
                    $res = isset($id) ? $album->getOne($id) : $album->get();
                    break;
                case 'PUT':
                    $res = $album->add();
                    break;
                case 'POST':
                    $res = isset($id) ? $album->update($id, $r) : $sql->savesort($r['sort']);
                    break;
                case 'DELETE':
                    $res = $album->delete($id);
                    break;
            }
            break;
        default:
            throw new Exception('Не получен тип действия', 15);
    }
Example #4
0
 private function getAlbum()
 {
     Module::dependencies(isset($_POST['albumID']));
     $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
     echo json_encode($album->get());
 }
Example #5
0
 function build_autos($items, $data, $user)
 {
     foreach ($items as $index => &$item) {
         if (isset($item['auto'])) {
             if (isset($data['urls'][$item['auto']])) {
                 $item['path'] = $data['urls'][$item['auto']];
             } else {
                 if ($item['auto'] === 'set') {
                     $item['path'] = '';
                 }
             }
             if ($item['auto'] === 'profile') {
                 switch ($item['id']) {
                     case 'twitter':
                         $item['path'] = 'https://twitter.com/' . $user->twitter;
                         break;
                     default:
                         $item['path'] = $user->{$item['id']};
                         if (empty($item['path'])) {
                             unset($items[$index]);
                             continue;
                         }
                         break;
                 }
                 if (!isset($item['label']) || empty($item['label'])) {
                     $item['label'] = ucwords($item['id']) . ($item['id'] === 'google' ? '+' : '');
                 }
             } else {
                 if ($item['auto'] === 'rss') {
                     $item['path'] = '/feed/' . $item['id'] . ($item['id'] === 'essay' ? 's' : '') . '/recent.rss';
                     if (!isset($item['label'])) {
                         $item['label'] = $data['url_data'][$item['id']]['plural'] . ' RSS';
                     }
                 } else {
                     if (preg_match('/s$/', $item['auto']) || $item['auto'] === 'timeline') {
                         if ($item['auto'] === 'timeline' && isset($item['year'])) {
                             $item['path'] .= $item['year'] . '/';
                             if (isset($item['month']) && $item['month'] !== false && $item['month'] !== 'any') {
                                 $m = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
                                 $item['path'] .= $m . '/';
                             }
                         }
                         if (strpos($item['auto'], '_') !== false) {
                             foreach (array('id', 'slug', 'month', 'year', 'day') as $id) {
                                 if ($id === 'month') {
                                     if (!isset($item['month']) || $item['month'] === 'any' || $item['month'] === false) {
                                         $item['month'] = '';
                                     } else {
                                         $item['month'] = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
                                     }
                                 }
                                 if ($id === 'day' && !isset($item['day'])) {
                                     $item['day'] = '';
                                 }
                                 if ($id === 'slug' && !isset($item['slug']) && isset($item['id'])) {
                                     if (strpos($item['auto'], 'tag_') === 0) {
                                         $item['slug'] = $item['id'];
                                     } else {
                                         $c = new Category();
                                         if (is_numeric($item['id'])) {
                                             $c->select('slug')->get_by_id($item['id']);
                                             $item['slug'] = $c->slug;
                                         } else {
                                             $item['slug'] = $item['id'];
                                         }
                                     }
                                 }
                                 if (isset($item[$id])) {
                                     $item['path'] = str_replace(":{$id}", $item[$id], $item['path']);
                                 }
                             }
                         } else {
                             if (!isset($item['label'])) {
                                 $item['label'] = $data['url_data'][$item['auto'] === 'categories' ? 'category' : rtrim($item['auto'], 's')]['plural'];
                             }
                         }
                     } else {
                         if ($item['auto'] === 'home') {
                             if (!isset($item['label'])) {
                                 $item['label'] = $data['url_data']['home'];
                             }
                             $item['path'] = '/home/';
                         } else {
                             if ($item['auto'] === 'album' || $item['auto'] === 'set') {
                                 $a = new Album();
                                 $a->select('id,slug,created_on,title');
                                 if (is_numeric($item['id'])) {
                                     $a->where('id', $item['id']);
                                 } else {
                                     $a->where('slug', $item['id'])->or_where('internal_id', $item['id']);
                                 }
                                 $a->get();
                                 if (!$a->exists()) {
                                     unset($items[$index]);
                                     continue;
                                 }
                                 $item['path'] = str_replace(':id', $a->id, $item['path']);
                                 $item['path'] = str_replace(':slug', $a->slug, $item['path']);
                                 $item['path'] = str_replace(':year', date('Y', $a->created_on), $item['path']);
                                 $item['path'] = str_replace(':month', date('m', $a->created_on), $item['path']);
                                 $item['path'] = str_replace(':day', date('d', $a->created_on), $item['path']);
                                 if (!isset($item['label'])) {
                                     $item['label'] = $a->title;
                                 }
                             } else {
                                 if ($item['auto'] === 'page' || $item['auto'] === 'essay') {
                                     $t = new Text();
                                     $t->select('id,slug,published_on,title');
                                     if (is_numeric($item['id'])) {
                                         $t->where('id', $item['id']);
                                     } else {
                                         $t->where('slug', $item['id']);
                                     }
                                     $t->get();
                                     if (!$t->exists()) {
                                         unset($items[$index]);
                                         continue;
                                     }
                                     $item['path'] = str_replace(':id', $t->id, $item['path']);
                                     $item['path'] = str_replace(':slug', $t->slug, $item['path']);
                                     $item['path'] = str_replace(':year', date('Y', $t->published_on), $item['path']);
                                     $item['path'] = str_replace(':month', date('m', $t->published_on), $item['path']);
                                     $item['path'] = str_replace(':day', date('d', $t->published_on), $item['path']);
                                     if (!isset($item['label'])) {
                                         $item['label'] = $t->title;
                                     }
                                 } else {
                                     if ($item['auto'] === 'content') {
                                         $c = new Content();
                                         $c->select('id,slug,captured_on,title');
                                         if (isset($item['album_id'])) {
                                             $item['path'] = preg_replace('/:(id|slug)/', ':album_$1', $data['urls']['album']) . substr(str_replace(':year/:month/', '', $data['urls']['content']), 1);
                                             $a = new Album();
                                             $a->select('id,slug,created_on,title');
                                             if (is_numeric($item['album_id'])) {
                                                 $a->where('id', $item['album_id']);
                                             } else {
                                                 $a->where('slug', $item['album_id'])->or_where('internal_id', $item['album_id']);
                                             }
                                             $a->get();
                                             if (!$a->exists()) {
                                                 unset($items[$index]);
                                                 continue;
                                             }
                                             $item['path'] = str_replace(':album_id', $a->id, $item['path']);
                                             $item['path'] = str_replace(':album_slug', $a->slug, $item['path']);
                                             $date = $a->created_on;
                                         } else {
                                             $date = $c->captured_on;
                                         }
                                         if (is_numeric($item['id'])) {
                                             $c->where('id', $item['id']);
                                         } else {
                                             $c->where('slug', $item['id'])->or_where('internal_id', $item['id']);
                                         }
                                         $c->get();
                                         if (!$c->exists()) {
                                             unset($items[$index]);
                                             continue;
                                         }
                                         $item['path'] = str_replace(':id', $c->id, $item['path']);
                                         $item['path'] = str_replace(':slug', $c->slug, $item['path']);
                                         $item['path'] = str_replace(':year', date('Y', $date), $item['path']);
                                         $item['path'] = str_replace(':month', date('m', $date), $item['path']);
                                         $item['path'] = str_replace(':day', date('d', $date), $item['path']);
                                         if (!isset($item['label'])) {
                                             $item['label'] = $c->title;
                                         }
                                         if (isset($item['lightbox']) && $item['lightbox']) {
                                             $item['path'] .= 'lightbox/';
                                         }
                                     } else {
                                         if ($item['auto'] === 'tag') {
                                             $item['path'] = str_replace(':slug', $item['id'], $item['path']);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($item['auto'] !== 'profile') {
                 $item['path'] = str_replace(array(':year', ':month'), '', $item['path']);
                 $item['path'] = preg_replace('/[\\(\\)\\?\\:]/', '', $item['path']);
                 $item['path'] = preg_replace('~[/]+~', '/', $item['path']);
             }
         }
     }
     return $items;
 }
/**
 * Gets news articles and images of a gallery to show them together on the news section
 *
 * NOTE: This function does not exclude articles that are password protected via a category
 *
 * @param int $articles_per_page The number of articles to get
 * @param string $mode 	"latestimages-thumbnail"
 *											"latestimages-thumbnail-customcrop"
 *											"latestimages-sizedimage"
 *											"latestalbums-thumbnail"
 *		 									"latestalbums-thumbnail-customcrop"
 *		 									"latestalbums-sizedimage"
 *		 									"latestimagesbyalbum-thumbnail"
 *		 									"latestimagesbyalbum-thumbnail-customcrop"
 *		 									"latestimagesbyalbum-sizedimage"
 *		 									"latestupdatedalbums-thumbnail" (for RSS and getLatestNews() used only)
 *		 									"latestupdatedalbums-thumbnail-customcrop" (for RSS and getLatestNews() used only)
 *		 									"latestupdatedalbums-sizedimage" (for RSS and getLatestNews() used only)
 *	NOTE: The "latestupdatedalbums" variants do NOT support pagination as required on the news loop!
 *
 * @param string $published "published" for published articles,
 * 													"unpublished" for un-published articles,
 * 													"all" for all articles
 * @param string $sortorder 	id, date or mtime, only for latestimages-... modes
 * @param bool $sticky set to true to place "sticky" articles at the front of the list.
 * @return array
 */
function getCombiNews($articles_per_page = '', $mode = '', $published = NULL, $sortorder = '', $sticky = true)
{
    deprecated_function_notify(gettext('Use the Zenpage class method instead.'));
    global $_zp_gallery, $_zp_flash_player;
    processExpired('news');
    if (is_null($published)) {
        if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
            $published = "all";
        } else {
            $published = "published";
        }
    }
    if (empty($mode)) {
        $mode = getOption("zenpage_combinews_mode");
    }
    if ($published == "published") {
        $show = " WHERE `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
        $imagesshow = " AND images.show = 1 ";
    } else {
        $show = "";
        $imagesshow = "";
    }
    $passwordcheck = "";
    if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
        $albumWhere = "";
        $passwordcheck = "";
    } else {
        $albumscheck = query_full_array("SELECT * FROM " . prefix('albums') . " ORDER BY title");
        foreach ($albumscheck as $albumcheck) {
            if (!checkAlbumPassword($albumcheck['folder'])) {
                $albumpasswordcheck = " AND albums.id != " . $albumcheck['id'];
                $passwordcheck = $passwordcheck . $albumpasswordcheck;
            }
        }
        $albumWhere = "AND albums.show=1" . $passwordcheck;
    }
    $limit = getLimitAndOffset($articles_per_page);
    if (empty($sortorder)) {
        $combinews_sortorder = getOption("zenpage_combinews_sortorder");
    } else {
        $combinews_sortorder = $sortorder;
    }
    $stickyorder = '';
    if ($sticky) {
        $stickyorder = 'sticky DESC,';
    }
    $type3 = query("SET @type3:='0'");
    switch ($mode) {
        case "latestimages-thumbnail":
        case "latestimages-thumbnail-customcrop":
        case "latestimages-sizedimage":
            $sortorder = "images." . $combinews_sortorder;
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='images'");
            switch ($combinews_sortorder) {
                case 'id':
                case 'date':
                    $imagequery = "(SELECT albums.folder, images.filename, images.date, @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
                case 'mtime':
                    $imagequery = "(SELECT albums.folder, images.filename, FROM_UNIXTIME(images.mtime), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            break;
        case "latestalbums-thumbnail":
        case "latestalbums-thumbnail-customcrop":
        case "latestalbums-sizedimage":
            $sortorder = $combinews_sortorder;
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='albums'");
            switch ($combinews_sortorder) {
                case 'id':
                case 'date':
                    $albumquery = "(SELECT albums.folder, albums.title, albums.date, @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                    break;
                case 'mtime':
                    $albumquery = "(SELECT albums.folder, albums.title, FROM_UNIXTIME(albums.mtime), @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $albumquery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            break;
        case "latestimagesbyalbum-thumbnail":
        case "latestimagesbyalbum-thumbnail-customcrop":
        case "latestimagesbyalbum-sizedimage":
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='albums'");
            if (empty($combinews_sortorder) || $combinews_sortorder != "date" || $combinews_sortorder != "mtime") {
                $combinews_sortorder = "date";
            }
            $combinews_sortorder = "date";
            $sortorder = "images." . $combinews_sortorder;
            switch ($combinews_sortorder) {
                case "date":
                    $imagequery = "(SELECT DISTINCT DATE_FORMAT(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.`date`,'%Y-%m-%d'), @type2 FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
                case "mtime":
                    $imagequery = "(SELECT DISTINCT FROM_UNIXTIME(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.`mtime`,'%Y-%m-%d'), @type2 FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER By date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            //echo "<pre>"; print_r($result); echo "</pre>";
            //$result = "";
            break;
        case "latestupdatedalbums-thumbnail":
        case "latestupdatedalbums-thumbnail-customcrop":
        case "latestupdatedalbums-sizedimage":
            $latest = getNewsArticles($articles_per_page, '', NULL, true);
            $counter = '';
            foreach ($latest as $news) {
                $article = new ZenpageNews($news['titlelink']);
                if ($article->checkAccess($hint, $show)) {
                    $counter++;
                    $latestnews[$counter] = array("albumname" => $article->getTitle(), "titlelink" => $article->getTitlelink(), "date" => $article->getDateTime(), "type" => "news");
                }
            }
            $albums = getAlbumStatistic($articles_per_page, "latestupdated");
            $latestalbums = array();
            $counter = "";
            foreach ($albums as $album) {
                $counter++;
                $tempalbum = new Album($_zp_gallery, $album['folder']);
                $tempalbumthumb = $tempalbum->getAlbumThumbImage();
                $timestamp = $tempalbum->get('mtime');
                if ($timestamp == 0) {
                    $albumdate = $tempalbum->getDateTime();
                } else {
                    $albumdate = strftime('%Y-%m-%d %H:%M:%S', $timestamp);
                }
                $latestalbums[$counter] = array("albumname" => $tempalbum->getFolder(), "titlelink" => $tempalbum->getTitle(), "date" => $albumdate, "type" => 'albums');
            }
            //$latestalbums = array_merge($latestalbums, $item);
            $latest = array_merge($latestnews, $latestalbums);
            $result = sortMultiArray($latest, "date", true);
            if (count($result) > $articles_per_page) {
                $result = array_slice($result, 0, 10);
            }
            break;
    }
    //$result = "";
    return $result;
}
/**
 * Prints a table with a bar graph of the values.
 *
 * @param string $sortorder "popular", "mostrated","toprated","mostcommented" or - only if $type = "albums"! - "mostimages"
 * @param string_type $type "albums", "images", "pages", "news", "tags"
 * @param int $limit Number of entries to show
 */
function printBarGraph($sortorder = "mostimages", $type = "albums", $from_number = 0, $to_number = 10)
{
    global $gallery, $webpath;
    $limit = $from_number . "," . $to_number;
    $bargraphmaxsize = 400;
    switch ($type) {
        case "albums":
            $typename = gettext("Albums");
            $dbquery = "SELECT * FROM " . prefix('albums');
            break;
        case "images":
            $typename = gettext("Images");
            $dbquery = "SELECT * FROM " . prefix('images');
            break;
        case "pages":
            $typename = gettext("Pages");
            $dbquery = "SELECT * FROM " . prefix('pages');
            break;
        case "news":
            $typename = gettext("News Articles");
            $dbquery = "SELECT * FROM " . prefix('news');
            break;
        case "newscategories":
            $typename = gettext("News Categories");
            $dbquery = "SELECT * FROM " . prefix('news_categories');
            break;
        case "tags":
            $typename = gettext("Tags");
            break;
        case "rss":
            $typename = gettext("rss");
            break;
    }
    switch ($sortorder) {
        case "mostused":
            switch ($type) {
                case "tags":
                    $itemssorted = query_full_array("SELECT tagobj.tagid, count(*) as tagcount, tags.* FROM " . prefix('obj_to_tag') . " AS tagobj, " . prefix('tags') . " AS tags WHERE tags.id=tagobj.tagid GROUP BY tags.id ORDER BY tagcount DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['tagcount'];
                    }
                    break;
                case "newscategories":
                    $itemssorted = query_full_array("SELECT news2cat.cat_id, count(*) as catcount, cats.* FROM " . prefix('news2cat') . " AS news2cat, " . prefix('news_categories') . " AS cats WHERE cats.id=news2cat.cat_id GROUP BY news2cat.cat_id ORDER BY catcount DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['catcount'];
                    }
                    break;
            }
            $headline = $typename . " - " . gettext("most used");
            break;
        case "popular":
            switch ($type) {
                case 'rss':
                    $itemssorted = query_full_array("SELECT `type`,`aux`, `data` FROM " . prefix('plugin_storage') . " WHERE `type` = 'rsshitcounter' ORDER BY CONVERT(data,UNSIGNED) DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['data'];
                    }
                    break;
                default:
                    $itemssorted = query_full_array($dbquery . " ORDER BY hitcounter DESC LIMIT " . $limit);
                    if (empty($itemssorted)) {
                        $maxvalue = 0;
                    } else {
                        $maxvalue = $itemssorted[0]['hitcounter'];
                    }
                    break;
            }
            $headline = $typename . " - " . gettext("most viewed");
            break;
        case "mostrated":
            $itemssorted = query_full_array($dbquery . " ORDER BY total_votes DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['total_votes'];
            }
            $headline = $typename . " - " . gettext("most rated");
            break;
        case "toprated":
            $itemssorted = query_full_array($dbquery . " ORDER BY (total_value/total_votes) DESC LIMIT {$limit}");
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                if ($itemssorted[0]['total_votes'] != 0) {
                    $maxvalue = $itemssorted[0]['total_value'] / $itemssorted[0]['total_votes'];
                } else {
                    $maxvalue = 0;
                }
            }
            $headline = $typename . " - " . gettext("top rated");
            break;
        case "mostcommented":
            switch ($type) {
                case "albums":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, albums.* FROM " . prefix('comments') . " AS comments, " . prefix('albums') . " AS albums WHERE albums.id=comments.ownerid AND type = 'albums' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "images":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, images.* FROM " . prefix('comments') . " AS comments, " . prefix('images') . " AS images WHERE images.id=comments.ownerid AND type = 'images' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "pages":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, pages.* FROM " . prefix('comments') . " AS comments, " . prefix('pages') . " AS pages WHERE pages.id=comments.ownerid AND type = 'page' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "news":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, news.* FROM " . prefix('comments') . " AS comments, " . prefix('news') . " AS news WHERE news.id=comments.ownerid AND type = 'news' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
            }
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['commentcount'];
            }
            $headline = $typename . " - " . gettext("most commented");
            break;
        case "mostimages":
            $itemssorted = query_full_array("SELECT images.albumid, count(*) as imagenumber, albums.* FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums WHERE albums.id=images.albumid GROUP BY images.albumid ORDER BY imagenumber DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['imagenumber'];
            }
            $headline = $typename . " - " . gettext("most images");
            break;
        case "latest":
            switch ($type) {
                case "albums":
                    $allalbums = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $albums = array();
                    foreach ($allalbums as $album) {
                        $albumobj = new Album($gallery, $album['folder']);
                        $albumentry = array("id" => $albumobj->get('id'), "title" => $albumobj->getTitle(), "folder" => $albumobj->name, "imagenumber" => $albumobj->getNumImages(), "show" => $albumobj->get("show"));
                        array_unshift($albums, $albumentry);
                    }
                    $maxvalue = 1;
                    $itemssorted = sortMultiArray($albums, 'id', true, true);
                    // The items are originally sorted by id;
                    $headline = $typename . " - " . gettext("latest");
                    break;
                case "images":
                    $itemssorted = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $barsize = 0;
                    $maxvalue = 1;
                    $headline = $typename . " - " . gettext("latest");
                    break;
            }
            break;
        case "latestupdated":
            $albums = getAlbumStatistic($to_number, 'latestupdated', '');
            $maxvalue = 1;
            if (!empty($albums)) {
                foreach ($albums as $key => $album) {
                    $albumobj = new Album($gallery, $album['folder']);
                    $albums[$key]['imagenumber'] = $albumobj->getNumImages();
                }
            }
            $itemssorted = $albums;
            $headline = $typename . " - " . gettext("latest updated");
            break;
    }
    if ($maxvalue == 0 || empty($itemssorted)) {
        $maxvalue = 1;
        $no_hitcount_enabled_msg = '';
        if ($sortorder == 'popular' && $type != 'rss' && !getOption('zp_plugin_hitcounter')) {
            $no_hitcount_enabled_msg = gettext("(The hitcounter plugin is not enabled.)");
        }
        $no_statistic_message = "<tr><td><em>" . gettext("No statistic available.") . $no_hitcount_enabled_msg . "</em></td><td></td><td></td><td></td></tr>";
    } else {
        $no_statistic_message = "";
        if ($sortorder == 'popular' && $type != 'rss' && !getOption('zp_plugin_hitcounter')) {
            $no_statistic_message = "<tr><td colspan='4'><em>" . gettext("Note: The hitcounter plugin is not enabled, therefore any existing values will not get updated.") . "</em></td><td></td><td></td><td></td></tr>";
        }
    }
    if ($from_number <= 1) {
        $count = 1;
    } else {
        $count = $from_number;
    }
    $countlines = 0;
    echo "<table class='bordered'>";
    echo "<tr><th colspan='4'><strong>" . $headline . "</strong>";
    if (isset($_GET['stats'])) {
        echo "<a href='gallery_statistics.php'> | " . gettext("Back to the top 10 lists") . "</a>";
    } else {
        if (empty($no_statistic_message)) {
            echo "<a href='gallery_statistics.php?stats=" . $sortorder . "&amp;type=" . $type . "'> | " . gettext("View more") . "</a>";
        }
        echo "<a href='#top'> | " . gettext("top") . "</a>";
    }
    echo "</th></tr>";
    echo $no_statistic_message;
    foreach ($itemssorted as $item) {
        if (array_key_exists("filename", $item)) {
            $name = $item['filename'];
        } else {
            if (array_key_exists("folder", $item)) {
                $name = $item['folder'];
            } else {
                if ($type === "pages" or $type === "news") {
                    $name = $item['titlelink'];
                } else {
                    if ($type === "newscategories") {
                        $name = $item['title'];
                    } else {
                        if ($type === "tags") {
                            $name = "";
                        }
                    }
                }
            }
        }
        switch ($sortorder) {
            case "popular":
                switch ($type) {
                    case 'rss':
                        $barsize = round($item['data'] / $maxvalue * $bargraphmaxsize);
                        $value = $item['data'];
                        break;
                    default:
                        $barsize = round($item['hitcounter'] / $maxvalue * $bargraphmaxsize);
                        $value = $item['hitcounter'];
                        break;
                }
                break;
            case "mostrated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_votes'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['total_votes'];
                break;
            case "toprated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_value'] / $item['total_votes'] / $maxvalue * $bargraphmaxsize);
                    $value = round($item['total_value'] / $item['total_votes']);
                } else {
                    $barsize = 0;
                    $value = 0;
                }
                break;
            case "mostcommented":
                if ($maxvalue != 0) {
                    $barsize = round($item['commentcount'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['commentcount'];
                break;
            case "mostimages":
                $barsize = round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = $item['imagenumber'];
                break;
            case "latest":
                switch ($type) {
                    case "albums":
                        $barsize = 0;
                        //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                        $value = sprintf(gettext("%s images"), $item['imagenumber']);
                        break;
                    case "images":
                        $barsize = 0;
                        $value = "";
                        break;
                }
                break;
            case "latestupdated":
                $barsize = 0;
                //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = sprintf(gettext("%s images"), $item['imagenumber']);
                break;
            case "mostused":
                switch ($type) {
                    case "tags":
                        if ($maxvalue != 0) {
                            $barsize = round($item['tagcount'] / $maxvalue * $bargraphmaxsize);
                        } else {
                            $barsize = 0;
                        }
                        $value = $item['tagcount'];
                        break;
                    case "newscategories":
                        if ($maxvalue != 0) {
                            $barsize = round($item['catcount'] / $maxvalue * $bargraphmaxsize);
                        } else {
                            $barsize = 0;
                        }
                        $value = $item['catcount'];
                        break;
                }
                break;
        }
        // counter to have a gray background of every second line
        if ($countlines === 1) {
            $style = " style='background-color: #f4f4f4'";
            // a little ugly but the already attached class for the table is so easiest overriden...
            $countlines = 0;
        } else {
            $style = "";
            $countlines++;
        }
        switch ($type) {
            case "albums":
                $editurl = $webpath . "/admin-edit.php?page=edit&amp;album=" . $name;
                $viewurl = WEBPATH . "/index.php?album=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "images":
                $getalbumfolder = query_single_row("SELECT title, folder, `show` from " . prefix("albums") . " WHERE id = " . $item['albumid']);
                if ($sortorder === "latest") {
                    $value = "<span";
                    if ($getalbumfolder['show'] != "1") {
                        $value = $value . " class='unpublished_item'";
                    }
                    $value = $value . ">" . get_language_string($getalbumfolder['title']) . "</span> (" . $getalbumfolder['folder'] . ")";
                }
                $editurl = $webpath . "/admin-edit.php?page=edit&amp;album=" . $getalbumfolder['folder'] . "&amp;image=" . $item['filename'] . "&amp;tab=imageinfo#IT";
                $viewurl = WEBPATH . "/index.php?album=" . $getalbumfolder['folder'] . "&amp;image=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "pages":
                $editurl = $webpath . '/' . PLUGIN_FOLDER . "/zenpage/admin-edit.php?page&amp;titlelink=" . $name;
                $viewurl = WEBPATH . "/index.php?p=pages&amp;title=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "news":
                $editurl = $webpath . '/' . PLUGIN_FOLDER . "/zenpage/admin-edit.php?news&amp;titlelink=" . $name;
                $viewurl = WEBPATH . "/index.php?p=news&amp;title=" . $name;
                $title = get_language_string($item['title']);
                break;
            case "newscategories":
                $editurl = $webpath . '/' . PLUGIN_FOLDER . "/zenpage/admin-categories.php?edit&amp;id=" . $item['id'];
                $viewurl = WEBPATH . "/index.php?p=news&amp;category=" . $name;
                $title = get_language_string($item['titlelink']);
                break;
            case "tags":
                $editurl = $webpath . "/admin-tags.php";
                $viewurl = WEBPATH . "/index.php?p=search&amp;searchfields=tags&amp;words=" . $item['name'];
                $title = get_language_string($item['name']);
                break;
            case "rss":
                $editurl = '';
                $viewurl = WEBPATH . "/index.php?" . html_encode(strrchr($item['aux'], 'rss'));
                $title = html_encode(strrchr($item['aux'], 'rss'));
                break;
        }
        if (isset($item['show'])) {
            if ($item['show'] != "1") {
                $show = " class='unpublished_item'";
            } else {
                $show = "";
            }
        } else {
            $show = "";
        }
        if ($value != 0 or $sortorder === "latest") {
            if (empty($name)) {
                $name = "";
            } else {
                $name = "(" . $name . ")";
            }
            ?>
		<tr class="statistic_wrapper">
		<td class="statistic_counter" <?php 
            echo $style;
            ?>
>
		<?php 
            echo $count;
            ?>
		</td>
		<td class="statistic_title" <?php 
            echo $style;
            ?>
>
		<strong<?php 
            echo $show;
            ?>
><?php 
            echo $title;
            ?>
</strong> <?php 
            echo $name;
            ?>
		</td>
		<td class="statistic_graphwrap" <?php 
            echo $style;
            ?>
>
		<div class="statistic_bargraph" style="width: <?php 
            echo $barsize;
            ?>
px"></div>
		<div class="statistic_value"><?php 
            echo $value;
            ?>
</div>
		</td>
		<td class="statistic_link" <?php 
            echo $style;
            ?>
>
		<?php 
            switch ($type) {
                case 'rss':
                    echo "<a href='" . $viewurl . "' title='" . $name . "'>" . gettext("View") . "</a></td>";
                    break;
                default:
                    echo "<a href='" . $editurl . "' title='" . $name . "'>" . gettext("Edit") . "</a> | <a href='" . $viewurl . "' title='" . $name . "'>" . gettext("View") . "</a></td>";
                    break;
            }
            echo "</tr>";
            $count++;
            if ($count === $limit) {
                break;
            }
        }
    }
    // foreach end
    echo "</table>";
}
				$('.album_'+id+'_'+what).attr('checked','checked');
			}
			// ]]> -->
		</script>
		<form name="publish" action="" method="post"><?php 
        echo gettext('Images:');
        ?>
		<?php 
        XSRFToken('schedule_content');
        ?>
		<input type="hidden" name="publish_images" value="true" />
		<ul class="scheduleimagechecklist">
		<?php 
        foreach ($publish_images_list as $key => $imagelist) {
            $album = new Album($gallery, $key);
            $albumid = $album->get('id');
            $imagelist = array_flip($imagelist);
            natcasesort($imagelist);
            $imagelist = array_flip($imagelist);
            ?>
			<li>
				<p class="scheduleimagechecklisthead">
					<a href="javascript:publishAll(<?php 
            echo $albumid;
            ?>
,'p');" title="<?php 
            echo gettext('Set all to be published');
            ?>
">
						<img src="../images/pass.png" style="border: 0px;" alt="publish all" />
					</a>
/**
 * adds (sub)albums to menu base with their gallery sorting order intact
 *
 * @param string $menuset chosen menu set
 * @param object $gallery a gallery object
 * @param int $id table id of the parent.
 * @param string $link folder name of the album
 * @param string $sort xxx-xxx-xxx style sort order for album
 */
function addSubalbumMenus($menuset, $gallery, $id, $link, $sort)
{
    $album = new Album($gallery, $link);
    $show = $album->get('show');
    $title = $album->getTitle();
    $sql = "INSERT INTO " . prefix('menu') . " (`link`,`type`,`title`,`show`,`menuset`,`sort_order`, `parentid`) " . 'VALUES (' . db_quote($link) . ', "album",' . db_quote($album->name) . ', ' . $show . ',' . db_quote($menuset) . ',' . db_quote($sort) . ',' . $id . ')';
    $result = query($sql, false);
    if ($result) {
        $id = db_insert_id();
    } else {
        $result = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="album" AND `link`=' . db_quote($link));
        $id = $result['id'];
    }
    if (!$album->isDynamic()) {
        $albums = $album->getAlbums();
        foreach ($albums as $key => $link) {
            addSubalbumMenus($menuset, $gallery, $id, $link, $sort . '-' . sprintf('%03u', $key));
        }
    }
}
/**
 * Prints a table with a bar graph of the values.
 *
 * @param string $sortorder "popular", "mostrated","toprated","mostcommented" or - only if $type = "albums"! - "mostimages" 
 * @param string_type $type "albums" or "images"
 * @param int $limit Number of entries to show
 */
function printBarGraph($sortorder = "mostimages", $type = "albums", $from_number = 0, $to_number = 10)
{
    global $gallery, $webpath;
    $limit = $from_number . "," . $to_number;
    $bargraphmaxsize = 400;
    switch ($type) {
        case "albums":
            $typename = gettext("Albums");
            $dbquery = "SELECT id, title, folder, hitcounter, total_votes, total_value, `show` FROM " . prefix('albums');
            break;
        case "images":
            $typename = gettext("Images");
            $dbquery = "SELECT id, title, filename, albumid, hitcounter, total_votes, total_value, `show` FROM " . prefix('images');
            break;
    }
    switch ($sortorder) {
        case "popular":
            $itemssorted = query_full_array($dbquery . " ORDER BY hitcounter DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['hitcounter'];
            }
            $headline = $typename . " - " . gettext("most viewed");
            break;
        case "mostrated":
            $itemssorted = query_full_array($dbquery . " ORDER BY total_votes DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['total_votes'];
            }
            $headline = $typename . " - " . gettext("most rated");
            break;
        case "toprated":
            switch ($type) {
                case "albums":
                    $itemssorted = query_full_array("SELECT * FROM " . prefix('albums') . " ORDER BY (total_value/total_votes) DESC LIMIT {$limit}");
                    break;
                case "images":
                    $itemssorted = query_full_array("SELECT * FROM " . prefix('images') . " ORDER BY (total_value/total_votes) DESC LIMIT {$limit}");
                    break;
            }
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                if ($itemssorted[0]['total_votes'] != 0) {
                    $maxvalue = $itemssorted[0]['total_value'] / $itemssorted[0]['total_votes'];
                } else {
                    $maxvalue = 0;
                }
            }
            $headline = $typename . " - " . gettext("top rated");
            break;
        case "mostcommented":
            switch ($type) {
                case "albums":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, albums.* FROM " . prefix('comments') . " AS comments, " . prefix('albums') . " AS albums WHERE albums.id=comments.ownerid AND type = 'albums' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
                case "images":
                    $itemssorted = query_full_array("SELECT comments.ownerid, count(*) as commentcount, images.* FROM " . prefix('comments') . " AS comments, " . prefix('images') . " AS images WHERE images.id=comments.ownerid AND type = 'images' GROUP BY comments.ownerid ORDER BY commentcount DESC LIMIT " . $limit);
                    break;
            }
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['commentcount'];
            }
            $headline = $typename . " - " . gettext("most commented");
            break;
        case "mostimages":
            $itemssorted = query_full_array("SELECT images.albumid, count(*) as imagenumber, albums.* FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums WHERE albums.id=images.albumid GROUP BY images.albumid ORDER BY imagenumber DESC LIMIT " . $limit);
            if (empty($itemssorted)) {
                $maxvalue = 0;
            } else {
                $maxvalue = $itemssorted[0]['imagenumber'];
            }
            $headline = $typename . " - " . gettext("most images");
            break;
        case "latest":
            switch ($type) {
                case "albums":
                    $allalbums = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $albums = array();
                    foreach ($allalbums as $album) {
                        $albumobj = new Album($gallery, $album['folder']);
                        $albumentry = array("id" => $albumobj->get('id'), "title" => $albumobj->getTitle(), "folder" => $albumobj->name, "imagenumber" => $albumobj->getNumImages(), "show" => $albumobj->get("show"));
                        array_unshift($albums, $albumentry);
                    }
                    $maxvalue = 0;
                    if (empty($albums)) {
                        $itemssorted = array();
                    } else {
                        foreach ($albums as $entry) {
                            if (array_key_exists('imagenumber', $entry)) {
                                $v = $entry['imagenumber'];
                                if ($v > $maxvalue) {
                                    $maxvalue = $v;
                                }
                            }
                        }
                        $itemssorted = $albums;
                        // The items are originally sorted by id;
                    }
                    $headline = $typename . " - " . gettext("latest");
                    break;
                case "images":
                    $itemssorted = query_full_array($dbquery . " ORDER BY id DESC LIMIT " . $limit);
                    $barsize = 0;
                    $maxvalue = 1;
                    $headline = $typename . " - " . gettext("latest");
                    break;
            }
            break;
        case "latestupdated":
            // part taken from the image_albums_statistics - could probably be optimized regarding queries...
            // get all albums
            $allalbums = query_full_array("SELECT id, title, folder, `show` FROM " . prefix('albums'));
            $albums = array();
            $latestimages = array();
            foreach ($allalbums as $album) {
                $albumobj = new Album($gallery, $album['folder']);
                $albumentry = array("id" => $albumobj->get('id'), "title" => $albumobj->getTitle(), "folder" => $albumobj->name, "imagenumber" => $albumobj->getNumImages(), "show" => $albumobj->get("show"));
                array_unshift($albums, $albumentry);
            }
            // get latest images of each album
            $count = 0;
            foreach ($albums as $album) {
                $count++;
                $image = query_single_row("SELECT id, albumid, mtime FROM " . prefix('images') . " WHERE albumid = " . $album['id'] . " ORDER BY id DESC LIMIT 1");
                if (is_array($image)) {
                    array_push($latestimages, $image);
                }
                if ($count === $to_number) {
                    break;
                }
            }
            // sort latest image by mtime
            $latestimages = sortMultiArray($latestimages, "mtime", "desc", false, false);
            //echo "<pre>"; print_r($albums); echo "</pre>";
            $itemssorted = array();
            $count = 0;
            foreach ($latestimages as $latestimage) {
                $count++;
                foreach ($allalbums as $album) {
                    if ($album['id'] === $latestimage['albumid']) {
                        array_push($albums, $album);
                    }
                }
                if ($count === $to_number) {
                    break;
                }
            }
            if ($to_number < 1) {
                $stopelement = 1;
            } else {
                $stopelement = $to_number;
            }
            $albums = array_slice($albums, 0, $stopelement);
            // clear unnessesary items fron array
            $maxvalue = 0;
            if (empty($albums)) {
                $itemssorted = array();
            } else {
                foreach ($albums as $key => $entry) {
                    if (array_key_exists('imagenumber', $entry)) {
                        $v = $entry['imagenumber'];
                        if ($v > $maxvalue) {
                            $maxvalue = $v;
                        }
                    } else {
                        unset($albums[$key]);
                        // if it has no imagenumber it must not be a valid entry!
                    }
                }
                $itemssorted = $albums;
                // The items are originally sorted by id;
            }
            $headline = $typename . " - " . gettext("latest updated");
            //echo "<pre>"; print_r($albums); echo "</pre>";
            break;
    }
    if ($maxvalue == 0 or empty($itemssorted)) {
        $maxvalue = 1;
        $no_statistic_message = "<tr><td><em>" . gettext("No statistic available") . "</em></td><td></td><td></td><td></td></tr>";
    } else {
        $no_statistic_message = "";
    }
    if ($from_number <= 1) {
        $count = 1;
    } else {
        $count = $from_number;
    }
    $countlines = 0;
    echo "<table class='bordered'>";
    echo "<tr><th colspan='4'><strong>" . $headline . "</strong>";
    if (isset($_GET['stats'])) {
        echo "<a href='gallery_statistics.php'> | " . gettext("Back to the top 10 lists") . "</a>";
    } else {
        if (empty($no_statistic_message)) {
            echo "<a href='gallery_statistics.php?stats=" . $sortorder . "&amp;type=" . $type . "'> | " . gettext("View more") . "</a>";
        }
        echo "<a href='#top'> | " . gettext("top") . "</a>";
    }
    echo "</th></tr>";
    echo $no_statistic_message;
    foreach ($itemssorted as $item) {
        if (array_key_exists("filename", $item)) {
            $name = $item['filename'];
        } else {
            if (array_key_exists("folder", $item)) {
                $name = $item['folder'];
            }
        }
        switch ($sortorder) {
            case "popular":
                $barsize = round($item['hitcounter'] / $maxvalue * $bargraphmaxsize);
                $value = $item['hitcounter'];
                break;
            case "mostrated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_votes'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['total_votes'];
                break;
            case "toprated":
                if ($item['total_votes'] != 0) {
                    $barsize = round($item['total_value'] / $item['total_votes'] / $maxvalue * $bargraphmaxsize);
                    $value = round($item['total_value'] / $item['total_votes']);
                } else {
                    $barsize = 0;
                    $value = 0;
                }
                break;
            case "mostcommented":
                if ($maxvalue != 0) {
                    $barsize = round($item['commentcount'] / $maxvalue * $bargraphmaxsize);
                } else {
                    $barsize = 0;
                }
                $value = $item['commentcount'];
                break;
            case "mostimages":
                $barsize = round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = $item['imagenumber'];
                break;
            case "latest":
                switch ($type) {
                    case "albums":
                        $barsize = 0;
                        //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                        $value = sprintf(gettext("%s images"), $item['imagenumber']);
                        break;
                    case "images":
                        $barsize = 0;
                        $value = "";
                        break;
                }
                break;
            case "latestupdated":
                $barsize = 0;
                //round($item['imagenumber'] / $maxvalue * $bargraphmaxsize);
                $value = sprintf(gettext("%s images"), $item['imagenumber']);
                break;
        }
        // counter to have a gray background of every second line
        if ($countlines === 1) {
            $style = "style='background-color: #f4f4f4'";
            // a little ugly but the already attached class for the table is so easiest overriden...
            $countlines = 0;
        } else {
            $style = "";
            $countlines++;
        }
        switch ($type) {
            case "albums":
                $editurl = $webpath . "/admin.php?page=edit&amp;album=" . $name;
                $viewurl = WEBPATH . "/index.php?album=" . $name;
                break;
            case "images":
                $getalbumfolder = query_single_row("SELECT title, folder, `show` from " . prefix("albums") . " WHERE id = " . $item['albumid']);
                if ($sortorder === "latest") {
                    $value = "<span";
                    if ($getalbumfolder['show'] != "1") {
                        $value = $value . " class='unpublished_item'";
                    }
                    $value = $value . ">" . get_language_string($getalbumfolder['title']) . "</span> (" . $getalbumfolder['folder'] . ")";
                }
                $editurl = $webpath . "/admin.php?page=edit&amp;album=" . $getalbumfolder['folder'] . "&amp;image=" . $item['filename'] . "&amp;tab=imageinfo#IT";
                $viewurl = WEBPATH . "/index.php?album=" . $getalbumfolder['folder'] . "&amp;image=" . $name;
                break;
        }
        if ($item['show'] != "1") {
            $show = " class='unpublished_item'";
        } else {
            $show = "";
        }
        if ($value != 0 or $sortorder === "latest") {
            ?>
		<tr class="statistic_wrapper">
		<td class="statistic_counter" <?php 
            echo $style;
            ?>
><?php 
            echo $count;
            ?>
</td>
		<td class="statistic_title" <?php 
            echo $style;
            ?>
><strong<?php 
            echo $show;
            ?>
><?php 
            echo get_language_string($item['title']);
            ?>
</strong> (<?php 
            echo $name;
            ?>
)</td>
		<td class="statistic_graphwrap" <?php 
            echo $style;
            ?>
><div class="statistic_bargraph" style="width: <?php 
            echo $barsize;
            ?>
px"></div><div class="statistic_value"><?php 
            echo $value;
            ?>
</div></td>
		<td class="statistic_link" <?php 
            echo $style;
            ?>
>
		<?php 
            echo "<a href='" . $editurl . "' title='" . $name . "'>" . gettext("Edit") . "</a> | <a href='" . $viewurl . "' title='" . $name . "'>" . gettext("View") . "</a></td";
            echo "</tr>";
            $count++;
            if ($count === $limit) {
                break;
            }
        }
    }
    // foreach end
    echo "</table>";
}
Example #11
0
     if (isset($_POST['ids'])) {
         $action = processAlbumBulkActions();
         if (!empty($action)) {
             $action = '&bulkmessage=' . $action;
         }
     }
     header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin-edit.php?page=edit' . $action . '&saved' . $notify);
     exit;
     break;
 case 'savesubalbumorder':
     XSRFdefender('savealbumorder');
     $album = new Album($gallery, $folder);
     $album->setSubalbumSortType('manual');
     $album->setSortDirection('album', 0);
     $album->save();
     $notify = postAlbumSort($album->get('id'));
     if (isset($_POST['ids'])) {
         $action = processAlbumBulkActions();
         if (!empty($action)) {
             $action = '&bulkmessage=' . $action;
         }
     }
     header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin-edit.php?page=edit' . $action . '&album=' . $folder . '&tab=subalbuminfo&saved' . $notify);
     exit;
     break;
 case 'sorttags':
     if (isset($_GET['subpage'])) {
         $pg = '&subpage=' . $_GET['subpage'];
         $tab = '&tab=imageinfo';
     } else {
         $pg = '';
Example #12
0
     $ext = strtolower(strrchr($item->filename, "."));
     $albumobj = $item->getAlbum();
     $itemlink = $host . WEBPATH . $albumpath . pathurlencode($albumobj->name) . $imagepath . pathurlencode($item->filename) . $modrewritesuffix;
     $fullimagelink = $host . WEBPATH . "/albums/" . pathurlencode($albumobj->name) . "/" . $item->filename;
     $imagefile = "albums/" . $albumobj->name . "/" . $item->filename;
     $thumburl = '<img border="0" src="' . $protocol . '://' . $host . $item->getCustomImage($size, NULL, NULL, NULL, NULL, NULL, NULL, TRUE) . '" alt="' . get_language_string(get_language_string($item->get("title"), $locale)) . '" />';
     $itemcontent = '<![CDATA[<a title="' . html_encode(get_language_string($item->get("title"), $locale)) . ' in ' . html_encode(get_language_string($albumobj->get("title"), $locale)) . '" href="' . $protocol . '://' . $itemlink . '">' . $thumburl . '</a>' . get_language_string(get_language_string($item->get("desc"), $locale)) . ']]>';
     $videocontent = '<![CDATA[<a title="' . html_encode(get_language_string($item->get("title"), $locale)) . ' in ' . html_encode(get_language_string($albumobj->getTitle(), $locale)) . '" href="' . $protocol . '://' . $itemlink . '"><img src="' . $protocol . '://' . $host . $item->getThumb() . '" alt="' . get_language_string(get_language_string($item->get("title"), $locale)) . '" /></a>' . get_language_string(get_language_string($item->get("desc"), $locale)) . ']]>';
     $datecontent = '<![CDATA[Date: ' . zpFormattedDate(DATE_FORMAT, $item->get('mtime')) . ']]>';
 } else {
     $galleryobj = new Gallery();
     $albumitem = new Album($galleryobj, $item['folder']);
     $totalimages = $albumitem->getNumImages();
     $itemlink = $host . WEBPATH . $albumpath . pathurlencode($albumitem->name);
     $thumb = $albumitem->getAlbumThumbImage();
     $thumburl = '<img border="0" src="' . $thumb->getCustomImage($size, NULL, NULL, NULL, NULL, NULL, NULL, TRUE) . '" alt="' . html_encode(get_language_string($albumitem->get("title"), $locale)) . '" />';
     $title = get_language_string($albumitem->get("title"), $locale);
     if (true || getOption("feed_sortorder_albums") == "latestupdated") {
         $filechangedate = filectime(ALBUM_FOLDER_SERVERPATH . internalToFilesystem($albumitem->name));
         $latestimage = query_single_row("SELECT mtime FROM " . prefix('images') . " WHERE albumid = " . $albumitem->getAlbumID() . " AND `show` = 1 ORDER BY id DESC");
         $lastuploaded = query("SELECT COUNT(*) FROM " . prefix('images') . " WHERE albumid = " . $albumitem->getAlbumID() . " AND mtime = " . $latestimage['mtime']);
         $row = db_fetch_row($lastuploaded);
         $count = $row[0];
         if ($count == 1) {
             $imagenumber = sprintf(gettext('%s (1 new image)'), $title);
         } else {
             $imagenumber = sprintf(gettext('%1$s (%2$s new images)'), $title, $count);
         }
         $itemcontent = '<![CDATA[<a title="' . $title . '" href="' . $protocol . '://' . $itemlink . '">' . $thumburl . '</a>' . '<p>' . html_encode($imagenumber) . '</p>' . html_encode(get_language_string($albumitem->get("desc"), $locale)) . ']]>';
         $videocontent = '';
         $datecontent = '<![CDATA[' . sprintf(gettext("Last update: %s"), zpFormattedDate(DATE_FORMAT, $filechangedate)) . ']]>';
Example #13
0
    exit;
}
$_zp_gallery = new Gallery();
$albumobj = new Album($_zp_gallery, $album8);
if (!$albumobj->checkAccess() && !zp_loggedin(VIEW_FULLIMAGE_RIGHTS)) {
    //	handle password form if posted
    zp_handle_password('zp_image_auth', getOption('protected_image_password'), getOption('protected_image_user'));
    //check for passwords
    $hash = getOption('protected_image_password');
    $authType = 'zp_image_auth';
    $hint = get_language_string(getOption('protected_image_hint'));
    $show = getOption('protected_image_user');
    if (empty($hash)) {
        // check for album password
        $hash = $albumobj->getPassword();
        $authType = "zp_album_auth_" . $albumobj->get('id');
        $hint = $albumobj->getPasswordHint();
        $show = $albumobj->getUser();
        if (empty($hash)) {
            $albumobj = $albumobj->getParent();
            while (!is_null($albumobj)) {
                $hash = $albumobj->getPassword();
                $authType = "zp_album_auth_" . $albumobj->get('id');
                $hint = $albumobj->getPasswordHint();
                $show = $albumobj->getUser();
                if (!empty($hash)) {
                    break;
                }
                $albumobj = $albumobj->getParent();
            }
        }
/**
 * Prints the sortable nested albums list
 * returns true if nesting levels exceede the database container
 *
 * @param array $pages The array containing all pages
 * @param bool $show_thumb set false to use thumb standin image.
 *
 * @return bool
 */
function printNestedAlbumsList($albums, $show_thumb)
{
    global $gallery;
    $indent = 1;
    $open = array(1 => 0);
    $rslt = false;
    foreach ($albums as $album) {
        $order = $album['sort_order'];
        $level = max(1, count($order));
        if ($toodeep = $level > 1 && $order[$level - 1] === '') {
            $rslt = true;
        }
        if ($level > $indent) {
            echo "\n" . str_pad("\t", $indent, "\t") . "<ul class=\"page-list\">\n";
            $indent++;
            $open[$indent] = 0;
        } else {
            if ($level < $indent) {
                while ($indent > $level) {
                    $open[$indent]--;
                    $indent--;
                    echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n";
                }
            } else {
                // indent == level
                if ($open[$indent]) {
                    echo str_pad("\t", $indent, "\t") . "</li>\n";
                    $open[$indent]--;
                } else {
                    echo "\n";
                }
            }
        }
        if ($open[$indent]) {
            echo str_pad("\t", $indent, "\t") . "</li>\n";
            $open[$indent]--;
        }
        $albumobj = new Album($gallery, $album['name']);
        if ($albumobj->isDynamic()) {
            $nonest = ' class="no-nest"';
        } else {
            $nonest = '';
        }
        echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $albumobj->get('id') . "\"{$nonest} >";
        printAlbumEditRow($albumobj, $show_thumb);
        $open[$indent]++;
    }
    while ($indent > 1) {
        echo "</li>\n";
        $open[$indent]--;
        $indent--;
        echo str_pad("\t", $indent, "\t") . "</ul>";
    }
    if ($open[$indent]) {
        echo "</li>\n";
    } else {
        echo "\n";
    }
    return $rslt;
}
/**
 * Show the content of an media album with .flv/.mp4/.mp3 movie/audio files only as a playlist or as separate players with Flowplayer 3
 * Important: The Flowplayer 3 plugin needs to be activated to use this plugin. This plugin shares all settings with this plugin, too.
 *
 * You can either show a 'one player window' playlist or show all items as separate players paginated. See the examples below.
 * (set in the settings for thumbs per page) on one page (like on a audio or podcast blog).
 *
 * There are two usage modes:
 *
 * a) 'playlist'
 * The playlist is meant to replace the 'next_image()' loop on a theme's album.php.
 * It can be used with a special 'album theme' that can be assigned to media albums with with .flv/.mp4/.mp3s, although Flowplayer 3 also supports images
 * Replace the entire 'next_image()' loop on album.php with this:
 * <?php flowplayerPlaylist("playlist"); ?>
 *
 * This produces the following html:
 * <div class="wrapper">
 * <a class="up" title="Up"></a>
 * <div class="playlist">
 * <div class="clips">
 * <!-- single playlist entry as an "template" -->
 * <a href="${url}">${title}</a>
 * </div>
 * </div>
 * <a class="down" title="Down"></a>
 * </div>
 * </div>
 * This is styled by the css file 'playlist.css" that is located within the 'zp-core/plugins/flowplayer3_playlist/flowplayer3_playlist.css' by default.
 * Alternatively you can style it specifically for your theme. Just place a css file named "flowplayer3_playlist.css" in your theme's folder.
 *
 * b) 'players'
 * This displays each audio/movie file as a separate player on album.php.
 * If there is no videothumb image for an mp3 file existing only the player control bar is shown.
 * Modify the 'next_image()' loop on album.php like this:
 * <?php
 * while (next_image()):
 * flowplayerPlaylist("players");
 * endwhile;
 * ?>
 * Of course you can add further functions to b) like printImageTitle() etc., too.
 *
 * @param string $option The mode to use "players", "playlist" or "playlist-mp3". "playlist-mp3" is the same as "playlist" except that only the controlbar is shown (if you are too lazy for custom video thumbs and don't like the empty screen)
 * @param string $albumfolder For "playlist" mode only: To show a playlist of an specific album directly on another page (for example on index.php). Note: Currently it is not possible to have several playlists on one page
 */
function flowplayerPlaylist($option = "playlist", $albumfolder = "")
{
    global $_zp_current_image, $_zp_current_album, $_zp_flash_player;
    $curdir = getcwd();
    chdir(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3');
    $filelist = safe_glob('flowplayer-*.swf');
    $swf = array_shift($filelist);
    $filelist = safe_glob('flowplayer.audio-*.swf');
    $audio = array_shift($filelist);
    $filelist = safe_glob('flowplayer.controls-*.swf');
    $controls = array_shift($filelist);
    chdir($curdir);
    $playlistwidth = getOption('flow_player3_playlistwidth');
    $playlistheight = getOption('flow_player3_playlistheight');
    switch ($option) {
        case 'playlist':
        case 'playlist-mp3':
            $splashimage = getOption('flow_player3_playlistsplashimage');
            if ($option == 'playlist-mp3') {
                $playlistheight = FLOW_PLAYER_MP3_HEIGHT;
                $splashimage = 'none';
            }
            if (empty($albumfolder)) {
                $albumname = $_zp_current_album->name;
            } else {
                $albumname = $albumfolder;
            }
            $album = new Album(new Gallery(), $albumname);
            if (getOption("flow_player3_playlistautoplay") == 1) {
                $autoplay = 'true';
            } else {
                $autoplay = 'false';
            }
            $playlist = $album->getImages();
            // slash image fetching
            $videoobj = new Video($album, $playlist[0]);
            $albumfolder = $album->name;
            $splashimagerwidth = $playlistwidth;
            $splashimageheight = $playlistheight;
            $videoThumbImg = '';
            if ($splashimage != 'none') {
                switch ($splashimage) {
                    case 'albumthumb':
                        $albumthumbobj = $album->getAlbumThumbImage();
                        getMaxSpaceContainer($splashimagerwidth, $splashimageheight, $albumthumbobj, true);
                        $albumthumb = $albumthumbobj->getCustomImage(null, $splashimagerwidth, $splashimageheight, null, null, null, null, true);
                        $videoThumbImg = '<img src="' . pathurlencode($albumthumb) . '" alt="" />';
                        break;
                    case 'firstentry':
                        getMaxSpaceContainer($splashimagerwidth, $splashimageheight, $videoobj, true);
                        $videoThumb = $videoobj->getCustomImage(null, $splashimagerwidth, $splashimageheight, null, null, null, null, true);
                        $videoThumbImg = '<img src="' . pathurlencode($videoThumb) . '" alt="" />';
                        break;
                }
            }
            if ($album->getNumImages() != 0) {
                if (getOption('flow_player3_playlistnumbered')) {
                    $liststyle = 'ol';
                } else {
                    $liststyle = 'div';
                }
                echo '<div class="flowplayer3_playlistwrapper">
			<a id="player' . $album->get('id') . '" class="flowplayer3_playlist" style="display:block; width: ' . $playlistwidth . 'px; height: ' . $playlistheight . 'px;">
			' . $videoThumbImg . '
			</a>
			<script type="text/javascript">
			// <!-- <![CDATA[
			$(function() {

			$("div.playlist").scrollable({
				items:"' . $liststyle . '.clips' . $album->get('id') . '",
				vertical:true,
				next:"a.down",
				prev:"a.up",
				mousewheel: true
			});
			flowplayer("player' . $album->get('id') . '","' . WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3/' . $swf . '", {
			plugins: {
				audio: {
					url: "' . $audio . '"
				},
				controls: {
					url: "' . $controls . '",
					backgroundColor: "' . getOption('flow_player3_controlsbackgroundcolor') . '",
					autoHide: "' . getOption('flow_player3_playlistautohide') . '",
					timeColor:"' . getOption('flow_player3_controlstimecolor') . '",
					durationColor: "' . getOption('flow_player3_controlsdurationcolor') . '",
					progressColor: "' . getOption('flow_player3_controlsprogresscolor') . '",
					progressGradient: "' . getOption('flow_player3_controlsprogressgradient') . '",
					bufferColor: "' . getOption('flow_player3_controlsbuffercolor') . '",
					bufferGradient:	 "' . getOption('fflow_player3_controlsbuffergradient') . '",
					sliderColor: "' . getOption('flow_player3_controlsslidercolor') . '",
					sliderGradient: "' . getOption('flow_player3_controlsslidergradient') . '",
					buttonColor: "' . getOption('flow_player3_controlsbuttoncolor') . '",
					buttonOverColor: "' . getOption('flow_player3_controlsbuttonovercolor') . '",
					scaling: "' . getOption('flow_player3_scaling') . '",
					playlist: true
				}
			},
			canvas: {
				backgroundColor: "' . getOption('flow_player3_backgroundcolor') . '",
				backgroundGradient: "' . getOption('flow_player3_backgroundcolorgradient') . '"
			},';
                $list = '';
                foreach ($playlist as $item) {
                    $image = newImage($album, $item);
                    $coverimagerwidth = getOption('flow_player3_playlistwidth');
                    $coverimageheight = getOption('flow_player3_playlistheight');
                    getMaxSpaceContainer($coverimagerwidth, $coverimageheight, $image, true);
                    $cover = $image->getCustomImage(null, $coverimagerwidth, $coverimageheight, null, null, null, null, true);
                    $ext = strtolower(strrchr($item, "."));
                    if ($ext == ".flv" || $ext == ".mp3" || $ext == ".mp4") {
                        $list .= '{
					url:"' . ALBUM_FOLDER_WEBPATH . $album->name . '/' . $item . '",
					autoPlay: ' . $autoplay . ',
					title: "' . $image->getTitle() . ' <small>(' . $ext . ')</small>",
					autoBuffering: ' . $autoplay . ',
					coverImage: {
						url: "' . urlencode($cover) . '",
						scaling: "fit"
					}
				},';
                    }
                    // if ext end
                }
                // foreach end
                echo 'playlist: [' . substr($list, 0, -1) . ']
			});
			flowplayer("player' . $album->get('id') . '").playlist("' . $liststyle . '.clips' . $album->get('id') . ':first", {loop:true});
			});
			// ]]> -->
			</script>';
                ?>
		<div class="wrapper">
					<a class="up" title="Up"></a>

			<div class="playlist playlist<?php 
                echo $album->get('id');
                ?>
">
				<<?php 
                echo $liststyle;
                ?>
 class="clips clips<?php 
                echo $album->get('id');
                ?>
">
					<!-- single playlist entry as an "template" -->
					<?php 
                if ($liststyle == 'ol') {
                    ?>
 <li> <?php 
                }
                ?>
					<a href="${url}">${title}</a>
					<?php 
                if ($liststyle == 'ol') {
                    ?>
 </li> <?php 
                }
                ?>
				</<?php 
                echo $liststyle;
                ?>
>
			</div>
		<a class="down" title="Down"></a>
</div>
</div><!-- flowplayer3_playlist wrapper end -->
<?php 
            }
            // check if there are images end
            break;
        case 'players':
            $_zp_flash_player->printPlayerConfig('', '', imageNumber());
            break;
    }
    // switch end
}