Пример #1
0
 public function sign_out()
 {
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     $auth::getInstance()->unsetUserSession();
     Go::to();
 }
Пример #2
0
 public function __construct()
 {
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     $auth::getInstance();
     $this->addContent('user_data', AuthenticationHandler::$data);
     $m = new ModelCategory();
     $this->addContent('categories', $m->all(Query::condition()->order('name_category', 'ASC')));
 }
Пример #3
0
 public function share()
 {
     Autoload::addComponent("Achilles.share");
     $this->setTitle("Submit a link");
     /** @var AuthenticationHandler $auth */
     $auth = Application::getInstance()->authenticationHandler;
     if (!$auth::is(AuthenticationHandler::USER)) {
         Go::to404();
     }
     $m = new ModelPost();
     $form = new Form("post_share");
     if ($form->isValid()) {
         $v = $form->getValues();
         $insertedPermalink = $m->share($v);
         Header::location('post/' . $insertedPermalink);
     } else {
         $this->addContent("error", $form->getError());
     }
     $this->addForm("share", $form);
 }
Пример #4
0
 /**
  * ATTENTION AU NAME DE L'INPUT
  * ==> FORM[INPUTNAME] <==
  *
  * ATTENTION A LA TECHNIQUE DE RENVOIE D'INFORMATION !M&eacute;thode priv&eacute;e
  *
  * @return void
  */
 public function upload_async()
 {
     $datas = null;
     $response = array("error" => "");
     if (!isset($_POST["form_name"]) || empty($_POST["form_name"])) {
         $response["error"] = '$_POST["form_name"] require';
         $this->response($response);
     }
     if (!isset($_POST["input_name"]) || empty($_POST["input_name"])) {
         $response["error"] = '$_POST["input_name"] require';
         $this->response($response);
     }
     $file = $_FILES[$_POST["input_name"]];
     if (!isset($file) || empty($file)) {
         $response["error"] = "Aucun fichier n'a été transmis";
     }
     if (empty($response["error"])) {
         $app = $_POST["application"];
         $path_to_form = "includes/applications/" . $app . "/modules/";
         if (isset($_POST["module"]) && !empty($_POST['module'])) {
             $path_to_form .= $_POST["module"] . "/";
         } else {
             $path_to_form .= "front/";
         }
         $form_name = $_POST["form_name"];
         $path_to_form .= "forms/form." . $form_name . ".json";
         if (!file_exists($path_to_form)) {
             $path_to_form = preg_replace("/_[0-9]+\\.json\$/", ".json", $path_to_form);
         }
         try {
             $datas = SimpleJSON::import($path_to_form);
         } catch (Exception $e) {
             $response["error"] = "Formulaire introuvable " . $path_to_form;
             $this->response($response);
         }
         if (!is_array($datas[$_POST["input_name"]])) {
             $response["error"] = "Champs cibl&eacute; introuvable";
             $this->response($response);
         }
         $input = $datas[$_POST["input_name"]];
         if ($input["tag"] != Form::TAG_UPLOAD && ($input["tag"] != "input" && $input["attributes"]["type"] != "file")) {
             $response["error"] = "Le champ ciblé n'est pas un input type 'file'";
             $this->response($response);
         }
         $fileName = "";
         if (isset($input["fileName"])) {
             $fileName = "file" . rand(0, 999999);
         }
         $folderName = Form::PATH_TO_UPLOAD_FOLDER;
         if (isset($input["folder"])) {
             $folderName .= $input["folder"];
         }
         $upload = new Upload($file, $folderName, $fileName);
         if (isset($input["resize"]) && is_array($input["resize"])) {
             $upload->resizeImage($input["resize"][0], $input["resize"][1]);
         }
         if (!$upload->isMimeType($input["fileType"])) {
             $response["error"] = "Type de fichier non-autorisé (" . $input["fileType"] . ")";
             $this->response($response);
         }
         try {
             $upload->send();
         } catch (Exception $e) {
             $response["error"] = "Upload impossible";
             $this->response($response);
         }
         if (isset($input["fileName"]) && !empty($input["fileName"])) {
             $fileName = preg_replace("/(\\{id\\})/", $upload->id_upload, $input["fileName"]);
             $upload->renameFile($fileName);
         }
         $response["path_upload"] = Application::getInstance()->getPathPart() . $upload->pathFile;
         $response["id_upload"] = $upload->id_upload;
     }
     $this->response($response);
 }
