Skip to content

Commit

Permalink
Channels and Playlists added
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel authored and daniel committed Jun 27, 2017
1 parent fe310da commit 13af186
Show file tree
Hide file tree
Showing 34 changed files with 2,852 additions and 219 deletions.
10 changes: 10 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
RewriteRule ^users.json$ objects/users.json.php [NC,L]
RewriteRule ^updateUser$ objects/userUpdate.json.php [NC,L]
RewriteRule ^savePhoto$ objects/userSavePhoto.php [NC,L]
RewriteRule ^saveBackground$ objects/userSaveBackground.php [NC,L]
RewriteRule ^addNewUser$ objects/userAddNew.json.php [NC,L]
RewriteRule ^deleteUser$ objects/userDelete.json.php [NC,L]
RewriteRule ^recoverPass$ objects/userRecoverPass.php [NC,L]
Expand All @@ -71,6 +72,15 @@
RewriteRule ^addNewCategory$ objects/categoryAddNew.json.php [NC,L]
RewriteRule ^deleteCategory$ objects/categoryDelete.json.php [NC,L]

#manager playList
#RewriteRule ^playLists$ view/managerPlayLists.php [NC,L]
RewriteRule ^playLists.json$ objects/playlists.json.php [NC,L]
#RewriteRule ^addNewPlayList$ objects/playlistAddNew.json.php [NC,L]
RewriteRule ^addNewPlayList$ objects/playlistAddNew.json.php [NC,L]
RewriteRule ^playListAddVideo.json$ objects/playListAddVideo.json.php [NC,L]
RewriteRule ^channel/([0-9]+)/?$ view/channel.php?user_id=$1 [NC,L]
RewriteRule ^channel/?$ view/channel.php [NC,L]

#manager videos
RewriteRule ^orphanFiles$ view/orphanFiles.php [NC,L]
RewriteRule ^mvideos$ view/managerVideos.php [NC,L]
Expand Down
2 changes: 1 addition & 1 deletion install/checkConfiguration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$installationVersion = "3.1";
$installationVersion = "3.2";

header('Content-Type: application/json');

