/**
  * Purge Cms Page
  *
  * @param Mage_Cms_Model_Page $page
  * @return Phoenix_VarnishCache_Model_Control_Cms_Page
  */
 public function purge(Mage_Cms_Model_Page $page)
 {
     if ($this->_canPurge()) {
         $storeIds = Mage::getResourceModel('varnishcache/cms_page_store_collection')->addPageFilter($page->getId())->getAllIds();
         if (count($storeIds) && current($storeIds) == 0) {
             $storeIds = Mage::getResourceModel('core/store_collection')->setWithoutDefaultFilter()->getAllIds();
         }
         foreach ($storeIds as $storeId) {
             $url = Mage::app()->getStore($storeId)->getUrl(null, array('_direct' => $page->getIdentifier()));
             extract(parse_url($url));
             $path = rtrim($path, '/');
             $this->_getCacheControl()->clean($host, '^' . $path . '/{0,1}$');
             // Purge if current page is a home page
             $homePageIdentifier = Mage::getStoreConfig(self::XML_PATH_WEB_DEFAULT_CMS_HOME_PAGE, $storeId);
             if ($page->getIdentifier() == $homePageIdentifier) {
                 $url = Mage::app()->getStore($storeId)->getUrl();
                 extract(parse_url($url));
                 $path = rtrim($path, '/');
                 $this->_getCacheControl()->clean($host, '^' . $path . '/{0,1}$');
                 $this->_getCacheControl()->clean($host, '^/{0,1}$');
             }
         }
         $this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for "%s" has been purged.', $page->getTitle()));
     }
     return $this;
 }
 /**
  * @param Mage_Cms_Model_Page $page
  *
  * @return bool
  */
 public function isCustomerAllowed(Mage_Cms_Model_Page $page)
 {
     $customer = Mage::helper('customer')->getCustomer();
     $pageCustomerIds = array_flip(explode(',', $page->getAllowCustomerIds()));
     $isValidGroup = (pow(2, $customer->getGroupId()) & $page->getAllowCustomerGroups()) > 0;
     $isValidCustomerId = isset($pageCustomerIds[$customer->getEntityId()]);
     return $isValidGroup || $isValidCustomerId;
 }
Beispiel #3
0
 public function createVersion(Mage_Cms_Model_Page $page)
 {
     $data = $page->getData();
     $versionData = array();
     $versionData['content'] = $data['content'];
     $versionData['parent_id'] = $data['page_id'];
     $versionData['creation_time'] = $data['update_time'];
     $versionData['user_id'] = Mage::getSingleton('admin/session')->getUser()->getId();
     $this->setData($versionData);
     $this->save();
     return $this;
 }
Beispiel #4
0
 /**
  * @test
  */
 public function testCmsPageSaveAfter()
 {
     $this->_fpc->save('page1', 'page1_cache_id', array(sha1('cms_1')));
     $this->_fpc->save('page2', 'page2_cache_id', array(sha1('cms_2')));
     $this->_fpc->save('page3', 'page3_cache_id', array(sha1('cms_3')));
     $page = new Mage_Cms_Model_Page();
     $page->setId(1);
     $page->setIdentifier('3');
     Mage::dispatchEvent('cms_page_save_after', array('object' => $page));
     $this->assertFalse($this->_fpc->load('page1_cache_id'));
     $this->assertFalse($this->_fpc->load('page3_cache_id'));
     $this->assertEquals('page2', $this->_fpc->load('page2_cache_id'));
 }
 /**
  * Retrieve a collection of post's associated with the given product
  *
  * @param Mage_Cms_Model_Page $page
  * @return false|Fishpig_Wordpress_Model_Resource_Post_Collection_Abstract
  */
 public function getAssociatedPostsByCmsPage(Mage_Cms_Model_Page $page)
 {
     if (!$page instanceof Mage_Cms_Model_Page) {
         return false;
     }
     $associations = array_keys($this->getAssociations('cms_page/post', $page->getId(), 0));
     $categoryAssociations = array_keys($this->getAssociations('cms_page/category', $page->getId(), 0));
     $associations = array_merge($associations, $this->_convertWpCategoryIds($categoryAssociations));
     if (count($associations) > 0) {
         return Mage::getResourceModel('wordpress/post_collection')->addFieldToFilter('ID', array('IN' => $associations))->addIsPublishedFilter();
     }
     return false;
 }
