• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Mecha类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Mecha的典型用法代码示例。如果您正苦于以下问题:PHP Mecha类的具体用法?PHP Mecha怎么用?PHP Mecha使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Mecha类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: __callStatic

 public static function __callStatic($id, $arguments = array())
 {
     $c = get_called_class();
     $d = Tree::$config;
     $dd = self::$config['classes'];
     if (!isset(self::$menus[$c][$id])) {
         return false;
     }
     $AD = array('ul', "", $id . ':');
     $arguments = Mecha::extend($AD, $arguments);
     $type = $arguments[0];
     $arguments[0] = self::$menus[$c][$id];
     if (!is_array($arguments[0])) {
         return "";
     }
     Tree::$config['trunk'] = $type;
     Tree::$config['branch'] = $type;
     Tree::$config['twig'] = 'li';
     Tree::$config['classes']['trunk'] = $dd['parent'];
     Tree::$config['classes']['branch'] = $dd['child'];
     Tree::$config['classes']['twig'] = false;
     Tree::$config['classes']['current'] = $dd['current'];
     Tree::$config['classes']['chink'] = $dd['separator'];
     $output = call_user_func_array('Tree::grow', $arguments);
     Tree::$config = $d;
     // reset to the previous state
     return $output;
 }
开发者ID:yiannisSt,项目名称:mecha-cms,代码行数:28,代码来源:menu.php


示例2: placeholder

 public static function placeholder($url = null)
 {
     if (is_array($url)) {
         return Mecha::eat($url)->shake()->get(0);
     }
     return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:7,代码来源:image.php


示例3: do_private_post

function do_private_post($content, $results)
{
    global $config, $speak;
    $results = Mecha::O($results);
    $results = $config->is->post ? Get::postHeader($results->path, POST . DS . $config->page_type, '/', $config->page_type . ':') : false;
    if ($results === false) {
        return $speak->plugin_private_post->description;
    }
    $s = isset($results->fields->pass) ? $results->fields->pass : "";
    if (strpos($s, ':') !== false) {
        $s = explode(':', $s, 2);
        if (isset($s[1])) {
            $speak->plugin_private_post->hint = ltrim($s[1]);
        }
        // override password hint
        $s = $s[0];
    }
    $hash = md5($s . PRIVATE_POST_SALT);
    $html = Notify::read(false) . '<div class="overlay--' . File::B(__DIR__) . '"></div><form class="form--' . File::B(__DIR__) . '" action="' . $config->url . '/' . File::B(__DIR__) . '/do:access" method="post">' . NL;
    $html .= TAB . Form::hidden('token', Guardian::token()) . NL;
    $html .= TAB . Form::hidden('_', $hash) . NL;
    $html .= TAB . Form::hidden('kick', $config->url_current) . NL;
    $html .= TAB . '<p>' . $speak->plugin_private_post->hint . '</p>' . NL;
    $html .= TAB . '<p>' . Form::text('access', "", $speak->password . '&hellip;', array('autocomplete' => 'off')) . ' ' . Form::button($speak->submit, null, 'submit') . '</p>' . NL;
    $html .= '</form>' . O_END;
    if ($results && isset($results->fields->pass) && trim($results->fields->pass) !== "") {
        if (!Guardian::happy() && Session::get('is_allow_post_access') !== $hash) {
            return $html;
        }
    }
    return $content;
}
开发者ID:tovic,项目名称:private-post-plugin-for-mecha-cms,代码行数:32,代码来源:launch.php


示例4: get

 public static function get($param = null, $fallback = false, $str_eval = true)
 {
     if (is_null($param)) {
         return $_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET) && !empty($_GET) ? $str_eval ? Converter::strEval($_GET, false) : $_GET : $fallback;
     }
     $output = Mecha::GVR($_GET, $param, $fallback);
     return $output === '0' || !empty($output) ? $str_eval ? Converter::strEval($output, false) : $output : $fallback;
 }
开发者ID:yiannisSt,项目名称:mecha-cms,代码行数:8,代码来源:request.php


