public function testその他正常系() { // eye_catch_sizeチェック $data = array('thumb_width' => 1, 'thumb_height' => 1, 'mobile_thumb_width' => 1, 'mobile_thumb_height' => 1); $this->BlogContent->create(array('BlogContent' => array('eye_catch_size' => BcUtil::serialize($data)))); $this->assertTrue($this->BlogContent->validates()); $this->assertArrayNotHasKey('eye_catch_size', $this->BlogContent->validationErrors); }
/** * アイキャッチサイズフィールドの値をDB用に変換する * * @param array $data * @return array */ public function deconstructEyeCatchSize($data) { $data['BlogContent']['eye_catch_size'] = BcUtil::serialize(array('thumb_width' => $data['BlogContent']['eye_catch_size_thumb_width'], 'thumb_height' => $data['BlogContent']['eye_catch_size_thumb_height'], 'mobile_thumb_width' => $data['BlogContent']['eye_catch_size_mobile_thumb_width'], 'mobile_thumb_height' => $data['BlogContent']['eye_catch_size_mobile_thumb_height'])); unset($data['BlogContent']['eye_catch_size_thumb_width']); unset($data['BlogContent']['eye_catch_size_thumb_height']); unset($data['BlogContent']['eye_catch_size_mobile_thumb_width']); unset($data['BlogContent']['eye_catch_size_mobile_thumb_height']); return $data; }
/** * baserマーケットのテーマデータを取得する */ public function admin_ajax_get_market_themes() { $baserThemes = array(); $cachePath = 'views' . DS . 'baser_market_themes.rss'; if (Configure::read('debug') > 0) { clearCache('baser_market_themes', 'views', '.rss'); } $baserThemes = cache($cachePath); if (!$baserThemes) { $Xml = new Xml(); try { $baserThemes = $Xml->build(Configure::read('BcApp.marketThemeRss')); } catch (Exception $ex) { } if ($baserThemes) { $baserThemes = $Xml->toArray($baserThemes->channel); $baserThemes = $baserThemes['channel']['item']; cache($cachePath, BcUtil::serialize($baserThemes)); chmod(CACHE . $cachePath, 0666); } else { $baserThemes = array(); } } else { $baserThemes = BcUtil::unserialize($baserThemes); } $this->set('baserThemes', $baserThemes); }
/** * ユーザーグループのよく使う項目の初期値を登録する * * @return boolean */ public function admin_set_default_favorites($id) { if (!$this->request->data) { $this->ajaxError(500, '無効な処理です。'); } $user = $this->BcAuth->user(); $this->UserGroup->id = $id; $this->UserGroup->recursive = -1; $data = $this->UserGroup->read(); $data['UserGroup']['default_favorites'] = BcUtil::serialize($this->request->data); $this->UserGroup->set($data); if ($this->UserGroup->save()) { echo true; } exit; }
/** * シリアライズ / アンシリアライズ */ public function testSerialize() { // BcUtil::serialize()でシリアライズした場合 $serialized = BcUtil::serialize('hoge'); $result = BcUtil::unserialize($serialized); $this->assertEquals('hoge', $result, 'BcUtil::serialize()で正しくシリアライズ/アンシリアライズできません'); // serialize()のみでシリアライズした場合 $serialized = serialize('hoge'); $result = BcUtil::unserialize($serialized); $this->assertEquals('hoge', $result, 'serializeのみで正しくシリアライズ/アンシリアライズできません'); }
/** * [AJAX] ウィジェットを削除 * * @param int $widgetAreaId * @param int $id * @return void * @access public */ public function admin_del_widget($widgetAreaId, $id) { $widgetArea = $this->WidgetArea->read(null, $widgetAreaId); if (!$widgetArea['WidgetArea']['widgets']) { exit; } $widgets = BcUtil::unserialize($widgetArea['WidgetArea']['widgets']); foreach ($widgets as $key => $widget) { $type = key($widget); if ($id == $widget[$type]['id']) { unset($widgets[$key]); break; } } if ($widgets) { $widgetArea['WidgetArea']['widgets'] = BcUtil::serialize($widgets); } else { $widgetArea['WidgetArea']['widgets'] = ''; } $this->WidgetArea->set($widgetArea); if ($this->WidgetArea->save()) { echo true; } // 全てのキャッシュを削除しないと画面に反映できない。 //clearViewCache('element_widget',''); clearViewCache(); exit; }
/** * SimplePieでフィードを取得する * * @param string RSSのURL * @param string キャッシュ保持期間 * @return array RSSデータ */ protected function _getFeed($url, $cacheExpires = null) { if (!$url) { return false; } if (Configure::read('Cache.check') == false || Configure::read('debug') > 0) { // キャッシュをクリア clearCache($this->_createCacheHash('', $url), 'views', '.rss'); } // キャッシュを取得 $cachePath = $this->cacheFolder . DS . $this->_createCacheHash('.rss', $url); $rssData = cache($cachePath, null, $cacheExpires); if (empty($rssData)) { $SimplePie = new SimplePie(); $SimplePie->set_feed_url($url); $SimplePie->enable_cache(false); // 一旦デバッグモードをオフに $debug = Configure::read('debug'); Configure::write('debug', 0); $ret = $SimplePie->init(); Configure::write('debug', $debug); if (!$ret) { return false; } $rssData = $this->_convertSimplePie($SimplePie->get_items()); // ログインしてなければキャッシュを作成 if (!isset($_SESSION['Auth'][Configure::read('BcAuthPrefix.admin.sessionKey')])) { cache($cachePath, BcUtil::serialize($rssData)); chmod(CACHE . $cachePath, 0666); } if ($rssData) { return $rssData; } else { return false; } } else { return BcUtil::unserialize($rssData); } }
/** * コンテンツメタ情報を更新する * * @param string $contentCategory * @return boolean * @access public */ public function updateContentMeta(Model $model) { $db = ConnectionManager::getDataSource('baser'); $contentCategories = array(); $contentTypes = array(); if ($db->config['datasource'] == 'Database/BcCsv') { // CSVの場合GROUP BYが利用できない(baserCMS 2.0.2) $contents = $this->Content->find('all', array('conditions' => array('Content.status' => true))); foreach ($contents as $content) { if ($content['Content']['category'] && !in_array($content['Content']['category'], $contentCategories)) { $contentCategories[$content['Content']['category']] = $content['Content']['category']; } if ($content['Content']['type'] && !in_array($content['Content']['type'], $contentTypes)) { $contentTypes[$content['Content']['type']] = $content['Content']['type']; } } } else { $contents = $this->Content->find('all', array('fields' => array('Content.category'), 'group' => array('Content.category'), 'conditions' => array('Content.status' => true))); foreach ($contents as $content) { if ($content['Content']['category']) { $contentCategories[$content['Content']['category']] = $content['Content']['category']; } } $contents = $this->Content->find('all', array('fields' => array('Content.type'), 'group' => array('Content.type'), 'conditions' => array('Content.status' => true))); foreach ($contents as $content) { if ($content['Content']['type']) { $contentTypes[$content['Content']['type']] = $content['Content']['type']; } } } $siteConfigs['SiteConfig']['content_categories'] = BcUtil::serialize($contentCategories); $siteConfigs['SiteConfig']['content_types'] = BcUtil::serialize($contentTypes); $SiteConfig = ClassRegistry::init('SiteConfig'); return $SiteConfig->saveKeyValue($siteConfigs); }
/** * コンテンツメタ情報を更新する * * @param Model $model * @return boolean */ public function updateSearchIndexMeta(Model $model) { $db = ConnectionManager::getDataSource('default'); $contentTypes = array(); $searchIndexes = $this->SearchIndex->find('all', array('fields' => array('SearchIndex.type'), 'group' => array('SearchIndex.type'), 'conditions' => array('SearchIndex.status' => true))); foreach ($searchIndexes as $searchIndex) { if ($searchIndex['SearchIndex']['type']) { $contentTypes[$searchIndex['SearchIndex']['type']] = $searchIndex['SearchIndex']['type']; } } $siteConfigs['SiteConfig']['content_types'] = BcUtil::serialize($contentTypes); $SiteConfig = ClassRegistry::init('SiteConfig'); return $SiteConfig->saveKeyValue($siteConfigs); }
$data['WidgetArea']['widgets'] = BcUtil::serialize(unserialize($data['WidgetArea']['widgets'])); if (!$WidgetArea->save($data)) { $result = false; } } if ($result) { $this->setUpdateLog('widget_areas テーブルの変換に成功しました。'); } else { $this->setUpdateLog('widget_areas テーブルの変換に失敗しました。', true); } /** * シリアライズされたデータを更新 * * BlogContent.eye_catch_size */ CakePlugin::load('Blog'); App::uses('BlogContent', 'Blog.Model'); $BlogContent = new BlogContent(); $datas = $BlogContent->find('all', array('recursive' => -1)); $result = true; foreach ($datas as $data) { $data['BlogContent']['eye_catch_size'] = BcUtil::serialize(unserialize($data['BlogContent']['eye_catch_size'])); if (!$BlogContent->save($data)) { $result = false; } } if ($result) { $this->setUpdateLog('blog_contents テーブルの変換に成功しました。'); } else { $this->setUpdateLog('blog_contents テーブルの変換に失敗しました。', true); }