Expand Down
69 changes: 46 additions & 23 deletions install/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema youPHPTube
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Table `users`
-- -----------------------------------------------------
Expand All @@ -24,6 +20,7 @@ CREATE TABLE IF NOT EXISTS `users` (
`photoURL` VARCHAR(255) NULL,
`lastLogin` DATETIME NULL,
`recoverPass` VARCHAR(255) NULL,
`backgroundURL` VARCHAR(255) NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `user_UNIQUE` (`user` ASC))
ENGINE = InnoDB;
Expand Down Expand Up @@ -334,40 +331,66 @@ CREATE TABLE IF NOT EXISTS `video_ads_logs` (
ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `video_documents`
-- Table `subscribes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `video_documents` (
CREATE TABLE IF NOT EXISTS `subscribes` (
`id` INT NOT NULL AUTO_INCREMENT,
`doc_name` VARCHAR(255) NOT NULL,
`doc_description` TEXT NULL,
`email` VARCHAR(100) NOT NULL,
`status` ENUM('a', 'i') NOT NULL DEFAULT 'a',
`created` DATETIME NULL,
`modified` DATETIME NULL,
`blob` BLOB NOT NULL,
`videos_id` INT NOT NULL,
`ip` VARCHAR(45) NULL,
`users_id` INT NOT NULL COMMENT 'subscribes to user channel',
PRIMARY KEY (`id`),
INDEX `fk_video_documents_videos1_idx` (`videos_id` ASC),
CONSTRAINT `fk_video_documents_videos1`
FOREIGN KEY (`videos_id`)
REFERENCES `videos` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
INDEX `fk_subscribes_users1_idx` (`users_id` ASC),
CONSTRAINT `fk_subscribes_users1`
FOREIGN KEY (`users_id`)
REFERENCES `users` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `subscribes`
-- Table `playlists`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `subscribes` (
CREATE TABLE IF NOT EXISTS `playlists` (
`id` INT NOT NULL AUTO_INCREMENT,
`email` VARCHAR(100) NOT NULL,
`status` ENUM('a', 'i') NOT NULL DEFAULT 'a',
`name` VARCHAR(45) NOT NULL,
`created` DATETIME NULL,
`modified` DATETIME NULL,
`ip` VARCHAR(45) NULL,
`users_id` INT NOT NULL,
`status` ENUM('public', 'private') NOT NULL DEFAULT 'public',
PRIMARY KEY (`id`),
UNIQUE INDEX `email_UNIQUE` (`email` ASC))
INDEX `fk_playlists_users1_idx` (`users_id` ASC),
CONSTRAINT `fk_playlists_users1`
FOREIGN KEY (`users_id`)
REFERENCES `users` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `playlists_has_videos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `playlists_has_videos` (
`playlists_id` INT NOT NULL,
`videos_id` INT NOT NULL,
PRIMARY KEY (`playlists_id`, `videos_id`),
INDEX `fk_playlists_has_videos_videos1_idx` (`videos_id` ASC),
INDEX `fk_playlists_has_videos_playlists1_idx` (`playlists_id` ASC),
CONSTRAINT `fk_playlists_has_videos_playlists1`
FOREIGN KEY (`playlists_id`)
REFERENCES `playlists` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_playlists_has_videos_videos1`
FOREIGN KEY (`videos_id`)
REFERENCES `videos` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;


Expand Down
185 changes: 185 additions & 0 deletions objects/Object.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?php

abstract class Object{

abstract static protected function getTableName();
abstract static protected function getSearchFieldsNames();
private $fieldsName = array();

protected function load($id) {
$user = self::getFromDb($id);
if (empty($user))
return false;
foreach ($user as $key => $value) {
$this->$key = $value;
}
return true;
}


function __construct($id) {
if (!empty($id)) {
// get data from id
$this->load($id);
}
}

static protected function getFromDb($id) {
global $global;
$id = intval($id);
$sql = "SELECT * FROM ".static::getTableName()." WHERE id = $id LIMIT 1";
$res = $global['mysqli']->query($sql);
if ($res) {
$user = $res->fetch_assoc();
} else {
$user = false;
}
return $user;
}

static function getAll() {
global $global;
$sql = "SELECT * FROM ".static::getTableName()." WHERE 1=1 ";

$sql .= self::getSqlFromPost();

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


static function getTotal() {
//will receive
//current=1&rowCount=10&sort[sender]=asc&searchPhrase=
global $global;
$sql = "SELECT id FROM ".static::getTableName()." WHERE 1=1 ";

$sql .= self::getSqlSearchFromPost();

$res = $global['mysqli']->query($sql);


return $res->num_rows;
}


static function getSqlFromPost() {
$sql = self::getSqlSearchFromPost();

if(!empty($_POST['sort'])){
$orderBy = array();
foreach ($_POST['sort'] as $key => $value) {
$orderBy[] = " {$key} {$value} ";
}
$sql .= " ORDER BY ".implode(",", $orderBy);
}else{
//$sql .= " ORDER BY CREATED DESC ";
}

if(!empty($_POST['rowCount']) && !empty($_POST['current']) && $_POST['rowCount']>0){
$current = ($_POST['current']-1)*$_POST['rowCount'];
$sql .= " LIMIT $current, {$_POST['rowCount']} ";
}else{
$_POST['current'] = 0;
$_POST['rowCount'] = 0;
$sql .= " LIMIT 12 ";
}
return $sql;
}

static function getSqlSearchFromPost() {
$sql = "";
if(!empty($_POST['searchPhrase'])){
$_GET['q'] = $_POST['searchPhrase'];
}
if(!empty($_GET['q'])){
global $global;
$search = $global['mysqli']->real_escape_string($_GET['q']);

$like = array();
$searchFields = static::getSearchFieldsNames();
foreach ($searchFields as $value) {
$like[] = " {$value} LIKE '%{$search}%' ";
}
if(!empty($like)){
$sql .= " AND (". implode(" OR ", $like).")";
}else{
$sql .= " AND 1=1 ";
}
}

return $sql;
}

function save(){
global $global;
$fieldsName = $this->getAllFields();
if (!empty($this->id)) {
$sql = "UPDATE ".static::getTableName()." SET ";
$fields = array();
foreach ($fieldsName as $value) {
if(strtolower($value) == 'created' ){
// do nothing
}else if(strtolower($value) == 'modified' ){
$fields[] = " {$value} = now() ";
}else {
$fields[] = " {$value} = '{$this->$value}' ";
}
}
$sql .= implode(", ", $fields);
$sql .= " WHERE id = {$this->id}";
} else {
$sql = "INSERT INTO ".static::getTableName()." ( ";
$sql .= implode(",", $fieldsName). " )";
$fields = array();
foreach ($fieldsName as $value) {
if(strtolower($value) == 'created' || strtolower($value) == 'modified' ){
$fields[] = " now() ";
}else if(!isset($this->$value)){
$fields[] = " NULL ";
}else{
$fields[] = " '{$this->$value}' ";
}
}
$sql .= " VALUES (".implode(", ", $fields).")";
}
//echo $sql;
$insert_row = $global['mysqli']->query($sql);

if ($insert_row) {
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);
}
}

private function getAllFields(){
global $global, $mysqlDatabase;
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{$mysqlDatabase}' AND TABLE_NAME = '".static::getTableName()."'";

$res = $global['mysqli']->query($sql);
$rows = array();
if ($res) {
while ($row = $res->fetch_assoc()) {
$rows[] = $row["COLUMN_NAME"];
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $rows;
}
}

10 changes: 0 additions & 10 deletions objects/configurationUpdate.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
$config->setFfmpegMp3($_POST['ffmpegMp3']);
$config->setFfmpegOgg($_POST['ffmpegOgg']);
$config->setYoutubeDl($_POST['youtubeDl']);
$config->setYoutubeDlPath($_POST['youtubeDlPath']);
$config->setFfmpegPath($_POST['ffmpegPath']);
$config->setExiftoolPath($_POST['exiftoolPath']);
$config->setExiftool($_POST['exiftool']);
$config->setFfmpegMp4Portrait($_POST['ffmpegMp4Portrait']);
$config->setFfmpegWebmPortrait($_POST['ffmpegWebmPortrait']);
Expand All @@ -45,13 +42,6 @@
$config->setEncode_webm($_POST['encode_webm']);
$config->setEncode_mp3spectrum($_POST['encode_mp3spectrum']);
$config->setFfmpegSpectrum($_POST['ffmpegSpectrum']);
}else{
$config->setDisable_analytics($config->getDisable_analytics());
$config->setSession_timeout($config->getSession_timeout());
$config->setEncode_mp4($config->getEncode_mp4());
$config->setEncode_webm($config->getEncode_webm());
$config->setEncode_mp3spectrum($config->getEncode_mp3spectrum());
$config->setFfmpegSpectrum($config->getFfmpegSpectrum());
}

$config->setHead($_POST['head']);
Expand Down
1 change: 1 addition & 0 deletions objects/include_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@

session_start();

require_once $global['systemRootPath'].'objects/Object.php';
require_once $global['systemRootPath'].'locale/function.php';
11 changes: 9 additions & 2 deletions objects/notifySubscribers.json.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php
require_once '../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/user.php';
if (!User::isAdmin()) {

if(!User::canUpload()){
header("Location: {$global['webSiteRootURL']}?error=" . __("You can not notify"));
exit;
}
$user_id = User::getId();
// if admin bring all subscribers
if(User::isAdmin()){
$user_id = "";
}

require_once 'subscribe.php';
header('Content-Type: application/json');
$Subscribes = Subscribe::getAllSubscribes();
$Subscribes = Subscribe::getAllSubscribes($user_id);
require_once $global['systemRootPath'] . 'objects/PHPMailer/PHPMailerAutoload.php';

$obj = new stdClass();
Expand Down
18 changes: 18 additions & 0 deletions objects/playListAddVideo.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
header('Content-Type: application/json');
if(empty($global['systemRootPath'])){
$global['systemRootPath'] = "../";
}
require_once $global['systemRootPath'].'videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/user.php';
require_once $global['systemRootPath'] . 'objects/playlist.php';
if (!User::isLogged()) {
die('{"error":"'.__("Permission denied").'"}');
}

$obj = new PlayList($_POST['playlists_id']);
if(empty($obj || User::getId()!=$obj->getUsers_id()) || empty($_POST['videos_id'])){
return false;
}

echo '{"status":"'.$obj->addVideo($_POST['videos_id'], $_POST['add']).'"}';
Loading

0 comments on commit 13af186

Please sign in to comment.