diff --git a/objects/categories.json.php b/objects/categories.json.php index ee55a277f..047ae3847 100644 --- a/objects/categories.json.php +++ b/objects/categories.json.php @@ -1,42 +1,42 @@ ', '
', '
'); +//$breaks = array('
', '
', '
'); foreach ($categories as $key => $value) { $categories[$key]['iconHtml'] = ""; - $categories[$key]['description'] = str_ireplace($breaks, "\r\n", $value['description']); + //$categories[$key]['description'] = str_ireplace($breaks, "\r\n", $value['description']); /* $sql = "SELECT * FROM `category_type_cache` WHERE categoryId = ?"; $res = sqlDAL::readSql($sql,"i",array($value['id'])); $catTypeCache = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if($catTypeCache!=false){ if($catTypeCache['manualSet']=="0"){ $categories[$key]['type'] = "3"; } else { $categories[$key]['type'] = $catTypeCache['type']; } } else { $categories[$key]['type'] = "3"; } * */ } if (empty($_POST['sort']) && empty($_GET['sort'])) { array_multisort(array_column($categories, 'hierarchyAndName'), SORT_ASC, $categories); } echo '{ "current": '.getCurrentPage().',"rowCount": '.getRowCount().', "total": '.$total.', "rows":'. json_encode($categories).'}'; diff --git a/objects/category.php b/objects/category.php index b30b35431..e6b341903 100644 --- a/objects/category.php +++ b/objects/category.php @@ -1,893 +1,895 @@ order); } function setOrder($order) { $this->order = intval($order); } function getUsers_id() { if (empty($this->users_id)) { $this->users_id = User::getId(); } return $this->users_id; } function getPrivate() { return $this->private; } function setUsers_id($users_id) { // only admin can change owner if (!empty($this->users_id) && !User::isAdmin()) { return false; } $this->users_id = intval($users_id); } function setPrivate($private) { $this->private = empty($private) ? 0 : 1; } function setName($name) { - $this->name = xss_esc($name); + $this->name = $name; } function setClean_name($clean_name) { $clean_name = preg_replace('/\W+/', '-', strtolower(cleanString($clean_name))); $this->clean_name = $clean_name; } function setNextVideoOrder($nextVideoOrder) { $this->nextVideoOrder = $nextVideoOrder; } function setParentId($parentId) { $this->parentId = $parentId; } /* function setType($type, $overwriteUserId = 0) { global $global; $internalId = $overwriteUserId; 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)); $catTypeCache = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($catTypeCache != false) { $exist = true; } if ($type == "3") { // auto-cat-type Video::autosetCategoryType($internalId); } else { if ($exist) { $sql = "UPDATE `category_type_cache` SET `type` = ?, `manualSet` = '1' WHERE `category_type_cache`.`categoryId` = ?;"; 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)); } } } * */ function setDescription($description) { - $this->description = xss_esc($description); + $this->description = $description; } function __construct($id, $name = '') { if (empty($id)) { // get the category data from category and pass - $this->name = xss_esc($name); + $this->name = $name; } else { $this->id = $id; // get data from id $this->load($id); } } private function load($id) { $row = self::getCategory($id); if (empty($row)) return false; foreach ($row as $key => $value) { $this->$key = $value; } return true; } function loadSelfCategory() { $this->load($this->getId()); } function save($allowOfflineUser = false) { global $global; if (!$allowOfflineUser && !self::canCreateCategory()) { return false; } if (!$allowOfflineUser && !empty($this->id) && !self::userCanEditCategory($this->id)) { return false; } if (empty($this->users_id)) { $this->users_id = User::getId(); } $this->clean_name = self::fixCleanTitle($this->clean_name, 1, $this->id); // check if clean name exists $exists = $this->getCategoryByName($this->clean_name); if (!empty($exists) && $exists['id'] != $this->id) { $this->clean_name .= uniqid(); } $this->nextVideoOrder = intval($this->nextVideoOrder); $this->parentId = intval($this->parentId); if (!empty($this->id)) { $sql = "UPDATE categories SET " . "name = ?," . "clean_name = ?," . "description = ?," . "nextVideoOrder = ?," . "parentId = ?," . "iconClass = ?," . "users_id = ?," . "`private` = ?, allow_download = ?, `order` = ?, modified = now() WHERE id = ?"; $format = "sssiisiiiii"; - $values = array(xss_esc($this->name), xss_esc($this->clean_name), xss_esc($this->description), $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->getUsers_id(), $this->getPrivate(), $this->getAllow_download(), $this->getOrder(), $this->id); + $values = array($this->name, $this->clean_name, $this->description, $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->getUsers_id(), $this->getPrivate(), $this->getAllow_download(), $this->getOrder(), $this->id); } else { $sql = "INSERT INTO categories ( " . "name," . "clean_name," . "description," . "nextVideoOrder," . "parentId," . "iconClass, " . "users_id, " . "`private`, allow_download, `order`, created, modified) VALUES (?, ?,?,?,?,?,?,?,?,?,now(), now())"; $format = "sssiisiiii"; - $values = array(xss_esc($this->name), xss_esc($this->clean_name), xss_esc($this->description), $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->getUsers_id(), $this->getPrivate(), $this->getAllow_download(), $this->getOrder()); + $values = array($this->name, $this->clean_name, $this->description, $this->nextVideoOrder, $this->parentId, $this->getIconClass(), $this->getUsers_id(), $this->getPrivate(), $this->getAllow_download(), $this->getOrder()); } $insert_row = sqlDAL::writeSql($sql, $format, $values); if ($insert_row) { $_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; ObjectYPT::deleteALLCache(); if (empty($this->id)) { $id = $global['mysqli']->insert_id; } else { $id = $this->id; } return $id; } else { die($sql . ' Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } } static function fixCleanTitle($clean_title, $count, $id, $original_title = "") { global $global; if (empty($original_title)) { $original_title = $clean_title; } $sql = "SELECT * FROM categories WHERE clean_name = '{$clean_title}' "; if (!empty($id)) { $sql .= " AND id != {$id} "; } $sql .= " LIMIT 1"; $res = sqlDAL::readSql($sql, "", array(), true); $cleanTitleExists = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($cleanTitleExists != false) { return self::fixCleanTitle($original_title . "-" . $count, $count + 1, $id, $original_title); } return $clean_title; } function delete() { if (!self::canCreateCategory()) { return false; } if (!self::userCanEditCategory($this->id)) { return false; } // cannot delete default category if ($this->id == 1) { return false; } global $global; if (!empty($this->id)) { $_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; $categories_id = self::getSiteCategoryDefaultID(); if ($categories_id) { $sql = "UPDATE videos SET categories_id = ? WHERE categories_id = ?"; sqlDAL::writeSql($sql, "ii", array($categories_id, $this->id)); } $sql = "DELETE FROM categories WHERE id = ?"; } else { return false; } ObjectYPT::deleteALLCache(); self::clearCacheCount(); self::deleteAssets($this->id); return sqlDAL::writeSql($sql, "i", array($this->id)); } static function deleteAssets($categories_id) { $dirPaths = self::getCategoryDirPath($categories_id); return rrmdir($dirPaths['path']); } /* static function getCategoryType($categoryId) { global $global; $sql = "SELECT * FROM `category_type_cache` WHERE 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"); } } * */ static function getCategory($id) { global $global; $id = intval($id); $sql = "SELECT * FROM categories WHERE id = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "i", array($id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $result['name'] = xss_esc_back($result['name']); } return ($res) ? $result : false; } static function getCategoryByName($name) { global $global; $sql = "SELECT * FROM categories WHERE clean_name = ? LIMIT 1"; $res = sqlDAL::readSql($sql, "s", array($name)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $result['name'] = xss_esc_back($result['name']); + $result['description_html'] = textToLink(htmlentities($result['description'])); } return ($res) ? $result : false; } static function getOrCreateCategoryByName($name) { $cat = self::getCategoryByName($name); if (empty($cat)) { $obj = new Category(0); $obj->setName($name); $obj->setClean_name($name); $obj->setDescription(""); $obj->setIconClass(""); $obj->setNextVideoOrder(0); $obj->setParentId(0); $id = $obj->save(); return self::getCategoryByName($name); } return $cat; } 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) { $result['name'] = xss_esc_back($result['name']); } return ($res) ? $result : false; } static function getSiteCategoryDefaultID() { $obj = AVideoPlugin::getObjectDataIfEnabled("PredefinedCategory"); $id = false; if ($obj) { $id = $obj->defaultCategory; } else { $row = self::getCategoryDefault(); if ($row) { $id = $row['id']; } } return $id; } static function getAllCategories($filterCanAddVideoOnly = false, $onlyWithVideos = false) { global $global, $config; if ($config->currentVersionLowerThen('8.4')) { return false; } $sql = "SELECT * FROM categories c WHERE 1=1 "; if (!empty($_GET['parentsOnly'])) { $sql .= "AND parentId = 0 "; } if ($filterCanAddVideoOnly && !User::isAdmin()) { if (is_int($filterCanAddVideoOnly)) { $users_id = $filterCanAddVideoOnly; } else { $users_id = User::getId(); } if ($config->currentVersionGreaterThen('6.1')) { $sql .= " AND (private=0 OR users_id = '{$users_id}') "; } } if ($onlyWithVideos) { $sql .= " AND ((SELECT count(*) FROM videos v where v.categories_id = c.id OR categories_id IN (SELECT id from categories where parentId = c.id)) > 0 "; if (AVideoPlugin::isEnabledByName("Live")) { $sql .= " OR " . " (" . " SELECT count(*) FROM live_transmitions lt where " . " (lt.categories_id = c.id OR lt.categories_id IN (SELECT id from categories where parentId = c.id))" //. " AND lt.id = (select id FROM live_transmitions lt2 WHERE lt.users_id = lt2.users_id ORDER BY CREATED DESC LIMIT 1 )" . " ) > 0 "; } if (AVideoPlugin::isEnabledByName("LiveLinks")) { $sql .= " OR " . " (" . " SELECT count(*) FROM LiveLinks ll where " . " (ll.categories_id = c.id OR ll.categories_id IN (SELECT id from categories where parentId = c.id))" . " ) > 0 "; } $sql .= ")"; } $sortWhitelist = array('id', 'name', 'clean_name', 'description', 'iconClass', 'nextVideoOrder', 'parentId', 'type', 'users_id', 'private', 'allow_download', 'order'); if(!empty($_POST['sort']) && is_array($_POST['sort'])){ foreach ($_POST['sort'] as $key => $value) { if(!in_array($key, $sortWhitelist)){ unset($_POST['sort'][$key]); } } } $sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY `order`, name ASC "); $cacheName = md5($sql); if (empty($_SESSION['user']['sessionCache']['getAllCategoriesClearCache'])) { $category = object_to_array(ObjectYPT::getCache($cacheName, 36000)); } else { _session_start(); unset($_SESSION['user']['sessionCache']['getAllCategoriesClearCache']); } if (empty($category)) { $res = sqlDAL::readSql($sql); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $category = array(); if ($res) { foreach ($fullResult as $row) { $totals = self::getTotalFromCategory($row['id']); $fullTotals = self::getTotalFromCategory($row['id'], false, true, true); - $row['name'] = xss_esc_back($row['name']); + $row['name'] = $row['name']; $row['total'] = $totals['total']; $row['fullTotal'] = $fullTotals['total']; $row['fullTotal_videos'] = $fullTotals['videos']; $row['fullTotal_lives'] = $fullTotals['lives']; $row['fullTotal_livelinks'] = $fullTotals['livelinks']; $row['owner'] = User::getNameIdentificationById(@$row['users_id']); $row['canEdit'] = self::userCanEditCategory($row['id']); $row['canAddVideo'] = self::userCanAddInCategory($row['id']); $row['hierarchy'] = self::getHierarchyString($row['parentId']); $row['hierarchyAndName'] = $row['hierarchy'] . $row['name']; + $row['description_html'] = textToLink(htmlentities($row['description'])); $category[] = $row; } //$category = $res->fetch_all(MYSQLI_ASSOC); ObjectYPT::setCache($cacheName, $category); } else { $category = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } } return $category; } static function getHierarchyArray($categories_id, $hierarchyArray = array()) { if (empty($categories_id)) { return $hierarchyArray; } $sql = "SELECT * FROM categories WHERE id=? "; $res = sqlDAL::readSql($sql, "i", array($categories_id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); if ($result) { $hierarchyArray[] = $result; return self::getHierarchyArray($result['parentId'], $hierarchyArray); } return $hierarchyArray; } static function getHierarchyString($categories_id) { if (empty($categories_id)) { return "/"; } $array = array_reverse(self::getHierarchyArray($categories_id)); //$array = (self::getHierarchyArray($categories_id)); //var_dump($array);exit; if (empty($array)) { return "/"; } $str = "/"; foreach ($array as $value) { $str .= xss_esc_back($value['name']) . "/"; } return $str; } static function userCanAddInCategory($categories_id, $users_id = 0) { if (empty($categories_id)) { return false; } if (empty($users_id)) { $users_id = User::getId(); } if (empty($users_id)) { return false; } $cat = new Category($categories_id); if (empty($cat->getPrivate()) || $users_id == $cat->getUsers_id()) { return true; } return false; } static function userCanEditCategory($categories_id, $users_id = 0) { if (empty($categories_id)) { return false; } if (empty($users_id)) { $users_id = User::getId(); } if (empty($users_id)) { return false; } if (User::isAdmin()) { return true; } $cat = new Category($categories_id); if ($users_id == $cat->getUsers_id()) { return true; } return false; } static function canCreateCategory() { global $advancedCustomUser; if (User::isAdmin()) { return true; } if ($advancedCustomUser && $advancedCustomUser->usersCanCreateNewCategories && User::canUpload()) { return true; } return false; } static function getChildCategories($parentId, $filterCanAddVideoOnly = false) { global $global, $config; if ($config->currentVersionLowerThen('8.4')) { return false; } $sql = "SELECT * FROM categories WHERE parentId=? AND id!=? "; if ($filterCanAddVideoOnly && !User::isAdmin()) { if (is_int($filterCanAddVideoOnly)) { $users_id = $filterCanAddVideoOnly; } else { $users_id = User::getId(); } if ($config->currentVersionGreaterThen('6.1')) { $sql .= " AND (private=0 OR users_id = '{$users_id}') "; } } $sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY `order`, name ASC "); $res = sqlDAL::readSql($sql, "ii", array($parentId, $parentId)); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $category = array(); if ($res) { foreach ($fullResult as $row) { $totals = self::getTotalFromCategory($row['id']); $row['name'] = xss_esc_back($row['name']); $row['total'] = $totals['total']; $row['total_array'] = $totals; $category[] = $row; } } else { $category = false; die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } return $category; } static function getChildCategoriesFromTitle($clean_title) { $row = self::getCategoryByName($clean_title); return self::getChildCategories($row['id']); } static function getTotalFromCategory($categories_id, $showUnlisted = false, $getAllVideos = false, $renew = false) { $videos = self::getTotalVideosFromCategory($categories_id, $showUnlisted, $getAllVideos, $renew); $lives = self::getTotalLivesFromCategory($categories_id, $showUnlisted, $renew); $livelinkss = self::getTotalLiveLinksFromCategory($categories_id, $showUnlisted, $renew); $total = $videos + $lives + $livelinkss; return array('videos' => $videos, 'lives' => $lives, 'livelinks' => $livelinkss, 'total' => $total); } static function getTotalFromChildCategory($categories_id, $showUnlisted = false, $getAllVideos = false, $renew = false) { $categories = self::getChildCategories($categories_id); $array = array('videos' => 0, 'lives' => 0, 'livelinks' => 0, 'total' => 0); foreach ($categories as $value) { $totals = self::getTotalFromCategory($categories_id, $showUnlisted, $getAllVideos, $renew); $array = array( 'videos' => $array['videos'] + $totals['videos'], 'lives' => $array['lives'] + $totals['lives'], 'livelinks' => $array['livelinks'] + $totals['livelinks'], 'total' => $array['total'] + $totals['total']); $totals = self::getTotalFromChildCategory($value['id'], $showUnlisted, $getAllVideos, $renew); $array = array( 'videos' => $array['videos'] + $totals['videos'], 'lives' => $array['lives'] + $totals['lives'], 'livelinks' => $array['livelinks'] + $totals['livelinks'], 'total' => $array['total'] + $totals['total']); } return $array; } static function getTotalVideosFromCategory($categories_id, $showUnlisted = false, $getAllVideos = false, $renew = false) { global $global, $config; if ($renew || empty($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]['videos'])) { $sql = "SELECT count(id) as total FROM videos v WHERE 1=1 AND categories_id = ? "; if (User::isLogged()) { $sql .= " AND (v.status IN ('" . implode("','", Video::getViewableStatus($showUnlisted)) . "') OR (v.status='u' AND v.users_id ='" . User::getId() . "'))"; } else { $sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus($showUnlisted)) . "')"; } if (!$getAllVideos) { $sql .= Video::getUserGroupsCanSeeSQL(); } //echo $categories_id, $sql;exit; $res = sqlDAL::readSql($sql, "i", array($categories_id)); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $total = empty($fullResult[0]['total']) ? 0 : intval($fullResult[0]['total']); $rows = self::getChildCategories($categories_id); foreach ($rows as $value) { $total += self::getTotalVideosFromCategory($value['id'], $showUnlisted, $getAllVideos, $renew); } _session_start(); $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]['videos'] = $total; } return $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][intval($getAllVideos)]['videos']; } static function getLatestVideoFromCategory($categories_id, $showUnlisted = false, $getAllVideos = false) { global $global, $config; $sql = "SELECT * FROM videos v WHERE 1=1 AND (categories_id = ? OR categories_id IN (SELECT id from categories where parentId = ?))"; if (User::isLogged()) { $sql .= " AND (v.status IN ('" . implode("','", Video::getViewableStatus($showUnlisted)) . "') OR (v.status='u' AND v.users_id ='" . User::getId() . "'))"; } else { $sql .= " AND v.status IN ('" . implode("','", Video::getViewableStatus($showUnlisted)) . "')"; } if (!$getAllVideos) { $sql .= Video::getUserGroupsCanSeeSQL(); } $sql .= "ORDER BY created DESC LIMIT 1"; //var_dump($sql, $categories_id); $res = sqlDAL::readSql($sql, "ii", array($categories_id, $categories_id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); return $result; } static function getLatestLiveFromCategory($categories_id) { if (!AVideoPlugin::isEnabledByName("Live")) { return array(); } global $global, $config; $sql = "SELECT * FROM live_transmitions lt LEFT JOIN live_transmitions_history lth ON lt.users_id = lth.users_id " . " WHERE 1=1 AND (categories_id = ? OR categories_id IN (SELECT id from categories where parentId = ?))"; $sql .= "ORDER BY lth.created DESC LIMIT 1"; //var_dump($sql, $categories_id); $res = sqlDAL::readSql($sql, "ii", array($categories_id, $categories_id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); return $result; } static function getLatestLiveLinksFromCategory($categories_id) { if (AVideoPlugin::isEnabledByName("LiveLinks")) { return array(); } global $global, $config; $sql = "SELECT * FROM livelinks WHERE 1=1 AND (categories_id = ? OR categories_id IN (SELECT id from categories where parentId = ?))"; $sql .= "ORDER BY created DESC LIMIT 1"; //var_dump($sql, $categories_id); $res = sqlDAL::readSql($sql, "ii", array($categories_id, $categories_id)); $result = sqlDAL::fetchAssoc($res); sqlDAL::close($res); return $result; } static function getTotalLiveLinksFromCategory($categories_id, $showUnlisted = false, $renew = false) { global $global; if (!AVideoPlugin::isEnabledByName("LiveLinks")) { return 0; } if ($renew || empty($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['livelinks'])) { $sql = "SELECT count(id) as total FROM LiveLinks v WHERE 1=1 AND categories_id = ? "; if (empty($showUnlisted)) { $sql .= " AND `type` = 'public' "; } //echo $categories_id, $sql;exit; $res = sqlDAL::readSql($sql, "i", array($categories_id)); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $total = empty($fullResult[0]['total']) ? 0 : intval($fullResult[0]['total']); $rows = self::getChildCategories($categories_id); foreach ($rows as $value) { $total += self::getTotalLivesFromCategory($value['id'], $showUnlisted, $renew); } _session_start(); $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['livelinks'] = $total; } return $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['livelinks']; } static function getTotalLivesFromCategory($categories_id, $showUnlisted = false, $renew = false) { if (!AVideoPlugin::isEnabledByName("Live")) { return 0; } global $global; if ($renew || empty($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['live'])) { $sql = "SELECT count(id) as total FROM live_transmitions v WHERE 1=1 AND categories_id = ? "; if (empty($showUnlisted)) { $sql .= " AND public = 1 "; } //echo $categories_id, $sql;exit; $res = sqlDAL::readSql($sql, "i", array($categories_id)); $fullResult = sqlDAL::fetchAllAssoc($res); sqlDAL::close($res); $total = empty($fullResult[0]['total']) ? 0 : intval($fullResult[0]['total']); $rows = self::getChildCategories($categories_id); foreach ($rows as $value) { $total += self::getTotalLivesFromCategory($value['id'], $showUnlisted, $renew); } _session_start(); $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['live'] = $total; } return $_SESSION['user']['sessionCache']['categoryTotal'][$categories_id][intval($showUnlisted)][0]['live']; } static function clearCacheCount($categories_id = 0) { // clear category count cache _session_start(); if (empty($categories_id)) { unset($_SESSION['user']['sessionCache']['categoryTotal']); $_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1; } else { unset($_SESSION['user']['sessionCache']['categoryTotal'][$categories_id]); } //session_write_close(); } static function getTotalCategories($filterCanAddVideoOnly = false, $onlyWithVideos = false) { global $global, $config; if ($config->currentVersionLowerThen('5.01')) { return false; } $sql = "SELECT id, parentId FROM categories c WHERE 1=1 "; if ($filterCanAddVideoOnly && !User::isAdmin()) { if (is_int($filterCanAddVideoOnly)) { $users_id = $filterCanAddVideoOnly; } else { $users_id = User::getId(); } if ($config->currentVersionGreaterThen('6.1')) { $sql .= " AND (private=0 OR users_id = '{$users_id}') "; } } if (!empty($_GET['parentsOnly'])) { $sql .= "AND parentId = 0 OR parentId = -1 "; } if ($onlyWithVideos) { $sql .= " AND ((SELECT count(*) FROM videos v where v.categories_id = c.id OR categories_id IN (SELECT id from categories where parentId = c.id)) > 0 "; if (AVideoPlugin::isEnabledByName("Live")) { $sql .= " OR " . " (" . " SELECT count(*) FROM live_transmitions lt where " . " (lt.categories_id = c.id OR lt.categories_id IN (SELECT id from categories where parentId = c.id))" //. " AND lt.id = (select id FROM live_transmitions lt2 WHERE lt.users_id = lt2.users_id ORDER BY CREATED DESC LIMIT 1 )" . " ) > 0 "; } if (AVideoPlugin::isEnabledByName("LiveLinks")) { $sql .= " OR " . " (" . " SELECT count(*) FROM LiveLinks ll where " . " (ll.categories_id = c.id OR ll.categories_id IN (SELECT id from categories where parentId = c.id))" . " ) > 0 "; } $sql .= ")"; } $sql .= BootGrid::getSqlSearchFromPost(array('name')); //echo $sql;exit; $res = sqlDAL::readSql($sql); $numRows = sqlDal::num_rows($res); sqlDAL::close($res); return $numRows; } function getIconClass() { if (empty($this->iconClass)) { return "fa fa-folder"; } return $this->iconClass; } function setIconClass($iconClass) { $this->iconClass = $iconClass; } function getName() { return $this->name; } function getClean_name() { return $this->clean_name; } function getDescription() { return $this->description; } function getAllow_download() { return $this->allow_download; } function setAllow_download($allow_download) { $this->allow_download = intval($allow_download); } static function getCategoryDirPath($categories_id = "") { global $global; $dir = "videos/categories/assets/"; if (!empty($categories_id)) { $dir .= $categories_id . "/"; } $path = array(); $path['dir'] = "{$global['systemRootPath']}{$dir}"; make_path($path['dir']); $path['path'] = "{$global['systemRootPath']}{$dir}"; $path['url'] = "{$global['webSiteRootURL']}{$dir}"; return $path; } static function isAssetsValids($categories_id) { $photo = Category::getCategoryPhotoPath($categories_id); $background = Category::getCategoryBackgroundPath($categories_id); //var_dump(filesize($background['path']), $background['path'], filesize($photo['path']), $photo['path'] ); if (!file_exists($photo['path']) || !file_exists($background['path'])) { return false; } if(filesize($photo['path']) <= 190){ // transparent image return false; } if(filesize($background['path']) <= 980 || filesize($background['path']) == 4480){ // transparent image return false; } return true; } static function getCategoryPhotoPath($categories_id) { $path = self::getCategoryAssetPath("photo.png", $categories_id); return $path; } static function getCategoryBackgroundPath($categories_id) { $path = self::getCategoryAssetPath("background.png", $categories_id); return $path; } private static function getCategoryAssetPath($name, $categories_id) { if (empty($categories_id)) { return false; } if (empty($name)) { return false; } $dirPaths = self::getCategoryDirPath($categories_id); global $global; $path = array(); $path['dir'] = $dirPaths['url']; $path['path'] = "{$dirPaths['path']}{$name}"; $path['url'] = "{$dirPaths['url']}{$name}"; if (file_exists($path['path'])) { $path['url+timestamp'] = "{$path['url']}?" . filectime($path['path']); } else { $path['url+timestamp'] = $path['url']; } return $path; } } diff --git a/objects/categoryAddNew.json.php b/objects/categoryAddNew.json.php index 4971582f9..8e11540a4 100644 --- a/objects/categoryAddNew.json.php +++ b/objects/categoryAddNew.json.php @@ -1,48 +1,48 @@ error = true; $obj->msg = true; $obj->categories_id = 0; $obj->image1 = 0; $obj->image2 = 0; if(!Category::canCreateCategory()){ $obj->msg = __("Permission denied"); die(json_encode($obj)); } $objCat = new Category(intval(@$_POST['id'])); $objCat->setName($_POST['name']); $objCat->setClean_name($_POST['clean_name']); -$objCat->setDescription(nl2br ($_POST['description'])); +$objCat->setDescription($_POST['description']); $objCat->setIconClass($_POST['iconClass']); $objCat->setNextVideoOrder($_POST['nextVideoOrder']); $objCat->setParentId($_POST['parentId']); $objCat->setPrivate($_POST['private']); $objCat->setAllow_download($_POST['allow_download']); $objCat->setOrder($_POST['order']); $obj->categories_id = $objCat->save(); //$objCat->setType($_POST['type'],$id); if(!empty($obj->categories_id)){ $obj->error = false; $path = Category::getCategoryPhotoPath($obj->categories_id); $obj->image1 = saveCroppieImage($path['path'], "image1"); $obj->image1P = $path['path']; $path = Category::getCategoryBackgroundPath($obj->categories_id); $obj->image2 = saveCroppieImage($path['path'], "image2"); $obj->image2P = $path['path']; } die(json_encode($obj)); diff --git a/plugin/Gallery/view/mainAreaCategory.php b/plugin/Gallery/view/mainAreaCategory.php index 075e7af3a..402bb1348 100644 --- a/plugin/Gallery/view/mainAreaCategory.php +++ b/plugin/Gallery/view/mainAreaCategory.php @@ -1,54 +1,64 @@ CategoriesRowCount * 3; $videos = Video::getAllVideos("viewableNotUnlisted", false, !$obj->hidePrivateVideos); if (!empty($videos)) { ?>

+ + + +

error = true; if (!isset($global['systemRootPath'])) { require_once '../../videos/configuration.php'; } if (!User::canUpload()) { $obj->msg = "Only logged users can upload"; die(json_encode($obj)); } header('Content-Type: application/json'); // A list of permitted file extensions $allowed = Video::$types; $advancedCustom = AVideoPlugin::getObjectDataIfEnabled("CustomizeAdvanced"); if (isset($_FILES['upl']) && $_FILES['upl']['error'] == 0) { $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION); if (!in_array(strtolower($extension), $allowed)) { $obj->msg = "File extension error [{$_FILES['upl']['name']}], we allow only (" . implode(",", $allowed) . ")"; die(json_encode($obj)); } require_once $global['systemRootPath'] . 'objects/video.php'; $duration = Video::getDurationFromFile($_FILES['upl']['tmp_name']); $path_parts = pathinfo($_FILES['upl']['name']); $mainName = preg_replace("/[^A-Za-z0-9]/", "", cleanString($path_parts['filename'])); $filename = uniqid($mainName . "_", true); $videos_id = 0; if (!empty($_FILES['upl']['videoId'])) { $videos_id = $_FILES['upl']['videoId']; } else if (!empty($_POST['videos_id'])) { $videos_id = $_POST['videos_id']; } $title = preg_replace("/_+/", " ", str_ireplace(".{$extension}", "", $_FILES['upl']['name'])); if (empty($videos_id)) { $video = new Video($title, $filename, 0); } else { $video = new Video("", $filename, $videos_id); if ($video->getTitle() === "Video automatically booked") { $video->setTitle($title); $video->setStatus(Video::$statusInactive); } } //var_dump($videos_id, $_FILES['upl']['name'], $title, $video->getTitle());exit; $video->setDuration($duration); if (!empty($_POST['title'])) { $video->setTitle($_POST['title']); } if (!empty($_POST['description'])) { if (strip_tags($_POST['description']) === $_POST['description']) { $_POST['description'] = nl2br(textToLink($_POST['description'])); } $video->setDescription($_POST['description']); } if ($extension == "mp4" || $extension == "webm") { if (!empty($advancedCustom->disableMP4Upload)) { $obj->msg = "Video Files are not Allowed"; die(json_encode($obj)); } $video->setType("video", true); } else if (($extension == "mp3") || ($extension == "ogg")) { if (!empty($advancedCustom->disableMP3Upload)) { $obj->msg = "MP3 Files are not Allowed"; die(json_encode($obj)); } $video->setType("audio", true); } else if (($extension == "pdf")) { if (!empty($advancedCustom->disablePDFUpload)) { $obj->msg = "PDF Files are not Allowed"; die(json_encode($obj)); } $video->setType("pdf", true); } if (($extension == "jpg" || $extension == "jpeg" || $extension == "png" || $extension == "gif" || $extension == "webp")) { if (!empty($advancedCustom->disableImageUpload)) { $obj->msg = "Images Files are not Allowed"; die(json_encode($obj)); } $video->setType("image", true); } if (($extension == "zip")) { if (!empty($global['disableAdvancedConfigurations'])) { $obj->msg = "Zip is disabled on this server"; die(json_encode($obj)); } if (!empty($advancedCustom->disableZipUpload)) { $obj->msg = "Zip Files are not Allowed"; die(json_encode($obj)); } $video->setType("zip", true); } $video->setAutoStatus(Video::$statusInactive); $id = $video->save(); if ($id) { /** * This is when is using in a non uploaded movie */ $aws_s3 = AVideoPlugin::loadPluginIfEnabled('AWS_S3'); $tmp_name = $_FILES['upl']['tmp_name']; $filenameMP4 = $filename . "." . $extension; decideMoveUploadedToVideos($tmp_name, $filenameMP4, $video->getType()); if ((AVideoPlugin::isEnabledByName('MP4ThumbsAndGif')) && ($extension == "mp4" || $extension == "webm" || $extension == "mp3")) { $videoFileName = $video->getFilename(); MP4ThumbsAndGif::getImage($videoFileName, 'jpg', $id); MP4ThumbsAndGif::getImage($videoFileName, 'gif', $id); MP4ThumbsAndGif::getImage($videoFileName, 'webp', $id); } // } else if(($extension=="mp3")||($extension=="ogg")){ // } $obj->title = $video->getTitle(); $obj->error = false; $obj->filename = $filename; $obj->duration = $duration; $obj->videos_id = $id; if (!empty($_FILES['upl']['tmp_name'])) { AVideoPlugin::afterNewVideo($obj->videos_id); } - if ($extension !== "jpg" && $video->getType() == "image") { sleep(1); // to make sure the file will be available $file = $video->getFilename(); $jpgFrom = Video::getPathToFile("{$file}.{$extension}"); $jpgTo = Video::getPathToFile("{$file}.jpg"); try { convertImage($jpgFrom, $jpgTo, 70); } catch (Exception $exc) { _error_log("We could not convert the image to JPG " . $exc->getMessage()); } } die(json_encode($obj)); } } $obj->msg = "\$_FILES Error"; $obj->FILES = $_FILES; die(json_encode($obj));