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')));
 }
 public static function isUser($pLogin, $pMdp)
 {
     if (empty($pLogin) || empty($pMdp)) {
         return false;
     }
     $instance = self::getInstance();
     if ($result = $instance->one(Query::condition()->andWhere(Configuration::$authentication_fieldLogin, Query::EQUAL, $pLogin))) {
         if ($result[configuration::$authentication_fieldPassword] == $pMdp) {
             self::$data = $result;
             return true;
         }
     }
     return false;
 }
 public function prepareCategories($pTags)
 {
     if (empty($pTags)) {
         return array();
     }
     $ids = array();
     foreach ($pTags as $t) {
         if (Query::count($this->table, Query::condition()->andWhere('name_category', Query::EQUAL, $t))) {
             continue;
         }
         $permalink = RoutingHandler::sanitize($t);
         $this->insert(array('name_category' => $t, 'permalink_category' => $permalink));
         $ids[] = $this->getInsertId();
     }
     return $ids;
 }
Beispiel #4
0
 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 static function isUser($pLogin, $pMdp, $pHash = false)
 {
     if (empty($pLogin) || empty($pMdp)) {
         return false;
     }
     /** @var BaseModel $instance */
     $instance = self::getInstance();
     if ($result = $instance->one(Query::condition()->andWhere(Configuration::$authentication_fieldLogin, Query::EQUAL, $pLogin))) {
         $salt = $result[Configuration::$authentication_fieldSalt];
         $value = $pMdp;
         if (!$pHash) {
             $value = self::computePasswordHash($pMdp, $salt);
         }
         if ($result[configuration::$authentication_fieldPassword] == $value) {
             self::$data = $result;
             return true;
         }
     }
     return false;
 }
Beispiel #6
0
 public function getPostsByDay($pCat = null, $pDaysCount = 7, $pFirstDay = null)
 {
     if ($pFirstDay == null) {
         $pFirstDay = date('Y-m-d');
     }
     $days = array();
     if (!is_null($pCat)) {
         $this->addJoinOnSelect('post_category b', ' JOIN ', 'main_post.id_post = b.id_post');
         $this->addJoinOnSelect('main_category c', ' JOIN ', 'c.id_category = b.id_category');
     }
     for ($i = 0; $i < $pDaysCount; $i++) {
         $ts = strtotime($pFirstDay) - $i * 24 * 60 * 60;
         $cond = Query::condition()->andWhere('added_date_post', Query::LIKE, date('Y-m-d', $ts) . '%')->andWhere('status_post', Query::EQUAL, 1)->order('added_date_post', 'DESC');
         if (!is_null($pCat)) {
             $cond->andWhere('c.permalink_category', Query::EQUAL, $pCat);
         }
         $date = date('l, dS F Y', $ts);
         $days[$date] = $this->all($cond, 'main_post.*');
     }
     return $days;
 }
 /**
  * @return QueryCondition
  */
 public function getConditionLimit()
 {
     return Query::condition()->limit($this->first, $this->number);
 }
Beispiel #8
0
 /**
  * @return QueryCondition
  */
 protected function getCondition()
 {
     if (!$this->condition) {
         $this->condition = Query::condition();
     }
     return $this->condition;
 }
 /**
  * @return void
  */
 public function autocomplete()
 {
     $datas = null;
     $response = array("error" => "");
     if (!isset($_GET["form_name"]) || empty($_GET["form_name"])) {
         $response["error"] = '$_GET["form_name"] require';
     }
     if (!isset($_GET["input_name"]) || empty($_GET["input_name"])) {
         $response["error"] = '$_GET["input_name"] require';
     }
     if (empty($response["error"])) {
         $path_to_form = "includes/applications/" . $_GET["application"] . "/modules/";
         if ($_GET["module"]) {
             $path_to_form .= $_GET["module"] . "/";
         } else {
             $path_to_form .= "front/";
         }
         $path_to_form .= "forms/form." . $_GET["form_name"] . ".json";
         try {
             $datas = SimpleJSON::import($path_to_form);
         } catch (Exception $e) {
             $response["error"] = "Formulaire introuvable " . $path_to_form;
             $this->response($response);
         }
         if (!is_array($datas[$_GET["input_name"]])) {
             $response["error"] = "Champs cibl&eacute; introuvable";
             $this->response($response);
         }
         $input = $datas[$_GET["input_name"]];
         if ($input["tag"] != Form::TAG_INPUT || $input["attributes"]["type"] != "text") {
             $response["error"] = "Champs cibl&eacute; n'est pas un input type 'text'";
             $this->response($response);
         }
         if (!$input["autoComplete"] || !is_array($input["autoComplete"])) {
             $response["error"] = "Les &eacute;l&eacute;ments de bases ne sont pas renseign&eacute;s";
             $this->response($response);
         }
         $model = new $input["autoComplete"]["model"]();
         $cond = Query::condition()->andWhere($input["autoComplete"]["value"], Query::LIKE, "%" . $_GET["q"] . "%");
         if (isset($input["autoComplete"]["condition"]) && is_array($input["autoComplete"]["condition"]) && count($input["autoComplete"]["condition"])) {
             foreach ($input["autoComplete"]["condition"] as $m => $p) {
                 call_user_func_array(array($cond, $m), $p);
             }
         }
         if (isset($_GET["replies"]) && Form::isNumeric($_GET["replies"])) {
             $result = $model->{$input}["autoComplete"]["method"]($_GET["replies"]);
         } else {
             $result = $model->{$input}["autoComplete"]["method"]($cond, $input["autoComplete"]["value"]);
         }
         $response["responses"] = array();
         foreach ($result as $r) {
             $d = array("value" => $r[$input["autoComplete"]["value"]]);
             if (isset($input["autoComplete"]["raw"]) && is_array($input["autoComplete"]["raw"])) {
                 foreach ($input["autoComplete"]["raw"] as $v) {
                     $d[$v] = $r[$v];
                 }
             }
             $response["responses"][] = $d;
         }
     }
     $this->response($response);
 }
