Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 /**
  * Gets all the pages of the specific type, whether they reside in the tree or not
  * @param string $itemType The name of the template
  * @return array An array of OPages
  */
 public function getPagesByType($itemType)
 {
     $page = new Page();
     $result = $page->getPagesByType($itemType);
     foreach ($result as &$p) {
         $p = $this->localize($p);
     }
     return $result;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
    /**
     * Gets all the nodes with a specified template
     * @param string $type The name of the template
     * @param string $order The field to order the nodes. (t = TreeNode properties, p = page properties)
     * @param int $startIndex The index to begin returning with
     * @param int $maxItems The number of nodes to return
     * @return array An array of OTreeNodes
     * @throws \Exception
     */
    public function getChildrenByType($type = 'homepage', $order = 't.treeId', $startIndex = 0, $maxItems = 0)
    {
        if (!is_numeric($startIndex)) {
            throw $this->throwException(ParameterException::INTEGER_EXCEPTION);
        }
        if (!is_numeric($maxItems)) {
            throw $this->throwException(ParameterException::INTEGER_EXCEPTION);
        }
        $sql = 'SELECT t.* ' . 'FROM tree t ' . 'JOIN page p on t.pageId = p.pageId ' . "WHERE p.itemType = (SELECT it.itemId FROM itemtypes it WHERE it.label = '" . Connection::getInstance()->escape_string($type) . "') " . 'AND ((UNIX_TIMESTAMP(p.publicationdate) <= ' . time() . '
				AND UNIX_TIMESTAMP(p.expirationdate) >= ' . time() . ')
				OR p.alwayspublished = 1) ' . 'ORDER BY ' . Connection::getInstance()->escape_string($order);
        if ($maxItems > 0) {
            $sql .= ' LIMIT ' . $startIndex . ', ' . $maxItems;
        }
        $childrenRows = $this->_conn->getRows($sql);
        $children = array();
        $root = $this->getRoot();
        $page = new Page();
        foreach ($childrenRows as $childRow) {
            $child = new OTreeNode();
            $child->treeId = $childRow->treeId;
            $child->parentId = $childRow->parentId;
            $child->index = $childRow->index;
            $child->path = $this->getPath($child->treeId, $root->treeId);
            $child->page = $page->getPageById($childRow->pageId);
            $child->loginrequired = $childRow->loginrequired;
            $child->init();
            $children[] = $child;
            unset($child);
        }
        return $children;
    }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 private function _parse($pid)
 {
     $tpl = new Template();
     $template = $tpl->getTemplateDefinitionByPageId($pid);
     if ((int) $template->templatetype != 1) {
         throw $this->throwException(7008);
     }
     $_SESSION['language'] = 'tpl';
     $page = new Page();
     $opage = $page->getPageById($pid, false, true);
     $tn = new OTreeNode();
     $tn->page = $opage;
     $tname = $template->itemtype;
     if (!file_exists(BASEPATH . '/bright/site/views/' . $tname . 'View.php')) {
         throw $this->throwException(7010, array($tname . 'View'));
     }
     //		include_once('views/' . $tname . 'View.php');
     $viewclass = $tname . 'View';
     $view = new $viewclass($tn);
     // Simplify page for parsing
     // @deprecated Should not be used anymore
     foreach ($opage->content as $cfield => $value) {
         $opage->{$cfield} = $value;
     }
     $deactivationlink = BASEURL . 'bright/';
     if (defined('USEACTIONDIR') && USEACTIONDIR) {
         $deactivationlink .= 'actions/';
     }
     $deactivationlink .= 'registration.php?action=deactivate&email={email}&code={code}';
     $view->deactivationlink = $deactivationlink;
     define('DEACTIVATIONLINK', $deactivationlink);
     if (method_exists($view, 'parseTemplate')) {
         // Bright parser
         $parsed = $view->parseTemplate($view, $template->itemtype);
     } else {
         // Smarty parser
         \Smarty::muteExpectedErrors();
         $parsed = $view->output();
         \Smarty::unmuteExpectedErrors();
     }
     $parsed = preg_replace_callback('/<img([^>]*)src="\\/([^"]*)"([^>]*)\\/>/ism', array($this, '_replaceImage'), $parsed);
     $result = new \stdClass();
     $result->page = $opage;
     $result->parsed = $parsed;
     return $result;
 }
