示例#1
0
 public function route($route = null)
 {
     $ro = null !== $route ? new $route() : new RouteApp();
     $instance = '\\olifant\\route\\RouteBase';
     if (false === is_subclass_of($ro, $instance)) {
         throw new AppException('Class ' . get_class($ro) . ' is not instanceof ' . $instance);
     }
     $ro->route();
     $ctx = $ro->getContext();
     $map = $ro->getMap();
     $uri = $this->request->getUri();
     $call = null;
     foreach ($map as $mapkey => $target) {
         $cleaned = $this->cleanPath($mapkey);
         if ($this->compare($cleaned, $uri) or null !== $route and $cleaned === '/') {
             list($call, $options) = $target;
             if ($options) {
                 if (isset($options['method'])) {
                     $methods = is_array($options['method']) ? $options['method'] : array($options['method']);
                     if (false === in_array(strtolower($_SERVER['REQUEST_METHOD']), $methods)) {
                         $call = null;
                         break;
                     }
                 }
                 if (isset($options['secure'])) {
                     if (true === $options['secure']) {
                         if (false == RequestBuilder::isHTTPS()) {
                             $call = null;
                             break;
                         }
                     }
                 }
             }
             $this->request->setMapKey($mapkey);
             $this->request->excludeSubPath($cleaned);
             break;
         }
     }
     if (null === $call) {
         return (object) array('controller' => '\\olifant\\controller\\ControllerError', 'action' => 'notFound404');
     }
     if (is_string($call) and false !== strpos($call, '::')) {
         list($controller, $action) = explode('::', $call);
         return (object) array('controller' => '\\olifant\\controller\\' . $controller, 'action' => $action);
     }
     if (is_string($call) and 0 === strpos(strtolower($call), 'route')) {
         return $this->route('\\olifant\\route\\' . $call);
     }
     if (\is_closure($call)) {
         return (object) array('controller' => '\\olifant\\controller\\ControllerClosure', 'action' => \olifant\controller\ControllerClosure::bind($call));
     }
     if (null !== $ctx) {
         return (object) array('controller' => '\\olifant\\controller\\' . $ctx, 'action' => $call);
     }
     throw new AppException('Unsupported callback type');
 }
示例#2
0
文件: form.php 项目: ahmed555/Cupcake
 public function form_for($name, $object = null, $url = "", $options = null, $block = null)
 {
     if (is_closure($options)) {
         $block = $options;
         $options = array();
     }
     $this->object = $object;
     $this->object_name = $name;
     echo form_tag($url, array_merge($options, array("name" => $name)));
     echo $block($this);
     echo "</form>";
 }
示例#3
0
 public static function bind($closure, $uniqfn = null)
 {
     if (false == \is_closure($closure)) {
         throw new AppException('Invalid closure');
     }
     if (null === $uniqfn) {
         $uniqfn = 'closureMethod' . ++self::$index;
     } else {
         if (array_key_exists($uniqfn, self::$fn)) {
             throw new AppException('Method ' . $uniqfn . ' already exists in ' . __CLASS__);
         }
     }
     self::$fn[$uniqfn] = $closure;
     return $uniqfn;
 }
示例#4
0
 public function __construct($IsRoute, $Function = null)
 {
     global $p;
     if ($IsRoute) {
         if (is_string($Function)) {
             $this->Result = $this->{$Function}($p);
         }
         if (is_closure($Function)) {
             $this->Result = $Function($p);
         }
         if (isset($this->Result) && !is_string($this->Result)) {
             $this->CSS .= $this->Result->CSS;
             $this->JS .= $this->Result->JS;
         }
     }
 }
示例#5
0
文件: Route.php 项目: jankal/mvc
 /**
  * Map routes based on their request type
  * @param String          $name
  * @param string          $pattern
  * @param string|\Closure $callable
  * @param bool            $isRegEx
  * @return \Route\Path
  */
 public static function &add($name, $pattern, $callable, $isRegEx = false)
 {
     $name = strtoupper($name);
     $action = $callable;
     if (is_closure($action)) {
         $closure = true;
     } else {
         $closure = false;
         $action = self::getArray($action);
     }
     if (!$isRegEx) {
         $pattern = self::makeRegEx($pattern);
     }
     self::$routes[$name][$pattern] = new \Route\Path($action, $name, $closure);
     return self::$routes[$name][$pattern];
 }
