/** * Form Handler to save a content quick create. * * @param Form $form * * @return string|bool */ public static function QuickDraftSave(Form $form) { if (!$form->getElementValue('title')) { \Core\set_message('All pages must have titles.', 'error'); return false; } /** @var $model ContentModel */ $model = new ContentModel(); /** @var $page PageModel Page object for this model, already linked up! */ $page = $model->getLink('Page'); // The content nickname is derived from the page title. $model->set('nickname', $form->getElementValue('title')); $model->save(); $ins = new InsertableModel(); $ins->set('site', $page->get('site')); $ins->set('baseurl', '/content/view/' . $model->get('id')); $ins->set('name', 'body'); $ins->set('value', '<p>' . nl2br($form->getElementValue('content')) . '</p>'); $ins->save(); $page->set('title', $form->getElementValue('title')); $page->set('published_status', 'draft'); $page->set('editurl', '/content/edit/' . $model->get('id')); $page->set('deleteurl', '/content/delete/' . $model->get('id')); $page->set('component', 'content'); $page->save(); return true; }
public function update() { $content = new ContentModel(); $id = $_POST['id']; if ($id != '') { $data['id'] = $id; $data['title'] = $_POST['title']; $data['content'] = $_POST['content']; if ($content->save($data)) { $this->assign("jumpUrl", "__URL__/index"); $this->success("更新数据成功!"); } else { $this->assign("jumpUrl", "__URL__/index"); $this->success("更新数据失败!"); } } else { echo "保存数据失败!"; } }
protected function createContentElements(&$objItem) { if ($objItem->tl_content) { // need to wrap <p> around text for contao $tidyConfig = array('enclose-text' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'quote-ampersand' => true, 'clean' => false, 'wrap-attributes' => false, 'wrap' => 500); $bodyText = '<!DOCTYPE html><head><title></title></head><body>' . $objItem->tl_content . '</body></html>'; // $bodyText = $this->convert_external_link_tags($bodyText); // $bodyText = $this->convert_internal_link_tags($bodyText); $bodyText = $this->nl2p($bodyText); $tidy = new \tidy(); $tidy->parseString($bodyText, $tidyConfig, $GLOBALS['TL_CONFIG']['dbCharset']); $body = $tidy->body(); $objContent = new \ContentModel(); $objContent->text = urldecode($objContent->text); // decode, otherwise link and email regex wont work $objContent->text = trim(str_replace(array('<body>', '</body>'), '', $body)); $objContent->text = preg_replace("/<img[^>]+\\>/i", "", $objContent->text); // strip images // remove inline styles $objContent->text = preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $objContent->text); // remove white space from empty tags $objContent->text = preg_replace('#(<[a-z]*)(\\s+)>#', '$1>', $objContent->text); // create links from text $objContent->text = preg_replace('!(\\s|^)((https?://|www\\.)+[a-z0-9_./?=&-]+)!i', ' <a href="http://$2" target="_blank">$2</a>', $objContent->text); // replace <b> by <strong> $objContent->text = preg_replace('!<b(.*?)>(.*?)</b>!i', '<strong>$2</strong>', $objContent->text); // replace plain email text with inserttags $objContent->text = preg_replace('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?(?![^<]*>)(?![^>]*<)/i', "{{email::\$1@\$2.\$3}}", $objContent->text); // replace email links with inserttags $objContent->text = preg_replace('/<a.*href=[\'|"]mailto:([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?[\'|"].*>(.*)<\\/a>/i', "{{email::\$1@\$2.\$3}}", $objContent->text); // strip not allowed tags $objContent->text = strip_tags($objContent->text, \Config::get('allowedTags')); $objContent->text = $this->stripAttributes($objContent->text, array('style', 'class', 'id')); $objContent->ptable = $this->dbTargetTable; $objContent->pid = $objItem->id; $objContent->sorting = 16; $objContent->tstamp = time(); $objContent->type = 'text'; $objContent->save(); } }
/** * Create a new wrapper element. * * @param \Model $parent The parent element. * @param int $sorting The sorting index. * @param string $type The wrapper type. * * @return \ContentModel */ protected function createElement($parent, &$sorting, $type = Helper::TYPE_SEPARATOR) { $model = new \ContentModel(); if ($type == Helper::TYPE_START) { $sorting = $sorting - 2; } else { $sorting = $sorting + 2; $model->bootstrap_parentId = $parent->id; } $model->tstamp = time(); $model->pid = $parent->pid; $model->ptable = $parent->ptable; $model->type = $this->wrapper->getTypeName($type); $model->sorting = $sorting; $model->save(); return $model; }
protected function createContentElements(&$objItem) { if ($objItem->tl_content) { // need to wrap <p> around text for contao $tidyConfig = array('enclose-text' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'quote-ampersand' => true, 'clean' => false); $bodyText = '<!DOCTYPE html><head><title></title></head><body>' . $objItem->tl_content . '</body></html>'; // $bodyText = $this->convert_external_link_tags($bodyText); // $bodyText = $this->convert_internal_link_tags($bodyText); $bodyText = $this->nl2p($bodyText); $tidy = new \tidy(); $tidy->parseString($bodyText, $tidyConfig, $GLOBALS['TL_CONFIG']['dbCharset']); $body = $tidy->body(); $objContent = new \ContentModel(); $objContent->text = trim(str_replace(array('<body>', '</body>'), '', $body)); $objContent->text = preg_replace("/<img[^>]+\\>/i", "", $objContent->text); // strip images // create links from text $objContent->text = preg_replace('!(\\s|^)((https?://|www\\.)+[a-z0-9_./?=&-]+)!i', ' <a href="http://$2" target="_blank">$2</a>', $objContent->text); // replace <b> by <strong> $objContent->text = preg_replace('!<b(.*?)>(.*?)</b>!i', '<strong>$2</strong>', $objContent->text); // replace emails with inserttags $objContent->text = preg_replace('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?/i', "{{email::\$1@\$2.\$3}}", $objContent->text); // strip not allowed tags $objContent->text = strip_tags($objContent->text, \Config::get('allowedTags')); $objContent->text = $this->stripAttributes($objContent->text, array('style', 'class', 'id')); $objContent->ptable = static::$strTable; $objContent->pid = $objItem->id; $objContent->sorting = 16; $objContent->tstamp = time(); $objContent->type = 'text'; $objContent->save(); } }
//} $fac = new ModelFactory('BlogArticleModel'); foreach ($fac->get() as $model) { /** @var BlogArticleModel $model */ /** @var PageModel $page */ $page = $model->getLink('Page'); $page->setMeta('description', $model->getTeaser()); $page->setMeta('image', $model->get('image')); $page->set('published_status', $model->get('status')); $page->set('published', $model->get('published')); // Clone this to a content page. $content = new ContentModel(); $content->set('nickname', $model->get('title')); $content->set('created', $model->get('created')); $content->set('updated', $model->get('updated')); $content->save(); $page->set('component', 'content'); $page->set('baseurl', '/content/view/' . $content->get('id')); $page->set('editurl', '/content/edit/' . $content->get('id')); $page->set('deleteurl', '/content/delete/' . $content->get('id')); $page->set('page_template', 'blog-article.tpl'); $page->save(); $insertable = new InsertableModel(); $insertable->set('site', $page->get('site')); $insertable->set('baseurl', '/content/view/' . $content->get('id')); $insertable->set('name', 'body'); $insertable->set('value', $model->get('body')); $insertable->save(); $model->resetLink('Page'); $model->delete(); }