<?php
defined('_JEXEC') or die('Restricted access');

/**
 *
 * @package  MediaLibrary
 * @copyright 2021 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru); Rob de Cleen(rob@decleen.com);
 * Homepage: https://ordasoft.com
 * @version: 4.6 Free
 * @license GNU General Public license version 2 or later; see LICENSE.txt
 *
 */

if (version_compare(JVERSION, "1.6.0", "lt")){
  class JElementDisplayGame extends JElement{
    var $_name = 'categorylayout';
    function fetchElement($name, $value, &$node, $control_name){
      $component_path = JPath::clean(JPATH_SITE. '/components/com_medialibrary/views/displaygame/tmpl');
      $component_layouts = array();
      $layouts = array();
      if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\.php$',
         false, true))){
        $layout = new stdClass;
        $layout->layout = "";
        $layout->title  = "Use Global";
        $layouts[] = $layout;
        foreach ($component_layouts as $i => $file){
          $select_file_name = pathinfo($file);
          $select_file_name = $select_file_name['filename'];
          $layout = new stdClass;
          $layout->layout = $select_file_name;
          $layout->title = $select_file_name;
          $layouts[] = $layout;
        }
      }
      return JHTML::_('select.genericlist', $layouts, ''.$control_name.'['.$name.']', 'class="inputbox"',
          'layout' , 'title', $value, $control_name.$name);
      
    }
  }
} else if (version_compare(JVERSION, "1.6.0", "ge")){
  class JFormFieldDisplayGame extends JFormField{
    protected $type = 'categorylayout';
    protected function getInput(){
      $component_path = JPath::clean(JPATH_SITE. '/components/com_medialibrary/views/displaygame/tmpl');
      $component_layouts = array();
      $options = array();
      if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\.php$',
         false, true))){
        $options[] = JHtml::_('select.option', '', 'Use Global');
      foreach ($component_layouts as $i => $file){
        $select_file_name = pathinfo($file);
      $select_file_name = $select_file_name['filename'];
      $options[] = JHtml::_('select.option', $select_file_name, $select_file_name);
      }
      }
      
      return  JHtml::_('select.genericlist', $options, $this->name, 'class="inputbox"', 'value', 'text', 
          $this->value, $this->id);
    }
  }
} else {echo "Sanity test. Error version check!"; exit;}
?>
