Файловый менеджер - Редактировать - /var/www/vhosts/morphe2.dev1.mndrn.cloud/OlD/libs/standardObject.lib.php
Назад
<?php ### GYURAL ### class standardObject { var $gyu_id = 'id'; // Filter the query! public function filter() { $className = get_class($this); $args = func_get_args(); $whereC = array(); $endQ = array(); $isArray = 1; foreach($args as $a) { if(is_array($a)) { if(count($a) == 2) { list($key, $value) = $a; $operator = '='; } else list($key, $operator, $value) = $a; if($operator == 'LIKE') $whereC[] = "`".$key."` " . $operator . " '%" . $value . "%'"; else $whereC[] = "`".$key."` " . $operator . " '" . $value . "'"; } else { if($a == 'ONE') $isArray = 0; else $endQ[] = $a; } } $label = $whereC ? ' WHERE ' : ''; $query = "SELECT * FROM `".$this->gyu_table."` " . $label . implode(' AND ', $whereC) . ' ' . implode(" ", $endQ); return(FetchObject(Database()->query($query), $isArray, $className)); } // Get! public function get($index) { return $this->filter(array($this->gyu_id, $index), 'LIMIT 1', 'ONE'); } // Render the $name from the object { try to call rendername(); } public function render($name) { if(method_exists($this, 'render' . ucFirst($name))) return call_user_func(array($this, 'render' . ucFirst($name))); else return stripslashes($this->$name); } // Not null public function notNull($what) { if(strlen($this->getAttr($what)) > 0 && $this->getAttr($what) != 0) return true; else return false; } ########################### ## Manipulate the Object ## ########################### // Get the $name attr from the object. { try to call getname(); } public function getAttr($name) { if(method_exists($this, 'get' . ucFirst($name))) return call_user_func(array($this, 'get' . ucFirst($name))); else return stripslashes($this->$name); } // Set the $key attribute with the $vValue value public function setAttr($key, $vValue) { if(method_exists($this, 'set' . ucFirst($key))) return call_user_func(array($this, 'set' . ucFirst($key)), $vValue); else return $this->$key = $vValue; } // Refill the object with the $vArray values. public function refill($vArray = null) { if(!$vArray) return false; foreach($vArray as $key=>$vValue) $this->setAttr($key, $vValue); return $this; } ############################## ## Insert an object into db ## ############################## // $object->hang() ==> prepare the query to insert the object in the database. public function hang($vArray = null) { if($vArray) $this->refill($vArray); return CreateQuery('I', $this->gyu_table, $this); } // $object->hangExecute() ==> execute the query, prepared by ->hang(); public function hangExecute($vArray = null) { if($query = $this->hang($vArray)) { Database()->query($query); return Database()->insert_id; } } ############################## ## Update an Object into db ## ############################## // $object->put() ==> prepare the query to update the object in the database. public function put($vArray = null, $id = null) { if(isset($vArray) && !is_array($vArray)) $id = $vArray; else if(isset($vArray)) $this->refill($vArray); if($id == null) $id = 'id = ' . $this->getAttr('id'); return CreateQuery('U', $this->gyu_table, $this, $id); } // $object->putExecute() ==> execute the query, prepared by ->put(); public function putExecute($vArray = null, $id = null) { if($query = $this->put($vArray, $id)) return Database()->query($query); } ############################## ## Delete an object from db ## ############################## // $object->delete() ==> prepare the query to delete the object in the database. public function delete($id = null) { if(!$id) $id = 'id = ' . $this->id; return "DELETE FROM `" . $this->gyu_table . "` WHERE " . $id; } // $object->deleteExecute() ==> execute the query, prepared by ->delete(); public function deleteExecute($id = null) { if($query = $this->delete($id)) return Database()->query($query); } ################ ## Formatting ## ################ // $categorie[0]->format('<li>{{name}} e {{madre}}</li>'); public function format($template, $externalVars) { $pattern = '/\{\{([^}]*)\}\}/i'; preg_match_all($pattern, $template, $res); list($originali, $chiavi) = $res; foreach($chiavi as $intKey => $value) { if(strstr($value, '.')) list($value, $subValue) = explode(".", $value); if(!isset($externalVars[$value])) { if(!isset($subValue)) $replace[$intKey] = $this->getAttr($value); else $replace[$intKey] = $this->getAttr($value)->getAttr($subValue); } else $replace[$intKey] = $externalVars[$value]; } $parsed = str_replace($originali, $replace, $template); echo($parsed); } } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.5 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка