Esempio n. 1
0
 public function search($word, $coords, $distance = 5, $limit = 25, $offset = 0)
 {
     $collection = $tmp = $idEtabs = [];
     $nb = $incr = 0;
     $services = rdb('geo', 'service')->select('id')->where(['family', 'LIKE', '%' . $word . '%'])->where(['code', 'LIKE', '%' . $word . '%'], 'OR')->where(['label', 'LIKE', '%' . $word . '%'], 'OR')->exec(true);
     foreach ($services as $service) {
         $sEtabs = $service->pivots(rdb('geo', 'etablissement')->model())->exec();
         foreach ($sEtabs as $sEtab) {
             $idEtabs[] = $sEtab['etablissement_id'];
         }
     }
     $idEtabs = array_unique($idEtabs);
     $db = Model::Location();
     $odm = $db->getOdm();
     $coll = $odm->selectCollection($db->collection);
     $coll->ensureIndex(['value' => '2d', 'object_motor' => 1, 'object_database' => 1, 'object_table' => 1]);
     $filter = ["value" => ['$within' => ['$center' => [[floatval($coords['lng']), floatval($coords['lat'])], floatval($distance / 111.12)]]], 'object_motor' => 'dbredis', 'object_database' => 'geo', 'object_table' => 'etablissement'];
     $results = $coll->find($filter);
     foreach ($results as $result) {
         if (Arrays::in($result['object_id'], $idEtabs)) {
             $etab = rdb('geo', 'etablissement')->find($result['object_id']);
             $distances = distanceKmMiles($coords['lng'], $coords['lat'], $etab->lng, $etab->lat);
             $distance = $distances['km'];
             $item = $etab->assoc();
             $item['distance'] = $distance;
             $collection[] = $item;
         }
     }
     $collection = $this->orderBy($collection, 'distance');
     if ($limit == 0) {
         return $collection;
     } else {
         return array_slice($collection, $offset, $limit);
     }
 }
Esempio n. 2
0
 private function can()
 {
     $nonLoginPages = array('login', 'password');
     $this->user = session('backend')->getUser();
     if (is_null($this->user) && !Arrays::in($this->action, $nonLoginPages)) {
         $this->_url->redirect('login');
     } else {
         if (!is_null($this->user)) {
             $this->view->isLogged = true;
         }
     }
 }
Esempio n. 3
0
 public static function __callStatic($method, $args)
 {
     $auth = ['GET', 'POST', 'COOKIE', 'SESSION', 'SERVER', 'REQUEST', 'GLOBALS'];
     $method = Inflector::upper($method);
     if (Arrays::in($method, $auth) && count($args) > 0) {
         $default = isset($args[1]) ? $args[1] : null;
         return isAke(self::tab($method), Arrays::first($args), $default);
     } elseif (Arrays::in($method, $auth) && count($args) == 0) {
         return self::tab($method);
     } else {
         throw new Exception("Wrong parameters.");
     }
 }
Esempio n. 4
0
 public static function execute($module, $controller, $action, $args = [])
 {
     $dirModule = APPLICATION_PATH . DS . 'modules' . DS . SITE_NAME . DS . Inflector::lower($module);
     if (!is_dir($dirModule)) {
         throw new Exception("The directory '{$dirModule}' does not exist.");
     }
     $dirController = $dirModule . DS . 'controllers';
     if (!is_dir($dirController)) {
         throw new Exception("The directory '{$dirController}' does not exist.");
     }
     $controllerFile = $dirController . DS . Inflector::lower($controller) . 'Controller.php';
     if (!File::exists($controllerFile)) {
         throw new Exception("The file '{$controllerFile}' does not exist.");
     }
     require_once $controllerFile;
     $oldRoute = container()->getRoute();
     container()->setRoute(with(new Container())->setModule($module)->setController($controller)->setAction($action));
     $controllerClass = 'Thin\\' . Inflector::lower($controller) . 'Controller';
     $controllerInstance = new $controllerClass();
     $actions = get_class_methods($controllerClass);
     if (strstr($action, '-')) {
         $words = explode('-', $action);
         $newAction = '';
         for ($i = 0; $i < count($words); $i++) {
             $word = trim($words[$i]);
             if ($i > 0) {
                 $word = ucfirst($word);
             }
             $newAction .= $word;
         }
         $action = $newAction;
     }
     $actionName = $action . 'Action';
     if (!Arrays::in($actionName, $actions)) {
         throw new Exception("The action '{$actionName}' does not exist in {$controllerFile}.");
     }
     if (Arrays::in('init', $actions)) {
         $controllerInstance->init();
     }
     if (Arrays::in('preDispatch', $actions)) {
         $controllerInstance->preDispatch();
     }
     $res = call_user_func_array([$controllerInstance, $actionName], $args);
     if (Arrays::in('postDispatch', $actions)) {
         $controllerInstance->preDispatch();
     }
     container()->setRoute($oldRoute);
     return $res;
 }
Esempio n. 5
0
 public function factory()
 {
     if (File::exists($this->file)) {
         require_once $this->file;
         $instance = new $this->class();
         $methods = get_class_methods($this->class);
         $tab = explode('\\', get_class($instance));
         $item = Inflector::lower(Arrays::last($tab));
         if (Arrays::in('init', $methods)) {
             $instance->init();
         }
         $this->app->bindShared($this->type . '.' . $item, function ($app) use($instance) {
             return $instance;
         });
         return $this;
     } else {
         throw new Exception("The file '{$file}' does not exist.");
     }
 }
Esempio n. 6
0
File: Env.php Progetto: schpill/thin
 /**
  * Require specified ENV vars to be present, or throw Exception.
  * You can also pass through an set of allowed values for the environment variable.
  *
  * @throws \RuntimeException
  * @param  mixed             $environmentVariables the name of the environment variable or an array of names
  * @param  string[]          $allowedValues
  * @return true              (or throws exception on error)
  */
 public static function required($environmentVariables, array $allowedValues = array())
 {
     $environmentVariables = (array) $environmentVariables;
     $missingEnvironmentVariables = [];
     foreach ($environmentVariables as $environmentVariable) {
         $value = static::findEnvironmentVariable($environmentVariable);
         if (is_null($value)) {
             $missingEnvironmentVariables[] = $environmentVariable;
         } elseif ($allowedValues) {
             if (!Arrays::in($value, $allowedValues)) {
                 // may differentiate in the future, but for now this does the job
                 $missingEnvironmentVariables[] = $environmentVariable;
             }
         }
     }
     if ($missingEnvironmentVariables) {
         throw new \RuntimeException(sprintf("Required environment variable missing, or value not allowed: '%s'", implode("', '", $missingEnvironmentVariables)));
     }
     return true;
 }
Esempio n. 7
0
 private function sanitize($_)
 {
     if (!is_string($_)) {
         return false;
     }
     if (empty($_)) {
         return false;
     }
     $stop = strlen($_);
     $_ = str_replace('/url?q=', '', Inflector::lower($_));
     for ($i = 0; $i < $stop; $i++) {
         if (Arrays::in($_[$i], array('&amp;', '"', '&', "'"))) {
             $stop = $i;
             $i = strlen($_);
         }
     }
     $url = '';
     for ($j = 0; $j < $stop; $j++) {
         $url .= $_[$j];
     }
     return rawurldecode($url);
 }
Esempio n. 8
0
 private function getCategories($articles)
 {
     $collection = $tuples = [];
     foreach ($articles as $article) {
         $item_id = isAke($article, 'item_id', 0);
         if (0 < $item_id) {
             $family = repo('segment')->getFamilyfromItem($item_id);
             $cat = isset($family[1]) ? $family[1] : false;
             if (false !== $cat) {
                 $item = [];
                 $item['id'] = $cat['id'];
                 $item['name'] = $cat['name'];
                 $item['icon'] = $cat['icon'];
                 if (!Arrays::in($cat['id'], $tuples)) {
                     array_push($collection, $item);
                     array_push($tuples, $cat['id']);
                 }
             }
         } else {
             $item = [];
             $item['id'] = 0;
             $item['name'] = 'autre';
             $item['icon'] = 'fa fa-cubes';
             if (!Arrays::in('o', $tuples)) {
                 array_push($collection, $item);
                 array_push($tuples, 'o');
             }
         }
     }
     return $collection;
 }
