예제 #1
0
 public function __set($name, $value)
 {
     switch ($name) {
         case 'maintemplate':
         case 'viewtemplate':
             if (!BrightUtils::endsWith($value, '.tpl')) {
                 $value .= '.tpl';
             }
             break;
     }
     $this->_data[$name] = $value;
 }
예제 #2
0
 public static function createSearchString($obj)
 {
     $str = '';
     if ($obj) {
         foreach ($obj as $value) {
             if (is_scalar($value)) {
                 $str .= strip_tags($value) . " ";
             } else {
                 $str .= BrightUtils::createSearchString($value);
             }
         }
     }
     return $str;
 }
예제 #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
파일: Page.php 프로젝트: rsids/bright_api
 /**
  * Updates a page
  * @param OPage page The page to update
  * @return OPage The updated page
  */
 private function _updatePage($page)
 {
     $ap = $page->alwayspublished ? 1 : 0;
     $sn = $page->showinnavigation ? 1 : 0;
     $cachebleChanged = $this->_cachebleChanged($page);
     $page->label = Connection::getInstance()->escape_string($this->generateLabel($page->label, $page->pageId));
     $page->modifiedby = isset($_SESSION['administratorId']) ? $_SESSION['administratorId'] : 0;
     BrightUtils::forceInt($page, array('publicationdate', 'expirationdate', 'itemType', 'pageId'));
     $sql = "UPDATE page \n\t\t\t\tSET label='{$page->label}',\n\t\t\t\titemType='{$page->itemType}', \n\t\t\t\tpublicationdate=FROM_UNIXTIME({$page->publicationdate}),\n\t\t\t\texpirationdate=FROM_UNIXTIME({$page->expirationdate}), \n\t\t\t\talwayspublished={$ap},\n\t\t\t\tshowinnavigation={$sn},\n\t\t\t\tmodificationdate=NOW(),\n\t\t\t\tmodifiedby={$page->modifiedby}\n\t\t\t\tWHERE pageId={$page->pageId}";
     $this->conn->updateRow($sql);
     $this->setContent($page);
     if ($cachebleChanged) {
         // Flush cache
         $cache = new Cache();
         $cache->flushCache();
         $tree = new Tree();
         $tree->generateSitemap();
     }
     return $this->getPageById($page->pageId, true);
 }
예제 #5
0
 /**
  * Gets the event
  * @param string $sql The SQL query to get the event with
  * @return null|\OPage
  */
 private function _getEvent($sql)
 {
     $rows = $this->_conn->getRows($sql, 'OCalendarEvent');
     if (!$rows) {
         return null;
     }
     $event = $rows[0];
     $event = $this->getContent($event, false, 'calendarcontent');
     $event->dates = array();
     $event->publicationdate = (double) $rows[0]->starttime;
     $event->expirationdate = (double) $rows[0]->endtime;
     foreach ($rows as $row) {
         if (!array_key_exists($row->dateId, $event->dates)) {
             $ocd = new OCalendarDateObject();
             $ocd->starttime = (double) $row->starttime;
             $ocd->endtime = (double) $row->endtime;
             $ocd->allday = $row->allday == 1;
             $ocd->noend = $row->noend == 1;
             $ocd->calendarId = $row->calendarId;
             $event->dates[$row->dateId] = $ocd;
         }
         $ocd = new OCalendarDateObject();
         $ocd->starttime = (double) $row->rawstarttime;
         $ocd->endtime = (double) $row->rawendtime;
         $ocd->calendarId = $row->calendarId;
         $ocd->allday = $row->rawallday == 1;
         $ocd->noend = $row->rawnoend == 1;
         $ocd->eventId = $row->eventId;
         $event->rawdates[$row->eventId] = $ocd;
     }
     unset($event->deleted);
     unset($event->starttime);
     unset($event->endtime);
     unset($event->rawstarttime);
     unset($event->rawendtime);
     unset($event->dateId);
     unset($event->eventId);
     unset($event->allday);
     unset($event->rawallday);
     unset($event->noend);
     unset($event->rawnoend);
     $event->rawdates = BrightUtils::cleanArray($event->rawdates);
     $event->dates = BrightUtils::cleanArray($event->dates);
     return $event;
 }
