public function avatar() { $mime = File::getMimeType(self::DEFAULT_AVATAR); Header::content_type($mime); echo file_get_contents(self::DEFAULT_AVATAR); Core::endApplication(); }
/** * Constructor */ public function __construct() { $this->smarty = new Smarty(); $this->smarty->assign("path_to_theme", Core::$path_to_theme); $this->smarty->assign("server_url", Configuration::$server_url); Core::setupSmarty($this->smarty); $this->phpmailer = new PHPMailer(); }
public function retrieve_states() { if (!Core::checkRequiredGetVars('id_link')) { Core::performResponse('Missing argument'); } $m = new ModelLink(); $s = $m->getStatesByLink($_GET['id_link']); Core::performResponse(SimpleJSON::encode($s), 'json'); }
public function index() { $cat = null; if (Core::checkRequiredGetVars('cat')) { $cat = $_GET['cat']; } $this->setTitle('Achilles'); $m = new ModelPost(); $this->addContent('posts', $m->getPostsByDay($cat)); }
public function scrap() { if (!isset($_POST) || !isset($_POST["url"])) { Core::performResponse(SimpleJSON::encode(array("error" => "Url missing.")), "json"); } $return = array("request" => array("post" => $_POST)); $url = $_POST["url"]; $m = new ModelPost(); try { $return["data"] = $m->retrieveDataFrom($url); } catch (\Exception $e) { Core::performResponse(SimpleJSON::encode(array("error" => "Unable to retrieve infos.", "details" => $e->getMessage())), "json"); } Core::performResponse(SimpleJSON::encode($return), "json"); }
function smarty_function_rewriteurl($params, &$smarty) { $controller = ""; $action = ""; $langue = ""; extract($params); $param = array(); foreach ($params as $name => $value) { if ($name == "controller" || $name == "action" || $name == "langue") { continue; } $param[$name] = $value; } echo Core::rewriteURL($controller, $action, $param, $langue); }
function smarty_function_getPagination($params, &$smarty) { $test = false; $info = array(); $noPage = 0; extract($params); if (empty($info) || $info["nbPages"] < 2) { return; } if (isset($info["noPage"])) { $noPage = $info["noPage"]; } if (isset($_GET["page"])) { $test = true; } $_GET["page"] = $info["currentPage"] - 1; echo '<div class="pagination"><div class="previous">'; echo '<a href="' . Core::rewriteURL(Core::$controller, Core::$action, $_GET) . '" class="button ' . ($info["currentPage"] == 1 ? 'disabled' : '') . '">' . Dictionary::term("global.pagination.previous") . '</a> '; echo '</div><div class="pages">'; if ($noPage) { echo $info["currentPage"] . " / " . $info["nbPages"]; } else { for ($i = 1; $i <= $info["nbPages"]; ++$i) { if ($i == 1 || $i == $info["currentPage"] || $i == $info["currentPage"] + 1 || $i == $info["currentPage"] - 1 || $i == $info["nbPages"]) { $_GET["page"] = $i; if ($i > 1) { echo ' - '; } if ($i == $info["currentPage"]) { echo '<span class="current_page">' . $i . '</span>'; } else { echo '<a href="' . Core::rewriteURL(Core::$controller, Core::$action, $_GET) . '" class="button">' . $i . '</a>'; } } if (($i == $info["currentPage"] + 2 || $i == $info["currentPage"] - 2) && ($i != 1 && $i != $info["nbPages"])) { echo " - ... "; } } } echo '</div>'; $_GET["page"] = $info["currentPage"] + 1; echo '<div class="next">'; echo '<a href="' . Core::rewriteURL(Core::$controller, Core::$action, $_GET) . '" class="button ' . ($info["currentPage"] == $info["nbPages"] || !$info["nbPages"] ? 'disabled' : '') . '">' . Dictionary::term("global.pagination.next") . '</a>'; echo "</div></div>"; if (!$test) { unset($_GET["page"]); } }
public function update() { if (!Core::checkRequiredGetVars('permalink_list', 'prop_list') || !isset($_POST) || empty($_POST) || !isset($_POST['value']) || empty($_POST['value'])) { Go::to404(); } $m = new ModelList(); $list = $m->one(Query::condition()->andWhere('permalink_list', Query::EQUAL, $_GET['permalink_list'])); if (!$list) { Go::to404(); } $name = $_GET['prop_list']; if ($m->updateById($list['id_list'], array($name => $_POST['value']))) { $response = array("message" => "ok"); } else { $response = array("error", "Unable to perform an update on field '" . $name . "'"); } $response = SimpleJSON::encode($response); Core::performResponse($response, 'json'); }
public function __construct($pFile) { if (!file_exists($pFile)) { return; } $this->items = SimpleJSON::import($pFile); if (!$this->items) { trigger_error('[Object Menu] No Items loaded', E_USER_NOTICE); } foreach ($this->items as &$item) { if (!isset($item['parameters'])) { $item['parameters'] = array(); } if (!isset($item['controller'])) { $item['controller'] = ''; } if (!isset($item['action'])) { $item['action'] = ''; } $item['current'] = Core::$controller == $item['controller'] && Core::$action == $item['action']; $item['url'] = Core::rewriteURL($item['controller'], $item['action'], $item['parameters']); } }
private function response($response) { Core::performResponse(json_encode($response), "json"); }
public function plz_update() { $m = new ModelLink(); $m->updatePriceLinks(); Core::performResponse('bouboup'); }
/** * @param array|null $pParams * @param Smarty $pSmarty * @param bool $pReturn * @return string|void */ public function display(array $pParams = null, &$pSmarty = null, $pReturn = false) { $noForm = false; $noMandatory = false; $output = $idForm = $classes = ""; $controller = Core::$controller; $action = Core::$action; $helper = "core\\tools\\form\\FormHelpers"; if ($pParams != null) { extract($pParams, EXTR_REFS); } if (!$noForm) { $n = array(); $s = array("controller", "action", "noForm", "noMandatory", "helper", "idForm", "classes"); foreach ($pParams as $np => $vp) { if (in_array($np, $s)) { continue; } $n[$np] = $vp; } $pParams = $n; $output .= '<form action="' . Core::rewriteURL($controller, $action, $pParams, Application::getInstance()->currentLanguage) . '" method="post"'; if ($this->hasUpload) { $output .= ' enctype="multipart/form-data"'; } if (!empty($idForm)) { $output .= ' id="' . $idForm . '" '; } if (!empty($classes)) { $output .= ' class="' . $classes . '" '; } $output .= '>'; } if ($this->countMendatory > 0 && !$noMandatory) { $output .= "<div class='mandatory'>* "; if ($this->countMendatory == 1) { $output .= Dictionary::term("global.forms.inputRequire"); } else { $output .= Dictionary::term("global.forms.inputsRequire"); } $output .= "</div>"; } foreach ($this->data as $n => $d) { $require = ""; if ($d["require"] == true) { $require = "*"; } if (!isset($d["tag"])) { continue; } if ($d["tag"] == "input" && $d["attributes"]["type"] == "file") { $d["tag"] = self::TAG_UPLOAD; } $id = "inp_" . $this->name . "_" . $n; if (strrpos($n, "[") > -1) { $n = str_replace("[", "][", $n); $name = $this->name . "[" . $n; } else { $name = $this->name . "[" . $n . "]"; } $d["form_name"] = $this->name; $d["field_name"] = $n; if (call_user_func_array(array($helper, "has"), array($d["tag"]))) { $output .= call_user_func_array($helper . "::get", array($d["tag"], array($name, $id, $d, $require))); } } if (!$noForm) { $output .= "</form>"; } if ($pReturn == true) { return $output; } echo $output; }
/** * @param string $pContent */ private function output($pContent) { Header::content_length(strlen($pContent)); echo $pContent; Core::endApplication(); }
<?php date_default_timezone_set("Europe/Paris"); define("MEMORY_REAL_USAGE", true); $timeInit = microtime(true); $memInit = memory_get_usage(MEMORY_REAL_USAGE); require_once __DIR__ . "/includes/libs/core/application/class.Singleton.php"; require_once __DIR__ . "/includes/libs/core/application/class.Autoload.php"; use core\application\Autoload; use core\application\Core; Autoload::$folder = __DIR__; spl_autoload_register(array(Autoload::getInstance(), "load")); Core::checkEnvironment(); Core::init(); Core::parseURL(); Core::execute(Core::getController(), Core::getAction(), Core::getTemplate()); Core::endApplication();
/** * @static * @param DefaultController|null $pController * @param null $pAction * @param string $pTemplate * @return void */ public static function execute($pController = null, $pAction = null, $pTemplate = "") { if ($pController != "statique") { $pController->setTemplate(self::$controller, self::$action, $pTemplate); } if ($pAction != null) { $pController->{$pAction}(); } if (!Core::$request_async) { Header::content_type("text/html"); $pController->render(); if (Core::debug()) { Debugger::render(); } } else { $return = $pController->getGlobalVars(); $return = array_merge($return, Debugger::getGlobalVars()); if (isset($_POST) && isset($_POST["render"]) && $_POST["render"] != "false") { $return["html"] = $pController->render(false); } $response = SimpleJSON::encode($return); $type = "json"; self::performResponse($response, $type); } }
/** * Gestionnaire des erreurs de scripts Php * Peut stopper l'application en cas d'erreur bloquante * @param Number $pErrorLevel Niveau d'erreur * @param String $pErrorMessage Message renvoyé * @param String $pErrorFile Adresse du fichier qui a déclenché l'erreur * @param Number $pErrorLine Ligne où se trouve l'erreur * @param String $pErrorContext Contexte * @return void */ public static function errorHandler($pErrorLevel, $pErrorMessage, $pErrorFile, $pErrorLine, $pErrorContext) { $stopApplication = false; switch ($pErrorLevel) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: $stopApplication = true; $type = "error"; break; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: $type = "warning"; break; case E_NOTICE: case E_USER_NOTICE: $type = "notice"; break; default: case self::E_USER_EXCEPTION: $stopApplication = true; $type = "error"; break; } $pErrorFile = pathinfo($pErrorFile); $pErrorFile = $pErrorFile["basename"]; if (preg_match('/href=/', $pErrorMessage, $matches)) { $pErrorMessage = preg_replace('/href=\'([a-z\\.\\-\\_]*)\'/', 'href=\'http://www.php.net/$1\' target=\'_blank\'', $pErrorMessage); } self::addToConsole($type, $pErrorMessage, $pErrorFile, $pErrorLine); if ($stopApplication) { if (!Core::debug()) { Logs::write($pErrorMessage . " " . $pErrorFile . " " . $pErrorLine . " " . $pErrorContext, $pErrorLevel); } Header::content_type("text/html", Configuration::$global_encoding); self::$open = true; self::render(true, true); Core::endApplication(); } }
/** * Méthode public de rendu de la page en cours * @param bool $pDisplay * @return string */ public function render($pDisplay = true) { $smarty = new Smarty(); Core::setupSmarty($smarty); if (!$smarty->template_exists($this->template)) { if (Core::debug()) { trigger_error("Le template <b>" . $this->template . "</b> est introuvable", E_USER_ERROR); } else { Go::to404(); } } $conf = get_class_vars('core\\application\\Configuration'); $terms = Dictionary::terms(); $globalVars = $this->getGlobalVars(); $smarty->assign_by_ref("configuration", $conf); $smarty->assign_by_ref("request_async", Core::$request_async); $smarty->assign_by_ref("dictionary", $terms); foreach ($this->forms as $n => &$form) { $smarty->register_object("form_" . $n, $form, array("display", "name", "getValue", "getLabel", "getOptions", "isChecked")); } foreach ($globalVars as $n => &$v) { $smarty->assign_by_ref($n, $v); } if (!Core::debug()) { $smarty->load_filter('output', 'gzip'); } return $smarty->fetch($this->template, null, null, $pDisplay); }