コード例 #1
0
 public function act_packages()
 {
     $packages = Posts::get(array('content_type' => 'plugin', 'nolimit' => true));
     $xml = new SimpleXMLElement('<packages/>');
     foreach ($packages as $package) {
         if (!$package->info->guid) {
             continue;
         }
         $package_node = $xml->addChild('package');
         $package_node->addChild('description', utf8_encode(Format::summarize(strip_tags($package->content))));
         $package_node->addAttribute('guid', $package->info->guid);
         $package_node->addAttribute('name', $package->title);
         if ($package->info->author) {
             $package_node->addAttribute('author', $package->info->author);
         }
         if ($package->info->author_url) {
             $package_node->addAttribute('author_url', $package->info->author_url);
         }
         $package_node->addAttribute('type', 'plugin');
         $package_node->addAttribute('tags', implode(',', (array) $package->tags));
         $versions_node = $package_node->addChild('versions');
         foreach ($package->versions as $version) {
             if ($version->habari_version) {
                 $version_node = $versions_node->addChild('version', $version->description);
                 $version_node->addAttribute('version', $version->version);
                 $version_node->addAttribute('archive_md5', $version->md5);
                 $version_node->addAttribute('archive_url', $version->url);
                 $version_node->addAttribute('habari_version', $version->habari_version);
             }
         }
     }
     ob_clean();
     header('Content-Type: application/xml');
     echo $xml->asXml();
 }
コード例 #2
0
 /**
  * Sends the email and writes to the log
  */
 private function send_mail($email, $subject, $message, $body, $headers, $type)
 {
     // use PHP_EOL instead of \r\n to separate headers as you must use native
     // line endings for the system running PHP
     $mailHeaders = 'MIME-Version: 1.0' . PHP_EOL;
     $mailHeaders .= 'Content-type: text/plain; charset=utf-8' . PHP_EOL;
     $mailHeaders .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL;
     $mailHeaders .= $headers . PHP_EOL;
     // strip all HTML tags as this email is sent in plain text
     $body = strip_tags($body);
     // limit post/comment content to 50 words or 3 paragraphs
     // (which doesn't make any different for plain text)
     $body = Format::summarize($body, 50, 3);
     $message .= $body;
     // for the reason above, use consistent line separators
     $message = str_replace(array("\r\n", "\n", "\r"), PHP_EOL, $message);
     if (mail($email, $subject, $message, $mailHeaders) === TRUE) {
         EventLog::log($type . ' email sent to ' . $email, 'info', 'default', 'notify_all');
     } else {
         EventLog::log($type . ' email could not be sent to  ' . $email, 'err', 'default', 'notify_all');
     }
 }
コード例 #3
0
 /**
  * Modify the publish form to include the iTunes settings for 
  * a specific post
  *
  * @param FormUI $form The form being modified
  * @param Post $post The post being edited
  * @param string $feed The name of the feed for which the form is being modified
  *
  */
 protected function post_itunes_form($form, $post, $feed)
 {
     $postfields = $form->publish_controls->enclosures;
     if (isset($post->info->{$feed})) {
         $options = $post->info->{$feed};
     }
     $control_id = md5($feed);
     $fieldname = "{$control_id}_player_settings";
     $player = $postfields->append('fieldset', $fieldname, _t('Display Settings'));
     $player->class = 'podcast-settings';
     $fieldname = "show_player_{$control_id}";
     $field = $player->append('checkbox', $fieldname, 'null:null', _t('Show player instead of link', 'podcast'), 'tabcontrol_checkbox');
     $field->value = isset($options['show_player']) ? $options['show_player'] : TRUE;
     $fieldname = "show_download_{$control_id}";
     $field = $player->append('checkbox', $fieldname, 'null:null', _t('Show download link under player', 'podcast'), 'tabcontrol_checkbox');
     $field->value = isset($options['show_download']) ? $options['show_download'] : TRUE;
     $fieldname = "{$control_id}_settings";
     $feed_fields = $postfields->append('fieldset', $fieldname, _t('Settings for ', 'podcast') . $feed);
     $feed_fields->class = 'podcast-settings';
     $fieldname = "enclosure_{$control_id}";
     $customfield = $feed_fields->append('text', $fieldname, 'null:null', _t('Podcast Enclosure * :', 'podcast'), 'tabcontrol_text');
     $customfield->value = isset($options['enclosure']) ? $options['enclosure'] : '';
     $customfield->add_validator('validate_required');
     $fieldname = "subtitle_{$control_id}";
     $customfield = $feed_fields->append('text', $fieldname, 'null:null', _t('Subtitle:', 'podcast'), 'tabcontrol_text');
     $customfield->value = isset($options['subtitle']) ? $options['subtitle'] : '';
     $fieldname = "explicit_{$control_id}";
     $customfield = $feed_fields->append('select', $fieldname, 'null:null', _t('Content Rating:', 'podcast'));
     $customfield->template = 'tabcontrol_select';
     $customfield->options = $this->itunes_rating;
     $customfield->value = isset($options['rating']) ? $this->itunes_rating[array_search($options['rating'], $this->itunes_rating)] : $this->itunes_rating['No'];
     $fieldname = "summary_{$control_id}";
     $customfield = $feed_fields->append('textarea', $fieldname, 'null:null', _t('Summary:', 'podcast'), 'tabcontrol_textarea');
     $customfield->value = isset($options['summary']) ? $options['summary'] : strip_tags(Format::summarize(Format::autop($post->content)));
     $fieldname = "block_{$control_id}";
     $customfield = $feed_fields->append('checkbox', $fieldname, 'null:null', _t('Block:', 'podcast'), 'tabcontrol_checkbox');
     $customfield->value = isset($options['block']) ? $options['block'] : 0;
 }
