コード例 #1
0
ファイル: Settings.php プロジェクト: rsids/bright_api
 /**
  * Gets all the custom defined settings<br/>
  */
 public function getSettings()
 {
     $cache = new Cache();
     $result = $cache->getCache('bright_settings');
     if ($result === false) {
         $sql = 'SELECT * FROM `settings`';
         $result = $this->_conn->getRows($sql);
         $cache->setCache($result, 'bright_settings', time() + 10000000);
     }
     return $result;
 }
コード例 #2
0
ファイル: Maps.php プロジェクト: rsids/bright_api
 private function _getMarker($id, $full, $enabledOnly, $byPage = false)
 {
     $id = (int) $id;
     $cname = 'marker_' . $id;
     $cname .= $full ? 1 : 0;
     $cname .= $enabledOnly ? 1 : 0;
     $cname .= $byPage ? 1 : 0;
     $cache = new Cache();
     $result = $cache->getCache($cname);
     if ($result) {
         return $result;
     }
     $esql = $enabledOnly ? ' AND `enabled`=1' : '';
     if ($byPage) {
         $sql = "SELECT * FROM `gm_markers` WHERE `deleted`=0 {$esql} AND pageId={$id}";
     } else {
         $sql = "SELECT * FROM `gm_markers` WHERE `deleted`=0 {$esql} AND markerId={$id}";
     }
     $marker = $this->_conn->getRow($sql, 'OMarker');
     if (!$marker) {
         return null;
     }
     if (!$full) {
         $cache->setCache($marker, $cname, strtotime('+1 year'));
         return $marker;
     }
     $page = new Page();
     $contents = $page->getPageById($marker->pageId, false, false);
     if ($contents) {
         foreach ($contents as $key => $value) {
             $marker->{$key} = $value;
         }
         $marker->_explicitType = 'OMarker';
     }
     $cache->setCache($marker, $cname, strtotime('+1 year'));
     return $marker;
 }
コード例 #3
0
ファイル: Calendar.php プロジェクト: rsids/bright_api
 /**
  * Gets a page of type 'event'
  * @param $calendarId
  * @throws \Exception
  * @internal param \calendarId $int The id of the page / event
  * @return OCalendarEvent A CalendarEvent
  */
 public function getEvent($calendarId)
 {
     if (!is_numeric($calendarId)) {
         throw $this->throwException(ParameterException::INTEGER_EXCEPTION);
     }
     $c = new Cache();
     $event = $c->getCache("calendaritem_{$calendarId}");
     if (!$event) {
         $sql = "SELECT cn.*, cd.allday, cd.dateId, ce.eventId, cd.noend,\n\t\t\t\t\tUNIX_TIMESTAMP(cd.starttime) as `starttime`,\n\t\t\t\t\tUNIX_TIMESTAMP(cd.endtime) as `endtime`,\n\t\t\t\t\tUNIX_TIMESTAMP(cn.until) as `until`,\n\t\t\t\t\tUNIX_TIMESTAMP(ce.starttime) as `rawstarttime`,\n\t\t\t\t\tUNIX_TIMESTAMP(ce.endtime) as `rawendtime`,\n\t\t\t\t\tce.allday as `rawallday`,\n\t\t\t\t\tce.noend as `rawnoend`,\n\t\t\t\t\tUNIX_TIMESTAMP(cn.creationdate) as `creationdate`,\n\t\t\t\t\tUNIX_TIMESTAMP(cn.modificationdate) as `modificationdate`,\n\t\t\t\t\tit.lifetime as `lifetime`,\n\t\t\t\t\tit.label as `itemLabel`,\n\t\t\t\t\tcd.allday\n\t\t\t\t\tFROM `calendarnew` cn\n\t\t\t\t\tINNER JOIN itemtypes it ON cn.itemType = it.itemId\n\t\t\t\t\tLEFT JOIN `calendardates` cd ON cn.calendarId = cd.calendarId\n\t\t\t\t\tLEFT JOIN `calendareventsnew` ce ON cn.calendarId = ce.calendarId\n\t\t\t\t\tWHERE cn.calendarId={$calendarId}";
         $event = $this->_getEvent($sql);
         // @todo: Check template lifetime
         $c->setCache($event, "calendaritem_{$calendarId}", strtotime('+1 year'));
     }
     return $event;
 }