示例#6
0
文件: co.php 项目: netgusto/co
 public static function run(&$genfunc)
 {
     return Promise(function ($resolve, $reject) use(&$genfunc) {
         if (is_closure($genfunc)) {
             $gen = $genfunc();
         }
         if (!is_generator($gen)) {
             return $resolve($gen);
         }
         $ret = $gen->current();
         $next = function ($ret) use(&$gen, &$resolve, &$reject, &$next) {
             if (is_promise($ret)) {
                 $ret->then(function ($resolvedValue) use(&$gen, &$resolve, &$reject, &$next) {
                     try {
                         $tempret = $gen->send($resolvedValue);
                     } catch (\Exception $e) {
                         return $reject($e);
                     }
                     if ($gen->valid()) {
                         return $next($tempret);
                     } else {
                         return $resolve($resolvedValue);
                     }
                 });
             } else {
                 $tempret = $gen->send($ret);
                 if ($gen->valid()) {
                     return $next($tempret);
                 } else {
                     return $resolve($ret);
                 }
             }
         };
         return $next($ret);
     });
 }
示例#7
0
文件: CoreTest.php 项目: ejz/core
 public function testIsClosure()
 {
     $closure = function () {
     };
     $this->assertFalse(is_closure('is_closure'));
     $this->assertFalse(is_closure(array($this, 'testIsClosure')));
     $this->assertTrue(is_closure($closure));
 }
示例#8
0
文件: Core.php 项目: VOMVC/VOMVC
/**
 *
 * Merges the second array onto the first array with distinct data for each key.
 * Essentially "replacing" the data at any recursive string from array 2, onto array 1.
 * @param (array) $array1 // To Be Replaced
 * @param (array) $array2 // Replacing With
 */
function array_merge_recursive_distinct($array1, $array2 = null)
{
    /* array_merge_recursive_distinct */
    // Start our '$merged' array as the initial $array1
    $merged = $array1;
    if (is_array($array1)) {
        if (is_array($array2)) {
            // Loop over $array2
            foreach ($array2 as $key => $val) {
                // If $val or $array2[$key] is an array
                if (is_array($array2[$key])) {
                    $merged[$key] = isset($merged[$key]) && is_array($merged[$key]) ? array_merge_recursive_distinct($merged[$key], $array2[$key]) : $array2[$key];
                } else {
                    $merged[$key] = $val;
                }
            }
        }
        if (is_object($array2)) {
            $merged = $array2;
        }
    }
    if (is_bool($array1)) {
        if (is_bool($array2)) {
            $merged = $array2;
        }
    }
    if (is_null($array2)) {
        $merged = $array2;
    }
    if (is_closure($array1) && is_closure($array2)) {
        $merged = $array2;
    }
    return $merged;
}
示例#9
0
 /**
  * Links a route to an action in the routes collection
  *
  * If an existing link matches matches the same compiled pattern then the action is
  * checked for compatibility.  In short, closures are never compatible, strings callables
  * that match are OK, and array callables that match are OK.
  *
  * @access public
  * @param string $base_url The base url for all the routes
  * @param string $route The route key/mapping
  * @param mixed $action The action to execute, callback strings are custom
  * @return void
  * @throws Flourish\ProgrammerException in the case of conflicting routes
  */
 public function link($base_url, $route, $action)
 {
     $base_url = rtrim($base_url, '/');
     $route = ltrim($route, '/');
     list($pattern, $params) = self::compile($base_url . '/' . $route);
     if (isset($this->links[$pattern])) {
         $existing_action = $this->links[$pattern]['action'];
         if (is_string($existing_action)) {
             if (!is_string($action) || $existing_action != $action) {
                 throw new Flourish\ProgrammerException('Cannot add conflicting route %s, conflicting action %s', $route, $action);
             }
         } elseif (is_array($existing_action)) {
             if (!is_array($action) || (object) $existing_action != (object) $action) {
                 throw new Flourish\ProgrammerException('Cannot add conflicting route %s, incompatible object callback', $route);
             }
         } elseif (is_closure($existing_action)) {
             throw new Flourish\ProgrammerException('Cannot add conflicting route %s, action is a closure', $route);
         }
     }
     $this->links[$pattern] = ['base_url' => $base_url, 'action' => $action, 'params' => $params, 'route' => $route];
 }
