Example #1
0
 /**
  * Override isValid()
  *
  * Ensure that validation error messages mask password value.
  *
  * @param  string $value
  * @param  mixed $context
  * @return bool
  */
 public function isValid($value, $context = null)
 {
     foreach ($this->getValidators() as $validator) {
         if ($validator instanceof AbstractValidator) {
             $validator->setValueObscured(true);
         }
     }
     return parent::isValid($value, $context);
 }
Example #2
0
 /**
  * Return label
  *
  * If no label is present, returns the currently set name.
  *
  * If a translator is present, returns the translated label.
  *
  * @return string
  */
 public function getLabel()
 {
     $value = parent::getLabel();
     if (null === $value) {
         $value = $this->getName();
     }
     if (null !== ($translator = $this->getTranslator())) {
         return $translator->translate($value);
     }
     return $value;
 }
Example #3
0
 /**
  * Get the singleton instance of Xhtml.
  * @return  Xhtml
  */
 public static function instance($file = NULL, $config_name = 'default')
 {
     if (self::$_instance === NULL) {
         // Create a new instance
         self::$_instance = new self($file);
         // Set instance of Head class
         self::$head = Head::instance(array(), $config_name);
         // Set defaults from config
         $default = Kohana::config('xhtml.' . $config_name);
         foreach (array('doctype', 'langcode', 'htmlatts', 'body') as $key) {
             if (isset($default[$key]) and !empty($default[$key])) {
                 self::${$key} = $default[$key];
             }
         }
     }
     return self::$_instance;
 }
Example #4
0
 /**
  * Render CSRF token in form
  *
  * @param  \Zend\View\Renderer $view
  * @return string
  */
 public function render(View $view = null)
 {
     $this->initCsrfToken();
     return parent::render($view);
 }
Example #5
0
 /**
  * Is the captcha valid?
  *
  * @param  mixed $value
  * @param  mixed $context
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     $this->getCaptcha()->setName($this->getName());
     $belongsTo = $this->getBelongsTo();
     if (empty($belongsTo) || !is_array($context)) {
         return parent::isValid($value, $context);
     }
     $name = $this->getFullyQualifiedName();
     $root = substr($name, 0, strpos($name, '['));
     $segments = substr($name, strpos($name, '['));
     $segments = ltrim($segments, '[');
     $segments = rtrim($segments, ']');
     $segments = explode('][', $segments);
     array_unshift($segments, $root);
     array_pop($segments);
     $newContext = $context;
     foreach ($segments as $segment) {
         if (array_key_exists($segment, $newContext)) {
             $newContext = $newContext[$segment];
         }
     }
     return parent::isValid($value, $newContext);
 }
Example #6
0
 /**
  * Set value
  *
  * If value matches checked value, sets to that value, and sets the checked
  * flag to true.
  *
  * Any other value causes the unchecked value to be set as the current
  * value, and the checked flag to be set as false.
  *
  *
  * @param  mixed $value
  * @return \Zend\Form\Element\Checkbox
  */
 public function setValue($value)
 {
     if ($value == $this->getCheckedValue()) {
         parent::setValue($value);
         $this->checked = true;
     } else {
         parent::setValue($this->getUncheckedValue());
         $this->checked = false;
     }
     return $this;
 }
