Esempio n. 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));
 }
Esempio n. 2
0
 public function assignRoles($id)
 {
     if (count($_POST) > 0) {
         $roles = Model::load('system.user_roles')->getJustWithUserId($id);
         foreach ($roles as $role) {
             $role->delete();
         }
         foreach ($_POST as $roleId) {
             $role = Model::load('system.user_roles')->getNew();
             $role->user_id = $id;
             $role->role_id = $roleId;
             $role->save();
         }
         Ntentan::redirect($this->route);
     }
     $item = $this->model->getJustFirstWithId($id);
     $roles = Model::load('system.roles')->getAll();
     $assignedRoles = Model::load('system.user_roles')->getJustWithUserId($id, array('fields' => array('role_id')))->toArray();
     $structuredAssignedRoles = array();
     foreach ($assignedRoles as $assignedRole) {
         $structuredAssignedRoles[$assignedRole['role_id']] = true;
     }
     $this->set('roles', $roles);
     $this->set('assigned_roles', $structuredAssignedRoles);
     $this->set('item', (string) $item);
 }
Esempio n. 3
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];
 }
Esempio n. 4
0
 public function signin()
 {
     $oauthapp = new \YahooOAuthApplication(Ntentan::$config['social.yahoo.consumer_key'], Ntentan::$config['social.yahoo.consumer_secret'], Ntentan::$config['social.yahoo.app_id'], Ntentan::$config['social.yahoo.redirect_uri']);
     if (!isset($_REQUEST['openid_mode'])) {
         Ntentan::redirect($oauthapp->getOpenIDUrl($oauthapp->callback_url), true);
         die;
     }
     if ($_REQUEST['openid_mode'] == 'id_res') {
         $requestToken = new \YahooOAuthRequestToken($_REQUEST['openid_oauth_request_token'], '');
         $_SESSION['yahoo_oauth_request_token'] = $requestToken->to_string();
         $oauthapp->token = $oauthapp->getAccessToken($requestToken);
         $_SESSION['yahoo_oauth_access_token'] = $oauthapp->token->to_string();
     }
     $profile = $oauthapp->getProfile()->profile;
     if (is_object($profile)) {
         if (is_array($profile->emails)) {
             foreach ($profile->emails as $email) {
                 if ($email->primary == 'true') {
                     $email = $email->handle;
                     break;
                 }
             }
         }
         return array('firstname' => $profile->givenName, 'lastname' => $profile->familyName, 'key' => "yahoo_{$profile->guid}", 'avatar' => $profile->image->imageUrl, 'email' => $email, 'email_confirmed' => true);
     }
     die('Failed');
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 public function execute()
 {
     $menuItems = array();
     $selected = false;
     $default = false;
     $fullyMatched = false;
     $route = Ntentan::getUrl(Ntentan::$route);
     $requestedRoute = Ntentan::getUrl(Ntentan::$requestedRoute);
     foreach ($this->items as $index => $item) {
         if (is_string($item) || is_numeric($item)) {
             $item = array('label' => $item, 'url' => Ntentan::getUrl(strtolower(str_replace(' ', '_', $item))));
         }
         $item['selected'] = $item['url'] == substr($route, 0, strlen($item['url'])) || $item['url'] == substr($requestedRoute, 0, strlen($item['url']));
         $item['fully_matched'] = $item['url'] == $requestedRoute || $item['url'] == $route;
         if ($item['selected'] === true) {
             $selected = true;
         }
         if ($item['fully_matched'] === true) {
             $fullyMatched = true;
         }
         if ($item['default'] === true) {
             $default = $index;
         }
         $menuItems[$index] = $item;
     }
     if (!$selected && $default !== false && !$fullyMatched !== false) {
         $menuItems[$default]['selected'] = true;
         $menuItems[$default]['fully_matched'] = true;
     }
     $this->set('items', $menuItems);
     $this->set('css_classes', $this->cssClasses);
 }
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
 public function preExecute()
 {
     if ($_SESSION["logged_in"] === true) {
         if (is_array($this->authenticated[$_SESSION['role_id']])) {
             foreach ($this->authenticated[$_SESSION['role_id']] as $authenticated) {
                 if (is_string($authenticated)) {
                     if (preg_match($authenticated, Ntentan::$route, $members)) {
                         return;
                     }
                 }
             }
             header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
             die;
         }
     } else {
         foreach ($this->anonymous as $anonymous) {
             if (Ntentan::$route === $this->controller->authComponent->loginRoute) {
                 $this->controller->authComponent->login();
                 break;
             } else {
                 if (preg_match("{$anonymous["path"]}", Ntentan::$route) > 0) {
                     if ($anonymous["access"] == "disallow") {
                         if (isset($anonymous["fallback"])) {
                             Ntentan::redirect($anonymous["fallback"]);
                         } else {
                             Ntentan::redirect($this->controller->authComponent->loginRoute . "&redirect=" . \urlencode(Ntentan::$route));
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
 private function getWyfClassName($wyfPath, $type)
 {
     $namespace = Ntentan::getNamespace();
     $wyfPathParts = explode('.', $wyfPath);
     $name = Text::ucamelize(array_pop($wyfPathParts));
     $base = (count($wyfPathParts) ? '\\' : '') . implode('\\', $wyfPathParts);
     return "\\{$namespace}\\app{$base}\\{$type}\\{$name}";
 }
Esempio n. 10
0
 public function run()
 {
     $this->set('report_title', $this->report->getTitle());
     $this->set('action_route', Ntentan::getUrl("{$this->route}/generate"));
     $this->set('report_filters', $this->report->getDataSource('ntentan_data')->getMetaData());
     $this->set('default_filters', $this->defaultFilters);
     $this->view->template = 'report_setup.tpl.php';
 }
Esempio n. 11
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;
     }
 }
Esempio n. 12
0
 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();
 }
Esempio n. 13
0
 public function testWrongPath()
 {
     $this->setExpectedException('PHPUnit_Framework_Error', 'The file cache directory *i_dont_think_this_dir_would_exist* was not found or is not writable!');
     Ntentan::$debug = false;
     // prevent the error message from showing
     Cache::setCachePath('i_dont_think_this_dir_would_exist');
     Cache::add('test', 'should fail');
     Ntentan::$debug = true;
 }
Esempio n. 14
0
 /**
  * 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;
 }
Esempio n. 15
0
 public function __construct($model)
 {
     $this->renderWithType = 'select';
     $model = \ntentan\models\Model::load($model);
     $entity = Ntentan::singular($model->getName());
     $this->setLabel(Ntentan::toSentence($entity));
     $this->setName("{$entity}_id");
     $options = $model->getAll();
     foreach ($options as $option) {
         $this->option((string) $option, $option->id);
     }
 }
Esempio n. 16
0
 protected function addImplementation($key, $object, $ttl)
 {
     if (file_exists(self::getCacheFile()) && is_writable(self::getCacheFile())) {
         $expires = $ttl == 0 ? $ttl : $ttl + time();
         $object = array('expires' => $expires, 'object' => $object);
         $key = $this->hashKey($key);
         file_put_contents(self::getCacheFile("{$key}"), serialize($object));
     } else {
         // Throwing exceptions here sometimes breaks the template engine
         Ntentan::error("The file cache directory *" . self::getCacheFile() . "* was not found or is not writable!", 'Caching error!');
         trigger_error("The file cache directory *" . self::getCacheFile() . "* was not found or is not writable!");
     }
 }
Esempio n. 17
0
 public function __construct($label, $model, $value = null, $extraConditions = array())
 {
     parent::__construct();
     $this->label = $label;
     $modelInstance = Model::load($model);
     if ($value === null) {
         $data = $modelInstance->get('all', count($extraConditions) > 0 ? array('conditions' => $extraConditions) : null);
     } else {
         $data = $modelInstance->get('all', array('fields' => array('id', $value), 'conditions' => count($extraConditions) > 0 ? $extraConditions : null));
     }
     $this->setName(Ntentan::singular($model) . "_id");
     for ($i = 0; $i < $data->count(); $i++) {
         $this->addOption($value == null ? $data[$i] : $data[$i][$value], $data[$i]["id"]);
     }
 }
Esempio n. 18
0
 public function generate($templateData, $view)
 {
     if (file_exists($this->template)) {
         foreach ($templateData as $key => $value) {
             ${$key} = Variable::initialize($value);
         }
         $helpers = $this->helpers;
         $widgets = $this->widgets;
         ob_start();
         include $this->template;
         return ob_get_clean();
     } else {
         echo Ntentan::message("Template file *{$this->template}* not found");
     }
 }
Esempio n. 19
0
 public function __construct()
 {
     $this->addComponent('auth', array('users_model' => 'system.users', 'on_success' => 'call_function', 'login_route' => 'auth/login', 'success_function' => AuthController::class . '::postLogin'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../../views/default'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../../views/menus'));
     View::set('route_breakdown', explode('/', Router::getRoute()));
     View::set('wyf_title', Config::get('ntentan:app.name'));
     $class = get_class($this);
     $namespace = Ntentan::getNamespace();
     if (preg_match("/{$namespace}\\\\app\\\\(?<base>.*)\\\\controllers\\\\(?<name>.*)Controller/", $class, $matches)) {
         $this->package = strtolower(str_replace("\\", ".", $matches['base']) . "." . $matches['name']);
         $this->name = str_replace(".", " ", $this->package);
         $this->path = str_replace(' ', '/', $this->name);
     }
 }
Esempio n. 20
0
File: Wyf.php Progetto: ntentan/wyf
 public static function init($parameters = [])
 {
     Router::mapRoute('wyf_auth', 'auth/{action}', ['default' => ['controller' => controllers\AuthController::class]]);
     Router::mapRoute('wyf_api', 'api/{*path}', ['default' => ['controller' => controllers\ApiController::class, 'action' => 'rest']]);
     Router::mapRoute('wyf_main', function ($route) {
         $routeArray = explode('/', $route);
         $routeDetails = self::getController($routeArray, realpath(__DIR__ . '/../../../../src/app/'), \ntentan\Ntentan::getNamespace() . '\\app');
         return $routeDetails;
     }, ['default' => ['action' => 'index']]);
     TemplateEngine::appendPath(realpath(__DIR__ . '/../views/layouts'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../views'));
     AssetsLoader::appendSourceDir(realpath(__DIR__ . '/../assets'));
     View::set('wyf_app_name', $parameters['short_name']);
     InjectionContainer::bind(ModelClassResolver::class)->to(ClassNameResolver::class);
     InjectionContainer::bind(ControllerClassResolver::class)->to(ClassNameResolver::class);
 }
Esempio n. 21
0
 private function getLink($index)
 {
     if ($this->query == '') {
         $link = Ntentan::getUrl($this->baseRoute . $index);
     } else {
         $link = Ntentan::getUrl($this->baseRoute) . '?';
         foreach ($_GET as $key => $value) {
             if ($key == $this->query) {
                 continue;
             }
             $link .= "{$key}=" . urlencode($value) . '&';
         }
         $link .= "{$this->query}={$index}";
     }
     return $link;
 }
Esempio n. 22
0
 public function __construct($model, $submodel)
 {
     $this->renderWithType = 'select';
     $model = \ntentan\models\Model::load($model);
     $submodel = \ntentan\models\Model::load($submodel);
     $entity = Ntentan::singular($submodel->getName());
     $parentEntity = Ntentan::singular($model->getName());
     $this->setLabel(Ntentan::toSentence($entity));
     $this->setName("{$entity}_id");
     $parentId = "{$parentEntity}_id";
     $options = $model->getAll();
     foreach ($options as $option) {
         $suboptions = $submodel->getAll(array('conditions' => array($parentId => $option->id)));
         foreach ($suboptions as $suboption) {
             $this->option("{$option} / {$suboption}", $suboption->id);
         }
     }
 }
Esempio n. 23
0
 public static function initialize($data)
 {
     $type = gettype($data);
     switch ($type) {
         case 'string':
             return new Variable($data);
         case 'array':
             return new Variable($data, array_keys($data));
         case 'object':
         case 'boolean':
         case 'integer':
         case 'double':
         case 'NULL':
             return $data;
         default:
             \ntentan\Ntentan::error("Cannot handle the {$type} type in templates");
     }
 }
Esempio n. 24
0
 public function trail_data($data = false)
 {
     if ($data === false) {
         if ($this->trailData === false) {
             $url = Ntentan::getUrl('/');
             $trailData = array(array('url' => $url, 'label' => 'Home'));
             foreach (explode('/', Ntentan::$requestedRoute) as $route) {
                 $url .= "{$route}/";
                 $trailData[] = array('url' => $url, 'label' => Ntentan::toSentence($route));
             }
             return $trailData;
         } else {
             return $this->trailData;
         }
     } else {
         $this->trailData = $data;
         return $this;
     }
 }
Esempio n. 25
0
 public function __call($method, $args)
 {
     if (preg_match("/(sort)(?<dir>Ascending|Descending)?(?<by>By)(?<field>[a-zA-Z]*)/", $method, $matches)) {
         if ($matches['dir'] == 'Ascending') {
             $dir = 'ASC';
         } elseif ($matches['dir'] == 'Descending') {
             $dir = 'DESC';
         }
         $this->sortBy(Ntentan::deCamelize($matches['field']), $dir);
     } elseif (preg_match("/(sort)(?<dir>Ascending|Descending)?(?<sub_module>[a-zA-Z]*)(?<sub_by>By)(?<field>[a-zA-Z]*)/", $method, $matches)) {
         if ($matches['dir'] == 'Ascending') {
             $dir = 'ASC';
         } elseif ($matches['dir'] == 'Descending') {
             $dir = 'DESC';
         }
         $this->getParams[$matches['sub_module'] . "_sort"][] = Ntentan::deCamelize($matches['field']) . " {$dir}";
     }
     return $this;
 }
Esempio n. 26
0
 public function out($viewData)
 {
     try {
         if ($this->template === false) {
             $data = null;
         } else {
             $data = TemplateEngine::render($this->template, $viewData, $this);
         }
         if ($this->layout !== false && !Ntentan::isAjax()) {
             $viewData['contents'] = $data;
             $output = TemplateEngine::render($this->layout, $viewData, $this);
         } else {
             $output = $data;
         }
     } catch (Exception $e) {
         print "Error!";
     }
     return $output;
 }
Esempio n. 27
0
 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();
 }
Esempio n. 28
0
 public function __toString()
 {
     $filename = "public/" . $this->getExtension() . "/bundle_{$this->context}." . $this->getExtension();
     if (!file_exists($filename) || Ntentan::$debug === true) {
         foreach ($this->minifiableScripts as $script) {
             if (Ntentan::$debug === true) {
                 $tags .= $this->getTag(Ntentan::getUrl(TemplateEngine::loadAsset($this->getExtension() . "/" . basename($script), $script)));
             } else {
                 $minifiedScript .= file_get_contents($script);
             }
         }
         if (Ntentan::$debug === false) {
             file_put_contents($filename, Minifier::minify($minifiedScript, $this->getMinifier()));
         }
     }
     if (Ntentan::$debug === false) {
         $tags = $this->getTag(Ntentan::getUrl($filename));
     }
     foreach ($this->otherScripts as $script) {
         $tags .= $this->getTag(Ntentan::getUrl($script));
     }
     return $tags;
 }
Esempio n. 29
0
 public function redirectToLogin()
 {
     View::set("login_message", $this->authMethodInstance->getMessage());
     View::set("login_status", false);
     $route = Ntentan::getRouter()->getRoute();
     $loginRoute = $this->parameters->get('login_route', 'login');
     if ($route !== $loginRoute) {
         return Redirect::path($loginRoute);
     }
 }
Esempio n. 30
0
 private static function setupAutoloader()
 {
     spl_autoload_register(function ($class) {
         $prefix = Ntentan::getNamespace() . "\\";
         $baseDir = 'src/';
         $len = strlen($prefix);
         if (strncmp($prefix, $class, $len) !== 0) {
             return;
         }
         $relativeClass = substr($class, $len);
         $file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
         if (file_exists($file)) {
             require_once $file;
         }
     });
 }