function edit($ctx) { _render('form'); try { $channel_id = (string) $_GET['id'] !== '' ? intval($_GET['id']) : ''; $m = Channel::get($channel_id); if (!$m) { _redirect($this->_list_url()); return; } $wx_info = WxChannelInfo::get($channel_id); if ($_POST) { $f = $_POST['f']; // 生成二维码 每次保存都更新一次 但是如果已经发放了 其实不能更新的 因为会过期 所以,永久的不能更新 临时的更新可以处理 $expire_type = intval($f['expire_type']); $expire_seconds = intval($f['expire_seconds']); $expire_seconds = max(0, $expire_seconds); $status = intval($f['status']); $wx_info = WxChannelInfo::qrcode_create($channel_id, $expire_type, $expire_seconds, $status); _redirect($this->_list_url()); } $ctx->wx_info = $wx_info; $ctx->m = $m; } catch (Exception $e) { $msg = $e->getMessage(); $ctx->errmsg = $msg; $ctx->m = $m; $ctx->wx_info = $wx_info; } }
function create($ctx) { _render('form'); if (isset($_POST['f']) && $_POST['f']) { $_POST['f']['create_time'] = date('Y-m-d H:i:s'); $_POST['f']['pay_amount'] = Money::yuan2fen($_POST['f']['pay_amount']); Tactics::save($_POST['f']); _redirect($this->_list_url()); } }
function render($_f, $_l = 'layout') { global $v; foreach ($v as $_k => $_v) { ${$_k} = $_v; } ob_start(); include 'views/' . trim($_f) . '.php'; _render(ob_get_clean(), $_l); }
/** * Download and make an addon from a Builder template. * --force will re-download an exist template */ public function handle() { $this->logo(); if ($this->download($template = $this->argument('template'), $this->option('force'))) { /* read the Builder template metadata and return the templaet context object */ $context = $this->getTemplateContext($template); list($vendor, $type, $slug, $path) = _resolveAddonNamespace(_render('{{ vendor }}.{{ type }}.{{ slug }}', $context), $this->option('shared')); $this->dispatch(new ScaffoldTemplate($vendor, $type, $slug, $this->getBuilderPath($template), $path, $context)); $this->info("Builder has successfully created an addon from '{$template}'"); } else { $this->output->error("Builder template not found. Use 'builder:list' command for a list of avilable templates."); } }
function edit($ctx) { _render('form'); if ($_POST) { return $this->save($ctx); } $id = intval($_GET['id']); $m = WxAccount::get($id); if (!$m) { _redirect($this->_list_url()); return; } $ctx->m = $m; }
?> <?php if (isset(${$item}) && $item === 'footer') { ?> <?php $item_layout = $item . '.html.php'; $item_template = realpath(__DIR__ . '/' . $item_layout); if (empty($item_template)) { $item_template = $_template->getTemplate('layouts/' . $item_layout); } if (empty($item_template)) { $item_template = $_template->getTemplate($item_layout); } if (!empty($item_template)) { _render($item_template, array('content' => ${$item})); } else { ?> <div id="<?php _getid($item); ?> " class="structure-<?php echo $item; ?> "> <?php if (is_array(${$item})) { ?> <ul> <?php
/** * Download a Builder template from the registery,. * * @param string $template, the selected template * @param bool $force, force download if the template already exists * * @return bool (true = success) */ protected function download($template, $force = false) { $dist = $this->getBuilderPath(); $path = "{$dist}/{$template}"; if (!$this->files->exists($path) || $force) { $bar = $this->createProgressIndicator(); $src = _render(_config('config.archive'), ['registry' => $this->registry, 'template' => $template]); /* get a temp folder to download the template zip to */ $tmp = $this->getBuilderPath(_config('config.tmp')); try { /* download the template zip file, show progress, uncompress and remove */ $bar->start(" Downloading '{$template}' ... "); $this->files->put($tmp, file_get_contents($src, false, stream_context_create([], ['notification' => function ($notification_code) use($bar) { if (in_array($notification_code, [STREAM_NOTIFY_CONNECT, STREAM_NOTIFY_PROGRESS])) { $bar->advance(); } }]))); $this->zip->open($tmp); $this->zip->extractTo($dist); $this->zip->close(); $this->files->moveDirectory("{$path}-master", $path, true); $this->files->deleteDirectory(dirname($tmp)); $bar->finish(" Download '{$template}' was successful "); } catch (\ErrorException $e) { return false; } } else { $this->output->note("Builder template '{$template}' already exists. \nUse --force option to get a fresh copy."); } return true; }
function save($ctx) { _render('form'); $id = intval($_POST['id']); $m = WxReplyItem::get($id); if ($id && !$m) { _redirect($this->_list_url()); return; } $type = $_POST['type']; $title = $_POST['title']; $desc = $_POST['desc']; $img_url = $_POST['img_url']; $link = $_POST['link']; $content = $_POST['content']; if (!$type) { $ctx->errmsg = "空内容1."; return; } $reply_list = array(); foreach ($type as $index => $mt) { if ($mt == 'text') { $c = $content[$index]; if (!strlen($c)) { continue; } $reply_list[] = array('type' => $mt, 'content' => $c); } else { if ($mt == 'news') { $t = $title[$index]; $d = $desc[$index]; $i = $img_url[$index]; $l = $link[$index]; if (!strlen($t) || !strlen($i) || !strlen($l)) { continue; } $channel_info = WxReplyKeyword::check_channel_subscribe_keyword($_POST['keywords']); if ($channel_info) { // 所有链接带上pcode $arr_query = parse_url($l); parse_str($arr_query['query'], $output); $output['pcode'] = $channel_info->promotion_code; $str_query = http_build_query($output); $l = $arr_query['scheme'] . '://' . $arr_query['host'] . $arr_query['path'] . '?' . $str_query; } $reply_list[] = array('type' => $mt, 'title' => $t, 'desc' => $d, 'img_url' => $i, 'link' => $l); } else { $ctx->errmsg = "异常错误!"; return; } } } if (!$reply_list) { $ctx->errmsg = "空内容2."; return; } $content = Text::json_encode($reply_list); if (!$m) { $m = WxReplyItem::save(array('status' => 0, 'type' => 'mixed', 'content' => $content)); } else { $m->update(array('content' => $content)); $m = WxReplyItem::get($id); } $keyword_type = $_POST['keyword_type']; $m->reset_keywords($_POST['keywords'], $keyword_type); _redirect($this->_list_url()); return; }