Example #7
0
        });
        $div->div(function ($div) use($callback, $toolbarCallback) {
            if (!is_null($toolbarCallback)) {
                $div->div(function ($div) use($toolbarCallback) {
                    $toolbarCallback($div);
                    $div->setClass('toolbar');
                });
            }
            $callback($div);
            $div->setClass('content-box-content');
        });
        $div->setCLass('content-box');
    });
});
Xform::macro('box_panel', function ($title, $callback) {
    $macro = Xhtml::getMacro('box_panel');
    return $macro($title, $callback);
});
function get_form_error_message($form, $name, $format = ':message')
{
    $errors = $form->get_errors();
    $error_message = null;
    if (!is_null($errors) && is_object($errors)) {
        if ($errors->has($name)) {
            $error_message = $errors->first($name, ':message');
        }
    }
    return $error_message;
}
function have_error($form, $name)
{
Example #8
0
 /**
  * Render form element
  * Checks for decorator interface to prevent errors
  *
  * @param  \Zend\View\ViewEngine $view
  * @return string
  */
 public function render(View $view = null)
 {
     $marker = false;
     foreach ($this->getDecorators() as $decorator) {
         if ($decorator instanceof FileDecorator) {
             $marker = true;
         }
     }
     if (!$marker) {
         throw new Exception\RunTimeException('No file decorator found... unable to render file element');
     }
     return parent::render($view);
 }
Example #9
0
File: Multi.php Project: rexmac/zf2
 /**
  * Is the value provided valid?
  *
  * Autoregisters InArray validator if necessary.
  *
  * @param  string $value
  * @param  mixed $context
  * @return bool
  */
 public function isValid($value, $context = null)
 {
     if ($this->registerInArrayValidator()) {
         if (!$this->getValidator('InArray')) {
             $multiOptions = $this->getMultiOptions();
             $options = array();
             foreach ($multiOptions as $opt_value => $opt_label) {
                 // optgroup instead of option label
                 if (is_array($opt_label)) {
                     $options = array_merge($options, array_keys($opt_label));
                 } else {
                     $options[] = $opt_value;
                 }
             }
             $this->addValidator('InArray', true, array($options));
         }
     }
     return parent::isValid($value, $context);
 }
Example #10
0
echo Xhtml::make('div', function ($html) {
    $html->content_panel('Pages', function ($div) {
        $div->div(function ($html) {
            $html->table(function ($table) {
                $table->setClass('table table-striped table-hover');
                $table->thead(function ($thead) {
                    $thead->tr(function ($tr) {
                        $tr->th('Title');
                        $tr->th('author');
                        $tr->th('publish date');
                        $tr->th('created');
                        $tr->th('updated');
                        $tr->th('');
                    });
                });
                $table->tbody(function ($tbody) {
                    $tbody->tr(function ($tr) {
                        $tr->td(function ($td) {
                            $td->span(function ($span) {
                                $span->a(function ($a) {
                                    $a->i()->class('icon-edit');
                                    // $a->setHref('#edit');
                                    $a->setTitle(trans('ravel::form.edit'));
                                    $a->setRootAttr('ng-click', 'edit(item)');
                                });
                            });
                            $td->span()->ng_bind('item.title', 'ng-bind');
                        });
                        $tr->td()->ng_bind('item.author.username', 'ng-bind');
                        $tr->td()->ng_bind('item.publish_date', 'ng-bind');
                        $tr->td()->ng_bind('item.created_at', 'ng-bind');
                        $tr->td()->ng_bind('item.updated_at', 'ng-bind');
                        $tr->td(function ($td) {
                        });
                        $tr->setNgRepeat('item in recordset', 'ng-repeat');
                    });
                });
                $table->tfoot(function ($tfoot) {
                    $tfoot->tr(function ($tr) {
                        $tr->td(function ($td) {
                            // $td->div(function($div)
                            // {
                            //   // $content = "<div class='paginator' paginate-pages='{{pages}}'></div>";
                            //   // $div->putText($content);
                            //   $div->setClass('pagination');
                            //   $div->setRootAttr('paginate-pages',aw('pages'));
                            // });
                            $td->div()->class('paginator pagination')->paginatepages('{{pages}}', 'paginate-pages');
                            $td->setColspan('6');
                        });
                    });
                });
            });
        });
    }, function ($html) {
        $html->button('create')->class('button')->ng_click('create()', 'ng-click');
    });
});
Example #11
0
        foreach ($menulinks as $key => $menu) {
            $ul->li(function ($li) use($menu, $parent) {
                $ParentlinkClass = 'menu-parent';
                if ($menu['active']) {
                    $ParentlinkClass = 'menu-parent current';
                }
                if (isset($menu['children'])) {
                    $li->a($menu['label'])->href($menu['link'])->class($ParentlinkClass);
                    $li->menulinks($menu['children'], false);
                } else {
                    if ($parent) {
                        $li->a($menu['label'])->href($menu['link'])->class($ParentlinkClass);
                    } else {
                        if ($menu['active']) {
                            $li->a($menu['label'])->href($menu['link'])->class('current');
                        } else {
                            $li->a($menu['label'])->href($menu['link']);
                        }
                    }
                }
            });
        }
        if ($parent) {
            $ul->setId('main-nav');
        }
    });
});
echo Xhtml::make('nav', function ($div) use($menu_links) {
    $div->setClass('test');
    $div->menulinks($menu_links);
});
Example #12
0
echo Xhtml::make('div', function ($html) {
    $html->content_panel(trans('ravel::content.post_categories'), function ($div) {
        $div->div(function ($html) {
            $html->table(function ($table) {
                $table->setClass('table table-striped table-hover');
                $table->thead(function ($thead) {
                    $thead->tr(function ($tr) {
                        $tr->th(trans('ravel::content.category_name'));
                        $tr->th(trans('ravel::content.list_layout'));
                        $tr->th(trans('ravel::content.item_layout'));
                        $tr->th(trans('ravel::app.created_at'));
                        $tr->th(trans('ravel::app.updated_at'));
                        $tr->th('');
                    });
                });
                $table->tbody(function ($tbody) {
                    $tbody->tr(function ($tr) {
                        $tr->td(function ($td) {
                            $td->span(function ($span) {
                                $span->a(function ($a) {
                                    $a->i()->class('icon-edit');
                                    // $a->setHref('#edit');
                                    $a->setTitle(trans('ravel::form.edit'));
                                    $a->setRootAttr('ng-click', 'edit(item)');
                                });
                            });
                            $td->span()->ng_bind('item.name', 'ng-bind');
                        });
                        $tr->td()->ng_bind('item.list_layout', 'ng-bind');
                        $tr->td()->ng_bind('item.item_layout', 'ng-bind');
                        $tr->td()->ng_bind('item.created_at', 'ng-bind');
                        $tr->td()->ng_bind('item.updated_at', 'ng-bind');
                        $tr->td(function ($td) {
                        });
                        $tr->setNgRepeat('item in recordset', 'ng-repeat');
                    });
                });
                $table->tfoot(function ($tfoot) {
                    $tfoot->tr(function ($tr) {
                        $tr->td(function ($td) {
                            $td->div()->class('paginator pagination')->paginatepages('{{pages}}', 'paginate-pages');
                            $td->setColspan('6');
                        });
                    });
                });
            });
        });
    }, function ($html) {
        $html->button('create')->class('button')->ng_click('create()', 'ng-click');
    });
});
Example #13
0
        foreach ($menulinks as $key => $menu) {
            $ul->li(function ($li) use($menu, $parent) {
                $ParentlinkClass = 'nav-top-item no-submenu';
                if ($menu['active']) {
                    $ParentlinkClass = 'nav-top-item no-submenu current';
                }
                if (isset($menu['children'])) {
                    $li->a($menu['label'])->href($menu['link'])->class($ParentlinkClass);
                    $li->menulinks($menu['children'], false);
                } else {
                    if ($parent) {
                        $li->a($menu['label'])->href($menu['link'])->class($ParentlinkClass);
                    } else {
                        if ($menu['active']) {
                            $li->a($menu['label'])->href($menu['link'])->class('current');
                        } else {
                            $li->a($menu['label'])->href($menu['link']);
                        }
                    }
                }
            });
        }
        if ($parent) {
            $ul->setId('main-nav');
        }
    });
});
echo Xhtml::make('nav', function ($div) use($menu_links) {
    $div->setClass('menu-main-menu-container');
    $div->menulinks($menu_links);
});
Example #14
0
 /**
  * Returns the rendered head tag
  * @param boolean echo result
  * @return string
  */
 public function render($output = false)
 {
     $close_single = Xhtml::instance()->is_xhtml ? ' />' : '>';
     $html = '<head>';
     $html .= '<title>' . $this->title . '</title>';
     foreach ($this->meta_extra as $key => $value) {
         $html .= '<meta' . Html::attributes(array('http-equiv' => $key, 'content' => $value)) . $close_single;
     }
     foreach ($this->metas as $key => $value) {
         $html .= '<meta' . Html::attributes(array('name' => $key, 'content' => $value)) . $close_single;
     }
     foreach ($this->links as $value) {
         $html .= '<link' . Html::attributes($value) . $close_single;
     }
     // styles
     if (Kohana::config('xhtml.cache_styles')) {
         $html .= Html::style($this->cached_styles);
     } else {
         foreach ($this->styles as $value) {
             $style_file = NULL;
             $style_atts = array();
             $style_cond = NULL;
             if (is_string($value)) {
                 $style_file = $value;
             } elseif (is_array($value)) {
                 if (isset($value['file'])) {
                     $style_file = $value['file'];
                     unset($value['file']);
                 }
                 if (isset($value['condition'])) {
                     $style_cond = $value['condition'];
                     unset($value['condition']);
                 }
                 $style_atts = $value;
             }
             if ($style_file) {
                 if ($style_cond) {
                     $html .= '<!--[if ' . $style_cond . ']>';
                 }
                 $html .= Html::style($style_file, $style_atts);
                 if ($style_cond) {
                     $html .= '<![endif]-->';
                 }
             }
         }
     }
     // scripts
     if (Kohana::config('xhtml.cache_scripts')) {
         $html .= Html::script($this->cached_scripts);
     } else {
         foreach ($this->scripts as $file) {
             $html .= Html::script($file);
         }
         foreach ($this->codes as $code) {
             $html .= '<script' . Html::attributes(array('type' => 'text/javascript')) . '>//<![CDATA[' . "\n" . $code . "\n" . '//]]></script>';
         }
     }
     $html .= '</head>';
     if ($output) {
         echo $html;
     }
     return $html;
 }
