Exemple #1
0
    /**
     * return the  permalink based on permalink structure
     * which is defined in WP Admin
     *
     * @param Fishpig_Wordpress_Model_Post
     * @return string
     */
	public function getPermalink(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, '%');
					
						switch($part) {
							case 'year': 		$url[] 	= $post->getPostDate('Y');		break;
							case 'monthnum':	$url[] 	= $post->getPostDate('m');		break;
							case 'day':			$url[]  = $post->getPostDate('d');		break;
							case 'hour':		$url[]  = $post->getPostDate('H');		break;
							case 'minute':		$url[]  = $post->getPostDate('i');		break;
							case 'second':		$url[]  = $post->getPostDate('s');		break;
							case 'post_id':		$url[] 	= $post->getId();				break;
							case 'postname':	$url[] 	= urldecode($post->getPostName());			break;
							case 'category':	$url[] 	= $this->_getPermalinkCategoryPortion($post);	break;
							case 'author':																break;
							default:			$this->log("Unknown permalink token ({$segment})");		break;
						}
					}
					else {
						$url[] = $part;
					}
				}

				return $this->getUrl(implode('', $url));
			}
		}
	}
Exemple #2
0
 /**
  * return the  permalink based on permalink structure
  * which is defined in WP Admin
  *
  * @param Fishpig_Wordpress_Model_Post
  * @return string
  */
 public function getPermalink(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] .= '/';
             }
             return $this->getUrl(implode('', $url));
         }
     }
 }