Beispiel #10
0
 /**
  * Méthode de pré-traitement du formulaire avant envoi &agrave; la vue (parsing des libellés, des types de balises, définition des js/css requis)
  * @return void
  */
 public function prepareToView()
 {
     $this->cleanData();
     if (isset($this->post)) {
         $this->injectValues($this->post);
     }
     Autoload::addScript("Form");
     $this->countMendatory = 0;
     foreach ($this->data as $name => &$data) {
         switch ($data["tag"]) {
             case self::TAG_RICHEDITOR:
                 /** @ todo **/
                 trace("you must handle richeditor");
                 Autoload::addScript("ckeditor/ckeditor.js");
                 break;
             case self::TAG_UPLOAD:
                 Autoload::addComponent("Uploader");
                 Autoload::addScript("M4Tween");
                 $this->hasUpload = true;
                 break;
             case self::TAG_INPUT:
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "checkbox") {
                     unset($data["attributes"]["valueOff"]);
                 }
                 if (isset($data["autoComplete"])) {
                     Autoload::addComponent('Autocomplete');
                 }
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "file") {
                     Autoload::addComponent("Uploader");
                     Autoload::addScript("M4Tween");
                     $this->hasUpload = true;
                 } else {
                     if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "submit" && Application::getInstance()->multiLanguage) {
                         $data["attributes"]["value"] = Dictionary::term($data["attributes"]["value"]);
                     }
                 }
                 break;
             case self::TAG_DATEPICKER:
                 Autoload::addComponent("Pikaday");
                 $this->hasDatePicker = true;
                 break;
             case self::TAG_COLORPICKER:
                 Autoload::addScript("jscolor/jscolor.js");
                 $this->hasColorPicker = true;
                 break;
             case self::TAG_RADIOGROUP:
             case self::TAG_CHECKBOXGROUP:
             case self::TAG_SELECT:
                 if (isset($data["fromModel"]) && is_array($data["fromModel"])) {
                     $condition = null;
                     $fm = $data["fromModel"];
                     if (isset($fm["condition"]) && is_array($fm["condition"])) {
                         $condition = Query::condition();
                         foreach ($fm["condition"] as $method => $parameters) {
                             call_user_func_array(array($condition, $method), $parameters);
                         }
                     }
                     $model = method_exists($fm["model"], "getInstance") ? $fm["model"]::getInstance() : new $fm["model"]();
                     $datas = $model->{$fm}["method"]($condition);
                     $options = array();
                     $defaultChecked = isset($data["attributes"]["checked"]) && !isset($this->post);
                     foreach ($datas as $donnees) {
                         if (is_object($donnees)) {
                             $donnees_name = $donnees->{$fm}["name"];
                             $donnees_value = $donnees->{$fm}["value"];
                         } else {
                             $donnees_name = isset($donnees[$fm['name']]) ? $donnees[$fm["name"]] : '';
                             $donnees_value = isset($donnees[$fm['value']]) ? $donnees[$fm["value"]] : '';
                         }
                         $options[] = array("name" => $donnees_name, "label" => $donnees_name, "value" => $donnees_value, "checked" => $defaultChecked);
                     }
                     if (!isset($data["options"])) {
                         $data["options"] = $options;
                     } else {
                         $data["options"] = array_merge($data["options"], $options);
                     }
                 }
                 if (isset($data["chosen"]) && $data["chosen"] == true) {
                     Autoload::addScript("chosen/chosen.min.js");
                     /** @todo componentify this */
                     Autoload::addStyle(Core::$path_to_components . "/chosen/style/chosen.css");
                 }
                 break;
         }
         if ($data["require"]) {
             $this->countMendatory++;
         }
         if (isset($data["attributes"]["valueGet"])) {
             if (isset($_GET[$data["attributes"]["valueGet"]])) {
                 $data["attributes"]["value"] = $_GET[$data["attributes"]["valueGet"]];
                 unset($this->data[$name]["attributes"]["valueGet"]);
             } else {
                 if (isset($data["attributes"]["type"]) && $data["attributes"]["type"] == "hidden") {
                     unset($this->data[$name]);
                 }
             }
         }
     }
 }
