Наследование: extends App_CLI
Пример #1
0
 public function addItem($title, $action = null, $class = 'Menu_Advanced_Item')
 {
     $i = $this->add($class, null, null, array_merge($this->defaultTemplate(), array('Item')));
     /** @type Menu_Advanced_Item $i */
     if (is_array($title)) {
         if ($title['badge']) {
             /** @type View $v */
             $v = $i->add('View', null, 'Badge');
             $v->setElement('span')->addClass('atk-label')->set($title['badge']);
             unset($title['badge']);
         }
     }
     if ($action) {
         if (is_string($action) || is_array($action) || $action instanceof URL) {
             $i->template->set('url', $url = $this->app->url($action));
             if ($url->isCurrent($this->highlight_subpages)) {
                 $i->addClass('active');
             }
         } else {
             $i->on('click', $action);
         }
     }
     $i->set($title);
     return $i;
 }
Пример #2
0
Файл: jUI.php Проект: atk4/atk4
 /**
  * Adds stylesheet
  *
  * @param string $file
  * @param string $ext
  * @param bool $template
  *
  * @return $this
  */
 public function addStylesheet($file, $ext = '.css', $template = false)
 {
     $url = $this->app->locateURL('css', $file . $ext);
     if (!$this->atk4_initialised || $template) {
         return parent::addStylesheet($file, $ext);
     }
     parent::addOnReady('$.atk4.includeCSS("' . $url . '")');
 }
Пример #3
0
 public function setSource($model, $data)
 {
     $this->app->initializeSession();
     if ($data === UNDEFINED || $data === null) {
         $data = '-';
     }
     if (!$_SESSION['ctl_data'][$data]) {
         $_SESSION['ctl_data'][$data] = array();
     }
     if (!$_SESSION['ctl_data'][$data][$model->table]) {
         $_SESSION['ctl_data'][$data][$model->table] = array();
     }
     $model->_table[$this->short_name] =& $_SESSION['ctl_data'][$data][$model->table];
 }
Пример #4
0
 public function isCurrent($href)
 {
     // returns true if item being added is current
     if (!is_object($href)) {
         $href = str_replace('/', '_', $href);
     }
     return $href == $this->app->page || $href == ';' . $this->app->page || $href . $this->app->getConfig('url_postfix', '') == $this->app->page || (string) $href == (string) $this->app->url();
 }
Пример #5
0
 /**
  * Reload object.
  *
  * You can bind this to custom event and trigger it if object is not
  * directly accessible.
  * If interval is given, then object will periodically reload itself.
  *
  * @param array        $arg
  * @param jQuery_Chain $fn
  * @param string       $url
  * @param int          $interval Interval in milisec. how often to reload object
  *
  * @return $this
  */
 public function reload($arg = array(), $fn = null, $url = null, $interval = null)
 {
     if ($fn && $fn instanceof self) {
         $fn->_enclose();
     }
     $obj = $this->owner;
     if ($url === null) {
         $url = $this->app->url(null, array('cut_object' => $obj->name));
     }
     return $this->univ()->_fn('reload', array($url, $arg, $fn, $interval));
 }
Пример #6
0
Файл: Web.php Проект: atk4/atk4
 /**
  * Default handling of Content page. To be replaced by App_Frontend
  * This function initializes content. Content is page-dependant.
  */
 public function layout_Content()
 {
     $page = str_replace('/', '_', $this->page);
     if (method_exists($this, $pagefunc = 'page_' . $page)) {
         $p = $this->add('Page', $this->page, 'Content');
         $this->{$pagefunc}($p);
     } else {
         $this->app->locate('page', str_replace('_', '/', $this->page) . '.php');
         $this->add('page_' . $page, $page, 'Content');
         //throw new BaseException("No such page: ".$this->page);
     }
 }
Пример #7
0
 public function addMenuItem($page, $label = null)
 {
     if (!$label) {
         $label = ucwords(str_replace('_', ' ', $page));
     }
     /** @type View $li */
     $li = $this->add('View');
     $li->setElement('li');
     /** @type View $a */
     $a = $li->add('View');
     $a->setElement('a')->set($label);
     if ($page instanceof jQuery_Chain) {
         $li->js('click', $page);
         return $li;
     }
     $a->setAttr('href', $this->app->url($page));
     if ($this->isCurrent($page) && $this->current_menu_class) {
         $li->addClass($this->current_menu_class);
     }
     return $li;
 }
Пример #8
0
 function init()
 {
     parent::init();
     $this->page = null;
     $this->saved_base_path = $this->pm->base_path;
     $this->pm->base_path .= basename($_SERVER["SCRIPT_NAME"]);
     $this->add('jUI');
     $this->template->trySet('version', 'Web Software Installer');
     $this->stickyGET('step');
     $this->s_first = $this->s_last = $this->s_current = $this->s_prev = $this->s_next = null;
     $this->s_cnt = 0;
     $this->initInstaller();
 }
Пример #9
0
 /**
  * Adds static stylesheet
  *
  * @param string $file
  * @param string $ext
  * @param string $locate
  *
  * @return $this
  */
 public function addStaticStylesheet($file, $ext = '.css', $locate = 'css')
 {
     //$file=$this->app->locateURL('css',$file.$ext);
     if (@$this->included[$locate . '-' . $file . $ext]++) {
         return;
     }
     if (strpos($file, 'http') !== 0 && $file[0] != '/') {
         $url = $this->app->locateURL($locate, $file . $ext);
     } else {
         $url = $file;
     }
     $this->app->template->appendHTML('js_include', '<link type="text/css" href="' . $url . '" rel="stylesheet" />' . "\n");
     return $this;
 }
Пример #10
0
 /**
  * @todo Description
  */
 public function initInstaller()
 {
     //$m = $this->layout->add('Menu');
     foreach (get_class_methods($this) as $method) {
         list(, $method) = explode('step_', $method);
         if (!$method) {
             continue;
         }
         if (is_null($this->s_first)) {
             $this->s_first = $method;
         }
         $this->s_last = $method;
         /*$u = */
         $this->url(null, array('step' => $method));
         $this->page = $this->pm->base_path . '?step=' . $_GET['step'];
         // $m->addMenuItem($u, ucwords(strtr($method, '_', ' ')));
         $this->page = null;
         if (is_null($this->s_current)) {
             ++$this->s_cnt;
             if ($method == $_GET['step']) {
                 $this->s_current = $method;
                 $this->s_title = ucwords(strtr($method, '_', ' '));
             } else {
                 $this->s_prev = $method;
             }
         } else {
             if (is_null($this->s_next)) {
                 $this->s_next = $method;
             }
         }
     }
     if (!$_GET['step']) {
         if ($this->show_intro) {
             return $this->showIntro($this->makePage('init'));
         }
         $this->app->redirect($this->stepURL('first'));
     }
     $this->initStep($this->s_current);
 }
Пример #11
0
 public function save()
 {
     // TODO: start transaction here
     try {
         if ($this->hook('update')) {
             return $this;
         }
         if (!($m = $this->getModel())) {
             throw new BaseException("Can't save, model not specified");
         }
         if (!is_null($this->get_field)) {
             $this->app->stickyForget($this->get_field);
         }
         foreach ($this->elements as $short_name => $element) {
             if ($element instanceof Form_Field) {
                 if (!$element->no_save) {
                     //if(is_null($element->get()))
                     $m->set($short_name, $element->get());
                 }
             }
         }
         $m->save();
     } catch (BaseException $e) {
         if ($e instanceof Exception_ValidityCheck) {
             $f = $e->getField();
             if ($f && is_string($f) && ($fld = $this->hasElement($f))) {
                 /** @type Form_Field $fld */
                 $fld->displayFieldError($e->getMessage());
             } else {
                 $this->js()->univ()->alert($e->getMessage())->execute();
             }
         }
         if ($e instanceof Exception_ForUser) {
             $this->js()->univ()->alert($e->getMessage())->execute();
         }
         throw $e;
     }
 }
Пример #12
0
Файл: CRUD.php Проект: atk4/atk4
 /**
  * Called after on post-init hook when form is submitted.
  *
  * @param Form $form Form which was submitted
  */
 protected function formSubmit($form)
 {
     try {
         $form->update();
         $self = $this;
         $this->app->addHook('pre-render', function () use($self) {
             $self->formSubmitSuccess()->execute();
         });
     } catch (Exception_ValidityCheck $e) {
         $form->displayError($e->getField(), $e->getMessage());
     }
 }
Пример #13
0
 /**
  * Detect server environment and tries to guess absolute and relative
  * URLs to your application.
  *
  * See docs: doc/application/routing/parsing
  */
 public function parseRequestedURL()
 {
     // This is the re-constructions of teh proper URL.
     // 1. Schema
     $url = $this->app->getConfig('atk/base_url', null);
     if (is_null($url)) {
         // Detect it
         $url = 'http';
         $https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443;
         if ($https) {
             $url .= 's';
         }
         // 2. Continue building. We are adding hostname next and port.
         $url .= '://' . $_SERVER['SERVER_NAME'];
         //if($_SERVER["SERVER_PORT"]!="80")$url .= ":".$_SERVER['SERVER_PORT'];
         if ($_SERVER['SERVER_PORT'] == '80' && !$https || $_SERVER['SERVER_PORT'] == '443' && $https) {
         } else {
             $url .= ':' . $_SERVER['SERVER_PORT'];
         }
     }
     // We have now arrived at base_url as defined
     $this->base_url = $url;
     // 3. Next we need a base_part of our URL. There are many different
     // variables and approaches we tried it, REDIRECT_URL_ROOT, REDIRECT_URL,
     // etc, however most reliable is $this->unix_dirname(SCRIPT_NAME)
     $path = $this->unix_dirname($_SERVER['SCRIPT_NAME']);
     if (substr($path, -1) != '/') {
         $path .= '/';
     }
     // We have now arrived at base_path as defined
     $this->base_path = $path;
     // 4. We now look at RequestURI and extract base_path from the beginning
     if (isset($_GET['page'])) {
         $page = $_GET['page'];
         $this->page = $page;
     } else {
         $request_uri = $this->getRequestURI();
         if (strpos($request_uri, $path) !== 0) {
             throw $this->exception('URL matching problem')->addMoreInfo('RequestURI', $request_uri)->addMoreInfo('BasePath', $path);
         }
         $page = substr($request_uri, strlen($path));
         if (!$page) {
             $page = 'index';
         }
         // Preserve actual page
         $this->page = $page;
         // Remove postfix from page if any
         $page = preg_replace('/\\..*$/', '', $page);
         $page = preg_replace('/\\/$/', '', $page);
         $page = str_replace('/', '_', $page);
         if (substr($page, -1) == '_') {
             $page = substr($page, 0, -1);
         }
     }
     if (strpos($page, '.') !== false) {
         throw $this->exception('Page may not contain periods (.)')->addMoreInfo('page', $page);
     }
     // We have now arrived at the page as per specification.
     $this->app->page = str_replace('/', '_', $page);
     $this->template_filename = $this->app->page;
     if (substr($this->template_filename, -1) == '/') {
         $this->template_filename .= 'index';
     }
 }
Пример #14
0
 public function init()
 {
     parent::init();
     $this->app->router = $this;
     $this->app->addHook('buildURL', array($this, 'buildURL'));
 }
Пример #15
0
 public function isCurrent($href)
 {
     // returns true if item being added is current
     $href = str_replace('/', '_', $href);
     return $href == $this->app->page || $href == ';' . $this->app->page || $href . $this->app->getConfig('url_postfix', '') == $this->app->page;
 }
Пример #16
0
 /**
  * @todo Description
  *
  * @param Exception $e
  */
 public function caughtException($e)
 {
     if ($e instanceof Exception_Migration) {
         try {
             // The mesage is for user. Let's display it nicely.
             $this->app->pathfinder->addLocation(array('public' => '.'))->setCDN('http://www.agiletoolkit.org/');
             /** @type Layout_Basic $l */
             $l = $this->app->add('Layout_Basic', null, null, array('layout/installer'));
             /** @type View $i */
             $i = $l->add('View');
             $i->addClass('atk-align-center');
             /** @type H1 $h */
             $h = $i->add('H1');
             $h->set($e->getMessage());
             if ($e instanceof Exception_Migration) {
                 /** @type P $p */
                 $p = $i->add('P');
                 $p->set('Hello and welcome to Agile Toolkit 4.3. ' . 'Your project may require some minor tweaks before you can use 4.3.');
             }
             /** @type Button $b */
             $b = $i->add('Button');
             $b->addClass('atk-swatch-green')->set(array('Migration Guide', 'icon' => 'book'))->link('https://github.com/atk4/docs/blob/master/articles/migration42/index.md');
             if ($this->app->template && $this->app->template->hasTag('Layout')) {
                 $t = $this->app->template;
             } else {
                 /** @type GiTemplate $t */
                 $t = $this->add('GiTemplate');
                 $t->loadTemplate('html');
             }
             $t->setHTML('Layout', $l->getHTML());
             $t->trySet('css', 'http://css.agiletoolkit.org/framework/css/installer.css');
             echo $t->render();
             exit;
         } catch (BaseException $e) {
             echo 'here';
             $this->app->add('Logger');
             return parent::caughtException($e);
         }
     }
     return parent::caughtException($e);
 }
Пример #17
0
 /**
  * Precaches template chunks.
  */
 public function precacheTemplate()
 {
     // Extract template chunks from grid template
     // header
     $header = $this->template->cloneRegion('header');
     $header_col = $header->cloneRegion('col');
     $header_sort = $header_col->cloneRegion('sort');
     $header->del('cols');
     // data row and column
     $row = $this->row_t;
     $col = $row->cloneRegion('col');
     $row->setHTML('row_id', '{$id}');
     $row->trySetHTML('odd_even', '{$odd_even}');
     $row->del('cols');
     // totals row and column
     if ($t_row = $this->totals_t) {
         $t_col = $t_row->cloneRegion('col');
         $t_row->del('cols');
     }
     // Add requested columns to row templates
     foreach ($this->columns as $name => $column) {
         // header row
         $header_col->set('descr', $column['descr'])->trySet('type', $column['type']);
         // sorting
         // TODO: rewrite this (and move into Advanced)
         if (isset($column['sortable'])) {
             $s = $column['sortable'];
             $header_sort->trySet('order', $s[0])->trySet('sorticon', $this->sort_icons[$s[0]]);
             $header_col->trySet('sortid', $sel = $this->name . '_sort_' . $name)->setHTML('sort', $header_sort->render());
             $this->js('click', $this->js()->reload(array($this->name . '_sort' => $s[1])))->_selector('#' . $sel);
         } else {
             $header_col->del('sort')->tryDel('sortid')->tryDel('sort_del');
         }
         // add thparams for header columns
         if ($column['thparam']) {
             $header_col->trySetHTML('thparam', $column['thparam']);
         } else {
             $header_col->tryDel('thparam');
         }
         $header->appendHTML('cols', $header_col->render());
         // data row
         $col->del('content')->setHTML('content', '{$' . $name . '}')->setHTML('tdparam', '{tdparam_' . $name . '}style="white-space:nowrap"{/}');
         $row->appendHTML('cols', $col->render());
         // totals row
         if (isset($t_row) && isset($t_col)) {
             $t_col->del('content')->setHTML('content', '{$' . $name . '}')->trySetHTML('tdparam', '{tdparam_' . $name . '}style="white-space:nowrap"{/}');
             $t_row->appendHTML('cols', $t_col->render());
         }
     }
     // Generate templates from rendered strings
     // header
     $this->template->setHTML('header', $this->show_header ? $header->render() : '');
     // data row
     $this->row_t = $this->app->add('GiTemplate');
     /** @type GiTemplate $this->row_t */
     $this->row_t->loadTemplateFromString($row->render());
     // totals row
     if (isset($t_row) && $this->totals_t) {
         $this->totals_t = $this->app->add('GiTemplate');
         /** @type GiTemplate $this->totals_t */
         $this->totals_t->loadTemplateFromString($t_row->render());
     }
 }
