forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
daniel
authored and
daniel
committed
Jun 27, 2017
1 parent
fe310da
commit 13af186
Showing
34 changed files
with
2,852 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']).'"}'; |
Oops, something went wrong.