Skip to content

Commit

Permalink
hide empty categories
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel authored and daniel committed Sep 11, 2018
1 parent 2a06e7f commit 1266075
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
/plugin/AD_Server_Promote_Videos/
/plugin/Blackblaze_B2/
/plugin/VideoDocuments/
/plugin/VideoSpeed/
/plugin/VideoSpeed/
/plugin/FTPAutoImport/
105 changes: 67 additions & 38 deletions objects/category.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

global $global, $config;
if(!isset($global['systemRootPath'])){
if (!isset($global['systemRootPath'])) {
require_once dirname(__FILE__) . '/../videos/configuration.php';
}

Expand Down Expand Up @@ -35,33 +36,33 @@ function setParentId($parentId) {
$this->parentId = $parentId;
}

function setType($type,$overwriteUserId = 0){
function setType($type, $overwriteUserId = 0) {
global $global;
$internalId = $overwriteUserId;
if(empty($internalId)){
if (empty($internalId)) {
$internalId = $this->id;
}
$exist = false;
// require this cause of Video::autosetCategoryType - but should be moveable easy here..
require_once dirname(__FILE__) . '/../objects/video.php';
$sql = "SELECT * FROM `category_type_cache` WHERE categoryId = ?";
$res = sqlDAL::readSql($sql,"i",array($internalId));
$res = sqlDAL::readSql($sql, "i", array($internalId));
$catTypeCache = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if($catTypeCache!=false){
if ($catTypeCache != false) {
$exist = true;
}

if($type=="3"){
if ($type == "3") {
// auto-cat-type
Video::autosetCategoryType($internalId);
} else {
if($exist){
if ($exist) {
$sql = "UPDATE `category_type_cache` SET `type` = ?, `manualSet` = '1' WHERE `category_type_cache`.`categoryId` = ?;";
sqlDAL::writeSql($sql,"si",array($type,$internalId));
sqlDAL::writeSql($sql, "si", array($type, $internalId));
} else {
$sql = "INSERT INTO `category_type_cache` (`categoryId`, `type`, `manualSet`) VALUES (?,?,'1')";
sqlDAL::writeSql($sql,"is",array($internalId,$type));
sqlDAL::writeSql($sql, "is", array($internalId, $type));
}
}
}
Expand Down Expand Up @@ -105,13 +106,13 @@ function save() {
if (!empty($this->id)) {
$sql = "UPDATE categories SET name = ?,clean_name = ?,description = ?,nextVideoOrder = ?,parentId = ?,iconClass = ?, modified = now() WHERE id = ?";
$format = "sssiisi";
$values = array(xss_esc($this->name),xss_esc($this->clean_name),xss_esc($this->description),$this->nextVideoOrder,$this->parentId,$this->getIconClass(),$this->id);
$values = array(xss_esc($this->name), xss_esc($this->clean_name), xss_esc($this->description), $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->id);
} else {
$sql = "INSERT INTO categories ( name,clean_name,description,nextVideoOrder,parentId,iconClass, created, modified) VALUES (?, ?,?,?,?,?,now(), now())";
$format = "sssiis";
$values = array(xss_esc($this->name),xss_esc($this->clean_name),xss_esc($this->description),$this->nextVideoOrder,$this->parentId,$this->getIconClass());
$values = array(xss_esc($this->name), xss_esc($this->clean_name), xss_esc($this->description), $this->nextVideoOrder, $this->parentId, $this->getIconClass());
}
$insert_row = sqlDAL::writeSql($sql,$format,$values);
$insert_row = sqlDAL::writeSql($sql, $format, $values);
if ($insert_row) {
if (empty($this->id)) {
$id = $global['mysqli']->insert_id;
Expand Down Expand Up @@ -139,34 +140,34 @@ function delete() {
} else {
return false;
}
return sqlDAL::writeSql($sql,"i",array($this->id));
return sqlDAL::writeSql($sql, "i", array($this->id));
}

static function getCategoryType($categoryId){
static function getCategoryType($categoryId) {
global $global;
$sql = "SELECT * FROM `category_type_cache` WHERE categoryId = ?;";
$res = sqlDAL::readSql($sql,"i",array($categoryId));
$res = sqlDAL::readSql($sql, "i", array($categoryId));
$data = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if($res) {
if(!empty($data)){
return $data;
} else {
return array("categoryId" => "-1","type"=>"0","manualSet" => "0");
}
}
else {
return array("categoryId" => "-1","type"=>"0","manualSet" => "0");
if ($res) {
if (!empty($data)) {
return $data;
} else {
return array("categoryId" => "-1", "type" => "0", "manualSet" => "0");
}
} else {
return array("categoryId" => "-1", "type" => "0", "manualSet" => "0");
}
}

static function getCategory($id) {
global $global;
$id = intval($id);
$sql = "SELECT * FROM categories WHERE id = ? LIMIT 1";
$res = sqlDAL::readSql($sql,"i",array($id));
$res = sqlDAL::readSql($sql, "i", array($id));
$result = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if($result){
if ($result) {
$result['name'] = xss_esc_back($result['name']);
}
return ($res) ? $result : false;
Expand All @@ -175,37 +176,37 @@ static function getCategory($id) {
static function getCategoryByName($name) {
global $global;
$sql = "SELECT * FROM categories WHERE clean_name = ? LIMIT 1";
$res = sqlDAL::readSql($sql,"s",array($name));
$res = sqlDAL::readSql($sql, "s", array($name));
$result = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if($result){
if ($result) {
$result['name'] = xss_esc_back($result['name']);
}
return ($res) ? $result : false;
}

static function getCategoryDefault() {
global $global;
$sql = "SELECT * FROM categories ORDER BY id ASC LIMIT 1";
$res = sqlDAL::readSql($sql);
$result = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);
if($result){
if ($result) {
$result['name'] = xss_esc_back($result['name']);
}
return ($res) ? $result : false;
}

static function getAllCategories() {
global $global, $config;
if($config->currentVersionLowerThen('5.01')){
if ($config->currentVersionLowerThen('5.01')) {
return false;
}
$sql = "SELECT * FROM categories WHERE 1=1 ";
if(!empty($_GET['parentsOnly'])){
if (!empty($_GET['parentsOnly'])) {
$sql .= "AND parentId = 0 ";
}
if(isset($_POST['sort']['title'])){
if (isset($_POST['sort']['title'])) {
unset($_POST['sort']['title']);
}
$sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY name ASC ");
Expand All @@ -216,6 +217,7 @@ static function getAllCategories() {
if ($res) {
foreach ($fullResult as $row) {
$row['name'] = xss_esc_back($row['name']);
$row['total'] = self::getTotalVideosFromCategory($row['id']);
$category[] = $row;
}
//$category = $res->fetch_all(MYSQLI_ASSOC);
Expand All @@ -228,18 +230,19 @@ static function getAllCategories() {

static function getChildCategories($parentId) {
global $global, $config;
if($config->currentVersionLowerThen('5.01')){
if ($config->currentVersionLowerThen('5.01')) {
return false;
}
$sql = "SELECT * FROM categories WHERE parentId=? AND id!=? ";
$sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY name ASC ");
$res = sqlDAL::readSql($sql,"ii",array($parentId,$parentId));
$res = sqlDAL::readSql($sql, "ii", array($parentId, $parentId));
$fullResult = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$category = array();
if ($res) {
foreach ($fullResult as $row) {
$row['name'] = xss_esc_back($row['name']);
$row['total'] = self::getTotalVideosFromCategory($row['id']);
$category[] = $row;
}
} else {
Expand All @@ -249,16 +252,42 @@ static function getChildCategories($parentId) {
return $category;
}

static function getTotalVideosFromCategory($categories_id) {
global $global, $config;
if (!isset($_SESSION['categoryTotal'][$categories_id])) {
$sql = "SELECT count(id) as total FROM videos WHERE 1=1 AND categories_id = ? ";
$res = sqlDAL::readSql($sql, "i", array($categories_id));
$fullResult = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$total = $fullResult[0]['total'];
$rows = self::getChildCategories($categories_id);
foreach ($rows as $value) {
$total += self::getTotalVideosFromCategory($value['id']);
}
session_write_close();
session_start();
$_SESSION['categoryTotal'][$categories_id] = $total;
session_write_close();
}
return $_SESSION['categoryTotal'][$categories_id];
}

static function clearCacheCount() {
// clear category count cache
session_write_close();
session_start();
unset($_SESSION['categoryTotal']);
session_write_close();
}

static function getTotalCategories() {
global $global, $config;
if($config->currentVersionLowerThen('5.01')){

if ($config->currentVersionLowerThen('5.01')) {
return false;
}
$sql = "SELECT id, parentId FROM categories WHERE 1=1 ";
if(!empty($_GET['parentsOnly'])){
if (!empty($_GET['parentsOnly'])) {
$sql .= "AND parentId = 0 OR parentId = -1 ";
}
$sql .= BootGrid::getSqlSearchFromPost(array('name'));
Expand Down
2 changes: 2 additions & 0 deletions objects/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ function login($noPass = false, $encodedPass = false) {
} else {
$user = $this->find($this->user, $this->password, true, $encodedPass);
}
session_write_close();
session_start();
// if user is not verified
if (!empty($user) && empty($user['isAdmin']) && empty($user['emailVerified']) && !empty($advancedCustom->unverifiedEmailsCanNOTLogin)) {
unset($_SESSION['user']);
Expand Down
1 change: 1 addition & 0 deletions objects/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function save($updateVideoGroups = false) {
}
$insert_row = sqlDAL::writeSql($sql);
if ($insert_row) {
Category::clearCacheCount();
if (empty($this->id)) {
$id = $global['mysqli']->insert_id;
$this->id = $id;
Expand Down
11 changes: 8 additions & 3 deletions view/include/navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,20 +607,25 @@ function mkSub($catId) {
if (!empty($subcats)) {
echo "<ul style='margin-bottom: 0px; list-style-type: none;'>";
foreach ($subcats as $subcat) {
if(empty($subcat['total'])){
continue;
}
echo '<li class="' . ($subcat['clean_name'] == @$_GET['catName'] ? "active" : "") . '">'
. '<a href="' . $global['webSiteRootURL'] . 'cat/' . $subcat['clean_name'] . '" >'
. '<span class="' . (empty($subcat['iconClass']) ? "fa fa-folder" : $subcat['iconClass']) . '"></span> ' . $subcat['name'] . '</a></li>';
. '<span class="' . (empty($subcat['iconClass']) ? "fa fa-folder" : $subcat['iconClass']) . '"></span> ' . $subcat['name'] . ' <span class="badge">' . $subcat['total'] . '</span></a></li>';
mkSub($subcat['id']);
}
echo "</ul>";
}
}

foreach ($categories as $value) {

if(empty($value['total'])){
continue;
}
echo '<li class="' . ($value['clean_name'] == @$_GET['catName'] ? "active" : "") . '">'
. '<a href="' . $global['webSiteRootURL'] . 'cat/' . $value['clean_name'] . '" >'
. '<span class="' . (empty($value['iconClass']) ? "fa fa-folder" : $value['iconClass']) . '"></span> ' . $value['name'] . '</a>';
. '<span class="' . (empty($value['iconClass']) ? "fa fa-folder" : $value['iconClass']) . '"></span> ' . $value['name'] . ' <span class="badge">' . $value['total'] . '</span></a>';
mkSub($value['id']);
echo '</li>';
}
Expand Down

0 comments on commit 1266075

Please sign in to comment.