Exemplo n.º 7
0
    /**
     * Checks if database updates are needed
     * @param string $version The version string from the Frontend
     */
    public function check($version)
    {
        $permissions = $this->getPermissions();
        $this->updatePermissions(array('IS_AUTH', 'MANAGE_ADMIN', 'MANAGE_USER', 'CREATE_PAGE', 'DELETE_PAGE', 'EDIT_PAGE', 'MOVE_PAGE', 'DELETE_FILE', 'MANAGE_TEMPLATE', 'MANAGE_SETTINGS', 'UPLOAD_FILE', 'MANAGE_MAILINGS', 'MANAGE_CALENDARS', 'MANAGE_ELEMENTS', 'MANAGE_MAPS'));
        $varr = explode(' ', $version);
        $build = (int) array_pop($varr);
        if (file_exists(BASEPATH . 'bright/site/hooks/UpdateHook.php')) {
            require_once BASEPATH . 'bright/site/hooks/UpdateHook.php';
            $ch = new \UpdateHook();
            if (method_exists($ch, 'update')) {
                $ch->update($build);
            }
        }
        $prevbuild = $build - 1;
        $this->_conn->updateRow("UPDATE `update` SET `build`={$prevbuild} WHERE `build`=99999");
        $prevbuild = (int) $this->_conn->getField('SELECT MAX(`build`) FROM `update`');
        if ($prevbuild >= $build) {
            return;
        }
        $sqla[] = 'CREATE TABLE IF NOT EXISTS `treeaccess` (
				  `treeId` int(11) NOT NULL,
				  `groupId` int(11) NOT NULL,
				  KEY `treeId` (`treeId`,`groupId`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
        $sqla[] = 'CREATE TABLE IF NOT EXISTS `mailqueue` (
					  `id` int(11) NOT NULL AUTO_INCREMENT,
					  `pageId` int(11) NOT NULL,
					  `groups` varchar(255) CHARACTER SET utf8 NOT NULL,
					  `dateadded` datetime NOT NULL,
					  `issend` tinyint(4) NOT NULL DEFAULT \'0\',
					  PRIMARY KEY (`id`)
					) ENGINE=MyISAM  DEFAULT CHARSET=utf8;';
        $sqla[] = 'CREATE TABLE IF NOT EXISTS `parsers` (
					`parserId` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
					`label` VARCHAR( 255 ) NOT NULL ,
					UNIQUE (`label`)
					) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;';
        $colcheck = "SHOW COLUMNS FROM `user` WHERE `field`='deleted'";
        $field = $this->_conn->getRow($colcheck);
        if (strpos($field->Type, 'tinyint') !== false) {
            $sqla[] = "ALTER TABLE  `user` CHANGE  `deleted`  `deleted` TINYINT( 1 ) NULL DEFAULT  '0'";
            $sqla[] = "UPDATE `user` SET `deleted`= null WHERE `deleted`=0";
            $sqla[] = "ALTER TABLE  `user` CHANGE  `deleted`  `deleted` VARCHAR( 50 ) NULL DEFAULT  NULL";
            $sqla[] = "UPDATE `user` SET `deleted`= NOW() WHERE `deleted`='1'";
            $sqla[] = "ALTER TABLE  `user` CHANGE  `deleted`  `deleted` DATETIME NULL DEFAULT NULL";
            $sqla[] = "ALTER TABLE  `user` ADD UNIQUE (`email` ,`deleted`)";
        }
        $colcheck = "SHOW COLUMNS FROM `userfields` WHERE `field`='lang'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sqla[] = "ALTER TABLE  `userfields` ADD  `lang` VARCHAR( 3 ) NOT NULL DEFAULT  'tpl' AFTER  `userId`";
            $sqla[] = "ALTER TABLE  `userfields` ADD  `index` TINYINT( 1 ) NOT NULL DEFAULT  '1' AFTER  `value`";
        }
        $colcheck = "SHOW COLUMNS FROM `page` WHERE `field`='alwayspublished'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sqla[] = "ALTER TABLE  `page` CHANGE  `allwayspublished`  `alwayspublished` TINYINT( 1 ) NOT NULL ;";
            $sqla[] = "UPDATE administrators SET settings = REPLACE(settings, 'allwayspublished', 'alwayspublished') WHERE settings LIKE '%allwayspublished%';";
        }
        $colcheck = "SHOW COLUMNS FROM `content` WHERE `field`='deleted'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sqla[] = "ALTER TABLE  `content` ADD UNIQUE (`pageId` ,`lang` ,`field` ,`index`);";
            $sqla[] = "ALTER TABLE  `userfields` ADD UNIQUE (`userId` ,`lang` ,`field` ,`index`);";
            $sqla[] = "ALTER TABLE  `content` ADD  `deleted` TINYINT( 1 ) NOT NULL DEFAULT  '0'";
        }
        $sqla[] = "CREATE TABLE IF NOT EXISTS `calendarnew` (\n\t\t\t\t\t  `calendarId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  `itemType` int(11) NOT NULL,\n\t\t\t\t\t  `label` varchar(255) NOT NULL,\n\t\t\t\t\t  `recur` varchar(255) DEFAULT NULL,\n\t\t\t\t\t  `until` datetime DEFAULT NULL,\n\t\t\t\t\t  `deleted` datetime DEFAULT NULL,\n\t\t\t\t\t  `creationdate` timestamp NULL DEFAULT NULL,\n\t\t\t\t\t  `modificationdate` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t  `createdby` int(11) DEFAULT NULL,\n\t\t\t\t\t  `modifiedby` int(11) DEFAULT NULL,\n\t\t\t\t\t  PRIMARY KEY (`calendarId`)\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
        $sqla[] = "CREATE TABLE IF NOT EXISTS `calendardates` (\n\t\t\t\t  `dateId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `calendarId` int(11) NOT NULL,\n\t\t\t\t  `starttime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t  `endtime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t  `allday` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t  `deleted` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t  PRIMARY KEY (`dateId`),\n\t\t\t\t  UNIQUE KEY `calendarId` (`calendarId`,`starttime`,`endtime`)\n\t\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8";
        $sqla[] = "CREATE TABLE IF NOT EXISTS `calendarcontent` (\n\t\t\t\t  `contentId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `calendarId` int(11) NOT NULL,\n\t\t\t\t  `lang` varchar(3) NOT NULL DEFAULT 'ALL',\n\t\t\t\t  `field` varchar(20) NOT NULL,\n\t\t\t\t  `value` longtext NOT NULL,\n\t\t\t\t  `index` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t  `deleted` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t  `searchable` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t  PRIMARY KEY (`contentId`),\n\t\t\t\t  UNIQUE KEY `callangfield` (`calendarId`,`lang`,`field`, `index`),\n\t\t\t\t  KEY `lang` (`lang`,`field`),\n\t\t\t\t  FULLTEXT KEY `value` (`value`)\n\t\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8;";
        $sqla[] = "CREATE TABLE IF NOT EXISTS `calendareventsnew` (\n\t\t\t\t  `eventId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `calendarId` int(11) NOT NULL,\n\t\t\t\t  `starttime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t  `endtime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t  `deleted` tinyint(1) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`eventId`),\n \t\t\t\t  `allday` TINYINT( 1 ) NOT NULL DEFAULT  '0',\n\t\t\t\t  UNIQUE KEY `calendarId` (`calendarId`,`starttime`,`endtime`),\n\t\t\t\t  KEY `calendarId2` (`calendarId`),\n\t\t\t\t  KEY `starttime` (`starttime`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
        $this->_performQueries($sqla);
        $tblcheck = "show tables like 'calendareventsnew'";
        if ($this->_conn->getField($tblcheck)) {
            $colcheck = "SHOW COLUMNS FROM `calendareventsnew` WHERE `field`='allday'";
            $hasField = $this->_conn->getField($colcheck);
            if ($hasField == null) {
                $sqla[] = "ALTER TABLE  `calendareventsnew` ADD  `allday` TINYINT( 1 ) NOT NULL DEFAULT  '0'";
                $sqla[] = "ALTER TABLE  `calendareventsnew` CHANGE  `starttime`  `starttime` TIMESTAMP NULL DEFAULT NULL ,CHANGE  `endtime`  `endtime` TIMESTAMP NULL DEFAULT NULL";
            }
            $colcheck = "SHOW COLUMNS FROM `calendareventsnew` WHERE `field`='noend'";
            $hasField = $this->_conn->getField($colcheck);
            if ($hasField == null) {
                $sqla[] = "ALTER TABLE  `calendareventsnew` ADD  `noend` TINYINT( 1 ) NOT NULL DEFAULT  '0'";
            }
        }
        $tblcheck = "show tables like 'calendardates'";
        if ($this->_conn->getField($tblcheck)) {
            $colcheck = "SHOW COLUMNS FROM `calendardates` WHERE `field`='noend'";
            $hasField = $this->_conn->getField($colcheck);
            if ($hasField == null) {
                $sqla[] = "ALTER TABLE  `calendardates` ADD  `noend` TINYINT( 1 ) NOT NULL DEFAULT  '0'";
            }
        }
        $colcheck = "SHOW COLUMNS FROM `calendarnew` WHERE `field`='enabled'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sql = "ALTER TABLE  `calendarnew` ADD  `enabled` TINYINT( 1 ) NOT NULL DEFAULT  '1' AFTER  `until` , ADD INDEX (  `enabled` )";
            $this->_conn->updateRow($sql);
        }
        $colcheck = "SHOW COLUMNS FROM `calendarnew` WHERE `field`='locationId'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sqla[] = "ALTER TABLE  `calendarnew` ADD  `locationId` INT( 11 ) NULL DEFAULT NULL AFTER  `calendarId`, ADD INDEX (  `locationId` )";
        }
        $colcheck = "SHOW COLUMNS FROM `gm_markers` WHERE `field`='enabled'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sql = "ALTER TABLE  `gm_markers` ADD  `enabled` TINYINT( 1 ) NOT NULL DEFAULT  '1' AFTER  `deleted` , ADD INDEX (  `enabled` )";
            $this->_conn->updateRow($sql);
            $sql = "ALTER TABLE  `gm_polys` ADD  `enabled` TINYINT( 1 ) NOT NULL DEFAULT  '1' AFTER  `deleted` , ADD INDEX (  `enabled` )";
            $this->_conn->updateRow($sql);
        }
        $colcheck = "SHOW COLUMNS FROM `gm_markers` WHERE `field`='street'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sql = "ALTER TABLE  `gm_markers` ADD  `street` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD  `number` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD  `zip` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD  `city` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD  `country` INT( 11 ) NULL DEFAULT NULL";
            $this->_conn->updateRow($sql);
        }
        $colcheck = "SHOW COLUMNS FROM `gm_polys` WHERE `field`='search'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sql = "ALTER TABLE  `gm_polys` ADD  `search` LONGTEXT NULL , ADD FULLTEXT (`search`)";
            $this->_conn->updateRow($sql);
        }
        $colcheck = "SHOW COLUMNS FROM `gm_markers` WHERE `field`='search'";
        $hasField = $this->_conn->getField($colcheck);
        if ($hasField == null) {
            $sqla[] = "ALTER TABLE  `gm_polys` CHANGE  `pageId`  `pageId` INT( 11 ) NULL DEFAULT NULL ,\nCHANGE  `label`  `label` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
            $sql = "ALTER TABLE  `gm_markers` ADD  `search` LONGTEXT NULL , ADD FULLTEXT (`search`)";
            $this->_conn->updateRow($sql);
            $maps = new Maps();
            $lay = new Layers();
            $layers = $lay->getLayers();
            $markers = $this->_conn->getRows("SELECT markerId, pageId FROM gm_markers");
            foreach ($markers as $marker) {
                if ($marker->pageId) {
                    $sql = "SELECT `value` FROM content WHERE pageId = {$marker->pageId}";
                    $rows = $this->_conn->getFields($sql);
                    $search = implode("\r\n", $rows);
                    $search = Connection::getInstance()->escape_string($search);
                    $sql = "UPDATE gm_markers SET `search`='{$search}' WHERE markerId={$marker->markerId}";
                    $this->_conn->updateRow($sql);
                }
            }
        }
        $colcheck = "SHOW COLUMNS FROM `page` WHERE `field`='creationdate'";
        if ($this->_conn->getField($colcheck) == null) {
            $sqla[] = "ALTER TABLE  `page` ADD  `creationdate` TIMESTAMP NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD  `createdby` INT( 11 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD  `modifiedby` INT( 11 ) NULL DEFAULT NULL";
        }
        $colcheck = "SHOW COLUMNS FROM `backup` WHERE `field`='content'";
        $c = $this->_conn->getRow($colcheck);
        if ($c->Type == 'text') {
            $sqla[] = "ALTER TABLE  `backup` CHANGE  `content`  `content` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL";
        }
        $tblcheck = "SHOW TABLES LIKE 'calendarindex'";
        if (!$this->_conn->getField($tblcheck)) {
            $this->_conn->insertRow("CREATE TABLE IF NOT EXISTS `calendarindex` (\n\t\t\t\t\t\t\t\t\t\t  `calendarId` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t  `search` text,\n\t\t\t\t\t\t\t\t\t\t  PRIMARY KEY (`calendarId`),\n\t\t\t\t\t\t\t\t\t\t  FULLTEXT KEY `search` (`search`)\n\t\t\t\t\t\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
            $cal = new Calendar();
            $ids = $this->_conn->getFields("SELECT calendarId FROM calendarnew");
            $sqlc = "INSERT INTO calendarindex (calendarId, search) VALUES";
            $sqlca = array();
            foreach ($ids as $id) {
                $ev = $cal->getEvent($id);
                $search = BrightUtils::createSearchString($ev);
                if ((int) $ev->locationId > 0) {
                    $search .= $this->_conn->getField("SELECT search FROM gm_markers WHERE pageId={$ev->locationId}");
                }
                $search = Connection::getInstance()->escape_string($search);
                $sqlca[] = "({$ev->calendarId}, '{$search}')";
            }
            if (count($sqlca) > 0) {
                $sqlc .= implode(",\r\n", $sqlca);
                $sqla[] = $sqlc;
            }
            $sqla[] = "ALTER TABLE  `calendareventsnew` ADD INDEX (  `starttime` )";
        }
        $tblcheck = "SHOW TABLES LIKE 'pageindex'";
        if (!$this->_conn->getField($tblcheck)) {
            $this->_conn->insertRow("CREATE TABLE IF NOT EXISTS `pageindex` (\n\t\t\t\t\t\t\t\t\t\t  `pageId` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t  `search` text,\n\t\t\t\t\t\t\t\t\t\t  PRIMARY KEY (`pageId`),\n\t\t\t\t\t\t\t\t\t\t  FULLTEXT KEY `search` (`search`)\n\t\t\t\t\t\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
            $el = new Element();
            $page = new Page();
            $ids = $el->getElements(false);
            $sqle = "INSERT INTO pageindex (pageId, search) VALUES";
            $sqlea = array();
            foreach ($ids as $elm) {
                $ev = $page->getPageById($elm->pageId);
                $search = BrightUtils::createSearchString($ev);
                $search = Connection::getInstance()->escape_string($search);
                $sqlea[] = "({$ev->pageId}, '{$search}')";
            }
            if (count($sqlea) > 0) {
                $sqle .= implode(",\r\n", $sqlea);
                $sqla[] = $sqle;
            }
        }
        if ($prevbuild < 7098) {
            // Update user settings, this fixes a bug with AmfPHP 2.x,
            // which does not correctly deserialize flex.messaging.io.objectproxy to php stdClass objects
            $rows = Connection::getInstance()->getRows("SELECT id, settings FROM `administrators`");
            foreach ($rows as $row) {
                $settings = json_decode($row->settings);
                if ($settings) {
                    if (isset($settings->_externalizedData)) {
                        $settings = $settings->_externalizedData;
                    }
                    // Clean up settings object
                    foreach ($settings as $key => $value) {
                        if (strpos($key, 'pageDivider_') === 0) {
                            unset($settings->{$key});
                        }
                    }
                    $settings = Connection::getInstance()->escape_string(json_encode($settings));
                    $sql = "UPDATE administrators SET settings='{$settings}' WHERE id={$row->id}";
                    Connection::getInstance()->updateRow($sql);
                }
            }
        }
        // Update to latest version
        $sqla[] = 'TRUNCATE `update`';
        $sqla[] = 'INSERT INTO `update` (`build`) VALUES (' . $build . ')';
        $this->_performQueries($sqla);
        $sql = "SHOW TABLES LIKE 'calendar'";
        $rows = $this->_conn->getRow($sql);
        if ($rows) {
            $sql = 'SELECT * FROM calendar';
            $rows = $this->_conn->getRows($sql);
            if ($rows) {
                $page = new Page();
                $cal = new Calendar();
                $ids = array();
                foreach ($rows as $row) {
                    $ids[] = $row->pageId;
                    $ev = $page->getPageById($row->pageId);
                    $cdo = new OCalendarDateObject();
                    $cdo->starttime = $ev->publicationdate;
                    $cdo->endtime = $ev->expirationdate;
                    $cdo->allday = date('d-m-Y', $cdo->starttime) != date('d-m-Y', $cdo->endtime) || $row->allday;
                    if (date('H', $cdo->starttime) == 22) {
                        $cdo->starttime += 7200;
                        $cdo->endtime += 7200;
                        $cdo->allday = 1;
                    }
                    if (date('H', $cdo->starttime) == 23) {
                        $cdo->starttime += 3600;
                        $cdo->endtime += 3600;
                        $cdo->allday = 1;
                    }
                    if (date('H', $cdo->endtime) == 22) {
                        $cdo->starttime += 7200;
                        $cdo->endtime += 7200;
                        $cdo->allday = 1;
                    }
                    if (date('H', $cdo->endtime) == 23) {
                        $cdo->starttime += 3600;
                        $cdo->endtime += 3600;
                        $cdo->allday = 1;
                    }
                    $cestring = serialize($ev);
                    $cestring = str_replace('O:5:"OPage"', 'O:14:"OCalendarEvent"', $cestring);
                    $cestring = str_replace('s:13:"_explicitType";s:5:"OPage"', 's:13:"_explicitType";s:14:"OCalendarEvent"', $cestring);
                    $ev = unserialize($cestring);
                    $ev->dates = array($cdo);
                    $cal->setEvent($ev);
                }
                $page->deletePages($ids);
                $sql = 'DELETE FROM calendar';
                $rows = $this->_conn->deleteRow($sql);
                $sql = 'DELETE FROM calendarevents';
                $rows = $this->_conn->deleteRow($sql);
            }
        }
        $this->updatePermissions($permissions);
    }
Exemplo n.º 8
0
 /**
  * Processes a value from a content row
  * @param string $value The value to process
  * @param string $definition The definition of the template
  * @param string $field The name of the value
  * @return mixed The processed value
  */
 private function _processValue($value, $definition, $field)
 {
     switch ($definition->{$field}->type) {
         case 'array':
             $raw = $value;
             $return = json_decode($value);
             if ($return == null && ($raw != null && $raw != '')) {
                 // Value is not a json string
                 $return = $raw;
             }
             $return = array($return);
             break;
         case 'json':
             try {
                 $return = json_decode($value);
             } catch (\Exception $ex) {
                 $return = $value;
             }
             break;
         case 'gmaps':
             try {
                 $return = json_decode($value);
                 $layers = array();
                 $markers = array();
                 $polys = array();
                 $gm_layers = new Layers();
                 $gm_maps = new Maps();
                 foreach ($return->layers as $layer) {
                     $l = $gm_layers->getLayer($layer->layerId);
                     if ($l) {
                         $l->visible = $layer->visible;
                         $layers[] = $l;
                         $m = $gm_maps->getMarkers($layer->layerId);
                         $p = $gm_maps->getPolys($layer->layerId);
                         $markers = array_merge($m, $markers);
                         $polys = array_merge($p, $polys);
                     }
                 }
                 $return->layers = $layers;
                 $return->markers = $markers;
                 $return->polys = $polys;
             } catch (\Exception $ex) {
                 $return = $value;
             }
             break;
         case 'elements':
             $ids = explode(',', $value);
             $elements = array();
             foreach ($ids as $id) {
                 $page = new Page();
                 $el = $page->getPageById($id);
                 if ($el) {
                     $elements[] = (object) $el;
                 }
             }
             $return = $elements;
             break;
         default:
             $return = $value;
     }
     return $return;
 }