function onAfterRender() { $app = JFactory::getApplication(); if ($app->isSite()) { $loaded = JLoader::getClassList(); if (isset($loaded['baformshelper'])) { $html = JResponse::getBody(); $html_split = explode('<body', $html, 2); $pre = $html_split['0']; $body = '<body' . $html_split['1']; $body_split = explode('</body>', $body); $post = array_pop($body_split); $body = implode('</body>', $body_split) . '</body>'; $body = $this->getContent($body); $html = $pre . $body . $post; JResponse::setBody($html); } } }
function onAfterRender() { $app = JFactory::getApplication(); if ($app->isSite()) { $loaded = JLoader::getClassList(); if (in_array(JPATH_ROOT . '/administrator/components/com_baforms/helpers/baforms.php', $loaded)) { $html = JResponse::getBody(); $html_split = explode('<body', $html, 2); $pre = $html_split['0']; $body = '<body' . $html_split['1']; $body_split = explode('</body>', $body); $post = array_pop($body_split); $body = implode('</body>', $body_split) . '</body>'; $body = $this->getContent($body); $html = $pre . $body . $post; JResponse::setBody($html); } } }
/** * Get the path based on a class name * * @param string The class name * @return string|false Returns the path on success FALSE on failure */ protected function _pathFromClassname($classname) { $path = false; $word = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $classname); $parts = explode('_', $word); // If class start with a 'J' it is a Joomla framework class and we handle it if(array_shift($parts) == $this->_prefix) { $class = strtolower($classname); //force to lower case if (class_exists($class)) { return; } $classes = method_exists('JLoader','getClassList') ? JLoader::getClassList() : JLoader::register(); if(array_key_exists( $class, $classes)) { $path = $classes[$class]; } } return $path; }
/** * Tests the JLoader::register method. * * @return void * * @since 11.1 */ public function testRegister() { JLoader::register('BogusLoad', $this->bogusFullPath); $this->assertThat(in_array($this->bogusFullPath, JLoader::getClassList()), $this->isTrue(), 'Tests that the BogusLoad class has been registered.'); JLoader::register('fred', 'fred.php'); $this->assertThat(in_array('fred.php', JLoader::getClassList()), $this->isFalse(), 'Tests that a file that does not exist does not get registered.'); }
/** * Method to intelligently load class files in the framework * * @param string $classname The class name * @param string $filepath The filepath ( dot notation ) * @param array $options * @return boolean */ public static function load($classname, $filepath = 'library', $options = array('site' => 'site', 'type' => 'libraries', 'ext' => 'dioscouri')) { $classname = strtolower($classname); if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $classes = JLoader::getClassList(); } else { // Joomla! 1.5 code here $classes = JLoader::register(); } if (class_exists($classname) || array_key_exists($classname, $classes)) { // echo "$classname exists<br/>"; return true; } static $paths; if (empty($paths)) { $paths = array(); } if (empty($paths[$classname]) || !is_file($paths[$classname])) { // find the file and set the path if (!empty($options['base'])) { $base = $options['base']; } else { // recreate base from $options array switch ($options['site']) { case "site": $base = JPATH_SITE . '/'; break; default: $base = JPATH_ADMINISTRATOR . '/'; break; } $base .= !empty($options['type']) ? $options['type'] . '/' : ''; $base .= !empty($options['ext']) ? $options['ext'] . '/' : ''; } $paths[$classname] = $base . str_replace('.', '/', $filepath) . '.php'; } // if invalid path, return false if (!is_file($paths[$classname])) { // echo "file does not exist<br/>"; return false; } // if not registered, register it if (!array_key_exists($classname, $classes)) { // echo "$classname not registered, so registering it<br/>"; JLoader::register($classname, $paths[$classname]); return true; } return false; }
/** * This test should try and fail to register a non-existent class * * @group JLoader * @covers JLoader::register * @return void */ public function testFailsToRegisterABadClass() { JLoader::register("fred", "fred.php"); $this->assertFalse(in_array('fred.php', JLoader::getClassList())); }