Example #15
0
echo Xhtml::make('div', function ($html) {
    $html->content_panel('Users', function ($div) {
        $div->div(function ($html) {
            $html->table(function ($table) {
                $table->thead(function ($thead) {
                    $thead->tr(function ($tr) {
                        $tr->th('username');
                        $tr->th('email');
                        $tr->th('usergroup');
                        $tr->th('status');
                        $tr->th('created');
                        $tr->th('updated');
                        $tr->th('');
                    });
                });
                $table->tbody(function ($tbody) {
                    $tbody->tr(function ($tr) {
                        $tr->td()->ng_bind('item.username', 'ng-bind');
                        $tr->td()->ng_bind('item.email', 'ng-bind');
                        $tr->td()->ng_bind('item.usergroup.group', 'ng-bind');
                        $tr->td(function ($td) {
                            $td->span(showActivated())->ng_show('item.activated', 'ng-show');
                            $td->span(showDeactivated())->ng_hide('item.activated', 'ng-hide');
                        });
                        $tr->td()->ng_bind('item.created_at', 'ng-bind');
                        $tr->td()->ng_bind('item.updated_at', 'ng-bind');
                        $tr->td();
                        $tr->setNgRepeat('item in recordset', 'ng-repeat');
                    });
                });
                $table->tfoot(function ($tfoot) {
                    $tfoot->tr(function ($tr) {
                        $tr->td(function ($td) {
                            $td->div(function ($div) {
                                $content = '<a href="#" title="First Page">&laquo; First</a><a href="#" title="Previous Page">&laquo; Previous</a>
                      <a href="#" class="number" title="1">1</a>
                      <a href="#" class="number" title="2">2</a>
                      <a href="#" class="number current" title="3">3</a>
                      <a href="#" class="number" title="4">4</a>
                      <a href="#" title="Next Page">Next &raquo;</a><a href="#" title="Last Page">Last &raquo;</a>';
                                $div->putText($content);
                                $div->setClass('pagination');
                            });
                            $td->setColspan('6');
                        });
                    });
                });
            });
        });
    }, function ($html) {
        $html->button('create')->class('button')->ng_click('create()', 'ng-click');
    });
});