Пример #1
0
 public function config()
 {
     $this->T_block = $this->O->glob('block_central_1');
     $this->tpl_dir = dirname(__FILE__) . '/../template/';
     $params = $this->getRequestParams();
     $this->data['var'] = Filter::Int($this->M->var_id_node, $this->getRequestId());
 }
Пример #2
0
 public final function init()
 {
     $this->hook('before_config');
     $this->config();
     $this->hook('tpl_config');
     $this->hook('after_config');
     if (!$this->method) {
         // on récupère la methode pour le module
         $method = Filter::id($this->var_method, $_GET);
         $this->setMethod($method);
     }
     return $this;
 }
Пример #3
0
 /**
  * @covers Fp\Core\Filter::float
  * @todo   Implement testFloat().
  */
 public function testFloat()
 {
     $this->assertEquals(null, \Fp\Core\Filter::float(null));
     $this->assertEquals(0, \Fp\Core\Filter::float(0));
     $this->assertEquals(3.14, \Fp\Core\Filter::float(3.14));
 }
Пример #4
0
 public function setName($name = false, $noOverwrite = 0, $timestamp = null)
 {
     if ($name) {
         $sanit_name = Filter::fileName($name);
         $sanit_name = substr($sanit_name, 0, 200);
         $this->extension = $this->fileExt($name);
         $pref = '';
         if ($timestamp) {
             $timestamp = date("YmdGi_");
         } else {
             $timestamp = '';
         }
         if ($noOverwrite) {
             $c = 0;
             while (is_file($this->upload_dir . $timestamp . $pref . $sanit_name)) {
                 $pref = $c++ . '_';
             }
         }
         $this->name = $timestamp . $pref . $sanit_name;
         return $this->name;
     }
     if (empty($this->name)) {
         throw new Exception("Le nom {$name} est invalide");
     }
 }
Пример #5
0
 private function setHtml()
 {
     // debug option
     if ($this->global['debug'] >= 2) {
         $session_console = $newsession_console = is_object($this->session) ? $this->session()->get('console') : 0;
         $consoleGet = Filter::id('console', $_GET);
         //show block data ?
         if ($consoleGet == 'off') {
             $newsession_console = 0;
         } elseif ($consoleGet == '1') {
             $newsession_console = 1;
         }
         if ($session_console != $newsession_console) {
             if (is_object($this->session)) {
                 $this->session()->set('console', $newsession_console);
             }
             $session_console = $newsession_console;
         }
         if ($session_console) {
             $this->tpl()->setDebug($session_console);
         }
         // reset cache
         if ($consoleGet == 'cache_reset') {
             $dir_cache = $this->glob('dir_cache');
             \Fp\File\Dir::emptyDir($dir_cache . 'cdn/');
             \Fp\File\Dir::emptyDir($dir_cache . 'pool/');
         }
         // stop cache
         $cache = $this->glob('cache');
         if (!$cache) {
             // not override if cache is disabled ( cache == 1 )
             $new_cache = is_object($this->session) ? $this->session()->get('console_cache') : $cache;
             if ($consoleGet == 'cache_stop') {
                 $new_cache = 1;
             } elseif ($consoleGet == 'cache_start') {
                 $new_cache = 0;
             }
             if ($new_cache != $cache) {
                 if (is_object($this->session)) {
                     $this->session()->set('console_cache', $new_cache);
                 }
                 $cache = $new_cache;
             }
         }
         $this->global['cache'] = $cache;
         if ($consoleGet && ($redirect = Filter::custom('redirect', $_GET, function ($var) {
             return urldecode($var);
         }))) {
             $this->header()->redirect($redirect);
         }
     }
 }
Пример #6
0
 private static function keyName($key)
 {
     return Filter::dirName($key);
 }
Пример #7
0
 protected function onNodeChange($id_node, $node, $old_node)
 {
     $this->O->event()->trigger($this->namespace . '.node.change');
     $uid = $this->O->auth()->uid();
     $label = Filter::text('node.revision.label', $node, 'revision');
     $comment = Filter::text('node.revision.comment', $node);
     $this->addRevision($id_node, $uid, $label, $comment, Date::fromStrtotime(time())->mysqlDateTime(), $old_node);
 }
Пример #8
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     $errstr = $backtrace = $errno = $errfile = $errline = $code = null;
     if (isset($context[0]) && $context[0] instanceof \Exception) {
         $errstr = $context[0]->getMessage();
         $backtrace = $context[0]->getTraceAsString();
         $errfile = $context[0]->getFile();
         $errline = $context[0]->getLine();
         $code = $context[0]->getCode();
     } else {
         if (array_key_exists('exception', $context) and $context['exception'] instanceof \Exception) {
             $errstr = $context['exception']->getMessage();
             $backtrace = $context['exception']->getTraceAsString();
             $errfile = $context['exception']->getFile();
             $errline = $context['exception']->getLine();
             $code = $context['exception']->getCode();
         } else {
             $errortype = array(E_ERROR => 'Erreur', E_WARNING => 'Alerte', E_PARSE => 'Erreur d\'analyse', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'Erreur spécifique', E_USER_WARNING => 'Alerte spécifique', E_USER_NOTICE => 'Note spécifique', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Catchable Fatal Error');
             $errno = Filter::int($level);
             if ($errno && array_key_exists($errno, $errortype)) {
                 $level = $errortype[$errno];
             }
             $errfile = Filter::raw('file', $context);
             $errline = Filter::raw('line', $context);
             $code = null;
         }
     }
     \Fp\Core\Debug::msg($message, $backtrace, $errno, $errfile, $errline, $level);
     self::$logMessage[] = "<div><b>{$level}:</b> {$message}<div>{$errfile} {$errline}<pre>{$backtrace}</pre></div></div>";
 }
Пример #9
0
 /**
  * @return \Fp\Module\Controller
  */
 public function autoMode()
 {
     $m = Filter::id('m', $_GET);
     if ($this->modeExist($m)) {
         $this->setMode($m);
         $m = $this->mode;
         return $this->{$m}();
     } else {
         return $this->html();
     }
 }
Пример #10
0
 /**
  * @param id $group
  */
 public function sanitizeIdGroup($group)
 {
     $group = Filter::id($group);
     $group = $this->idGroup($group);
     return $group;
 }
Пример #11
0
 public function rewriteUrl($url, $keyword = null)
 {
     $_url = $url = trim($url, "\t\n\r\v. /");
     if (!array_key_exists($_url, self::$urlCache)) {
         // on supprime les params incomplet
         if (strpos($url, '{')) {
             $url = preg_replace('#/(?:[a-z0-9_]*)-\\{(?:[a-z0-9_]*)\\}#', '', $url);
             $url = preg_replace('#/{[a-z0-9_]*\\}#', '', $url);
         }
         if (strpos($url, '%7B')) {
             $url = preg_replace('#/%7B[a-z0-9_]*\\%7D#', '', $url);
         }
         self::$urlCache[$_url] = $url;
     } else {
         $url = self::$urlCache[$_url];
     }
     if (!empty($keyword)) {
         $keyword = (string) $keyword;
         if (!array_key_exists($keyword, self::$keywordCache)) {
             $kwd = Filter::dirName($keyword);
             $kwd = str_replace('_', '-', $kwd);
             $kwd = trim($kwd, '-');
             $kwd = preg_replace("#-{2,}#", '-', '+' . $kwd);
             self::$keywordCache[$keyword] = $kwd;
         } else {
             $kwd = self::$keywordCache[$keyword];
         }
         $url = preg_replace('#/$#', '', $url) . $kwd;
     }
     return $url;
 }
Пример #12
0
 function metaHttpEquiv($name, $content)
 {
     $this->meta['http_equiv' . $name . $content] = '<meta  http-equiv="' . Filter::htmlAttr($name) . '" content="' . Filter::htmlAttr($content) . '" />';
     return $this;
 }