示例#10
0
function metris_generate_fieldset($callback, $options)
{
    $defaults = array('id' => false, 'type' => 'table', 'title' => false, 'title_type' => 'h5', 'heading' => false, 'row_title_class' => 'width1', 'row_data_class' => '', 'elements' => array(), 'class' => 'tableclass tableclass_form', 'extra_settings' => array(), 'elements_before' => '', 'elements_after' => '');
    $options = array_merge($defaults, $options);
    if (function_exists('hook_filter_var')) {
        $options = hook_filter_var('generate_fieldset_options', $options);
    }
    ob_start();
    ?>

    <div class="box <?php 
    echo isset($options['heading']['responsive']) ? ' box-responsive' : '';
    ?>
">
        <header>
            <?php 
    if ($options['heading']) {
        if (!isset($options['heading']['type']) || $options['heading']['type'] != 'h5') {
            $options['heading']['type'] = 'h5';
        }
        print_heading($options['heading']);
    } else {
        if ($options['title']) {
            ?>
                <<?php 
            echo $options['title_type'];
            ?>
><?php 
            _e($options['title']);
            ?>
</<?php 
            echo $options['title_type'];
            ?>
>
            <?php 
        }
    }
    ?>
        </header>
        <!-- .block -->
        <div class="body">
            <?php 
    echo $options['elements_before'];
    ?>
            <?php 
    if ($options['elements']) {
        ?>
            <table class="<?php 
        echo $options['class'];
        ?>
">
                <tbody>
                <?php 
        foreach ($options['elements'] as $element) {
            if (isset($element['ignore']) && $element['ignore']) {
                continue;
            }
            if (isset($element['field']) && !isset($element['fields'])) {
                $element['fields'] = array($element['field']);
                unset($element['field']);
            }
            ?>
                    <tr>
                        <?php 
            if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) {
                ?>
                            <th colspan="2" style="text-align:center">
                                <?php 
                if (isset($element['message'])) {
                    ?>
                                    <?php 
                    echo $element['message'];
                    ?>
                                <?php 
                } else {
                    if (isset($element['warning'])) {
                        ?>
                                    <span class="error_text"><?php 
                        echo $element['warning'];
                        ?>
</span>
                                <?php 
                    }
                }
                ?>

                            </th>
                        <?php 
            } else {
                ?>
                        <?php 
                if (isset($element['title'])) {
                    ?>
                            <th class="<?php 
                    echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class'];
                    ?>
">
                                <?php 
                    echo htmlspecialchars(_l($element['title']));
                    ?>
                            </th>
                            <?php 
                }
                if (isset($element['fields'])) {
                    ?>
                            <td class="<?php 
                    echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class'];
                    ?>
">
                                <?php 
                    if (is_array($element['fields'])) {
                        foreach ($element['fields'] as $dataid => $field) {
                            if (is_array($field)) {
                                // treat this as a call to the form generate option
                                module_form::generate_form_element($field);
                                echo ' ';
                            } else {
                                if (is_closure($field)) {
                                    $field();
                                } else {
                                    echo $field . ' ';
                                }
                            }
                        }
                    } else {
                        echo $element['fields'];
                    }
                    ?>
                            </td>
                        <?php 
                }
                ?>
                    </tr>
                    <?php 
            }
        }
        if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) {
            module_extra::display_extras($options['extra_settings']);
        }
        ?>
                </tbody>
            </table>
            <?php 
    }
    echo $options['elements_after'];
    ?>
        </div>
        <!-- /.block -->
    </div>


    <?php 
    return ob_get_clean();
}
示例#11
0
    public static function generate_fieldset($options)
    {
        // let the themes override this search bar function.
        $result = hook_handle_callback('generate_fieldset', $options);
        if (is_array($result)) {
            // has been handed by a theme.
            return current($result);
        }
        $defaults = array('id' => false, 'type' => 'table', 'title' => false, 'title_type' => 'h3', 'heading' => false, 'row_title_class' => 'width1', 'row_data_class' => '', 'elements' => array(), 'class' => 'tableclass tableclass_form', 'extra_settings' => array(), 'elements_before' => '', 'elements_after' => '');
        $options = array_merge($defaults, $options);
        if (function_exists('hook_filter_var')) {
            $options = hook_filter_var('generate_fieldset_options', $options);
        }
        //todo - hook in here for themes.
        ob_start();
        if ($options['heading']) {
            print_heading($options['heading']);
        } else {
            if ($options['title']) {
                ?>

            <<?php 
                echo $options['title_type'];
                ?>
><?php 
                _e($options['title']);
                ?>
</<?php 
                echo $options['title_type'];
                ?>
>
        <?php 
            }
        }
        ?>

        <?php 
        echo $options['elements_before'];
        ?>

        <?php 
        if ($options['elements']) {
            ?>

        <table class="<?php 
            echo $options['class'];
            ?>
">
            <tbody>
            <?php 
            foreach ($options['elements'] as $element) {
                if (isset($element['ignore']) && $element['ignore']) {
                    continue;
                }
                if (isset($element['field']) && !isset($element['fields'])) {
                    $element['fields'] = array($element['field']);
                    unset($element['field']);
                }
                ?>

                <tr>
                    <?php 
                if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) {
                    ?>

                        <td colspan="2" align="center">
                            <?php 
                    if (isset($element['message'])) {
                        ?>

                                <?php 
                        echo $element['message'];
                        ?>

                            <?php 
                    } else {
                        if (isset($element['warning'])) {
                            ?>

                                <span class="error_text"><?php 
                            echo $element['warning'];
                            ?>
</span>
                            <?php 
                        }
                    }
                    ?>


                        </td>
                    <?php 
                } else {
                    ?>

                        <?php 
                    if (isset($element['title'])) {
                        ?>

                        <th class="<?php 
                        echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class'];
                        ?>
">
                            <?php 
                        echo htmlspecialchars(_l($element['title']));
                        ?>

                        </th>
                        <?php 
                    }
                    if (isset($element['fields'])) {
                        ?>

                        <td class="<?php 
                        echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class'];
                        ?>
">
                            <?php 
                        if (is_array($element['fields'])) {
                            foreach ($element['fields'] as $dataid => $field) {
                                if (is_array($field)) {
                                    // treat this as a call to the form generate option
                                    self::generate_form_element($field);
                                    echo ' ';
                                } else {
                                    if (is_closure($field)) {
                                        $field();
                                    } else {
                                        echo $field . ' ';
                                    }
                                }
                            }
                        } else {
                            echo $element['fields'];
                        }
                        ?>

                        </td>
                    <?php 
                    }
                    ?>

                </tr>
                <?php 
                }
            }
            if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) {
                module_extra::display_extras($options['extra_settings']);
            }
            ?>

            </tbody>
        </table>
        <?php 
        }
        echo $options['elements_after'];
        ?>

        <?php 
        return ob_get_clean();
    }
 /**
  * Load all the functions related to this module name.
  *
  * @param string $callback
  */
 public function loadModule($module_uid)
 {
     if (!isset($this->module[$module_uid])) {
         DEBUG && error(sprintf(_("Il modulo %s è già stato registrato."), "<code>" . esc_html($module_uid) . "</code>"));
         return false;
     }
     // Short form
     $module =& $this->module[$module_uid];
     // Load every callback
     $tot_status = true;
     $n = count($module);
     for ($i = 0; $i < $n; $i++) {
         if (is_closure($module[$i])) {
             $status = $module[$i]();
             if (DEBUG && $status === false) {
                 error(sprintf(_("Errore caricando il modulo %s (callback %s°)."), "<em>" . esc_html($module_uuid) . "</em>", "<em>" . $i . "</em>"));
             }
         } else {
             $status = false;
             DEBUG && error(sprintf(_("Il callback richiesto per il modulo %s non esiste."), "<em>" . esc_html($module_uuid) . "</em>"));
         }
         $tot_status = $tot_status && $status;
     }
     return $tot_status;
 }
