<?php
/**
* @package pkg_dearflip
* @subpackage plg_dearflip
* @since 1.0.2
* @copyright Copyright © 2007 Free Software Foundation, Inc. All rights reserved.
* @license GNU General Public License version 3 or later; see https://www.gnu.org/licenses/gpl-3.0.en.html
*/
defined('_JEXEC') or die('Restricted access');
//use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
class PlgContentDearflip extends JPlugin
{
protected $autoloadLanguage = true;
//Global setting function for retrieving global values and returns an array of global values.
public function globalSettings($context)
{
if (strpos($context,'com_finder')!==false || strpos($context,'com_ajax') !== false){
return true;
}
//startglobal
$db1 = JFactory::getDbo();
$query1 = $db1->getQuery(true);
$query1->select(array('id',
'dfx_setting_3d_2d',
'dfx_setting_hardpages',
'dfx_setting_pdfPagerenderSize',
'dfx_setting_autoEnableSound',
'dfx_setting_enableDownload',
'dfx_setting_pageMode',
'dfx_setting_singlePageMode',
'dfx_setting_controlsPosition',
'dfx_setting_enableAutoPlay',
'dfx_setting_enableAutoPlayAutomatically',
'dfx_setting_thumb_type',
'dfx_setting_enableAnalytics',
'dfx_setting_enableZoomOnScroll',
'dfx_setting_bgColor',
'dfx_setting_bgImage',
'dfx_setting_containerHeight',
'dfx_setting_paddingLeft',
'dfx_setting_paddingRight',
'dfx_setting_flipduration',
'dfx_setting_zoomRatio',
'dfx_setting_paperStiffness',
'dfx_setting_moreControls',
'dfx_settings_hide_controls',
'dfx_setting_disablePartialLoading',
'dfx_setting_pdfPartialLoadingChunkSize',
'dfx_setting_autoplayDuration',
'dfx_setting_pdfLinkOpenTarget',
'dfx_settings_translate_loading_message',
'dfx_settings_translate_turn_on_off_sound',
'dfx_settings_translate_toggle_thumbnails',
'dfx_settings_translate_toggle_outline_bookmark',
'dfx_settings_translate_previous_page' ,
'dfx_settings_translate_next_page',
'dfx_settings_translate_toggle_fullscreen',
'dfx_settings_translate_zoom_in',
'dfx_settings_translate_zoom_out',
'dfx_settings_translate_toggle_help',
'dfx_settings_translate_single_page_mode',
'dfx_settings_translate_double_page_mode',
'dfx_settings_translate_download_pdf_file',
'dfx_settings_translate_goto_first_page',
'dfx_settings_translate_goto_last_page',
'dfx_settings_translate_play',
'dfx_settings_translate_pause',
'dfx_settings_translate_share',
'dfx_settings_translate_share_mail_subject',
'dfx_settings_translate_share_mail_message'
))
->from($db1->quoteName('#__dearflipsetting'))
->order($db1->quoteName('id') . ' DESC');
$db1->setQuery($query1);
$globalrows = $db1->loadAssocList();
$pdfchunksize_in_bytes=$globalrows[0]['dfx_setting_pdfPartialLoadingChunkSize']*1024;
//start global script
?>
<script type="text/javascript">
// TODO dflip location
var dFlipLocation = "<?php echo JURI::root() . 'plugins/content/dearflip/dflip/' ?>";
var dFlipWPGlobal={
webgl: <?php echo $globalrows[0]['dfx_setting_3d_2d']; ?>,
autoPlay: <?php echo $globalrows[0]['dfx_setting_enableAutoPlay']; ?>,
autoPlayDuration: <?php echo $globalrows[0]['dfx_setting_autoplayDuration']; ?>,
autoPlayStart: <?php echo $globalrows[0]['dfx_setting_enableAutoPlayAutomatically']; ?>,
backgroundColor: "<?php echo $globalrows[0]['dfx_setting_bgColor']; ?>",
backgroundImage: "<?php echo JURI::root() . $globalrows[0]['dfx_setting_bgImage']; ?>",
height: "<?php echo $globalrows[0]['dfx_setting_containerHeight']; ?>",
controlsPosition: "<?php echo $globalrows[0]['dfx_setting_controlsPosition']; ?>",
disableRange: <?php echo $globalrows[0]['dfx_setting_disablePartialLoading']; ?>,
duration: "<?php echo $globalrows[0]['dfx_setting_flipduration']; ?>",
enableAnalytics: <?php echo $globalrows[0]['dfx_setting_enableAnalytics']; ?>,
enableDownload: <?php echo $globalrows[0]['dfx_setting_enableDownload']; ?>,
hard: "<?php echo $globalrows[0]['dfx_setting_hardpages']; ?>",
hideControls: "<?php echo $globalrows[0]['dfx_settings_hide_controls']; ?>",
linkTarget: <?php echo $globalrows[0]['dfx_setting_pdfLinkOpenTarget']; ?>,
<?php
if($globalrows[0]['dfx_setting_moreControls'] =="")
{
?> moreControls: "download,pageMode,startPage,endPage,sound", <?php
}
else{
?>
moreControls: "<?php echo $globalrows[0]['dfx_setting_moreControls']; ?>",
<?php
}
?>
paddingLeft: <?php echo $globalrows[0]['dfx_setting_paddingLeft']; ?>,
paddingRight: <?php echo $globalrows[0]['dfx_setting_paddingRight']; ?>,
pageMode: <?php echo $globalrows[0]['dfx_setting_pageMode']; ?>,
pdfRenderSize: "<?php echo $globalrows[0]['dfx_setting_pdfPagerenderSize']; ?>",
rangeChunkSize: "<?php echo $pdfchunksize_in_bytes?>",
scrollWheel: <?php echo $globalrows[0]['dfx_setting_enableZoomOnScroll']; ?>,
zoomRatio: <?php echo $globalrows[0]['dfx_setting_zoomRatio']; ?>,
singlePageMode: <?php echo $globalrows[0]['dfx_setting_singlePageMode']; ?>,
soundEnable: <?php echo $globalrows[0]['dfx_setting_autoEnableSound']; ?>,
stiffness: <?php echo $globalrows[0]['dfx_setting_paperStiffness']; ?>,
text:{
<?php
if(!$globalrows[0]['dfx_settings_translate_loading_message'] =="")
{
?> loading: "<?php echo $globalrows[0]['dfx_settings_translate_loading_message']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_turn_on_off_sound'] =="")
{
?> toggleSound: "<?php echo $globalrows[0]['dfx_settings_translate_turn_on_off_sound']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_toggle_thumbnails'] =="")
{
?> toggleThumbnails: "<?php echo $globalrows[0]['dfx_settings_translate_toggle_thumbnails']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_toggle_outline_bookmark'] =="")
{
?>
toggleOutline: "<?php echo $globalrows[0]['dfx_settings_translate_toggle_outline_bookmark']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_previous_page'] =="")
{
?>
previousPage:"<?php echo $globalrows[0]['dfx_settings_translate_previous_page']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_next_page'] =="")
{
?>
nextPage: "<?php echo $globalrows[0]['dfx_settings_translate_next_page']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_toggle_fullscreen'] =="")
{
?>
toggleFullscreen: "<?php echo $globalrows[0]['dfx_settings_translate_toggle_fullscreen']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_zoom_in'] =="")
{
?>
zoomIn: "<?php echo $globalrows[0]['dfx_settings_translate_zoom_in']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_zoom_out'] =="")
{
?>
zoomOut: "<?php echo $globalrows[0]['dfx_settings_translate_zoom_out']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_toggle_help'] =="")
{
?>
toggleHelp: "<?php echo $globalrows[0]['dfx_settings_translate_toggle_help']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_single_page_mode'] =="")
{
?>
singlePageMode: "<?php echo $globalrows[0]['dfx_settings_translate_single_page_mode']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_double_page_mode'] =="")
{
?>
doublePageMode: "<?php echo $globalrows[0]['dfx_settings_translate_double_page_mode']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_download_pdf_file'] =="")
{
?>
downloadPDFFile: "<?php echo $globalrows[0]['dfx_settings_translate_download_pdf_file']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_goto_first_page'] =="")
{
?>
gotoFirstPage: "<?php echo $globalrows[0]['dfx_settings_translate_goto_first_page']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_goto_last_page'] =="")
{
?>
gotoLastPage: "<?php echo $globalrows[0]['dfx_settings_translate_goto_last_page']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_play'] =="")
{
?>
play: "<?php echo $globalrows[0]['dfx_settings_translate_play']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_pause'] =="")
{
?>
pause: "<?php echo $globalrows[0]['dfx_settings_translate_pause']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_share'] =="")
{
?>
share: "<?php echo $globalrows[0]['dfx_settings_translate_share']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_share_mail_subject'] =="")
{
?>
mailSubject:"<?php echo $globalrows[0]['dfx_settings_translate_share_mail_subject']?>",
<?php
}
?>
<?php
if(!$globalrows[0]['dfx_settings_translate_share_mail_message'] =="")
{
?>
mailBody:"<?php echo $globalrows[0]['dfx_settings_translate_share_mail_message']?>",
<?php
}
?>
}
}
</script>
<?php
//end global script
//endglobal
return $globalrows;
}
public function dfCallDataBase($id, $condition_quotename){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$conditions = array(
$db->quoteName($condition_quotename) . ' =' . $id
);
$query->select(array('id',
'book_title',
'df_cat',
'published',
'dfx_book_type_list',
'dfx_pdf',
'dfx_images_source',
'dfx_images_sort_by',
'dfx_view_mode',
'dfx_thumb',
'dfx_button_text',
'dfx_custom_text',
'dfx_3d_2d',
'dfx_hardpages',
'dfx_bgColor',
'dfx_bgImage',
'dfx_flipduration',
'dfx_containerHeight',
'dfx_pdfPagerenderSize',
'dfx_autoEnableSound',
'dfx_enableDownload',
'dfx_pageMode',
'dfx_singlePageMode',
'dfx_controlsPosition',
'dfx_hide_controls',
'dfx_direction',
'dfx_forcePageFit',
'dfx_enableAutoPlay',
'dfx_autoPlayDuration',
'dfx_enableAutoPlayAutomatically',
'dfx_pageSize',
'dfx_autoEnableOutline',
'dfx_autoEnableThumbnail'))
->from($db->quoteName('#__dearflip'))
->order($db->quoteName('id') . ' DESC')
->where($conditions);
$db->setQuery($query);
$row = $db->loadAssocList();
return $row;
}
public function onContentPrepare($context, &$article, &$params, $limitstart)
{
if (strpos($context,'com_finder')!==false || strpos($context,'com_ajax') !== false){
return true;
}
$document = JFactory::getDocument();
/* $options = array("version" => "auto");
$attributes = array("defer" => "defer");*/
$document->addStyleSheet(JURI::root() . "plugins/content/dearflip/dflip/css/dflip.min.css?v=2.1.189");
//$document->addStyleSheet(JURI::root() . "plugins/content/dearflip/dflip/css/themify-icons.css");
/* $document->addScript(JURI::root() . "plugins/content/dearflip/dflip/js/libs/jquery.min.js");*/
if(class_exists("HTMLHelper")){
HTMLHelper::_('jquery.framework');
}
else {
JHtml::_('jquery.framework');
}
$document->addScript(JURI::root() . "plugins/content/dearflip/dflip/js/dflip.min.js?v=2.1.189");
$regexmodid = '/{dearflip\sid=([1-9][0-9]*)}/i';
preg_match_all($regexmodid, $article->text, $matchesmodid, PREG_SET_ORDER);
// If no matches, skip this
if ($matchesmodid) {
//run global script only if the shortcode is present in the content
//startglobal
$globalrows = self::globalSettings($context);
//endglobal
foreach ($matchesmodid as $match) {
$id = trim($match[1]);
$row= self::dfCallDataBase($id, 'id');
if (count($row) !== 0 and $row[0]['published']==1 ) {
// We should replace only first occurrence in order to allow positions with the same name to regenerate their content:
if (($start = strpos($article->text, $match[0])) !== false) {
$display_title = '';
$dfd_book_title = $row[0]['book_title'];
if ($dfd_book_title == '') {
$display_title = '[no title]';
} else {
$display_title = $dfd_book_title;
}
$dfd_published = $row[0]['published'];
$dfd_cat = $row[0]['df_cat'];
$dfd_book_type_list = $row[0]['dfx_book_type_list'];
$dfd_pdf = trim($row[0]['dfx_pdf'], ' ');
$checked_absolute_or_relative_url = $this->check_absolute_or_relative_url($dfd_pdf);
$dfd_images_source = trim($row[0]['dfx_images_source'], ' ');
$dfd_images_sort_by = $row[0]['dfx_images_sort_by'];
$dfd_view_mode = $row[0]['dfx_view_mode'];
$dfd_thumb = trim($row[0]['dfx_thumb'], ' ');
//thumb type
$thumbtype= $globalrows[0]['dfx_setting_thumb_type'];
$dfd_button_text = $row[0]['dfx_button_text'];
$dfd_custom_text = $row[0]['dfx_custom_text'];
$dfd_3d_2d = $row[0]['dfx_3d_2d'];
$dfd_hardpages = $row[0]['dfx_hardpages'];
$dfd_bgColor = $row[0]['dfx_bgColor'];
$dfd_bgImage = trim($row[0]['dfx_bgImage'], ' ');
$dfd_flipduration = $row[0] ['dfx_flipduration'];
$dfd_containerHeight = $row[0]['dfx_containerHeight'];
$dfd_pdfPagerenderSize = $row[0]['dfx_pdfPagerenderSize'];
$dfd_autoEnableSound = $row[0]['dfx_autoEnableSound'];
$dfd_enableDownload = $row[0]['dfx_enableDownload'];
$dfd_pageMode = $row[0]['dfx_pageMode'];
$dfd_singlePageMode = $row[0]['dfx_singlePageMode'];
$dfd_controlsPosition = $row[0]['dfx_controlsPosition'];
$dfd_hide_controls= trim($row[0]['dfx_hide_controls'], ' ');
$dfd_direction = $row[0]['dfx_direction'];
$dfd_forcePageFit = $row[0]['dfx_forcePageFit'];
$dfd_enableAutoPlay = $row[0]['dfx_enableAutoPlay'];
$dfd_autoPlayDuration = $row[0]['dfx_autoPlayDuration'];
$dfd_enableAutoPlayAutomatically = $row[0]['dfx_enableAutoPlayAutomatically'];
$dfd_pageSize = $row[0]['dfx_pageSize'];
$dfd_autoEnableOutline = $row[0]['dfx_autoEnableOutline'];
$dfd_autoEnableThumbnail = $row[0]['dfx_autoEnableThumbnail'];
$dflip_id = "option_flip" . $id;
//For PDF Source
$flipbook_source1 = "";
if ($dfd_book_type_list == 1) {
if ($dfd_pdf == "images/") {
$flipbook_source1 = '""';
} else {
/*$flipbook_source1 = '"' . JURI::root() . $dfd_pdf . '"';*/
$flipbook_source1 = 'atob("' .base64_encode($checked_absolute_or_relative_url) . '")';
}
} else {
if ($dfd_images_source == "images/") {
$flipbook_source1 = '""';
} else {
$image_files = glob("" . $dfd_images_source . "/*.{jpe,jpeg,JPEG,JPG,PNG,jpg,png,bmp,GIF,gif}", GLOB_BRACE);
$unsorted_images_files=$image_files;
switch ($dfd_images_sort_by) {
case "2":
$sorted_images_files=$this->sort_by_images_name_desc($unsorted_images_files);
break;
case "3":
$sorted_images_files=$this->sort_by_images_newest_first($unsorted_images_files);
break;
case "4":
$sorted_images_files=$this->sort_by_images_oldest_first($unsorted_images_files);
break;
default:
$sorted_images_files=$this->sort_by_images_name_asc($unsorted_images_files);
}
$images_src = JUri::base() . implode("','" . JUri::base(), $sorted_images_files);
$flipbook_source1 = "['" . $images_src . "']";
/* echo "$flipbook_source1";*/
}
}
?>
<script type="text/javascript">
var <?php echo $dflip_id ?> =
{
source: <?php echo $flipbook_source1 ?>,
//webgl
<?php
if($dfd_3d_2d!="global")
{
?> webgl: "<?php echo $dfd_3d_2d ?>", <?php
}
?>
//height
<?php
if(!($dfd_containerHeight=="global" || $dfd_containerHeight ==""))
{
?> height: "<?php echo $dfd_containerHeight?>", <?php
}
?>
//background color
<?php
if(!($dfd_bgColor=="global" || $dfd_bgColor ==""))
{
?> backgroundColor: "<?php echo $dfd_bgColor?>", <?php
}
?>
//background image
<?php
if($dfd_bgImage!="")
{
?> backgroundImage: "<?php echo JURI::root() . $dfd_bgImage?>", <?php
}
?>
//flip duration
<?php
if(! ($dfd_flipduration == "global" || $dfd_flipduration == ""))
{
?> duration: "<?php echo $dfd_flipduration?>", <?php
}
?>
/*
:<?php /*echo $dfd_flipduration*/?>,*/
//hard pages
<?php
if($dfd_hardpages!="global")
{
?> hard: "<?php echo $dfd_hardpages?>", <?php
}
?>
//pdf page render size
<?php
if($dfd_pdfPagerenderSize!="global")
{
?> pdfRenderSize: "<?php echo $dfd_pdfPagerenderSize?>", <?php
}
?>
//enable sound
<?php
if($dfd_autoEnableSound!="global")
{
?> soundEnable: <?php echo $dfd_autoEnableSound?>, <?php
}
?>
//enable download
<?php
if($dfd_enableDownload!="global")
{
?> enableDownload: <?php echo $dfd_enableDownload?>, <?php
}
?>
//page mode
<?php
if($dfd_pageMode!="global")
{
?> pageMode: <?php echo $dfd_pageMode?>, <?php
}
?>
//single page mode
<?php
if($dfd_singlePageMode!="global")
{
?> singlePageMode: <?php echo $dfd_singlePageMode?>, <?php
}
?>
//direction
direction: "<?php echo $dfd_direction?>",
//enable autoplay
<?php
if($dfd_enableAutoPlay!="global")
{
?> autoPlay: <?php echo $dfd_enableAutoPlay?>, <?php
}
?>
//autoplay duration
<?php
if(!($dfd_autoPlayDuration=="global" || $dfd_autoPlayDuration == ""))
{
?> autoPlayDuration: <?php echo $dfd_autoPlayDuration?>, <?php
}
?>
//Enable autoplay automatically
<?php
if($dfd_enableAutoPlayAutomatically!="global")
{
?> autoPlayStart: <?php echo $dfd_enableAutoPlayAutomatically?>, <?php
}
?>
//hide controls
<?php
if(!($dfd_hide_controls=="global" || $dfd_hide_controls == ""))
{
?> hideControls: "<?php echo $dfd_hide_controls?>", <?php
}
?>
//controls position
<?php
if($dfd_controlsPosition!="global")
{
?> controlsPosition: "<?php echo $dfd_controlsPosition?>", <?php
}
?>
//page size
<?php
if($dfd_pageSize!="global")
{
?> pageSize: <?php echo $dfd_pageSize?>, <?php
}
?>
forceFit:<?php echo $dfd_forcePageFit?>,
autoEnableOutline: <?php echo $dfd_autoEnableOutline?>,
autoEnableThumbnail:<?php echo $dfd_autoEnableThumbnail?>,
}
;
</script>
<?php
//
if ($dfd_view_mode == '_df_book') {
$article->text = substr_replace($article->text, "<div class='_df_book' id='flip" . $id . "' > </div>", $start, strlen($match[0]));
} elseif ($dfd_view_mode == '_df_thumb') {
if( $thumbtype=="img"){
if($dfd_thumb=="")
{
$article->text = substr_replace($article->text, "<div class='_df_thumb' thumbtype='img' id='flip" . $id . "' >" . $display_title . " </div>", $start, strlen($match[0]));
}
else {
$article->text = substr_replace($article->text, "<div class='_df_thumb' thumbtype='img' thumb= '" . JURI::root() . $dfd_thumb . "' id='flip" . $id . "'
>" . $display_title . " </div>", $start, strlen($match[0]));
}
}
elseif ($thumbtype=="div"){
$article->text = substr_replace($article->text, "<div class='_df_thumb' thumbtype='div' id='flip" . $id . "' thumb= '" . JURI::root() . $dfd_thumb . "' >" . $display_title . " </div>", $start, strlen($match[0]));
}
} elseif ($dfd_view_mode == '_df_button') {
$article->text = substr_replace($article->text, "<div class='_df_button' id='flip" . $id . "' > " . $dfd_button_text . " </div>", $start, strlen($match[0]));
} elseif ($dfd_view_mode == '_df_custom') {
$article->text = substr_replace($article->text, "<div class='_df_custom' id='flip" . $id . "' > " . $dfd_custom_text . " </div>", $start, strlen($match[0]));
}
}
}
else {
if (($start = strpos($article->text, $match[0])) !== false) {
$article->text = substr_replace($article->text, "<div class='dearflip-book' ></div>", $start, strlen($match[0]));
}
}
}
}
//startcategory
$regexcat = '/{dearflip\scategory_id=([1-9][0-9]*)}/i';
preg_match_all($regexcat, $article->text, $matchescatid, PREG_SET_ORDER);
if ($matchescatid) {
//startglobal
$globalrows = self::globalSettings($context);
//endglobal
foreach ($matchescatid as $matchcat) {
$catid = trim($matchcat[1]);
$db1 = JFactory::getDbo();
$query1 = $db1->getQuery(true);
$conditions1 = array(
$db1->quoteName('id') . ' =' . $catid
);
$query1->select(array('id', 'dfx_cat_view_mode','dfx_cat_button_text_type',
'published'))
->from($db1->quoteName('#__dearflipcat'))
->order($db1->quoteName('id') . ' DESC')
->where($conditions1);
$db1->setQuery($query1);
$catss = $db1->loadAssocList();
// end test
if (count($catss) != 0 and $catss[0]["published"] == 1) {
$dfx_cat_view_mode= $catss[0]['dfx_cat_view_mode'];
$dfx_cat_button_text_type= $catss[0]['dfx_cat_button_text_type'];
$catrows= self::dfCallDataBase($catid, 'df_cat');
if (count($catrows) !== 0) {
$replacearry = [];
if (($start = strpos($article->text, $matchcat[0])) !== false) {
foreach ($catrows as $catrow) {
$display_title = '';
$dfd_book_title = $catrow['book_title'];
if ($dfd_book_title == '') {
$display_title = '[no title]';
} else {
$display_title = $dfd_book_title;
}
$dfd_published = $catrow['published'];
$dfd_cat = $catrow['df_cat'];
$dfd_book_type_list = $catrow['dfx_book_type_list'];
$dfd_pdf = trim($catrow['dfx_pdf'], ' ');
$checked_absolute_or_relative_url_for_cat= $this->check_absolute_or_relative_url($dfd_pdf);
$dfd_images_source = trim($catrow['dfx_images_source'], ' ');
$dfd_images_sort_by = $catrow['dfx_images_sort_by'];
$dfd_view_mode = '_df_thumb';
$dfd_thumb = trim($catrow['dfx_thumb'], ' ');
$dfd_button_text=$catrow['dfx_button_text'];
$dfd_3d_2d = $catrow['dfx_3d_2d'];
$dfd_hardpages = $catrow['dfx_hardpages'];
$dfd_bgColor = $catrow['dfx_bgColor'];
$dfd_bgImage = trim($catrow['dfx_bgImage'], ' ');
$dfd_flipduration = $catrow['dfx_flipduration'];
$dfd_containerHeight = $catrow['dfx_containerHeight'];
$dfd_pdfPagerenderSize = $catrow['dfx_pdfPagerenderSize'];
$dfd_autoEnableSound = $catrow['dfx_autoEnableSound'];
$dfd_enableDownload = $catrow['dfx_enableDownload'];
$dfd_pageMode = $catrow['dfx_pageMode'];
$dfd_singlePageMode = $catrow['dfx_singlePageMode'];
$dfd_controlsPosition = $catrow['dfx_controlsPosition'];
$dfd_hide_controls= trim( $catrow['dfx_hide_controls'], ' ');
$dfd_direction = $catrow['dfx_direction'];
$dfd_forcePageFit = $catrow['dfx_forcePageFit'];
$dfd_enableAutoPlay = $catrow['dfx_enableAutoPlay'];
$dfd_autoPlayDuration = $catrow['dfx_autoPlayDuration'];
$dfd_enableAutoPlayAutomatically = $catrow['dfx_enableAutoPlayAutomatically'];
$dfd_pageSize = $catrow['dfx_pageSize'];
$dfd_autoEnableOutline = $catrow['dfx_autoEnableOutline'];
$dfd_autoEnableThumbnail = $catrow['dfx_autoEnableThumbnail'];
$dflip_id = "option_flip" . $catrow['id'];
if ($dfd_published == 1) {
if ($dfx_cat_view_mode == "_df_button") {
$display_text = '';
if ($dfx_cat_button_text_type == "button_text") {
$display_text = $dfd_button_text;
} else {
$display_text = $display_title;
}
$replacestr = "<div class='_df_button' id='flip" . $catrow['id'] . "' >$display_text</div>";
} elseif ($dfx_cat_view_mode == "_df_thumb") {
$thumbtype = $globalrows[0]['dfx_setting_thumb_type'];
if ($thumbtype == "img") {
if ($dfd_thumb == "") {
$replacestr = "<div class='_df_thumb' thumbtype='img' id='flip" . $catrow['id'] . "' >$display_title</div>";
} else {
$replacestr = "<div class='_df_thumb' thumbtype='img' thumb= '" . JURI::root() . $dfd_thumb . "' id='flip" . $catrow['id'] . "' >$display_title</div>";
}
} elseif ($thumbtype == "div") {
$replacestr = "<div class='_df_thumb' thumbtype='div' thumb= '" . JURI::root() . $dfd_thumb . "' id='flip" . $catrow['id'] . "' >$display_title</div>";
}
}
$replacearry[] = $replacestr;
$flipbook_source = "";
if ($dfd_book_type_list == 1) {
if ($dfd_pdf == "images/") {
$flipbook_source = '""';
} else {
$flipbook_source = 'atob("' .base64_encode($checked_absolute_or_relative_url_for_cat) . '")';
}
}
elseif ($dfd_book_type_list == 2) {
if ($dfd_images_source == "images/") {
$flipbook_source = '""';
} else {
$image_files = glob("" . $dfd_images_source . "/*.{jpe,jpeg,JPEG,JPG,PNG,jpg,png,bmp,GIF,gif}", GLOB_BRACE);
$unsorted_images_files=$image_files;
switch ($dfd_images_sort_by) {
case "2":
$sorted_images_files=$this->sort_by_images_name_desc($unsorted_images_files);
break;
case "3":
$sorted_images_files=$this->sort_by_images_newest_first($unsorted_images_files);
break;
case "4":
$sorted_images_files=$this->sort_by_images_oldest_first($unsorted_images_files);
break;
default:
$sorted_images_files=$this->sort_by_images_name_asc($unsorted_images_files);
}
$images_src = JUri::base() . implode("','" . JUri::base(), $sorted_images_files);
$flipbook_source = "['" . $images_src . "']";
}
}
?>
<script type="text/javascript">
var <?php echo $dflip_id ?> =
{
source: <?php echo $flipbook_source ?>,
//webgl
<?php
if($dfd_3d_2d!="global")
{
?> webgl: "<?php echo $dfd_3d_2d?>", <?php
}
?>
//height
<?php
if(!($dfd_containerHeight =="global" || $dfd_containerHeight ==""))
{
?> height: "<?php echo $dfd_containerHeight?>", <?php
}
?>
//background color
<?php
if(!($dfd_bgColor=="global" || $dfd_bgColor ==""))
{
?> backgroundColor: "<?php echo $dfd_bgColor?>", <?php
}
?>
//background image
<?php
if($dfd_bgImage!="")
{
?> backgroundImage: "<?php echo JURI::root() . $dfd_bgImage?>", <?php
}
?>
//flip duration
<?php
if(!($dfd_flipduration == "global" or $dfd_flipduration == ""))
{
?> duration: "<?php echo $dfd_flipduration?>", <?php
}
?>
/*
:<?php /*echo $dfd_flipduration*/?>,*/
//hard pages
<?php
if($dfd_hardpages!="global")
{
?> hard: "<?php echo $dfd_hardpages?>", <?php
}
?>
//pdf page render size
<?php
if($dfd_pdfPagerenderSize!="global")
{
?> pdfRenderSize: "<?php echo $dfd_pdfPagerenderSize?>", <?php
}
?>
//enable sound
<?php
if($dfd_autoEnableSound!="global")
{
?> soundEnable: "<?php echo $dfd_autoEnableSound?>", <?php
}
?>
//enable download
<?php
if($dfd_enableDownload!="global")
{
?> enableDownload: <?php echo $dfd_enableDownload?>, <?php
}
?>
//page mode
<?php
if($dfd_pageMode!="global")
{
?> pageMode: <?php echo $dfd_pageMode?>, <?php
}
?>
//single page mode
<?php
if($dfd_singlePageMode!="global")
{
?> singlePageMode: <?php echo $dfd_singlePageMode?>, <?php
}
?>
//direction
direction: "<?php echo $dfd_direction?>",
//enable autoplay
<?php
if($dfd_enableAutoPlay!="global")
{
?> autoPlay: <?php echo $dfd_enableAutoPlay?>, <?php
}
?>
//autoplay duration
<?php
if(!($dfd_autoPlayDuration=="global" or $dfd_autoPlayDuration == ""))
{
?> autoPlayDuration: <?php echo $dfd_autoPlayDuration?>, <?php
}
?>
//Enable autoplay automatically
<?php
if($dfd_enableAutoPlayAutomatically!="global")
{
?> autoPlayStart: <?php echo $dfd_enableAutoPlayAutomatically?>, <?php
}
?>
//hide controls
<?php
if(!($dfd_hide_controls=="global" || $dfd_hide_controls == ""))
{
?> hideControls: "<?php echo $dfd_hide_controls?>",
<?php
}
?>
//controls position
<?php
if($dfd_controlsPosition!="global")
{
?> controlsPosition: "<?php echo $dfd_controlsPosition?>", <?php
}
?>
//page size
<?php
if($dfd_pageSize!="global")
{
?> pageSize: <?php echo $dfd_pageSize?>, <?php
}
?>
forceFit:<?php echo $dfd_forcePageFit?>,
autoEnableOutline: <?php echo $dfd_autoEnableOutline?>,
autoEnableThumbnail:<?php echo $dfd_autoEnableThumbnail?>,
};
</script>
<?php
#$article->text = substr_replace( $article->text, "<div class='_df_book' id='flip".$id."' source='" . JURI::root() . "images/pdfs/".$dfd_pdf."test.pdf'>" . $row[0]['book_title'] . " </div>", $start, strlen( $match[0] ) );
}
}
$article->text = substr_replace($article->text, "<div class='dearflip-books' >" . implode($replacearry) . "</div>", $start, strlen($matchcat[0]));
}
} else {
if (($start = strpos($article->text, $matchcat[0])) !== false) {
$article->text = substr_replace($article->text, "<div class='dearflip-books' ></div>", $start, strlen($matchcat[0]));
}
}
} else {
if (($start = strpos($article->text, $matchcat[0])) !== false) {
$article->text = substr_replace($article->text, "<div class='dearflip-books' ></div>", $start, strlen($matchcat[0]));
}
}
}
}
//endcategory
return true;
}
//check for http &https
function check_absolute_or_relative_url($pdf_url)
{
if(strncmp($pdf_url, 'http', 4)!==0)
{
$pdf_url= JURI::root() . $pdf_url;
}
return $pdf_url;
}
//start sort images
function sort_by_images_name_asc($sorting_images_files){
natsort($sorting_images_files);
return $sorting_images_files;
}
function sort_by_images_name_desc($sorting_images_files){
natsort($sorting_images_files);
return array_reverse($sorting_images_files);
}
function sort_by_images_newest_first($sorting_images_files){
usort($sorting_images_files, function ($x, $y) {
if(filemtime($x) == filemtime($y))
{
return filemtime($x) == filemtime($y);
}
else {
return filemtime($x) < filemtime($y);
}
});
return $sorting_images_files;
}
function sort_by_images_oldest_first($sorting_images_files){
usort($sorting_images_files, function ($x, $y) {
if(filemtime($x) == filemtime($y))
{
return filemtime($x) == filemtime($y);
}
else {
return filemtime($x) > filemtime($y);
}
});
return $sorting_images_files;
}
//end sort images
}