Exemple #1
0
 /**
  * Initializes the component
  */
 public function init()
 {
     // Connect to the current backend
     $this->_backend = Yii::app()->backendManager->getCurrent();
     $hostname = Backend::normalizeAddress($this->_backend->hostname);
     $endpoint = 'http://' . $hostname . ':' . $this->_backend->port . '/jsonrpc';
     $clientFlags = JsonRPCClient::FLAG_ATTEMPT_UTF8_RECOVERY;
     $clientOptions = array('timeout' => Setting::getInteger('requestTimeout'));
     $this->_client = new JsonRPCClient($endpoint, $this->_backend->username, $this->_backend->password, $clientFlags, $clientOptions);
     // Initialize the VFS helper
     $this->_vfsHelper = new VFSHelper();
     parent::init();
 }
 /**
  * Class constructor
  * @param Media[] $rawData the data
  * @param array $config the component configuration (optional)
  */
 public function __construct($rawData, $config = array())
 {
     // Optionally apply pagination, unless it has been explicitly disabled
     $pagesize = Setting::getInteger('pagesize');
     if (!isset($config['pagination'])) {
         $config['pagination'] = $pagesize ? array('pageSize' => $pagesize) : false;
     }
     // Determine the key field from the first item
     if (isset($rawData[0])) {
         $config['keyField'] = $rawData[0]->getIdField();
     }
     parent::__construct($rawData, $config);
 }
 /**
  * Initializes the controller. The application name and language is set here.
  */
 public function init()
 {
     // Use the defined request timeout as execution time limit
     $requestTimeout = Setting::getInteger('requestTimeout');
     set_time_limit($requestTimeout);
     // Fallback to XBMC Video Server if the user has removed the
     // application name
     $name = Setting::getString('applicationName');
     if (!$name) {
         $name = 'XBMC Video Server';
     }
     Yii::app()->name = $name;
     Yii::app()->language = Yii::app()->languageManager->getCurrent();
     parent::init();
 }
 /**
  * Generates and stores a cached copy of this thumbnail. It first retrieves 
  * the original image to a temporary location for processing. This is done 
  * because Kodi doesn't like the HTTP/1.0 requests that the built-in PHP 
  * image manipulation functions (as well as file_get_contents()) use.
  */
 public function generate()
 {
     // Create a HTTP/1.1 stream context
     $context = stream_context_create(array('http' => array('timeout' => Setting::getInteger('requestTimeout'), 'protocol_version' => 1.1, 'header' => 'Connection: close')));
     // Retrieve the image data and store it in a temporary file
     $imageData = file_get_contents($this->getOriginalUrl(), false, $context);
     $imageFile = tempnam(sys_get_temp_dir(), self::TEMP_FILE_PREFIX);
     if ($imageData === false || file_put_contents($imageFile, $imageData) === false) {
         return;
     }
     // Resize and cache the thumbnail
     $imagine = $this->imagineFactory();
     $imagine->open($imageFile)->thumbnail(new \Imagine\Image\Box($this->_size, PHP_INT_MAX))->save($this->_cache->getCachePath() . DIRECTORY_SEPARATOR . $this->getFilename(), array('jpeg_quality' => 70));
     // Delete the temporary file
     unlink($imageFile);
 }