コード例 #4
0
ファイル: format.php プロジェクト: anupom/my-blog
 /**
  * Returns a truncated version of post content when the post isn't being displayed on its own.
  * Posts are split either at the comment <!--more--> or at the specified maximums.
  * Use only after applying autop or other paragrpah styling methods.
  * Apply to posts using:
  * <code>Format::apply_with_hook_params( 'more', 'post_content_out' );</code>
  * @param string $content The post content
  * @param Post $post The Post object of the post
  * @param string $more_text The text to use in the "read more" link.
  * @param integer $max_words null or the maximum number of words to use before showing the more link
  * @param integer $max_paragraphs null or the maximum number of paragraphs to use before showing the more link
  * @return string The post content, suitable for display
  **/
 public static function more($content, $post, $more_text = 'Read More &raquo;', $max_words = null, $max_paragraphs = null)
 {
     // If the post requested is the post under consideration, always return the full post
     if ($post->slug == Controller::get_var('slug')) {
         return $content;
     } else {
         $matches = preg_split('/<!--\\s*more\\s*-->/is', $content, 2, PREG_SPLIT_NO_EMPTY);
         if (count($matches) > 1) {
             return reset($matches) . ' <a href="' . $post->permalink . '">' . $more_text . '</a>';
         } elseif (isset($max_words) || isset($max_paragraphs)) {
             $max_words = empty($max_words) ? 9999999 : intval($max_words);
             $max_paragraphs = empty($max_paragraphs) ? 9999999 : intval($max_paragraphs);
             $summary = Format::summarize($content, $max_words, $max_paragraphs);
             if (strlen($summary) >= strlen($content)) {
                 return $content;
             } else {
                 return $summary . ' <a href="' . $post->permalink . '">' . $more_text . '</a>';
             }
         }
     }
     return $content;
 }
