Exemple #1
0
 public function __toString()
 {
     TemplateEngine::appendPath(Ntentan::getFilePath('lib/views/helpers/lists/templates'));
     $this->rowTemplate = $this->rowTemplate == null ? 'row.tpl.php' : $this->rowTemplate;
     $this->defaultCellTemplate = $this->defaultCellTemplate == null ? 'default_cell.tpl.php' : $this->defaultCellTemplate;
     return TemplateEngine::render('list.tpl.php', array("headers" => $this->headers, "data" => $this->data, "row_template" => $this->rowTemplate, "cell_templates" => $this->cellTemplates, "default_cell_template" => $this->defaultCellTemplate, "variables" => $this->variables, "has_headers" => $this->hasHeaders));
 }
Exemple #2
0
 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];
 }
Exemple #3
0
 /**
  * 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;
 }
Exemple #4
0
 public static function loadAsset($asset, $copyFrom = null)
 {
     $assetPath = $copyFrom == null ? "assets/{$asset}" : $copyFrom;
     $publicPath = "public/{$asset}";
     $publicDirectory = dirname($publicPath);
     if (file_exists($publicPath) && !Ntentan::$debug) {
         return $publicPath;
     }
     if (file_exists($assetPath) && file_exists($publicDirectory) && is_writable($publicDirectory)) {
         copy($assetPath, $publicPath);
     } else {
         if (file_exists(Ntentan::getFilePath("assets/{$asset}")) && file_exists($publicDirectory) && is_writable($publicDirectory)) {
             copy(Ntentan::getFilePath("assets/{$asset}"), $publicPath);
         } else {
             if (file_exists($copyFrom) && is_writable($publicDirectory)) {
                 copy($copyFrom, $publicPath);
             } else {
                 if (!file_exists($assetPath)) {
                     Ntentan::error("File not found <b><code>{$assetPath}</code></b>");
                 } else {
                     if (!is_writable($publicPath)) {
                         Ntentan::error("Destination <b><code>public/{$asset}</code></b> is not writable");
                     }
                 }
                 die;
             }
         }
     }
     return $publicPath;
 }
Exemple #5
0
 public function login()
 {
     TemplateEngine::appendPath(Ntentan::getFilePath('lib/controllers/components/auth/views'));
     if (isset($_REQUEST["username"]) && isset($_REQUEST["password"])) {
         return $this->authLocalPassword($_REQUEST["username"], $_REQUEST["password"]);
     } else {
         return false;
     }
 }
Exemple #6
0
 public static function getStylesheet()
 {
     return Ntentan::getFilePath('lib/views/helpers/forms/css/forms.css');
 }
Exemple #7
0
 public static function message($message, $subTitle = null, $type = null, $showTrace = true, $trace = false)
 {
     // Be silent in production systems at all cost
     if (Ntentan::$debug == false) {
         return;
     }
     if ($showTrace === true) {
         $trace = is_array($trace) ? $trace : debug_backtrace();
     }
     ob_start();
     if (defined('STDERR') || ini_get('html_errors') == 'off' || ini_get('html_errors') == '0') {
         include Ntentan::getFilePath("templates/message-cli.tpl.php");
     } else {
         include Ntentan::getFilePath("templates/message.tpl.php");
     }
     $message = ob_get_clean();
     return $message;
 }
Exemple #8
0
 public static function getClassFile($class)
 {
     $key = "file_{$class}";
     if (Cache::exists($key)) {
         $classFile = Cache::get($key);
     } else {
         $fullPath = explode("\\", $class);
         //Get rid of any initial empty class name
         if ($fullPath[0] == "") {
             array_shift($fullPath);
         }
         $class = array_pop($fullPath);
         if ($fullPath[0] == \ntentan\Ntentan::$namespace) {
             $basePath = Ntentan::$appHome . '/' . implode("/", $fullPath);
         } else {
             if ($fullPath[0] == 'ntentan' && $fullPath[1] == "plugins") {
                 array_shift($fullPath);
                 array_shift($fullPath);
                 $basePath = \ntentan\Ntentan::getPluginPath(implode("/", $fullPath));
             } else {
                 if ($fullPath[0] == 'ntentan' && $fullPath[1] == "dev") {
                     array_shift($fullPath);
                     array_shift($fullPath);
                     $basePath = NTENTAN_DEV_HOME . '/' . implode("/", $fullPath);
                 } else {
                     if ($fullPath[0] == 'ntentan') {
                         array_shift($fullPath);
                         $basePath = \ntentan\Ntentan::getFilePath('lib/' . implode("/", $fullPath));
                     }
                 }
             }
         }
         $classFile = $basePath . '/' . $class . '.php';
         Cache::add($key, $classFile);
     }
     return $classFile;
 }
Exemple #9
0
 public function getStylesheet()
 {
     return Ntentan::getFilePath('lib/controllers/components/admin/css/admin.css');
 }
Exemple #10
0
 private function loadComponent($component, $arguments, $path, $plugin = null)
 {
     $camelizedComponent = Ntentan::camelize($component);
     $componentName = "{$path}\\{$component}\\{$camelizedComponent}Component";
     if (file_exists(Ntentan::getClassFile($componentName))) {
         $key = Ntentan::camelizeAndLowerFirst($plugin . ($plugin == null ? $camelizedComponent : $camelizedComponent));
         $componentClass = new ReflectionClass($componentName);
         $componentInstance = $componentClass->newInstanceArgs($arguments);
         $componentInstance->filePath = Ntentan::getFilePath("lib/controllers/components/{$component}");
         $this->componentInstances[$key] = $componentInstance;
         $this->componentInstances[$key]->setController($this);
         $this->componentInstances[$key]->route = $this->route;
         $this->componentInstances[$key]->init();
         return $componentName;
     } else {
         return false;
     }
 }
Exemple #11
0
/**
 * A shortcut wrapper around the Ntentan::getFilePath method
 * @param unknown_type $path
 */
function n($path)
{
    return Ntentan::getFilePath($path);
}
Exemple #12
0
 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;
             }
         }
     }
 }