Chapter 3: Blog type

Chapter 3: Blog type

In the blog.php file we define our class as follows:

class ARKContextsMyCCKBlog extends ARKContextsMyCCKItem
{
	//Rest of the code goes here…
}

We extend the ARKContextsMyCCKItem class we defined in the item.php file for the item type. This is because most of the work is already done by that class; all we need to do is make slight modifications to the triggerContentPlugins and the Save method.

Here is our full implementation for the ARKContextsMyCCKBlog class:

class ARKContextsMyCCKBlog extends ARKContextsMyCCKItem
{
			
	public function triggerContentPlugins($rawText)
	{
		
		$item = new stdclass;
					
		$text = '';
		
		if (isset($rawText))
		{
			$pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i';
			$tagPos = preg_match($pattern, $rawText);
			
			if ($tagPos == 0)
			{
				
				$text = $rawText;
			}
			else
			{
				list ($text, $rawText) = preg_split($pattern, $rawText, 2);
			}
		}

		$item->text = $text;
		$params = new JObject;
		$params->set('inline',false);
		$dispatcher	= JEventDispatcher::getInstance();
		JPluginHelper::importPlugin('content');
		$dispatcher->trigger('onContentPrepare', array ('com_mycck.category', &$item, &$params, 0));
			
		return array( 'data'=>$item->text);
	}
	
	public function save($data,$type = 'body')
	{
		if($this->id == null)
			return array( 'title'=>'','data'=>'');	

		if($type == 'title')
		{
			$data['title'] = strip_tags($data['title']); 
			$data['title'] = html_entity_decode($data['title']);
		}
		if(isset($data['articletext']))
			$data['articletext'] = base64_decode($data['articletext']);	
		
		$this->table->save($data);
		
		//We need to process data as we are sending it back to the client
		
		JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models');
		$model = JModelLegacy::getInstance('article','ContentModel');
		$item = $model->getItem($this->id);
		$item->text = $item->introtext;
		
		//let's detect if any plugin tags are being used 
		//if so let's inform the system to warn the user
		$message = $this->detectPluginTags($item->text);
		
		$dispatcher	= JEventDispatcher::getInstance();
		JPluginHelper::importPlugin('content');
		$item->params->set('inline',false); //set this so inline plugin does not pick this up
		$dispatcher->trigger('onContentPrepare', array ('com_mycck.category', &$item, &$item->params, 0));
												
		return array( 'title'=>$item->title,'data'=>$item->text,'message'=>$message);	
	}
	
}

TriggerContentPlugins Method

The method is basically the same as the implementation of the parent class, except here we are not simply striping out the read more tag but we are splitting the text and only returning the introduction part.

Save Method

Saving the actual data is the same as in the Item type class. However, when we are returning the data, just as in the trigger ContentPlugins method when we are dealing with the HTML content, we only return the introduction text.

Also, we change this line of code:

$dispatcher->trigger('onContentPrepare', array ('com_mycck.item', &$item, &$item->params, 0));

To

$dispatcher->trigger('onContentPrepare', array ('com_mycck.category', &$item, &$item->params, 0));

Please take note: that how we deal with the introduction text and the main text for our items in our component, maybe different to how you deal with it in yours. You may use some string truncation function and if that is the case you will need to use that method instead.

Read more: Chapter 3: Blog type

  • Hits: 18

Chapter 3: Item Type [TriggerContentPlugins Method]

Chapter 3: Item Type [TriggerContentPlugins Method]

The triggerContentPlugins method, again, is similar to our implementation for the category class as the purpose of it is to render the data back to a similar state before the user edited the editable type.

So we have a two step process:

  1. Use the Get method to get the current selected editable type data as stored in the database so the user can edit the whole content.
  2. After the user has finished editing, use the triggerContentPlugins to render the data back to a similar state as when the active component originally rendered the editable type.

In our component, we use Joomla’s read more tag to mark in edit mode where the introduction text begins and ends. So in this method we have to deal with this also.

Read more: Chapter 3: Item Type [TriggerContentPlugins Method]

  • Hits: 15

Chapter 3: Item Type [Get Method]

Chapter 3: Item Type [Get Method]

In our component, MyCCK, just like Joomla article manager, we store the content for our article/items in two fields in our database table. This makes things easier when we want to show only the introduction text in the category blog view.  So because of this in our get method we have to concatenate the two fields ‘introtext’ and ‘fulltext’ so that when the user comes to inline-edit an article, he can edit the whole article/item.

Read more: Chapter 3: Item Type [Get Method]

  • Hits: 13