function getDiffTime($pointNumber = 'point', $getTotalDiff = false, $exit = false) { global $timeValue, $resTimeValue; //$curr = time(); $curr = microtime(1); if ($timeValue == 0) { $res = 0; } else { $res = $curr - $timeValue; } $resTimeValue += $res; $timeValue = $curr; if (isConsole()) { echo "-- " . date('H:i:s', $timeValue) . " -> " . number_format($res, 4) . " -> [" . $pointNumber . "] \n"; if ($getTotalDiff == true) { echo '-- TOTAL TIME DIFF: ' . number_format($resTimeValue, 4) . " --\n"; } } else { echo " <br/>" . date('H:i:s', $timeValue) . " -> " . number_format($res, 4) . " -> [" . $pointNumber . "] <br/>"; if ($getTotalDiff == true) { echo 'TOTAL TIME DIFF: ' . number_format($resTimeValue, 4) . '<br/>'; } } if ($exit) { exit; } }
/** * 指定されたURLに対応しRouterパース済のCakeRequestのインスタンスを返す * * @param string $url URL * @return CakeRequest */ protected function _getRequest($url) { Router::reload(); $request = new CakeRequest($url); // コンソールからのテストの場合、requestのパラメーターが想定外のものとなってしまうので調整 if (isConsole()) { $baseUrl = Configure::read('App.baseUrl'); if ($request->url === false) { $request->here = $baseUrl . '/'; } elseif (preg_match('/^' . preg_quote($request->webroot, '/') . '/', $request->here)) { $request->here = $baseUrl . '/' . preg_replace('/^' . preg_quote($request->webroot, '/') . '/', '', $request->here); } if ($baseUrl) { if (preg_match('/^\\//', $baseUrl)) { $request->base = $baseUrl; } else { $request->base = '/' . $baseUrl; } $request->webroot = $baseUrl; } else { $request->base = ''; $request->webroot = '/'; } } Router::setRequestInfo($request); $params = Router::parse($request->url); $request->addParams($params); return $request; }
public function make($routeName = null, $arguments = [], $absolute = false, $envPrefix = true) { if (!$routeName) { $routeName = $this->data["name"]; } foreach ($this->routes as $routeArr) { foreach ($routeArr as $route) { if ($route["name"] == $routeName) { $args = []; foreach ($arguments as $key => $val) { $args["[" . $key . "]"] = $val; } foreach ($route['resolvers'] ?? [] as $key => $resolver) { /** * If index is not set, argument should be resolved by post/get data or similar. * T00D00 - this needs to be resolved without proper index (find by class) */ if (isset($args['[' . $key . ']'])) { $args['[' . $key . ']'] = resolve($resolver)->parametrize($args['[' . $key . ']']); } } if ($args) { /** * Replace parameters in url. */ foreach ($args as $key => &$arg) { if (is_string($arg)) { if (strpos(strtolower($key), 'url') !== false) { $arg = sluggify($arg); } else { $arg = urlencode($arg); } } } $filteredArgs = (new Collection($args))->reduce(function ($item) { return !is_object($item); }, true)->all(); $route['url'] = str_replace(array_keys($filteredArgs), $filteredArgs, $route['url']); } return ($absolute || isConsole() ? $this->config->get("protocol") . '://' . ($this->config->get("domain") ?? $_SERVER['HTTP_HOST']) : "") . ($envPrefix && dev() && !isConsole() ? "/dev.php" : "") . $route["url"]; } } } }
/** * コンストラクタ * * @param boolean $id * @param string $table * @param string $ds */ public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); if (isConsole() && !isInstalled()) { App::uses('PageCategory', 'Model'); $this->PageCategory = new PageCategory(null, null, $ds); } }
/** * ページリストを取得する * * @param mixid $parentCategoryId / '' / 0 * @return type * @access public */ public function get_page_list_recursive($parentCategoryId = null, $recursive = null) { if (isConsole()) { $this->Page = ClassRegistry::init('Page'); } return $this->__getPageListRecursive($parentCategoryId, $recursive); }
set_time_limit(600); require_once 'debug.php'; require_once 'const.php'; require_once BASE_DIR . 'classes/KDGLoader.php'; $config = array(); $config['db_user'] = DB_USERNAME; $config['db_password'] = DB_PASSWORD; $config['db_host'] = DB_SERVER; $config['db_name'] = DB_DATABASE; KDGLoader::loadLibraryClass('KDGGeneral'); KDGLoader::loadLibraryClass('KDGSession'); KDGLoader::loadLibraryClass('KDGModel'); KDGLoader::loadLibraryClass('Encoding'); KDGLoader::loadLibraryClass('KDGMemory'); KDGLoader::loadLibraryClass('ISDString'); KDGLoader::loadLibraryClass('Inflector'); KDGLoader::loadLibraryClass('KDGEntity'); KDGLoader::loadLibraryClass('KDGParser'); KDGLoader::loadLibraryClass('KDGCrawler'); KDGLoader::loadLibraryClass('KDGDatabase'); KDGLoader::loadLibraryClass('KDGInflector'); if (isConsole() && isset($argv) && $argv) { foreach ($argv as $val) { if (stristr($val, '=')) { $parts = explode('=', $val); if (isset($parts[0]) && isset($parts[1])) { setRequestParameter($parts[0], $parts[1]); } } } }
protected function sendBuffered($content = null) { if ($content) { echo $content . (isConsole() ? "\n" : '</br>'); } @ob_flush(); @flush(); }
/** * セッションメッセージを出力する */ public function testFlash() { // TODO コンソールからのセッションのテストをどうするか?そもそもするか? ryuring if (isConsole()) { return; } $messsage = 'エラーが発生しました。'; App::uses('SessionComponent', 'Controller/Component'); App::uses('ComponentCollection', 'Controller/Component'); $Session = new SessionComponent(new ComponentCollection()); $Session->setFlash($messsage); ob_start(); $this->BcBaser->flash(); $result = ob_get_clean(); $this->assertEqual($result, '<div id="MessageBox"><div id="flashMessage" class="message">' . $messsage . '</div></div>'); }
/** * サイトのトップレベルのURLを取得する * * @param boolean $lastSlash * @return string */ function topLevelUrl($lastSlash = true) { if (isConsole()) { return false; } $protocol = 'http://'; if (!empty($_SERVER['HTTPS'])) { $protocol = 'https://'; } $host = $_SERVER['HTTP_HOST']; $url = $protocol . $host; if ($lastSlash) { $url .= '/'; } return $url; }
/** * コンストラクタ * * @param View $View ビュークラス * @param array $settings ヘルパ設定値(BcBaserHelper では利用していない) */ public function __construct(View $View, $settings = array()) { parent::__construct($View, $settings); // モデルクラスをセット // 一度初期化した後に再利用し、処理速度を向上する為にコンストラクタでセットしておく if ($this->_View && BC_INSTALLED && !Configure::read('BcRequest.isUpdater') && !Configure::read('BcRequest.isMaintenance')) { // DBに接続できない場合、CakePHPのエラーメッセージが表示されてしまう為、 try を利用 try { $this->_Permission = ClassRegistry::init('Permission'); $this->_Page = ClassRegistry::init('Page'); } catch (Exception $ex) { } } // サイト基本設定データをセット if (BC_INSTALLED || isConsole()) { $this->siteConfig = $this->_View->get('siteConfig', array()); } // プラグインのBaserヘルパを初期化 if (BC_INSTALLED && !Configure::read('BcRequest.isUpdater') && !Configure::read('BcRequest.isMaintenance')) { $this->_initPluginBasers(); } }
public function execute(callable $next) { if (isConsole()) { return $next(); } $router = router()->get(); $routeName = $router['name']; foreach (config('pckg.auth.gates', []) as $gate) { $auth = auth($gate['provider']); /** * Check status rules. */ if ($gate['status']) { if ($gate['status'] == 'logged-out' && $auth->isLoggedIn()) { continue; } elseif ($gate['status'] == 'logged-in' && !$auth->isLoggedIn()) { continue; } } /** * Check user group rules. */ if ($gate['userGroup']) { if (!in_array($auth->getGroupId(), $gate['userGroup'])) { continue; } } /** * Check if route is excluded in rule. */ if (isset($gate['exclude'])) { if (in_array($routeName, $gate['exclude'])) { continue; } foreach ($gate['exclude'] as $route) { if (preg_match('#' . $route . '#', $routeName)) { continue; } } } /** * Check if route is included in rule. */ if (isset($gate['include']) && !in_array($routeName, $gate['include'])) { $found = false; foreach ($gate['include'] as $route) { if (preg_match('#' . $route . '#', $routeName)) { $found = true; break; } } if (!$found) { continue; } } /** * Check for callback. */ if (isset($gate['callback'])) { if (Reflect::method($gate['callback']['class'], $gate['callback']['method'])) { continue; } } redirect(url($gate['redirect'])); } return $next(); }
/** * セッションメッセージを出力する * * @return void */ public function testFlash() { // TODO コンソールからのセッションのテストをどうするか?そもそもするか? ryuring if (isConsole()) { return; } $message = 'エラーが発生しました。'; $this->expectOutputString('<div id="MessageBox"><div id="flashMessage" class="message">' . $message . '</div></div>'); App::uses('SessionComponent', 'Controller/Component'); App::uses('ComponentCollection', 'Controller/Component'); $Session = new SessionComponent(new ComponentCollection()); $Session->setFlash($message); $this->BcBaser->flash(); }
/** * Before render * * @param Controller $controller * @return void */ public function beforeRender(Controller $controller) { parent::beforeRender($controller); if (BcUtil::isAdminSystem()) { $controller->set('contentsSettings', $this->settings['items']); // パンくずをセット array_unshift($controller->crumbs, array('name' => 'コンテンツ一覧', 'url' => array('plugin' => null, 'controller' => 'contents', 'action' => 'index'))); if ($controller->subMenuElements && !in_array('contents', $controller->subMenuElements)) { array_unshift($controller->subMenuElements, 'contents'); } else { $controller->subMenuElements = ['contents']; } if ($this->useForm && in_array($controller->request->action, [$this->editAction, 'admin_edit_alias']) && !empty($controller->request->data['Content'])) { // フォームをセット $this->settingForm($controller, $controller->request->data['Content']['site_id'], $controller->request->data['Content']['id']); // フォームを読み込む為のイベントを設定 // 内部で useForm を参照できない為、ここに記述。 // フォームの設定しかできないイベントになってしまっている。 // TODO 改善要 App::uses('BcContentsEventListener', 'Event'); CakeEventManager::instance()->attach(new BcContentsEventListener()); } } else { // ビューキャッシュ設定 if (empty($controller->request->query['preview'])) { // @deprecated 5.0.0 since 4.0.0 // CakePHP3では、ビューキャッシュは廃止となる為、別の方法に移行する if ($this->useViewCache && !BcUtil::loginUser('admin') && !isConsole() && !empty($controller->request->params['Content'])) { $controller->helpers[] = 'BcCache'; $controller->cacheAction = $controller->Content->getCacheTime($controller->request->params['Content']); } } } }
/** * ビューを表示する * * @param mixed * @return void * @access public */ public function display() { $path = func_get_args(); // CUSTOMIZE ADD 2014/07/02 ryuring // >>> if (is_array($path) && count($path) == 1) { $path = explode('/', $path[0]); } $url = '/' . implode('/', $path); // モバイルディレクトリへのアクセスは Not Found if (isset($path[0]) && ($path[0] == Configure::read('BcAgent.mobile.prefix') || $path[0] == Configure::read('BcAgent.smartphone.prefix'))) { $this->notFound(); } // <<< $count = count($path); if (!$count) { return $this->redirect('/'); } $page = $subpage = $titleForLayout = null; if (!empty($path[0])) { $page = $path[0]; } if (!empty($path[1])) { $subpage = $path[1]; } if (!empty($path[$count - 1])) { $titleForLayout = Inflector::humanize($path[$count - 1]); } // CUSTOMIZE ADD 2014/07/02 ryuring // >>> $agentAlias = Configure::read('BcRequest.agentAlias'); if ($agentAlias) { $checkUrl = '/' . $agentAlias . $url; } else { $checkUrl = $url; } // 固定ページを保存する際、非公開の場合でも、検索用データを作成時に // requestAction で呼ばれる為、requestAction時には無視する仕様とする if (empty($this->request->params['requested']) && !$this->Page->checkPublish($url)) { $this->notFound(); } // キャッシュ設定 // TODO 手法検討要 // Consoleから requestAction で呼出された場合、getCacheTimeがうまくいかない // Consoleの場合は実行しない if (!isset($_SESSION['Auth']['User']) && !isConsole()) { $this->helpers[] = 'BcCache'; $this->cacheAction = $this->Page->getCacheTime($checkUrl); } // ナビゲーションを取得 $this->crumbs = $this->_getCrumbs($url); $this->subMenuElements = array('default'); // <<< $this->set(array('page' => $page, 'subpage' => $subpage, 'title_for_layout' => $titleForLayout)); // CUSTOMIZE ADD 2014/07/02 ryuring // >>> $data = $this->Page->findByUrl($checkUrl); $template = $layout = $agent = ''; if (Configure::read('BcRequest.agent')) { $agent = '_' . Configure::read('BcRequest.agent'); } if (empty($data['PageCategory']['id'])) { if (!empty($this->siteConfigs['root_layout_template' . $agent])) { $layout = $this->siteConfigs['root_layout_template' . $agent]; } if (!empty($this->siteConfigs['root_content_template' . $agent])) { $template = 'templates/' . $this->siteConfigs['root_content_template' . $agent]; } else { $template = join('/', $path); } } else { if (!empty($data['PageCategory']['layout_template'])) { $layout = $data['PageCategory']['layout_template']; } if (!empty($data['PageCategory']['content_template'])) { $template = 'templates/' . $data['PageCategory']['content_template']; } else { $template = join('/', $path); } } if ($layout) { $this->layout = $layout; } if ($template) { $this->set('pagePath', implode('/', $path)); } else { $template = implode('/', $path); } // <<< try { // CUSTOMIZE MODIFY 2014/07/02 ryuring // >>> //$this->render(implode('/', $path)); // --- $this->render($template); // <<< } catch (MissingViewException $e) { if (Configure::read('debug')) { throw $e; } throw new NotFoundException(); } }
/** * サイトのトップレベルのURLを取得する * * @param boolean $lastSlash * @return string */ function topLevelUrl($lastSlash = true) { if (isConsole() && empty($_SERVER['HTTP_HOST'])) { return Configure::read('App.fullBaseUrl'); } $protocol = 'http://'; if (!empty($_SERVER['HTTPS'])) { $protocol = 'https://'; } $host = $_SERVER['HTTP_HOST']; $url = $protocol . $host; if ($lastSlash) { $url .= '/'; } return $url; }
/** * サイトの設置URLを取得する */ public function testSiteUrl() { if (isConsole()) { $this->assertEquals('http://localhost/', siteUrl()); } else { $topLevelUrl = topLevelUrl(false); Configure::write('App.baseUrl', '/test/'); $this->assertEquals($topLevelUrl . '/test/', siteUrl()); Configure::write('App.baseUrl', '/test/index.php'); $this->assertEquals($topLevelUrl . '/test/', siteUrl()); Configure::write('App.baseUrl', '/test/hoge/'); $this->assertEquals($topLevelUrl . '/test/hoge/', siteUrl()); } }
/** * ページリストを取得する * * @param mixid $parentCategoryId / '' / 0 * @return type * @access public */ public function get_page_list_recursive($parentCategoryId = null, $recursive = null) { if (isConsole()) { $this->Page = new Page(null, null, 'baser'); } return $this->__getPageListRecursive($parentCategoryId, $recursive); }
/** * コンストラクタ * * @param CakeRequest $request リクエストオブジェクト * @param CakeResponse $response レスポンスオブジェクト */ public function __construct($request = null, $response = null) { parent::__construct($request, $response); if (isConsole()) { unset($this->components['Session']); } // テンプレートの拡張子 $this->ext = Configure::read('BcApp.templateExt'); $isRequestView = $request->is('requestview'); $isInstall = $request->is('install'); // インストールされていない場合、トップページにリダイレクトする // コンソールベースのインストールの際のページテンプレート生成において、 // BC_INSTALLED、$isInstall ともに true でない為、コンソールの場合は無視する if (!(BC_INSTALLED || isConsole()) && !$isInstall) { $this->redirect('/'); } // コンソールベースのインストールの際のページテンプレート生成において、 // BC_INSTALLEDが true でない為、コンソールの場合も実行する if ((BC_INSTALLED || isConsole()) && $isRequestView) { // サイト基本設定の読み込み // DBに接続できない場合、CakePHPのエラーメッセージが表示されてしまう為、 try を利用 try { $SiteConfig = ClassRegistry::init('SiteConfig'); $this->siteConfigs = Configure::read('BcSite'); // asset ファイルの読み込みの際、bootstrap で、loadSiteConfig() を実行しない仕様となっているが、 // 存在しない asset ファイルを読み込んだ際に、上記理由により、Not Found ページで、テーマが適用されない為、 // 再度、loadSiteConfig() を実行 if (!$this->siteConfigs) { loadSiteConfig(); $this->siteConfigs = Configure::read('BcSite'); } if (empty($this->siteConfigs['version'])) { $this->siteConfigs['version'] = $this->getBaserVersion(); $SiteConfig->saveKeyValue($this->siteConfigs); } } catch (Exception $ex) { $this->siteConfigs = array(); } } // TODO beforeFilterでも定義しているので整理する if ($this->name == 'CakeError') { $this->uses = null; // サブサイト用のエラー try { $Site = ClassRegistry::init('Site'); $site = $Site->findByUrl($this->request->url); if (!empty($site['Site']['name'])) { $this->layoutPath = $site['Site']['name']; if ($site['Site']['name'] == 'mobile') { $this->helpers[] = 'BcMobile'; } elseif ($site['Site']['name'] == 'smartphone') { $this->helpers[] = 'BcSmartphone'; } } } catch (Exception $e) { } } /* 携帯用絵文字のモデルとコンポーネントを設定 */ // TODO 携帯をコンポーネントなどで判別し、携帯からのアクセスのみ実行させるようにする // ※ コンストラクト時点で、$this->request->params['prefix']を利用できない為。 // TODO 2008/10/08 egashira // beforeFilterに移動してみた。実際に携帯を使うサイトで使えるかどうか確認する //$this->uses[] = 'EmojiData'; //$this->components[] = 'Emoji'; }
/** * コンストラクタ * * @param CakeRequest $request リクエストオブジェクト * @param CakeResponse $response レスポンスオブジェクト * @access private */ public function __construct($request = null, $response = null) { parent::__construct($request, $response); if (isConsole()) { unset($this->components['Session']); } // テンプレートの拡張子 $this->ext = Configure::read('BcApp.templateExt'); // コンソールベースのインストールの際のページテンプレート生成において、 // BC_INSTALLEDが true でない為、コンソールの場合も実行する if (BC_INSTALLED || isConsole()) { // サイト基本設定の読み込み // DBに接続できない場合、CakePHPのエラーメッセージが表示されてしまう為、 try を利用 try { $SiteConfig = ClassRegistry::init('SiteConfig'); $this->siteConfigs = Configure::read('BcSite'); if (empty($this->siteConfigs['version'])) { $this->siteConfigs['version'] = $this->getBaserVersion(); $SiteConfig->saveKeyValue($this->siteConfigs); } } catch (Exception $ex) { $this->siteConfigs = array(); } } else { if ($this->name != 'Installations') { if ($this->name == 'CakeError' && $request->params['controller'] != 'installations') { $this->redirect('/'); } } } // TODO beforeFilterでも定義しているので整理する if ($this->name == 'CakeError') { $this->uses = null; // モバイルのエラー用 if (Configure::read('BcRequest.agent')) { $this->layoutPath = Configure::read('BcRequest.agentPrefix'); $agent = Configure::read('BcRequest.agent'); if ($agent == 'mobile') { $this->helpers[] = 'BcMobile'; } elseif ($agent == 'smartphone') { $this->helpers[] = 'BcSmartphone'; } } } if (Configure::read('BcRequest.agent') == 'mobile') { if (!Configure::read('BcApp.mobile')) { $this->notFound(); } } if (Configure::read('BcRequest.agent') == 'smartphone') { if (!Configure::read('BcApp.smartphone')) { $this->notFound(); } } /* 携帯用絵文字のモデルとコンポーネントを設定 */ // TODO 携帯をコンポーネントなどで判別し、携帯からのアクセスのみ実行させるようにする // ※ コンストラクト時点で、$this->request->params['prefix']を利用できない為。 // TODO 2008/10/08 egashira // beforeFilterに移動してみた。実際に携帯を使うサイトで使えるかどうか確認する //$this->uses[] = 'EmojiData'; //$this->components[] = 'Emoji'; }
public static function getFullDomain() { if (isConsole() && empty($_SERVER['HTTP_HOST'])) { return ''; } return $_SERVER['HTTP_HOST']; }
if (!isConsole()) { $Session = new CakeSession(); $Session->start(); } /** * Viewのキャッシュ設定・ログの設定 */ if (Configure::read('debug') == 0) { if (isset($_SESSION) && session_id()) { // 管理ユーザーでログインしている場合、ページ機能の編集ページへのリンクを表示する為、キャッシュをオフにする。 // ただし、現在の仕様としては、セッションでチェックしているので、ブラウザを閉じてしまった場合、一度管理画面を表示する必要がある。 // TODO ブラウザを閉じても最初から編集ページへのリンクを表示する場合は、クッキーのチェックを行い、認証処理を行う必要があるが、 // セキュリティ上の問題もあるので実装は検討が必要。 // bootstrapで実装した場合、他ページへの負荷の問題もある if (isset($_SESSION['Auth']['User'])) { Configure::write('Cache.check', false); } } Configure::write('Exception', array('handler' => 'ErrorHandler::handleException', 'renderer' => 'ExceptionRenderer', 'log' => false)); } else { Configure::write('Cache.check', false); clearViewCache(); } /** * テーマヘルパーのパスを追加する */ if (BC_INSTALLED || isConsole()) { $helperPaths = App::path('View/Helper'); array_unshift($helperPaths, WWW_ROOT . 'theme' . DS . Configure::read('BcSite.theme') . DS . 'Helper' . DS); App::build(array('View/Helper' => $helperPaths)); }
protected function endBuffering() { $this->sendBuffered(); if (!isConsole()) { echo '</body></html>'; } }