示例5: inspect

 public static function inspect($path, $output = null, $fallback = false)
 {
     $path = self::path($path);
     $n = self::N($path);
     $e = self::E($path);
     $update = self::T($path);
     $update_date = !is_null($update) ? date('Y-m-d H:i:s', $update) : null;
     $results = array('path' => $path, 'name' => $n, 'url' => self::url($path), 'extension' => is_file($path) ? $e : null, 'update_raw' => $update, 'update' => $update_date, 'size_raw' => file_exists($path) ? filesize($path) : null, 'size' => file_exists($path) ? self::size($path) : null, 'is' => array('hidden' => strpos($n, '__') === 0 || strpos($n, '.') === 0, 'file' => is_file($path), 'folder' => is_dir($path)));
     return !is_null($output) ? Mecha::GVR($results, $output, $fallback) : $results;
 }
开发者ID:yiannisSt,项目名称:mecha-cms,代码行数:10,代码来源:file.php


示例6: info

 public static function info($folder = null, $array = false)
 {
     $config = Config::get();
     $speak = Config::speak();
     // Check whether the localized "about" file is available
     if (!($info = File::exist(PLUGIN . DS . $folder . DS . 'about.' . $config->language . '.txt'))) {
         $info = PLUGIN . DS . $folder . DS . 'about.txt';
     }
     $default = 'Title' . S . ' ' . ucwords(Text::parse($folder, '->text')) . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description);
     $info = Text::toPage(File::open($info)->read($default), 'content', 'plugin:');
     return $array ? $info : Mecha::O($info);
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:12,代码来源:plugin.php


