File: /home/centralexf/www/plugins/content/plg_jabookmark.php
<?php
/*
# ------------------------------------------------------------------------
# JA Bookmark plugin for Joomla 1.5
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license - PHP files are GNU/GPL V2. CSS / JS are Copyrighted Commercial,
# bound by Proprietary License of JoomlArt. For details on licensing,
# Please Read Terms of Use at http://www.joomlart.com/terms_of_use.html.
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com
# Redistribution, Modification or Re-licensing of this file in part of full,
# is bound by the License applied.
# ------------------------------------------------------------------------
*/
/**
* JA Bookmark Plugin is a module using for Display icons for your online social networking sites.
*/
// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die();
// include libs.
jimport( 'joomla.plugin.plugin' );
jimport('joomla.application.module.helper');
/**
* plgContentPlg_Jabookmark class
*/
class plgContentPlg_Jabookmark extends JPlugin {
/**
* @var JParameter $params.
*
* @access public.
*/
var $params = null;
/**
* @var stdClass store Plugin Information
*
* @access public
*/
var $plugin;
/**
* var $string $__output store html output.
*
* @access private
*/
var $__output = null;
/**
* constructor.
*/
function plgContentPlg_Jabookmark( &$subject, $params=null ){
if (!$subject) return;
parent::__construct( $subject, $params );
$this->plugin =& JPluginHelper::getPlugin('content', 'plg_jabookmark');
$this->params = new JParameter( $this->plugin->params );
}
/**
* check valid showing addthis service.
*
* @param JParameter $params.
* @param stdClass $article.
* @return boolean.
*/
function isValidShowing( $params, $article, $mode ){
global $option, $mainframe;
if ( $option != "com_content" ) return false;
// and only procces in the article page.
$view = JRequest::getCmd( "view" );
if( strtolower($view) != 'article' ){
return false;
}
if( $mode != 'auto' ){
return true;
}
// check custom_display_in mode
if( $params->get('mode-auto-category', '') == '' ){
return true;
} else {
$categories = $params->get('mode-auto-category');
if( !is_array($categories) ) {
$categories = split( ',', $params->get('mode-auto-category') );
}
if( !empty($categories) ){
return in_array( $article->catid, $categories );
}
}
return true;
}
/**
* only render button some postions such as TOP, BOTTOM, CUSTOM LOCATION.
*/
function onPrepareContent( &$article, &$params, $page=0 ){
if( preg_match('/onPrepareContent-(\w+)/', $this->params->get('location'), $out) ) {
switch( $out[1] ){
case "Bottom":
$article->text .= $this->render( $this->params, $article );
break;
case "Custom":
$article->jabookmark = $this->render( $this->params, $article );
break;
default:
$text = $this->render( $this->params, $article ). $article->text;
$article->text = $text;
unset( $text );
break;
}
}
return true;
}
/**
* only render button at postion after content.
*/
function onAfterDisplayContent( &$article, &$params, $page=0 ){
if( $this->params->get('location') == 'onAfterDisplayContent' ){
$text = $this->render( $this->params, $article );
return $text;
}
}
/**
* only render button at postion before content.
*/
function onBeforeDisplayContent( &$article, &$params, $page=0 ){
if( $this->params->get('location') == 'onBeforeDisplayContent' ){
$text = $this->render( $this->params, $article );
return $text;
}
}
function onAfterDisplayTitle( &$article, &$params, $page=0 ){
if( $this->params->get('location') == 'onAfterDisplayTitle' ){
$text = $this->render( $this->params, $article );
return $text;
}
}
/**
* processing render service layout.
*/
function onAfterRender(){
if( $this->__output != null ){
$body = JResponse::getBody();
$body = str_replace( '</body>', $this->__output ."\n</body>", $body );
JResponse::setBody($body);
unset( $this->__output );
}
}
/**
* render button service
*
* @param JParameter $params
* @array stdClass $article
* @return string.
*/
function render( $params, &$article ){
$overrideLocation = false;
$mode = $params->get('mode');
// only show JA BOOKMARK with content components and article view.
if( !($this->isValidShowing($params, $article, $mode)) ) {
$article->text = $this->removeConfigString( $article->text );
return ;
}
// get configuration string from Article's content.
$configs = $this->parserConfigString( $article->text );
// if use "turnoff" mode
if( $mode == 'turnoff'){
$article->text = $this->removeConfigString( $article->text );
return '';
}
else if( $mode == 'manual' && ( $configs == null || empty($configs)) ){
return '';
}
//find "off" mode in a article
if( isset($configs[0][0]) ){
if( strpos($configs[0][0], "off") ){
$article->text = $this->removeConfigString( $article->text );
return '';
} else {
$overrideLocation = true;
}
}
// load css file
// $this->stylesheet();
$system = $params->get( 'system', 'addthis' );
// get HTML output from system view
$content_layout = $this->renderLayout( $system, compact('system', 'configs') );
// render a centain layout and this system view
$this->__output = $this->renderLayout( 'common', compact('content_layout') );
// it's wapper would be replace by other.
$wapper = '<div id="jabookmarkWapper"></div>';
// if using override location, this function would be apply for all "display mode" options.
if( $overrideLocation ){
$article->text = $this->removeConfigString($article->text, $wapper);
return '';
} else {
return $wapper;
}
}
/**
* render layout, allow override layout by owner.
*
* @param stdClass $plugin plugin information
* @param string layout
* @return string
*/
function getLayoutPath( $plugin, $layout = 'default' ){
global $mainframe;
// Build the template and base path for the layout
$tPath = JPATH_BASE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.$plugin->name.DS.$layout.'.php';
$bPath = JPATH_BASE.DS.'plugins'.DS.$plugin->type.DS.$plugin->name.DS.'tmpl'.DS.$layout.'.php';
// If the template has a layout override use it
if (file_exists($tPath)) {
return $tPath;
} elseif (file_exists($bPath)) {
return $bPath;
}
return '';
}
/**
* render layout.
*
* @param string $layout layout's name.
* @param array data passed.
* @return string is HTML.
*/
function renderLayout( $layout, $data=array() ){
extract( $data );
// include processor file to render User inteface
$pathFile = $this->getLayoutPath( $this->plugin, $layout );
if( $pathFile != '' ){
ob_start();
require_once( $pathFile );
$content = ob_get_contents();
ob_end_clean();
return $content;
}
return '';
}
function stylesheet ( $plugin ) {
global $mainframe;
JHTML::stylesheet('style.css','plugins/'.$plugin->type.'/'.$plugin->name.'/');
if (is_file(JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'css'.DS.$plugin->name.".css"))
JHTML::stylesheet($plugin->name.".css",'templates/'.$mainframe->getTemplate().'/css/');
}
/**
* parser string in the article's content, check having configuration social existed?
*
* @param string $text.
* @return array if having, equal null if not.
*/
function parserConfigString( $text ){
if( preg_match("#{jabookmark(.*)}#s", $text, $matches, PREG_OFFSET_CAPTURE) ){
return $matches;
}
return null;
}
/**
* remove configuration string in the artilce's content.
*
* @param string $text.
* @return boolean
*/
function removeConfigString( $text, $string='' ){
return preg_replace( '#{jabookmark(.*)}#s', $string, $text );
}
}
?>