Пример #5
0
 private static function upload($pName, $pId, $pData, $pRequire = "")
 {
     self::$ct_upload++;
     $file = $style = $value = "";
     $server_url = Configuration::$server_url;
     /**
      * @todo concaténer la valeur du relative path de l'application en cours à $server_url ?
      */
     $disabled = isset($pData["attributes"]["disabled"]) && $pData["attributes"]["disabled"] == "disabled" ? "disabled" : "";
     if (isset($pData["attributes"]["value"]) && !empty($pData["attributes"]["value"])) {
         $value = $pData["attributes"]["value"];
         $file = $server_url;
         /** @var ModelUpload $m */
         $m = isset($pData["model"]) && !empty($pData["model"]) ? $pData["model"] : "core\\models\\ModelUpload";
         if (Form::isNumeric($value)) {
             $file .= Application::getInstance()->getPathPart() . $m::getPathById($value);
         } else {
             $file .= $value;
         }
     }
     $deleteFileAction = "";
     if (isset($pData['deleteFileAction']) && !empty($pData['deleteFileAction'])) {
         if ($value && Form::isNumeric($value)) {
             $action = preg_replace('/\\{id\\}/', $value, $pData['deleteFileAction']);
         } else {
             $action = $pData['deleteFileAction'];
         }
         $deleteFileAction = 'data-delete_file_action="' . $action . '"';
     }
     $comp = "<input " . $disabled . " type='file' name='" . $pName . "_input' data-form_name='" . $pData["form_name"] . "' data-input_name='" . $pData["field_name"] . "' data-application='" . Core::$application . "' data-value='" . $value . "' data-file='" . $file . "' data-module='" . Core::$module . "'" . $deleteFileAction . ">";
     $input = self::getLabel($pData["label"] . $pRequire, $pId);
     $input .= self::getComponent($comp, 'upload');
     return $input;
 }
Пример #6
0
 /**
  * Méthode de désactivation systématique du mode de debug
  * @return void
  */
 public static function deactivateDebug()
 {
     Configuration::$global_debug = false;
     $authHandler = Application::getInstance()->authenticationHandler;
     $authHandler::$permissions = array();
 }
Пример #7
0
 public function __construct()
 {
     parent::__construct(Application::getInstance() . "_upload", "id_upload");
 }
 /**
  * Constructor
  * Se doit d'être appeler dans la classe fille
  * Vérifie si l'utilisateur est identifié
  * Définie le nom du controller (de la classe courante)
  */
 public function __construct()
 {
     $authHandler = Application::getInstance()->authenticationHandler;
     if (!call_user_func_array(array($authHandler, 'is'), array($authHandler::ADMIN))) {
         Go::to();
     }
     $class = explode("\\", get_class($this));
     $this->className = end($class);
     $this->formName = $this->className;
     Autoload::addScript("Backoffice");
     $this->h1 = new BOLabelList("h1", ucfirst($this->className));
     $this->titles = new BOLabelList("titles", ucfirst($this->className));
     $this->actions = new BOActionList();
     $this->actions->enable('view', 'view', true);
     $this->actions->enable('edit', 'edit', true);
     $this->actions->enable('delete', 'delete', true);
     $this->actions->enable('listing', 'listing', false);
     $this->actions->enable('add', 'add', false);
     $this->menu = new Menu(Core::$path_to_application . '/modules/back/menu.json');
 }
Пример #9
0
 /**
  * @return array
  */
 public function getGlobalVars()
 {
     $is = array();
     /** @var AuthenticationHandler $authHandler */
     $authHandler = Application::getInstance()->authenticationHandler;
     foreach ($authHandler::$permissions as $name => $value) {
         $is[$name] = $authHandler::$data && $authHandler::is($name);
     }
     return array("path_to_theme" => Core::$path_to_theme, "path_to_components" => Core::$path_to_components, "scripts" => Autoload::scripts(), "styles" => Autoload::styles(), "head" => $this->head, "forms" => $this->forms, "content" => $this->content, "user_is" => $is, "controller" => preg_replace("/\\_/", "-", Core::$controller), "action" => preg_replace("/\\_/", "-", Core::$action));
 }
Пример #10
0
 /**
  * Méthode de correction des urls des assets utilisés dans les CSS
  * @param array $pMatches
  * @return string
  */
 private static function correctUrls($pMatches)
 {
     if (strpos($pMatches[2], 'data:image') > -1) {
         return $pMatches[0];
     }
     return $pMatches[1] . Application::getInstance()->getPathPart() . '../../' . self::$current_folder . '/' . $pMatches[2];
 }
Пример #11
0
 /**
  * @static
  * @param  $pURL
  * @return bool|string
  */
 public static function extractLanguage(&$pURL)
 {
     if (Application::getInstance()->multiLanguage && !preg_match("/^statique/", $pURL, $matches)) {
         $language = self::shift($pURL, self::REGEXP_LANGUAGE);
         if (!$language) {
             Go::to("", "", array(), Application::getInstance()->defaultLanguage);
         }
         return $language;
     }
     return Application::getInstance()->defaultLanguage;
 }