示例7: fire

 /**
  * ==============================================================
  *  FIRE !!!
  * ==============================================================
  *
  * -- CODE: -----------------------------------------------------
  *
  *    Weapon::fire('tank');
  *
  * --------------------------------------------------------------
  *
  *    Weapon::fire('jet', array('Blue', '1.1.0'));
  *
  * --------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------
  *  $name      | string | Hook name
  *  $arguments | array  | Hook function argument(s)
  *  ---------- | ------ | ---------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function fire($name, $arguments = array())
 {
     $name = get_called_class() . '::' . $name;
     if (isset(self::$armaments[$name])) {
         if (func_num_args() > 2) {
             $arguments = array_slice(func_get_args(), 1);
         }
         $weapons = Mecha::eat(self::$armaments[$name])->order('ASC', 'stack')->vomit();
         foreach ($weapons as $weapon => $cargo) {
             if (!isset(self::$armaments_e[$name . '->' . $cargo['stack']])) {
                 call_user_func_array($cargo['fn'], $arguments);
             }
         }
     } else {
         self::$armaments[$name] = array();
     }
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:41,代码来源:weapon.php


示例8: header

 public static function header($data = array(), $value = "")
 {
     if (!is_array($data)) {
         $data = array(self::fix($data) => $value);
     }
     foreach ($data as $k => $v) {
         if ($v === false) {
             unset($data[self::fix($k)], self::$bucket[self::fix($k)]);
         } else {
             // Restrict user(s) from inputting the `SEPARATOR` constant
             // to prevent mistake(s) in parsing the file content
             $data[self::fix($k)] = Text::ES($v);
         }
     }
     Mecha::extend(self::$bucket, $data);
     return new static();
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:17,代码来源:page.php


示例9: apply

 /**
  * ===================================================================
  *  APPLY FILTER
  * ===================================================================
  *
  * -- CODE: ----------------------------------------------------------
  *
  *    Filter::apply('content', $content);
  *
  * -------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ---------------------------------------------
  *  $name     | string | Filter name
  *  $value    | string | String to be manipulated
  *  --------- | ------ | ---------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function apply($name, $value)
 {
     $name = get_called_class() . '::' . $name;
     if (!isset(self::$filters[$name])) {
         self::$filters[$name] = array();
         return $value;
     }
     $params = array_slice(func_get_args(), 2);
     $filters = Mecha::eat(self::$filters[$name])->order('ASC', 'stack')->vomit();
     foreach ($filters as $filter => $cargo) {
         if (!isset(self::$filters_e[$name . '->' . $cargo['stack']])) {
             $arguments = array_merge(array($value), $params);
             $value = call_user_func_array($cargo['fn'], $arguments);
         }
     }
     return $value;
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:37,代码来源:filter.php


示例10: fire

 /**
  * ==============================================================
  *  FIRE !!!
  * ==============================================================
  *
  * -- CODE: -----------------------------------------------------
  *
  *    Weapon::fire('tank');
  *
  * --------------------------------------------------------------
  *
  *    Weapon::fire('jet', array('Blue', '1.1.0'));
  *
  * --------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------
  *  $name      | string | Hook name
  *  $arguments | array  | Hook function argument(s)
  *  ---------- | ------ | ---------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function fire($name, $arguments = array())
 {
     if (!is_array($name)) {
         $c = get_called_class();
         if (isset(self::$armaments[$c][$name])) {
             if (func_num_args() > 2) {
                 $arguments = array_slice(func_get_args(), 1);
             }
             $weapons = Mecha::eat(self::$armaments[$c][$name])->order('ASC', 'stack')->vomit();
             foreach ($weapons as $weapon => $cargo) {
                 call_user_func_array($cargo['fn'], $arguments);
             }
         } else {
             self::$armaments[$c][$name] = array();
         }
     } else {
         $arguments = func_get_args();
         foreach ($name as $v) {
             $arguments[0] = $v;
             call_user_func_array('self::fire', $arguments);
         }
     }
 }
开发者ID:yiannisSt,项目名称:mecha-cms,代码行数:47,代码来源:weapon.php


示例11: apply

 /**
  * ===================================================================
  *  APPLY FILTER
  * ===================================================================
  *
  * -- CODE: ----------------------------------------------------------
  *
  *    Filter::apply('content', $content);
  *
  *    Filter::apply(array('page:title', 'title'), $content);
  *
  * -------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ---------------------------------------------
  *  $name     | string | Filter name
  *  $value    | string | String to be manipulated
  *  --------- | ------ | ---------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function apply($name, $value)
 {
     if (!is_array($name)) {
         $c = get_called_class();
         if (!isset(self::$filters[$c][$name])) {
             self::$filters[$c][$name] = array();
             return $value;
         }
         $arguments = array_slice(func_get_args(), 1);
         $filters = Mecha::eat(self::$filters[$c][$name])->order('ASC', 'stack')->vomit();
         foreach ($filters as $filter => $cargo) {
             $arguments[0] = $value;
             $value = call_user_func_array($cargo['fn'], $arguments);
         }
     } else {
         $arguments = func_get_args();
         foreach (array_reverse($name) as $v) {
             $arguments[0] = $v;
             $arguments[1] = $value;
             $value = call_user_func_array('self::apply', $arguments);
         }
     }
     return $value;
 }
开发者ID:AdeHaze,项目名称:mecha-cms,代码行数:46,代码来源:filter.php


示例12: pageAnchor

 /**
  * ==========================================================================
  *  GET MINIMUM DATA OF A PAGE
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::pageAnchor('about'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $path      | string | The URL path of the page file, or a page slug
  *  $folder    | string | Folder of the page(s)
  *  $connector | string | See `Get::page()`
  *  $FP        | string | See `Get::page()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function pageAnchor($path, $folder = PAGE, $connector = '/', $FP = 'page:')
 {
     $config = Config::get();
     if (strpos($path, ROOT) === false) {
         $path = self::pagePath($path, $folder);
         // By page slug, ID or time
     }
     if ($path && ($buffer = File::open($path)->get(1)) !== false) {
         $results = self::pageExtract($path);
         $parts = explode(S, $buffer, 2);
         $results['url'] = self::AMF($config->url . $connector . $results['slug'], $FP, 'url');
         $results['title'] = self::AMF(isset($parts[1]) ? Text::DS(trim($parts[1])) : "", $FP, 'title');
         return Mecha::O($results);
     }
     return false;
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:38,代码来源:get.php


示例13: glob

    $filter = Request::get('q', "");
    $filter = $filter ? Text::parse($filter, '->safe_file_name') : false;
    $takes = glob($d . DS . '*', GLOB_NOSORT);
    if ($filter) {
        foreach ($takes as $k => $v) {
            if (strpos(File::N($v), $filter) === false) {
                unset($takes[$k]);
            }
        }
    }
    if ($_files = Mecha::eat($takes)->chunk($offset, $config->per_page * 2)->vomit()) {
        $files = array();
        foreach ($_files as $_file) {
            $files[] = File::inspect($_file);
        }
        $files = Mecha::eat($files)->order('ASC', 'path')->vomit();
        unset($_files);
    } else {
        $files = false;
    }
    Config::set(array('page_title' => $speak->assets . $config->title_separator . $config->manager->title, 'offset' => $offset, 'files' => $files, 'pagination' => Navigator::extract($takes, $offset, $config->per_page * 2, $config->manager->slug . '/asset'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.asset.php'));
    Shield::lot('segment', 'asset')->attach('manager', false);
});
/**
 * Asset Repair
 * ------------
 */