示例#13
0
文件: Query.php 项目: clancats/core
 /**
  * Create a where statement
  *
  * where query: <$column> <$param1> <$param2> <$type>
  * 
  * example:
  *     ->where( 'name', 'ladina' ) // name = landina
  *     ->where( 'age', '>', 18 )
  *     ->where( 'name', 'in', array( 'johanna', 'jennifer' ) )
  *
  * @param string		$column			The SQL column
  * @param mixed		$param1			
  * @param mixed		$param2
  * @param string		$type			The where type ( and, or )
  *
  * @return self
  */
 public function where($column, $param1 = null, $param2 = null, $type = 'and')
 {
     // if this is the first where element we are going to change
     // the where type to 'where'
     if (empty($this->wheres)) {
         $type = 'where';
     }
     // when column is an array we assume to make a bulk and where.
     // array( 'name' => 'ladina', 'language' => 'de' )
     // where name = ladina and language = de
     if (is_array($column)) {
         foreach ($column as $key => $val) {
             $this->where($key, $val, null, $type);
         }
         return $this;
     }
     // to make nested wheres possible you can pass an closure
     // wich will create a new query where you can add your nested wheres
     if (is_closure($column)) {
         $this->wheres[] = array($type, $column);
         return $this;
     }
     // when param2 is null we replace param2 with param one as the
     // value holder and make param1 to the = operator.
     if (is_null($param2)) {
         $param2 = $param1;
         $param1 = '=';
     }
     // if the param2 is an array we filter it. Im no more sure why
     // but it's there since 2 years so i think i had a reason.
     if (is_array($param2)) {
         $param2 = array_unique($param2);
     }
     $this->wheres[] = array($type, $column, $param1, $param2);
     return $this;
 }