Esempio n. 9
0
 public function query($condition)
 {
     list($field, $op, $value) = explode(' ', $condition, 3);
     $collection = array();
     $attribute = $this->dba->where('name = ' . $field)->first();
     $results = $this->dbr->where('attribute = ' . $attribute->getId())->where('entity_name = ' . $this->entity)->where('value ' . $op . ' ' . $value)->fetch();
     foreach ($results as $result) {
         if (!Arrays::in($result->getEntity(), $collection)) {
             array_push($collection, $result->getEntity());
         }
     }
     return $collection;
 }
Esempio n. 10
0
File: Mvc.php Progetto: schpill/thin
 private static function run(Container $route)
 {
     container()->setRoute($route);
     $is404 = true;
     $module = !isset($route->module) ? 'default' : $route->module;
     $controller = $route->controller;
     $action = $route->action;
     $render = !isset($route->render) ? $action : $route->render;
     $stats = !isset($route->stats) ? true : $route->stats;
     if ($action instanceof \Closure) {
         return call_user_func_array($action, [$route]);
     }
     if (!empty($module) && !empty($controller) && !empty($action)) {
         if (fnmatch('*-*', $action)) {
             $words = explode('-', $action);
             $newAction = '';
             for ($i = 0; $i < count($words); $i++) {
                 $word = trim($words[$i]);
                 if ($i > 0) {
                     $word = ucfirst($word);
                 }
                 $newAction .= $word;
             }
             $action = $newAction;
         }
         $actionName = $action . 'Action';
         $controllersDir = APPLICATION_PATH . DS . 'modules' . DS . strtolower($module) . DS . 'controllers';
         $viewsDir = APPLICATION_PATH . DS . 'modules' . DS . strtolower($module) . DS . 'views';
         $controllerFile = $controllersDir . DS . strtolower($controller) . 'Controller.php';
         $tplFile = $viewsDir . DS . Inflector::lower($controller) . DS . Inflector::lower($render) . '.phtml';
         if (File::exists($controllerFile)) {
             require_once $controllerFile;
             $controllerClass = 'Thin\\' . Inflector::lower($controller) . 'Controller';
             $controllerInstance = new $controllerClass();
             $actions = get_class_methods($controllerClass);
             if (Arrays::in($actionName, $actions)) {
                 $is404 = false;
                 $keyEvent = Inflector::lower($module) . '.' . Inflector::lower($controller) . '.' . $action;
                 if (File::exists($tplFile)) {
                     $view = new View($tplFile);
                     $controllerInstance->view = $view;
                 }
                 if (Arrays::in('boot', $actions)) {
                     $keyEv = $keyEvent . '.init';
                     Event::run($keyEv);
                     $controllerInstance->boot();
                 }
                 if (Arrays::in('preDispatch', $actions)) {
                     $keyEv = $keyEvent . '.before';
                     Event::run($keyEv);
                     $controllerInstance->preDispatch();
                 }
                 $controllerInstance->{$actionName}();
                 if (isset($controllerInstance->view)) {
                     $controllerInstance->view->render();
                 }
                 if (Arrays::in('postDispatch', $actions)) {
                     $keyEv = $keyEvent . '.after';
                     Event::run($keyEv);
                     $controllerInstance->postDispatch();
                 }
                 if (Arrays::in('exit', $actions)) {
                     $keyEv = $keyEvent . '.done';
                     Event::run($keyEv);
                     $controllerInstance->exit();
                 }
                 if (isset($controllerInstance->view)) {
                     if (true === $stats) {
                         echo $controllerInstance->view->showStats();
                     }
                 }
             }
         }
     }
     if (true === $is404) {
         return static::run(static::route(['controller' => 'static', 'action' => 'is404']));
     } else {
         exit;
     }
 }