예제 #6
0
파일: Files.php 프로젝트: rsids/bright_api
 /**
  * Downloads a file from the given url and stores it on the server
  * @param string $url The url of the file
  * @param string $filename The filename on the local server
  * @param string $parent The parent folder
  * @return object
  * @throws \Exception
  */
 public function uploadFromUrl($url, $filename, $parent)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     if ($filename === '') {
         $ua = explode('/', $url);
         $filename = array_pop($ua);
     }
     $url = str_replace(' ', '%20', $url);
     $url = filter_var($url, FILTER_VALIDATE_URL);
     $filename = filter_var($filename, FILTER_SANITIZE_STRING);
     $filename = preg_replace('/[\\s&\\|\\+\\!\\(\\)]/', '-', $filename);
     $filename = str_replace('%20', '-', $filename);
     while (strpos($filename, '--')) {
         $filename = str_replace('--', '-', $filename);
     }
     $parent = filter_var($parent, FILTER_SANITIZE_STRING);
     if ($url === false || $filename === false || $parent === false) {
         throw $this->throwException(ParameterException::STRING_EXCEPTION, __LINE__);
     }
     if (strpos($filename, '/') !== false || strpos($filename, '\\') !== false) {
         throw $this->throwException(ParameterException::STRING_EXCEPTION, __LINE__);
     }
     if (strpos($parent, '.') !== false) {
         throw $this->throwException(ParameterException::STRING_EXCEPTION, __LINE__);
     }
     if (!is_dir(BASEPATH . UPLOADFOLDER . $parent)) {
         throw $this->throwException(FilesException::FOLDER_NOT_FOUND);
     }
     $local = BASEPATH . UPLOADFOLDER . $parent . '/' . $filename;
     $i = 1;
     $fileParts = explode('.', $filename);
     $ext = array_pop($fileParts);
     if (count($fileParts) > 0) {
         $file = implode('.', $fileParts);
     } else {
         $file = $ext;
     }
     if (BrightUtils::endsWith($file, '-')) {
         $file = substr($file, 0, -1);
     }
     while (file_exists($local)) {
         $local = BASEPATH . UPLOADFOLDER . "{$parent}/{$file}-{$i}.{$ext}";
         $i++;
     }
     try {
         $ext = @file_get_contents($url);
     } catch (\Exception $e) {
         throw $this->throwException(FilesException::UPLOAD_FAILED);
     }
     if ($ext === false) {
         throw $this->throwException(FilesException::UPLOAD_FAILED);
     }
     $res = file_put_contents($local, $ext);
     if ($res === false) {
         throw $this->throwException(FilesException::UPLOAD_FAILED);
     }
     if (strpos($filename, '.') === false) {
         // No extension supplied, add it.
         $imgType = exif_imagetype($local);
         if ($imgType !== false) {
             $add = '';
             switch ($imgType) {
                 case IMAGETYPE_GIF:
                     $add = '.gif';
                     break;
                 case IMAGETYPE_JPEG:
                     $add = '.jpg';
                     break;
                 case IMAGETYPE_PNG:
                     $add = '.png';
                     break;
                 case IMAGETYPE_SWF:
                     $add = '.swf';
                     break;
                 case IMAGETYPE_PSD:
                     $add = '.psd';
                     break;
                 case IMAGETYPE_BMP:
                     $add = '.bmp';
                     break;
                 case IMAGETYPE_TIFF_II:
                     $add = '.tiff';
                     break;
                 case IMAGETYPE_TIFF_MM:
                     $add = '.tiff';
                     break;
             }
             if ($add != '') {
                 // Found correct extension
                 rename($local, $local . $add);
                 $filename .= $add;
             }
         }
     }
     return (object) array('files' => $this->getFiles($parent), 'file' => $filename);
 }
예제 #7
0
 /**
  * Does the actual sending. DO NOT CALL THIS METHOD FROM YOUR SCRIPTS
  * @private
  */
 public function realSend()
 {
     BrightUtils::inBrowser();
     $sql = 'SELECT id, pageId, `groups` FROM `mailqueue` WHERE issend=0';
     $mailings = $this->_conn->getRows($sql);
     $user = new User();
     foreach ($mailings as $mailing) {
         $sql = 'UPDATE `mailqueue` SET issend=1 WHERE id=' . (int) $mailing->id;
         $this->_conn->updateRow($sql);
         $groups = explode(',', $mailing->groups);
         $emails = $user->getUsersInGroups($groups, false, true);
         $this->_send($mailing->pageId, $emails);
         $sql = 'UPDATE `mailqueue` SET issend=2 WHERE id=' . (int) $mailing->id;
         $this->_conn->updateRow($sql);
     }
 }
예제 #8
0
 /**
  * Saves a element
  * @param OPage $element The element to save
  * @param bool $returnall
  * @return \stdClass An object containing element, the just saved element and elements, an array of all elements
  * @throws \Exception
  */
 public function setElement($element, $returnall = true)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     if (method_exists($this->_hook, 'preSetElement')) {
         $element = $this->_hook->preSetElement($element);
     }
     $element = $this->_page->setPage($element, false, false);
     if (method_exists($this->_hook, 'postSetElement')) {
         $this->_hook->postSetElement($element);
     }
     $c = new Cache();
     $c->deleteCacheByPrefix("element_filter_");
     $search = BrightUtils::createSearchString($element);
     $search = Connection::getInstance()->escape_string($search);
     $sql = "INSERT INTO pageindex (pageId, search) VALUES ({$element->pageId}, '{$search}') ON DUPLICATE KEY UPDATE search='{$search}' ";
     Connection::getInstance()->insertRow($sql);
     if (!$returnall) {
         return $element;
     }
     return $this->_page->getPages(4, null, true);
 }
