RandomAdInserter plugin issues

More
14 years 1 month ago #5131 by webcluj
I was trying to make the RandomAdInserter plugin work inside a flexycontent page but it did not load the ad inside the content.
I modified the code to check for 'items' view and work on $article->fulltext instead on $article->text.
I also enabled the plugin, and I enabled it to work on the main description field.
What can I do to make it work?
Code:
<?php /** * @description : * @version $Id: RandomAdInserter.php 1.5 * @copyright OpenGlobal * @license GPL * @author OpenGlobal - http://www.openglobal.co.uk */ if(!defined('_JEXEC')) die('Restricted access'); jimport( 'joomla.event.plugin' ); $GLOBALS['ograi_adsused'] = 0; class plgContentRandomAdInserter extends JPlugin { function isArticle() { return JRequest :: getVar('view') == 'items' ? TRUE : FALSE; } function isSection() { return JRequest :: getVar('view') == 'section' ? TRUE : FALSE; } function isCategory() { return JRequest::getVar('view') == 'category' ? TRUE : FALSE; } function isHome() { $menu = & JSite::getMenu(); return $menu->getActive() == $menu->getDefault() ? TRUE : FALSE; } function isFrontPage() { return JRequest :: getVar('view') == 'frontpage' ? TRUE : FALSE; } function isBlogView() { return JRequest :: getVar('layout') == 'blog' ? TRUE : FALSE; } function param($name) { static $plugin,$pluginParams; if (!isset( $plugin )) { $plugin =& JPluginHelper::getPlugin('content', 'RandomAdInserter'); $pluginParams = new JParameter( $plugin->params ); } return $pluginParams->get($name); } function plgContentRandomAdInserter( &$subject, $params ) { parent::__construct( $subject, $params ); } function trimArray($array) { if(!is_array($array)||empty($array)) { return array(); } foreach ($array as &$item) { $item = trim($item); } return $array; } function onPrepareContent( &$article, &$params ) { $not_show_articles = $this->trimArray(explode(',',$this->param('not_show_articles'))); $not_show_cats = $this->trimArray(explode(',',$this->param('not_show_categories'))); if (!(($article->catid && in_array($article->catid,$not_show_cats)) || ($article->id && in_array($article->id,$not_show_articles)))) { if ( ($this->isHome() && $this->param('show_in_home')) || ($this->isSection() && $this->isBlogView() && $this->param('show_in_sections') == 1) || ($this->isCategory() && $this->isBlogView() && ($this->param('show_in_categories') == 1)) || ($this->isArticle()) && ($this->param('show_in_articles') == 1)) { if ($article->fulltext) { if ($GLOBALS['ograi_adsused'] < $this->param('max_ads_per_page')) { $GLOBALS['ograi_adsused']++; $positions = array(); $lastpos = -1; $repchar = (strpos($article->fulltext, "<p") === false) ? "<br" : "<p"; while (strpos($article->fulltext, $repchar, $lastpos+1) !== false) { $lastpos = strpos($article->fulltext, $repchar, $lastpos+1); $positions[] = $lastpos; } $article->fulltext = substr_replace($article->fulltext, $this->param('adcode'), $positions[rand(0, sizeof($positions)-1)], 0); } } } } } } ?>

Please Log in or Create an account to join the conversation.

More
14 years 1 month ago #5132 by kenmcd
.
Moderator note: split from another thread.


Please post a link to the plug-in info, download, etc.

.

Please Log in or Create an account to join the conversation.

More
More
14 years 1 month ago #5231 by kenmcd
.
Working here in items/articles.
Just changed "article" to "items" on line 17.

Everything other than Show ads in articles must be set to Off.
All the other settings depend on core Joomla features - Section Blog, Category Blog, Frontpage, etc. - which do not exist in FLEXIcontent.

The Category and Article exemption parameters should probably also work, but I did not test them.

Getting it to work in other locations within FLEXIcontent would require substantial modifications.

.

Please Log in or Create an account to join the conversation.

More
14 years 1 month ago #5268 by webcluj
Thank you :)

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.282 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline