PDA

Zobacz pełną wersję : Plugin Contented Access Text



dudi88
17-10-2013, 21:07
Witam,

Używam tego pluginu na mojej stronie jednak całkiem dobrze on nie działa.

Kiedy wpiszę w tekście artykułu pomiędzy tagami pluginu jakis tekst bez któregoś z tych znaków: np. "()", "{}", "[]", "*", "?", "+" to plugin działa doskonale, jak tutaj:

{accessText}text text text{/accessText}

Ale jeśli użyję któregoś ze znaków w tekście pomiędzy tagami plugina, np taki znak "()" to plugin nie działa, jak tutaj:

{accessText}text (text) text{/accessText}

Dlaczego?

Kod tego plugin:

<?php

defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.plugin.plugin' );

class plgContentContented_accessText extends JPlugin {

var $plugtag = 'accessText';

function plgContentContented_accessText( &$subject, $params ){
parent::__construct( $subject, $params );
}

function onContentPrepare($context, &$row, &$params, $page = 0){

// API
jimport('joomla.filesystem.file');
$mainframe = &JFactory::getApplication();
$document = &JFactory::getDocument();

// Assign paths
$sitePath = JPATH_SITE;
$siteUrl = JURI::base();

// Check if plugin is enabled
if(JPluginHelper::isEnabled('content','contented_a ccessText')==false) return;


// Load the plugin language file the proper way
JPlugin::loadLanguage('plg_content_contented_acces sText', JPATH_ADMINISTRATOR);

// simple performance check to determine whether plugin should process further
if(JString::strpos($row->text, $this->plugtag) === false) return;

// expression to search for
$regex = '#{'.$this->plugtag.'}(.*?){/'.$this->plugtag.'}#s';

// find all instances of the plugin and put them in $matches
preg_match_all($regex,$row->text,$matches);

// Number of plugins
$count = count($matches[0]);

// Plugin only processes if there are any instances of the plugin in the text
if(!$count) return;



// ----------------------------------- Get plugin parameters -----------------------------------

$linktext = $this->params->get('linktext','Register now to access');
$linkto = (int) $this->params->get('linkto', 0);
$itemid = (int) $this->params->get('itemid', 160);
$menuitem = $this->params->get('menuitem');
$usergroup = (int) $this->params->get('usergroup',2);


//get the users groups
$user = JFactory::getUser();
$userGroups = $user->getAuthorisedGroups();

// Process plugin tags
if(preg_match_all($regex, $row->text, $matches, PREG_PATTERN_ORDER) > 0)
{
// start the replace loop
foreach ($matches[0] as $key => $match) {

$tagcontent = preg_replace('/{.+?}/', '', $match);
if(in_array($usergroup,$userGroups))
{
//show original content (minus curly braces)
$row->text = preg_replace( '#{'.$this->plugtag.'}'.$tagcontent.'{/'.$this->plugtag.'}#s', $tagcontent , $row->text );
}
else
{
//show alternate link
//check action
switch ($linkto)
{
case 0:
$linkurl = $siteUrl . "index.php?option=com_users&view=registration";
break;

case 1:
$linkurl = $siteUrl . "index.php?option=com_k2&amp;view=item&amp;layout=item&amp;id=1 60";
break;

case 2:
$linkurl = $siteUrl . "index.php?option=com_content&view=article&id=" . $itemid;
break;

case 3:
$linkurl = $siteUrl . "index.php?option=com_k2&view=item&id=" . $itemid;
break;

case 4:
$db = JFactory::getDBO();
$query = "SELECT link FROM #__menu WHERE id=" . $menuitem;
$db->setQuery($query);
$linkurl= $db->loadResult() . "&Itemid=" . $menuitem;
break;

case 5:
$linkurl = false;
break;
}

//now generate code
if ($linkurl)
{
$newcontent = '<a class="accesstext" href=" '. $linkurl . '">' . $linktext . '</a>';
$row->text = preg_replace( '#{'.$this->plugtag.'}'.$tagcontent.'{/'.$this->plugtag.'}#s', $newcontent , $row->text );
}
else
{
$row->text = preg_replace( '#{'.$this->plugtag.'}'.$tagcontent.'{/'.$this->plugtag.'}#s', $linktext , $row->text );
}
}//end else
} // end foreach
} // end if
}

} // End class



Proszę o pomoc.
Dziękuję!