示例#14
0
function adminlte_generate_fieldset($callback, $options)
{
    $defaults = array('id' => false, 'type' => 'table', 'title' => false, 'title_type' => 'h3', 'heading' => false, 'row_title_class' => 'width1', 'row_data_class' => '', 'elements' => array(), 'class' => 'tableclass tableclass_form', 'extra_settings' => array(), 'elements_before' => '', 'elements_after' => '');
    $options = array_merge($defaults, $options);
    if (function_exists('hook_filter_var')) {
        $options = hook_filter_var('generate_fieldset_options', $options);
    }
    ob_start();
    ?>

    <div class="box <?php 
    echo module_theme::get_config('adminlte_boxstyle', 'box-solid');
    echo isset($options['heading']['responsive']) ? ' box-responsive' : '';
    ?>
">
        <div class="box-header">
            <?php 
    if ($options['heading']) {
        if (!isset($options['heading']['type']) || $options['heading']['type'] != 'h3') {
            $options['heading']['type'] = 'h3';
        }
        $options['heading']['class'] = 'box-title';
        print_heading($options['heading']);
    } else {
        if ($options['title']) {
            ?>
                <<?php 
            echo $options['title_type'];
            ?>
 class="box-title"><?php 
            _e($options['title']);
            ?>
</<?php 
            echo $options['title_type'];
            ?>
>
            <?php 
        }
    }
    ?>
        </div>
        <!-- .block -->
        <div class="box-body">
            <?php 
    echo $options['elements_before'];
    ?>
            <?php 
    if ($options['elements']) {
        if (module_theme::get_config('adminlte_formstyle', 'table') == 'table') {
            ?>
                    <table class="<?php 
            echo $options['class'];
            ?>
">
                        <tbody>
                        <?php 
            foreach ($options['elements'] as $element) {
                if (isset($element['ignore']) && $element['ignore']) {
                    continue;
                }
                if (isset($element['field']) && !isset($element['fields'])) {
                    $element['fields'] = array($element['field']);
                    unset($element['field']);
                }
                ?>
                            <tr>
                                <?php 
                if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) {
                    ?>
                                    <th colspan="2" class="text-center">
                                        <?php 
                    if (isset($element['message'])) {
                        ?>
                                            <?php 
                        echo $element['message'];
                        ?>
                                        <?php 
                    } else {
                        if (isset($element['warning'])) {
                            ?>
                                            <span class="error_text"><?php 
                            echo $element['warning'];
                            ?>
</span>
                                        <?php 
                        }
                    }
                    ?>
                                    </th>
                                <?php 
                } else {
                    ?>
                                    <th class="<?php 
                    echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class'];
                    ?>
">
                                        <?php 
                    if (isset($element['title'])) {
                        ?>
                                            <?php 
                        echo htmlspecialchars(_l($element['title']));
                        ?>
                                        <?php 
                    }
                    ?>
                                    </th>
                                    <td class="<?php 
                    echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class'];
                    ?>
">
                                    <?php 
                    if (isset($element['fields'])) {
                        ?>
                                        <?php 
                        if (is_array($element['fields'])) {
                            foreach ($element['fields'] as $dataid => $field) {
                                if (is_array($field)) {
                                    // treat this as a call to the form generate option
                                    module_form::generate_form_element($field);
                                    echo ' ';
                                } else {
                                    if (is_closure($field)) {
                                        $field();
                                    } else {
                                        echo $field . ' ';
                                    }
                                }
                            }
                        } else {
                            echo $element['fields'];
                        }
                        ?>
                                    <?php 
                    }
                    // fields
                    ?>
                                    </td> <!-- /.input-group -->
                                <?php 
                }
                //else
                ?>
                            </tr> <!-- /.form-group -->
                        <?php 
            }
            if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) {
                module_extra::display_extras($options['extra_settings']);
            }
            ?>
                        </tbody>
                        </table> <!-- /.elements -->
                    <?php 
            // end table layout
        } else {
            if (module_theme::get_config('adminlte_formstyle', 'table') == 'div') {
                ?>
                    <div class="<?php 
                echo $options['class'];
                ?>
">
                        <?php 
                foreach ($options['elements'] as $element) {
                    if (isset($element['ignore']) && $element['ignore']) {
                        continue;
                    }
                    if (isset($element['field']) && !isset($element['fields'])) {
                        $element['fields'] = array($element['field']);
                        unset($element['field']);
                    }
                    ?>
                            <div class="form-group">
                                <?php 
                    if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) {
                        ?>
                                    <div class="text-center">
                                        <?php 
                        if (isset($element['message'])) {
                            ?>
                                            <?php 
                            echo $element['message'];
                            ?>
                                        <?php 
                        } else {
                            if (isset($element['warning'])) {
                                ?>
                                            <span class="error_text"><?php 
                                echo $element['warning'];
                                ?>
</span>
                                        <?php 
                            }
                        }
                        ?>
                                    </div>
                                <?php 
                    } else {
                        ?>
                                    <div class="input-group<?php 
                        echo !isset($element['title']) ? '-notitle' : '';
                        ?>
">
                                    <?php 
                        if (isset($element['title'])) {
                            ?>
                                        <span class="input-group-addon table-row-title"><span class="<?php 
                            echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class'];
                            ?>
"><?php 
                            echo htmlspecialchars(_l($element['title']));
                            ?>
</span></span>
                                    <?php 
                        }
                        if (isset($element['fields'])) {
                            ?>

                                        <?php 
                            if (is_array($element['fields'])) {
                                // if there is only one element we put it up in the form-control so that it displays nicely.
                                // if there are more than one elements we wrap them in a div form-control.
                                $do_wrap = true;
                                if (count($element['fields']) == 1) {
                                    $field = current($element['fields']);
                                    if (is_array($field) && $field['type'] != 'wysiwyg' && $field['type'] != 'check' && $field['type'] != 'checkbox') {
                                        $do_wrap = false;
                                        $currency = false;
                                        if ($field['type'] == 'currency') {
                                            $field['type'] = 'text';
                                            $currency = true;
                                            //$field['class'] = (isset($field['class']) ? $field['class'] : '') .' currency ';
                                        }
                                        $field['class'] = (isset($field['class']) ? $field['class'] : '') . ' form-control ' . (isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']);
                                        $help_text = false;
                                        if (isset($field['help'])) {
                                            // we put the help element outside in its own <span class="input-group-addon"></span>
                                            // don't let the generatE_form_element produce it.
                                            $help_text = $field['help'];
                                            unset($field['help']);
                                        }
                                        module_form::generate_form_element($field);
                                        if ($currency) {
                                            ?>
		                                                <span class="input-group-addon"><?php 
                                            echo currency('', true, isset($field['currency_id']) ? $field['currency_id'] : false);
                                            ?>
</span>
		                                                <?php 
                                        }
                                        if ($help_text) {
                                            ?>
		                                                <span class="input-group-addon"><?php 
                                            _h($help_text);
                                            ?>
</span>
		                                                <?php 
                                        }
                                    }
                                }
                                if ($do_wrap) {
                                    ?>
 <div class="form-control<?php 
                                    echo !isset($element['title']) ? '-notitle' : '';
                                    ?>
 <?php 
                                    echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class'];
                                    ?>
"> <?php 
                                    $help_text = false;
                                    foreach ($element['fields'] as $dataid => $field) {
                                        if (is_array($field) && isset($field['help'])) {
                                            // this element has a help text.
                                            if ($help_text) {
                                                // already a help text (shouldn't happen, ditch it.. and display multiple as normal)
                                                $help_text = false;
                                                break;
                                            } else {
                                                $help_text = $field['help'];
                                            }
                                        }
                                    }
                                    foreach ($element['fields'] as $dataid => $field) {
                                        if (is_array($field)) {
                                            if (isset($field['help']) && $help_text) {
                                                unset($field['help']);
                                            }
                                            // treat this as a call to the form generate option
                                            module_form::generate_form_element($field);
                                            echo ' ';
                                        } else {
                                            if (is_closure($field)) {
                                                $field();
                                            } else {
                                                echo $field . ' ';
                                            }
                                        }
                                    }
                                    ?>
 </div> <?php 
                                    if ($help_text) {
                                        ?>
	                                                <span class="input-group-addon"><?php 
                                        _h($help_text);
                                        ?>
</span>
	                                                <?php 
                                    }
                                }
                            } else {
                                ?>
 <div class="form-control <?php 
                                echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class'];
                                ?>
"> <?php 
                                echo $element['fields'];
                                ?>
 </div> <?php 
                            }
                            ?>
                                    <?php 
                        }
                        // fields
                        ?>
                                    </div> <!-- /.input-group -->
                                <?php 
                    }
                    //else
                    ?>
                            </div> <!-- /.form-group -->
                        <?php 
                }
                if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) {
                    module_extra::display_extras($options['extra_settings']);
                }
                ?>
                        </div> <!-- /.elements -->
                    <?php 
            } else {
                if (module_theme::get_config('adminlte_formstyle', 'table') == 'long') {
                    ?>
                    <div class="<?php 
                    echo $options['class'];
                    ?>
">
                        <?php 
                    foreach ($options['elements'] as $element) {
                        if (isset($element['ignore']) && $element['ignore']) {
                            continue;
                        }
                        if (isset($element['field']) && !isset($element['fields'])) {
                            $element['fields'] = array($element['field']);
                            unset($element['field']);
                        }
                        ?>
                            <div class="form-group form-group-long">
                                <?php 
                        if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) {
                            ?>
                                    <div class="text-center">
                                        <?php 
                            if (isset($element['message'])) {
                                ?>
                                            <?php 
                                echo $element['message'];
                                ?>
                                        <?php 
                            } else {
                                if (isset($element['warning'])) {
                                    ?>
                                            <span class="error_text"><?php 
                                    echo $element['warning'];
                                    ?>
</span>
                                        <?php 
                                }
                            }
                            ?>
                                    </div>
                                <?php 
                        } else {
                            ?>

                                    <?php 
                            if (isset($element['title'])) {
                                ?>
                                        <label class="<?php 
                                echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class'];
                                ?>
"><?php 
                                echo htmlspecialchars(_l($element['title']));
                                ?>
</label>
                                    <?php 
                            }
                            if (isset($element['fields'])) {
                                ?>

                                        <?php 
                                if (is_array($element['fields'])) {
                                    foreach ($element['fields'] as $dataid => $field) {
                                        if (is_array($field)) {
                                            // treat this as a call to the form generate option
                                            $field['class'] = (isset($field['class']) ? $field['class'] : '') . ' ' . (isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']);
                                            switch ($field['type']) {
                                                case 'check':
                                                case 'checkbox':
                                                case 'wysiwyg':
                                                    break;
                                                default:
                                                    $field['class'] .= ' form-control ';
                                            }
                                            module_form::generate_form_element($field);
                                            echo ' ';
                                        } else {
                                            if (is_closure($field)) {
                                                $field();
                                            } else {
                                                echo $field . ' ';
                                            }
                                        }
                                    }
                                } else {
                                    ?>
 <div class="form-control <?php 
                                    echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class'];
                                    ?>
"> <?php 
                                    echo $element['fields'];
                                    ?>
 </div> <?php 
                                }
                                ?>
                                    <?php 
                            }
                            // fields
                            ?>
                                <?php 
                        }
                        //else
                        ?>
                            </div> <!-- /.form-group -->
                        <?php 
                    }
                    if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) {
                        module_extra::display_extras($options['extra_settings']);
                    }
                    ?>
                        </div> <!-- /.elements -->
                    <?php 
                }
            }
        }
        // end div layout
    }
    echo $options['elements_after'];
    ?>
        <!-- /.block -->
        </div>
    </div>


    <?php 
    return ob_get_clean();
}
示例#15
0
 public static function callStack()
 {
     $GC = CARRY('get_class');
     $callstack = Tree::getActiveCallstack();
     $count = count($callstack);
     Tree::$currentIndex = count(Tree::getActiveNodes()) - 1;
     if (!$count) {
         return false;
     }
     for ($i = 0; $i < $count; $i++) {
         foreach (array_keys($callstack[$i]) as $key) {
             if (strpos($key, '_') === 0) {
                 $callstack[$i][substr($key, 1)] = $callstack[$i][$key];
                 unset($callstack[$i][$key]);
             } elseif ($i < $count - 1) {
                 unset($callstack[$i][$key]);
             }
         }
     }
     $final = array();
     for ($i = $count - 1; $i >= 0; $i--) {
         $final += $callstack[$i];
     }
     ksort($final);
     foreach ($final as $key => $value) {
         if (is_string($value)) {
             $name = "{$value}";
         } elseif (is_array($value) and is_string($value[0])) {
             $name = "{$value[0]}";
         } elseif (is_array($value) and is_array($value[0]) and is_string($value[0][0])) {
             $name = "{$value[0][0]}, {$value[0][1]}";
         } elseif (is_array($value) and is_array($value[0]) and is_object($value[0][0])) {
             $name = "{$GC($value[0][0])}, {$value[0][1]}";
         } elseif (is_closure($value)) {
             $name = "CLOSURE ({$key})";
         } else {
             continue;
         }
         Profiling::start($name);
         if (is_closure($value)) {
             $value();
         } else {
             if (is_string($value)) {
                 $value = array($value);
             }
             $function = array_shift($value);
             call_user_func_array($function, $value);
         }
         Profiling::stop();
     }
     return true;
 }
