Guest User

Untitled

a guest
May 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. <?php
  2.     class view extends Controller{
  3.  
  4.         public function index(Request $resquest){
  5.  
  6.             $this->data['feedback'] = SessionRegistry::instance()->getFeedback();
  7.            
  8.             //Check to see if the page id is present if not redirect to index
  9.             if(!isset($_GET['page_id'])){
  10.                 header('Location: index.php');
  11.             }
  12.            
  13.             //Load the News model to get the headlines
  14.             $news = $this->getModel('News');
  15.             $this->data['news'] = $news->getHeadlines();
  16.            
  17.  
  18.             //Load the page model
  19.             $page = $this->getModel('Page');
  20.             $p = $page->getPage($_GET['page_id']);
  21.        
  22.             if($p == null){
  23.                 $this->data['pageTitle'] = 'Page Not Found';
  24.                 $this->data['pageContent'] = 'Page Not Found';
  25.             }
  26.             else{
  27.                 $this->data['pageTitle'] = $p['page_title'];
  28.                 $this->data['relatedInfo'] = $p['page_sub_text'];
  29.                 $this->data['pageContent'] = $p['page_content'];
  30.                
  31.                 //Check to see if there are any blocks in the page content if so swap them out
  32.                 preg_match_all("[block:(\d+)]", $this->data['pageContent'], $blockMatches);
  33.                 //print_r($matches);   
  34.                 if(count($blockMatches) > 0){
  35.                     //Load the model
  36.                     $content = $this->data['pageContent'];
  37.                     $block = $this->getModel('Block');         
  38.                     foreach($blockMatches[1] as $m){
  39.                         $blockContent = trim($block->getBlockContent($m));  //Remove Whitespace off block as it breaks some layouts
  40.                         if(strlen($blockContent) < 1){
  41.                             $blockContent = "Block ID: $m Not Found";
  42.                         }
  43.                         $replaceString = "[block:$m]";
  44.                         $content =  str_replace($replaceString, $blockContent,$content);
  45.                     }
  46.                     $this->data['pageContent'] = $content;
  47.                 }
  48.                
  49.                 //Check to see if there are any gallery matches
  50.                 preg_match_all("[gallery:(\d+)]", $this->data['pageContent'], $galleryMatches);
  51.                
  52.                 if(count($galleryMatches) > 0){
  53.                     //Load the model
  54.                     $content = $this->data['pageContent'];
  55.                     $gallery = $this->getModel('Gallery');
  56.                     foreach($galleryMatches[1] as $m){
  57.                         $images = $gallery->getGalleryImages($m);
  58.                         $info = $gallery->getGalleryInfo($m);
  59.                         $galleryHTML = $gallery->getHTML($images,'table');
  60.                         $replaceString = "[gallery:$m]";
  61.                         $content =  str_replace($replaceString, $galleryHTML,$content);
  62.                     }  
  63.                     $this->data['pageContent'] = $content;
  64.                 }
  65.                
  66.        
  67.             }
  68.            
  69.  
  70.            
  71.  
  72.             //Load the menu model and get the menu
  73.             $menu = $this->getModel('Menu');
  74.             $this->data['menu'] = $menu->getMenu();
  75.  
  76.  
  77.             $breadcrumbs = array();
  78.             $breadcrumbs[] = array('Home','index.php');
  79.             $breadcrumbs[] = array($p['page_title'],'');
  80.             $this->data['breadcrumbs'] = $breadcrumbs;
  81.  
  82.             $this->templates[] = 'view/template/default/common/header.php';
  83.             $this->templates[] = 'view/template/default/page/view.php';
  84.             //Switch the footer
  85.             if($_GET['page_id'] == 1 || $_GET['page_id'] == 6){
  86.                 $this->templates[] = 'view/template/default/common/footer_complex.php';
  87.             }
  88.             else{
  89.                 $this->templates[] = 'view/template/default/common/footer_simplified.php';
  90.             }
  91.  
  92.             echo $this->render();
  93.  
  94.         }
  95.     }
  96. ?>
Add Comment
Please, Sign In to add comment