コード例 #1
0
ファイル: Mailing.php プロジェクト: rsids/bright_api
 /**
  * Saves a mailing
  * @param OPage $mailing The mailing to save
  * @return \stdClass An object containing mailing, the just saved mailing and mailings, an array of all mailings
  * @throws \Exception
  */
 public function setMailing(OPage $mailing)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(1001);
     }
     $page = new Page();
     $mailing = $page->setPage($mailing, false);
     $result = new \stdClass();
     // Fetch mailing again, fixes #43
     $result->mailing = $page->getPageById($mailing->pageId, false, true);
     $result->mailings = $page->getPages(1, null, true);
     return $result;
 }
コード例 #2
0
ファイル: Backup.php プロジェクト: rsids/bright_api
 public function restoreBackup($backupId, $fields)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(1001);
     }
     if (!is_numeric($backupId)) {
         throw $this->throwException(2002);
     }
     if (!is_array($fields)) {
         throw $this->throwException(2007);
     }
     $backup = $this->getBackupById($backupId);
     if (!$backup) {
         throw $this->throwException(5004);
     }
     $page = new Page();
     $current = $page->getPageById($backup->content->pageId);
     if ($current) {
         foreach ($fields as $field) {
             // Sanitize input
             $field = addslashes($field);
             if (!isset($current->content)) {
                 $current->content = new \stdClass();
             }
             // Remove current property
             if (isset($current->content->{$field})) {
                 unset($current->content->{$field});
             }
             // Restore backed-up property (if present)
             // THIS MEANS THAT IT WILL BE NULL IF ITS NOT PRESENT IN THE BACKUP
             if (isset($backup->content->content->{$field})) {
                 $current->content->{$field} = $backup->content->content->{$field};
             }
         }
         $page->setPage($current, false, false);
     }
 }
コード例 #3
0
ファイル: Maps.php プロジェクト: rsids/bright_api
 /**
  * Saves a full poly
  * @param OPoly $poly
  * @return OPoly
  */
 public function setFullPoly($poly)
 {
     $page = new Page();
     $p = $page->setPage($poly, false, false);
     if ($poly->pageId == 0) {
         $poly->pageId = $p->pageId;
     }
     $sql = 'UPDATE `gm_polys` ' . 'SET `layer`=' . (int) $poly->layer . ', ' . '`uselayercolor`=' . (int) $poly->uselayercolor . ', ' . '`enabled`=' . (int) $poly->enabled . ', ' . '`pageId`=' . (int) $poly->pageId . ', ' . '`color`=' . (int) $poly->color . ', ' . '`label`=\'' . Connection::getInstance()->escape_string($poly->label) . '\', ' . '`search`=\'' . Connection::getInstance()->escape_string(BrightUtils::createSearchString($poly)) . '\' ' . 'WHERE `polyId`=' . (int) $poly->polyId;
     $this->_conn->updateRow($sql);
     $cache = new Cache();
     $cache->deleteCacheByPrefix('marker');
     return $this->getPoly($poly->polyId, true);
 }
