<?xml version="1.0" encoding="utf-8"?>
<hookexport>
  <hookdata>
    <config>
      <hook_name>Promote post to article</hook_name>
      <hook_desc>Allow promotion of posts in the forums to articles in IP.Content</hook_desc>
      <hook_author>Invision Power Services, Inc</hook_author>
      <hook_email>support@invisionpower.com</hook_email>
      <hook_website>http://invisionpower.com</hook_website>
      <hook_update_check/>
      <hook_requirements><![CDATA[a:3:{s:21:"required_applications";a:1:{s:4:"core";a:3:{s:8:"app_name";s:6:"System";s:11:"min_version";i:31000;s:11:"max_version";i:0;}}s:20:"hook_php_version_min";s:0:"";s:20:"hook_php_version_max";s:0:"";}]]></hook_requirements>
      <hook_version_human>2.2.0</hook_version_human>
      <hook_version_long>22000</hook_version_long>
      <hook_extra_data><![CDATA[a:2:{s:7:"display";N;s:8:"database";a:0:{}}]]></hook_extra_data>
      <hook_key>contentPromoteToArticle</hook_key>
      <hook_global_caches/>
    </config>
  </hookdata>
  <hookfiles>
    <file>
      <hook_file_real>contentPromoteToArticle.php</hook_file_real>
      <hook_type>templateHooks</hook_type>
      <hook_classname>contentPromoteToArticle</hook_classname>
      <hook_data><![CDATA[a:8:{s:12:"dataLocation";s:0:"";s:14:"libApplication";s:0:"";s:15:"classToOverload";s:0:"";s:9:"skinGroup";s:10:"skin_topic";s:12:"skinFunction";s:4:"post";s:4:"type";s:2:"if";s:2:"id";s:7:"hasblog";s:8:"position";s:10:"post.endif";}]]></hook_data>
      <hooks_source><![CDATA[<?php

class contentPromoteToArticle
{
	/**
	 * Registry object
	 *
	 * @var		object
	 */	
	protected $registry;
	
	/**
	 * Constructor
	 *
	 * @return	@e void
	 */
	public function __construct()
	{
		$this->registry	= ipsRegistry::instance();
	}
	
	/**
	 * Get the output
	 *
	 * @return	string
	 */
	public function getOutput()
	{
	}
	
	/**
	 * Replace output
	 *
	 * @param	string		Output
	 * @param	string		Hook key
	 * @return	string		Output parsed
	 */
	public function replaceOutput( $output, $key )
	{
		if( is_array($this->registry->output->getTemplate('topic')->functionData['post']) AND count($this->registry->output->getTemplate('topic')->functionData['post']) )
		{
			if( !$this->registry->isClassLoaded('articles') )
			{
				$classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'ccs' ) . '/sources/promote.php', 'promoteArticle', 'ccs' );
				$this->registry->setClass( 'articles', new $classToLoad( ipsRegistry::instance() ) );
			}
			
			$tag	= '<!--hook.' . $key . '-->';
			$last	= 0;
		
			foreach( $this->registry->output->getTemplate('topic')->functionData['post'] as $_post )
			{
				$pos	= strpos( $output, $tag, $last );

				if( $pos AND !$_post['post']['post']['_isDeleted'] AND !$_post['topic']['_isArchived'] )
				{
					$pid	= $_post['post']['post']['pid'];
					$string	= $this->registry->articles->getPostHook( $pid );
					$output	= substr_replace( $output, $string . $tag, $pos, strlen( $tag ) ); 
					$last	= $pos + strlen( $tag . $string );
				}
			}
		}
		
		return $output;
	}
}]]></hooks_source>
    </file>
  </hookfiles>
  <hookextras_settings/>
  <hookextras_language/>
  <hookextras_modules/>
  <hookextras_help/>
  <hookextras_templates/>
  <hookextras_css/>
  <hookextras_replacements/>
  <hookextras_tasks/>
  <hookextras_database_create/>
  <hookextras_database_alter/>
  <hookextras_database_update/>
  <hookextras_database_insert/>
</hookexport>
