Example #1
0
 /**
  * As found on php.net posted by: BigueNique at yahoo dot ca 20-Apr-2010 07:15
  * A safe empowered glob().
  *
  * Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR
  * Additional flags: GlobFlags::GLOB_NODIR, GlobFlags::GLOB_PATH, GlobFlags::GLOB_NODOTS, GlobFlags::GLOB_RECURSE (not original glob() flags, defined here)
  *
  * @author BigueNique AT yahoo DOT ca
  *
  * @param string $pattern
  * @param int    $flags
  *
  * @return array|bool
  */
 public static function glob($pattern, $flags = 0)
 {
     $_split = explode('/', str_replace('\\', '/', $pattern));
     $_mask = array_pop($_split);
     $_path = implode('/', $_split);
     $_glob = false;
     if (false !== ($_directory = opendir($_path))) {
         $_glob = array();
         while (false !== ($_file = readdir($_directory))) {
             //	Recurse directories
             if ($flags & GlobFlags::GLOB_RECURSE && is_dir($_file) && !in_array($_file, array('.', '..'))) {
                 $_glob = array_merge($_glob, Scalar::array_prepend(self::glob($_path . '/' . $_file . '/' . $_mask, $flags), $flags & GlobFlags::GLOB_PATH ? '' : $_file . '/'));
             }
             // Match file mask
             if (fnmatch($_mask, $_file)) {
                 if ((!($flags & GLOB_ONLYDIR) || is_dir("{$_path}/{$_file}")) && (!($flags & GlobFlags::GLOB_NODIR) || !is_dir($_path . '/' . $_file)) && (!($flags & GlobFlags::GLOB_NODOTS) || !in_array($_file, array('.', '..')))) {
                     $_glob[] = ($flags & GlobFlags::GLOB_PATH ? $_path . '/' : '') . $_file . ($flags & GLOB_MARK ? '/' : '');
                 }
             }
         }
         closedir($_directory);
         if (!($flags & GLOB_NOSORT)) {
             sort($_glob);
         }
     }
     return $_glob;
 }
Example #2
0
    /**
     * @param string $type
     * @param array  $attributes
     * @param string $contents
     *
     * @return string
     */
    public function field($type, array $attributes = array(), $contents = null)
    {
        $_html = null;
        $_type = strtolower(trim($type));
        $_wrapInput = Scalar::in($_type, 'checkbox', 'radio');
        $_labelEnd = null;
        $_labelAttributes = array();
        $_id = Option::get($attributes, 'id', Option::get($attributes, 'name'));
        $_inputAppend = Option::get($attributes, 'append', null, true);
        $_inputPrepend = Option::get($attributes, 'prepend', null, true);
        $this->cleanNames($attributes);
        $_label = Option::get($attributes, 'label', null, true);
        if (is_array($_label)) {
            $_labelAttributes = Option::get($_label, 'attributes', array());
            $_labelText = Option::get($_label, 'value', array());
        } else {
            $_labelText = $_label;
        }
        //	Add .control-label for the class to labels
        if (static::Horizontal == $this->_formType) {
            if (!isset($_labelAttributes['class'])) {
                $_labelAttributes['class'] = null;
            }
            $_labelAttributes['class'] = static::addValue($_labelAttributes['class'], $_wrapInput ? $_type : 'control-label');
        }
        $_label = static::tag('label', $_labelAttributes, $_wrapInput ? null : $_labelText, !$_wrapInput);
        $_labelEnd = $_wrapInput ? $_label . '</label>' : null;
        if (null !== ($_hint = Option::get($attributes, 'hint', null, true))) {
            $_hint = static::tag('span', array('class' => 'help-block'), $_hint);
        }
        $_blockStart = $_blockEnd = null;
        $_inputStart = $_inputEnd = null;
        $_inputWrap = trim(($_inputAppend ? 'input-append' : null) . ' ' . ($_inputPrepend ? 'input-prepend' : null));
        switch ($this->_formType) {
            case static::Horizontal:
                $_blockStart = static::tag('div', array('class' => 'control-group'), null, false);
                $_inputStart = static::tag('div', array('class' => 'controls'), null, false);
                $_inputEnd = $_blockEnd = '</div>';
                if (!$_wrapInput) {
                    $_blockStart .= $_label . $_labelEnd;
                    $_label = $_labelEnd = null;
                }
                break;
            case static::Search:
                $_class = Option::get($attributes, 'class');
                $attributes['class'] = static::addValue($_class, 'search-query');
                break;
        }
        if (null === $contents && !empty($this->_formData)) {
            $contents = Option::get($this->_formData, $_id);
        }
        //	X-editable?
        if (false !== stripos(Option::get($attributes, 'class'), 'x-editable')) {
            //	Replace contents with the x-editable link...
            $contents = static::tag('a', array('class' => 'x-editable', 'href' => '#', 'id' => $_id, 'data-type' => $_type, 'data-pk' => Option::get($this->_attributes, 'x-editable-pk', Option::get($this->_formData, 'id')), 'data-url' => Option::get($this->_attributes, 'x-editable-url', Option::get($attributes, 'x-editable-url', null, true)), 'data-original-title' => $_labelText, 'data-inputclass' => Option::get($attributes, 'class', 'input-xlarge')), $contents);
            //	New type of just HTML...
            $_type = 'html';
        }
        switch ($_type) {
            case 'html':
                $_input = $contents;
                break;
            case 'textarea':
                $attributes['class'] = static::addValue(Option::get($attributes, 'class'), 'input-xxlarge');
                $_input = static::wrap($_type, $contents, $attributes);
                break;
            case 'select':
                if (!isset($attributes['value'])) {
                    $attributes['value'] = $contents;
                }
                $_input = static::select(Option::get($attributes, 'data', array(), true), $attributes);
                break;
            case 'button':
                $_input = static::button($attributes, $contents);
                break;
            default:
                $_input = $this->_handleUnknownField($_type, $attributes, $contents);
                break;
        }
        if (!empty($_inputWrap)) {
            $_input = '<div class="' . $_inputWrap . '">' . $_inputPrepend . $_input . $_inputAppend . '</div>';
        }
        $_html = <<<HTML
{$_blockStart}{$_inputStart}{$_label}{$_input}{$_labelEnd}{$_hint}{$_inputEnd}{$_blockEnd}
HTML;
        if (false !== $this->_builderMode) {
            $this->_contents .= $_html;
        }
        return $_html;
    }