/** * Fix link in the canonical metatag * It works only with * - item * - category */ public function canonicalFix() { if (!$this->_jbrequest->is('option', 'com_zoo')) { return null; } $this->_jbdebug->mark('jbzoo-sef::canonicalFix::start'); $flags = array($this->_jbrequest->getWord('task'), $this->_jbrequest->getWord('view'), $this->_jbrequest->getWord('layout')); $newCanUrl = null; if (in_array('item', $flags)) { $itemId = $this->_jbrequest->getSystem('item'); $newCanUrl = $this->_getUrl($this->_itemTable->get($itemId), 'item'); } else { if (in_array('category', $flags)) { $categoryId = $this->_jbrequest->getSystem('category'); $newCanUrl = $this->_getUrl($this->_catTable->get($categoryId), 'category'); } } if ($newCanUrl) { // remove all canocical link $headData = $this->_joomlaDoc->getHeadData(); $canKey = array_search(array('relation' => 'canonical', 'relType' => 'rel', 'attribs' => array()), $headData['links']); unset($headData['links'][$canKey]); $this->_joomlaDoc->setHeadData($headData); // set new url $baseUrl = $this->_jbrouter->getHostUrl(); $this->_joomlaDoc->addHeadLink($baseUrl . $newCanUrl, 'canonical'); } $this->_jbdebug->mark('jbzoo-sef::canonicalFix::finish'); }
/** * Test getHeadData * * @return void */ public function testSetAndGetHeadData() { // Get default values $default = $this->object->getHeadData(); // Test invalid data $return = $this->object->setHeadData('invalid'); $this->assertThat($this->object->getHeadData(), $this->equalTo($default), 'JDocumentHtml::setHeadData invalid data allowed to be set'); // Test return value $this->assertThat($return, $this->isNull(), 'JDocumentHtml::setHeadData did not return null'); // Test setting/ getting values $test_data = array('title' => 'My Custom Title', 'description' => 'My Description', 'link' => 'http://joomla.org', 'metaTags' => array('myMetaTag' => 'myMetaContent'), 'links' => array('index.php' => array('relation' => 'Start', 'relType' => 'rel', 'attribs' => array())), 'styleSheets' => array('test.css' => array('mime' => 'text/css', 'media' => null, 'attribs' => array())), 'style' => array('text/css' => 'body { background: white; }'), 'scripts' => array('test.js' => array('mime' => 'text/javascript', 'defer' => false, 'async' => false)), 'script' => array('text/javascript' => "window.addEvent('load', function() { new JCaption('img.caption'); });"), 'custom' => array("<script>var html5 = true;</script>")); foreach ($test_data as $dataKey => $dataValue) { // Set $return = $this->object->setHeadData(array($dataKey => $dataValue)); // Get $compareTo = $this->object->getHeadData(); // Assert $this->assertThat($compareTo[$dataKey], $this->equalTo($dataValue), 'JDocumentHtml::setHeadData did not return ' . $dataKey . ' properly or setHeadData with ' . $dataKey . ' did not work'); // Test return value $this->assertThat($return, $this->equalTo($this->object), 'JDocumentHtml::setHeadData did not return JDocumentHtml instance'); } // Could use native methods (JDocument::addStyleSheet, etc) like $this->mergeHeadData }
/** * Set head data * Hack for empty scripts or styles arrays * @param string $type * @param array $data */ protected function setHeadData($type, $data) { if (!empty($data[$type])) { $this->doc->setHeadData($data); } else { if ($type == 'scripts') { $this->doc->_scripts = array(); } else { if ($type == 'styleSheets') { $this->doc->_styleSheets = array(); } } } }
/** * Cleanup system links from Joomla, Zoo, JBZoo */ protected function _excludeAssets(array $allPatterns) { $data = $this->doc->getHeadData(); foreach ($allPatterns as $type => $patterns) { foreach ($data[$type] as $path => $meta) { $found = false; foreach ($patterns as $pattern) { if (preg_match('#' . $pattern . '#iu', $path)) { $found = true; break; } } if ($found) { unset($data[$type][$path]); } } } $this->doc->setHeadData($data); }
/** * @testdox Test that setHeadData returns an instance of $this */ public function testEnsureSetHeadDataReturnsThisObject() { // This method calls JText::script() which has a dependency to JHtml::_('behavior.core') and requires the application be loaded JFactory::$application = $this->getMockCmsApp(); $this->assertSame($this->object, $this->object->setHeadData($this->testHeadData)); }
/** * @testdox Test that setHeadData returns an instance of $this */ public function testEnsureSetHeadDataReturnsThisObject() { $this->assertSame($this->object, $this->object->setHeadData($this->testHeadData)); }