예제 #9
0
파일: Update.php 프로젝트: rsids/bright_api
    /**
     * 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);
    }
예제 #10
0
 /**
  * Inserts content into the database
  * @param OPage $page
  * @param string $table
  * @return int
  * @throws ParameterException
  */
 protected function setContent($page, $table = 'content')
 {
     $pid = 'pageId';
     switch ($table) {
         case 'content':
             $pid = 'pageId';
             break;
         case 'userfields':
             $pid = 'userId';
             break;
         case 'calendarcontent':
             $pid = 'calendarId';
             break;
     }
     $id = (int) $page->{$pid};
     $table = Connection::getInstance()->escape_string($table);
     $b = new Backup();
     $b->setBackup($page, $table);
     if (!isset($page->content) || $page->content == null) {
         throw new ParameterException(ParameterException::OBJECT_EXCEPTION);
     }
     $sql = "UPDATE `{$table}` SET `deleted`=1 WHERE `{$pid}`={$id}";
     $this->conn->updateRow($sql);
     $it = new Template();
     $def = $it->getTemplateDefinition($page->itemType, true);
     $def->title = new \stdClass();
     $def->title->contenttype = 'string';
     $def->title->searchable = 1;
     $sql = "INSERT INTO `{$table}` (`{$pid}`, `lang`, `field`, `value`,`index`,`searchable`) VALUES ";
     $sqla = array();
     foreach ($page->content as $field => $langs) {
         $searchable = 0;
         if ($field == 'title') {
             $searchable = 1;
             if ($table == 'content' && $this->_titleChanged($langs, $page->{$pid})) {
                 $cache = new Cache();
                 $cache->flushCache();
             }
         } else {
             $searchable = isset($def->{$field}) && $def->{$field}->searchable ? 1 : 0;
         }
         foreach ($langs as $lang => $val) {
             // 20130725 Fix for unknown fields
             $contenttype = isset($def->{$field}) && isset($def->{$field}->contenttype) ? $def->{$field}->contenttype : 'string';
             switch ($contenttype) {
                 case 'array':
                     $index = 0;
                     if (!is_array($val)) {
                         $val = array($val);
                     }
                     foreach ($val as $listval) {
                         $lang = BrightUtils::escapeSingle($lang);
                         $field = BrightUtils::escapeSingle($field);
                         if (!is_string($listval)) {
                             //throw $this -> throwException(Exceptions::INCORRECT_PARAM_STRING, '$listval: ' . print_r($listval, true));
                             $listval = json_encode($listval);
                         }
                         $listval = BrightUtils::escapeHtml($listval);
                         $sqlid = $page->{$pid};
                         $sqla[] = "({$sqlid},\n\t\t\t\t\t\t\t\t\t\t'{$lang}',\n\t\t\t\t\t\t\t\t\t\t'{$field}',\n\t\t\t\t\t\t\t\t\t\t'{$listval}', {$index}, {$searchable}) ";
                         $index++;
                     }
                     break;
                 default:
                     $lang = BrightUtils::escapeSingle($lang);
                     $field = BrightUtils::escapeSingle($field);
                     if ($val !== null && $val !== false && !is_scalar($val)) {
                         $val = json_encode($val);
                         if ($val == '{}') {
                             $val = '';
                         }
                         //throw $this -> throwException(Exceptions::INCORRECT_PARAM_STRING, 'val: ' . print_r($val, true));
                     }
                     $val = BrightUtils::escapeHtml($val);
                     if ($val != '') {
                         $sqlid = $page->{$pid};
                         $sqla[] = "({$sqlid},\n\t\t\t\t\t\t\t\t\t\t'{$lang}',\n\t\t\t\t\t\t\t\t\t\t'{$field}',\n\t\t\t\t\t\t\t\t\t\t'{$val}', 0, {$searchable}) ";
                     }
             }
         }
     }
     if (count($sqla) > 0) {
         $sql .= implode(", \r\n", $sqla);
         $sql .= " ON DUPLICATE KEY UPDATE `value`=VALUES(`value`), `deleted`=0";
         $result = $this->conn->insertRow($sql);
     } else {
         // Delete old content? uncomment line
         // $result = 1;
     }
     if ($result !== false && $result > 0) {
         // All is well, clean up old data
         $sql = "DELETE FROM `{$table}` WHERE `deleted`= 1 AND  `{$pid}`={$id}";
         $this->conn->deleteRow($sql);
     }
     return $result;
 }