示例#16
0
    public function print_row($row)
    {
        static $c = 0;
        if (_DEBUG_MODE) {
            module_debug::log(array('title' => 'row'));
        }
        if (is_closure($this->row_callback)) {
            /** @var Closure $row_callback */
            $row_callback = $this->row_callback;
            $result = $row_callback($row, $this);
            if ($result === false) {
                return false;
            }
            $row = array_merge($row, $result);
        }
        // options for this row output...
        $row_class = $this->row_class . ' ' . ($c++ % 2 ? "odd" : "even");
        ?>
        <tr<?php 
        echo $this->row_id ? ' id="' . $this->row_id . '"' : '';
        ?>
 class="<?php 
        echo $row_class;
        ?>
"<?php 
        foreach ($this->row_attributes as $key => $val) {
            echo ' ' . $key . '="' . htmlspecialchars($val) . '"';
        }
        ?>
>
            <?php 
        foreach ($this->columns as $column_id => $column_data) {
            ?>
                <td<?php 
            if (isset($row[$column_id]) && is_array($row[$column_id]) && isset($row[$column_id]['cell_class'])) {
                echo ' class="' . $row[$column_id]['cell_class'] . '"';
            } else {
                if (isset($column_data['cell_class'])) {
                    echo ' class="' . $column_data['cell_class'] . '"';
                }
            }
            if (isset($row[$column_id]) && is_array($row[$column_id]) && isset($row[$column_id]['cell_colspan'])) {
                echo ' colspan="' . $row[$column_id]['cell_colspan'] . '"';
            } else {
                if (isset($column_data['cell_colspan'])) {
                    echo ' colspan="' . $column_data['cell_colspan'] . '"';
                }
            }
            ?>
>
                    <?php 
            if (is_array($column_data) && isset($column_data['callback']) && is_closure($column_data['callback'])) {
                $column_data['callback']($row);
            } else {
                if (isset($row[$column_id])) {
                    echo $row[$column_id];
                } else {
                    _e('N/A');
                }
            }
            ?>
                </td>
                <?php 
        }
        if (class_exists('module_extra', false) && count($this->extra_fields)) {
            foreach ($this->extra_fields as $extra_field) {
                if (is_closure($extra_field['callback'])) {
                    $extra_field['callback']($row);
                }
            }
        }
        if (class_exists('module_subscription', false) && count($this->subscription_fields)) {
            foreach ($this->subscription_fields as $subscription_field) {
                if (is_closure($subscription_field['callback'])) {
                    $subscription_field['callback']($row);
                }
            }
        }
        ?>
        </tr>
        <?php 
        return true;
    }