コード例 #4
0
ファイル: Page.php プロジェクト: rsids/bright_api
 /**
  * Gets all the pages of the specific type, whether they reside in the tree or not
  * @param int $templateId The id template
  * @return array An array of OPages
  */
 public function getPagesByTemplateId($templateId)
 {
     $templateId = (int) $templateId;
     $c = new Cache();
     $cname = 'pages-getPagesByTemplateId-' . $templateId;
     $pages = $c->getCache($cname);
     $sql = "SELECT p.pageId, \n\t\t\t\tp.itemType, \n\t\t\t\tp.label, \n\t\t\t\tit.lifetime as `lifetime`, \n\t\t\t\tit.label as `itemLabel`, \n\t\t\t\tUNIX_TIMESTAMP(p.modificationdate) as `modificationdate`, \n\t\t\t\tUNIX_TIMESTAMP(p.publicationdate) as `publicationdate`, \n\t\t\t\tUNIX_TIMESTAMP(p.expirationdate) as `expirationdate`, \n\t\t\t\tp.alwayspublished,\n\t\t\t\tp.showinnavigation \n\t\t\t\tFROM page p, itemtypes it \n\t\t\t\tWHERE p.itemType = {$templateId} AND p.itemType = it.itemId";
     $pages = $this->conn->getRows($sql, 'OPage');
     if (!$pages) {
         return null;
     }
     foreach ($pages as &$page) {
         $page = $this->getContent($page);
     }
     $c->setCache($pages, $cname, strtotime('+1 year'));
     return $pages;
 }
コード例 #5
0
ファイル: Tree.php プロジェクト: rsids/bright_api
 /**
  * Gets the children by their id's, it also returns their parent nodes, all the way up to the root<br/>
  * Required permissions:<br/>
  * <ul>
  * <li>IS_AUTH</li>
  * </ul>
  * @param array $ids An array of treeIds
  * @param boolean $includeParents When false only an array of pages is returned;
  * @return Object An object with the result as array and as nested array (tree structure)
  */
 public function getChildrenByIds($ids, $includeParents = true)
 {
     $c = new Cache();
     $cname = 'tree-getChildrenByIds-' . md5(json_encode(func_get_args()));
     $ret = $c->getCache($cname);
     if ($ret) {
         return $ret;
     }
     $map = array();
     if ($includeParents === false) {
         foreach ($ids as $id) {
             $map[] = $this->getChild($id, false);
         }
         $c->setCache($map, $cname, strtotime('+1 year'));
         return $map;
     }
     $root = null;
     foreach ($ids as $id) {
         $reqid = (int) $id;
         while ($id != 0) {
             $child = $this->getChild($id, true);
             $child->children = $this->getChildren($id);
             foreach ($child->children as $node) {
                 $tid = (int) $node->treeId;
                 if (!array_key_exists($tid, $map)) {
                     $map[$tid] = $node;
                 } else {
                     $node = $map[$tid];
                 }
             }
             if ($id == $reqid) {
                 $map[$id] = $child;
                 $pid = (int) $child->parentId;
                 if (array_key_exists($pid, $map)) {
                     for ($i = 0; $i < count($map[$pid]->children); $i++) {
                         if ((int) $map[$pid]->children[$i]->treeId == (int) $id) {
                             $map[$pid]->children[$i] = $child;
                         }
                     }
                 }
             } else {
                 if (!array_key_exists($id, $map)) {
                     $map[$id] = $child;
                 }
             }
             $id = (int) $child->parentId;
             if ($id == 0) {
                 $root = $child;
             }
         }
     }
     $ret = new \stdClass();
     $ret->arr = $map;
     $ret->tree = $map[1];
     $c->setCache($ret, $cname, strtotime('+1 year'));
     return $ret;
 }
