/** * テーマカラー設定を保存する * * @param array $data * @return boolean */ public function updateColorConfig($data) { $configPath = getViewPath() . 'css' . DS . 'config.css'; if (!file_exists($configPath)) { return false; } $File = new File($configPath); $config = $File->read(); $settings = array('MAIN' => 'color_main', 'SUB' => 'color_sub', 'LINK' => 'color_link', 'HOVER' => 'color_hover'); $settingExists = false; foreach ($settings as $key => $setting) { if (empty($data['ThemeConfig'][$setting])) { $config = preg_replace("/\n.+?" . $key . ".+?\n/", "\n", $config); } else { $config = str_replace($key, '#' . $data['ThemeConfig'][$setting], $config); $settingExists = true; } } $File = new File(WWW_ROOT . 'files' . DS . 'theme_configs' . DS . 'config.css', true, 0666); $File->write($config); $File->close(); if (!$settingExists) { unlink($configPath); } return true; }
public static function getViewsAvailable($placeholder) { $placeholder = strToLower($placeholder); $strPath = getViewPath($placeholder); $aryPath = array(); if (file_exists($strPath) && is_dir($strPath)) { $objDir = dir($strPath); while ($entry = $objDir->read()) { if ($entry != "." && $entry != ".." && is_file($objDir->path . "/" . $entry)) { $aryPath[] = $placeholder . "/" . $entry; } } } return $aryPath; }
public function render(Page $page) { $viewPath = $this->path; if (strToLower(substr($viewPath, strlen($viewPath) - 5, 5)) == ".xslt") { // file is XSLT $objXML = $page->xml; $objXSL = new DomDocument(); $objXSL->load(getViewPath($viewPath)); $objProc = new XSLTProcessor(); $objProc->registerPHPFunctions(); $objProc->importStyleSheet($objXSL); echo $objProc->transformToXML($objXML); } else { // FILE IS PHP $PAGE = $page; include getViewPath($this->path); } }
/** * PCのIDを元にモバイル・スマホの相対階層のIDを取得する * @param type $id * @return type */ public function getAgentRelativeId($type, $id) { if (!$id) { return $this->getAgentId($type); } else { $path = $this->getPath($id, array('name'), -1); $path = Hash::extract($path, '{n}.PageCategory.name'); $path = implode(DS, $path); $path = getViewPath() . 'Pages' . DS . $type . DS . $path; } $agentId = $this->getIdByPath($path); return $agentId; }
/** * 管理システムアセットへのシンボリックリンクをテーマフォルダ内に作成したかチェックする * 作成してないものがひとつでもあると true を返す * * @return boolean * @deprecated since version 3.0.1 */ public function testIsCreatedAdminAssetsSymlink() { $result = $this->BcManager->isCreatedAdminAssetsSymlink(); $this->assertFalse($result, '管理システムアセットへのシンボリックリンクをテーマフォルダ内に作成したかチェックが正しくありません'); $viewPath = getViewPath(); $paths = array('img' . DS . 'admin', 'css' . DS . 'admin', 'js' . DS . 'admin'); // シンボリックリンクを作成 foreach ($paths as $path) { symlink(BASER_WEBROOT . $path, $viewPath . $path); } // チェックを実行 $result = $this->BcManager->isCreatedAdminAssetsSymlink(); // シンボリックリンクを削除 foreach ($paths as $path) { unlink($viewPath . $path); } $this->assertTrue($result, '管理システムアセットへのシンボリックリンクをテーマフォルダ内に作成したかチェックが正しくありません'); }
/** * テーマ画像を取得する * * @param string $name テーマ画像名( log or main_image ) * @param array $options オプション(初期値 :array()) * - `num` : main_imageの場合の番号指定(初期値 : '') * - `thumb`: サムネイルを取得する(初期値 : false) * - `class`: 画像に設定する class 属性(初期値 : '') * - `popup`: ポップアップリンクを指定(初期値 : false) * - `alt` : 画像に設定する alt 属性。リンクの title 属性にも設定される。(初期値 : テーマ設定で設定された値) * - `link` : リンク先URL。popup を true とした場合、オリジナルの画像へのリンクとなる。(初期値 : テーマ設定で設定された値) * - `maxWidth : 最大横幅(初期値 : '') * - `maxHeight: 最大高さ(初期値 : '') * - `width : 最大横幅(初期値 : '') * - `height: 最大高さ(初期値 : '') * @return string $tag テーマ画像のHTMLタグ */ protected function _getThemeImage($name, $options = array()) { $ThemeConfig = ClassRegistry::init('ThemeConfig'); $data = $ThemeConfig->findExpanded(); $url = $imgPath = $uploadUrl = $uploadThumbUrl = $originUrl = ''; $thumbSuffix = '_thumb'; $dir = WWW_ROOT . 'files' . DS . 'theme_configs' . DS; $themeDir = $path = getViewPath() . 'img' . DS; $num = ''; if (!empty($options['num'])) { $num = '_' . $options['num']; } $options = array_merge(array('thumb' => false, 'class' => '', 'popup' => false, 'alt' => $data[$name . '_alt' . $num], 'link' => $data[$name . '_link' . $num], 'maxWidth' => '', 'maxHeight' => '', 'width' => '', 'height' => ''), $options); $name = $name . $num; if ($data[$name]) { $pathinfo = pathinfo($data[$name]); $uploadPath = $dir . $data[$name]; $uploadThumbPath = $dir . $pathinfo['filename'] . $thumbSuffix . '.' . $pathinfo['extension']; $uploadUrl = '/files/theme_configs/' . $data[$name]; $uploadThumbUrl = '/files/theme_configs/' . $pathinfo['filename'] . $thumbSuffix . '.' . $pathinfo['extension']; } if ($data[$name]) { if (!$options['thumb']) { if (file_exists($uploadPath)) { $imgPath = $uploadPath; $url = $uploadUrl; } } else { if (file_exists($uploadThumbPath)) { $imgPath = $uploadThumbPath; $url = $uploadThumbUrl; } } $originUrl = $uploadUrl; } if (!$url) { $exts = array('png', 'jpg', 'gif'); foreach ($exts as $ext) { if (file_exists($themeDir . $name . '.' . $ext)) { $url = '/theme/' . $this->siteConfig['theme'] . '/img/' . $name . '.' . $ext; $imgPath = $themeDir . $name . '.' . $ext; $originUrl = $url; } } } if (!$url) { return ''; } $imgOptions = array(); if ($options['class']) { $imgOptions['class'] = $options['class']; } if ($options['alt']) { $imgOptions['alt'] = $options['alt']; } if ($options['maxWidth'] || $options['maxHeight']) { $imginfo = getimagesize($imgPath); $widthRate = $heightRate = 0; if ($options['maxWidth']) { $widthRate = $imginfo[0] / $options['maxWidth']; } if ($options['maxHeight']) { $heightRate = $imginfo[1] / $options['maxHeight']; } if ($widthRate > $heightRate) { if ($options['maxWidth'] && $imginfo[0] > $options['maxWidth']) { $imgOptions['width'] = $options['maxWidth']; } } else { if ($options['maxHeight'] && $imginfo[1] > $options['maxHeight']) { $imgOptions['height'] = $options['maxHeight']; } } } if ($options['width']) { $imgOptions['width'] = $options['width']; } if ($options['height']) { $imgOptions['height'] = $options['height']; } $tag = $this->getImg($url, $imgOptions); if ($options['link'] || $options['popup']) { $linkOptions = array(); if ($options['popup']) { $linkOptions['rel'] = 'colorbox'; $link = $originUrl; } elseif ($options['link']) { $link = $options['link']; } if ($options['alt']) { $linkOptions['title'] = $options['alt']; } $tag = $this->getLink($tag, $link, $linkOptions); } return $tag; }
/** * [ADMIN] 固定ページファイルを登録する * * @return void * @access public */ function admin_entry_page_files() { // 現在のテーマの固定ページファイルのパスを取得 $pagesPath = getViewPath() . 'pages'; $result = $this->Page->entryPageFiles($pagesPath); clearViewCache(); $message = $result['all'] . ' ページ中 ' . $result['insert'] . ' ページの新規登録、 ' . $result['update'] . ' ページの更新に成功しました。'; $this->Session->setFlash($message); $this->redirect(array('action' => 'index')); }
/** * ページデータをコピーする * * @param int $id ページID * @param array $data コピーしたいデータ * @param array $expected 期待値 * @param string $message テストが失敗した時に表示されるメッセージ * @dataProvider copyDataProvider */ public function testCopy($id, $data, $expected, $message = null) { $data = array('Page' => $data); $result = $this->Page->copy($id, $data); // コピーしたファイル存在チェック $path = getViewPath() . 'Pages' . $result['Page']['url'] . '.php'; $this->assertFileExists($path, $message); @unlink($path); // DBに書き込まれているかチェック $exists = $this->Page->exists($result['Page']['id']); $this->assertTrue($exists); }
/** * エージェントカテゴリのIDを取得する * * @param int $targetId * @return int * @access public */ function getAgentId($type = 'mobile', $targetId = null) { if ($targetId) { if (in_array($targetId, array($this->getAgentId('mobile'), $this->getAgentId('smartphone')))) { $path = getViewPath() . 'pages' . DS . $type; } else { $path = $this->getPath($targetId, array('name'), -1); $path = Set::extract('/PageCategory/name', $path); $path = implode(DS, $path); $path = getViewPath() . 'pages' . DS . $type . DS . $path; } $agentId = $this->getIdByPath($path); } else { if (!isset($this->_agentId[$type])) { $this->_agentId[$type] = $this->field('id', array('PageCategory.name' => $type)); } $agentId = $this->_agentId[$type]; } return $agentId; }
/** * PCのIDを元にモバイル・スマホの相対階層のIDを取得する * @param type $id * @return type */ function getAgentRelativeId($type, $id) { if (!$id) { return $this->getAgentId($type); } else { $path = $this->getPath($id, array('name'), -1); $path = Set::extract('/PageCategory/name', $path); $path = implode(DS, $path); $path = getViewPath() . 'pages' . DS . $type . DS . $path; } $agentId = $this->getIdByPath($path); return $agentId; }
* @link http://basercms.net baserCMS Project * @since baserCMS v 3.0.6 * @license http://basercms.net/license/index.html */ /** * 管理システム用アセットファイルをデプロイ */ App::uses('BcManagerComponent', 'Controller/Component'); $BcManager = new BcManagerComponent(new ComponentCollection()); $BcManager->deployAdminAssets(); /** * プラグインの優先度の振り直し */ App::uses('Plugin', 'Model'); if (ClassRegistry::isKeySet('Plugin')) { $Plugin = ClassRegistry::getObject('Plugin'); } else { $Plugin = ClassRegistry::init('Plugin'); } $Plugin->rearrangePriorities(); /** * テーマ内の管理画面用のアセットファイルを削除する */ $path = getViewPath(); $paths = array($path . 'css' . DS . 'admin', $path . 'js' . DS . 'admin', $path . 'img' . DS . 'admin'); $Folder = new Folder(); foreach ($paths as $path) { if (is_dir($path)) { $Folder->delete($path); } }
/** * PCのIDを元にモバイル・スマホの相対階層のIDを取得する * * @param string type ユーザーエージェントのタイプ * @param int $id ページカテゴリーID * @return mixed $categoryId Or false */ public function getAgentRelativeId($type, $id) { if (!$id) { // ルート $agentId = $this->getAgentId($type); if ($agentId) { return (int) $agentId; } else { return false; } } else { $path = $this->getPath($id, array('name'), -1); if (!is_array($path)) { return false; } $path = Hash::extract($path, '{n}.PageCategory.name'); if ($path[0] == $type) { return false; } $path = implode(DS, $path); $path = getViewPath() . 'Pages' . DS . $type . DS . $path; } $categoryId = $this->getIdByPath($path); return $categoryId; }
/** * テーマカラー設定を保存する * * @param array $data 設定するテーマカラーのデータ * @param array $expected 期待値 * @param string $message テストが失敗した時に表示されるメッセージ * @dataProvider updateColorConfigDataProvider */ public function testUpdateColorConfig($data, $expected, $message = null) { // 設定元のファイル(config.css)を取得($dataが設定されてない場合、元のファイルが削除されるので、再生成するため) $configCssPathOriginal = getViewPath() . 'css' . DS . 'config.css'; $FileOriginal = new File($configCssPathOriginal); $configOriginal = $FileOriginal->read(); // 設定ファイルの取得 $configCssPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS . 'config.css'; $File = new File($configCssPath); // テーマーカラーの設定を実行 $data = array('ThemeConfig' => $data); $this->ThemeConfig->updateColorConfig($data); // 元のファイルを再生成 $FileOriginal->write($configOriginal); $FileOriginal->close(); // 生成したconfig.cssをの内容を取得 $setting = $File->read(); $File->close(); unlink($configCssPath); $this->assertRegExp('/' . $expected . '/s', $setting, $message); }
/** * [ADMIN] 固定ページファイルを登録する * * @return void * @access public */ public function admin_entry_page_files() { if (function_exists('ini_set')) { ini_set('max_execution_time', 0); ini_set('max_input_time', 0); ini_set('memory_limit ', '256M'); } // 現在のテーマの固定ページファイルのパスを取得 $pagesPath = getViewPath() . 'Pages'; $result = $this->Page->entryPageFiles($pagesPath); clearAllCache(); $this->setMessage($result['all'] . ' ページ中 ' . $result['insert'] . ' ページの新規登録、 ' . $result['update'] . ' ページの更新に成功しました。'); $this->redirect(array('action' => 'index')); }
/** * ページファイルを登録する * ※ 再帰処理 * * @param string $targetPath * @param string $parentCategoryId * @return array 処理結果 all / success */ public function entryPageFiles($targetPath, $parentCategoryId = '') { if ($this->Behaviors->loaded('BcCache')) { $this->Behaviors->unload('BcCache'); } if ($this->PageCategory->Behaviors->loaded('BcCache')) { $this->PageCategory->Behaviors->unload('BcCache'); } $this->fileSave = false; $Folder = new Folder($targetPath); $files = $Folder->read(true, true, true); $Folder = null; $insert = 0; $update = 0; $all = 0; // カテゴリの取得・登録 $categoryName = basename($targetPath); $specialCategoryIds = array('', $this->PageCategory->getAgentId('mobile'), $this->PageCategory->getAgentId('smartphone')); if (in_array($parentCategoryId, $specialCategoryIds) && $categoryName == 'templates') { return array('all' => 0, 'insert' => 0, 'update' => 0); } $pageCategoryId = ''; $this->PageCategory->updateRelatedPage = false; if ($categoryName != 'Pages') { // カテゴリ名の取得 // 標準では設定されてないので、利用する場合は、あらかじめ bootstrap 等で宣言しておく $categoryTitles = Configure::read('Baser.pageCategoryTitles'); $categoryTitle = -1; if ($categoryTitles) { $categoryNames = explode('/', str_replace(getViewPath() . 'Pages' . DS, '', $targetPath)); foreach ($categoryNames as $key => $value) { if (isset($categoryTitles[$value])) { if (count($categoryNames) == $key + 1) { $categoryTitle = $categoryTitles[$value]['title']; } elseif (isset($categoryTitles[$value]['children'])) { $categoryTitles = $categoryTitles[$value]['children']; } } } } $categoryId = $this->PageCategory->getIdByPath($targetPath); if ($categoryId) { $pageCategoryId = $categoryId; if ($categoryTitle != -1) { $pageCategory = $this->PageCategory->find('first', array('conditions' => array('PageCategory.id' => $pageCategoryId), 'recursive' => -1)); $pageCategory['PageCategory']['title'] = $categoryTitle; $this->PageCategory->set($pageCategory); $this->PageCategory->save(); } } else { $pageCategory['PageCategory']['parent_id'] = $parentCategoryId; $pageCategory['PageCategory']['name'] = $categoryName; if ($categoryTitle == -1) { $pageCategory['PageCategory']['title'] = $categoryName; } else { $pageCategory['PageCategory']['title'] = $categoryTitle; } $pageCategory['PageCategory']['sort'] = $this->PageCategory->getMax('sort') + 1; $this->PageCategory->cacheQueries = false; $this->PageCategory->create($pageCategory); if ($this->PageCategory->save()) { $pageCategoryId = $this->PageCategory->getInsertID(); } } } else { $categoryName = ''; } // ファイル読み込み・ページ登録 if (!$files[1]) { $files[1] = array(); } foreach ($files[1] as $path) { if (preg_match('/' . preg_quote(Configure::read('BcApp.templateExt')) . '$/is', $path) == false) { continue; } $pageName = basename($path, Configure::read('BcApp.templateExt')); $file = new File($path); $contents = $file->read(); $file->close(); $file = null; // タイトル取得・置換 $titleReg = '/<\\?php\\s+?\\$this->BcBaser->setTitle\\(\'(.*?)\'\\)\\s+?\\?>/is'; if (preg_match($titleReg, $contents, $matches)) { $title = trim($matches[1]); $contents = preg_replace($titleReg, '', $contents); } else { $title = Inflector::camelize($pageName); } // 説明文取得・置換 $descriptionReg = '/<\\?php\\s+?\\$this->BcBaser->setDescription\\(\'(.*?)\'\\)\\s+?\\?>/is'; if (preg_match($descriptionReg, $contents, $matches)) { $description = trim($matches[1]); $contents = preg_replace($descriptionReg, '', $contents); } else { $description = ''; } // PageTagコメントの削除 $pageTagReg = '/<\\!\\-\\- BaserPageTagBegin \\-\\->.*?<\\!\\-\\- BaserPageTagEnd \\-\\->/is'; $contents = preg_replace($pageTagReg, '', $contents); $conditions['Page.name'] = $pageName; if ($pageCategoryId) { $conditions['Page.page_category_id'] = $pageCategoryId; } else { $conditions['Page.page_category_id'] = null; } $page = $this->find('first', array('conditions' => $conditions, 'recursive' => -1)); if ($page) { $chage = false; if ($title != $page['Page']['title']) { $chage = true; } if ($description != $page['Page']['description']) { $chage = true; } if (trim($contents) != trim($page['Page']['contents'])) { $chage = true; } if ($chage) { $page['Page']['title'] = $title; $page['Page']['description'] = $description; $page['Page']['contents'] = $contents; $this->set($page); if ($this->save()) { $update++; } } } else { $page = $this->getDefaultValue(); $page['Page']['name'] = $pageName; $page['Page']['title'] = $title; $page['Page']['description'] = $description; $page['Page']['contents'] = $contents; $page['Page']['page_category_id'] = $pageCategoryId; $page['Page']['url'] = $this->getPageUrl($page); $this->create($page); if ($this->save()) { $insert++; } } $contents = $page = $pageName = $title = $description = $conditions = $descriptionReg = $titleReg = $pageTagReg = null; $all++; } // フォルダー内の登録 if (!$files[0]) { $files[0] = array(); } foreach ($files[0] as $file) { $folderName = basename($file); if ($folderName != '_notes' && $folderName != 'admin') { $result = $this->entryPageFiles($file, $pageCategoryId); $insert += $result['insert']; $update += $result['update']; $all += $result['all']; } } return array('all' => $all, 'insert' => $insert, 'update' => $update); }
/** * 管理システムアセットへのシンボリックリンクをテーマフォルダ内に作成したかチェックする * 作成してないものがひとつでもあると false を返す * * @return boolean * @deprecated since version 3.0.1 */ public function isCreatedAdminAssetsSymlink() { // Windowsの場合シンボリックリンクをサポートしないのでそのままtrueを返す if (DS == '\\') { return true; } $viewPath = getViewPath(); $css = $viewPath . 'css' . DS . 'admin'; $js = $viewPath . 'js' . DS . 'admin'; $img = $viewPath . 'img' . DS . 'admin'; $result = true; if (!is_dir($css) && !is_link($css)) { $result = false; } if (!is_dir($js) && !is_link($js)) { $result = false; } if (!is_dir($img) && !is_link($img)) { $result = false; } return $result; }
/** * 固定ページのコンテンツを出力する * * @return void */ public function content() { $agent = ''; if (Configure::read('BcRequest.agentPrefix')) { $agent = Configure::read('BcRequest.agentPrefix'); } $path = $this->_View->getVar('pagePath'); if ($agent) { $url = '/' . implode('/', $this->request->params['pass']); $linked = $this->Page->isLinked($agent, $url); if (!$linked) { $path = $agent . DS . $path; } } echo $this->_View->evaluate(getViewPath() . 'Pages' . DS . $path . '.php', $this->_View->viewVars); }
/** * 現在のビューディレクトリのパスを取得する */ public function testGetViewPath() { // テーマが設定されている場合 Configure::write('BcSite.theme', 'hoge'); $result = getViewPath(); $expect = WWW_ROOT . 'theme' . DS . 'hoge' . DS; $this->assertEquals($expect, $result, '取得した現在のビューディレクトリのパスが正しくありません'); // テーマが未設定の場合 Configure::write('BcSite.theme', null); $result = getViewPath(); $expect = APP . 'View' . DS; $this->assertEquals($expect, $result, '取得した現在のビューディレクトリのパスが正しくありません'); }
/** * カテゴリフォルダのパスから対象となるデータが存在するかチェックする * 存在する場合は id を返す * * @param string $path カテゴリフォルダのパス * @param array $expected 期待値 * @param string $message テストが失敗した時に表示されるメッセージ * @dataProvider getIdByPathDataProvider */ public function testGetIdByPath($path, $expected, $message = null) { $path = getViewPath() . 'Pages' . $path; $result = $this->PageCategory->getIdByPath($path); $this->assertEquals($expected, $result, $message); }