Skip to content

Commit

Permalink
Merge pull request #42 from hersche/unstable
Browse files Browse the repository at this point in the history
merge unstable to master
  • Loading branch information
Vinzenz Hersche authored Apr 6, 2018
2 parents 459536a + 3f4da9c commit 39fcae0
Show file tree
Hide file tree
Showing 45 changed files with 2,505 additions and 1,623 deletions.
4 changes: 2 additions & 2 deletions install/checkConfiguration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$installationVersion = "5.0";
$installationVersion = "5.01";


header('Content-Type: application/json');
Expand Down Expand Up @@ -93,7 +93,7 @@
exit;
}

$sql = "INSERT INTO categories (id, name, clean_name, created, modified) VALUES (1, 'Default', 'default', now(), now())";
$sql = "INSERT INTO categories (id, name, clean_name, description, created, modified) VALUES (1, 'Default', 'default','', now(), now())";
if ($mysqli->query($sql) !== TRUE) {
$obj->error = "Error creating category: " . $mysqli->error;
echo json_encode($obj);
Expand Down
14 changes: 14 additions & 0 deletions install/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS `categories` (
`clean_name` VARCHAR(45) NOT NULL,
`description` TEXT NULL,
`nextVideoOrder` INT(2) NOT NULL DEFAULT '0',
`parentId` INT NOT NULL DEFAULT '0',
`created` DATETIME NOT NULL,
`modified` DATETIME NOT NULL,
`iconClass` VARCHAR(45) NOT NULL DEFAULT 'fa fa-folder',
Expand Down Expand Up @@ -473,6 +474,19 @@ CREATE TABLE IF NOT EXISTS `comments_likes` (
ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `category_type_cache`
-- -----------------------------------------------------
CREATE TABLE `category_type_cache` (
`categoryId` int(11) NOT NULL,
`type` int(2) NOT NULL COMMENT '0=both, 1=audio, 2=video' DEFAULT 0,
`manualSet` int(1) NOT NULL COMMENT '0=auto, 1=manual' DEFAULT 0

) ENGINE=InnoDB;

ALTER TABLE `category_type_cache`
ADD UNIQUE KEY `categoryId` (`categoryId`);
COMMIT;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
Expand Down
1 change: 1 addition & 0 deletions locale/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
$t['You are hosting %d minutes and %d seconds of video'] = "Du verfügst über % d Minuten und % d Sekunden an Videos";
$t['You are running YouPHPTube version %s!'] = "Du nutzt YouPHPTube Version %s!";
$t['You asked for a recover link, click on the provided link'] = "Du hast nach einem Wiederherstellungslink gefragt, klicke auf den Link";
$t['You%20can%20not%20manage'] = "Du%20kannst"; // This is gramaticly not correct and only used in a error-field..
$t['You can not Manage This Video'] = "Du kannst das Videos nicht managen";
$t['You can not manage ads'] = "Du kannst keine Werbung managen";
$t['You can not manage categories'] = "Du kannst keine Kategorien managen";
Expand Down
13 changes: 13 additions & 0 deletions objects/categories.json.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
error_reporting(0);
require_once 'category.php';
header('Content-Type: application/json');
$categories = Category::getAllCategories();
Expand All @@ -7,5 +8,17 @@
foreach ($categories as $key => $value) {
$categories[$key]['iconHtml'] = "<span class='$value[iconClass]'></span>";
$categories[$key]['description'] = str_ireplace($breaks, "\r\n", $value['description']);
$sql = "SELECT * FROM `category_type_cache` WHERE categoryId = '".$value['id']."';";
$res = $global['mysqli']->query($sql);
$catTypeCache = $res->fetch_assoc();
if($catTypeCache){
if($catTypeCache['manualSet']=="0"){
$categories[$key]['type'] = "3";
} else {
$categories[$key]['type'] = $catTypeCache['type'];
}
} else {
$categories[$key]['type'] = "3";
}
}
echo '{ "current": '.$_POST['current'].',"rowCount": '.$_POST['rowCount'].', "total": '.$total.', "rows":'. json_encode($categories).'}';
94 changes: 88 additions & 6 deletions objects/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Category {
private $description;
private $iconClass;
private $nextVideoOrder;
private $parentId;
private $type;

function setName($name) {
$this->name = $name;
Expand All @@ -21,11 +23,48 @@ function setClean_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){
global $global;
$exist = false;
// require this cause of Video::autosetCategoryType - but should be moveable easy here..
require_once dirname(__FILE__) . '/../objects/video.php';

//$this->id is already replaced by the new..
$sql = "SELECT * FROM `category_type_cache` WHERE categoryId = '".$this->id."';";
$res = $global['mysqli']->query($sql);
$catTypeCache = $res->fetch_assoc();
if($catTypeCache){
$exist = true;
}

if($type=="3"){
// auto-cat-type
if($exist){
$sql = "UPDATE `category_type_cache` SET `manualSet` = '0' WHERE `category_type_cache`.`categoryId` = '".$this->id."';";
} else {
$sql = "INSERT INTO `category_type_cache` (`categoryId`, `type`, `manualSet`) VALUES ('".$this->id."', '0','0')";
}
$res = $global['mysqli']->query($sql);
Video::autosetCategoryType($this->id);
} else {
if($exist){
$sql = "UPDATE `category_type_cache` SET `type` = '".$type."', `manualSet` = '1' WHERE `category_type_cache`.`categoryId` = '".$this->id."';";
} else {
$sql = "INSERT INTO `category_type_cache` (`categoryId`, `type`, `manualSet`) VALUES ('".$this->id."', '".$type."','1')";
}
$res = $global['mysqli']->query($sql);
}
}

function setDescription($description) {
$this->description = $description;
}
Expand Down Expand Up @@ -56,9 +95,9 @@ function save() {
$this->isAdmin = "false";
}
if (!empty($this->id)) {
$sql = "UPDATE categories SET name = '{$this->name}',clean_name = '{$this->clean_name}',description = '{$this->description}',nextVideoOrder = '{$this->nextVideoOrder}',iconClass = '{$this->getIconClass()}', modified = now() WHERE id = {$this->id}";
$sql = "UPDATE categories SET name = '{$this->name}',clean_name = '{$this->clean_name}',description = '{$this->description}',nextVideoOrder = '{$this->nextVideoOrder}',parentId = '{$this->parentId}',iconClass = '{$this->getIconClass()}', modified = now() WHERE id = {$this->id}";
} else {
$sql = "INSERT INTO categories ( name,clean_name,description,nextVideoOrder,iconClass, created, modified) VALUES ('{$this->name}', '{$this->clean_name}','{$this->description}','{$this->nextVideoOrder}', '{$this->getIconClass()}',now(), now())";
$sql = "INSERT INTO categories ( name,clean_name,description,nextVideoOrder,parentId,iconClass, created, modified) VALUES ('{$this->name}', '{$this->clean_name}','{$this->description}','{$this->nextVideoOrder}','{$this->parentId}', '{$this->getIconClass()}',now(), now())";
}
$resp = $global['mysqli']->query($sql);
if (empty($resp)) {
Expand Down Expand Up @@ -89,17 +128,55 @@ function delete() {
return $resp;
}

static function getCategoryType($categoryId){
global $global;
$sql = "SELECT * FROM `category_type_cache` WHERE categoryId = '".$categoryId."';";
$res = $global['mysqli']->query($sql);
if($res) {
$sres = $res->fetch_assoc();
if(!empty($sres)){
return $sres;
} 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 = $id LIMIT 1";
$sql = "SELECT * FROM categories WHERE id = $id LIMIT 1";
$res = $global['mysqli']->query($sql);
return ($res) ? $res->fetch_assoc() : false;
}

static function getAllCategories() {
global $global;
$sql = "SELECT * FROM categories WHERE 1=1 ";
$sql = "SELECT * FROM categories WHERE 1=1 ";
if(!empty($_GET['parentsOnly'])){
$sql .= "AND parentId = 0 ";
}
$sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY name ASC ");

$res = $global['mysqli']->query($sql);
$category = array();
if ($res) {
while ($row = $res->fetch_assoc()) {
$category[] = $row;
}
//$category = $res->fetch_all(MYSQLI_ASSOC);
} else {
$category = false;
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $category;
}

static function getChildCategories($parentId) {
global $global;
$sql = "SELECT * FROM categories WHERE parentId=".$parentId." AND id!=".$parentId." ";

$sql .= BootGrid::getSqlFromPost(array('name'), "", " ORDER BY name ASC ");

Expand All @@ -116,10 +193,15 @@ static function getAllCategories() {
}
return $category;
}



static function getTotalCategories() {
global $global;
$sql = "SELECT id FROM categories WHERE 1=1 ";
$sql = "SELECT id, parentId FROM categories WHERE 1=1 ";
if(!empty($_GET['parentsOnly'])){
$sql .= "AND parentId = 0 OR parentId = -1 ";
}
$sql .= BootGrid::getSqlSearchFromPost(array('name'));

$res = $global['mysqli']->query($sql);
Expand Down
3 changes: 3 additions & 0 deletions objects/categoryAddNew.json.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
error_reporting(0);
header('Content-Type: application/json');
if (empty($global['systemRootPath'])) {
$global['systemRootPath'] = '../';
Expand All @@ -16,4 +17,6 @@
$obj->setDescription(nl2br ($_POST['description']));
$obj->setIconClass($_POST['iconClass']);
$obj->setNextVideoOrder($_POST['nextVideoOrder']);
$obj->setParentId($_POST['parentId']);
$obj->setType($_POST['type']);
echo '{"status":"'.$obj->save().'"}';
6 changes: 5 additions & 1 deletion objects/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static function getAllComments($videoId = 0, $comments_id_pai = 'NULL') {
return $comment;
}

static function getTotalComments($videoId = 0, $comments_id_pai = 'NULL') {
static function getTotalComments($videoId = 0, $comments_id_pai = 'NULL', $video_owner_users_id=0) {
global $global;
$sql = "SELECT c.id FROM comments c LEFT JOIN users as u ON u.id = users_id LEFT JOIN videos as v ON v.id = videos_id WHERE 1=1 ";

Expand All @@ -191,6 +191,10 @@ static function getTotalComments($videoId = 0, $comments_id_pai = 'NULL') {
$sql .= " AND comments_id_pai = {$comments_id_pai} ";
}

if(!empty($video_owner_users_id)){
$sql .= " AND v.users_id = {$video_owner_users_id} ";
}

$sql .= BootGrid::getSqlSearchFromPost(array('name'));

$res = $global['mysqli']->query($sql);
Expand Down
6 changes: 2 additions & 4 deletions objects/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function getimgsize($file_src) {
return $size;
}

function im_resize($file_src, $file_dest, $wd, $hd) {
function im_resize($file_src, $file_dest, $wd, $hd, $q = 50) {
if(empty($file_dest)){
return false;
}
Expand Down Expand Up @@ -694,9 +694,7 @@ function im_resize($file_src, $file_dest, $wd, $hd) {

imagecopyresampled($dest, $src, 0, 0, ($ws - $wc) / 2, ($hs - $hc) / 2, $wd, $hd, $wc, $hc);
$saved = false;
if (!isset($q))
$q = 50;
if ($destformat == '.png')
if ($destformat == '.png')
$saved = imagepng($dest, $file_dest);
if ($destformat == '.jpg')
$saved = imagejpeg($dest, $file_dest, $q);
Expand Down
7 changes: 5 additions & 2 deletions objects/uploadPoster.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
require_once $global['systemRootPath'] . 'objects/video.php';
$obj = new stdClass();
$obj->error = true;
if (!User::canUpload()) {
$obj->msg = 'Only logged users can file_dataoad';
if (!Video::canEdit($_GET['video_id'])) {
$obj->msg = 'You cant edit this file';
die(json_encode($obj));
}
header('Content-Type: application/json');
Expand All @@ -32,6 +32,9 @@
if (!move_uploaded_file($_FILES['file_data']['tmp_name'], "{$global['systemRootPath']}videos/" . $video->getFilename().".{$_GET['type']}")) {
$obj->msg = "Error on move_file_dataoaded_file(" . $_FILES['file_data']['tmp_name'] . ", " . "{$global['systemRootPath']}videos/" . $filename.".{$_GET['type']})";
die(json_encode($obj));
}else{
// delete thumbs from poster
Video::deleteThumbs($video->getFilename());
}
$obj->error = false;
echo "{}";
Expand Down
1 change: 1 addition & 0 deletions objects/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ static function getAllUsers() {
while ($row = $res->fetch_assoc()) {
$row['groups'] = UserGroups::getUserGroups($row['id']);
$row['tags'] = self::getTags($row['id']);
$row['name'] = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/u', '', $row['name']);
$user[] = $row;
}
//$user = $res->fetch_all(MYSQLI_ASSOC);
Expand Down
Loading

0 comments on commit 39fcae0

Please sign in to comment.