public function store($data)
 {
     $data = MageBridgeModelBridgeBlock::decode($data);
     $data = MageBridgeModelBridgeBlock::filterHtml($data);
     return parent::store($data);
 }
 /**
  * Handle the event that is generated when an user tries to login
  * 
  * @access public
  * @param string $context
  * @param object $row
  * @param string $params
  * @param mixed $page
  * @return null
  */
 public function onContentPrepare($context, $row, $params, $page)
 {
     // Do not continue if not enabled
     if ($this->isEnabled() == false) {
         return false;
     }
     // Get system variables
     $bridge = MageBridgeModelBridge::getInstance();
     // Load plugin paramaters
     jimport('joomla.html.parameter');
     $plugin = JPluginHelper::getPlugin('content', 'magebridgetags');
     $pluginParams = new JParameter($plugin->params);
     $max = $pluginParams->get('max_products', 10);
     // Find related data
     $tags = $this->getTags($row);
     // If there are no tags, don't do anything
     if (empty($tags)) {
         return false;
     }
     // Build the bridge
     $segment_id = $bridge->register('api', 'magebridge_tag.list', $tags);
     $bridge->build();
     $products = $bridge->getSegmentData($segment_id);
     // Do not continue if the result is empty
     if (empty($products)) {
         return false;
     }
     // Do not continue if the result is not an array
     if (!is_array($products)) {
         MageBridgeModelDebug::getInstance()->error("Fetching tags resulted in non-array: " . var_export($products, true));
         return false;
     }
     // Only show the needed amount of tags
     $products = array_slice($products, 0, $max);
     // Load the template script (and allow for overrides)
     jimport('joomla.filesystem.path');
     $template_dir = JPATH_THEMES . '/' . JFactory::getApplication()->getTemplate();
     // Determine the right folder
     if (is_dir(dirname(__FILE__) . '/tmpl')) {
         $tmplDir = 'tmpl';
     } else {
         $tmplDir = 'magebridgetags';
     }
     // Load the layout file
     $layout = $template_dir . '/html/plg_magebridgetags/default.php';
     if (!is_file($layout) || !is_readable($layout)) {
         $layout = dirname(__FILE__) . '/' . $tmplDir . '/default.php';
     }
     // Prepare the variables
     $tagstring = implode(', ', $tags);
     // Read the template
     ob_start();
     include $layout;
     $output = ob_get_contents();
     ob_end_clean();
     // Append the result to the content
     $row->text .= MageBridgeModelBridgeBlock::filterHtml($output);
     return true;
 }