public function Save()
 {
     // Create view
     $pageView = $this->ctrlHelper->CreateView('PageView');
     // Load file dependencies
     $this->ctrlHelper->LoadDALModel('UserDAL');
     $this->ctrlHelper->LoadDALModel('LoginDAL');
     // Create objects
     $pages = $this->ctrlHelper->CreateDALModel('PageDAL');
     $auth = $this->ctrlHelper->CreateService('AuthService');
     if ($auth->IsUserLoggedIn()) {
         // Get page info from view
         $pageInfoArray = $pageView->GetPageInfo();
         // Get logged in user
         $user = $auth->GetLoggedInUser();
         // Create new page
         $page = new \model\Page($pageInfoArray['pageId'], $pageInfoArray['header'], $pageInfoArray['content'], $user->GetUsername());
         // Check if there was validation errors
         if (!\model\ValidationService::IsValid()) {
             \model\ValidationService::ConvertErrorsToFlashMessages();
             $pageId = $page->GetPageId();
         } else {
             // Generate slug
             $page->GenerateSlug();
             $pageId = $pages->Save($page);
             \model\FlashMessageService::Add("Sidan sparades med ett lyckat resultat.");
         }
         // Get controller name
         $ctrlName = $this->ctrlHelper->CtrlToString($this);
         // Redirect
         $this->ctrlHelper->RedirectTo($ctrlName . "/show/" . $pageId . '/' . $page->GetSlug());
     }
 }
Esempio n. 2
0
File: Text.php Progetto: Eupeodes/gh
 public function view($url)
 {
     strtok($url, '/');
     $file = strtok('/');
     if (array_key_exists($file, $this->files)) {
         switch ($this->files[$file]) {
             case 'md':
                 $parseDown = new \lib\external\parseDown\ParseDown();
                 $parseDown->setMarkupEscaped(true);
                 $text = $parseDown->text(file_get_contents(dirname(__FILE__) . '/../' . strtoupper($file) . '.md'));
                 preg_match('/^<h1?.*>(?P<title>.*)<\\/h1>\\n(?P<content>.*)$/ims', $text, $matches);
                 $title = $matches['title'];
                 $content = $matches['content'];
                 break;
             case 'tpl':
                 require_once dirname(__FILE__) . '/../template/' . strtolower($file) . '.tpl.php';
                 break;
         }
     } else {
         $output = \model\Page::get($file);
         $title = $output->title;
         $content = $output->content;
     }
     if (is_null($content)) {
         \lib\Error::send(404, 'Page not found');
     }
     header('Content-type: text/json');
     echo json_encode(['title' => $title, 'content' => $content]);
 }
Esempio n. 3
0
 public static function load($page)
 {
     if ($page = \Model\Page::instance()->load($page)) {
         return $page['content'];
     } else {
         return NULL;
     }
 }
 public function indexAction()
 {
     //	init
     $this->init();
     //  get pages
     $this->view->pageArray = \Model\Page::find();
     //	set main view
     $this->view->setMainView('block-module-pages/admin-index');
 }
Esempio n. 5
0
 public function action_page()
 {
     $model = MPage::app();
     $url = implode('/', $this->params);
     $page = $model->getByUrl($url);
     if ($page == null) {
         throw new Ex404();
         /*$this->action_p404();
           return;*/
     }
     $this->title = $page['title'];
     $this->base_template = $page['base_template'];
     $this->content = View::template('inner_templates/' . $page['inner_template'], ['page' => $page]);
 }
