/** * Retrieve a single parent category * This is the category associated with the post with the lowest term_id * * @param Fishpig_Wordpress_Model_Post $post * @retrun Fishpig_Wordpress_Model_Post_Category_Collection */ public function getParentCategory(Fishpig_Wordpress_Model_Post $post) { $collection = Mage::getResourceModel('wordpress/post_category_collection')->addPostIdFilter($post->getId()); $collection->getSelect()->limit(1)->reset(Zend_Db_Select::ORDER)->order('main_table.term_id ASC'); $collection->load(); return $collection->getFirstItem()->getId() ? $collection->getFirstItem() : false; }
/** * Retrieve the icon HTML for the post * * @param Fishpig_Wordpress_Model_Post $post * @return string */ public function getIcons(Fishpig_Wordpress_Model_Post $post) { if ($this->isEnabled()) { $html = Mage::helper('wordpress')->getWpOption('st_tags'); if (preg_match_all("/(<span.*><\\/span>)/iU", $html, $matches)) { $tags = array(); foreach ($matches[1] as $match) { $class = $this->_patternMatch("/class='(.*)'/iU", $match); $displayText = $this->_patternMatch("/displayText='(.*)'/iU", $match); $stVia = trim($this->_patternMatch("/st_via='(.*)'/iU", $match)); if ($displayText) { $displayText = ' displayText="' . $displayText . '" '; } if ($stVia) { $stVia = ' st_via="' . $stVia . '"'; } $tag = sprintf('<span class="%s"%sst_title="%s" st_summary="%s" st_url="%s"%s></span>', $class, $displayText, addslashes($post->getPostTitle()), trim(strip_tags(addslashes($post->getPostExcerpt()))), $post->getPermalink(), $stVia); if ($image = $post->getFeaturedImage()) { $tag = str_replace('></span>', ' st_image="' . $image->getAvailableImage() . '"></span>', $tag); } $tags[] = $tag; } return implode('', $tags); } } }
public function getFeaturedImageUrl(Fishpig_Wordpress_Model_Post $post) { if ($image = $post->getFeaturedImage()) { return $image->getThumbnailImage(); } return false; }
/** * Set the post this comment is associated to * * @param Fishpig_Wordpress_Model_Post $post * @return Fishpig_Wordpress_Model_Post_Comment */ public function setPost(Fishpig_Wordpress_Model_Post $post) { $this->setPostId($post->getId()); $this->setData('comment_post_ID', $post->getId()); return parent::setData('post', $post); }
/** * Apply variables to a string * * @param string $str * @param Fishpig_Wordpress_Model_Post $post * @return string */ protected function _applyVars($str, $post) { if (trim($str) === '') { return ''; } $_helper = Mage::helper('wordpress'); return str_replace(array('%%AUTHORLINK%%', '%%POSTLINK%%', '%%BLOGLINK%%', '%%BLOGDESCLINK%%'), array($this->_createATag($post->getAuthor()->getUrl(), $post->getAuthor()->getDisplayName()), $this->_createATag($post->getPermalink(), $post->getPostTitle()), $this->_createATag($_helper->getUrl(), $_helper->getWpOption('blogname')), $this->_createATag($_helper->getUrl(), $_helper->getWpOption('blogname') . ' - ' . $_helper->getWpOption('blogdescription'))), $str); }
/** * Retrieve the post excerpt * * @param Fishpig_Wordpress_Model_Post $post * @return string */ public function getPostExcerpt(Fishpig_Wordpress_Model_Post $post) { if ($excerpt = trim(strip_tags($post->getPostExcerpt()))) { $words = explode(' ', $excerpt); if (count($words) > $this->getExcerptLength()) { $words = array_slice($words, 0, $this->getExcerptLength()); } return trim(implode(' ', $words), '.,!:-?"\'£$%') . '...'; } return ''; }
/** * Retrieve an array of related post ID's * * @param Fishpig_Wordpress_Model_Post $post * @return array|false */ public function getRelatedPostIds(Fishpig_Wordpress_Model_Post $post) { $helper = Mage::helper('wordpress/database'); $select = $helper->getReadAdapter()->select()->from($helper->getTableName('yarpp_related_cache'), 'ID')->where('reference_ID=?', $post->getId())->where('score > ?', 0)->order($this->getOrder() ? $this->getOrder() : 'score DESC')->limit($this->getLimit() ? $this->getLimit() : 5); try { return $helper->getReadAdapter()->fetchCol($select); } catch (Exception $e) { Mage::helper('wordpress')->log($e->getMessage()); } return array(); }
/** * Retrieve a collection of products assocaited with the post * * @param Fishpig_Wordpress_Model_Post $post * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getAssociatedProducts($post) { if ($post instanceof Fishpig_Wordpress_Model_Post) { $productIds = $this->_getAssociatedWpEntityIds($post->getId(), 'product', 'post', 'post_id'); if (count($productIds) > 0) { $collection = Mage::getResourceModel('catalog/product_collection'); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); $collection->addAttributeToFilter('status', 1); $collection->addAttributeToFilter('entity_id', array('in' => $productIds)); return $collection; } } return false; }
/** * Retrieve the icon HTML for the post * * @param Fishpig_Wordpress_Model_Post $post * @return string */ public function getIcons(Fishpig_Wordpress_Model_Post $post) { if ($this->isEnabled()) { $tags = Mage::helper('wordpress')->getWpOption('st_tags'); $tags = preg_replace("/(<\\?php[ ]{0,}the_title\\(\\)[;]{0,1}[ ]{0,}[php]{0,3}\\?>)/", addslashes($post->getPostTitle()), $tags); $tags = preg_replace("/(<\\?php[ ]{0,}the_permalink\\(\\)[;]{0,1}[ ]{0,}[php]{0,3}\\?>)/", addslashes($post->getPermalink()), $tags); $tags = preg_replace("/(<\\?php[ ]{0,}the_excerpt\\(\\)[;]{0,1}[ ]{0,}[php]{0,3}\\?>)/", addslashes(strip_tags($post->getPostExcerpt())), $tags); if (strpos($tags, 'the_image(') !== false) { if ($image = $post->getFeaturedImage()) { $tags = preg_replace("/(<\\?php[ ]{0,}the_image\\(\\)[;]{0,1}[ ]{0,}[php]{0,3}\\?>)/", $image->getThumbnailImage(), $tags); } } return $tags; } }
/** * Retrieve a collection of products assocaited with the post * * @param Fishpig_Wordpress_Model_Post $post * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getAssociatedProducts($post) { if ($post instanceof Fishpig_Wordpress_Model_Post) { $productIds = $this->_getAssociatedWpEntityIds($post->getId(), 'product', 'post', 'post_id'); try { foreach ($post->getParentCategories() as $category) { $productIds = array_merge($productIds, $this->_getAssociatedWpEntityIds($category->getId(), 'product', 'category', 'category_id')); } } catch (Exception $e) { $this->log($e->getMessage()); } if (count($productIds) > 0) { $collection = Mage::getResourceModel('catalog/product_collection'); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); $collection->addAttributeToFilter('status', 1); $collection->addAttributeToFilter('entity_id', array('in' => $productIds)); return $collection; } } return false; }
/** * Get the buttons HTML for the given $post and selected service * * @param Fishpig_Wordpress_Model_Post $post * @return string */ public function getButtons(Fishpig_Wordpress_Model_Post $post) { if ($this->isShareThis()) { $buttonsHtml = $this->_getButtonsHtml(); if (preg_match_all('/(<span.*)(>.*<\\/span>)/Us', $buttonsHtml, $matches)) { foreach ($matches[1] as $it => $prefix) { $suffix = $matches[2][$it]; $middle = sprintf(' st_title="%s"', $this->_sanitizeString($post->getPostTitle())); $middle .= sprintf(' st_url="%s"', $post->getPermalink()); if ($featuredImage = $post->getFeaturedImage()) { $middle .= sprintf(' st_image="%s"', $featuredImage->getAvailableImage()); } if (($excerpt = trim($post->getData('post_excerpt'))) !== '') { $middle .= sprintf(' st_summary="%s"', $this->_sanitizeString($excerpt, '<a><span><strong><em>')); } $buttonsHtml = str_replace($matches[0][$it], $prefix . $middle . $suffix, $buttonsHtml); } return $buttonsHtml; } } return ''; }
/** * Retrieve a collection of products assocaited with the post * * @param Fishpig_Wordpress_Model_Post $post * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getAssociatedProductsByPost(Fishpig_Wordpress_Model_Post $post) { if (!$this->isConnected() || !$post instanceof Fishpig_Wordpress_Model_Post) { return false; } $associations = array_keys($this->getReverseAssociations('product/post', $post->getId())); foreach ($post->getParentCategories() as $category) { $associations = array_merge($associations, array_keys($this->getReverseAssociations('product/category', $category->getId()))); } $associations = array_unique($associations); if (count($associations) > 0) { $collection = Mage::getResourceModel('catalog/product_collection'); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); if (!Mage::getStoreConfigFlag('cataloginventory/options/show_out_of_stock')) { Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection); } $collection->addAttributeToFilter('status', 1); $collection->addAttributeToFilter('entity_id', array('in' => $associations)); return $collection; } return false; }
public function getButtons(Fishpig_Wordpress_Model_Post $post) { if ($this->isShareThis()) { $buttonsHtml = $this->_getButtonsHtml(); if (preg_match_all('/(<span.*)(>.*<\\/span>)/Us', $buttonsHtml, $matches)) { foreach ($matches[1] as $it => $prefix) { $suffix = $matches[2][$it]; $middle = " st_title='" . addslashes(strip_tags($post->getPostTitle())) . "'"; $middle .= " st_url='" . $post->getPermalink() . "'"; if ($featuredImage = $post->getFeaturedImage()) { $middle .= " st_image='" . $featuredImage->getAvailableImage() . "'"; } $middle .= " st_summary='" . ($post->getData('post_excerpt') ? addslashes(strip_tags($post->getData('post_excerpt'))) : '') . "'"; $buttonsHtml = str_replace($matches[0][$it], $prefix . $middle . $suffix, $buttonsHtml); } return $buttonsHtml; } } return ''; }
/** * Retrieve the featured image for the post * * @param Fishpig_Wordpress_Model_Post $post * @return Fishpig_Wordpress_Model_Image $image */ public function getFeaturedImage(Fishpig_Wordpress_Model_Post $post) { if ($images = $post->getImages()) { $select = $this->_getReadAdapter()->select()->from($this->getTable('wordpress/post_meta'), 'meta_value')->where('post_id=?', $post->getId())->where('meta_key=?', '_thumbnail_id')->limit(1); if (($imageId = $this->_getReadAdapter()->fetchOne($select)) !== false) { if (preg_match('/([a-z-]{1,})([0-9]{1,})/', $imageId, $matches)) { if (($prefix = trim($matches[1], '- ')) !== '') { $eventData = array('object' => $post, 'image_id' => $matches[2], 'original_image_id' => $imageId, 'result' => new Varien_Object()); Mage::dispatchEvent('wordpress_post_get_featured_image_' . $prefix, $eventData); if ($eventData['result']->getFeaturedImage()) { return $eventData['result']->getFeaturedImage(); } } } else { return Mage::getModel('wordpress/image')->load($imageId); } } } return false; }
/** * Retrieve the author string * * @param Fishpig_Wordpress_Model_Post $post, * @param array $params = array * @return string */ public function getAuthorString(Fishpig_Wordpress_Model_Post $post) { $author = $post->getAuthor(); return $this->_generateAnchor($author->getUrl(), $author->getDisplayName()); }
public function getMetaValue($key) { return parent::getMetaValue('_wp_attachment_' . $key); }
/** * Retrieve a string indicating the number of comments * * @param Fishpig_Wordpress_Model_Post $post * @return string */ public function getCommentCountString(Fishpig_Wordpress_Model_Post $post) { if ($post->getCommentCount() == 0) { return $this->__('No Comments'); } else { if ($post->getCommentCount() > 1) { return $this->__('%s Comments', $post->getCommentCount()); } } return $this->__('1 Comment'); }
/** * Generates the category portion of the URL for a post * * @param Fishpig_Wordpress_Model_Post $post * @return string */ protected function _getPermalinkCategoryPortion(Fishpig_Wordpress_Model_Post $post) { if ($category = $post->getParentCategory()) { return trim($category->getSlug(), '/'); } }
/** * Get a collection of terms that belong this taxonomy and $post * * @param Fishpig_Wordpress_Model_Post $post * @return Fishpig_Wordpress_Model_Resource_Post_Collection */ public function getPostTermsCollection(Fishpig_Wordpress_Model_Post $post) { return Mage::getResourceModel('wordpress/term_collection')->addTaxonomyFilter($this->getTaxonomyType())->addPostIdFilter($post->getId()); }
/** * Retrieve a collection of categories * * @param Fishpig_Wordpress_Model_Post $post * @retrun Fishpig_Wordpress_Model_Post_Category_Collection */ public function getParentCategories(Fishpig_Wordpress_Model_Post $post) { return Mage::getResourceModel('wordpress/post_category_collection')->addPostIdFilter($post->getId()); }
/** * Get the post renderer template * * @param Fishpig_Wordpress_Model_Post $post * @return string */ public function getPostRendererTemplate(Fishpig_Wordpress_Model_Post $post) { if ($archiveTemplate = $post->getTypeInstance()->getArchiveTemplate()) { return $archiveTemplate; } if ($this->hasPostRendererTemplate()) { return $this->_getData('post_renderer_template'); } return 'wordpress/post/list/renderer/default.phtml'; }
/** * Unset a post's comment data * * @param Fishpig_Wordpress_Model_Post $post */ public function removePostCommentData(Fishpig_Wordpress_Model_Post $post) { return $this->unsetData('post_comment_data_' . $post->getId()); }
/** * Generates the category portion of the URL for a post * * @param Fishpig_Wordpress_Model_Post $post * @return string */ protected function _getPermalinkCategoryPortion(Fishpig_Wordpress_Model_Post $post) { if ($category = $post->getParentCategory()) { return $category->getNoBaseUri(); } return ''; }
/** * Filter the collection by a post model * This is just a wrapper for self::addPostIdFilter * * @param Fishpig_Wordpress_Model_Post $post */ public function addPostFilter(Fishpig_Wordpress_Model_Post $post) { return $this->addPostIdFilter($post->getId()); }
/** * return the permalink based on permalink structure * which is defined from WP Admin * * It's changed version of parent method getPermalink() * * @param Fishpig_Wordpress_Model_Post * @return string */ public function getPermalinkPost(Fishpig_Wordpress_Model_Post $post) { if ($this->useGuidLinks()) { return $this->getUrl('?p=' . $post->getId()); } else { $structure = $this->_getExplodedPermalinkStructure(); if (count($structure) > 0) { $url = array(); foreach ($structure as $part) { if (preg_match('/^\\%[a-zA-Z0-9_]{1,}\\%$/', $part)) { $part = trim($part, '%'); if ($part === 'year') { $url[] = $post->getPostDate('Y'); } else { if ($part === 'monthnum') { $url[] = $post->getPostDate('m'); } else { if ($part === 'day') { $url[] = $post->getPostDate('d'); } else { if ($part === 'hour') { $url[] = $post->getPostDate('H'); } else { if ($part === 'minute') { $url[] = $post->getPostDate('i'); } else { if ($part === 'second') { $url[] = $post->getPostDate('s'); } else { if ($part === 'post_id') { $url[] = $post->getId(); } else { if ($part === 'postname') { $url[] = urldecode($post->getPostName()); } else { if ($part === 'category') { $url[] = $this->_getPermalinkCategoryPortion($post); } else { if ($part === 'author') { } else { $response = new Varien_Object(array('value' => false)); Mage::dispatchEvent('wordpress_permalink_segment_unknown_getpermalink', array('response' => $response, 'post' => $post, 'segment' => $part)); if ($response->getValue() !== false) { $url[] = $response->getValue(); } } } } } } } } } } } } else { if ($part === '/') { $partCount = count($url); if ($partCount > 0 && $url[$partCount - 1] === $part) { continue; } } $url[] = $part; } } if ($this->permalinkHasTrainingSlash()) { $url[count($url) - 1] .= '/'; } // echo "<br>"; // echo $url; return $this->getUrl(implode('', $url)); } } }
/** * Retrieve a collection of categories * * @param Fishpig_Wordpress_Model_Post $post * @retrun Fishpig_Wordpress_Model_Post_Category_Collection */ public function getParentCategories(Fishpig_Wordpress_Model_Post $post) { return Mage::getResourceModel('wordpress/post_category_collection')->addFieldToFilter('main_table.term_id', array('in' => $post->getCategoryIds())); }
public function getModifiedDate(Fishpig_Wordpress_Model_Post $post) { return substr($post->getPostModified(), 0, 10); }
/** * Retrieve the position of a post in a product * * @param Fishpig_Wordpress_Model_Post $post * @param int $productId * @return int */ public function getPositionInProduct(Fishpig_Wordpress_Model_Post $post, $productId) { $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $select = $read->select()->from(Mage::getSingleton('core/resource')->getTableName('wordpress_product_post'), 'position')->where('post_id=?', $post->getId())->where('product_id=?', $productId)->limit(1); return number_format($read->fetchOne($select), 0); }