Beispiel #11
0
 public function insertUpload($pPath)
 {
     $this->delete(Query::condition()->andWhere("path_upload", Query::EQUAL, $pPath));
     return $this->insert(array("path_upload" => $pPath));
 }
 /**
  * Méthode permettant de lister toutes les entrées du model
  * Gestion automatique du ORDER BY
  * @param String $pCondition		Condition souhaitée pour la requête SQL
  * @return void
  */
 public function listing($pCondition = null)
 {
     if (!$this->actions->isEnabled("listing")) {
         Go::to404();
     }
     $this->setTitle($this->titles->get('listing'));
     $this->setTemplate("default", "listing");
     $this->addContent("titles", $this->listTitle);
     $this->addContent("id", $this->model->id);
     if (!$pCondition) {
         $pCondition = Query::condition();
     }
     $pConditionCount = clone $pCondition;
     for ($i = 0, $max = count($this->listTitle); $i < $max; $i++) {
         if (isset($_GET["order"]) && in_array($_GET["order"], $this->listTitle[$i])) {
             $pCondition->order($_GET["order"], isset($_GET["by"]) ? $_GET["by"] : "ASC");
             $i = $max;
         }
     }
     if ($this->usePaginationOnList) {
         $nbDatas = $this->model->count($pConditionCount);
         $currentPage = isset($_GET["page"]) ? $_GET["page"] : 1;
         $pagination = new PaginationHandler($currentPage, $this->nbItemsByPage, $nbDatas);
         $pCondition->limit($pagination->first, $pagination->number);
         $data = $this->model->all($pCondition);
         $this->addContent("paginationInfo", $pagination->getPaginationInfo());
     } else {
         $data = $this->model->all($pCondition);
     }
     $this->addContent("liste", $data);
     $this->addContent("h1", $this->h1->get('listing'));
 }
Beispiel #13
0
 public function retrieveByUser($pIdUser, $pCount = 10)
 {
     return $this->all(Query::condition()->andWhere('id_user', Query::EQUAL, $pIdUser)->order('name_list')->limit(0, $pCount));
 }
Beispiel #14
0
 /**
  * @param null $pCond
  * @param string $pFields
  * @return array
  */
 public function one($pCond = null, $pFields = "*")
 {
     if ($pCond == null) {
         $pCond = Query::condition();
     }
     $res = $this->all($pCond->limit(0, 1), $pFields);
     if (!isset($res[0])) {
         return null;
     }
     return $res[0];
 }
Beispiel #15
0
 public function addState($pUrl, $pIdUser = null)
 {
     $existing_link = $this->one(Query::condition()->andWhere('url_link', Query::EQUAL, $pUrl)->orWhere('canonical_link', Query::EQUAL, $pUrl));
     $headers = get_headers($pUrl);
     $code = substr($headers[0], 9, 3);
     if (in_array($code, array(404, 400, 401, 500, 503)) && $existing_link) {
         $this->deleteById($existing_link[$this->id]);
         return false;
     }
     $content = $this->parseLink($pUrl);
     if ($content === false || is_array($content) && empty($content['title']) && empty($content['price'])) {
         return false;
     }
     if (!$existing_link && isset($content['canonical']) && !empty($content['canonical'])) {
         $existing_link = $this->one(Query::condition()->andWhere('url_link', Query::EQUAL, $content['canonical'])->orWhere('canonical_link', Query::EQUAL, $content['canonical']));
     }
     if (!$existing_link) {
         Query::insert(array('url_link' => $pUrl, 'canonical_link' => $content['canonical'], 'title_link' => $content['title'], 'image_link' => $content['image']))->into($this->table)->execute($this->handler);
     } else {
         Query::update('sil_links')->values(array('url_link' => $pUrl, 'canonical_link' => $content['canonical'], 'title_link' => $content['title'], 'image_link' => $content['image']))->andWhere('id_link', Query::EQUAL, $existing_link['id_link'])->execute();
     }
     $existing_link = $this->one(Query::condition()->andWhere('url_link', Query::EQUAL, $pUrl)->orWhere('canonical_link', Query::EQUAL, $content['canonical']));
     if (isset($pIdUser)) {
         if (!Query::count('sil_user_links', Query::condition()->andWhere('id_user', Query::EQUAL, $pIdUser)->andWhere('id_link', Query::EQUAL, $existing_link['id_link']))) {
             Query::insert(array('id_user' => $pIdUser, 'id_link' => $existing_link['id_link']))->into('sil_user_links')->execute();
         }
     }
     Query::insert(array('id_link' => $existing_link['id_link'], 'price_state' => $content['price']['price'], 'devise_state' => $content['price']['devise']))->into('sil_states')->execute($this->handler);
     Query::update($this->table)->values(array('last_price_link' => $content['price']['price'], 'devise_link' => $content['price']['devise']))->andWhere('id_link', Query::EQUAL, $existing_link['id_link'])->execute();
     return true;
 }