Example #1
0
 public static function init($options = [])
 {
     $self = new self($options);
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         if (isset($_GET['reset'])) {
             echo '{ "success": "' . ($self->resetCache() ? 'yes' : 'no') . '" }';
         } else {
             if (isset($_GET['invalidate'])) {
                 echo '{ "success": "' . ($self->resetCache($_GET['invalidate']) ? 'yes' : 'no') . '" }';
             } else {
                 echo json_encode($self->getData(@$_GET['section'] ?: null));
             }
         }
         exit;
     } else {
         if (isset($_GET['reset'])) {
             $self->resetCache();
         } else {
             if (isset($_GET['invalidate'])) {
                 $self->resetCache($_GET['invalidate']);
             }
         }
     }
     return $self;
 }
Example #2
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Template
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $template = new self();
     $data = [];
     if (array_key_exists('data', $array)) {
         $data = $array['data'];
     } elseif ($strict) {
         throw new MissingArgumentException('data');
     }
     try {
         foreach ($data as $key => $dataArray) {
             if (!is_array($dataArray)) {
                 throw new ExpectedArrayException($key, gettype($dataArray));
             }
             try {
                 $template->getData()->add(Data::fromArray($dataArray, $strict));
             } catch (FromArrayCompilationException $e) {
                 throw new FromArrayCompilationException($key, $e->getMessage());
             }
         }
     } catch (FromArrayCompilationException $e) {
         throw new FromArrayCompilationException('data', $e->getMessage());
     }
     return $template;
 }
Example #3
0
 /**
  * A Static function that return the amount of points you need
  * @param array $data an array containing the points
  * @param int $amount the number of points you want to get
  * @param bool $ordered (optional) wether you want the points ordered by priority values or not (if not they will be ordered by abscissa values). Default is false.
  * @param string|int $x (optional) key of the abscissa values in each element of your data, default is 'x'
  * @param string|int $y (optional) key of the ordinate values in each element of your data, default is 'y'
  * @param string|int $priority (optional) key of the priority value in each element of data returned, default is 'priority'
  * @return array an array containing the filtered points
  */
 public static function filterPoints($data, $amount, $ordered = false, $x = 'x', $y = 'y', $priority = 'priority')
 {
     $Vis = new self($data, $x, $y, $priority);
     if ($ordered) {
         return $Vis->getOrderedData($amount);
     }
     return $Vis->getData($amount);
 }
 public static function deleteModelCommentaireAllByIdArticle($idArticle)
 {
     $model = new self(array());
     $model->collectionCommentaire = CommentaireGateway::getCommentaireAllByIdArticle($model->dataError, $idArticle);
     foreach ($model->getData() as $commentaire) {
         ModelCommentaire::deleteCommentaire($commentaire->getIdCom());
     }
 }
Example #5
0
    /**
     * Возвращает массив данных с ключами $valid_keys
     * где inetnum - сеть, country - индекс страны, city - название города
     * region - название региона, district - название округа, lat, lng - координаты
     * @param str $ip IP адрес клиента
     * @param str $key Один из параметров, перечисленных выше
     * @param bool $cache Кешировать в куки и отдавать из них
     * @return mixed
     */
    public static function getInfo($ip, $key = false, $cache = true) {
        // для работы требуется CURL
        if (!function_exists('curl_setopt') || !function_exists('curl_init')) { return false; }

        // если уже получали данные, возвращаем их сразу
        $cookie_data = (string)cmsCore::getCookie('geodata');
        if (!empty(self::$data[$ip])) {
            $data = self::$data[$ip];
        } else if ($cookie_data && $cache) {
            $data = unserialize($cookie_data);
            if (is_array($data)) {
                $data = cmsCore::cleanVar($data, 'array_str', null);
            } else {
                unset($data);
            }
        }

        if (!isset($data)) {

            // выполняем запрос к ipgeobase.ru
            $thisObj = new self($ip);

            $data = $thisObj->getData();
            if(!$data){ return false; }

            // сохраняем ответ
            // в свойство
            self::$data[$ip] = $data;
            // и в куки на сутки
            if($cache){
                cmsCore::setCookie('geodata', serialize($data), time()+3600*24);
            }

        }

        // можно запрашивать только определенные ключи
        if (!in_array($key, self::$valid_keys)) {
            $key = false;
        }

        // что возвращаем
        if ($key && isset($data[$key])) {
            return $data[$key];
        } else {
            return $data;
        }

    }
