Skip to content

Commit

Permalink
Patch.
Browse files Browse the repository at this point in the history
Improves PHP code style normalisation to reduce inconsistency, refactors
and simplifies some PHP code, slightly beautifies some CSS code.
  • Loading branch information
Maikuolan committed Sep 16, 2017
1 parent a6ad438 commit 40ecbd2
Show file tree
Hide file tree
Showing 93 changed files with 984 additions and 1,054 deletions.
8 changes: 5 additions & 3 deletions locale/function.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
if(empty($config)){
if (empty($config)) {
return true;
}
if (empty($_SESSION['language'])) {
Expand Down Expand Up @@ -39,7 +39,7 @@ function getEnabledLangs() {
global $global;
$dir = "{$global['systemRootPath']}locale";
$flags = array();
if(empty($global['dont_show_us_flag'])){
if (empty($global['dont_show_us_flag'])) {
$flags[] = 'us';
}
if ($handle = opendir($dir)) {
Expand All @@ -56,5 +56,7 @@ function getEnabledLangs() {

function textToLink($string) {
return preg_replace(
"~[[:alpha:]]+:https://[^<>[:space:]'\"]+[[:alnum:]/]~", "<a href=\"\\0\">\\0</a>", $string);
"~[[:alpha:]]+:https://[^<>[:space:]'\"]+[[:alnum:]/]~", "<a href=\"\\0\">\\0</a>",
$string
);
}
70 changes: 33 additions & 37 deletions objects/Object.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

abstract class Object{

abstract static protected function getTableName();
abstract static protected function getSearchFieldsNames();
private $fieldsName = array();
Expand All @@ -16,14 +15,13 @@ protected function load($id) {
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);
Expand All @@ -36,13 +34,13 @@ static protected function getFromDb($id) {
}
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) {
Expand All @@ -54,10 +52,9 @@ static function getAll() {
}
return $rows;
}



static function getTotal() {
//will receive
//will receive
//current=1&rowCount=10&sort[sender]=asc&searchPhrase=
global $global;
$sql = "SELECT id FROM ".static::getTableName()." WHERE 1=1 ";
Expand All @@ -70,90 +67,90 @@ static function getTotal() {
return $res->num_rows;
}


static function getSqlFromPost() {
$sql = self::getSqlSearchFromPost();
if(!empty($_POST['sort'])){

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

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

static function getSqlSearchFromPost() {
$sql = "";
if(!empty($_POST['searchPhrase'])){
if (!empty($_POST['searchPhrase'])) {
$_GET['q'] = $_POST['searchPhrase'];
}
if(!empty($_GET['q'])){
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).")";
$sql .= " AND (". implode(" OR ", $like).")";
}else{
$sql .= " AND 1=1 ";
}
}

return $sql;
}
function save(){

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' ){
if (strtolower($value) == 'created') {
// do nothing
}else if(strtolower($value) == 'modified' ){
} elseif (strtolower($value) == 'modified') {
$fields[] = " {$value} = now() ";
}else {
} else {
$fields[] = " {$value} = '{$this->$value}' ";
}
}
}
$sql .= implode(", ", $fields);
$sql .= " WHERE id = {$this->id}";
} else {
$sql = "INSERT INTO ".static::getTableName()." ( ";
$sql .= implode(",", $fieldsName). " )";
$sql .= implode(",", $fieldsName). " )";
$fields = array();
foreach ($fieldsName as $value) {
if(strtolower($value) == 'created' || strtolower($value) == 'modified' ){
if (strtolower($value) == 'created' || strtolower($value) == 'modified') {
$fields[] = " now() ";
}else if(!isset($this->$value)){
} elseif (!isset($this->$value)) {
$fields[] = " NULL ";
}else{
} 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;
Expand All @@ -165,11 +162,11 @@ function save(){
die($sql . ' Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
}
private function getAllFields(){

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) {
Expand All @@ -182,4 +179,3 @@ private function getAllFields(){
return $rows;
}
}

19 changes: 8 additions & 11 deletions objects/bootGrid.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

class BootGrid {

static function getSqlFromPost($searchFieldsNames = array(), $keyPrefix = "") {
$sql = self::getSqlSearchFromPost($searchFieldsNames);
if(!empty($_POST['sort'])){

if (!empty($_POST['sort'])) {
$orderBy = array();
foreach ($_POST['sort'] as $key => $value) {
$orderBy[] = " {$keyPrefix}{$key} {$value} ";
}
$sql .= " ORDER BY ".implode(",", $orderBy);
}else{
} 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']} ";
Expand All @@ -24,27 +23,25 @@ static function getSqlFromPost($searchFieldsNames = array(), $keyPrefix = "") {
}
return $sql;
}

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

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

return $sql;
}



}
59 changes: 31 additions & 28 deletions objects/captcha.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

if(empty($global['systemRootPath'])){
$global['systemRootPath'] = "../";
if (empty($global['systemRootPath'])) {
$global['systemRootPath'] = '../';
}
require_once $global['systemRootPath'].'videos/configuration.php';
require_once $global['systemRootPath'] . 'videos/configuration.php';
class Captcha{
private $largura, $altura, $tamanho_fonte, $quantidade_letras;

function __construct($largura, $altura, $tamanho_fonte, $quantidade_letras) {
if (session_status() == PHP_SESSION_NONE) {
session_start();
Expand All @@ -17,37 +16,41 @@ function __construct($largura, $altura, $tamanho_fonte, $quantidade_letras) {
$this->quantidade_letras = $quantidade_letras;
}

public function getCaptchaImage(){

public function getCaptchaImage() {
global $global;
header("Content-type: image/jpeg");
header('Content-type: image/jpeg');
$imagem = imagecreate($this->largura,$this->altura); // define a largura e a altura da imagem
$fonte = $global['systemRootPath'] . "objects/monof55.ttf"; //voce deve ter essa ou outra fonte de sua preferencia em sua pasta
$preto = imagecolorallocate($imagem,0,0,0); // define a cor preta
$branco = imagecolorallocate($imagem,255,255,255); // define a cor branca
$fonte = $global['systemRootPath'] . 'objects/monof55.ttf'; //voce deve ter essa ou outra fonte de sua preferencia em sua pasta
$preto = imagecolorallocate($imagem, 0, 0, 0); // define a cor preta
$branco = imagecolorallocate($imagem, 255, 255, 255); // define a cor branca

// define a palavra conforme a quantidade de letras definidas no parametro $quantidade_letras
//$letters = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnPpQqRrSsTtUuVvYyXxWwZz23456789";
$letters = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnPpQqRrSsTtUuVvYyXxWwZz23456789";
$palavra = substr(str_shuffle($letters),0,($this->quantidade_letras));
//$letters = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnPpQqRrSsTtUuVvYyXxWwZz23456789';
$letters = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnPpQqRrSsTtUuVvYyXxWwZz23456789';
$palavra = substr(str_shuffle($letters), 0, ($this->quantidade_letras));
$_SESSION["palavra"] = $palavra; // atribui para a sessao a palavra gerada
for($i = 1; $i <= $this->quantidade_letras; $i++){
imagettftext($imagem,$this->tamanho_fonte,rand(-10,10),($this->tamanho_fonte*$i),($this->tamanho_fonte + 10),$branco,$fonte,substr($palavra,($i-1),1)); // atribui as letras a imagem
for ($i = 1; $i <= $this->quantidade_letras; $i++) {
imagettftext(
$imagem,
$this->tamanho_fonte,
rand(-10, 10),
($this->tamanho_fonte*$i),
($this->tamanho_fonte + 10),
$branco,
$fonte,
substr($palavra, ($i - 1), 1)
); // atribui as letras a imagem
}
imagejpeg($imagem); // gera a imagem
imagedestroy($imagem); // limpa a imagem da memoria
}
static public function validation($word){

static public function validation($word) {
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (strcasecmp($word, $_SESSION["palavra"])==0){
return true;
}else{
return false;
}
}


}
return (strcasecmp($word, $_SESSION["palavra"]) == 0);
}

}
3 changes: 1 addition & 2 deletions objects/categories.json.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

require_once 'category.php';
header('Content-Type: application/json');
$categories = Category::getAllCategories();
$total = Category::getTotalCategories();
foreach ($categories as $key => $value) {
$categories[$key]['iconHtml'] = "<span class='$value[iconClass]'></span>";
}
echo '{ "current": '.$_POST['current'].',"rowCount": '.$_POST['rowCount'].', "total": '.$total.', "rows":'. json_encode($categories).'}';
echo '{ "current": '.$_POST['current'].',"rowCount": '.$_POST['rowCount'].', "total": '.$total.', "rows":'. json_encode($categories).'}';
Loading

0 comments on commit 40ecbd2

Please sign in to comment.