Beispiel #6
0
 /**
  * @test
  */
 public function testCmsPageSaveAfter()
 {
     $page1Data = new \Lesti_Fpc_Model_Fpc_CacheItem('page1', time(), 'text/html');
     $this->_fpc->save($page1Data, 'page1_cache_id', array(sha1('cms_1')));
     $page2Data = new \Lesti_Fpc_Model_Fpc_CacheItem('page2', time(), 'text/html');
     $this->_fpc->save($page2Data, 'page2_cache_id', array(sha1('cms_2')));
     $page3Data = new \Lesti_Fpc_Model_Fpc_CacheItem('page3', time(), 'text/html');
     $this->_fpc->save($page3Data, 'page3_cache_id', array(sha1('cms_3')));
     $page = new Mage_Cms_Model_Page();
     $page->setId(1);
     $page->setIdentifier('3');
     Mage::dispatchEvent('cms_page_save_after', array('object' => $page));
     $this->assertFalse($this->_fpc->load('page1_cache_id'));
     $this->assertFalse($this->_fpc->load('page3_cache_id'));
     $this->assertEquals($page2Data, $this->_fpc->load('page2_cache_id'));
 }
 /**
  * Get CMS page from request
  *
  * @return Mage_Cms_Model_Page
  */
 private function _getCmsPage()
 {
     if (!$this->_cmsPage) {
         $this->_cmsPage = Mage::getModel('Mage_Cms_Model_Page');
         $cmsPageId = (int) $this->getRequest()->getParam('cms_page', 0);
         if (!$cmsPageId && $this->_getUrlRewrite()->getId()) {
             $urlRewriteId = $this->_getUrlRewrite()->getId();
             /** @var $cmsUrlRewrite Mage_Cms_Model_Page_Urlrewrite */
             $cmsUrlRewrite = Mage::getModel('Mage_Cms_Model_Page_Urlrewrite');
             $cmsUrlRewrite->load($urlRewriteId, 'url_rewrite_id');
             $cmsPageId = $cmsUrlRewrite->getCmsPageId();
         }
         if ($cmsPageId) {
             $this->_cmsPage->load($cmsPageId);
         }
     }
     return $this->_cmsPage;
 }
Beispiel #8
0
 /**
  * Validate cms page before delete
  *
  * @param Mage_Cms_Model_Page $model
  * @return void
  */
 public function cmsBlockDeleteBefore($model)
 {
     $originalStoreIds = $model->getResource()->lookupStoreIds($model->getId());
     if (!$this->_role->hasExclusiveStoreAccess($originalStoreIds)) {
         $this->_throwDelete();
     }
 }
 /**
  * @param Mage_Cms_Model_Page $page
  * @param $data
  * @throws Exception
  */
 private function _createUpdatePage($identifier, Mage_Cms_Model_Page $page, $data)
 {
     $canSave = false;
     // Load page model
     if (!$page->getId()) {
         $page = Mage::getModel('cms/page');
         $page->setIdentifier($identifier);
     }
     unset($data['contents']);
     if (isset($data['stores'])) {
         // Loop through the store view names to get its corresponding ID
         $storeIds = array();
         foreach ($data['stores'] as $storeViewName) {
             $store = Mage::getModel('core/store')->load($storeViewName, 'code');
             if (!$store->getId()) {
                 throw new Exception("Store View Name: {$storeViewName} does not exist for {$identifier}");
             }
             $storeIds[] = $store->getId();
             unset($store);
         }
         unset($storeViewName);
         // @todo check what stores it is associated to already
         $oldStoreIds = Mage::getModel('cms/page')->load($page->getId())->getStoreId();
         sort($storeIds);
         if ($oldStoreIds != $storeIds) {
             $canSave = true;
             $page->setStores($storeIds);
         }
         unset($oldStoreIds);
         unset($storeIds);
         unset($data['stores']);
     } else {
         $page->setStores(array(0));
     }
     // Loop through page attributes
     foreach ($data as $key => $value) {
         // content file attribute would require to read it from a file
         if ($key == "content_file") {
             // If a value/path is set then get its contents
             if ($value != "") {
                 // locate file path
                 $filePath = Mage::getBaseDir() . DS . 'app' . DS . 'etc' . DS . 'components' . DS . 'html' . DS . $value;
                 // Check if the file exists
                 if (file_exists($filePath)) {
                     // Get the contents of the file and save it as the value
                     $value = file_get_contents($filePath);
                     unset($filePath);
                     $key = 'content';
                 } else {
                     throw new Exception("No file found in {$filePath}");
                 }
             } else {
                 continue;
             }
         }
         // If the value is already equal to the value in the database, skip it
         if ($page->getData($key) == $value) {
             continue;
         }
         $canSave = true;
         $page->setData($key, $value);
         $this->log("Setting page attribute {$key} to {$value} for {$identifier}");
     }
     if ($canSave) {
         $page->save();
         $this->log("Saved page {$identifier}");
     }
 }
Beispiel #10
0
 protected function _updateChildrenCount(Mage_Cms_Model_Page $page, $pageIds, $operator)
 {
     $table = $this->getTable('cms/page');
     $childrenCount = $this->getChildrenCount($page->getId()) + 1;
     $adapter = $this->_getWriteAdapter();
     $sql = "UPDATE {$table} SET children_count=children_count {$operator} {$childrenCount} WHERE page_id IN(?)";
     $adapter->query($adapter->quoteInto($sql, $pageIds));
 }