Esempio n. 11
0
 private function getPics()
 {
     $seg = $this->tag('<div id="links">', '</div>', $this->seg);
     $tab = explode('<a href=', $seg);
     $picIds = array();
     if (!empty($seg)) {
         for ($i = 1; $i < count($tab); $i++) {
             $img = $this->tag('"', '"', trim($tab[$i]));
             $picId = $this->tag('-big-', '.', $img);
             if (!Arrays::in($picId, $picIds)) {
                 array_push($picIds, $picId);
             }
         }
     }
     $this->property['pics'] = implode(',', $picIds);
     return $this;
 }
Esempio n. 12
0
 public static function dispatchBundle(Container $route)
 {
     $bundle = $route->getBundle();
     $controller = $route->getController();
     $action = $route->getAction();
     $path = realpath(APPLICATION_PATH . '/../');
     $bundle = ucfirst(Inflector::lower($bundle));
     $viewsDir = $path . DS . 'bundles' . DS . $bundle . DS . 'views';
     $controllersDir = $path . DS . 'bundles' . DS . $bundle . DS . 'controllers';
     $tpl = $viewsDir . DS . Inflector::lower($controller) . ucfirst(Inflector::lower($action)) . '.phtml';
     $controllerFile = $controllersDir . DS . Inflector::lower($controller) . '.php';
     $file = $path . DS . 'bundles' . DS . $bundle . DS . $bundle . '.php';
     if (File::exists($file)) {
         $getNamespaceAndClassNameFromCode = getNamespaceAndClassNameFromCode(fgc($file));
         list($namespace, $class) = $getNamespaceAndClassNameFromCode;
         if (File::exists($controllerFile)) {
             if (File::exists($tpl)) {
                 $view = new View($tpl);
                 container()->setView($view);
             }
             require_once $controllerFile;
             $controllerClass = $namespace . '\\' . Inflector::lower($controller) . 'Controller';
             $controller = new $controllerClass();
             if (File::exists($tpl)) {
                 $controller->view = $view;
             }
             container()->setController($controller);
             $actions = get_class_methods($controllerClass);
             container()->setAction($action);
             if (strstr($action, '-')) {
                 $words = explode('-', $action);
                 $newAction = '';
                 for ($i = 0; $i < count($words); $i++) {
                     $word = trim($words[$i]);
                     if ($i > 0) {
                         $word = ucfirst($word);
                     }
                     $newAction .= $word;
                 }
                 $action = $newAction;
             }
             $actionName = $action . 'Action';
             if (Arrays::in('init', $actions)) {
                 $controller->init();
             }
             if (Arrays::in('preDispatch', $actions)) {
                 $controller->preDispatch();
             }
             if (!Arrays::in($actionName, $actions)) {
                 throw new Exception("The action '{$actionName}' does not exist.");
             }
             $controller->{$actionName}();
             if (File::exists($tpl)) {
                 $controller->view->render();
             }
             /* stats */
             if (File::exists($tpl) && null === container()->getNoShowStats() && null === $route->getNoShowStats()) {
                 echo View::showStats();
             }
             if (Arrays::in('postDispatch', $actions)) {
                 $controller->preDispatch();
             }
             if (Arrays::in('exit', $actions)) {
                 $controller->exit();
             }
         } else {
             context()->is404();
         }
     } else {
         context()->is404();
     }
 }
Esempio n. 13
0
File: Csv.php Progetto: schpill/thin
 public function validateLineBreak()
 {
     $lineBreak = $this->getLineBreak();
     if (Arrays::in($lineBreak, array("\r\n", "\n"))) {
         return $lineBreak;
     }
     throw new Exception("Invalid line break. Please use unix \\n or win \\r\\n line breaks.");
 }
Esempio n. 14
0
 /**
  * Determine if a key and message combination already exists.
  *
  * @param  string  $key
  * @param  string  $message
  * @return bool
  */
 protected function unique($key, $message)
 {
     return !isset($this->messages[$key]) || !Arrays::in($message, $this->messages[$key]);
 }
