Exemple #1
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;
 }
Exemple #2
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;
 }