コード例 #5
0
ファイル: format.php プロジェクト: rynodivino/system
	/**
	 * Returns a truncated version of post content when the post isn't being displayed on its own.
	 * Posts are split either at the comment <!--more--> or at the specified maximums.
	 * Use only after applying autop or other paragrpah styling methods.
	 * Apply to posts using:
	 * <code>Format::apply_with_hook_params( 'more', 'post_content_out' );</code>
	 * @param string $content The post content
	 * @param Post $post The Post object of the post
	 * @param string $more_text The text to use in the "read more" link.
	 * @param integer $max_words null or the maximum number of words to use before showing the more link
	 * @param integer $max_paragraphs null or the maximum number of paragraphs to use before showing the more link
	 * @return string The post content, suitable for display
	 */
	public static function more( $content, $post, $properties = array() )
	{
		// If the post requested is the post under consideration, always return the full post
		if ( $post->slug == Controller::get_var( 'slug' ) ) {
			return $content;
		}
		elseif ( is_string( $properties ) ) {
			$args = func_get_args();
			$more_text = $properties;
			$max_words = ( isset( $args[3] ) ? $args[3] : null );
			$max_paragraphs = ( isset( $args[4] ) ? $args[4] : null );
			$paramstring = "";
		}
		else {
			$paramstring = "";
			$paramarray = Utils::get_params( $properties );

			$more_text = ( isset( $paramarray['more_text'] ) ? $paramarray['more_text'] : 'Read More' );
			$max_words = ( isset( $paramarray['max_words'] ) ? $paramarray['max_words'] : null );
			$max_paragraphs = ( isset( $paramarray['max_paragraphs'] ) ? $paramarray['max_paragraphs'] : null );

			if ( isset( $paramarray['title:before'] ) || isset( $paramarray['title'] ) || isset( $paramarray['title:after'] ) ) {
				$paramstring .= 'title="';

				if ( isset( $paramarray['title:before'] ) ) {
					$paramstring .= $paramarray['title:before'];
				}
				if ( isset( $paramarray['title'] ) ) {
					$paramstring .= $post->title;
				}
				if ( isset( $paramarray['title:after'] ) ) {
					$paramstring .= $paramarray['title:after'];
				}
				$paramstring .= '" ';
			}
			if ( isset( $paramarray['class'] ) ) {
				$paramstring .= 'class="' . $paramarray['class'] . '" ';
			}

		}
		$matches = preg_split( '/<!--\s*more\s*-->/isu', $content, 2, PREG_SPLIT_NO_EMPTY );
		if ( count( $matches ) > 1 ) {
			return ( $more_text != '' ) ? reset( $matches ) . ' <a ' . $paramstring . 'href="' . $post->permalink . '">' . $more_text . '</a>' : reset( $matches );
		}
		elseif ( isset( $max_words ) || isset( $max_paragraphs ) ) {
			$max_words = empty( $max_words ) ? 9999999 : intval( $max_words );
			$max_paragraphs = empty( $max_paragraphs ) ? 9999999 : intval( $max_paragraphs );
			$summary = Format::summarize( $content, $max_words, $max_paragraphs );
			if ( MultiByte::strlen( $summary ) >= MultiByte::strlen( $content ) ) {
				return $content;
			}
			else {
				if ( strlen( $more_text  ) ) {
					// Tokenize the summary and link
					$ht = new HTMLTokenizer( $summary );
					$summary_set = $ht->parse();
					$ht = new HTMLTokenizer( '<a ' . $paramstring . ' href="' . $post->permalink . '">' . $more_text . '</a>' );
					$link_set= $ht->parse();
					// Find out where to put the link
					$end = $summary_set->end();
					$key = $summary_set->key();
					// Inject the link
					$summary_set->insert( $link_set, $key );

					return (string)$summary_set;
				}
				else {
					return $summary;
				}
			}
		}

	return $content;
	}
コード例 #6
0
ファイル: format.php プロジェクト: habari-extras/lace
 /**
  * Returns a truncated version of post content when the post isn't being displayed on its own.
  * Posts are split either at the comment <!--more--> or at the specified maximums.
  * Use only after applying autop or other paragrpah styling methods.	 	 
  * Apply to posts using:
  * <code>Format::apply_with_hook_params( 'more', 'post_content_out' );</code>	 
  * @param string $content The post content
  * @param Post $post The Post object of the post
  * @param string $more_text The text to use in the "read more" link.
  * @param integer $max_words null or the maximum number of words to use before showing the more link
  * @param integer $max_paragraphs null or the maximum number of paragraphs to use before showing the more link	 
  * @return string The post content, suitable for display
  **/
 public static function more($content, $post, $more_text = 'Read More &raquo;', $max_words = null, $max_paragraphs = null)
 {
     // There should be a more readable way than this to detect if this post is being displayed by itself:
     if (isset(Controller::get_handler()->handler_vars['slug'])) {
         return $content;
     } else {
         $matches = preg_split('/<!--\\s*more\\s*-->/is', $content, 2, PREG_SPLIT_NO_EMPTY);
         if (count($matches) > 1) {
             return reset($matches) . ' <a href="' . $post->permalink . '">' . $more_text . '</a>';
         } elseif (isset($max_words) || isset($max_paragraphs)) {
             $max_words = empty($max_words) ? 9999999 : intval($max_words);
             $max_paragraphs = empty($max_paragraphs) ? 9999999 : intval($max_paragraphs);
             $summary = Format::summarize($content, $max_words, $max_paragraphs);
             if (strlen($summary) >= strlen($content)) {
                 return $content;
             } else {
                 return $summary . ' <a href="' . $post->permalink . '">' . $more_text . '</a>';
             }
         }
     }
     return $content;
 }