Пример #18
0
 public function getTag($tag, $attr = null, $value = null)
 {
     /**
      * Draw HTML attribute with supplied attributes.
      *
      * Short description how this getTag may be used:
      *
      * Use get tag to build HTML tag.
      * echo getTag('img',array('src'=>'foo.gif','border'=>0);
      *
      * The unobvius advantage of this function is ability to merge
      * attribute arrays. For example, if you have function, which
      * must display img tag, you may add optional $attr argument
      * to this function.
      *
      * function drawImage($src,$attr=array()){
      *     echo getTag('img',array_merge(array('src'=>$src),$attr));
      * }
      *
      * so calling drawImage('foo.gif') will echo: <img src="foo.gif">
      *
      * The benefit from such a function shows up when you use 2nd argument:
      *
      * 1. adding additional attributes
      * drawImage('foo.gif',array('border'=>0'));
      * --> <img src="foo.gif" border="0">
      * (NOTE: you can even have attr templates!)
      *
      * 2. adding no-value attributes, such as nowrap:
      * getTag('td',arary('nowrap'=>true));
      * --> <td nowrap>
      *
      * 3. disabling some attributes.
      * drawImage('foo.gif',array('src'=>false));
      * --> <img>
      *
      * 4. re-defining attributes
      * drawImage('foo.gif',array('src'=>'123'));
      * --> <img src="123">
      *
      * 5. or you even can re-define tag itself
      * drawImage('foo.gif',array(
      *                      ''=>'input',
      *                      'type'=>'picture'));
      * --> <input type="picture" src="foo.gif">
      *
      * 6. xml-valid tags without closing tag
      * getTag('img/',array('src'=>'foo.gif'));
      * --> <img src=>"foo.gif"/>
      *
      * 7. closing tags
      * getTag('/td');
      * --> </td>
      *
      * 8. using $value will add $value after tag followed by closing tag
      * getTag('a',array('href'=>'foo.html'),'click here');
      * --> <a href="foo.html">click here</a>
      *
      * 9. you may not skip attribute argument.
      * getTag('b','text in bold');
      * --> <b>text in bold</b>
      *
      * 10. nesting
      * getTag('a',array('href'=>'foo.html'),getTag('b','click here'));
      * --> <a href="foo.html"><b>click here</b></a>
      */
     if (is_string($attr)) {
         $value = $attr;
         $attr = null;
     }
     if (!$attr) {
         return "<{$tag}>" . ($value ? $value . "</{$tag}>" : '');
     }
     $tmp = array();
     if (substr($tag, -1) == '/') {
         $tag = substr($tag, 0, -1);
         $postfix = '/';
     } else {
         $postfix = '';
     }
     foreach ($attr as $key => $val) {
         if ($val === false) {
             continue;
         }
         if ($val === true) {
             $tmp[] = "{$key}";
         } elseif ($key === '') {
             $tag = $val;
         } else {
             $tmp[] = "{$key}=\"" . $this->app->encodeHtmlChars($val) . '"';
         }
     }
     return "<{$tag} " . implode(' ', $tmp) . $postfix . '>' . ($value ? $value . "</{$tag}>" : '');
 }