vendor/con4gis/core/Resources/contao/classes/ResourceLoader.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3.  * con4gis - the gis-kit
  4.  *
  5.  * @version   php 5
  6.  * @package   con4gis
  7.  * @author    con4gis contributors (see "authors.txt")
  8.  * @license   GNU/LGPL http://opensource.org/licenses/lgpl-3.0.html
  9.  * @copyright Küstenschmiede GmbH Software & Design 2011 - 2018
  10.  * @link      https://www.kuestenschmiede.de
  11.  */
  12. namespace con4gis\CoreBundle\Resources\contao\classes;
  13. /**
  14.  * Class ResourceLoader
  15.  * @package c4g\Core
  16.  */
  17. class ResourceLoader
  18. {
  19.     /**
  20.      * Function loadResourcesForModule
  21.      *
  22.      * Loads core-resources needed by the given module
  23.      */
  24.     public static function loadResourcesForModule($module)
  25.     {
  26.         global $objPage;
  27.         $neededResources = array();
  28.         switch ($module) {
  29.             case 'maps':
  30.                 // Maps 3
  31.                 //
  32.                 $neededResources['clipboard'] = true;
  33.                 // check if jQuery needs to be loaded
  34.                 $jQueryLoaded false;
  35.                 $scripts $GLOBALS['TL_JAVASCRIPT'];
  36.                 if (is_array($scripts)) {
  37.                     foreach ($scripts as $strScriptUrl) {
  38.                         if (preg_match('/assets\/jquery\/core\/\d+\.\d+\.\d+\/jquery\.min\.js/i'$strScriptUrl)) {
  39.                             $jQueryLoaded true;
  40.                             break;
  41.                         }
  42.                     }
  43.                 }
  44.                 if ($objPage->hasJQuery)
  45.                 {
  46.                     $jQueryLoaded true;
  47.                 }
  48.                 if ($GLOBALS['CON4GIS']['JQUERY-LOADED'])
  49.                 {
  50.                     $jQueryLoaded true;
  51.                 }
  52.                 $neededResources['jquery'] = !$jQueryLoaded;
  53.                 
  54.                 // Load magnific-popup.js for projects
  55.                 $neededResources['magnific-popup'] = $GLOBALS['con4gis']['projects']['installed'];
  56.                 //ToDo switch for pdf export
  57.                 $neededResources['jspdf'] = false;
  58.                 break;
  59.             default:
  60.                 return false;
  61.         }
  62.         return self::loadResources($neededResources);
  63.     }
  64.     /**
  65.      * Function loadResources
  66.      *
  67.      * Loads the requested resources
  68.      */
  69.     public static function loadResources($resources=array())
  70.     {
  71.         if (!is_array($resources) || empty($resources)) {
  72.             $allByDefault true;
  73.             $resources = array();
  74.         } else {
  75.             $allByDefault false;
  76.         }
  77.         $resources array_merge(array
  78.         (
  79.             'jquery' => $allByDefault,
  80.             'magnific-popup' => $allByDefault,
  81.             'clipboard' => $allByDefault,
  82.             'jspdf' => $allByDefault,
  83.         ),
  84.         $resources);
  85.         if ($resources['jquery']) {
  86.             // load jQuery
  87.             if (version_compareVERSION'3''>=' ) &&
  88.                 is_array$GLOBALS['TL_JAVASCRIPT'] ) &&
  89.                 (array_search'assets/jquery/js/jquery.min.js|static'$GLOBALS['TL_JAVASCRIPT'] ) !== false))
  90.             {
  91.                 // jQuery is already loaded by Contao 3, don't load again!
  92.             }
  93.             else {
  94.                 self::loadJavaScriptRessource('c4g_jquery''assets/jquery/js/jquery.min.js|static'true);
  95.             }
  96.         }
  97.         if ($resources['magnific-popup']) {
  98.             // load magnific-popup
  99.             self::loadJavaScriptRessource('magnific-popup''bundles/con4giscore/vendor/magnific-popup/jquery.magnific-popup.min.js'true);
  100.             self::loadCssRessource('magnific-popup''bundles/con4giscore/vendor/magnific-popup/magnific-popup.css');
  101.         }
  102.         if ($resources['clipboard']) {
  103.             // load clipboard
  104.             self::loadJavaScriptRessource('clipboard''bundles/con4giscore/vendor/clipboard.min.js'true);
  105.         }
  106.         if ($resources['jspdf']) {
  107.             // load clipboard
  108.             self::loadJavaScriptRessource('jspdf''bundles/con4giscore/vendor/jspdf/jspdf.min.js'true);
  109.             //$GLOBALS['TL_JAVASCRIPT']['jspdf.plugin.from_html'] = 'bundles/con4giscore/vendor/jspdf/plugins/from_html.js|static';
  110.         }
  111.         return true;
  112.     }
  113.     public static function loadCssRessource($key$cssFile) {
  114.         $GLOBALS['TL_CSS'][$key] = $cssFile;
  115.     }
  116.     public static function loadJavaScriptRessource($key$jsFile$inHeader false) {
  117.         if ($inHeader) {
  118.             $GLOBALS['TL_JAVASCRIPT'][$key] = $jsFile;
  119.         } else
  120.         {
  121.             $GLOBALS['TL_BODY'][$key] = \Template::generateScriptTag($jsFile) . "\n";
  122.         }
  123.     }
  124. }