Esempio n. 15
0
 /**
  * Check if a rowid exists in the current cart instance
  *
  * @param  string  $id  Unique ID of the item
  * @return boolean
  */
 protected function hasRowId($rowId)
 {
     $cart = $this->getContent();
     $rows = $cart->_fields;
     return Arrays::in($rowId, $rows);
 }
Esempio n. 16
0
 /**
  * Assert that value is in array of choices.
  *
  * @param mixed $value
  * @param array $choices
  * @param string $message
  * @param string $propertyPath
  * @return void
  * @throws Exception
  */
 public static function choice($value, array $choices, $message = null, $propertyPath = null)
 {
     if (!Arrays::in($value, $choices, true)) {
         $message = $message ?: sprintf('Value "%s" is not an element of the valid values: %s', static::stringify($value), implode(", ", array_map('Assert\\Assertion::stringify', $choices)));
         throw static::createException($value, $message, static::INVALID_CHOICE, $propertyPath, array('choices' => $choices));
     }
 }
Esempio n. 17
0
 public function get($results = null)
 {
     $resultsGet = null !== $results ? $results : $this->results;
     $queryKey = sha1(serialize($this->wheres) . serialize($resultsGet));
     $cache = Data::cache($this->type, $queryKey);
     if (!empty($cache) && true === $this->cache) {
         return $cache;
     }
     if (count($resultsGet)) {
         if (null !== $this->groupBy) {
             $groupBys = array();
             $ever = array();
             foreach ($resultsGet as $key => $id) {
                 $object = Data::getById($this->type, $id);
                 $getter = getter($this->groupBy);
                 $obj = $object->{$getter}();
                 if ($obj instanceof Container) {
                     $obj = $obj->getId();
                 }
                 if (!Arrays::in($obj, $ever)) {
                     $groupBys[$key] = $id;
                     $ever[] = $obj;
                 }
             }
             $this->results = $groupBys;
             $this->order($this->groupBy);
             $resultsGet = $this->results;
         }
         if (0 < $this->limit) {
             $max = count($resultsGet);
             $number = $this->limit - $this->offset;
             if ($number > $max) {
                 $this->offset = $max - $this->limit;
                 if (0 > $this->offset) {
                     $this->offset = 0;
                 }
                 $this->limit = $max;
             }
             $resultsGet = array_slice($resultsGet, $this->offset, $this->limit);
         }
     }
     $collection = array();
     if (count($resultsGet)) {
         $_sum = 0;
         $_avg = 0;
         $_min = 0;
         $_max = 0;
         $first = true;
         foreach ($resultsGet as $key => $id) {
             $object = Data::getById($this->type, $id);
             if (null !== $this->sum) {
                 $getter = getter($this->sum);
                 $_sum += $object->{$getter}();
             }
             if (null !== $this->avg) {
                 $getter = getter($this->avg);
                 $_avg += $object->{$getter}();
             }
             if (null !== $this->min) {
                 $getter = getter($this->min);
                 if (true === $first) {
                     $_min = $object->{$getter}();
                 } else {
                     $_min = $object->{$getter}() < $_min ? $object->{$getter}() : $_min;
                 }
             }
             if (null !== $this->max) {
                 $getter = getter($this->max);
                 if (true === $first) {
                     $_max = $object->{$getter}();
                 } else {
                     $_max = $object->{$getter}() > $_max ? $object->{$getter}() : $_max;
                 }
             }
             $collection[] = $object;
             $first = false;
         }
     }
     if (null !== $this->min) {
         $collection = $_min;
     }
     if (null !== $this->max) {
         $collection = $_max;
     }
     if (null !== $this->sum) {
         $collection = $_sum;
     }
     if (null !== $this->avg) {
         $collection = $_avg / count($collection);
     }
     $cache = Data::cache($this->type, $queryKey, $collection);
     return $collection;
 }
Esempio n. 18
0
 protected static function id($name, $attributes)
 {
     // If an ID has been explicitly specified in the attributes, we will
     // use that ID. Otherwise, we will look for an ID in the array of
     // label names so labels and their elements have the same ID.
     if (Arrays::exists('id', $attributes)) {
         return $attributes['id'];
     }
     if (Arrays::in($name, static::$labels)) {
         return $name;
     }
 }