示例#17
0
文件: CCStr.php 项目: clancats/core
 /**
  * Try to get a string from a callback reading the output buffer
  *
  * @param mixed		$callback
  * @param array 		$params 
  * @return string
  */
 public static function capture($callback, $params = array())
 {
     if (is_string($callback)) {
         return $callback;
     }
     if (!is_closure($callback)) {
         return "";
     }
     if (!is_array($params)) {
         $params = array($params);
     }
     ob_start();
     $return = call_user_func_array($callback, $params);
     $buffer = ob_get_clean();
     if (!is_null($return)) {
         return $return;
     }
     return $buffer;
 }
示例#18
0
 public function show($id, $callback = null)
 {
     $model = $this->model()->newInstance();
     //$model = $this->model();
     if (!is_null($callback) && is_closure($callback)) {
         $this->doRunClosure($callback, $model);
     }
     $result = $model->find($id);
     if (is_null($result)) {
         $this->addErrorMessage('Not Found', 404);
         return false;
     }
     return $result;
 }
示例#19
0
文件: E.php 项目: clancats/core
 /**
  * render this element
  *
  * @return string
  */
 public function render()
 {
     // execute callback if we have one first
     if (is_closure($this->value)) {
         ob_start();
         $return = call_user_func($this->value);
         $this->value = ob_get_clean() . $return;
     }
     return '<' . $this->name . static::attr($this->attr) . (!is_null($this->value) ? '>' . $this->value . '</' . $this->name . '>' : ' />');
 }
