本文整理汇总了PHP中Mecha::walk方法的典型用法代码示例。如果您正苦于以下问题:PHP Mecha::walk方法的具体用法?PHP Mecha::walk怎么用?PHP Mecha::walk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mecha
的用法示例。
在下文中一共展示了Mecha::walk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: files
/**
* ==========================================================================
* GET ALL FILE(S) RECURSIVELY
* ==========================================================================
*
* -- CODE: -----------------------------------------------------------------
*
* $files = Get::files(
* 'some/path',
* 'txt',
* 'ASC',
* 'update'
* );
*
* $files = Get::files(
* 'some/path',
* 'gif,jpg,jpeg,png',
* 'ASC',
* 'update'
* );
*
* $files = Get::files(
* 'some/path',
* 'txt',
* 'ASC',
* null,
* 'key:path' // output only the `path` data
* );
*
* --------------------------------------------------------------------------
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Parameter | Type | Desription
* ---------- | ------- | --------------------------------------------------
* $folder | string | Path to folder of file(s) you want to be listed
* $e | string | The file extension(s)
* $order | string | Ascending or descending? ASC/DESC?
* $sorter | string | The key of array item as sorting reference
* $filter | string | Filter the resulted array by a keyword
* $recursive | boolean | Get file(s) from a folder recursively?
* ---------- | ------- | --------------------------------------------------
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
*/
public static function files($folder = ASSET, $e = '*', $order = 'ASC', $sorter = 'path', $filter = "", $recursive = true)
{
$results = array();
$folder = rtrim(File::path($folder), DS);
$e = $e ? explode(',', str_replace(' ', "", $e)) : true;
if ($files = File::explore($folder, $recursive, true, false)) {
if (strpos($filter, 'key:') === 0) {
$s = explode(' ', substr($filter, 4), 2);
$output = $s[0];
$filter = isset($s[1]) ? $s[1] : "";
$sorter = null;
} else {
$output = null;
}
foreach ($files as $k => $v) {
$_k = File::B($k);
$_kk = DS . str_replace($folder . DS, "", $k);
if (!$filter || strpos(File::N($k), $filter) !== false) {
if ($v === 1) {
if ($e === true || $e === array('*') || Mecha::walk($e)->has(File::E($k))) {
$o = File::inspect($k, $output);
if (is_null($output)) {
$o['is']['hidden'] = strpos($_k, '__') === 0 || strpos($_k, '.') === 0 || strpos($_kk, DS . '__') !== false || strpos($_kk, DS . '.') !== false;
}
$results[] = $o;
}
} else {
if ($e === true || $e === array('/')) {
$results[] = File::inspect($k, $output);
}
}
}
}
unset($files, $_k, $_kk);
return !empty($results) ? Mecha::eat($results)->order($order, $sorter)->vomit() : false;
}
return false;
}
示例2: function
Shield::attach('page-' . $slug);
}, 100);
/**
* Home Page
* ---------
*
* [1]. /
*
*/
Route::accept('/', function () use($config, $excludes) {
Session::kill('search.query');
Session::kill('search.results');
$s = Get::articles();
if ($articles = Mecha::eat($s)->chunk(1, $config->index->per_page)->vomit()) {
$articles = Mecha::walk($articles, function ($path) use($excludes) {
return Get::article($path, $excludes);
});
} else {
$articles = false;
}
Filter::add('pager:url', function ($url) {
return Filter::apply('index:url', $url);
});
Config::set(array('articles' => $articles, 'pagination' => Navigator::extract($s, 1, $config->index->per_page, $config->index->slug)));
Shield::attach('page-home');
}, 110);
/**
* Route Hook: after
* -----------------
*/
Weapon::fire('routes_after');
示例3: count
$_path = ASSET . DS . $v;
File::open($_path)->delete();
return $_path;
});
$is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file';
$P = array('data' => array('files' => $info_path));
Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
Weapon::fire(array('on_asset_update', 'on_asset_destruct'), array($P, $P));
Guardian::kick($config->manager->slug . '/asset/1' . str_replace('&', '&', HTTP::query('path', $p)));
} else {
Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete);
}
Shield::lot(array('segment' => 'asset', 'files' => Mecha::O($deletes)))->attach('manager');
});
/**
* Multiple Asset Action
* ---------------------
*/
Route::accept($config->manager->slug . '/asset/do', function ($path = "") use($config, $speak) {
if ($request = Request::post()) {
Guardian::checkToken($request['token']);
if (!isset($request['selected'])) {
Notify::error($speak->notify_error_no_files_selected);
Guardian::kick($config->manager->slug . '/asset/1');
}
$files = Mecha::walk($request['selected'], function ($v) {
return str_replace('%2F', '/', Text::parse($v, '->encoded_url'));
});
Guardian::kick($config->manager->slug . '/asset/' . $request['action'] . '/files:' . implode(';', $files));
}
});
示例4: 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));
示例5: function
<?php
/**
* Post Manager
* ------------
*/
Route::accept(array($config->manager->slug . '/(' . $post . ')', $config->manager->slug . '/(' . $post . ')/(:num)'), function ($segment = "", $offset = 1) use($config, $speak) {
$posts = false;
$offset = (int) $offset;
$s = call_user_func('Get::' . $segment . 's', strtoupper(Request::get('order', 'DESC')), Request::get('filter', ""), 'txt,draft,archive');
if ($files = Mecha::eat($s)->chunk($offset, $config->manager->per_page)->vomit()) {
$posts = Mecha::walk($files, function ($v) use($segment) {
return call_user_func('Get::' . $segment . 'Header', $v);
});
} else {
if ($offset !== 1) {
Shield::abort();
}
}
Config::set(array('page_title' => $speak->{$segment . 's'} . $config->title_separator . $config->manager->title, 'pages' => $posts, 'offset' => $offset, 'pagination' => Navigator::extract($s, $offset, $config->manager->per_page, $config->manager->slug . '/' . $segment), 'cargo' => 'cargo.post.php'));
Shield::lot(array('segment' => $segment))->attach('manager');
});
/**
* Post Repairer/Igniter
* ---------------------
*/
Route::accept(array($config->manager->slug . '/(' . $post . ')/ignite', $config->manager->slug . '/(' . $post . ')/repair/id:(:num)'), function ($segment = "", $id = false) use($config, $speak, $response) {
$units = array('title', 'slug', 'link', 'content', 'content_type', 'description', 'post' . DS . 'author');
foreach ($units as $k => $v) {
Weapon::add('tab_content_1_before', function ($page, $segment) use($config, $speak, $v) {
include __DIR__ . DS . 'unit' . DS . 'form' . DS . $v . '.php';
示例6: array
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'field' . DS . 'title.php';
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'key.php';
?>
<?php
$types = array('text' => $speak->text, 'summary' => $speak->summary, 'boolean' => $speak->boolean, 'option' => $speak->option, 'file' => $speak->file, 'composer' => $speak->composer, 'editor' => $speak->editor);
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'type.php';
?>
<?php
$scopes = Mecha::walk(array_merge(glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR), glob(RESPONSE . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR)), function ($v) {
return File::B($v);
});
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'scope[].php';
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'placeholder.php';
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'value.textarea.php';
?>
<?php
include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'description.text.php';
?>
<div class="grid-group">
示例7: function
Shield::abort();
}
File::write($config->{'__total_' . $segment . 's'})->saveTo(LOG . DS . $segment . 's.total.log', 0600);
if ($files = call_user_func('Get::' . $segment . 's', 'DESC', Request::get('filter', ""), 'txt,hold')) {
$responses_id = Mecha::walk($files, function ($v) {
$parts = explode('_', File::B($v));
return $parts[1];
});
if (strtoupper(Request::get('order', 'DESC')) === 'DESC') {
rsort($responses_id);
} else {
sort($responses_id);
}
$responses_id = Mecha::eat($responses_id)->chunk($offset, $config->manager->per_page)->vomit();
$responses = Mecha::walk($responses_id, function ($v) use($segment) {
return call_user_func('Get::' . $segment, $v);
});
} else {
$files = array();
$responses = false;
}
Config::set(array('page_title' => $speak->{$segment . 's'} . $config->title_separator . $config->manager->title, 'pages' => $responses, 'offset' => $offset, 'pagination' => Navigator::extract($files, $offset, $config->manager->per_page, $config->manager->slug . '/' . $segment), 'cargo' => 'cargo.response.php'));
Shield::lot(array('segment' => array($segment, $post)))->attach('manager');
});
/**
* Response Repairer/Igniter
* -------------------------
*/
Route::accept(array($config->manager->slug . '/(' . $response . ')/ignite', $config->manager->slug . '/(' . $response . ')/repair/id:(:num)'), function ($segment = "", $id = false) use($config, $speak, $post) {
$units = array('name', 'email', 'url', 'message', 'content_type');
foreach ($units as $k => $v) {
示例8: isset
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 . '…', 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;
}
$filters = Mecha::walk(glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR), function ($v) {
return File::B($v) . ':content';
});
Filter::add($filters, 'do_private_post', 30);
示例9: foreach
</th>
<th class="text-center" colspan="2"><?php
echo $speak->action;
?>
</th>
</tr>
</thead>
<tbody>
<?php
foreach ($files as $file) {
?>
<?php
$url = File::url(str_replace($cache_path, "", $file->path));
?>
<tr<?php
echo Mecha::walk(Session::get('recent_item_update', array()))->has(File::B($file->path)) ? ' class="active"' : "";
?>
>
<td class="td-icon"><?php
echo Form::checkbox('selected[]', $url);
?>
</td>
<td class="td-collapse"><time datetime="<?php
echo Date::format($file->update_raw, 'c');
?>
"><?php
echo str_replace('-', '/', $file->update);
?>
</time></td>
<td><span title="<?php
echo $file->size;
示例10: in
/**
* =====================================================================
* CHECK IF TEXT CONTAIN(S) `A` OR `B`
* =====================================================================
*
* -- CODE: ------------------------------------------------------------
*
* if(Text::check('A', 'B')->in($text)) { ... }
*
* ---------------------------------------------------------------------
*
*/
public static function in($text)
{
$arguments = is_array($text) ? $text : func_get_args();
if (count(self::$texts) === 1) {
if (count($arguments) === 1) {
return strpos($arguments[0], self::$texts[0]) !== false;
}
return Mecha::walk($arguments)->has(self::$texts[0]);
}
foreach (self::$texts as $v) {
if (strpos($arguments[0], $v) !== false) {
return true;
}
}
return false;
}
示例11: unset
}
unset($request['content']);
// Remove content from request array
$request['path'] = $results;
File::serialize($request)->saveTo(__DIR__ . DS . 'states' . DS . 'config.txt', 0600);
Notify::success(Config::speak('notify_success_updated', $speak->plugin));
Guardian::kick(File::D($config->url_current));
}
});
/**
* Cache Killer
* ------------
*/
function do_remove_cache()
{
global $config, $c_cache;
foreach ($c_cache->path as $path => $expire) {
$path = str_replace(array('(:any)', '(:num)', '(:all)', '(', ')', '|', '/', ':'), array('*', '[0-9]*', '*', '{', '}', ',', '.', '.'), $path) . '.cache';
if ($cache = File::exist(CACHE . DS . $path)) {
File::open($cache)->delete();
} else {
foreach (glob(CACHE . DS . $path, GLOB_NOSORT | GLOB_BRACE) as $cache) {
File::open($cache)->delete();
}
}
}
}
$hooks = Mecha::walk(glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR), function ($v) {
return 'on_' . File::B($v) . '_update';
});
Weapon::add($hooks, 'do_remove_cache', 10);
示例12: array
<?php
$name = $_FILES['file']['name'];
$mime = $_FILES['file']['type'];
$extension = File::E($name);
$mime_accept = array('application/download', 'application/octet-stream', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip');
$extension_accept = array('zip');
$path = File::N($name);
if (!empty($name)) {
if (File::exist($destination . DS . $path)) {
Notify::error(Config::speak('notify_folder_exist', '<code>' . $path . '</code>'));
} else {
if (!Mecha::walk($mime_accept)->has($mime) || !Mecha::walk($extension_accept)->has($extension)) {
Notify::error(Config::speak('notify_invalid_file_extension', 'ZIP'));
}
}
} else {
Notify::error($speak->notify_error_no_file_selected);
}
示例13: recentResponse
/**
* Widget Recent Response
* ----------------------
*
* [1]. Widget::recentResponse();
* [2]. Widget::recentResponse(5);
*
*/
public static function recentResponse($total = 7, $avatar_size = 50, $summary = 100, $d = 'monsterid', $folder = array(COMMENT, ARTICLE))
{
$T1 = TAB;
$T2 = str_repeat($T1, 2);
$T3 = str_repeat($T1, 3);
$T4 = str_repeat($T1, 4);
$T5 = str_repeat($T1, 5);
$r = $folder[0] !== RESPONSE ? File::B($folder[0]) : 'response';
$p = $folder[1] !== POST ? File::B($folder[1]) : 'post';
$id = Config::get('widget_recent_' . $r . '_id', 0) + 1;
$config = Config::get();
$speak = Config::speak();
$html = O_BEGIN . '<div class="widget widget-recent widget-recent-response" id="widget-recent-response-' . $id . '">' . NL;
if ($responses = call_user_func('Get::' . $r . 's')) {
$responses_id = Mecha::walk($responses, function ($v) {
$parts = explode('_', File::B($v));
return $parts[1];
});
rsort($responses_id);
$html .= $T1 . '<ul class="recent-responses">' . NL;
for ($i = 0, $count = count($responses_id); $i < $total; ++$i) {
if ($i === $count) {
break;
}
$response = call_user_func('Get::' . $r, $responses_id[$i]);
$post = call_user_func('Get::' . $p . 'Anchor', $response->post);
$html .= $T2 . '<li class="recent-response">' . NL;
if ($avatar_size !== false && $avatar_size > 0) {
$html .= $T3 . '<div class="recent-response-avatar">' . NL;
$html .= $T4;
$attr = ' alt="" width="' . $avatar_size . '" height="' . $avatar_size . '"';
if ($avatar = File::exist(ASSET . DS . '__avatar' . DS . $avatar_size . 'x' . $avatar_size . DS . md5($response->email) . '.png')) {
$html .= Asset::image($avatar, $attr);
} else {
if ($avatar = File::exist(ASSET . DS . '__avatar' . DS . '60x60' . DS . md5($response->email) . '.png')) {
$html .= Asset::image($avatar, $attr);
} else {
if ($avatar = File::exist(ASSET . DS . '__avatar' . DS . md5($response->email) . '.png')) {
$html .= Asset::image($avatar, $attr);
} else {
$html .= Asset::image($config->protocol . 'www.gravatar.com/avatar/' . md5($response->email) . '?s=' . $avatar_size . '&d=' . urlencode($d), $attr);
}
}
}
$html .= $T3 . '</div>' . NL;
}
$html .= $T3 . '<div class="recent-response-header">' . NL;
if ($response->url === '#') {
$html .= $T4 . '<span class="recent-response-name">' . $response->name . '</span>' . NL;
} else {
$html .= $T4 . '<a class="recent-response-name" href="' . $response->url . '" rel="nofollow">' . $response->name . '</a>' . NL;
}
$html .= $T3 . '</div>' . NL;
$html .= $T3 . '<div class="recent-response-body">' . Converter::curt($response->message, $summary, $config->excerpt->suffix) . '</div>' . NL;
$html .= $T3 . '<div class="recent-response-footer">' . NL;
$html .= $T4 . '<span class="recent-response-time">' . NL;
$html .= $T5 . '<time datetime="' . $response->date->W3C . '">' . $response->date->FORMAT_3 . '</time> <a title="' . ($post ? Text::parse($post->title, '->text') : $speak->notify_error_not_found) . '" href="' . $response->permalink . '" rel="nofollow">#</a>' . NL;
$html .= $T4 . '</span>' . NL;
$html .= $T3 . '</div>' . NL;
$html .= $T2 . '</li>' . NL;
}
$html .= $T1 . '</ul>' . NL;
} else {
$html .= $T1 . Config::speak('notify_empty', strtolower($speak->{$r . 's'})) . NL;
}
$html .= '</div>' . O_END;
Config::set('widget_recent_' . $r . '_id', $id);
return Filter::apply(array('widget:recent.' . $r, 'widget:recent.response', 'widget:recent', 'widget'), $html, $id);
}
示例14: isset
if (strpos(DS . $path . DS, DS . '..' . DS) !== false) {
Shield::abort();
}
// File not found
if (!($snippet = File::exist(ASSET . DS . '__snippet' . DS . $x . DS . $path . '.' . $x))) {
Shield::abort();
}
$content = File::open($snippet)->read();
// Allow to run `printf` in snippet content for `txt` file
if ($x === 'txt') {
$lot = isset($get['lot']) ? explode(',', $get['lot']) : false;
if ($lot !== false && strpos($content, '%') !== false) {
// `http://stackoverflow.com/a/2053931`
if (preg_match_all('#%(?:(\\d+)[$])?[-+]?(?:[ 0]|[\'].)?(?:[-]?\\d+)?(?:[.]\\d+)?[%bcdeEfFgGosuxX]#', $content, $matches)) {
$lot = Mecha::walk($lot, function ($v) {
return str_replace(',', ',', $v);
});
if (count($lot) >= count(array_unique($matches[1]))) {
$content = vsprintf($content, $lot);
}
}
}
}
// Apply `do_snippet` filter if available
if (function_exists('do_snippet')) {
// Allow nested snippet(s) two time(s)
$content = do_snippet(do_snippet($content));
}
// Apply all post content filter to the snippet output
$filters = array();
foreach (glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR) as $post) {
示例15: isset
// Loading the language file(s)
$lang = LANGUAGE . DS . 'en_US' . DS . 'speak.txt';
$lang_a = LANGUAGE . DS . $config['language'] . DS . 'speak.txt';
if (!file_exists($lang) && !file_exists($lang_a)) {
Guardian::abort('Language file not found.');
}
$lang = Text::toArray(File::open($lang)->read(""), S, ' ');
if ($config['language'] !== 'en_US') {
$lang_a = Text::toArray(File::open($lang_a)->read(""), S, ' ');
Mecha::extend($lang, $lang_a);
}
$config['query'] = $config['url_query'] = HTTP::query($_GET);
$config['offset'] = isset($s[1]) && is_numeric($s[1]) ? (int) $s[1] : 1;
$config['page_type'] = $page;
$config['speak'] = $lang;
$config['is'] = array('post' => $page !== '404' && Mecha::walk(glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR))->has(POST . DS . $page), 'posts' => Mecha::walk(array('index', 'tag', 'archive', 'search', ""))->has($page), 'response' => false, 'responses' => false);
unset($ss, $s, $lang, $lang_a);
Config::set($config);
});
/**
* =============================================================
* GET LANGUAGE FILE TO SPEAK
* =============================================================
*
* -- CODE: ----------------------------------------------------
*
* echo Config::speak('home');
*
* -------------------------------------------------------------
*
* echo Config::speak('action')->save;