shell bypass 403

Cubjrnet7 Shell


name : dearflip.php
<?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, $document)
    {
      
      
		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;



    $dFlipLocation = '"' . JURI::root() . 'plugins/content/dearflip/dflip/' .'"';

   
    $scriptglobal = "
    var dFlipLocation = $dFlipLocation;
    var dFlipWPGlobal = { 
  
";

if ($globalrows[0]['dfx_setting_3d_2d'] != '') {
  $scriptglobal .= "webgl: \"" . $globalrows[0]['dfx_setting_3d_2d'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_enableAutoPlay'] != '') {
  $scriptglobal .= "autoPlay: " . $globalrows[0]['dfx_setting_enableAutoPlay'] . ",\n";
}

if ($globalrows[0]['dfx_setting_autoplayDuration'] != '') {
  $scriptglobal .= "autoPlayDuration: \"" . $globalrows[0]['dfx_setting_autoplayDuration'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_enableAutoPlayAutomatically'] != '') {
  $scriptglobal .= "autoPlayStart: " . $globalrows[0]['dfx_setting_enableAutoPlayAutomatically'] . ",\n";
}

if ($globalrows[0]['dfx_setting_bgColor'] != '') {
  $scriptglobal .= "backgroundColor: \"" . $globalrows[0]['dfx_setting_bgColor'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_bgImage'] != '') {
  $scriptglobal .= "backgroundImage: \"" . JURI::root() . $globalrows[0]['dfx_setting_bgImage'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_containerHeight'] != '') {
  $scriptglobal .= "height: \"" . $globalrows[0]['dfx_setting_containerHeight'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_controlsPosition'] != '') {
  $scriptglobal .= "controlsPosition: \"" . $globalrows[0]['dfx_setting_controlsPosition'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_disablePartialLoading'] != '') {
  $scriptglobal .= "disableRange: " . $globalrows[0]['dfx_setting_disablePartialLoading'] . ",\n";
}

if ($globalrows[0]['dfx_setting_flipduration'] != '') {
  $scriptglobal .= "duration: \"" . $globalrows[0]['dfx_setting_flipduration'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_enableAnalytics'] != '') {
  $scriptglobal .= "enableAnalytics: " . $globalrows[0]['dfx_setting_enableAnalytics'] . ",\n";
}

if ($globalrows[0]['dfx_setting_enableDownload'] != '') {
  $scriptglobal .= "enableDownload: " . $globalrows[0]['dfx_setting_enableDownload'] . ",\n";
}

if ($globalrows[0]['dfx_setting_hardpages'] != '') {
  $scriptglobal .= "hard: \"" . $globalrows[0]['dfx_setting_hardpages'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_hide_controls'] != '') {
  $scriptglobal .= "hideControls: \"" . $globalrows[0]['dfx_settings_hide_controls'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_pdfLinkOpenTarget'] != '') {
  $scriptglobal .= "linkTarget: " . $globalrows[0]['dfx_setting_pdfLinkOpenTarget'] . ",\n";
}

if ($globalrows[0]['dfx_setting_moreControls'] == '') {
  $scriptglobal .= "moreControls: \"download,pageMode,startPage,endPage,sound\",\n";
} else {
  $scriptglobal .= "moreControls: \"" . $globalrows[0]['dfx_setting_moreControls'] . "\",\n";
}

if ($globalrows[0]['dfx_setting_paddingLeft'] != '') {
  $scriptglobal .= "paddingLeft: " . $globalrows[0]['dfx_setting_paddingLeft'] . ",\n";
}

if ($globalrows[0]['dfx_setting_paddingRight'] != '') {
  $scriptglobal .= "paddingRight: " . $globalrows[0]['dfx_setting_paddingRight'] . ",\n";
}

if ($globalrows[0]['dfx_setting_pageMode'] != '') {
  $scriptglobal .= "pageMode: " . $globalrows[0]['dfx_setting_pageMode'] . ",\n";
}

if ($globalrows[0]['dfx_setting_pdfPagerenderSize'] != '') {
  $scriptglobal .= "pdfRenderSize: \"" . $globalrows[0]['dfx_setting_pdfPagerenderSize'] . "\",\n";
}

if ($pdfchunksize_in_bytes != '') {
  $scriptglobal .= "rangeChunkSize: \"" . $pdfchunksize_in_bytes . "\",\n";
}

if ($globalrows[0]['dfx_setting_enableZoomOnScroll'] != '') {
  $scriptglobal .= "scrollWheel: " . $globalrows[0]['dfx_setting_enableZoomOnScroll'] . ",\n";
}

if ($globalrows[0]['dfx_setting_zoomRatio'] != '') {
  $scriptglobal .= "zoomRatio: " . $globalrows[0]['dfx_setting_zoomRatio'] . ",\n";
}

if ($globalrows[0]['dfx_setting_singlePageMode'] != '') {
  $scriptglobal .= "singlePageMode: " . $globalrows[0]['dfx_setting_singlePageMode'] . ",\n";
}

if ($globalrows[0]['dfx_setting_autoEnableSound'] != '') {
  $scriptglobal .= "soundEnable: " . $globalrows[0]['dfx_setting_autoEnableSound'] . ",\n";
}

if ($globalrows[0]['dfx_setting_paperStiffness'] != '') {
  $scriptglobal .= "stiffness: " . $globalrows[0]['dfx_setting_paperStiffness'] . ",\n";
}
//translation

$scriptglobal .= "text:{";
if ($globalrows[0]['dfx_settings_translate_loading_message'] != '') {
  $scriptglobal .= "loading: \"" . $globalrows[0]['dfx_settings_translate_loading_message'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_turn_on_off_sound'] != '') {
  $scriptglobal .= "toggleSound: \"" . $globalrows[0]['dfx_settings_translate_turn_on_off_sound'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_toggle_thumbnails'] != '') {
  $scriptglobal .= "toggleThumbnails: \"" . $globalrows[0]['dfx_settings_translate_toggle_thumbnails'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_toggle_outline_bookmark'] != '') {
  $scriptglobal .= "toggleOutline: \"" . $globalrows[0]['dfx_settings_translate_toggle_outline_bookmark'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_previous_page'] != '') {
  $scriptglobal .= "previousPage: \"" . $globalrows[0]['dfx_settings_translate_previous_page'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_next_page'] != '') {
  $scriptglobal .= "nextPage: \"" . $globalrows[0]['dfx_settings_translate_next_page'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_toggle_fullscreen'] != '') {
  $scriptglobal .= "toggleFullscreen: \"" . $globalrows[0]['dfx_settings_translate_toggle_fullscreen'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_zoom_in'] != '') {
  $scriptglobal .= "zoomIn: \"" . $globalrows[0]['dfx_settings_translate_zoom_in'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_zoom_out'] != '') {
  $scriptglobal .= "zoomOut: \"" . $globalrows[0]['dfx_settings_translate_zoom_out'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_toggle_help'] != '') {
  $scriptglobal .= "toggleHelp: \"" . $globalrows[0]['dfx_settings_translate_toggle_help'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_single_page_mode'] != '') {
  $scriptglobal .= "singlePageMode: \"" . $globalrows[0]['dfx_settings_translate_single_page_mode'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_double_page_mode'] != '') {
  $scriptglobal .= "doublePageMode: \"" . $globalrows[0]['dfx_settings_translate_double_page_mode'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_download_pdf_file'] != '') {
  $scriptglobal .= "downloadPDFFile: \"" . $globalrows[0]['dfx_settings_translate_download_pdf_file'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_goto_first_page'] != '') {
  $scriptglobal .= "gotoFirstPage: \"" . $globalrows[0]['dfx_settings_translate_goto_first_page'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_goto_last_page'] != '') {
  $scriptglobal .= "gotoLastPage: \"" . $globalrows[0]['dfx_settings_translate_goto_last_page'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_play'] != '') {
  $scriptglobal .= "play: \"" . $globalrows[0]['dfx_settings_translate_play'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_pause'] != '') {
  $scriptglobal .= "pause: \"" . $globalrows[0]['dfx_settings_translate_pause'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_share'] != '') {
  $scriptglobal .= "share: \"" . $globalrows[0]['dfx_settings_translate_share'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_share_mail_subject'] != '') {
  $scriptglobal .= "mailSubject: \"" . $globalrows[0]['dfx_settings_translate_share_mail_subject'] . "\",\n";
}

if ($globalrows[0]['dfx_settings_translate_share_mail_message'] != '') {
  $scriptglobal .= "mailBody: \"" . $globalrows[0]['dfx_settings_translate_share_mail_message'] . "\",\n";
}


$scriptglobal .="}}";
//start global script
$document->addScriptDeclaration( $scriptglobal);
        



       // var_dump($dfnp_wegl);
        ?>

      

        <?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',
            'ordering'))
            ->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= 0)
    {
      $app = JFactory::getApplication();
      if ($app->isClient('api')) {
          return;
      }

		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.3.58");

        //$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.3.66");




        $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, $document);



            //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";*/


                            }
                        }

                        //adding script in head

                        $script = "
                        var $dflip_id ={
                        source: $flipbook_source1,\n";
                        //webgl
                        if($dfd_3d_2d!='global') {
                        $script .= "webgl: $dfd_3d_2d,\n";
                             
                            
                        }
                        if ($dfd_containerHeight != 'global' && $dfd_containerHeight != '') {
                          $script .= "height: \"$dfd_containerHeight\",\n";
                      }
                      
                      if ($dfd_bgColor != 'global' && $dfd_bgColor != '') {
                          $script .= "backgroundColor: \"$dfd_bgColor\",\n";
                      }
                      
                      if ($dfd_bgImage != '') {
                          $script .= "backgroundImage: \"" . JURI::root() . "$dfd_bgImage\",\n";
                      }
                      
                      if ($dfd_flipduration != 'global' && $dfd_flipduration != '') {
                          $script .= "duration: \"$dfd_flipduration\",\n";
                      }
                      
                      if ($dfd_hardpages != 'global') {
                          $script .= "hard: \"$dfd_hardpages\",\n";
                      }
                      
                      if ($dfd_pdfPagerenderSize != 'global') {
                          $script .= "pdfRenderSize: \"$dfd_pdfPagerenderSize\",\n";
                      }
                      
                      if ($dfd_autoEnableSound != 'global') {
                          $script .= "soundEnable: $dfd_autoEnableSound,\n";
                      }
                      
                      if ($dfd_enableDownload != 'global') {
                          $script .= "enableDownload: $dfd_enableDownload,\n";
                      }
                      
                      if ($dfd_pageMode != 'global') {
                          $script .= "pageMode: $dfd_pageMode,\n";
                      }
                      
                      if ($dfd_singlePageMode != 'global') {
                          $script .= "singlePageMode: $dfd_singlePageMode,\n";
                      }
                      
                      $script .= "direction: \"$dfd_direction\",\n";
                      
                      if ($dfd_enableAutoPlay != 'global') {
                          $script .= "autoPlay: $dfd_enableAutoPlay,\n";
                      }
                      
                      if ($dfd_autoPlayDuration != 'global' && $dfd_autoPlayDuration != '') {
                          $script .= "autoPlayDuration: $dfd_autoPlayDuration,\n";
                      }
                      
                      if ($dfd_enableAutoPlayAutomatically != 'global') {
                          $script .= "autoPlayStart: $dfd_enableAutoPlayAutomatically,\n";
                      }
                      
                      if ($dfd_hide_controls != 'global' && $dfd_hide_controls != '') {
                          $script .= "hideControls: \"$dfd_hide_controls\",\n";
                      }
                      
                      if ($dfd_controlsPosition != 'global') {
                          $script .= "controlsPosition: \"$dfd_controlsPosition\",\n";
                      }
                      
                      if ($dfd_pageSize != 'global') {
                          $script .= "pageSize: $dfd_pageSize,\n";
                      }
                      
                      $script .= "forceFit: $dfd_forcePageFit,\n";
                      $script .= "autoEnableOutline: $dfd_autoEnableOutline,\n";
                      $script .= "autoEnableThumbnail: $dfd_autoEnableThumbnail";
                      
                        $script .= "}";
                        
                     
                    //start global script
                    $document->addScriptDeclaration( $script, "text/javascript");


                        ?>


                  

                        <?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, $document);


            //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_sort_books_in_cat_by','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_sort_books_in_cat_by = $catss[0]['dfx_sort_books_in_cat_by'];

                    $dfx_cat_button_text_type= $catss[0]['dfx_cat_button_text_type'];



                    $catrows= self::dfCallDataBase($catid, 'df_cat');

                    if (count($catrows) !== 0) {
                        $replacearry = [];
                        //sorting in categories
                       // var_dump($catrows);

              
                        switch($dfx_sort_books_in_cat_by){
                          case "1":
                            $sorted_cat_rows=$this->sort_by_book_ID_desc($catrows);
                            break;
                          case "2":
                            $sorted_cat_rows=$this->sort_by_book_ID_asc($catrows);
                            break;
                          case "3":
                            $sorted_cat_rows=$this->sort_by_book_title_asc($catrows);
                            break;
                          case "4":
                            $sorted_cat_rows=$this->sort_by_book_title_desc($catrows);
                            break;
                          case "5":
                            $sorted_cat_rows=$this->sort_by_book_ordering_asc($catrows);
                            break;
                            case "6":
                              $sorted_cat_rows=$this->sort_by_book_ordering_desc($catrows);
                              break;    
                          default:
                            $sorted_cat_rows= $catrows;

                        }

                       // var_dump($sorted_cat_rows);

                        //


                        if (($start = strpos($article->text, $matchcat[0])) !== false) {
                            foreach ($sorted_cat_rows 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 . "']";

                                        }

                                    }


                                    //try adding script in head
                                    $scriptcat = "
                                      var $dflip_id ={
                                      source: $flipbook_source,\n";
                                      
                                      //webgl
                                    if ($dfd_3d_2d != 'global') {
                                      $scriptcat .= "webgl: \"$dfd_3d_2d\",\n";
                                  }
                                  
                                  if ($dfd_containerHeight != 'global' && $dfd_containerHeight != '') {
                                    $scriptcat .= "height: \"$dfd_containerHeight\",\n";
                                  }
                                  
                                  if ($dfd_bgColor != 'global' && $dfd_bgColor != '') {
                                    $scriptcat .= "backgroundColor: \"$dfd_bgColor\",\n";
                                  }
                                  
                                  if ($dfd_bgImage != '') {
                                    $scriptcat .= "backgroundImage: \"" . JURI::root() . "$dfd_bgImage\",\n";
                                  }
                                  
                                  if ($dfd_flipduration != 'global' && $dfd_flipduration != '') {
                                      $scriptcat .= "duration: \"$dfd_flipduration\",\n";
                                  }
                                  
                                  if ($dfd_hardpages != 'global') {
                                      $scriptcat .= "hard: \"$dfd_hardpages\",\n";
                                  }
                                  
                                  if ($dfd_pdfPagerenderSize != 'global') {
                                      $scriptcat .= "pdfRenderSize: \"$dfd_pdfPagerenderSize\",\n";
                                  }
                                  
                                  if ($dfd_autoEnableSound != 'global') {
                                      $scriptcat .= "soundEnable: \"$dfd_autoEnableSound\",\n";
                                  }
                                  
                                  if ($dfd_enableDownload != 'global') {
                                      $scriptcat .= "enableDownload: $dfd_enableDownload,\n";
                                  }
                                  
                                  if ($dfd_pageMode != 'global') {
                                      $scriptcat .= "pageMode: $dfd_pageMode,\n";
                                  }
                                  
                                  if ($dfd_singlePageMode != 'global') {
                                      $scriptcat .= "singlePageMode: $dfd_singlePageMode,\n";
                                  }
                                  
                                  $scriptcat .= "direction: \"$dfd_direction\",\n";
                                  
                                  if ($dfd_enableAutoPlay != 'global') {
                                      $scriptcat .= "autoPlay: $dfd_enableAutoPlay,\n";
                                  }
                                  
                                  if ($dfd_autoPlayDuration != 'global' && $dfd_autoPlayDuration != '') {
                                      $scriptcat .= "autoPlayDuration: $dfd_autoPlayDuration,\n";
                                  }
                                  
                                  if ($dfd_enableAutoPlayAutomatically != 'global') {
                                      $scriptcat .= "autoPlayStart: $dfd_enableAutoPlayAutomatically,\n";
                                  }
                                  
                                  if ($dfd_hide_controls != 'global' && $dfd_hide_controls != '') {
                                      $scriptcat .= "hideControls: \"$dfd_hide_controls\",\n";
                                  }
                                  
                                  if ($dfd_controlsPosition != 'global') {
                                      $scriptcat .= "controlsPosition: \"$dfd_controlsPosition\",\n";
                                  }
                                  
                                  if ($dfd_pageSize != 'global') {
                                      $scriptcat .= "pageSize: $dfd_pageSize,\n";
                                  }
                                  
                                  $scriptcat .= "forceFit: $dfd_forcePageFit,\n";
                                  
                                  $scriptcat .= "autoEnableOutline: $dfd_autoEnableOutline,\n";
                                  
                                  $scriptcat .= "autoEnableThumbnail: $dfd_autoEnableThumbnail,\n";
                                  

                                  $scriptcat .= "}";
                        
                     
                    //start cat script
                    $document->addScriptDeclaration( $scriptcat, "text/javascript");

                                    ?>

                                 


                                    <?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
    //start sorting in category
    function sort_by_book_ID_desc($catrows){
      array_multisort(array_column($catrows, 'id'), SORT_DESC, $catrows);

      return $catrows;

    }

    function sort_by_book_ID_asc($catrows){
      array_multisort(array_column($catrows, 'id'), SORT_ASC, $catrows);
      return $catrows;
    }

    function sort_by_book_title_asc($catrows){
      array_multisort(array_column($catrows, 'book_title'), SORT_ASC, SORT_NATURAL|SORT_FLAG_CASE, $catrows);
      

      return $catrows;
    }

    function sort_by_book_title_desc($catrows){
      array_multisort(array_column($catrows, 'book_title'), SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $catrows);

      return $catrows;
    }

    function sort_by_book_ordering_asc($catrows){
      array_multisort(array_column($catrows, 'ordering'), SORT_ASC, $catrows);

      return $catrows;
    }
    function sort_by_book_ordering_desc($catrows){
      array_multisort(array_column($catrows, 'ordering'), SORT_DESC, $catrows);

      return $catrows;
    }
    //end sorting in category



}


© 2025 Cubjrnet7