コード例 #7
0
ファイル: format.php プロジェクト: wwxgitcat/habari
 /**
  * Returns a truncated version of post content when the post isn't being displayed on its own.
  * Posts are split either at the comment <!--more--> or at the specified maximums.
  * Use only after applying autop or other paragrpah styling methods.
  * Apply to posts using:
  * <code>Format::apply_with_hook_params( 'more', 'post_content_out' );</code>
  * @param string $content The post content
  * @param Post $post The Post object of the post
  * @param string $more_text The text to use in the "read more" link.
  * @param integer $max_words null or the maximum number of words to use before showing the more link
  * @param integer $max_paragraphs null or the maximum number of paragraphs to use before showing the more link
  * @param boolean $inside_last Should the link be placed inside the last element, or not? Default: true
  * @return string The post content, suitable for display
  */
 public static function more($content, $post, $properties = array())
 {
     // If the post requested is the post under consideration, always return the full post
     if ($post->slug == Controller::get_var('slug')) {
         return $content;
     } elseif (is_string($properties)) {
         $args = func_get_args();
         $more_text = $properties;
         $max_words = isset($args[3]) ? $args[3] : null;
         $max_paragraphs = isset($args[4]) ? $args[4] : null;
         $inside_last = isset($args[5]) ? $args[5] : true;
         $paramstring = "";
     } else {
         $paramstring = "";
         $paramarray = Utils::get_params($properties);
         $more_text = isset($paramarray['more_text']) ? $paramarray['more_text'] : 'Read More';
         $max_words = isset($paramarray['max_words']) ? $paramarray['max_words'] : null;
         $max_paragraphs = isset($paramarray['max_paragraphs']) ? $paramarray['max_paragraphs'] : null;
         $inside_last = isset($paramarray['inside_last']) ? $paramarray['inside_last'] : true;
         if (isset($paramarray['title:before']) || isset($paramarray['title']) || isset($paramarray['title:after'])) {
             $paramstring .= 'title="';
             if (isset($paramarray['title:before'])) {
                 $paramstring .= $paramarray['title:before'];
             }
             if (isset($paramarray['title'])) {
                 $paramstring .= $post->title;
             }
             if (isset($paramarray['title:after'])) {
                 $paramstring .= $paramarray['title:after'];
             }
             $paramstring .= '" ';
         }
         if (isset($paramarray['class'])) {
             $paramstring .= 'class="' . $paramarray['class'] . '" ';
         }
     }
     $link_text = '<a ' . $paramstring . ' href="' . $post->permalink . '">' . $more_text . '</a>';
     // if we want it inside the last element, make sure there's a space before the link
     if ($inside_last) {
         $link_text = ' ' . $link_text;
     }
     // check for a <!--more--> link, which sets exactly where we should split
     $matches = preg_split('/<!--\\s*more\\s*-->/isu', $content, 2, PREG_SPLIT_NO_EMPTY);
     if (count($matches) > 1) {
         $summary = reset($matches);
     } else {
         // otherwise, we need to summarize it automagically
         $max_words = empty($max_words) ? 9999999 : intval($max_words);
         $max_paragraphs = empty($max_paragraphs) ? 9999999 : intval($max_paragraphs);
         $summary = Format::summarize($content, $max_words, $max_paragraphs);
     }
     // if the summary is equal to the length of the content (or somehow greater??), there's no need to add a link, just return the content
     if (MultiByte::strlen($summary) >= MultiByte::strlen($content)) {
         return $content;
     } else {
         // make sure there's actually text to append before we waste our time
         if (strlen($more_text)) {
             // parse out the summary and stick in our linky goodness
             // tokenize the summary
             $ht = new HTMLTokenizer($summary);
             $summary_set = $ht->parse();
             // tokenize the link we're adding
             $ht = new HTMLTokenizer($link_text);
             $link_set = $ht->parse();
             // find out where to put the link by bumping the iterator to the last element
             $end = $summary_set->end();
             // and what index is that?
             $key = $summary_set->key();
             // if we want it inside the last element, we're good to go - if we want it outside, we need to add it as the *next* element
             if ($inside_last == false) {
                 $key++;
             }
             // if the element is a text node, there were no tags; probably not autop'ed yet, just add link as new line
             if ($end['type'] == HTMLTokenizer::NODE_TYPE_TEXT) {
                 $summary_set->insert($link_set, $key + 1);
             } else {
                 // inject it, whereever we decided it should go
                 $summary_set->insert($link_set, $key);
             }
             // and return a stringified version
             return (string) $summary_set;
         } else {
             // no text to append? just return the summary
             return $summary;
         }
     }
     return $content;
 }
