Current Path :
/
home
/
develito
/
public_html
/
plugins
/
content
/
loadbook
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/public_html/plugins/content/loadbook/loadbook.php
<?php /** * @package loadbook Abook plugin * @copyright (C) 2010-2019 Federica Ugolotti * @license GNU/GPL, see LICENSE.php * Abook is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License 3 * as published by the Free Software Foundation. * Abook 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 Abook; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // no direct access // Check to ensure this file is included in Joomla! defined( '_JEXEC' ) or die(); jimport( 'joomla.html.html' ); jimport('joomla.plugin.plugin'); include_once(JPATH_SITE.'/components/com_abook/helpers/route.php'); class plgContentLoadbook extends JPlugin { public function onContentPrepare( $context, &$article, &$params, $page = 0 ) { $this->loadLanguage(); if (strpos($article->text, 'loadbook') === false) { return true; } // get a style sheet $doc = JFactory::getDocument(); $doc->addStyleSheet( 'components/com_abook/assets/css/style.css' ); $regex = '/{(loadbook)\s*(.*?)}/i'; $componentParams = JComponentHelper::getParams( 'com_abook' ); if ($componentParams->get('linkimage')!=''){ $img='<img src="components/com_abook/assets/images/link/'.$componentParams->get( 'linkimage', 'carrello.png').'" alt="" hspace="5px" style="vertical-align:middle;"/>'; } else { $img=null; } $parms=array(); $matches = array(); preg_match_all( $regex, $article->text, $matches, PREG_SET_ORDER ); if ($matches) { foreach ($matches as $elm) { $line=str_replace(" ", " ", $elm[2]); $line=str_replace(" ", "&", $line); parse_str( $line, $parms ); $html=$this->_book($parms, $params, $img); $article->text = preg_replace($regex, $html, $article->text, 1); } } } protected function _book($parms, $params, $img) { $componentParams = JComponentHelper::getParams( 'com_abook' ); $id=$parms['id']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('b.*, CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(":", b.id, b.alias) ELSE b.id END as slug'); $query->from('#__abbook AS b'); if ($this->params->get('showeditor')){ $query->select('e.name AS editor, e.id'); $query->join('left', '#__abeditor AS e ON e.id=b.ideditor'); } if ($this->params->get('showlocation')){ $query->select('l.name AS location, l.id'); $query->join('left', '#__ablocations AS l ON l.id=b.idlocation'); } if ($this->params->get('showlibrary')){ $query->select('lb.name AS library, lb.id'); $query->join('left', '#__ablibrary AS lb ON lb.id=b.idlibrary'); } $query->where('b.id='.$id); $db->setQuery( $query ); $book = $db->loadObject(); if (!$book) { $html ="<div class='abook_alert'>"; $html .= JText::sprintf("PLG_LOADBOOK_BOOK_NOT_FOUND", $id); $html .="</div>"; return $html; } $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); if (!in_array($book->access, $groups)) { //if ($book->access>(int) $user->gid){ return; } if ($book->state=='0') { $html ="<div class='abook_alert'>"; $html .= JText::_("PLG_LOADBOOK_BOOK_NOT_PUBLISHED")." ". $id; $html .="</div>"; return $html; }else{ $query = $db->getQuery(true); $query->select('*, CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(":", id, alias) ELSE id END as slug'); $query->from('#__abcategories'); $query->where('id='.$book->catid); $query->where('published=1'); $db->setQuery( $query ); $db->query(); $row=$db->getNumRows(); if ($this->params->get('showcategory')&&($row==1)) { $category = $db->loadObject(); if (!in_array($category->access, $groups)){ return; } }else{ $html ="<div class='abook_alert'>"; $html .= JText::_("PLG_LOADBOOK_CATEGORY_NOT_PUBLISHED")." ".$book->catid; $html .="</div>"; return $html; } } if ($this->params->get('showrating')){ $query = $db->getQuery(true); $query->select('ROUND( rating_sum / rating_count ) AS rating, rating_count'); $query->from('#__abrating'); $query->where('book_id='.$id); $db->setQuery( $query ); $rating = $db->loadObject(); $rating->rating = intval(@$rating->rating); $rating->rating_count = intval(@$rating->rating_count); } if ($this->params->get('showauthor')){ $query = $db->getQuery(true); $query->select('*, CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug'); if ($componentParams->get('name_display', 0) == 1){ $query->select('CONCAT(a.name, " ", a.lastname) AS name'); }else{ $query->select('CONCAT(a.lastname, " ", a.name) AS name'); } $query->from('#__abbookauth AS ab'); $query->join('INNER', '#__abauthor a ON ab.idauth = a.id'); $query->where('ab.idbook='.$id); $db->setQuery( $query ); $authors = $db->loadObjectList(); $n=count($authors); if ($n==0){ $authors=""; } } $itemid=$this->params->get('set_itemid'); $link=JRoute::_( AbookHelperRoute::getBookRoute($book->slug, $category->slug)); $html= null; $parms['style']= !isset($parms['style'])? 'standard':$parms['style']; switch ($parms['style']){ case 'bibliography': $style="<div class='clearfix'></div>"; $style.='<span class="bibliography">• '; if ($authors!=""){ $auth=null; $k=1; foreach ($authors as $author){ $link=JRoute::_( AbookHelperRoute::getAuthorRoute($author->slug)); $auth.='<a href="'.$link.'" class="biblio_author">'.$author->name."</a>"; $auth.= ($n == $k) ? '': ', '; $k=$k+1; } $style.=$auth; } $style.=', <a href="'.$link.'" class="biblio_title">'.$book->title; if ($book->subtitle!=""){ $style.='. '.$book->subtitle; } $style.='</a>'; if ($book->location!=""){ $style.=', '.$book->location; } if ($book->editor!=""){ $style.=', '.$book->editor; } if ($book->year!=0){ $style.=', '.$book->year; } $style.='</span>'; break; case "standard": default: if (($parms['style']=="standard")|| (!$parms['style'])){ $style='<div class="abook plg_content_abook">'; if ($this->params->get('showtitle')) $style.="\n".'<h2><a href="'.$link.'">'.$book->title."</a></h2>"; if ($book->subtitle != '') $style.="\n"."<h4>".$book->subtitle."</h4>"; if ($authors > 0 && $this->params->get('showauthor')){ $style.='<p>'; $auth=null; $k=1; foreach ($authors as $author){ $link=JRoute::_( AbookHelperRoute::getAuthorRoute($author->slug)); $auth.='<a href="'.$link.'">'.$author->name."</a>"; $auth.= ($n == $k) ? '': ', '; $k=$k+1; } $style.="\n".$book->editedby==1 ? JText::_('PLG_LOADBOOK_EDITED_BY')." " : JText::_('PLG_LOADBOOK_BY')." ".$auth; $style.='</p>'; } $style.='<div class="row-fluid booktab">'; $style.='<div class="span3">'; if ($book->image!=''){ $componentParams = JComponentHelper::getParams( 'com_abook' ); $style.='<img class="img-polaroid" src="'.$book->image.'" alt="'.$book->title.'" />'; }else{ $style.='<img class="img-polaroid" src="components/com_abook/assets/images/nocover.png" alt="nocover" />'; } if ($this->params->get('showrating')){ $star=""; $imgstar = ''; // look for images in template if available $starImageOn = JHTML::_('image','system/rating_star.png', NULL, NULL, true); $starImageOff = JHTML::_('image','system/rating_star_blank.png', NULL, NULL, true); for ($i=0; $i < $rating->rating; $i++) { $imgstar .= $starImageOn; } for ($i=$rating->rating; $i < 5; $i++) { $imgstar .= $starImageOff; } $star .= '<span class="content_rating">'; $star .= $imgstar .' / '; $star .= intval( $rating->rating_count ); $star .= "</span>\n"; $rate=$star; $style .= "\n<p>".$rate.'</p>'; } $style.="</div>"; $style.='<div class="span9 bookdetails">'; $style.='<dl>'; if ($this->params->get('showcategory')){ $link=JRoute::_( AbookHelperRoute::getCategoryRoute($category->slug)); $style .= "\n".'<dd>'; $style .= "\n<span class='icon-folder-open'></span> ".JText::_('PLG_LOADBOOK_CATEGORY').": "; $style .= "\n".'<a href="'.$link.'">'.$category->title.'</a>'; $style .= "\n</dd>"; } if ($this->params->get('showeditor')){ if ($book->editor!="") $style.="\n".'<dd><span class="icon-briefcase"></span> <strong>'.JText::_('PLG_LOADBOOK_EDITOR').":</strong> ".$book->editor."</dd>"; } if ($this->params->get('showpage')){ if ($book->pag!=0) $style.="\n".'<dd><span class="icon-stack"></span> <strong>'.JText::_('PLG_LOADBOOK_PAGES').":</strong> ".$book->pag."</dd>"; } if ($this->params->get('showprice')){ if ($book->price!=0) $style.="\n".'<dd><strong>'.JText::_('PLG_LOADBOOK_PRICE').":</strong> ".$book->price."</dd>"; } if ($this->params->get('showisbn')){ if ($book->isbn!="") $style.="\n".'<dd><strong>'.JText::_('PLG_LOADBOOK_ISBN').":</strong> ".$book->isbn."</dd>"; } if ($this->params->get('showcatalog')){ if ($book->catalogo!=0) $style.="\n".'<dd><strong>'.JText::_('PLG_LOADBOOK_CATALOG').":</strong> ".$book->catalogo."</dd>"; } if ($this->params->get('showlibrary')){ if ($book->library!="") $style.="\n".'<dd><span class="icon-home"></span> <strong>'.JText::_('PLG_LOADBOOK_LIBRARY').":</strong> ".$book->library."</dd>"; } if ($this->params->get('showlocation')){ if ($book->location!="") $style.="\n".'<dd><span class="icon-flag"></span> <strong>'.JText::_('PLG_LOADBOOK_LOCATION').":</strong> ".$book->location."</dd>"; } if ($this->params->get('showyear')){ if ($book->year!=0) $style.="\n".'<dd><span class="icon-calendar"></span> <strong>'.JText::_('PLG_LOADBOOK_YEAR').":</strong> ".$book->year."</dd>"; } if ($this->params->get('showlink')){ if ($book->url!="") $style.="\n".'<dd><strong>'.JText::_('PLG_LOADBOOK_LINK').':</strong> <a href="'.$book->url.'" target="_blank">'.$img.$book->url_label.'</a></dd>'; } if ($this->params->get('showfile')){ if ($book->file!="") $style.="\n".'<dd><span class="icon-file"></span> <strong>'.JText::_('PLG_LOADBOOK_FILE').':</strong> <a href="'.$book->file.'">'.$book->file.'</a></dd>'; } //$style.="</div>"; $style.="</dl></div></div></div>"; } break; } $html .= $style; return $html; } } ?>