Пример #13
0
 public static function htmlToText($t)
 {
     $c = clone $t;
     $c->vars = Filter::htmlToText($c->vars);
     return $c;
 }
Пример #14
0
 protected function makeSearchColumn($column, $search, $type = 'OR')
 {
     $column = $this->existColumn($column);
     $r = null;
     if ($column) {
         if (is_scalar($search)) {
             $t = $this->typeColumn($column);
             if ($t == 'varchar') {
                 $sp = $this->searchParser($search);
                 $tmp = array();
                 $search_str = trim($search, '"');
                 $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE " . $this->quote("{$search_str}");
                 $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE " . $this->quote("{$search_str}%");
                 $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE " . $this->quote("%{$search_str}%");
                 $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE " . $this->quote("%{$search_str}");
                 $poss = 1;
                 $stopWords = array('alors', 'au', 'aucuns', 'aussi', 'autre', 'avant', 'avec', 'car', 'ce', 'cela', 'ces', 'ceux', 'ci', 'dans', 'des', 'du', 'doit', 'donc', 'début', 'elle', 'elles', 'en', 'encore', 'essai', 'est', 'et', 'eu', 'il', 'ils', 'je', 'la', 'le', 'les', 'leur', 'là', 'ma', 'mot', 'même', 'ni', 'nous', 'ou', 'où', 'par', 'parce', 'pas', 'peu', 'pour', 'pourquoi', 'quand', 'que', 'quel', 'quelle', 'quelles', 'quels', 'qui', 'sa', 'sans', 'ses', 'si', 'sien', 'son', 'sont', 'sous', 'soyez', 'sujet', 'sur', 'ta', 'tels', 'tes', 'ton', 'tous', 'tout', 'trop', 'très', 'tu', 'vont', 'votre', 'vous', 'vu', 'ça', 'de', 'avec', 'à', 'a', "l'", "d'", 'aux', 'se', 'un', 'une', '&', '!', '?', '.', '\'', '"', ';', ':', '+', '-');
                 if (count($sp) > 1) {
                     $nb_case = count($sp);
                     foreach ($sp as $sp_search) {
                         $sp_search = trim($sp_search, '"');
                         if ($poss === 1 && $nb_case < 3) {
                             // si le premier match le début avec une recherche de moins de 3 mots
                             $v = $this->quote("{$sp_search}%");
                             $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE {$v} ";
                         }
                         if (strlen($sp_search) > 1 && !in_array(mb_strtolower($sp_search, 'UTF-8'), $stopWords)) {
                             // si il est contenu et n'est pas un stop words
                             $v = $this->quote("%{$sp_search}%");
                             $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE {$v} ";
                         }
                         if ($poss === count($nb_case) && $nb_case < 3) {
                             // si le dernier mach la fin avec une recherche de moins de 3 mots
                             $v = $this->quote("{$sp_search}%");
                             $this->searchCase[] = $tmp[] = "{$column} COLLATE utf8_general_ci LIKE {$v} ";
                         }
                         $poss++;
                     }
                 }
                 $r = implode(" {$type} ", $tmp);
             } else {
                 if ($t == 'date' || $t == 'datetime') {
                     if ($sdate = \Fp\Core\Filter::mysqlDateTime($search)) {
                         $v = $this->quote("{$sdate}");
                         $this->searchCase[] = $r = " {$column}={$v}";
                     } else {
                         // fix searching date (ex year 2014-)
                         if ($search) {
                             $v = $this->quote("%{$search}%");
                             $this->searchCase[] = $r = "{$column} LIKE {$v} ";
                         }
                     }
                 } else {
                     if ($search) {
                         $v = $this->quote("{$search}");
                         $this->searchCase[] = $r = " {$column}={$v} ";
                     }
                 }
             }
         } elseif (is_array($search)) {
             foreach ($search as $sub) {
                 if ($type == 'OR') {
                     $this->orSearch(array($column => $sub));
                 } else {
                     $this->andSearch(array($column => $sub));
                 }
             }
         }
     }
     return $r;
 }