コード例 #8
0
ファイル: format.php プロジェクト: psaintlaurent/Habari
 /**
  * Returns a truncated version of post content when the post isn't being displayed on its own.
  * Posts are split either at the comment <!--more--> or at the specified maximums.
  * Use only after applying autop or other paragrpah styling methods.
  * Apply to posts using:
  * <code>Format::apply_with_hook_params( 'more', 'post_content_out' );</code>
  * @param string $content The post content
  * @param Post $post The Post object of the post
  * @param string $more_text The text to use in the "read more" link.
  * @param integer $max_words null or the maximum number of words to use before showing the more link
  * @param integer $max_paragraphs null or the maximum number of paragraphs to use before showing the more link
  * @return string The post content, suitable for display
  **/
 public static function more($content, $post, $properties = array())
 {
     // If the post requested is the post under consideration, always return the full post
     if ($post->slug == Controller::get_var('slug')) {
         return $content;
     } else {
         if (is_string($properties)) {
             $args = func_get_args();
             $more_text = $properties;
             $max_words = isset($args[3]) ? $args[3] : NULL;
             $max_paragraphs = isset($args[4]) ? $args[4] : NULL;
             $paramstring = "";
         } else {
             $paramstring = "";
             $paramarray = Utils::get_params($properties);
             $more_text = isset($paramarray['more_text']) ? $paramarray['more_text'] : 'Read More';
             $max_words = isset($paramarray['max_words']) ? $paramarray['max_words'] : NULL;
             $max_paragraphs = isset($paramarray['max_paragraphs']) ? $paramarray['max_paragraphs'] : NULL;
             if (isset($paramarray['title:before']) || isset($paramarray['title']) || isset($paramarray['title:after'])) {
                 $paramstring .= 'title="';
                 if (isset($paramarray['title:before'])) {
                     $paramstring .= $paramarray['title:before'];
                 }
                 if (isset($paramarray['title'])) {
                     $paramstring .= $post->title;
                 }
                 if (isset($paramarray['title:after'])) {
                     $paramstring .= $paramarray['title:after'];
                 }
                 $paramstring .= '" ';
             }
             if (isset($paramarray['class'])) {
                 $paramstring .= 'class="' . $paramarray['class'] . '" ';
             }
         }
     }
     $matches = preg_split('/<!--\\s*more\\s*-->/isu', $content, 2, PREG_SPLIT_NO_EMPTY);
     if (count($matches) > 1) {
         return $more_text != '' ? reset($matches) . ' <a ' . $paramstring . 'href="' . $post->permalink . '">' . $more_text . '</a>' : reset($matches);
     } elseif (isset($max_words) || isset($max_paragraphs)) {
         $max_words = empty($max_words) ? 9999999 : intval($max_words);
         $max_paragraphs = empty($max_paragraphs) ? 9999999 : intval($max_paragraphs);
         $summary = Format::summarize($content, $max_words, $max_paragraphs);
         if (strlen($summary) >= strlen($content)) {
             return $content;
         } else {
             return $more_text != '' ? $summary . ' <a ' . $paramstring . ' href="' . $post->permalink . '">' . $more_text . '</a>' : $summary;
         }
     }
     return $content;
 }