Esempio n. 19
0
File: Cms.php Progetto: schpill/thin
 public static function loadDatas()
 {
     set_time_limit(0);
     $session = session('admin');
     $dirData = STORAGE_PATH . DS . 'data';
     if (!is_dir(STORAGE_PATH)) {
         mkdir(STORAGE_PATH, 0777);
     }
     if (!is_dir($dirData)) {
         mkdir($dirData, 0777);
     }
     $entities = array();
     if (is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Data' . DS . SITE_NAME)) {
         $datas = glob(APPLICATION_PATH . DS . 'models' . DS . 'Data' . DS . SITE_NAME . DS . '*.php');
         if (count($datas)) {
             foreach ($datas as $model) {
                 $infos = (include $model);
                 $tab = explode(DS, $model);
                 $entity = repl('.php', '', Inflector::lower(Arrays::last($tab)));
                 $entities[] = $entity;
                 $fields = $infos['fields'];
                 $settings = $infos['settings'];
                 Data::$_fields[$entity] = $fields;
                 Data::$_settings[$entity] = $settings;
             }
         }
     } else {
         mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Data' . DS . SITE_NAME, 0777);
     }
     $customtypes = Data::getAll('customtype');
     if (count($customtypes)) {
         foreach ($customtypes as $path) {
             $customtype = Data::getIt('customtype', $path);
             $entity = 'custom_' . Inflector::lower($customtype->getEntity());
             $entities[] = $entity;
             Data::$_fields[$entity] = eval('return ' . $customtype->getChamp() . ';');
             Data::$_settings[$entity] = eval('return ' . $customtype->getParam() . ';');
         }
     }
     if (count(Data::$_fields)) {
         foreach (Data::$_fields as $entity => $info) {
             if (!Arrays::in($entity, $entities)) {
                 $entities[] = $entity;
             }
         }
     }
     container()->setEntities($entities);
     $adminrights = Data::getAll('adminright');
     if (!count($adminrights)) {
         if (count($entities)) {
             static::fixtures();
         }
     } else {
         $adminTables = Data::getAll('admintable');
         if (count($adminTables)) {
             foreach ($adminTables as $path) {
                 $adminTable = Data::getIt('admintable', $path);
                 if ($adminTable instanceof Container) {
                     if (!Arrays::in($adminTable->getName(), $entities)) {
                         $sql = dm('adminright');
                         $rights = $sql->where('admintable = ' . $adminTable->getId())->get();
                         $adminTable->delete();
                         if (count($rights)) {
                             foreach ($rights as $right) {
                                 $right->delete();
                             }
                         }
                         $session->setRights(array());
                     }
                 }
             }
         }
     }
 }
