diff --git a/public_html/package-edit.php b/public_html/package-edit.php index 206a4eea..5b6ac01e 100644 --- a/public_html/package-edit.php +++ b/public_html/package-edit.php @@ -133,7 +133,7 @@ if (isset($_POST['submit'])) { $rest = $container->get(Rest::class); $rest->savePackage($_POST['name']); $rest->savePackagesCategory($packageRepository->find($_POST['name'], 'category')); - $content .= 'Package information successfully updated.

'; + $content .= 'Package information successfully updated.'; } elseif (isset($_GET['action']) && 'release_remove' === $_GET['action']) { if (!isset($_GET['release'])) { echo $template->render('error.php', [ @@ -144,7 +144,7 @@ if (isset($_POST['submit'])) { } if ($container->get(Release::class)->remove($_GET['id'], $_GET['release'])) { - $content .= 'Release successfully deleted.

'; + $content .= 'Release successfully deleted.'; } else { echo $template->render('error.php', [ 'errors' => ['An error occured while deleting the release!'], diff --git a/public_html/packages.php b/public_html/packages.php index 9de38570..b6bd5ba3 100644 --- a/public_html/packages.php +++ b/public_html/packages.php @@ -27,7 +27,9 @@ use App\Utils\Breadcrumbs; use App\Utils\Pagination; -$script_name = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES); +require_once __DIR__.'/../include/pear-prepend.php'; + +$scriptName = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES); /** * Returns an appropriate query string for a self referencing link @@ -35,30 +37,29 @@ $script_name = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES); function getQueryString($catpid, $catname, $showempty = false, $moreinfo = false) { $querystring = []; - $entries_cnt = 0; + $count = 0; if ($catpid) { $querystring[] = 'catpid='.(int)$catpid; - $entries_cnt++; + $count++; } if ($catname) { $querystring[] = 'catname='.urlencode($catname); - $entries_cnt++; + $count++; } if ($showempty) { $querystring[] = 'showempty='.(int)$showempty; - $entries_cnt++; + $count++; } if ($moreinfo) { $querystring[] = 'moreinfo='.(int)$moreinfo; - $entries_cnt++; + $count++; } - - if ($entries_cnt) { + if ($count) { return '?'.implode('&', $querystring); } else { return ''; @@ -66,15 +67,15 @@ function getQueryString($catpid, $catname, $showempty = false, $moreinfo = false } // Check input variables. Expected url vars: catpid (category parent id), catname, showempty -$moreinfo = isset($_GET['moreinfo']) ? (int)$_GET['moreinfo'] : false; -$catpid = isset($_GET['catpid']) ? (int)$_GET['catpid'] : null; -$showempty = isset($_GET['showempty']) ? (bool)$_GET['showempty'] : false; +$moreinfo = isset($_GET['moreinfo']) ? (int) $_GET['moreinfo'] : false; +$catpid = isset($_GET['catpid']) ? (int) $_GET['catpid'] : null; +$showempty = isset($_GET['showempty']) ? (bool) $_GET['showempty'] : false; if (empty($catpid)) { - $category_where = "IS NULL"; - $catname = "Top Level"; + $categoryWhere = 'IS NULL'; + $catname = 'Top Level'; } else { - $category_where = "= " . $catpid; + $categoryWhere = '= '.$catpid; if (isset($_GET['catname']) && preg_match('/^[0-9a-z_ ]{1,80}$/i', $_GET['catname'])) { $catname = $_GET['catname']; @@ -85,63 +86,59 @@ if (empty($catpid)) { // The user is already at the top level if (empty($catpid)) { - $showempty_link = 'Top Level'; + $showEmptyLink = 'Top Level'; } else { - $showempty_link = '' . ($showempty ? 'Hide empty' : 'Show empty').''; + $showEmptyLink = ''.($showempty ? 'Hide empty' : 'Show empty').''; } // Main part of script if ($catpid) { $catname = $database->run('SELECT name FROM categories WHERE id=:id', [':id' => $catpid])->fetch()['name']; - $category_title = "Package Browser :: " . htmlspecialchars($catname, ENT_QUOTES); + $categoryTitle = "Package Browser :: " . htmlspecialchars($catname, ENT_QUOTES); } else { - $category_title = 'Package Browser :: Top Level'; + $categoryTitle = 'Package Browser :: Top Level'; } -response_header($category_title); - // 1) Show categories of this level $statement = $database->run("SELECT c.*, COUNT(p.id) AS npackages FROM categories c LEFT JOIN packages p ON p.category = c.id WHERE p.package_type = 'pecl' - AND c.parent ".$category_where." + AND c.parent $categoryWhere GROUP BY c.id ORDER BY name"); // Get names of sub-categories -$subcats = $database->run("SELECT p.id AS pid, c.id AS id, c.name AS name, c.summary AS summary". - " FROM categories c, categories p ". - " WHERE p.parent $category_where ". - " AND c.parent = p.id ORDER BY c.name")->fetchAll(); +$subcats = $database->run("SELECT p.id AS pid, c.id AS id, c.name AS name, c.summary AS summary + FROM categories c, categories p + WHERE p.parent $categoryWhere + AND c.parent = p.id ORDER BY c.name")->fetchAll(); // Get names of sub-packages -$subpkgs = $database->run("SELECT p.category, p.id AS id, p.name AS name, p.summary AS summary". - " FROM packages p, categories c". - " WHERE c.parent $category_where ". - " AND p.package_type = 'pecl' ". - " AND p.category = c.id ORDER BY p.name")->fetchAll(); +$subpkgs = $database->run("SELECT p.category, p.id AS id, p.name AS name, p.summary AS summary + FROM packages p, categories c + WHERE c.parent $categoryWhere + AND p.package_type = 'pecl' + AND p.category = c.id ORDER BY p.name")->fetchAll(); -$max_sub_links = 4; -$totalpackages = 0; +$maxSubLinks = 4; +$totalPackages = 0; $categories = []; foreach ($statement->fetchAll() as $row) { - extract($row); - // Show only categories with packages - if (!$showempty AND $row['npackages'] < 1) { + if (!$showempty && $row['npackages'] < 1) { continue; } - $sub_links = []; + $subLinks = []; foreach ($subcats as $subcat) { if ($subcat['pid'] === $row['id']) { - $sub_links[] = '' . $subcat['name'].''; - if (count($sub_links) >= $max_sub_links) { + if (count($subLinks) >= $maxSubLinks) { break; } } @@ -149,28 +146,26 @@ foreach ($statement->fetchAll() as $row) { foreach ($subpkgs as $subpkg) { if ($subpkg['category'] === $row['id']) { - $sub_links[] = ''.$subpkg['name'].''; - if (count($sub_links) >= $max_sub_links) { + if (count($subLinks) >= $maxSubLinks) { break; } } } - if (count($sub_links) >= $max_sub_links) { - $sub_links = implode(', ', $sub_links).' [more]'; + if (count($subLinks) >= $maxSubLinks) { + $subLinks = implode(', ', $subLinks).' [more]'; } else { - $sub_links = implode(', ', $sub_links); + $subLinks = implode(', ', $subLinks); } - settype($npackages, 'string'); - - $data = ''.$name.' ('.$npackages.')
'; - $data .= $sub_links.'
'; + settype($row['npackages'], 'string'); + $data = ''.$row['name'].' ('.$row['npackages'].')
'; + $data .= $subLinks.'
'; $categories[] = $data; - - $totalpackages += $npackages; + $totalPackages += $row['npackages']; } // Begin code for showing packages if we aren't at the top level. @@ -187,7 +182,7 @@ if (!empty($catpid)) { if (count($subcats) > 0) { foreach ($subcats as $subcat) { $subCategories[] = sprintf('%s', - $script_name, + $scriptName, $subcat['id'], urlencode($subcat['name']), htmlspecialchars($subcat['summary'], ENT_QUOTES), @@ -201,7 +196,7 @@ if (!empty($catpid)) { $total = $database->run("SELECT count(*) FROM packages WHERE category = ? AND package_type='pecl'", [$catpid])->fetchColumn(); $pagination = new Pagination(); $pagination->setNumberOfItems($total); - $currentPage = isset($_GET['pageID']) ? (int)$_GET['pageID'] : 1; + $currentPage = isset($_GET['pageID']) ? (int) $_GET['pageID'] : 1; $pagination->setCurrentPage($currentPage); $from = $pagination->getFrom(); $to = $pagination->getTo(); @@ -228,7 +223,7 @@ if (!empty($catpid)) { } $link .= 'pageID='.$previousPage; - $prev = '<<Back'; + $prev = '<<Back'; } $next = ''; @@ -241,7 +236,7 @@ if (!empty($catpid)) { } $link .= 'pageID='.$nextPage; - $next = 'Next>>'; + $next = 'Next>>'; } foreach ($packages as $key => $pkg) { @@ -279,7 +274,22 @@ if ($moreinfo) { $hideMoreInfoLink = '#'; } -$breadcrumbs = $container->get(Breadcrumbs::class)->getBreadcrumbs($catpid, false); - -// Template -include __DIR__.'/../templates/packages.php'; +echo $template->render('pages/packages.php', [ + 'title' => $categoryTitle, + 'breadcrumbs' => $container->get(Breadcrumbs::class)->getBreadcrumbs($catpid, false), + 'showEmptyLink' => $showEmptyLink, + 'categories' => $categories, + 'catpid' => $catpid, + 'packages' => isset($packages) ? $packages : null, + 'subCategories' => isset($subCategories) ? $subCategories : null, + 'hideMoreInfoLink' => $hideMoreInfoLink, + 'showMoreInfoLink' => $showMoreInfoLink, + 'prev' => isset($prev) ? $prev : null, + 'from' => isset($from) ? $from : null, + 'to' => isset($to) ? $to : null, + 'total' => isset($total) ? $total : null, + 'next' => isset($next) ? $next : null, + 'defaultMoreInfoVis' => isset($defaultMoreInfoVis) ? $defaultMoreInfoVis : null, + 'totalPackages' => $totalPackages, + 'catname' => $catname, +]); diff --git a/templates/packages.php b/templates/packages.php deleted file mode 100644 index 97c27ecd..00000000 --- a/templates/packages.php +++ /dev/null @@ -1,175 +0,0 @@ - | - | Martin Jansen | - | Pierre Joye | - | Peter Kokot | - +----------------------------------------------------------------------+ -*/ - -?> - - - - - - - - -
- Contents of :: - - -
- - 0): ?> - - - - - - - -
- - - - - - - -
- - - - -
- - - Sub-categories:

- - - - - - - - - - - - - -
- - - - - - -
 Packages ( - of ) 
-
- - - - - - - - - - - - - - style="display: " id="moreInfo_"> - - - - - - style="display: " id="moreInfo__spacer"> - -
# - Package name - Description -  
- ,); return false" onmouseover="window.status = 'View more info about '; return true" onmouseout="window.status = ''" title="View more info about "> - - -
  - - - - - -
More information - ,)"> -
- - - - - - - - - - - - - - -
Number of releases:License type:
Status:
- - -
 
-
- - -

- No packages found in this category -

- - -
- -

- - Total number of packages:
- View package statistics - - Statistics for category "" - -

- -Edit package +

e($content) ?>

+
diff --git a/templates/pages/packages.php b/templates/pages/packages.php new file mode 100644 index 00000000..1660390b --- /dev/null +++ b/templates/pages/packages.php @@ -0,0 +1,156 @@ +extend('layout.php', ['title' => $title]) ?> + +start('content') ?> + + + + + + + + +
+ Contents of :: + + +
+ + 0): ?> + + + + + + + +
+ + + + + + + +
+ + + + +
+ + + Sub-categories:

+ + + + + + + + + + + + + + + + + +
+ + + + + + +
 Packages ( - of ) 
+
+ + + + + + + + + + + + + + id="moreInfo_"> + + + + + + id="moreInfo_noHtml($p['id']) ?>_spacer"> + + + +
# + Package name + Description +  
e($p['name']) ?>e($p['summary']) ?> + + + +
  + + + + + +
More information + +
+ + + + + + + + + + + + + + +
Number of releases:e($p['eInfo']['numReleases']) ?>License type:e($p['eInfo']['license']) ?>
Status:
+
 
+
+ + +

No packages found in this category

+ + +
+ +

+ + Total number of packages: e($totalPackages) ?>
+ View package statistics + + Statistics for category "e($catname) ?>" + +

+ +end('content') ?>