function phphoto_admin_links($db) { $text_index = phphoto_text($db, 'section', 'index'); $text_admin = phphoto_text($db, 'section', 'admin'); $text_galleries = phphoto_text($db, 'section', 'galleries'); $text_tags = phphoto_text($db, 'section', 'tags'); $text_images = phphoto_text($db, 'section', 'images'); $text_cameras = phphoto_text($db, 'section', 'cameras'); echo "\n<ul>"; echo "\n <li" . (!isset($_GET[GET_KEY_ADMIN_QUERY]) ? " class=active" : '') . "><a href='" . CURRENT_PAGE . "'>{$text_index}</a></li>"; echo "\n <li" . (isset($_GET[GET_KEY_ADMIN_QUERY]) && $_GET[GET_KEY_ADMIN_QUERY] == GET_VALUE_ADMIN_DEFAULT ? " class=active" : '') . "><a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_DEFAULT . "'>{$text_admin}</a></li>"; echo "\n <li" . (isset($_GET[GET_KEY_ADMIN_QUERY]) && $_GET[GET_KEY_ADMIN_QUERY] == GET_VALUE_ADMIN_GALLERY ? " class=active" : '') . "><a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_GALLERY . "'>{$text_galleries}</a></li>"; echo "\n <li" . (isset($_GET[GET_KEY_ADMIN_QUERY]) && $_GET[GET_KEY_ADMIN_QUERY] == GET_VALUE_ADMIN_TAG ? " class=active" : '') . "><a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_TAG . "'>{$text_tags}</a></li>"; echo "\n <li" . (isset($_GET[GET_KEY_ADMIN_QUERY]) && $_GET[GET_KEY_ADMIN_QUERY] == GET_VALUE_ADMIN_IMAGE ? " class=active" : '') . "><a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . "'>{$text_images}</a></li>"; echo "\n <li" . (isset($_GET[GET_KEY_ADMIN_QUERY]) && $_GET[GET_KEY_ADMIN_QUERY] == GET_VALUE_ADMIN_CAMERA ? " class=active" : '') . "><a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_CAMERA . "'>{$text_cameras}</a></li>"; echo "\n</ul>"; }
function phphoto_echo_galleries($db) { $gallery_sql = "\n SELECT\n id,\n title,\n description,\n (SELECT COUNT(*) FROM image_to_gallery WHERE gallery_id = g.id) AS images,\n \n (SELECT MAX(changed) FROM\n (\n (SELECT temp1.changed, temp1.id AS gallery_id FROM galleries temp1)\n UNION\n (SELECT temp2.changed, temp2.gallery_id FROM image_to_gallery temp2)\n UNION\n (SELECT (SELECT changed FROM images WHERE id = temp3.image_id) AS changed, temp3.gallery_id FROM image_to_gallery temp3)\n ) temp\n WHERE\n gallery_id = g.id\n ) AS changed\n FROM\n galleries g\n WHERE\n active = TRUE\n AND\n (\n SELECT COUNT(*) FROM image_to_gallery itg WHERE itg.gallery_id = g.id\n AND\n (\n SELECT COUNT(*) FROM images i WHERE i.id = itg.image_id AND active = TRUE\n ) > 0\n ) > 0\n ORDER BY\n " . GALLERY_SORT_COLUMN . "\n "; $tag_sql = "\n SELECT\n id,\n name,\n description\n FROM\n tags t\n WHERE\n active = TRUE\n AND\n (\n SELECT COUNT(*) FROM image_to_tag itt WHERE itt.tag_id = t.id\n AND\n (\n SELECT COUNT(*) FROM images i WHERE i.id = itt.image_id AND active = TRUE\n ) > 0\n ) > 0\n ORDER BY\n name\n "; echo "\n<div class='header'>"; echo "\n <p><a href='" . GALLERY_INDEX_PAGE . "'>" . GALLERY_TITLE . "</a></p>"; echo "\n</div>"; echo "\n<div class='container'>"; echo "\n <h1>" . GALLERY_WELCOME . "</h1>"; echo "\n <div class='wrapper'>"; foreach (phphoto_db_query($db, $gallery_sql) as $gallery) { echo "\n <div class='gallery'>"; echo "\n <a href='" . CURRENT_PAGE . "?" . GET_KEY_GALLERY_ID . "={$gallery['id']}'>"; echo "\n <img class='thumbnail' src='image.php?" . GET_KEY_GALLERY_ID . "={$gallery['id']}' title='{$gallery['description']}' alt='{$gallery['title']}' />"; echo "\n <h1>" . format_string($gallery['title'], 30) . "</h1>"; echo "\n <h2>updated " . format_date_time($gallery['changed']) . "</h2>"; echo "\n <p>" . format_string($gallery['description']) . "</p>"; echo "\n </a>"; echo "\n </div>"; } echo "\n </div>"; // echo links for the different tags $tags = array(); foreach (phphoto_db_query($db, $tag_sql) as $tag) { array_push($tags, "<a href='" . CURRENT_PAGE . "?" . GET_KEY_TAG_ID . "={$tag['id']}' title='{$tag['description']}'>{$tag['name']}</a>"); } if (count($tags) > 0) { echo "\n <p>" . phphoto_text($db, 'section', 'tags') . ": " . implode(', ', $tags) . '</p>'; } echo "\n</div>"; phphoto_echo_gallery_footer("<a href='http://github.com/RiJo/phphoto'>" . GALLERY_NAME . ' v.' . GALLERY_VERSION . "</a>"); }
function phphoto_page_numbering($db, $page_number, $pages, $url_previous, $url_next) { $string = ''; if ($page_number > 0) { $string .= "<a href='{$url_previous}'><img src='./icons/go-previous.png' /></a>"; } else { $string .= "<img src='./icons/go-previous-inactive.png' />"; } $string .= ' ' . phphoto_text($db, 'common', 'page_number', $page_number + 1, $pages) . ' '; if ($page_number < $pages - 1) { $string .= "<a href='{$url_next}'><img src='./icons/go-next.png' /></a>"; } else { $string .= "<img src='./icons/go-next-inactive.png' />"; } return $string; }
function phphoto_echo_admin_images($db) { phphoto_upload_image($db); phphoto_image_thumbnails($db); $order_by = isset($_GET[GET_KEY_SORT_COLUMN]) ? $_GET[GET_KEY_SORT_COLUMN] : 2; $items_per_page = isset($_GET[GET_KEY_ITEMS_PER_PAGE]) ? $_GET[GET_KEY_ITEMS_PER_PAGE] : DEFAULT_ITEMS_PER_PAGE; assert(is_numeric($items_per_page)); // prevent SQL injections $page_number = isset($_GET[GET_KEY_PAGE_NUMBER]) ? $_GET[GET_KEY_PAGE_NUMBER] : 0; assert(is_numeric($page_number)); // prevent SQL injections $sql = "SELECT CEIL(COUNT(*) / {$items_per_page}) AS pages FROM images"; $pages = phphoto_db_query($db, $sql); $pages = $pages[0]['pages'] > 0 ? $pages[0]['pages'] : 1; $sql = sprintf("\n SELECT\n id,\n IF (LENGTH(title) > 0, title, filename) AS name,\n active,\n width,\n height,\n (SELECT COUNT(*) FROM image_to_gallery WHERE image_id = id) AS galleries,\n (SELECT COUNT(*) FROM image_to_tag WHERE image_id = id) AS tags,\n views,\n views / (SELECT SUM(views) FROM images) AS popularity\n FROM\n images\n ORDER BY\n %s\n LIMIT\n " . $page_number * $items_per_page . ", {$items_per_page}", mysql_real_escape_string($order_by, $db)); $header = array(phphoto_text($db, 'header', 'thumbnail'), "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=2'>" . phphoto_text($db, 'header', 'name') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=3'>" . phphoto_text($db, 'header', 'active') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=4'>" . phphoto_text($db, 'header', 'resolution') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=6'>" . phphoto_text($db, 'header', 'galleries') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=7'>" . phphoto_text($db, 'header', 'tags') . "</a>", "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_SORT_COLUMN . "=8'>" . phphoto_text($db, 'header', 'views') . "</a>", ' '); $max_text_length = 12; $data = array(); foreach (phphoto_db_query($db, $sql) as $row) { array_push($data, array("<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_IMAGE_ID . "={$row['id']}'>\n <img src='image.php?" . GET_KEY_IMAGE_ID . "={$row['id']}t' class='thumbnail' /></a>", wordwrap(format_string($row['name']), 20, '<br>', true), format_bool($row['active']), $row['width'] . 'x' . $row['height'] . '<br>' . phphoto_image_aspect_ratio($row['width'], $row['height']), $row['galleries'], $row['tags'], $row['views'] . " (" . round($row['popularity'] * 100) . "%)", !$row['galleries'] && !$row['tags'] ? "<a href='" . CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_OPERATION . '=' . GET_VALUE_DELETE . '&' . GET_KEY_IMAGE_ID . "={$row['id']}'><img src='./icons/process-stop.png' /></a>" : "<img src='./icons/process-stop-inactive.png' />")); } echo "\n<div class='admin'>"; echo "\n <h1>" . phphoto_text($db, 'section', 'images') . "</h1>"; $url_previous = CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_PAGE_NUMBER . '=' . ($page_number - 1); $url_next = CURRENT_PAGE . '?' . GET_KEY_ADMIN_QUERY . '=' . GET_VALUE_ADMIN_IMAGE . '&' . GET_KEY_PAGE_NUMBER . '=' . ($page_number + 1); $footer = array(phphoto_page_numbering($db, $page_number, $pages, $url_previous, $url_next)); phphoto_to_html_table($data, $header, $footer); echo "\n</div>"; }