private static function getMinifier($minifier) { $minifierName = end(explode('.', $minifier)); $class = "ntentan\\views\\helpers\\minifiables\\minifiers\\" . str_replace(".", "\\", $minifier) . '\\' . Ntentan::camelize($minifierName) . "Minifier"; $instance = new $class(); return $instance; }
public function execute() { $rss = new \SimpleXMLElement('<rss></rss>'); $rss['version'] = '2.0'; $rss->addChild('channel'); foreach ($this->properties as $property => $value) { $rss->channel->addChild(Ntentan::camelize($property, '.', '', true), $value); } foreach ($this->items as $item) { $itemElement = $rss->channel->addChild('item'); foreach ($item as $field => $value) { if ($field == "published") { $field = 'pubDate'; } if ($field == "source") { $field = 'description'; } if ($field == "id") { $field = 'guid'; } $value = utf8_encode($value); $itemElement->addChild($field, $value); } } return $rss->asXML(); }
private function getHelper($helper) { $helperPlural = Ntentan::plural($helper); $helper = $helperPlural == null ? $helper : $helperPlural; if ($helper === null) { return false; } if (!isset($this->loadedHelpers[$this->plugin . $helper])) { $camelizedHelper = Ntentan::camelize($helper) . "Helper"; $helperFile = Ntentan::$modulesPath . "/helpers/{$helper}/{$camelizedHelper}.php"; if (file_exists($helperFile)) { require_once $helperFile; $helperClass = "\\" . Ntentan::$namespace . "\\helpers\\{$helper}\\{$camelizedHelper}"; } else { if ($this->pluginMode) { $path = Ntentan::getPluginPath("{$this->plugin}/helpers/{$helper}"); Ntentan::addIncludePath("{$this->plugin}"); $helperClass = "\\ntentan\\plugins\\{$this->plugin}\\helpers\\{$helper}\\{$camelizedHelper}"; } else { if (file_exists(Ntentan::getFilePath("lib/views/helpers/{$helper}"))) { $path = Ntentan::getFilePath("lib/views/helpers/{$helper}"); $helperClass = "\\ntentan\\views\\helpers\\{$helper}\\{$camelizedHelper}"; } else { return false; } } } Ntentan::addIncludePath($path); $helperInstance = new $helperClass(); $this->loadedHelpers[$this->plugin . $helper] = $helperInstance; } return $this->loadedHelpers[$this->plugin . $helper]; }
/** * Loads the widget. * * @todo this method should store in the cache the location of the widget */ public function loadWidget($widget) { $widgetFile = Ntentan::$modulesPath . "/widgets/{$widget}/" . Ntentan::camelize($widget) . "Widget.php"; if (file_exists($widgetFile)) { require_once $widgetFile; $widgetClass = "\\" . Ntentan::$namespace . "\\widgets\\{$widget}\\" . Ntentan::camelize($widget) . 'Widget'; $path = Ntentan::$namespace . "/widgets/{$widget}"; } else { if ($this->pluginMode) { $widgetClass = "\\ntentan\\plugins\\{$this->plugin}\\widgets\\{$widget}\\" . Ntentan::camelize($widget) . 'Widget'; $path = "plugins/{$this->plugin}/widgets/{$widget}"; } else { if (file_exists(Ntentan::getFilePath("lib/views/widgets/{$widget}/" . Ntentan::camelize($widget) . "Widget.php"))) { Ntentan::addIncludePath(Ntentan::getFilePath("lib/controllers/widgets/{$widget}")); $widgetClass = "\\ntentan\\views\\widgets\\{$widget}\\" . Ntentan::camelize($widget) . 'Widget'; $path = Ntentan::getFilePath("lib/views/widgets/{$widget}"); } else { return false; } } } $widgetClass = new ReflectionClass($widgetClass); $widgetInstance = $widgetClass->newInstance(); $widgetInstance->filePath = $path; $widgetInstance->name = $widget; $widgetInstance->plugin = $this->plugin; return $widgetInstance; }
public function generate($format) { $generatorClassName = Ntentan::camelize($format) . "Feed"; require "generators/{$format}/" . $generatorClassName . ".php"; $generatorClass = "\\ntentan\\views\\helpers\\feeds\\generators\\{$format}\\{$generatorClassName}"; $generator = new $generatorClass(); $generator->setup($this->properties, $this->items); return $generator->execute(); }
/** * Generates an instance of a Cache class. * * This method is here to provide a more transparent interface through * which caching classes could be instantiated. The implementation to be * used is determined from the ntentan configuration files and assigned * to the Ntentan::$cacheMethod property. * * @return Cache */ private static function instance() { if (Cache::$instance == null) { $class = Ntentan::camelize(Ntentan::$cacheMethod); require_once "{$class}.php"; $class = "ntentan\\caching\\{$class}"; Cache::$instance = new $class(); } return Cache::$instance; }
public static function getEngineInstance($template) { $last = explode(".", $template); $engine = end($last); if (!isset(TemplateEngine::$loadedInstances[$engine])) { Ntentan::addIncludePath(Ntentan::getFilePath("lib/views/template_engines/" . $engine)); $engineClass = "ntentan\\views\\template_engines\\{$engine}\\" . Ntentan::camelize($engine); try { $engineInstance = new $engineClass(); } catch (\Exception $e) { throw new \ntentan\exceptions\ClassNotFoundException("Could not load template engine class [{$engineClass}] for {$template}"); } TemplateEngine::$loadedInstances[$engine] = $engineInstance; } TemplateEngine::$loadedInstances[$engine]->template = $template; return TemplateEngine::$loadedInstances[$engine]; }
public static function start($store = '') { // setup the default store if ($store == '') { $store = Ntentan::$config[Ntentan::$context]['sessions.container']; } // Exit on the special none store means sessions are not needed if ($store == 'none') { return; } if ($store != '') { $handlerClass = "ntentan\\sessions\\stores\\" . Ntentan::camelize($store) . 'Store'; self::$handler = new $handlerClass(); $configExpiry = Ntentan::$config[Ntentan::$context]['sessions.lifespan']; self::$lifespan = $configExpiry > 0 ? $configExpiry : self::$lifespan; session_set_save_handler(array(self::$handler, 'open'), array(self::$handler, 'close'), array(self::$handler, 'read'), array(self::$handler, 'write'), array(self::$handler, 'destroy'), array(self::$handler, 'gc')); register_shutdown_function('session_write_close'); } session_start(); }
public static function getClassName($className) { $key = "model_class_{$className}"; if (Cache::exists($key)) { $return = Cache::get($key); } else { $classNameArray = explode('.', $className); $className = Ntentan::camelize(end($classNameArray)); $return = "\\" . str_replace("/", "\\", Ntentan::$namespace) . "\\modules\\" . implode("\\", $classNameArray) . "\\{$className}"; /*$modelClassFile = Ntentan::$modulesPath . '/modules/' . implode('/', $classNameArray) . "/$className.php" ; if(!file_exists($modelClassFile)) { throw new ModelNotFoundException("Model class *$return* not found"); }*/ } return $return; }
public function __call($function, $arguments) { if ($function == "open") { $this->container = new api\Form(); if ($arguments[0] != '') { $this->container->setId($arguments[0]); } $this->container->rendererMode = 'head'; $return = $this->container; } else { if ($function == "get") { $name = $arguments[0]['name']; $elementObject = $this->createModelField($arguments[0]); $elementObject->setValue(self::$data[$name]); if (isset($this->errors[$name])) { $elementObject->setErrors($this->errors[$name]); } $return = $elementObject; } else { if ($function == "close") { if ($arguments[0] != "") { foreach ($arguments as $argument) { $this->container->submitValues[] = $argument; } } elseif ($arguments[0] === false) { $this->container->showSubmit = false; } $this->container->rendererMode = 'foot'; $return = self::getRendererInstance()->foot(); $return .= $this->container; } else { if (substr($function, 0, 5) == "open_") { $container = "ntentan\\views\\helpers\\forms\\api\\" . Ntentan::camelize(substr($function, 5, strlen($function))); $containerClass = new ReflectionClass($container); $containerObject = $containerClass->newInstanceArgs($arguments); $return = $containerObject->renderHead(); } elseif (substr($function, 0, 6) == "close_") { $container = "ntentan\\views\\helpers\\forms\\api\\" . Ntentan::camelize(substr($function, 6, strlen($function))); $containerClass = new ReflectionClass($container); $containerObject = $containerClass->newInstanceArgs($arguments); $return = $containerObject->renderFoot(); } elseif (substr($function, 0, 4) == "get_") { $element = "ntentan\\views\\helpers\\forms\\api\\" . Ntentan::camelize(substr($function, 4, strlen($function))); $elementClass = new ReflectionClass($element); $elementObject = $elementClass->newInstanceArgs($arguments); $name = $elementObject->getName(); $elementObject->setValue(self::$data[$name]); if (isset($this->errors[$name])) { $elementObject->setErrors($this->errors[$name]); } $return = $elementObject; } elseif (substr($function, 0, 4) == "add_") { $element = "ntentan\\views\\helpers\\forms\\api\\" . Ntentan::camelize(substr($function, 4, strlen($function))); $elementClass = new ReflectionClass($element); $elementObject = $elementClass->newInstanceArgs($arguments); $return = $this->container->add($elementObject); } else { throw new Exception("Function *{$function}* not found in form helper."); } } } } if ($this->echo) { echo $return; } else { return $return; } }
public static function camelizeAndLowerFirst($string) { return Ntentan::camelize($string, '.', '', true); }
public function add() { $model = $this->getModel(); $description = $model->describe(); $entityCode = str_replace(' ', '_', $this->entity); $this->set("heading_level", $this->headingLevel); $this->set("headings", $this->headings); $this->set("fields", $description["fields"]); $this->set("entity", $this->entity); $this->set('entity_code', $entityCode); $this->view->template = "admin_component_add.tpl.php"; if ($this->consoleMode) { $addExtensionMethodName = Ntentan::camelize(Ntentan::plural($entityCode), ".", "", true) . 'AdminAdd'; if (method_exists($this->controller, $addExtensionMethodName)) { $addExtensionMethod = new ReflectionMethod($this->controller, $addExtensionMethodName); $addExtensionMethod->invoke($this->controller); } } if (count($_POST) > 0) { $model->setData($_POST); $id = $model->save(); if ($id > 0) { $route = $this->consoleMode ? $this->consoleModeRoute : $this->route; Ntentan::redirect("{$route}?n=1&i=" . base64_encode($model)); } else { $this->set("data", $_POST); $this->set("errors", $model->invalidFields); } } }
/** * A utility method to load a controller. This method loads the controller * and fetches the contents of the controller into the Controller::$contents * variable if the get_contents parameter is set to true on call. If a * controller doesn't exist in the module path, a ModelController is loaded * to help manipulate the contents of the model. If no model exists in that * location, it is asumed to be a package and a package controller is * loaded. * * @param $path The path for the model to be loaded. * @param $returnInstanceOnly Fources the method to return only the instance of the controller object. * @return Controller */ public static function load($route, $returnInstanceOnly = false) { $controllerRoute = ''; $routeArray = explode('/', $route); // Loop through the filtered path and extract the controller class for ($i = 0; $i < count($routeArray); $i++) { $p = $routeArray[$i]; $pCamelized = Ntentan::camelize($p); $filePath = Ntentan::$modulesPath . "/modules/{$controllerRoute}/{$p}/"; if (file_exists($filePath . "{$pCamelized}Controller.php")) { $controllerName = $pCamelized . "Controller"; $controllerRoute .= "/{$p}"; $modelRoute .= "{$p}"; if ($controllerRoute[0] == "/") { $controllerRoute = substr($controllerRoute, 1); } if ($controllerName == "") { Ntentan::error("Path not found! [{$route}]"); } else { Ntentan::addIncludePath(Ntentan::$modulesPath . "/{$controllerRoute}/"); //$controllerName.php"; $controllerNamespace = "\\" . str_replace("/", "\\", Ntentan::$namespace . "/modules/{$controllerRoute}/"); $controllerName = $controllerNamespace . $controllerName; if (class_exists($controllerName)) { $controller = new $controllerName(); foreach ($controller->components as $component) { $controller->addComponent($component); } $controller->setRoute($controllerRoute); $controller->setName($controllerName); $controller->modelRoute = $modelRoute; $controller->filePath = $filePath; $controller->init(); if ($returnInstanceOnly) { return $controller; } // Trap for the cache if (Cache::exists("view_" . Ntentan::getRouteKey()) && Ntentan::$debug === false) { echo Cache::get('view_' . Ntentan::$route); return; } if ($controller->method == '') { $controller->method = $routeArray[$i + 1] != '' ? Ntentan::camelize($routeArray[$i + 1], ".", "", true) : $controller->defaultMethodName; $controller->rawMethod = $routeArray[$i + 1] != '' ? $routeArray[$i + 1] : $controller->defaultMethodName; } if (!$controller->hasMethod()) { $modelRoute .= "."; continue; } } else { Ntentan::error("Controller class *{$controllerName}* not found."); } $controller->runMethod(array_slice($routeArray, $i + 2)); return; } } else { $controllerRoute .= "/{$p}"; $modelRoute .= "{$p}."; } } if (is_object($controller)) { $message = "Controller method *{$routeArray[$i - 1]}()* not found for the *{$controllerName}* controller."; } else { $message = "Controller not found for route *{$route}*"; } Ntentan::error($message); }
public function login() { Ntentan::addIncludePath(Ntentan::getFilePath('lib/controllers/components/auth/methods')); $authenticatorClass = __NAMESPACE__ . '\\methods\\' . Ntentan::camelize($this->authMethod); if (class_exists($authenticatorClass)) { $this->authMethodInstance = new $authenticatorClass(); $this->authMethodInstance->usersModel = $this->_usersModel; } else { print Ntentan::message("Authenticator class *{$authenticatorClass}* not found."); } if ($this->loggedIn()) { $this->performSuccessOperation(); } else { if ($this->authMethodInstance->login()) { $this->performSuccessOperation(); } else { switch ($this->onFailure) { case AuthComponent::CALL_FUNCTION: $decomposed = explode("::", $this->failureFunction); $className = $decomposed[0]; $methodName = $decomposed[1]; $method = new \ReflectionMethod($className, $methodName); $method->invoke(null, $this->controller); break; case AuthComponent::REDIRECT: $this->loginRoute = $this->loginRoute == null ? $this->controller->route . "/login" : $this->loginRoute; $this->logoutRoute = $this->logoutRoute == null ? $this->controller->route . "/logout" : $this->logoutRoute; $this->redirectToLogin(); break; default: $this->set('login_status', false); break; } } } }
public static function create() { $args = func_get_args(); $type = array_shift($args); $typeClass = new \ReflectionClass('ntentan\\plugins\\wyf\\helpers\\inputs\\forms\\' . \ntentan\Ntentan::camelize($type)); return $typeClass->newInstanceArgs($args); }
public function setPermissions() { $arguments = func_get_args(); $id = array_shift($arguments); $role = $this->model->getFirstWithId($id); if (count($_POST) > 0) { foreach ($_POST as $permissionName => $path) { $permission = Model::load('system.permissions')->getFirst(array('conditions' => array('role_id' => $id, 'permission' => $permissionName))); if ($permission->count() == 0 && $path != 'no') { $permission->setData(array('role_id' => $id, 'permission' => $permissionName, 'path' => $path, 'access' => true)); $permission->save(); } else { if ($path == 'no') { $permission->access = false; $permission->update(); } else { $permission->access = true; $permission->update(); } } } $role->menu_tree = json_encode($this->getMenuTree($role)); $role->update(); } $permissionItems = array(); $baseRoute = implode('/', $arguments) . (count($arguments) > 0 ? '/' : ''); $baseDirectory = Ntentan::$namespace . "/modules/{$baseRoute}"; $dir = dir($baseDirectory); while (false !== ($entry = $dir->read())) { if ($entry == '.' || $entry == '..') { continue; } $path = getcwd() . "/{$baseDirectory}{$entry}"; $class = Ntentan::camelize($entry) . 'Controller'; if (file_exists("{$path}/{$class}.php")) { $controller = Controller::load("{$baseRoute}{$entry}", true); if (is_a($controller, "\\ntentan\\plugins\\wyf\\lib\\WyfController")) { $permissionItem = array('type' => 'permission', 'label' => Ntentan::toSentence($entry), 'permissions' => array(), 'path' => "{$baseRoute}{$entry}"); foreach ($controller->getPermissions() as $permission => $description) { $active = $role->getPermission($permission); $permissionItem['permissions'][] = array('name' => $permission, 'description' => $description, 'active' => $active); } $permissionItems[] = $permissionItem; } continue; } $class = Ntentan::camelize($entry); if (file_exists("{$path}/{$class}.php")) { continue; } if (is_dir($path)) { $permissionItems[] = array('type' => 'link', 'label' => Ntentan::toSentence($entry), 'link' => Ntentan::getUrl("{$this->route}/set_permissions/{$id}/{$entry}")); } } $this->set('permission_items', $permissionItems); $this->set('role', (string) $role); }