| Current Path : /home/juvelize/www/plugins/content/calameo/ |
| Current File : /home/juvelize/www/plugins/content/calameo/calameo.php |
<?php
/*
Plugin Name: Content Calameo
Description: Embed Calameo publications & miniCalameo inside a post
Version: 3.0.0
Author: Calameo
*/
/* Copyright 2012 Calameo (email : contact@calameo.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined('_JEXEC') or die ('Direct Access to this location is not allowed.');
jimport('joomla.plugin.plugin');
class plgContentCalameo extends JPlugin
{
function onContentPrepare($context, $article, $params, $limitstart)
{
// Joomla 1.6
// Joomla 2.5
// Joomla 3.0
$this->Calameo_parser($article, $params, $limitstart);
}
function onPrepareContent($article, $params, $limitstart)
{
// Joomla 1.5
$this->Calameo_parser($article, $params, $limitstart);
}
function Calameo_parser($row, $params, $page = 0)
{
$regex = '/\[calameo (.*?)\]/i';
preg_match_all($regex, $row->text, $matches);
for ($x = 0; $x < count($matches[0]); $x++) {
$replace = $this->calameo_render($matches[0][$x]);
$row->text = str_replace($matches[0][$x], $replace, $row->text);
}
}
function calameo_render( $tags )
{
// Parsing attributes
if ( !preg_match_all('/([^= ]+)=([\S]*)/i', $tags, $matches) ) return '';
$attributes = array();
$count = count($matches[1]);
for ( $i = 0 ; $i < $count ; $i++ )
{
$attributes[$matches[1][$i]] = $matches[2][$i];
}
// Get code from URL
if ( !empty($attributes['url']) )
{
if ( preg_match('~calameo\.com/(read|books)/([0-9a-z]+)~i', $attributes['url'], $regs) )
{
$attributes['code'] = $regs[2];
}
}
// Checking attributes
if ( empty($attributes['code']) ) return '';
if ( empty($attributes['mode']) ) $attributes['mode'] = '';
if ( empty($attributes['page']) ) $attributes['page'] = 1;
if ( empty($attributes['wmode']) ) $attributes['wmode'] = '';
if ( empty($attributes['title']) ) $attributes['title'] = '.';
if ( !isset($attributes['showsharemenu']) ) $attributes['showsharemenu'] = 1;
$attributes['showsharemenu'] = ( $attributes['showsharemenu'] == '1' || $attributes['showsharemenu'] == 'true' ) ? 'true' : 'false';
// Language
$language = preg_match('/$([a-z]+)/i', 'en');
$languages = array(
'en'=>'en',
'fr'=>'fr',
'es'=>'es',
'de'=>'de',
'it'=>'it',
'pt'=>'pt',
'ru'=>'ru',
'ja'=>'jp',
'zh'=>'cn',
'kr'=>'kr'
);
if ( empty($attributes['lang']) )
{
$attributes['lang'] = ( !empty($language) && !empty($languages[$language]) ) ? $languages[$language] : 'en';
}
// Prepare viewer and link URLs
$book_url = 'http://calameo.com/books/' . $attributes['code'] . ( !empty($attributes['authid']) ? '?authid=' . $attributes['authid'] : '' );
$home_url = 'http://calameo.com';
$publish_url = 'http://calameo.com/upload';
$browse_url = 'http://calameo.com/browse/weekly/?o=7&w=DESC';
$viewer_url = 'http://v.calameo.com/';
// Preparing Flashvars
$flashvars = 'bkcode=' . $attributes['code'];
$flashvars .= '&language=' . $attributes['lang'];
$flashvars .= '&page=' . $attributes['page'];
$flashvars .= '&showsharemenu=' . $attributes['showsharemenu'];
switch ( $attributes['mode'] )
{
case 'mini':
if ( empty($attributes['width']) ) $attributes['width'] = '240';
if ( empty($attributes['height']) ) $attributes['height'] = '150';
if ( empty($attributes['clickto']) ) $attributes['clickto'] = 'public';
if ( empty($attributes['clicktarget']) ) $attributes['clicktarget'] = '_self';
if ( empty($attributes['clicktourl']) ) $attributes['clicktourl'] = '';
if ( empty($attributes['autoflip']) ) $attributes['autoflip'] = '0';
if ( empty($attributes['wmode']) ) $attributes['wmode'] = 'transparent';
$flashvars .= '&clickTo=' . urlencode($attributes['clickto']);
$flashvars .= '&clickTarget=' . urlencode($attributes['clicktarget']);
$flashvars .= '&clickToUrl=' . urlencode($attributes['clicktourl']);
$flashvars .= '&autoFlip=' . max(0, intval($attributes['autoflip']));
$flashvars .= '&mode=mini';
break;
case 'book':
case 'viewer':
$flashvars .= '&mode=viewer';
default:
if ( empty($attributes['width']) )$attributes['width'] = '100%';
if ( empty($attributes['height']) ) $attributes['height'] = '400';
break;
}
if ( !empty($attributes['authid']) ) $flashvars .= '&authid=' . $attributes['authid'];
if ( !empty($attributes['view']) ) $flashvars .= '&view=' . $attributes['view'];
if ( !empty($attributes['allowminiskin']) ) $flashvars .= '&allowminiskin=' . $attributes['allowminiskin'];
if ( !empty($attributes['skinurl']) ) $flashvars .= '&skinurl=' . $attributes['skinurl'];
if ( !empty($attributes['styleurl']) ) $flashvars .= '&styleurl=' . $attributes['styleurl'];
if ( !empty($attributes['shareurl']) ) $flashvars .= '&shareurl=' . $attributes['shareurl'];
if ( !empty($attributes['locales']) ) $flashvars .= '&locales=' . $attributes['locales'];
if ( !empty($attributes['volume']) ) $flashvars .= '&volume=' . $attributes['volume'];
if ( !empty($attributes['pagefxopacity']) ) $flashvars .= '&pagefxopacity=' . $attributes['pagefxopacity'];
if ( !empty($attributes['pagefxopacityonzoom']) ) $flashvars .= '&pagefxopacityonzoom=' . $attributes['pagefxopacityonzoom'];
if ( !empty($attributes['ip']) ) $flashvars .= '&ip=' . $attributes['ip'];
if ( !empty($attributes['apikey']) ) $flashvars .= '&apikey=' . $attributes['apikey'];
if ( !empty($attributes['expires']) ) $flashvars .= '&expires=' . $attributes['expires'];
if ( !empty($attributes['signature']) ) $flashvars .= '&signature=' . $attributes['signature'];
// Sizes and units
$attributes['widthUnit'] = ( strpos($attributes['width'], '%') ) ? '' : 'px';
$attributes['heightUnit'] = ( strpos($attributes['height'], '%') ) ? '' : 'px';
// Generate HTML embed code
$html = '<div style="' . ( empty($attributes['styles']) ? 'text-align: center; width:' . $attributes['width'] . $attributes['widthUnit'] . '; margin: 12px auto;' : $attributes['styles'] ) . '">';
if ( empty($attributes['hidelinks']) ) $html .= '<div style="margin: 4px 0px;"><a href="' . $book_url . '">' . $attributes['title'] . '</a></div>';
$id = 'calameo-viewer-' . $attributes['code'] . '-' . mktime() . '-' . rand(1000,9999);
$html .= '<iframe src="' . $viewer_url . '?' . $flashvars . '" width="' . $attributes['width'] . '" height="' . $attributes['height'] . '" style="width:' . $attributes['width'] . $attributes['widthUnit'] . ';height:' . $attributes['height'] . $attributes['heightUnit'] . '" seamless="seamless" frameborder="0" allowtransparency="true"></iframe>';
if ( empty($attributes['hidelinks']) ) $html .= '<div style="margin: 4px 0px; font-size: 90%;"><a rel="nofollow" href="' . $publish_url . '">.</a>.<a href="' . $home_url . '">.</a> . <a href="' . $browse_url . '">.</a>.</div>';
$html .= '</div>';
//
return $html;
}
}
?>