Exemple #1
0
		public function outputAutoHeaderItems() {
			$b = Block::getByID($this->bOriginalID);
			$bvt = new BlockViewTemplate($b);
			$headers = $bvt->getTemplateHeaderItems();
			if (count($headers) > 0) {
				foreach($headers as $h) {
					$this->addHeaderItem($h);
				}
			}
		}
 /** 
  * Gallery package is installed. Can we :
  * a. Override gallery/view.php in blocks/gallery.php, properly, as well as maintaining autoloaded items?
  * b. Override gallery/view.php in blocks/gallery/view.php. Add new autoload items to /blocks/gallery/ and ensure they are loaded
  * c. Setup a custom template in gallery/templates/custom_gallery_template.php, and maintain autoloaded items?
  * d. Setup a custom template directory at gallery/templates/custom_gallery_template/view.php, and load NEW autoloaded items?
  */
 public function testOverridePackageViewTemplate()
 {
     //assumes /gallery exists
     $p = Page::getByPath('/gallery');
     self::$_this = '';
     self::$_this->path = DIR_REL . '\\/packages\\/gallery/i';
     // a.
     touch(DIR_BASE . '/blocks/gallery.php');
     $blocks = $p->getBlocks('Main');
     $b = $blocks[0];
     $bv = new BlockViewTemplate($b);
     $this->assertEqual($bv->getTemplate(), DIR_BASE . '/blocks/gallery.php', 'Gallery Template Test - Block view override with gallery.php');
     phpQuery::browserGet(BASE_URL . DIR_REL . '/index.php/gallery', array('BlockOverrideTests', '_testGalleryHeaderItems'));
     $this->assertEqual(3, self::$_this->headerItem1Count + self::$_this->headerItem2Count, 'Gallery Header Test - Block view override with gallery.php');
     unlink(DIR_BASE . '/blocks/gallery.php');
     // b
     self::$_this = '';
     self::$_this->path = DIR_REL . '\\/blocks\\/gallery/i';
     mkdir(DIR_BASE . '/blocks/gallery');
     touch(DIR_BASE . '/blocks/gallery/view.php');
     touch(DIR_BASE . '/blocks/gallery/view.css');
     touch(DIR_BASE . '/blocks/gallery/view.js');
     $blocks = $p->getBlocks('Main');
     $b = $blocks[0];
     $bv = new BlockViewTemplate($b);
     $this->assertEqual($bv->getTemplate(), DIR_BASE . '/blocks/gallery/view.php', 'Gallery Template Test - Block view override with gallery/view.php');
     phpQuery::browserGet(BASE_URL . DIR_REL . '/index.php/gallery', array('BlockOverrideTests', '_testGalleryHeaderItems'));
     $this->assertEqual(2, self::$_this->headerItem1Count + self::$_this->headerItem2Count, 'Gallery Header Test - Block view override with gallery/view.php and local view.css, view.js');
     unlink(DIR_BASE . '/blocks/gallery/view.css');
     unlink(DIR_BASE . '/blocks/gallery/view.js');
     unlink(DIR_BASE . '/blocks/gallery/view.php');
     rmdir(DIR_BASE . '/blocks/gallery');
     // c
     self::$_this = '';
     self::$_this->path = DIR_REL . '\\/packages\\/gallery/i';
     mkdir(DIR_BASE . '/blocks/gallery');
     mkdir(DIR_BASE . '/blocks/gallery/templates');
     touch(DIR_BASE . '/blocks/gallery/templates/custom_gallery_template.php');
     $blocks = $p->getBlocks('Main');
     $b = $blocks[0];
     $b->setCustomTemplate('custom_gallery_template.php');
     $p = Page::getByPath('/gallery');
     $blocks = $p->getBlocks('Main');
     $b = $blocks[0];
     $bv = new BlockViewTemplate($b);
     $this->assertEqual($bv->getTemplate(), DIR_BASE . '/blocks/gallery/templates/custom_gallery_template.php', 'Gallery Template Test - Custom Template view override with gallery/templates/custom_gallery_template.php');
     phpQuery::browserGet(BASE_URL . DIR_REL . '/index.php/gallery', array('BlockOverrideTests', '_testGalleryHeaderItems'));
     $this->assertEqual(3, self::$_this->headerItem1Count + self::$_this->headerItem2Count, 'Gallery Header Test - Custom Template view override with gallery/templates/custom_gallery_template.php');
     unlink(DIR_BASE . '/blocks/gallery/templates/custom_gallery_template.php');
     rmdir(DIR_BASE . '/blocks/gallery/templates');
     rmdir(DIR_BASE . '/blocks/gallery');
     $b->setCustomTemplate(false);
 }
 public function outputAutoHeaderItems()
 {
     $b = $this->getBlockObject();
     $bvt = new BlockViewTemplate($b);
     $headers = $bvt->getTemplateHeaderItems();
     if (count($headers) > 0) {
         foreach ($headers as $h) {
             $this->addHeaderItem($h);
         }
     }
 }
 function testCustomTemplateInPackage()
 {
     self::$_this->headerItem1Count = 0;
     self::$_this->headerItem2Count = 0;
     $p = Page::getByID(1);
     $blocks = $p->getBlocks('Header Nav');
     $b = $blocks[0];
     $b->setCustomTemplate('test_template.php');
     $p = Page::getByID(1);
     $blocks = $p->getBlocks('Header Nav');
     $b = $blocks[0];
     touch(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php');
     $bvt = new BlockViewTemplate($b);
     $this->assertEqual($bvt->getTemplate(), DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php', 'Test K - File');
     unlink(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php');
     touch(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template.php');
     $bvt = new BlockViewTemplate($b);
     $this->assertEqual($bvt->getTemplate(), DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template.php', 'Test K - File in Templates');
     unlink(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template.php');
     $b->setCustomTemplate('test_template');
     $p = Page::getByID(1);
     $blocks = $p->getBlocks('Header Nav');
     $b = $blocks[0];
     mkdir(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template');
     touch(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template/view.php');
     $bvt = new BlockViewTemplate($b);
     $this->assertEqual($bvt->getTemplate(), DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template/view.php', 'Test K - File in Template Directory');
     unlink(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template/view.php');
     rmdir(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/templates/test_template');
     touch(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php');
     $b->setCustomTemplate('test_template.php');
     self::$_this->btHandle = 'autonav';
     touch(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/view.css');
     touch(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/view.js');
     phpQuery::browserGet(BASE_URL . DIR_REL . '/index.php', array('TemplateCoreWebTests', '_testHeaderItems'));
     $this->assertEqual(2, self::$_this->headerItem1Count + self::$_this->headerItem2Count, 'Test L - Loading Packaged Template with Core Header Items autoloaded');
     unlink(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php');
     unlink(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/view.css');
     unlink(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/view.js');
     $b->setCustomTemplate(false);
     self::$_this->btHandle = '';
     $b->setCustomTemplate('test_template.php');
     self::$_this->headerItem1Count = 0;
     self::$_this->headerItem2Count = 0;
     touch(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php');
     mkdir(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/css');
     mkdir(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/js');
     touch(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/css/test1.css');
     touch(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/css/test2.css');
     touch(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/js/test2.js');
     touch(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/js/test9.js');
     self::$_this->btHandle = 'autonav';
     phpQuery::browserGet(BASE_URL . DIR_REL . '/index.php', array('TemplateCoreWebTests', '_testHeaderItemDirectories'));
     $this->assertEqual(4, self::$_this->headerItem1Count + self::$_this->headerItem2Count, 'Test L - Loading Packaged Template with Core Header Items autoloaded from directories');
     unlink(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/css/test1.css');
     unlink(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/css/test2.css');
     unlink(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/js/test2.js');
     unlink(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/js/test9.js');
     rmdir(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/css');
     rmdir(DIR_FILES_BLOCK_TYPES_CORE . '/autonav/js');
     unlink(DIR_PACKAGES . '/autonav_test_template/blocks/autonav/test_template.php');
     self::$_this->btHandle = '';
 }
Exemple #5
0
		/** 
		 * Renders a particular view for a block or a block type
		 * @param Block | BlockType $obj
		 * @param string $view
		 * @param array $args
		 */
		public function render($obj, $view = 'view', $args = array()) {
			if ($this->hasRendered) {
				return false;
			}
			$this->blockObj = $obj;
			$customAreaTemplates = array();
			
			if ($obj instanceof BlockType) {
				$bt = $obj;
				$base = $obj->getBlockTypePath();
			} else {
				$bFilename = $obj->getBlockFilename();
				$b = $obj;
				$base = $b->getBlockPath();
				$this->block = $b;
				$this->c = $b->getBlockCollectionObject();
				if ($bFilename == '' && is_object($this->area)) {
					$customAreaTemplates = $this->area->getCustomTemplates();
					$btHandle = $b->getBlockTypeHandle();
					if (isset($customAreaTemplates[$btHandle])) {
						$bFilename = $customAreaTemplates[$btHandle];
					}
				}

			}				
			
			$btHandle = $obj->getBlockTypeHandle();
			
			if (!isset($this->controller)) {
				$this->controller = Loader::controller($obj);
			}
			if (in_array($view, array('view', 'add', 'edit'))) {
				$_action = $view;
			} else {
				$_action = 'view';
			}
			
			$u = new User();
			
			$outputContent = false;
			$useCache = false;
			$page = Page::getCurrentPage();
			
			if ($view == 'view') {
				if ($this->controller->cacheBlockOutput() && ($obj instanceof Block)) {
					if ((!$u->isRegistered() || ($this->controller->cacheBlockOutputForRegisteredUsers())) &&
						(($_SERVER['REQUEST_METHOD'] != 'POST' || ($this->controller->cacheBlockOutputOnPost() == true)))) {
							$useCache = true;
					}
					if ($useCache) {
						$cID = 0;
						if (is_object($page)) {
							$cID = $page->getCollectionID();
						}
						$outputContent = Cache::get('block_view_output', $cID . ':' . $obj->getBlockID() . ':' . $obj->getAreaHandle());
					}
				}
			}
			if ($outputContent == false) {
				$this->controller->setupAndRun($_action);
			}
			extract($this->controller->getSets());
			extract($this->controller->getHelperObjects());
			$headerItems = $this->controller->headerItems;
			extract($args);
			
			if ($this->controller->getRenderOverride() != '') { 
				$_filename = $this->controller->getRenderOverride() . '.php';
			} 
			
			if ($view == 'scrapbook') {
				$template = $this->getBlockPath(FILENAME_BLOCK_VIEW_SCRAPBOOK) . '/' . FILENAME_BLOCK_VIEW_SCRAPBOOK;
				if (!file_exists($template)) {
					$view = 'view';
				}
			}
			
			if (!in_array($view, array('composer','view', 'add', 'edit', 'scrapbook'))) {
				// then we're trying to render a custom view file, which we'll pass to the bottom functions as $_filename
				$_filename = $view . '.php';
				$view = 'view';
			}
			
			switch($view) {
				case 'scrapbook':
					$header = DIR_FILES_ELEMENTS_CORE . '/block_header_view.php';
					$footer = DIR_FILES_ELEMENTS_CORE . '/block_footer_view.php';										
					break;
				case 'composer':
				case 'view':				
					if (!$outputContent) {
						if (!isset($_filename)) {
							$_filename = FILENAME_BLOCK_VIEW;
						}					
						$bvt = new BlockViewTemplate($obj);
						if ($bFilename) {
							$bvt->setBlockCustomTemplate($bFilename); // this is PROBABLY already set by the method above, but in the case that it's passed by area we have to set it here
						} else if ($_filename != FILENAME_BLOCK_VIEW) {
							$bvt->setBlockCustomRender($_filename); 
						}
						$template = $bvt->getTemplate();
					}
					
					if ($view == 'composer') {
						$displayEditLink = true;
						$header = DIR_FILES_ELEMENTS_CORE . '/block_header_composer.php';
						$footer = DIR_FILES_ELEMENTS_CORE . '/block_footer_composer.php';
						$cpFilename = $obj->getBlockComposerFilename();
						if ($cpFilename) {
							$cmpbase = $this->getBlockPath(DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $cpFilename);
							if (file_exists($cmpbase . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $cpFilename)) {
								$template = $base . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $cpFilename;
								$displayEditLink = false;
							}
						}
						
						if ($displayEditLink) {
							$cmpbase = $this->getBlockPath(FILENAME_BLOCK_COMPOSER);
							if (file_exists($cmpbase . '/' . FILENAME_BLOCK_COMPOSER)) {
								$template = $base . '/' . FILENAME_BLOCK_COMPOSER;
								$displayEditLink = false;
							}
						}
						
					} else {
						$header = DIR_FILES_ELEMENTS_CORE . '/block_header_view.php';
						$footer = DIR_FILES_ELEMENTS_CORE . '/block_footer_view.php';										
					}
					break;
				case 'add':
					if (!isset($_filename)) {
						$_filename = FILENAME_BLOCK_ADD;
					}
					$header = DIR_FILES_ELEMENTS_CORE . '/block_header_add.php';
					$footer = DIR_FILES_ELEMENTS_CORE . '/block_footer_add.php';
					break;
				case 'edit':
					if (!isset($_filename)) {
						$_filename = FILENAME_BLOCK_EDIT;
					}
					$header = DIR_FILES_ELEMENTS_CORE . '/block_header_edit.php';
					$footer = DIR_FILES_ELEMENTS_CORE . '/block_footer_edit.php';
					break;
			} 		
			
			if (!isset($template)) {
				$base = $this->getBlockPath($_filename);
				$template = $base . '/' . $_filename;
			}
						
			if (isset($header)) {
				include($header);
			}
			if ($outputContent) {
				print $outputContent;			
			} else if ($template) {
				
				ob_start();
				include($template);
				$outputContent = ob_get_contents();
				ob_end_clean();					
				print $outputContent;
				
				if ($useCache) {
					$cID = 0;
					if (is_object($page)) {
						$cID = $page->getCollectionID();
					}				
					Cache::set('block_view_output', $cID . ':' . $obj->getBlockID() . ':' . $obj->getAreaHandle(), $outputContent, $this->controller->getBlockTypeCacheOutputLifetime());
				}
			}
			if (isset($footer)) {
				include($footer);
			}

			$this->template = $template;
			$this->header = $header;
			$this->footer = $footer;
			
			
		}