/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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(); } }
/** * 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(); }
/** * Generate target path * * @param Mage_Cms_Model_Page $cmsPage * @return string */ public function generateTargetPath($cmsPage) { return 'cms/page/view/page_id/' . $cmsPage->getId(); }
/** * @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}"); } }
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)); }
/** * 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())); }