Esempio n. 20
0
                }
                if (!Arrays::in($actionName, $actions)) {
                    return context()->is404();
                }
                $controller->{$actionName}();
                if (File::exists($tpl)) {
                    $controller->view->render();
                }
                /* stats */
                if (File::exists($tpl) && null === container()->getNoShowStats() && null === $route->getNoShowStats()) {
                    echo View::showStats();
                }
                if (Arrays::in('postDispatch', $actions)) {
                    $controller->preDispatch();
                }
                if (Arrays::in('exit', $actions)) {
                    $controller->exit();
                }
                container()->setIsDispatched(true);
            }
        } else {
            context()->is404();
        }
    }
});
$core->config(function () {
    static $settings = array();
    $name = Arrays::first(func_get_args());
    if (func_num_args() === 1) {
        if (Arrays::is($name)) {
            $settings = array_merge($settings, $name);
Esempio n. 21
0
                 array_push($codeLines, $i . '. ' . $codeLine);
             }
             $i++;
         }
         wdd('<div style="text-align: center; padding: 5px; color: black; border: solid 1px black; background: #f2f2f2;">' . $typeError . '</div>', '<div style="padding: 5px; color: red; border: solid 1px red; background: #f2f2f2;">' . $message . '</div>', '<div style="padding: 5px; color: navy; border: solid 1px navy; background: #f2f2f2;">' . $file . ' [<em>line: <u>' . $line . '</u></em>]</div>', '<div style="font-family: Consolas; font-weight: 400; padding: 5px; color: green; border: solid 1px green; background: #f2f2f2;">' . implode("\n", $codeLines) . '</div>', '<div style="text-align: center; padding: 5px; color: black; border: solid 1px black; background: #f2f2f2;">BACKTRACE</div>', '<div style="padding: 5px; color: purple; border: solid 1px purple; background: #f2f2f2;">' . displayCodeLines() . '</div>');
     }
 });
 register_shutdown_function(function () {
     $exception = error_get_last();
     if ($exception) {
         $message = isAke($exception, 'message', 'NA');
         $type = isAke($exception, 'type', 1);
         $line = isAke($exception, 'line', 1);
         $file = isAke($exception, 'file');
         $exception = new \ErrorException($message, $type, 0, $file, $line);
         $typeError = Arrays::in($type, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]) ? 'FATAL ERROR' : 'ERROR';
         if (fnmatch('*Allowed memory size*', $message)) {
             dd($file . '[' . $message . ']', 'Ligne:' . $line);
         } elseif (!fnmatch('*undefinedVariable*', $message) && !fnmatch('*connected*', $message) && file_exists($file)) {
             $start = $line > 5 ? $line - 5 : $line;
             $code = File::readLines($file, $start, $line + 5);
             $lines = explode("\n", $code);
             $codeLines = [];
             $i = $start;
             foreach ($lines as $codeLine) {
                 if ($i == $line) {
                     array_push($codeLines, $i . '. <span style="background-color: gold; color: black;">' . $codeLine . '</span>');
                 } else {
                     array_push($codeLines, $i . '. ' . $codeLine);
                 }
                 $i++;
Esempio n. 22
0
File: Orm.php Progetto: schpill/thin
 public function _getEmFromKey($key)
 {
     $classModel = $this->_datas['classModel'];
     $obj = new $classModel();
     if (Arrays::in($key, $this->_datas['keys'])) {
         if (isset($this->_datas['configModel']['relationship']) && ake($key, $this->_datas['configModel']['relationship'])) {
             $m = $this->_datas['configModel']['relationship'][$key];
             if (ake($modelField, $this->_datas['configModel']['relationshipEntities'])) {
                 $entity = $this->_datas['configModel']['relationshipEntities'][$key];
             } else {
                 $entity = $obj->_entity;
             }
             if (null !== $m) {
                 return new self($entity, $m['foreignTable']);
             }
         }
     }
     return null;
 }
Esempio n. 23
0
 /**
  * Determine if the request accepts a given content type.
  *
  * @param  string  $type
  * @return bool
  */
 public static function accepts($type)
 {
     return Arrays::in($type, static::accept());
 }
Esempio n. 24
0
 private function compare($comp, $op, $value)
 {
     $keyCache = sha1('compare_' . serialize(func_get_args()));
     $cached = $this->cached($keyCache);
     if (empty($cached)) {
         $res = false;
         if (isset($comp)) {
             $comp = Inflector::lower($comp);
             $value = Inflector::lower($value);
             switch ($op) {
                 case '=':
                     $res = sha1($comp) == sha1($value);
                     break;
                 case '>=':
                     $res = $comp >= $value;
                     break;
                 case '>':
                     $res = $comp > $value;
                     break;
                 case '<':
                     $res = $comp < $value;
                     break;
                 case '<=':
                     $res = $comp <= $value;
                     break;
                 case '<>':
                 case '!=':
                     $res = sha1($comp) != sha1($value);
                     break;
                 case 'LIKE':
                     $value = repl("'", '', $value);
                     $value = repl('%', '', $value);
                     if (strstr($comp, $value)) {
                         $res = true;
                     }
                     break;
                 case 'NOTLIKE':
                     $value = repl("'", '', $value);
                     $value = repl('%', '', $value);
                     if (!strstr($comp, $value)) {
                         $res = true;
                     }
                     break;
                 case 'LIKE START':
                     $value = repl("'", '', $value);
                     $value = repl('%', '', $value);
                     $res = substr($comp, 0, strlen($value)) === $value;
                     break;
                 case 'LIKE END':
                     $value = repl("'", '', $value);
                     $value = repl('%', '', $value);
                     if (!strlen($comp)) {
                         $res = true;
                     }
                     $res = substr($comp, -strlen($value)) === $value;
                     break;
                 case 'IN':
                     $value = repl('(', '', $value);
                     $value = repl(')', '', $value);
                     $tabValues = explode(',', $value);
                     $res = Arrays::in($comp, $tabValues);
                     break;
                 case 'NOTIN':
                     $value = repl('(', '', $value);
                     $value = repl(')', '', $value);
                     $tabValues = explode(',', $value);
                     $res = !Arrays::in($comp, $tabValues);
                     break;
             }
         }
         $this->cached($keyCache, $res);
         return $res;
     }
     return $cached;
 }
Esempio n. 25
0
 /**
  * private function trimLast ()
  * method to trim the bad endings
  */
 private function trimLast($string)
 {
     $length = strlen($string) - 1;
     if (Arrays::in($string[$length], array('t', 'x'))) {
         $string = substr($string, 0, $length);
     }
 }
Esempio n. 26
0
File: gma.php Progetto: noikiy/inovi
 private function isImage($file)
 {
     $exts = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'svg', 'tiff');
     if (strstr($file, '.')) {
         $tab = explode('.', $file);
         $ext = Inflector::lower(Arrays::last($tab));
         return Arrays::in($ext, $exts);
     }
     return false;
 }
Esempio n. 27
0
File: Acl.php Progetto: schpill/thin
 public function check()
 {
     $user = Utils::get('FTVUser');
     $aclRoles = $this->_datas['config']['acl']['roles'];
     $adminRole = $this->_datas['roleModel']->findByRoleName($this->_datas['config']['role']['admin']);
     $userRoles = em($this->_datas['config']['usersroles']['entity'], $this->_datas['config']['usersroles']['table'])->findByAccountId($user->getId());
     if (count($userRoles) == 1) {
         $userRoles = array($userRoles);
     }
     // check if role is allowed in application
     $continue = false;
     foreach ($userRoles as $uRole) {
         $roleName = em($this->_datas['config']['roles']['entity'], $this->_datas['config']['roles']['table'])->find($uRole->getRoleId())->getRoleName();
         $continue = Arrays::in($roleName, $aclRoles);
         if (true === $continue) {
             break;
         }
     }
     if (false === $continue) {
         Utils::go($this->_datas['noRight']);
         exit;
     }
     // check by user cannot
     if (count($this->_datas['cannotUsers'])) {
         if (Arrays::in($user->getId(), $this->_datas['cannotUsers'])) {
             Utils::go($this->_datas['noRight']);
             exit;
         }
     }
     // check by role cannot
     if (count($this->_datas['cannotRoles'])) {
         foreach ($this->_datas['cannotRoles'] as $idRole) {
             foreach ($userRoles as $uRole) {
                 $uRoleId = $uRole->getRoleId();
                 if ($idRole == $uRoleId) {
                     Utils::go($this->_datas['noRight']);
                     exit;
                 }
             }
         }
     }
     // check by user can
     if (count($this->_datas['canUsers'])) {
         if (Arrays::in($user->getId(), $this->_datas['canUsers'])) {
             return $this;
         }
     }
     // check by role can
     if (count($this->_datas['canRoles'])) {
         foreach ($this->_datas['canRoles'] as $idRole) {
             foreach ($userRoles as $uRole) {
                 $uRoleId = $uRole->getRoleId();
                 if ($idRole == $uRoleId) {
                     return $this;
                 }
             }
         }
     }
     // check if admin Role
     foreach ($userRoles as $uRole) {
         $idRole = $uRole->getRoleId();
         if ($idRole == $adminRole->getId()) {
             return $this;
         }
     }
 }