示例#20
0
文件: Builder.php 项目: clancats/core
 /**
  * Build the where part
  *
  * @param Query 		$query
  * @return string
  */
 public function compile_where(&$query)
 {
     $build = '';
     foreach ($query->wheres as $where) {
         // to make nested wheres possible you can pass an closure
         // wich will create a new query where you can add your nested wheres
         if (!isset($where[2]) && is_closure($where[1])) {
             $sub_query = new Query();
             call_user_func($where[1], $sub_query);
             // The parameters get added by the call of compile where
             $build .= ' ' . $where[0] . ' ( ' . substr($this->compile_where($sub_query), 7) . ' )';
             continue;
         }
         // when we have an array as where values we have
         // to parameterize them
         if (is_array($where[3])) {
             $where[3] = '(' . $this->parameterize($where[3]) . ')';
         } else {
             $where[3] = $this->param($where[3]);
         }
         // we always need to escepe where 1 wich referrs to the key
         $where[1] = $this->escape($where[1]);
         // implode the beauty
         $build .= ' ' . implode(' ', $where);
     }
     return $build;
 }
示例#21
0
文件: Content.php 项目: rodrane/ravel
 public function getMyContents($callback = null)
 {
     $author_id = $this->getAuthorId();
     $model = $this->model();
     $host = $this;
     return $model->with(array('contentmeta'))->where(function ($query) use($host, $callback) {
         if (is_closure($callback)) {
             $callback($query, $host);
         }
         $query->where('author_id', '=', $author_id);
     })->get();
 }