Esempio n. 6
0
 /**
  * @param $em \Doctrine\ORM\EntityManager
  * @param $data array
  * @param null $pageid int
  * @return int Id of processed page
  */
 protected function insertUpdateProcessing($em, $data, $pageid = null)
 {
     $update = !is_null($pageid);
     if ($update) {
         $page = $em->find('Model\\Page', $pageid);
     } else {
         $page = new Page();
     }
     if ($update) {
         $deleteurl = $em->createQueryBuilder()->delete()->from('Model\\Url', "url")->where("url.page=" . $page->getId())->getQuery();
         $deletepageblock = $em->createQueryBuilder()->delete()->from('Model\\PageBlock', "pb")->where("pb.page=" . $page->getId())->getQuery();
         $deleteurl->execute();
         $deletepageblock->execute();
     }
     $page->setName($data['name']);
     $page->setDescription($data['description']);
     $page->setTitle($data['title']);
     $page->setPublished(!is_null($data['published']));
     $page->setPublic(!is_null($data['public']));
     $language = $em->find('Model\\Language', $data['language']);
     $page->setLanguage($language);
     //Url insertion
     foreach ($data['url'] as $urlstring) {
         if (strlen($urlstring) > 2) {
             $url = new Url();
             $url->setUrl($urlstring);
             $page->addUrl($url);
         }
     }
     if (!$update) {
         $em->persist($page);
         $em->flush();
     }
     //Processing Blocks
     for ($i = 0; $i < count($data['block']['id']); $i++) {
         $blockid = $data['block']['id'][$i];
         //If block is new and content is empty, skip the block
         //Iterates over remaining blocks
         if (!($blockid == 0 && strlen($data['block']['content'][$i]) == 0)) {
             $isContentBlock = isset($data['block']['content'][$i]) && strlen($data['block']['content'][$i]) > 0;
             if ($blockid == 0) {
                 //Insert new block
                 $block = new \Model\ContentBlock();
             } else {
                 //Update existing block
                 if ($isContentBlock) {
                     $block = $em->find('Model\\ContentBlock', $blockid);
                 } else {
                     $block = $em->find('Model\\Block', $blockid);
                 }
             }
             if (is_null($block)) {
                 print "IS CONTENT BLOCK ->" . $isContentBlock . "\n";
                 print $data['block']['content'][$i];
                 print "BLOCK ID -> " . $blockid;
             }
             //Sets block properties
             $block->setName($data['block']['name'][$i]);
             $block->setDescription($data['block']['description'][$i]);
             $block->setBlockStyleClassName($data['block']['style'][$i]);
             $block->setBgurl($data['block']['bckurl'][$i]);
             $block->setBgred(intval($data['block']['bckred'][$i]));
             $block->setBggreen(intval($data['block']['bckgreen'][$i]));
             $block->setBgblue(intval($data['block']['bckblue'][$i]));
             $block->setBgopacity(floatval($data['block']['bckopacity'][$i]));
             $bgrepeatx = !(strlen($data['block']['bckrepeatx'][$i]) <= 0 || $data['block']['bckrepeatx'][$i] == 'false');
             $bgrepeaty = !(strlen($data['block']['bckrepeaty'][$i]) <= 0 || $data['block']['bckrepeaty'][$i] == 'false');
             $block->setBgrepeatx($bgrepeatx);
             $block->setBgrepeaty($bgrepeaty);
             $block->setBgsize($data['block']['bcksize'][$i]);
             // If is set content field, this block is a content block
             // If content is not set, I can work directly with block object
             if ($isContentBlock) {
                 $block->setContent($data['block']['content'][$i]);
             }
             if ($blockid == 0) {
                 $em->persist($block);
             } else {
                 $em->merge($block);
             }
             $em->flush();
             //Adding block to page
             $page->addBlock($block, $i);
         }
     }
     if ($update) {
         $em->merge($page);
     } else {
         $em->persist($page);
     }
     $em->flush();
     return $page->getId();
 }
Esempio n. 7
0
 public function __construct()
 {
     $this->model = \Model\Page::instance();
 }
Esempio n. 8
0
 public function __construct()
 {
     parent::__construct();
     $this->model = MPage::app();
     $this->check_access('edit_pages');
 }
Esempio n. 9
0
 public function testGetBlocks()
 {
     $this->assertTrue(count($this->pageinst->getPageBlocks()->toArray()) > 0);
 }