public static function ApplyExtends($view) { global $__env; extract(\View::getShared()); foreach (static::$compiles as $function) { if (!method_exists(__CLASS__, $function = 'compile_' . $function)) { continue; } $view = call_user_func([__CLASS__, $function], $view, $__env); } return $view; }
public function input() { if (!$this->relation->getRelatedModel()) { throw new \Exception('missing relation in config for the current model.'); } $this->fields = array_get(\View::getShared(), 'fields'); $id = $this->fields['id']->value; $modelName = $this->relation->getRelatedModel(); $model = Artificer::modelManager()->get($modelName); $this->modelManager = $model; if ((Route::currentRouteName() == 'admin.model.create' || Route::currentRouteName() == 'admin.model.field') && Session::has('_set_relation_on_create_' . $this->modelSettings->name)) { $relateds = Session::get('_set_relation_on_create_' . $this->modelSettings->name); $related_ids = []; foreach ($relateds as $related) { $related_ids[] = $related['id']; } $data = $relateds[0]['modelClass']::whereIn('id', $related_ids)->get()->toArray(); } else { $data = $model['class']::where($this->relation->getForeignKey(), '=', $id)->get(['id', $this->relation->getShow()])->toArray(); } $this->showItems($data); $this->createRoute = $this->createRoute($this->modelManager['route']) . '?' . http_build_query([$this->relation->getForeignKey() => $id, '_standalone' => 'true']); if (!Request::ajax() || $this->showFullField) { $this->relationModal($this->modelManager['route'], $id); ?> <div class="text-right"> <div class="btn-group"> <button class="btn btn-default" data-toggle="modal" data-url="<?php echo $this->createRoute; ?> " data-target="#form-modal-<?php echo $this->modelManager['route']; ?> "> <i class="fa fa-plus"></i> </button> </div> </div> <?php } }
<?php $classnavact = "menu-list nav-active"; $classnav = "menu-list"; $menuact = "class=active"; $act = null; $act = View::getShared(); ?> <ul class="nav nav-pills nav-stacked custom-nav"> <?php $data = Config::get('menu.menu'); ?> @foreach($data as $value) @if (isset($value['header'])) <li class="nav-header">{{$value['header']}}</li> @endif @foreach($value['items'] as $item) <li class="@if($item['id']==$act['ids']['navid']){{$classnavact}}@else{{$classnav}}@endif" id="{{$item['id']}}"> <a href="#"> <i class="@if(isset($item['class'])){{$item['class']}}@endif"></i> <span>{{$item['name']}}</span> <i class="ion ion-ios7-arrow-down pull-right"></i> </a> <ul class="sub-menu-list"> @foreach($item['menu'] as $subvalue) <li @if($subvalue['id']==$act['ids']['act']){{$menuact}}@endif id="{{$subvalue['name']}} "><a href="{{$subvalue['url']}}">{{$subvalue['name']}}</a></li> @endforeach </ul> </li>
/** * Require the template file with WordPress environment. * * The globals are set up for the template file to ensure that the WordPress * environment is available from within the function. The query variables are * also available. * * @since 1.5.0 * * @global array $posts * @global WP_Post $post * @global bool $wp_did_header * @global WP_Query $wp_query * @global WP_Rewrite $wp_rewrite * @global wpdb $wpdb * @global string $wp_version * @global WP $wp * @global int $id * @global object $comment * @global int $user_ID * * @param string $_template_file Path to template file. * @param bool $require_once Whether to require_once or require. Default true. */ function load_template($_template_file, $require_once = true) { global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; if (is_array($wp_query->query_vars)) { extract($wp_query->query_vars, EXTR_SKIP); } if (isset($s)) { $s = esc_attr($s); } if ($require_once === null) { return $_template_file; } extract(View::getShared(), EXTR_REFS); if ($isBlade = preg_match("/\\.blade\\.php\$/", $_template_file)) { $tplfile = str_replace(['Resources/views/', '.blade.php'], '', substr($_template_file, strlen(get_template_directory()) + 1)); //echo View::make($tplfile)->with(array_except(get_defined_vars(), array('__data', '__path'))); //echo View::file($_template_file)->with(array_except(get_defined_vars(), array('__data', '__path')) ); try { error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); echo View::file($_template_file)->with(array_except(get_defined_vars(), array('__data', '__path')))->render(); } catch (Exception $e) { kd($e); } return ''; } if ($require_once) { require_once $_template_file; } else { require $_template_file; } }
public static function get($name) { return array_get(\View::getShared(), 'fields')[$name]; }
public function register() { if (!class_exists('OT_Loader')) { require_once __DIR__ . '/option-tree/ot-loader.php'; } (new \OT_Loader())->load_option_tree(); foreach (glob(__DIR__ . '/Helpers/*.php') as $file) { if (preg_match("/^\\w+/", basename($file))) { require $file; } } //使WordPress支持post thumbnail if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); } // 支持自定义菜单 if (function_exists('register_nav_menus')) { register_nav_menus(array('header-menu' => __('网站主菜单'), "person-menu" => __('用户菜单'), "profile" => __('用户资料侧边栏'))); } $sidebars = array('sidebar-profile', 'Post Sidebar', 'Page Sidebar'); foreach ($sidebars as $name) { register_sidebar(array('name' => $name, 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>')); } register_sidebar(['name' => '会员资料', 'before_widget' => '<li class="list-group-item">', 'after_widget' => '</li>', 'before_title' => '<h3 class="hide">', 'after_title' => '</h3>']); if (function_exists('add_image_size')) { add_image_size('60x60', 60, 60, true); // (cropped) add_image_size('245x163', 245, 163, true); // (cropped) add_image_size('337x225', 337, 225, true); // (cropped) } /* //自动选择模板的函数 //通过 single_template 钩子挂载函数 add_filter('single_template', function ($single) { //定义模板文件所在目录为 single 文件夹 define('SINGLE_PATH', TEMPLATEPATH . '/single'); global $wp_query, $post; //通过分类别名或ID选择模板文件 $ext = '.blade.php'; foreach ((array)get_the_category() as $cat) : if (file_exists(SINGLE_PATH . '/' . $cat->slug . $ext)) { return SINGLE_PATH . '/' . $cat->slug . $ext; } elseif (file_exists(SINGLE_PATH . '/' . $cat->term_id . $ext)) { return SINGLE_PATH . '/' . $cat->term_id . $ext; } endforeach; return $single; }); */ add_action('load-themes.php', function () { if ($GLOBALS['pagenow'] != 'themes.php' || !isset($_GET['activated'])) { return; } //仅主题启用时执行 flush_rewrite_rules(); //更新伪静态规则, 解决自定义文章类型页面 404 的问题 }); add_filter('excerpt_more', function ($more) { return option('excerpt_more', ' ...'); }); add_filter('excerpt_length', function ($length) { return option('excerpt_length', 200); }); //apply_filters('logout_url', 'my_fixed_wp_logout_url'); add_filter('show_admin_bar', '__return_false'); add_filter('gettext', function ($translated, $text, $domain) { if ($domain != 'cutlass') { $t = __($text, 'cutlass'); if ($t != $text) { $translated = $t; } } return $translated; }, 10, 3); //让主题支持语言包 add_action('after_setup_theme', function () { load_theme_textdomain('cutlass', get_template_directory() . '/Resources/lang'); $locale = get_locale(); $locale_file = get_template_directory() . "/Resources/lang/{$locale}.php"; if (is_readable($locale_file)) { require_once $locale_file; } }); /*只能查看自己的文章评论*/ if (!current_user_can("edit_others_posts")) { add_filter("comments_clauses", function ($clauses) { if (is_admin() && !current_user_can("edit_others_posts")) { global $user_ID, $wpdb; $clauses["join"] = ", wp_posts"; $clauses["where"] .= " AND wp_posts.post_author = " . $user_ID . " AND wp_comments.comment_post_ID = wp_posts.ID"; } return $clauses; }); } /*只能查看自己发布的文章*/ add_filter("parse_query", function (\WP_Query $wp_query) { if (strpos($_SERVER["REQUEST_URI"], "/wp-admin/edit.php") !== false) { if (!current_user_can("edit_others_posts")) { global $current_user; $wp_query->set("author", $current_user->id); } } }); /** * WordPress 媒体库只显示用户自己上传的文件 * http://www.wpdaxue.com/view-user-own-media-only.html */ //在文章编辑页面的[添加媒体]只显示用户自己上传的文件 add_action('pre_get_posts', function (\WP_Query $wp_query_obj) { if (current_user_can("edit_others_posts")) { return; } global $current_user, $pagenow; if (!is_a($current_user, 'WP_User')) { return; } if ('admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments') { return; } if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) { $wp_query_obj->set('author', $current_user->ID); } return; }); //在[媒体库]只显示用户上传的文件 add_filter('parse_query', function (\WP_Query $wp_query) { if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false) { if (!current_user_can("edit_others_posts") && !current_user_can('manage_media_library')) { global $current_user; $wp_query->set('author', $current_user->id); } } }); // 为页面添加 Blade 解析功能 /** @todo 修复模板解析 * 格式: <pre tpl="section_name">...</pre> * 或者: <pre tpl>...</pre> * 星期三[1537]2015-09-09/06:01:58.221+0800 @foolant */ add_filter('the_content', function ($content) { if (!is_page()) { return $content; } extract($GLOBALS, EXTR_SKIP); extract(\View::getShared()); if (preg_match_all("/\\s*<pre[^>]+tpl(\\=(\")?(\\w+)\\2)?[^>]*?>(.+?)<\\/pre>\\s*/s", $content, $ms, PREG_SET_ORDER)) { foreach ($ms as $match) { list($all, $tplsign, $t, $tpl, $code) = $match; if ($tpl) { $code = "@section('{$tpl}')\n{$code}\n@endsection"; } $generated = \Blade::compileString($code); ob_start(); try { eval("?>" . $generated); } catch (\Exception $e) { ob_get_clean(); throw $e; } $result = ob_get_clean(); $content = str_replace($all, $result, $content); } } return $content; }); require __DIR__ . '/Helpers/admin/theme-options.php'; /* function auto_login_new_user($user_id) { // 这里设置的是跳转到首页,要换成其他页面 // 可以将home_url()改成你指定的URL // 如 wp_redirect( 'http://www.baidu.com' ); //wp_redirect( home_url() ); //exit; } */ // 用户注册成功后自动登录,并跳转到指定页面 // 不能使用, 后台手工注册用户也会自动登录 add_action('user_register', function ($user_id) { if (!is_admin()) { wp_set_current_user($user_id); wp_set_auth_cookie($user_id); } }); add_filter('get_user_option_admin_color', function () { return 'midnight'; }); //为新用户预设默认的后台配色方案 function set_default_admin_color($user_id) { $args = array('ID' => $user_id, 'admin_color' => 'midnight'); wp_update_user($args); } add_action('user_register', 'set_default_admin_color'); //在菜单中添加退出 add_filter('wp_nav_menu_items', function ($items, $args) { global $wp; //Nav location in your theme. In this case, primary nav. Adjust accordingly. if ($args->theme_location != 'person-menu' || !is_user_logged_in()) { return $items; } $link = '<a title="' . __('退出') . '" href="' . wp_logout_url(home_url(add_query_arg(array(), $wp->request))) . '">' . __('退出') . '</a>'; return $items .= ' <li id="loginout-link" class="menu-item menu-type-link">' . $link . '</li> '; }, 10, 2); //添加默认头像 add_filter('avatar_defaults', function ($avatar_defaults) { $myavatar = home_url('/static/assets/avatar.png'); $avatar_defaults[$myavatar] = __("本地默认头像"); return $avatar_defaults; }); add_filter('get_avatar', function ($url) { if (preg_match("/gravatar\\.com/", $url)) { return preg_replace("/src\\=\"(.+?)\"/", 'src="/static/assets/avatar.png"', $url); } return $url; }); // wpuf 用户表单显示hook add_action('form_register_userform', function ($form_id, $post_id, $form_settings) { // do what ever you want //kd(func_get_args()); }, 10, 3); // wpuf 填写注册表单后自动登录 //add_action('wpuf_after_register', function ($user_id, $userdata, $form_id, $form_settings) { // // return true; //}, 10, 3); /** @todo 注册小部件 星期一[1537]2015-09-07/16:15:45.814+0800 @foolant */ $this->registerWidgets(); }
protected function getData() { return \View::getShared()['data']; }