Beispiel #11
0
 /**
  * Data provider
  *
  * @return array
  */
 public function prepareLayoutDataProvider()
 {
     $urlRewrite = new Mage_Core_Model_Url_Rewrite();
     $cmsPage = new Mage_Cms_Model_Page(array('page_id' => 1, 'title' => 'Test CMS Page'));
     $existingUrlRewrite = new Mage_Core_Model_Url_Rewrite(array('url_rewrite_id' => 1));
     return array(array(array('cms_page' => $cmsPage, 'url_rewrite' => $urlRewrite), array('selector' => false, 'cms_page_link' => array('name' => $cmsPage->getTitle()), 'back_button' => true, 'save_button' => true, 'reset_button' => false, 'delete_button' => false, 'form' => array('cms_page' => $cmsPage, 'url_rewrite' => $urlRewrite), 'cms_pages_grid' => false)), array(array('url_rewrite' => $urlRewrite), array('selector' => true, 'cms_page_link' => false, 'back_button' => true, 'save_button' => false, 'reset_button' => false, 'delete_button' => false, 'form' => false, 'cms_pages_grid' => true)), array(array('url_rewrite' => $existingUrlRewrite, 'cms_page' => $cmsPage), array('selector' => false, 'cms_page_link' => array('name' => $cmsPage->getTitle()), 'back_button' => true, 'save_button' => true, 'reset_button' => true, 'delete_button' => true, 'form' => array('cms_page' => $cmsPage, 'url_rewrite' => $existingUrlRewrite), 'cms_pages_grid' => false)));
 }
 /**
  * Build a Solr document for a given page
  *
  * @param integer $storeId Store ID
  * @param Mage_Cms_Model_Page $page Page instance
  * @return Apache_Solr_Document
  */
 protected function buildPageDocument($storeId, $page)
 {
     $helper = Mage::helper('solr');
     $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
     $host = parse_url($baseUrl, PHP_URL_HOST);
     $document = new Apache_Solr_Document();
     $document->setField('appKey', 'Asm_Solr');
     $document->setField('type', 'cms/page');
     $document->setField('id', $helper->getPageDocumentId($page->getId()));
     $document->setField('site', $host);
     $document->setField('siteHash', $helper->getSiteHashForDomain($host));
     $document->setField('storeId', $storeId);
     $document->setField('created', $helper->dateToIso($page->getCreationTime()));
     $document->setField('changed', $helper->dateToIso($page->getUpdateTime()));
     $document->setField('sku', 'cms/page');
     $document->setField('productId', 0);
     $document->setField('pageId', $page->getId());
     $document->setField('title', $page->getTitle());
     $document->setField('content', Mage::helper('solr/contentExtractor')->getIndexableContent($page->getContent()));
     $document->setField('keywords', $helper->trimExplode(',', $page->getMetaKeywords(), true));
     $document->setField('url', Mage::helper('cms/page')->getPageUrl($page->getId()));
     return $document;
 }
Beispiel #13
0
 protected function _afterLoad()
 {
     parent::_afterLoad();
     $identifiers = explode('/', $this->getIdentifier());
     $this->setUrlKey(array_pop($identifiers));
     return $this;
 }
Beispiel #14
0
 /**
  * Get request path
  *
  * @param Mage_Cms_Model_Page $cmsPage
  * @return string
  */
 public function generateRequestPath($cmsPage)
 {
     return $cmsPage->getIdentifier();
 }
Beispiel #15
0
 /**
  * Init indexing process after cms page delete commit
  *
  */
 protected function _afterDeleteCommit()
 {
     parent::_afterDeleteCommit();
     Mage::getSingleton('index/indexer')->indexEvents(self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE);
 }
Beispiel #16
0
 /**
  * Update rewrite for page (if identifier changed)
  *
  * @param Mage_Cms_Model_Page $page
  * @return Enterprise_Cms_Model_Hierarchy_Node
  */
 public function updateRewriteUrls(Mage_Cms_Model_Page $page)
 {
     $xpaths = $this->_getResource()->getTreeXpathsByPage($page->getId());
     foreach ($xpaths as $xpath) {
         $this->_getResource()->updateRequestUrlsForTreeByXpath($xpath);
     }
     return $this;
 }
Beispiel #17
0
 /**
  * Return row url for js event handlers
  *
  * @param Mage_Cms_Model_Page|Varien_Object $row
  * @return string
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('*/*/edit', array('cms_page' => $row->getId()));
 }
Beispiel #18
0
<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_Cms
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$page = new Mage_Cms_Model_Page();
$page->setTitle('Cms Page 100')->setIdentifier('page100')->setStores(array(0))->setIsActive(1)->setContent('<h1>Cms Page 100 Title</h1>')->setRootTemplate('one_column')->save();
$page = new Mage_Cms_Model_Page();
$page->setTitle('Cms Page Design Modern')->setIdentifier('page_design_modern')->setStores(array(0))->setIsActive(1)->setContent('<h1>Cms Page Design Modern Title</h1>')->setRootTemplate('one_column')->setCustomTheme('default/modern/default')->save();
Beispiel #19
0
 /**
  * Should return list of tags to clean
  *
  * @param Mage_Cms_Model_Page $object
  * @return string[]|string
  */
 protected function _collectTags($object)
 {
     return self::TAG_PREFIX . $object->getId();
 }