Exemplo n.º 1
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);
 }
Exemplo n.º 2
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';
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
     }
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * Write a header to redirect the request to a new location. In cases where
  * a redirect parameter exists in the request, the $url parameter of this
  * method is totally ignored.
  *
  * @param string $url The url to redirect to. This could be a full URL or a
  *                    route to an Ntentan controller.
  * @param unknown_type $absolute
  */
 public static function redirect($url, $absolute = false)
 {
     $url = isset($_GET["redirect"]) ? $_GET["redirect"] : $url;
     $url = $absolute === true ? $url : Ntentan::getUrl($url);
     header("Location: {$url} ");
 }
Exemplo n.º 7
0
 public function confirm($operation, $id)
 {
     $this->setupOperations();
     $this->view->template = "confirm.tpl.php";
     $item = $this->getModel()->getFirstWithId($id);
     $this->set("item", (string) $item);
     $this->set("message", $this->operations[$operation]["confirm_message"]);
     $this->set("heading_level", $this->headingLevel);
     $route = $this->consoleMode ? $this->consoleModeRoute : $this->controller->route;
     $this->set("positive_route", Ntentan::getUrl("{$route}/{$operation}/{$id}"));
     $this->set("negative_route", Ntentan::getUrl($route));
 }
Exemplo n.º 8
0
/**
 * A shortcut wrapper function around the Ntentan::getUrl method
 * @param $url
 */
function u($url)
{
    return Ntentan::getUrl($url);
}
Exemplo n.º 9
0
 public static function loadAssetWithUrl($asset, $copyFrom = null)
 {
     return Ntentan::getUrl(self::loadAsset($asset, $copyFrom));
 }
Exemplo n.º 10
0
 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);
 }