コード例 #6
0
ファイル: Element.php プロジェクト: rsids/bright_api
 public function filter($start = 0, $limit = 20, $filter = null, $orderfield = 'pageId', $order = 'DESC')
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     $c = new Cache();
     $cname = "element_filter_" . md5(json_encode(func_get_args()));
     $result = $c->getCache($cname);
     if ($result) {
         return $result;
     }
     if ($orderfield == null || $orderfield == 'undefined') {
         $orderfield = 'pageId';
     }
     if ($order != 'DESC' && $order != 'ASC') {
         $order = 'DESC';
     }
     switch ($orderfield) {
         default:
             if (is_numeric($orderfield)) {
                 $orderfield = 'pageId';
             }
     }
     $start = (int) $start;
     $limit = (int) $limit;
     if ($limit == 0) {
         $limit = 20;
     }
     $additionalfields = array();
     $settings = $this->getSettings();
     if ($settings) {
         if ($settings !== null && isset($settings->element) && isset($settings->element->visibleColumns)) {
             foreach ($settings->element->visibleColumns as $col) {
                 if (!in_array($col, Config::$elementColumns)) {
                     $additionalfields[] = $col;
                 }
             }
         }
     }
     $fieldsql = '';
     $joins = array();
     if (count($additionalfields) != 0) {
         $fields = array();
         foreach ($additionalfields as $field) {
             $field = Connection::getInstance()->escape_string($field);
             $fields[] = " COALESCE(co{$field}.value, \\'\\') as `{$field}` ";
             $joins[] = "LEFT JOIN content co{$field} ON cn.pageId = co{$field}.pageId AND co{$field}.`lang`='tpl' AND co{$field}.`field`='{$field}' ";
         }
         $fieldsql = ', ' . join(', ', $fields);
     }
     $groupby = ' GROUP BY pageId ';
     $pdateselect = 'NOW()';
     if ($filter != null && $filter != '') {
         $filter = Connection::getInstance()->escape_string($filter);
         if (strpos($filter, '*') === false) {
             $filter = '*' . $filter . '*';
         }
         $joins[] = "INNER JOIN pageindex ci ON ci.pageId = cn.pageId AND MATCH(`ci`.`search`) AGAINST('{$filter}' IN BOOLEAN MODE) ";
     }
     $joinsql = join("\r\n", $joins) . "\r\n";
     $sql = "SELECT SQL_CALC_FOUND_ROWS cn.*,\n\t\tUNIX_TIMESTAMP(cn.modificationdate) as `modificationdate`,\t\tUNIX_TIMESTAMP(cn.creationdate) as `creationdate`\n\t\t{$fieldsql}\n\t\tFROM `page` cn\n\t\tINNER JOIN itemtypes it ON it.itemId = cn.itemType AND it.templatetype=4\n\t\t{$joinsql}\n\t\t{$groupby}\n\t\tORDER BY {$orderfield} {$order}\n\t\tLIMIT {$start},{$limit}";
     $rows = $this->_conn->getRows($sql, 'OPage');
     $total = (int) $this->_conn->getField('SELECT FOUND_ROWS()');
     $result = (object) array('result' => $rows, 'total' => $total);
     $c->setCache($result, $cname, strtotime('+1 year'));
     return $result;
 }
コード例 #7
0
ファイル: User.php プロジェクト: rsids/bright_api
 /**
  * Gets all the users of the specified template
  * @param int $type The id of the template
  * @param boolean $full When true, all content fields are retrieved
  * @return array|mixed
  */
 public function getUsersOfType($type, $full = true)
 {
     $type = (int) $type;
     $full = $full;
     $c = new Cache();
     $argstring = md5(json_encode(func_get_args()));
     $result = $c->getCache("user_getUsersOfType_{$argstring}");
     if ($result) {
         return $result;
     }
     $sql = "SELECT DISTINCT user.`userId`, user.itemType, user.`email`, user.`activationcode`, user.`label`, user.`registrationdate`, user.`lastlogin`, user.`modificationdate`, user.`activated`, user.`deleted`\n\t\tFROM user\n\t\tWHERE user.itemType = {$type}\n\t\tAND user.activated=1 \n\t\tAND (user.`deleted` IS NULL OR YEAR(user.`deleted`) = 0)";
     $users = $this->conn->getRows($sql, 'OUserObject');
     if ($full) {
         foreach ($users as &$user) {
             $user = $this->getContent($user, true, 'userfields');
         }
     }
     $c->setCache($users, "user_getUsersInGroups_{$argstring}", strtotime('+1 year'));
     return $users;
 }