コード例 #4
0
ファイル: Tree.php プロジェクト: rsids/bright_api
 /**
  * Adds a new page to the tree<br/>
  * Required permissions:<br/>
  * <ul>
  * <li>IS_AUTH</li>
  * </ul>
  * @param OPage $page page The page to add
  * @param int $parentId The id of the parent
  * @param int $index The index of the page
  * @param bool $returnId Return the id of the page?
  * @return array|int The new treenode
  * @throws \Exception
  */
 public function setPage($page, $parentId, $index, $returnId = false)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     if (!is_numeric($parentId) || !is_numeric($index)) {
         throw $this->throwException(ParameterException::INTEGER_EXCEPTION);
     }
     // If page already exists, throw exist exception
     if ($this->_checkForPageExistance($page->pageId, $parentId)) {
         throw $this->throwException(6003);
     }
     // Check if the number of children doesn't exceed the maximum
     $ncResult = $this->_getMaxChildren($parentId);
     if ((double) $ncResult->numchildren >= (double) $ncResult->maxchildren && (double) $ncResult->maxchildren > -1) {
         $this->throwException(6001, array($ncResult->maxchildren));
     }
     if ((int) $page->pageId == 0) {
         $pageClass = new Page();
         $page = $pageClass->setPage($page, false);
     }
     if (class_exists('TreeHook')) {
         $ph = new \TreeHook();
         if (method_exists($ph, 'preSetPage')) {
             $page = $ph->preSetPage($page, $parentId, $index);
         }
     }
     $loginreq = $page->itemLabel == 'login' ? 1 : 0;
     // If parent is a login, set required to 1,
     // This way, we can easily exclude hidden pages from search and sitemap
     if ($loginreq == 0) {
         $sql = 'SELECT `loginrequired` FROM tree WHERE `parentId`=' . $parentId;
         $result = $this->_conn->getRow($sql);
         if ($result) {
             $loginreq = (int) $result->loginrequired;
         }
     }
     $this->_cleanIndexes($parentId);
     $this->_updateIndexes($index, 1, $parentId);
     $sql = 'INSERT INTO tree (`parentId`, `pageId`, `index`, `loginrequired`) ' . 'VALUES ' . '(' . $parentId . ', ' . $page->pageId . ', ' . $index . ', ' . $loginreq . ')';
     $id = $this->_conn->insertRow($sql);
     $cache = new Cache();
     $cache->flushCache();
     $this->generateSitemap();
     if (isset($ph) && method_exists($ph, 'postSetPage')) {
         $ph->postSetPage($page, $parentId);
     }
     if ($returnId) {
         return $id;
     }
     return $this->getChildren($parentId);
 }
コード例 #5
0
ファイル: Files.php プロジェクト: rsids/bright_api
 /**
  * Moves a file from oldpath to newpath<br/>
  * Required permissions:<br/>
  * <ul>
  * <li>IS_AUTH</li>
  * </ul>
  * @param string $oldPath The directory where the file currently resides, relative to the base folder specified in the config.ini
  * @param string $newPath The target directory, relative to the base folder specified in the config.ini
  * @param string $filename The file to move
  * @return array The contents of oldpath
  * @throws \Exception
  */
 public function moveFile($oldPath, $newPath, $filename)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     if (!is_dir(BASEPATH . UPLOADFOLDER . $oldPath)) {
         throw $this->throwException(FilesException::PARENT_NOT_FOUND);
     }
     if (!file_exists(BASEPATH . UPLOADFOLDER . $oldPath . $filename)) {
         throw $this->throwException(FilesException::FILE_NOT_FOUND);
     }
     if (file_exists(BASEPATH . UPLOADFOLDER . $newPath . $filename)) {
         throw $this->throwException(FilesException::DUPLICATE_FILENAME);
     }
     $thumbParts = explode('.', $filename);
     $thumbParts[count($thumbParts) - 2] .= '__thumb__';
     $thumb = join('.', $thumbParts);
     $ext = $thumbParts[count($thumbParts) - 1];
     if (file_exists(BASEPATH . UPLOADFOLDER . $oldPath . $thumb)) {
         rename(BASEPATH . UPLOADFOLDER . $oldPath . $thumb, BASEPATH . UPLOADFOLDER . $newPath . $thumb);
     }
     if (strpos($filename, '__thumb__') !== false) {
         // Dragged file IS a thumb, move original too
         $thumbParts = explode('__thumb__', $filename);
         $thumb = join('', $thumbParts);
         if (file_exists(BASEPATH . UPLOADFOLDER . $oldPath . $thumb)) {
             rename(BASEPATH . UPLOADFOLDER . $oldPath . $thumb, BASEPATH . UPLOADFOLDER . $newPath . $thumb);
         }
     }
     if (strtolower($ext) === 'pdf') {
         // Update page
         $page = new Page();
         $p = $page->getPageByLabel(md5($oldPath . $filename));
         if ($p) {
             $p->label = md5($newPath . $filename);
             $p->content->path->all = $oldPath . $filename;
             $page->setPage($p);
         } else {
             // Re-index
         }
     }
     rename(BASEPATH . UPLOADFOLDER . $oldPath . $filename, BASEPATH . UPLOADFOLDER . $newPath . $filename);
     return $this->getFiles($oldPath);
 }