Example #6
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Query
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $href = '';
     $rel = '';
     $name = '';
     $prompt = '';
     if (array_key_exists('href', $array)) {
         $href = $array['href'];
     } elseif ($strict) {
         throw new MissingArgumentException('href');
     }
     if (array_key_exists('rel', $array)) {
         $rel = $array['rel'];
     } elseif ($strict) {
         throw new MissingArgumentException('rel');
     }
     if (array_key_exists('name', $array)) {
         $name = $array['name'];
     }
     if (array_key_exists('prompt', $array)) {
         $prompt = $array['prompt'];
     }
     $query = new self($href, $rel, $name, $prompt);
     if (array_key_exists('data', $array)) {
         if (!is_array($array['data'])) {
             throw new ExpectedArrayException('data', gettype($array['data']));
         }
         try {
             foreach ($array['data'] as $key => $dataArray) {
                 if (!is_array($dataArray)) {
                     throw new ExpectedArrayException($key, gettype($dataArray));
                 }
                 try {
                     $query->getData()->add(Data::fromArray($dataArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('data', $e->getMessage());
         }
     }
     return $query;
 }
Example #7
0
 public static function runRestMethod($executiveUserId, $methodName, $args, $navigation)
 {
     static $arManifest = null;
     static $arMethodsMetaInfo = null;
     if ($arManifest === null) {
         $arManifest = self::getManifest();
         $arMethodsMetaInfo = $arManifest['REST: available methods'];
     }
     // Check and parse params
     CTaskAssert::assert(isset($arMethodsMetaInfo[$methodName]));
     $arMethodMetaInfo = $arMethodsMetaInfo[$methodName];
     $argsParsed = CTaskRestService::_parseRestParams('ctaskchecklistitem', $methodName, $args);
     $returnValue = null;
     if (isset($arMethodMetaInfo['staticMethod']) && $arMethodMetaInfo['staticMethod']) {
         if ($methodName === 'add') {
             $taskId = $argsParsed[0];
             $arFields = $argsParsed[1];
             $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId);
             $oItem = self::add($oTaskItem, $arFields);
             $returnValue = $oItem->getId();
         } elseif ($methodName === 'getlist') {
             $taskId = $argsParsed[0];
             $order = $argsParsed[1];
             $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId);
             list($oCheckListItems, $rsData) = self::fetchList($oTaskItem, $order);
             $returnValue = array();
             foreach ($oCheckListItems as $oCheckListItem) {
                 $returnValue[] = $oCheckListItem->getData(false);
             }
         } else {
             $returnValue = call_user_func_array(array('self', $methodName), $argsParsed);
         }
     } else {
         $taskId = array_shift($argsParsed);
         $itemId = array_shift($argsParsed);
         $oTaskItem = CTaskItem::getInstance($taskId, $executiveUserId);
         $obElapsed = new self($oTaskItem, $itemId);
         if ($methodName === 'get') {
             $returnValue = $obElapsed->getData();
         } else {
             $returnValue = call_user_func_array(array($obElapsed, $methodName), $argsParsed);
         }
     }
     return array($returnValue, null);
 }
Example #8
0
File: db.php Project: nikilster/I
 public static function getRandomUnstartedActivityForUser($userId)
 {
     //We know this is clean
     $db = new self($userId);
     //Current date (Now in Mysql datetime format)
     $now = date("Y-m-d H:i:s");
     $activities = $db->getData($now);
     //Get the activities that are 0
     $unstartedActivities = array();
     foreach ($activities as $a) {
         if ($a['duration'] == 0) {
             array_push($unstartedActivities, $a);
         }
     }
     //TODO: if all of the activities are started - suggest important
     //Choose an activity at random
     $numActivities = count($unstartedActivities);
     if ($numActivities > 0) {
         return $unstartedActivities[rand(0, $numActivities - 1)];
     } else {
         return null;
     }
 }
Example #9
0
 /**
  * Lay thong tin user tu session (danh cho user da login hoac su dung remember me
  *
  */
 public function updateFromSession($registry)
 {
     $setting = $registry->setting;
     if ($registry->session->has('userLogin') && $registry->session->get('userLogin') > 0) {
         //New way
         $userid = (int) $registry->session->get('userLogin');
         $myCacher = new Cacher(self::cacheBuildKeystringDetail($userid));
         $userInfo = $myCacher->get();
         if (!$userInfo || $registry->request->query->has('live')) {
             $sql = 'SELECT * FROM lit_ac_user u
                     INNER JOIN lit_ac_user_profile up ON u.u_id = up.u_id
                     WHERE u.u_id = ?';
             $userInfo = $this->db->query($sql, array($userid))->fetch();
             $myCacher->set($userInfo, 3600);
         }
         $this->getDataByArray($userInfo);
     } elseif ($registry->request->cookies->has('myHashing') && strlen($registry->request->cookies->get('myHashing')) > 0) {
         $cookieRememberMeInfo = \Litpi\ViephpHashing::cookiehasingParser($registry->request->cookies->get('myHashing'));
         $myUserTmp = new self();
         $myUserTmp->getData($cookieRememberMeInfo['userid']);
         if (\Litpi\ViephpHashing::authenticateCookiehashing($cookieRememberMeInfo['shortPasswordString'], $myUserTmp->password)) {
             $registry->session->migrate();
             $this->copy($myUserTmp);
             ////////////////////////////////////////////////////////////////////////////////////
             //UPDATE LAST LOGIN TIME
             $sql = 'UPDATE ' . TABLE_PREFIX . 'ac_user_profile
                     SET up_datelastlogin = ?
                     WHERE u_id = ?
                     LIMIT 1';
             $this->db->query($sql, array(time(), $this->id));
             $registry->session->set('userLogin', $this->id);
             $registry->session->set('loginauto', 1);
         }
     }
 }
Example #10
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Item
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $href = '';
     if (array_key_exists('href', $array)) {
         $href = $array['href'];
     } elseif ($strict) {
         throw new MissingArgumentException('href');
     }
     $item = new self($href);
     if (array_key_exists('data', $array)) {
         if (!is_array($array['data'])) {
             throw new ExpectedArrayException('data', gettype($array['data']));
         }
         try {
             foreach ($array['data'] as $key => $dataArray) {
                 if (!is_array($dataArray)) {
                     throw new ExpectedArrayException($key, gettype($dataArray));
                 }
                 try {
                     $item->getData()->add(Data::fromArray($dataArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('data', $e->getMessage());
         }
     }
     if (array_key_exists('links', $array)) {
         if (!is_array($array['links'])) {
             throw new ExpectedArrayException('links', gettype($array['links']));
         }
         try {
             foreach ($array['links'] as $key => $linkArray) {
                 if (!is_array($linkArray)) {
                     throw new ExpectedArrayException($key, gettype($linkArray));
                 }
                 try {
                     $item->getLinks()->add(Link::fromArray($linkArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('links', $e->getMessage());
         }
     }
     return $item;
 }