Route::accept($config->manager->slug . '/asset/repair/(file|files):(:all)', function ($path = "", $old = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:31,代码来源:route.asset.php


示例14: info

 /**
  * ==========================================================
  *  GET SHIELD INFO
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    var_dump(Shield::info('normal'));
  *
  * ----------------------------------------------------------
  *
  */
 public static function info($folder = null, $array = false)
 {
     $config = Config::get();
     $speak = Config::speak();
     if (is_null($folder)) {
         $folder = $config->shield;
     }
     // Check whether the localized "about" file is available
     if (!($info = File::exist(SHIELD . DS . $folder . DS . 'about.' . $config->language . '.txt'))) {
         $info = SHIELD . DS . $folder . DS . 'about.txt';
     }
     $d = 'Title' . S . ' ' . Text::parse($folder, '->title') . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description);
     $info = Text::toPage(File::open($info)->read($d), 'content', 'shield:', array('id' => File::exist(SHIELD . DS . $folder) ? $folder : false));
     return $array ? $info : Mecha::O($info);
 }
开发者ID:AdeHaze,项目名称:mecha-cms,代码行数:27,代码来源:shield.php


示例15: configure

 public static function configure($key, $value = null)
 {
     if (is_array($key)) {
         Mecha::extend(self::$config, $key);
     } else {
         if (is_array($value)) {
             Mecha::extend(self::$config[$key], $value);
         } else {
             self::$config[$key] = $value;
         }
     }
     return new static();
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:13,代码来源:file.php


示例16: function

 * ===================================================================
 *  APPLY FILTER WITH PREFIX
 * ===================================================================
 *
 * -- CODE: ----------------------------------------------------------
 *
 *    Filter::colon('page:title', $content);
 *
 *    // is equal to ...
 *
 *    Filter::apply(array('page:title', 'title'), $content);
 *
 * -------------------------------------------------------------------
 *
 */
Filter::plug('colon', function ($name, $value) {
    $arguments = func_get_args();
    if (strpos($name, ':') !== false) {
        $s = explode(':', $name, 2);
        $arguments[0] = array($name, $s[1]);
    }
    return call_user_func_array('Filter::apply', $arguments);
});
// Set response, comment and user `status` as `pilot`, `passenger` and `intruder`
Filter::add(array('response:status', 'comment:status', 'user:status'), function ($status) {
    return Mecha::alter($status, array(0 => 'intruder', 1 => 'pilot', 2 => 'passenger'));
}, 1);
// Decode the obfuscated `email` value
Filter::add(array('response:email', 'comment:email', 'user:email'), function ($data) {
    return Text::parse($data, '->decoded_html');
}, 1);
开发者ID:yiannisSt,项目名称:mecha-cms,代码行数:31,代码来源:filter.php


示例17: attr

 /**
  * ====================================================================
  *  CONVERT ATTRIBUTE(S) OF ELEMENT INTO ARRAY OF DATA
  * ====================================================================
  *
  * -- CODE: -----------------------------------------------------------
  *
  *    var_dump(Converter::attr('<div id="foo">'));
  *
  * --------------------------------------------------------------------
  *
  *    var_dump(Converter::attr('<div id="foo">test content</div>'));
  *
  * --------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type    | Description
  *  --------- | ------- | ---------------------------------------------
  *  $input    | string  | The string of element to be converted
  *  $element  | array   | Tag open, tag close, tag separator
  *  $attr     | array   | Value open, value close, attribute separator
  *  $str_eval | boolean | Convert value with `Converter::strEval()` ?
  *  --------- | ------- | ---------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function attr($input, $element = array(), $attr = array(), $str_eval = true)
 {
     $ED = array('<', '>', ' ', '/', '[a-zA-Z0-9\\-._:]+');
     $AD = array('"', '"', '=', '[a-zA-Z0-9\\-._:]+');
     $E = Mecha::extend($ED, $element);
     $A = Mecha::extend($AD, $attr);
     $E0 = preg_quote($E[0], '#');
     $E1 = preg_quote($E[1], '#');
     $E2 = preg_quote($E[2], '#');
     $E3 = preg_quote($E[3], '#');
     $A0 = preg_quote($A[0], '#');
     $A1 = preg_quote($A[1], '#');
     $A2 = preg_quote($A[2], '#');
     if (!preg_match('#^\\s*(' . $E0 . ')(' . $E[4] . ')((' . $E2 . ')+(.*?))?((' . $E1 . ')([\\s\\S]*?)((' . $E0 . ')' . $E3 . '\\2(' . $E1 . '))|(' . $E2 . ')*' . $E3 . '?(' . $E1 . '))\\s*$#', $input, $M)) {
         return false;
     }
     $M[5] = preg_replace('#(^|(' . $E2 . ')+)(' . $A[3] . ')(' . $A2 . ')(' . $A0 . ')(' . $A1 . ')#', '$1$2$3$4$5<attr:value>$6', $M[5]);
     $results = array('element' => $M[2], 'attributes' => null, 'content' => isset($M[8]) && $M[9] === $E[0] . $E[3] . $M[2] . $E[1] ? $M[8] : null);
     if (preg_match_all('#(' . $A[3] . ')((' . $A2 . ')(' . $A0 . ')(.*?)(' . $A1 . '))?(?:(' . $E2 . ')|$)#', $M[5], $A)) {
         $results['attributes'] = array();
         foreach ($A[1] as $k => $v) {
             $results['attributes'][$v] = isset($A[5][$k]) && !empty($A[5][$k]) ? strpos($A[5][$k], '<attr:value>') === false ? $A[5][$k] : str_replace('<attr:value>', "", $A[5][$k]) : $v;
         }
     }
     return $str_eval ? self::strEval($results) : $results;
 }
开发者ID:razordaze,项目名称:mecha-cms,代码行数:52,代码来源:converter.php


示例18: function

<?php

$scopes = Mecha::walk(glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR), function ($v) {
    return File::B($v);
});
return array('pass' => array('title' => $speak->password, 'type' => 'text', 'scope' => implode(',', $scopes), 'description' => $speak->plugin_private_post->__description));
开发者ID:tovic,项目名称:private-post-plugin-for-mecha-cms,代码行数:6,代码来源:fields.php


示例19: foreach

    <h4><i class="fa fa-users"></i> <?php 
echo $speak->users;
?>
</h4>
    <?php 
if ($users = Guardian::ally()) {
    ?>
    <ul>
      <?php 
    foreach ($users as $user) {
        ?>
      <li><?php 
        echo $user['name'];
        ?>
 <i class="fa fa-user<?php 
        echo Mecha::alter($user['status_raw'], array(0 => '-times', 1 => '-md', 2 => ""));
        ?>
"></i></li>
      <?php 
    }
    ?>
    </ul>
    <?php 
}
?>
  </div>
</div>
<div class="grid-group">
  <div class="grid span-2">
    <h4>Recently Updated</h4>
    <p>Nothing.</p>
开发者ID:tovic,项目名称:dashboard-plugin-for-mecha-cms,代码行数:31,代码来源:cargo.manager.php


示例20: extract


//.........这里部分代码省略.........
  * ============================================================================
  *
  * -- CODE: -------------------------------------------------------------------
  *
  *    $pager = Navigator::extract(glob('some/files/*.txt'), 1, 5, 'foo/bar');
  *    echo $pager->prev->anchor;
  *
  * ----------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type    | Description
  *  ---------- | ------- | ----------------------------------------------------
  *  $pages     | array   | Array of file(s) to be paginated
  *  $current   | integer | The current page offset
  *  $current   | string  | The current page path
  *  $per_page  | integer | Number of file(s) to show per page request
  *  $connector | string  | Extra path to be inserted into URL
  *  ---------- | ------- | ----------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function extract($pages = array(), $current = 1, $per_page = 10, $connector = '/')
 {
     // Set default next, previous and step data
     $bucket = array('prev' => false, 'next' => false, 'step' => false);
     $pages = (array) $pages;
     $config = Config::get();
     $speak = Config::speak();
     $base = $config->url;
     $q = str_replace('&', '&amp;', $config->url_query);
     $qq = strpos($connector, '?') !== false ? str_replace('?', '&amp;', $q) : $q;
     $total = count($pages);
     $c = self::$config;
     if (strpos($connector, '%s') === false) {
         if (trim($connector, '/') !== "") {
             $connector = '/' . trim($connector, '/') . '/%s';
         } else {
             $connector = '/%s';
         }
     }
     if (is_int($current)) {
         $current = (int) $current;
         $prev = $current > 1 ? $current - 1 : false;
         $next = $current < ceil($total / $per_page) ? $current + 1 : false;
         // Generate next/previous URL for index page
         $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector);
         $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector);
         // Generate next/previous anchor for index page
         $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector);
         $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $next ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector);
         // Generate pagination anchor(s) for index page
         $html = '<span' . ($c['classes']['pagination'] !== false ? ' class="' . $c['classes']['pagination'] . '"' : "") . '>';
         $chunk = (int) ceil($total / $per_page);
         $step = $chunk > self::$config['step'] ? self::$config['step'] : $chunk;
         $left = $current - $step;
         if ($left < 1) {
             $left = 1;
         }
         if ($chunk > 1) {
             $bucket['step']['url']['first'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, 1) . $qq : false, 1, $connector);
             $bucket['step']['url']['prev'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : false, $prev, $connector);
             $bucket['step']['anchor']['first'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['first'] . '">' . $speak->first . '</a>' : '<span>' . $speak->first . '</span>', 1, $connector);
             $bucket['step']['anchor']['prev'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['prev'] . '" rel="prev">' . $speak->prev . '</a>' : '<span>' . $speak->prev . '</span>', $prev, $connector);
             $html .= $bucket['step']['anchor']['first'] . $bucket['step']['anchor']['prev'];
             $html .= '<span>';
             for ($i = $current - $step + 1; $i < $current + $step; ++$i) {
                 if ($chunk > 1) {
                     if ($i - 1 < $chunk && ($i > 0 && $i + 1 > $current - $left - round($chunk / 2))) {
                         $bucket['step']['url'][$i] = Filter::apply(array('pager:step.url', 'pager:url'), $i !== $current ? $base . sprintf($connector, $i) . $qq : false, $i, $connector);
                         $bucket['step']['anchor'][$i] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $i !== $current ? '<a href="' . $bucket['step']['url'][$i] . '">' . $i . '</a>' : '<strong' . ($c['classes']['current'] !== false ? ' class="' . $c['classes']['current'] . '"' : "") . '>' . $i . '</strong>', $i, $connector);
                         $html .= $bucket['step']['anchor'][$i];
                     }
                 }
             }
             $html .= '</span>';
             $bucket['step']['url']['next'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : false, $next, $connector);
             $bucket['step']['url']['last'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $chunk) . $qq : false, $chunk, $connector);
             $bucket['step']['anchor']['next'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['next'] . '" rel="next">' . $speak->next . '</a>' : '<span>' . $speak->next . '</span>', $next, $connector);
             $bucket['step']['anchor']['last'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['last'] . '">' . $speak->last . '</a>' : '<span>' . $speak->last . '</span>', $chunk, $connector);
             $html .= $bucket['step']['anchor']['next'] . $bucket['step']['anchor']['last'];
         }
         $bucket['step']['html'] = Filter::apply('pager:step.html', $html . '</span>');
     }
     if (is_string($current)) {
         for ($i = 0; $i < $total; ++$i) {
             if ($pages[$i] === $current) {
                 $prev = isset($pages[$i - 1]) ? $pages[$i - 1] : false;
                 $next = isset($pages[$i + 1]) ? $pages[$i + 1] : false;
                 // Generate next/previous URL for single page
                 $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector);
                 $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector);
                 // Generate next/previous anchor for single page
                 $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $bucket['prev']['url'] !== $base ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector);
                 $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $bucket['next']['url'] !== $base ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector);
                 break;
             }
         }
     }
     return Mecha::O($bucket);
 }
开发者ID:yiannisSt,项目名称:mecha-cms,代码行数:101,代码来源:navigator.php



注:本文中的Mecha类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Media类代码示例发布时间:2022-05-23
下一篇:
PHP MbqMain类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap