/**
  * Set up test environment.
  */
 public function setUp()
 {
     parent::setUp();
     $this->filesystem = new FileSystem(new LocalAdapter($this->build_path));
     $this->filesystem->emptyDir('/', ['BlogStructure.php']);
     $this->assertEquals(['BlogStructure.php'], $this->filesystem->files('/'));
     $this->assertEquals([], $this->filesystem->subdirs('/'));
     $this->blog_structure = new BlogStructure();
     $this->blog_structure->build($this->build_path, $this->connection);
 }
예제 #2
0
 public function manageConfigs()
 {
     $fileSystem = new Filesystem();
     $files = $fileSystem->files(__DIR__ . '/config');
     if (!empty($files)) {
         foreach ($files as $file) {
             $name = explode('/', $file);
             $this->mergeConfigFrom($file, str_replace('.php', '', $name[count($name) - 1]));
         }
     }
 }
예제 #3
0
 /**
  * Method for refreshing the cache in the database with the known language strings
  *
  * @return	boolean	True on success, Exception object otherwise
  *
  * @since		2.5
  */
 public function refresh()
 {
     require_once JPATH_COMPONENT . '/helpers/languages.php';
     $app = JFactory::getApplication();
     $app->setUserState('com_languages.overrides.cachedtime', null);
     // Empty the database cache first
     try {
         $this->_db->setQuery('TRUNCATE TABLE ' . $this->_db->qn('#__overrider'));
         $this->_db->query();
     } catch (RuntimeException $e) {
         return $e;
     }
     // Create the insert query
     $query = $this->_db->getQuery(true)->insert($this->_db->qn('#__overrider'))->columns('constant, string, file');
     // Initialize some variables
     $client = $app->getUserState('com_languages.overrides.filter.client', 'site') ? 'administrator' : 'site';
     $language = $app->getUserState('com_languages.overrides.filter.language', 'en-GB');
     $base = constant('JPATH_' . strtoupper($client));
     $path = $base . '/language/' . $language;
     $files = array();
     // Parse common language directory
     if (Filesystem::exists($path)) {
         $files = Filesystem::files($path, $language . '.*ini$', false, true);
     }
     // Parse language directories of components
     $files = array_merge($files, Filesystem::files($base . '/components', $language . '.*ini$', 3, true));
     // Parse language directories of modules
     $files = array_merge($files, Filesystem::files($base . '/modules', $language . '.*ini$', 3, true));
     // Parse language directories of templates
     $files = array_merge($files, Filesystem::files($base . '/templates', $language . '.*ini$', 3, true));
     // Parse language directories of plugins
     $files = array_merge($files, Filesystem::files(JPATH_PLUGINS, $language . '.*ini$', 3, true));
     // Parse all found ini files and add the strings to the database cache
     foreach ($files as $file) {
         $strings = LanguagesHelper::parseFile($file);
         if ($strings && count($strings)) {
             $query->clear('values');
             foreach ($strings as $key => $string) {
                 $query->values($this->_db->q($key) . ',' . $this->_db->q($string) . ',' . $this->_db->q(JPath::clean($file)));
             }
             try {
                 $this->_db->setQuery($query);
                 if (!$this->_db->query()) {
                     return new Exception($this->_db->getErrorMsg());
                 }
             } catch (RuntimeException $e) {
                 return $e;
             }
         }
     }
     // Update the cached time
     $app->setUserState('com_languages.overrides.cachedtime.' . $client . '.' . $language, time());
     return true;
 }
예제 #4
0
 /**
  * Outputs a <select> element with a specific value chosen
  *
  * @param   mixed   $val   Chosen value
  * @param   string  $name  Field name
  * @param   string  $id    ID
  * @param   string  $atts  Attributes
  * @return  string  HTML <select>
  */
 public static function scopes($val, $name, $id = null, $atts = null)
 {
     $adapters = \Filesystem::files(dirname(dirname(__DIR__)) . '/models/adapters', '\\.php$');
     $out = '<select name="' . $name . '" id="' . ($id ? $id : str_replace(array('[', ']'), '', $name)) . '"' . ($atts ? ' ' . $atts : '') . '>';
     $out .= '<option value="">' . \Lang::txt('COM_BLOG_SELECT_SCOPE') . '</option>';
     foreach ($adapters as $adapter) {
         $adapter = ltrim($adapter, DS);
         $adapter = preg_replace('#\\.[^.]*$#', '', $adapter);
         if ($adapter == 'base') {
             continue;
         }
         $selected = $adapter == $val ? ' selected="selected"' : '';
         $out .= '<option value="' . $adapter . '"' . $selected . '>' . $adapter . '</option>';
     }
     $out .= '</select>';
     return $out;
 }
예제 #5
0
" method="post" id="filelist">
		<?php 
if (count($this->folders) == 0 && count($this->docs) == 0) {
    ?>
			<p><?php 
    echo Lang::txt('COM_GROUPS_NO_FILES_FOUND');
    ?>
</p>
		<?php 
} else {
    ?>
			<table>
				<tbody>
				<?php 
    foreach ($this->folders as $k => $folder) {
        $num_files = count(Filesystem::files($k));
        $k = substr($k, strlen($this->path));
        ?>
					<tr>
						<td width="100%">
							<a class="icon-folder folder" href="<?php 
        echo Route::url('index.php?option=' . $this->option . '&controller=' . $this->controller . '&dir=' . urlencode($k) . '&gidNumber=' . $this->group->get('gidNumber') . '&tmpl=component&' . Session::getFormToken() . '=1');
        ?>
" target="media">
								<?php 
        echo trim($k, DS);
        ?>
							</a>
						</td>
						<td>
							<a class="icon-delete delete" href="<?php 
예제 #6
0
		<?php 
if (count($this->folders) == 0 && count($this->docs) == 0) {
    ?>
			<p><?php 
    echo Lang::txt('COM_BLOG_NO_FILES_FOUND');
    ?>
</p>
		<?php 
} else {
    ?>
			<table>
				<tbody>
				<?php 
    $base = rtrim(Request::base(true), '/');
    foreach ($this->folders as $k => $folder) {
        $num_files = count(Filesystem::files(PATH_APP . DS . $folder));
        ?>
					<tr>
						<td width="100%">
							<span class="icon-folder folder">
								<?php 
        echo $k;
        ?>
							</span>
						</td>
						<td>
							<a class="icon-delete delete" href="<?php 
        echo Route::url('index.php?option=' . $this->option . '&controller=' . $this->controller . '&task=deletefolder&folder=' . basename($folder) . '&scope=' . urlencode($this->archive->get('scope')) . '&id=' . $this->archive->get('scope_id') . '&tmpl=component&' . Session::getFormToken() . '=1');
        ?>
" target="filer" onclick="return deleteFolder('<?php 
        echo basename($folder);
예제 #7
0
 /**
  * Draw list
  *
  * @return  boolean
  */
 public function drawPackageList($attachments, $element, $elementId, $pub, $blockParams, $authorized)
 {
     // Get configs
     $configs = $this->getConfigs($element->params, $elementId, $pub, $blockParams);
     $list = NULL;
     if (!$attachments) {
         return false;
     }
     $list .= '<li>' . \Components\Projects\Models\File::drawIcon('csv') . ' data.csv</li>';
     // Add data files
     $dataFiles = array();
     if (is_dir($configs->dataPath)) {
         $dataFiles = Filesystem::files($configs->dataPath, '.', true, true);
     }
     if (!empty($dataFiles)) {
         $list .= '<li>' . \Components\Projects\Models\File::drawIcon('folder') . ' data</li>';
         foreach ($dataFiles as $e) {
             // Skip thumbnails and CSV
             if (preg_match("/_tn.gif/", $e) || preg_match("/_medium.gif/", $e) || preg_match("/data.csv/", $e)) {
                 continue;
             }
             $file = new \Components\Projects\Models\File($e);
             $fileinfo = pathinfo($e);
             $a_dir = $fileinfo['dirname'];
             $a_dir = trim(str_replace($configs->dataPath, '', $a_dir), DS);
             $fPath = $a_dir && $a_dir != '.' ? $a_dir . DS : '';
             $where = 'data' . DS . $fPath . basename($e);
             $list .= '<li class="level2"><span class="item-title">' . $file::drawIcon($file->get('ext')) . ' ' . trim($where, DS) . '</span></li>';
         }
     }
     return $list;
 }
예제 #8
0
 /**
  * Generate detailed responses CSV files and zip and offer up as download
  *
  * @return void
  **/
 private function downloadresponses()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'formReport.php';
     // Only allow for instructors
     if (!$this->course->offering()->section()->access('manage')) {
         App::abort(403, 'Sorry, you don\'t have permission to do this');
     }
     if (!($asset_ids = Request::getVar('assets', false))) {
         App::abort(422, 'Sorry, we don\'t know what results you\'re trying to retrieve');
     }
     $protected = 'site' . DS . 'protected';
     $tmp = $protected . DS . 'tmp';
     // We're going to temporarily house this in PATH_APP/site/protected/tmp
     if (!Filesystem::exists($protected)) {
         App::abort(500, 'Missing temporary directory');
     }
     // Make sure tmp folder exists
     if (!Filesystem::exists($tmp)) {
         Filesystem::makeDirectory($tmp);
     } else {
         // Folder was already there - do a sanity check and make sure no old responses zips are lying around
         $files = Filesystem::files($tmp);
         if ($files && count($files) > 0) {
             foreach ($files as $file) {
                 if (strstr($file, 'responses.zip') !== false) {
                     Filesystem::delete($tmp . DS . $file);
                 }
             }
         }
     }
     // Get the individual asset ids
     $asset_ids = explode('-', $asset_ids);
     // Set up our zip archive
     $zip = new ZipArchive();
     $path = PATH_APP . DS . $tmp . DS . time() . '.responses.zip';
     $zip->open($path, ZipArchive::CREATE);
     // Loop through the assets
     foreach ($asset_ids as $asset_id) {
         // Is it a number?
         if (!is_numeric($asset_id)) {
             continue;
         }
         // Get the rest of the asset row
         $asset = new \Components\Courses\Tables\Asset($this->db);
         $asset->load($asset_id);
         // Make sure asset is a part of this course
         if ($asset->get('course_id') != $this->course->get('id')) {
             continue;
         }
         if ($details = \Components\Courses\Models\FormReport::getLetterResponsesForAssetId($this->db, $asset_id, true, $this->course->offering()->section()->get('id'))) {
             $output = implode(',', $details['headers']) . "\n";
             if (isset($details['responses']) && count($details['responses']) > 0) {
                 foreach ($details['responses'] as $response) {
                     $output .= implode(',', $response) . "\n";
                 }
             }
             $zip->addFromString($asset_id . '.responses.csv', $output);
         } else {
             continue;
         }
     }
     // Close the zip archive handler
     $zip->close();
     if (is_file($path)) {
         // Set up the server
         $xserver = new \Hubzero\Content\Server();
         $xserver->filename($path);
         $xserver->saveas('responses.zip');
         $xserver->disposition('attachment');
         $xserver->acceptranges(false);
         // Serve the file
         $xserver->serve();
         // Now delete the file
         Filesystem::delete($path);
     }
     // All done!
     exit;
 }
예제 #9
0
 /**
  * Get array of help pages for component
  *
  * @param   string  $component  Component to get pages for
  * @return  array
  */
 public static function pages($component)
 {
     $database = \App::get('db');
     // Get component name from database
     $database->setQuery("SELECT `name`\n\t\t\tFROM `#__extensions`\n\t\t\tWHERE `type`=" . $database->quote('component') . "\n\t\t\tAND `element`=" . $database->quote($component) . "\n\t\t\tAND `enabled`=1");
     $name = $database->loadResult();
     // Make sure we have a component
     if ($name == '') {
         $name = str_replace('com_', '', $component);
         return array('name' => ucfirst($name), 'option' => $component, 'pages' => array());
     }
     // Path to help pages
     $helpPagesPath = self::path($component) . DS . 'help' . DS . \Lang::getTag();
     // Make sure directory exists
     $pages = array();
     if (is_dir($helpPagesPath)) {
         // Get help pages for this component
         $pages = \Filesystem::files($helpPagesPath, '.' . self::$ext);
     }
     $pages = array_map(function ($file) {
         return ltrim($file, DS);
     }, $pages);
     // Return pages
     return array('name' => $name, 'option' => $component, 'pages' => $pages);
 }
예제 #10
0
 /**
  * Edit an Import
  *
  * @return  void
  */
 public function editTask()
 {
     Request::setVar('hidemainmenu', 1);
     // get request vars
     $ids = Request::getVar('id', array());
     $id = isset($ids[0]) ? $ids[0] : null;
     // get the import object
     $this->view->import = new Models\Import($id);
     // import params
     $this->view->params = new \Hubzero\Config\Registry($this->view->import->get('params'));
     // get all files in import filespace
     $this->view->files = \Filesystem::files($this->view->import->fileSpacePath(), '.');
     // get all imports from archive
     $hooksArchive = Models\Import\Hook\Archive::getInstance();
     $this->view->hooks = $hooksArchive->hooks('list', array('state' => array(1)));
     // Get groups
     $this->view->groups = Group::find(array('authorized' => 'admin', 'fields' => array('cn', 'description', 'published', 'gidNumber', 'type'), 'type' => array(1, 3), 'sortby' => 'description'));
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }
예제 #11
0
 /**
  * Method to get the toc
  * @return array Table of contents
  */
 function &getToc()
 {
     if (is_null($this->toc)) {
         // Get vars
         $lang_tag = $this->getLangTag();
         $help_search = $this->getHelpSearch();
         // Get Help files
         $files = Filesystem::files(JPATH_BASE . '/help/' . $lang_tag, '\\.xml$|\\.html$');
         $this->toc = array();
         foreach ($files as $file) {
             $buffer = file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/' . $file);
             if (preg_match('#<title>(.*?)</title>#', $buffer, $m)) {
                 $title = trim($m[1]);
                 if ($title) {
                     // Translate the page title
                     $title = Lang::txt($title);
                     // strip the extension
                     $file = preg_replace('#\\.xml$|\\.html$#', '', $file);
                     if ($help_search) {
                         if (JString::strpos(JString::strtolower(strip_tags($buffer)), JString::strtolower($help_search)) !== false) {
                             // Add an item in the Table of Contents
                             $this->toc[$file] = $title;
                         }
                     } else {
                         // Add an item in the Table of Contents
                         $this->toc[$file] = $title;
                     }
                 }
             }
         }
         // Sort the Table of Contents
         asort($this->toc);
     }
     return $this->toc;
 }
예제 #12
0
 /**
  * Get array of help pages for component
  *
  * @param   string  $component  Component to get pages for
  * @return  array
  */
 private function helpPagesForComponent($component)
 {
     // Get component name from database
     $sql = "SELECT `name` FROM `#__extensions` WHERE `type`=" . $this->database->quote('component') . " AND `element`=" . $this->database->quote($component) . " AND `enabled`=1";
     $this->database->setQuery($sql);
     $name = $this->database->loadResult();
     // Make sure we have a component
     if ($name == '') {
         return array();
     }
     // Path to help pages
     $path = \Component::path($component) . DS . 'admin' . DS . 'help' . DS . Lang::getTag();
     // Make sure directory exists
     $pages = array();
     // Get help pages for this component
     $pages = \Filesystem::files($path, '.phtml');
     $pages = array_map(function ($file) {
         return ltrim($file, DS);
     }, $pages);
     // Return pages
     return array('name' => $name, 'option' => $component, 'pages' => $pages);
 }
예제 #13
0
 /**
  * Deletes paths from the current path
  *
  * @since 1.5
  */
 public function delete()
 {
     Session::checkToken(['get', 'post']);
     // Get some data from the request
     $tmpl = Request::getCmd('tmpl');
     $paths = Request::getVar('rm', array(), '', 'array');
     $folder = Request::getVar('folder', '', '', 'path');
     $redirect = 'index.php?option=com_media&folder=' . $folder;
     if ($tmpl == 'component') {
         // We are inside the iframe
         $redirect .= '&view=mediaList&tmpl=component';
     }
     $this->setRedirect($redirect);
     // Nothing to delete
     if (empty($paths)) {
         return true;
     }
     // Authorize the user
     if (!$this->authoriseUser('delete')) {
         return false;
     }
     // Set FTP credentials, if given
     JClientHelper::setCredentialsFromRequest('ftp');
     // Initialise variables.
     $ret = true;
     foreach ($paths as $path) {
         if ($path !== Filesystem::clean($path)) {
             // filename is not safe
             $filename = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
             Notify::warning(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', substr($filename, strlen(COM_MEDIA_BASE))));
             continue;
         }
         $fullPath = Filesystem::cleanPath(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path)));
         $object_file = new \Hubzero\Base\Object(array('filepath' => $fullPath));
         if (is_file($fullPath)) {
             // Trigger the onContentBeforeDelete event.
             $result = Event::trigger('content.onContentBeforeDelete', array('com_media.file', &$object_file));
             if (in_array(false, $result, true)) {
                 // There are some errors in the plugins
                 Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
                 continue;
             }
             $ret &= Filesystem::delete($fullPath);
             // Trigger the onContentAfterDelete event.
             Event::trigger('content.onContentAfterDelete', array('com_media.file', &$object_file));
             $this->setMessage(Lang::txt('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE))));
         } elseif (is_dir($fullPath)) {
             $contents = Filesystem::files($fullPath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'));
             if (empty($contents)) {
                 // Trigger the onContentBeforeDelete event.
                 $result = Event::trigger('content.onContentBeforeDelete', array('com_media.folder', &$object_file));
                 if (in_array(false, $result, true)) {
                     // There are some errors in the plugins
                     Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
                     continue;
                 }
                 $ret &= Filesystem::deleteDirectory($fullPath);
                 // Trigger the onContentAfterDelete event.
                 Event::trigger('content.onContentAfterDelete', array('com_media.folder', &$object_file));
                 $this->setMessage(Lang::txt('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE))));
             } else {
                 // This makes no sense...
                 Notify::warning(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', substr($fullPath, strlen(COM_MEDIA_BASE))));
             }
         }
     }
     return $ret;
 }
예제 #14
0
</span>
										<?php 
            }
            ?>
									</span>
									<?php 
        }
    }
}
?>
					</caption>
					<tbody>
					<?php 
foreach ($this->folders as $fullpath => $name) {
    $dir = DS . $name;
    $numFiles = count(\Filesystem::files($fullpath, '.', false, true, array()));
    if ($this->listdir == DS) {
        $this->listdir = '';
    }
    $d = $this->listdir ? $this->listdir . DS . $name : DS . $name;
    ?>
						<tr>
							<td width="100%">
								<a class="icon-folder" href="<?php 
    echo Route::url('index.php?option=' . $this->option . '&controller=' . $this->controller . '&task=filelist&tmpl=component&listdir=' . urlencode($d));
    ?>
">
									<?php 
    echo $dir;
    ?>
								</a>
예제 #15
0
 /**
  * Prep file directory (provisioned project)
  *
  * @param      boolean		$force
  *
  * @return     boolean
  */
 protected function _prepDir($force = true)
 {
     if (!$this->model->exists()) {
         $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH'));
         return;
     }
     // Get member files path
     $memberPath = $this->_getMemberPath();
     // Create and initialize local repo
     if (!$this->model->repo()->iniLocal()) {
         $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH'));
         return;
     }
     // Copy files from member directory
     if (!Filesystem::copyDirectory($memberPath, $this->model->repo()->get('path'))) {
         $this->setError(Lang::txt('COM_PROJECTS_FAILED_TO_COPY_FILES'));
         return false;
     }
     // Read copied files
     $get = Filesystem::files($this->model->repo()->get('path'));
     $num = count($get);
     $checkedin = 0;
     // Check-in copied files
     if ($get) {
         foreach ($get as $file) {
             $file = str_replace($this->model->repo()->get('path') . DS, '', $file);
             if (is_file($this->model->repo()->get('path') . DS . $file)) {
                 // Checkin into repo
                 $this->model->repo()->call('checkin', array('file' => $this->model->repo()->getMetadata($file, 'file', array())));
                 $checkedin++;
             }
         }
     }
     if ($num == $checkedin) {
         // Clean up member files
         Filesystem::deleteDirectory($memberPath);
         return true;
     }
     return false;
 }
예제 #16
0
 /**
  * Transfer files from one version to another
  *
  * @param      string  $sourceid Source version ID
  * @param      string  $destid   Destination version ID
  * @param      integer $rid      Resource ID
  * @return     boolean False if errors, True on success
  */
 public function transfer($sourceid, $destid, $rid)
 {
     Log::debug(__FUNCTION__ . '()');
     // Get resource information
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($rid);
     // Get screenshot information
     $ss = new \Components\Resources\Tables\Screenshot($this->database);
     $shots = $ss->getFiles($rid, $sourceid);
     // Build the path
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $listdir = \Components\Resources\Helpers\Html::build_path($resource->created, $rid, '');
     $srcdir = $listdir . DS . $sourceid;
     $destdir = $listdir . DS . $destid;
     $src = $this->_buildUploadPath($srcdir, '');
     $dest = $this->_buildUploadPath($destdir, '');
     // Make sure the path exist
     if (!is_dir($src)) {
         if (!Filesystem::makeDirectory($src)) {
             $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_CREATE_UPLOAD_PATH'));
             return false;
         }
     }
     Log::debug(__FUNCTION__ . "() {$src}");
     // do we have files to transfer?
     $files = Filesystem::files($src, '.', false, true, array());
     Log::debug(__FUNCTION__ . "() " . implode(',', $files));
     if (!empty($files)) {
         // Copy directory
         Log::debug(__FUNCTION__ . "() copying {$src} to {$dest}");
         if (!Filesystem::copyDirectory($src, $dest, '', true)) {
             return false;
         } else {
             // Update screenshot information for this resource
             $ss->updateFiles($rid, $sourceid, $destid, $copy = 1);
             Log::debug(__FUNCTION__ . '() updated files');
             return true;
         }
     }
     Log::debug(__FUNCTION__ . '() done');
     return true;
 }
예제 #17
0
 /**
  * Create manifest file for video
  *
  * @param      $resource     HUB Resource
  * @return     Void
  */
 private function createVideoManifestForResource($resource)
 {
     //base url for the resource
     $base = DS . trim($this->config->get('uploadpath'), DS);
     //build the rest of the resource path and combine with base
     $path = Html::build_path($resource->created, $resource->id, '');
     //instantiate params object then parse resource attributes
     $attributes = new \Hubzero\Config\Registry($resource->attribs);
     //var to hold manifest data
     $manifest = new stdClass();
     $manifest->presentation = new stdClass();
     $manifest->presentation->title = $resource->title;
     $manifest->presentation->type = 'Video';
     $manifest->presentation->width = intval($attributes->get('width', 0));
     $manifest->presentation->height = intval($attributes->get('height', 0));
     $manifest->presentation->duration = intval($attributes->get('duration', 0));
     $manifest->presentation->media = array();
     $manifest->presentation->subtitles = array();
     //get the videos
     $videos = \Filesystem::files(PATH_APP . DS . $base . $path, '.mp4|.MP4|.ogv|.OGV|.webm|.WEBM');
     //add each video to manifest
     foreach ($videos as $k => $video) {
         // get info about video
         $videoInfo = pathinfo($video);
         // object to hold media type & source
         $media = new stdClass();
         $media->type = $videoInfo['extension'];
         $media->source = $path . DS . $video;
         // add media object to array of media
         $manifest->presentation->media[] = $media;
     }
     //get the subs
     $subtitles = \Filesystem::files(PATH_APP . DS . $base . $path, '.srt|.SRT');
     //add each subtitle to manifest
     foreach ($subtitles as $k => $subtitle) {
         //get name
         $info = pathinfo($subtitle);
         $name = str_replace('-auto', '', $info['filename']);
         $name = ucfirst($name);
         // object to hold subtitle info
         $sub = new stdClass();
         $sub->type = 'SRT';
         $sub->name = $name;
         $sub->source = $path . DS . $subtitle;
         $sub->autoplay = strstr($subtitle, '-') ? 1 : 0;
         // add sub object to array of subtitles
         $manifest->presentation->subtitles[] = $sub;
     }
     //reset array of subs and media
     $manifest->presentation->media = array_values($manifest->presentation->media);
     $manifest->presentation->subtitles = array_values($manifest->presentation->subtitles);
     // json encode manifest
     $manifest = json_encode($manifest, JSON_PRETTY_PRINT);
     // attempt to create manifest file
     if (!\Filesystem::write(PATH_APP . DS . $base . $path . DS . 'presentation.json', $manifest)) {
         return false;
     }
     return true;
 }
예제 #18
0
 /**
  * Build imagelist
  *
  * @param string $listFolder The image directory to display
  * @since 1.5
  */
 function getList()
 {
     static $list;
     // Only process the list once per request
     if (is_array($list)) {
         return $list;
     }
     // Get current path from request
     $current = $this->getState('folder');
     // If undefined, set to empty
     if ($current == 'undefined') {
         $current = '';
     }
     // Initialise variables.
     if (strlen($current) > 0) {
         $basePath = COM_MEDIA_BASE . '/' . $current;
     } else {
         $basePath = COM_MEDIA_BASE;
     }
     $mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE . '/');
     $images = array();
     $folders = array();
     $docs = array();
     $fileList = false;
     $folderList = false;
     if (file_exists($basePath)) {
         // Get the list of files and folders from the given folder
         $fileList = Filesystem::files($basePath);
         $folderList = Filesystem::directories($basePath);
     }
     // Iterate over the files if they exist
     if ($fileList !== false) {
         foreach ($fileList as $file) {
             if (is_file($basePath . '/' . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
                 $tmp = new \Hubzero\Base\Object();
                 $tmp->name = $file;
                 $tmp->title = $file;
                 $tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', \Hubzero\Filesystem\Util::normalizePath($basePath . '/' . $file));
                 $tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
                 $tmp->size = filesize($tmp->path);
                 $ext = strtolower(Filesystem::extension($file));
                 switch ($ext) {
                     // Image
                     case 'jpg':
                     case 'png':
                     case 'gif':
                     case 'xcf':
                     case 'odg':
                     case 'bmp':
                     case 'jpeg':
                     case 'ico':
                         $info = @getimagesize($tmp->path);
                         $tmp->width = @$info[0];
                         $tmp->height = @$info[1];
                         $tmp->type = @$info[2];
                         $tmp->mime = @$info['mime'];
                         if ($info[0] > 60 || $info[1] > 60) {
                             $dimensions = MediaHelper::imageResize($info[0], $info[1], 60);
                             $tmp->width_60 = $dimensions[0];
                             $tmp->height_60 = $dimensions[1];
                         } else {
                             $tmp->width_60 = $tmp->width;
                             $tmp->height_60 = $tmp->height;
                         }
                         if ($info[0] > 16 || $info[1] > 16) {
                             $dimensions = MediaHelper::imageResize($info[0], $info[1], 16);
                             $tmp->width_16 = $dimensions[0];
                             $tmp->height_16 = $dimensions[1];
                         } else {
                             $tmp->width_16 = $tmp->width;
                             $tmp->height_16 = $tmp->height;
                         }
                         $images[] = $tmp;
                         break;
                         // Non-image document
                     // Non-image document
                     default:
                         $tmp->icon_32 = "media/mime-icon-32/" . $ext . ".png";
                         $tmp->icon_16 = "media/mime-icon-16/" . $ext . ".png";
                         $docs[] = $tmp;
                         break;
                 }
             }
         }
     }
     // Iterate over the folders if they exist
     if ($folderList !== false) {
         foreach ($folderList as $folder) {
             $tmp = new \Hubzero\Base\Object();
             $tmp->name = basename($folder);
             $tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', \Hubzero\Filesystem\Util::normalizePath($basePath . '/' . $folder));
             $tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
             $count = MediaHelper::countFiles($tmp->path);
             $tmp->files = $count[0];
             $tmp->folders = $count[1];
             $folders[] = $tmp;
         }
     }
     $list = array('folders' => $folders, 'docs' => $docs, 'images' => $images);
     return $list;
 }
예제 #19
0
 /**
  * Add files to repo from extracted archive
  *
  * @return  boolean
  */
 protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
 {
     $reserved = isset($params['reserved']) ? $params['reserved'] : array();
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
     $z = 0;
     foreach ($extracted as $e) {
         $fileinfo = pathinfo($e);
         $a_dir = $fileinfo['dirname'];
         $a_dir = str_replace($extractPath . DS, '', $a_dir);
         // Skip certain system files
         if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
             continue;
         }
         $file = $fileinfo['basename'];
         $size = filesize($e);
         // Run some checks, stop in case of a problem
         if (!$this->_check($file, $e, $size, $available)) {
             return false;
         }
         // Clean up filename
         $safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
         $safe_dir = trim($safe_dir, DS);
         $safe_file = Filesystem::clean($file);
         $skipDir = false;
         if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
             $skipDir = true;
         }
         $safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
         $localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
         $where = $target . DS . $safeName;
         $exists = is_file($where) ? true : false;
         // Provision directory
         if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
             if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
                 // File object
                 $localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
                 $fileObject = new Models\File(trim($localDirPath), $this->get('path'));
                 $fileObject->set('type', 'folder');
                 $params['file'] = $fileObject;
                 $params['replace'] = false;
                 // Success - check in change
                 $this->call('checkin', $params);
                 $z++;
             }
         }
         // Copy file into project
         if (Filesystem::copy($e, $target . DS . $safeName)) {
             // File object
             $fileObject = new Models\File(trim($localPath), $this->get('path'));
             $params['file'] = $fileObject;
             $params['replace'] = $exists;
             // Success - check in change
             $this->call('checkin', $params);
             $z++;
         }
     }
     return $z;
 }
예제 #20
0
 /**
  * Method to rename the template in the XML files and rename the language files
  *
  * @return	boolean   true if successful, false otherwise
  * @since	2.5
  */
 protected function fixTemplateName()
 {
     // Rename Language files
     // Get list of language files
     $result = true;
     $files = Filesystem::files($this->getState('to_path'), '.ini', true, true);
     $newName = strtolower($this->getState('new_name'));
     $oldName = $this->getTemplate()->element;
     foreach ($files as $file) {
         $newFile = str_replace($oldName, $newName, $file);
         $result = Filesystem::move($file, $newFile) && $result;
     }
     // Edit XML file
     $xmlFile = $this->getState('to_path') . '/templateDetails.xml';
     if (Filesystem::exists($xmlFile)) {
         $contents = Filesystem::read($xmlFile);
         $pattern[] = '#<name>\\s*' . $oldName . '\\s*</name>#i';
         $replace[] = '<name>' . $newName . '</name>';
         $pattern[] = '#<language(.*)' . $oldName . '(.*)</language>#';
         $replace[] = '<language${1}' . $newName . '${2}</language>';
         $contents = preg_replace($pattern, $replace, $contents);
         $result = Filesystem::write($xmlFile, $contents) && $result;
     }
     return $result;
 }
예제 #21
0
 /**
  * Add files to repo from extracted archive
  *
  * @return  boolean
  */
 protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
 {
     $reserved = isset($params['reserved']) ? $params['reserved'] : array();
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
     // check for viruses - scans the directory for efficency
     $command = "clamscan -i --no-summary --block-encrypted -r " . $extractPath;
     exec($command, $output, $virus_status);
     $virusChecked = FALSE;
     if ($virus_status == 0) {
         $virusChecked = TRUE;
     } else {
         Filesystem::deleteDirectory($extractPath);
         $this->setError('The antivirus software has rejected your files.');
         return false;
     }
     $z = 0;
     foreach ($extracted as $e) {
         $fileinfo = pathinfo($e);
         $a_dir = $fileinfo['dirname'];
         $a_dir = str_replace($extractPath . DS, '', $a_dir);
         // Skip certain system files
         if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
             continue;
         }
         $file = $fileinfo['basename'];
         $size = filesize($e);
         // Run some checks, stop in case of a problem
         if (!$this->_check($file, $e, $size, $available, $virusChecked)) {
             return false;
         }
         // Clean up filename
         $safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
         $safe_dir = trim($safe_dir, DS);
         $safe_file = Filesystem::clean($file);
         // Strips out temporary path
         if (strpos($safe_dir, 'tmp/') !== FALSE) {
             $parts = explode('/', $safe_dir);
             $safe_dir = str_replace($parts[0] . '/', '', $safe_dir);
             $safe_dir = str_replace($parts[1] . '/', '', $safe_dir);
         }
         $skipDir = false;
         if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
             $skipDir = true;
         }
         $safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
         $localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
         $where = $target . DS . $safeName;
         $exists = is_file($where) ? true : false;
         // Provision directory
         if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
             if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
                 // File object
                 $localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
                 $fileObject = new Models\File(trim($localDirPath), $this->get('path'));
                 $fileObject->set('type', 'folder');
                 $params['file'] = $fileObject;
                 $params['replace'] = false;
                 // Success - check in change
                 $this->call('checkin', $params);
                 $z++;
             }
         }
         // Strips out temporary path
         if (strpos($safeName, 'tmp/') !== FALSE) {
             $parts = explode('/', $safeName);
             $safeName = str_replace($parts[0] . '/', '', $safeName);
             $safeName = str_replace($parts[1] . '/', '', $safeName);
         }
         // Copy file into project
         if (Filesystem::copy($e, $target . DS . $safeName)) {
             // File object
             $fileObject = new Models\File(trim($localPath), $this->get('path'));
             $params['file'] = $fileObject;
             $params['replace'] = $exists;
             // Success - check in change
             $this->call('checkin', $params);
             $z++;
         }
     }
     return $z;
 }
예제 #22
0
 $presentation = json_decode($contents);
 $presentation = $presentation->presentation;
 // get subs from json file
 $subs = isset($presentation->subtitles) ? $presentation->subtitles : array();
 // make sure source is full path to assets folder
 $subFiles = array();
 foreach ($subs as $k => $subtitle) {
     if (!strpos($subtitle->source, DS)) {
         $subtitle->source = $content_folder . DS . $subtitle->source;
     }
     $subFiles[] = $subtitle->source;
 }
 // get local subs
 $local_subs = array();
 if (is_dir($content_folder)) {
     $local_subs = Filesystem::files(PATH_ROOT . DS . $content_folder, '.srt|.SRT', true, false);
 }
 // add local subtitles too
 foreach ($local_subs as $k => $subtitle) {
     $info = pathinfo($subtitle);
     $name = str_replace('-auto', '', $info['filename']);
     $autoplay = strstr($info['filename'], '-auto') ? 1 : 0;
     $source = $content_folder . DS . $subtitle;
     // add each subtitle
     $subtitle = new stdClass();
     $subtitle->type = 'SRT';
     $subtitle->name = ucfirst($name);
     $subtitle->source = $source;
     $subtitle->autoplay = $autoplay;
     // make sure we dont already have this file.
     if (!in_array($subtitle->source, $subFiles)) {
예제 #23
0
 /**
  * Upload a file or create a new folder
  *
  * @return  void
  */
 public function uploadTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $listdir = Request::getVar('listdir', '', 'post');
     if (!$listdir) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_LISTDIR'));
         $this->displayTask();
         return;
     }
     // Incoming sub-directory
     $subdir = Request::getVar('dirPath', '', 'post');
     // Build the path
     $path = Utilities::buildUploadPath($listdir, $subdir);
     // Are we creating a new folder?
     $foldername = Request::getVar('foldername', '', 'post');
     if ($foldername != '') {
         // Make sure the name is valid
         if (preg_match("/[^0-9a-zA-Z_]/i", $foldername)) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIR_INVALID_CHARACTERS'));
         } else {
             if (!is_dir($path . DS . $foldername)) {
                 if (!\Filesystem::makeDirectory($path . DS . $foldername)) {
                     $this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
                 }
             } else {
                 $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIR_EXISTS'));
             }
         }
         // Directory created
     } else {
         // Make sure the upload path exist
         if (!is_dir($path)) {
             if (!\Filesystem::makeDirectory($path)) {
                 $this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
                 $this->displayTask();
                 return;
             }
         }
         // Incoming file
         $file = Request::getVar('upload', '', 'files', 'array');
         if (!$file['name']) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_FILE'));
             $this->displayTask();
             return;
         }
         // Make the filename safe
         $file['name'] = \Filesystem::clean($file['name']);
         // Ensure file names fit.
         $ext = \Filesystem::extension($file['name']);
         $file['name'] = str_replace(' ', '_', $file['name']);
         if (strlen($file['name']) > 230) {
             $file['name'] = substr($file['name'], 0, 230);
             $file['name'] .= '.' . $ext;
         }
         // Perform the upload
         if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_UPLOADING'));
         } else {
             // File was uploaded
             // Was the file an archive that needs unzipping?
             $batch = Request::getInt('batch', 0, 'post');
             if ($batch) {
                 //build path
                 $path = rtrim($path, DS) . DS;
                 $escaped_file = escapeshellarg($path . $file['name']);
                 //determine command to uncompress
                 switch ($ext) {
                     case 'gz':
                         $cmd = "tar zxvf {$escaped_file} -C {$path}";
                         break;
                     case 'tar':
                         $cmd = "tar xvf {$escaped_file} -C {$path}";
                         break;
                     case 'zip':
                     default:
                         $cmd = "unzip -o {$escaped_file} -d {$path}";
                 }
                 //unzip file
                 if ($result = shell_exec($cmd)) {
                     // Remove original archive
                     \Filesystem::delete($path . $file['name']);
                     // Remove MACOSX dirs if there
                     if (\Filesystem::exists($path . '__MACOSX')) {
                         \Filesystem::deleteDirectory($path . '__MACOSX');
                     }
                     //remove ._ files
                     $dotFiles = \Filesystem::files($path, '._[^\\s]*', true, true);
                     foreach ($dotFiles as $dotFile) {
                         \Filesystem::delete($dotFile);
                     }
                 }
             }
         }
     }
     // Push through to the media view
     $this->displayTask();
 }
예제 #24
0
 protected function getTypeOptionsFromLayouts($component, $view)
 {
     // Initialise variables.
     $options = array();
     $layouts = array();
     $layoutNames = array();
     $templateLayouts = array();
     $lang = Lang::getRoot();
     // Get the layouts from the view folder.
     $path = PATH_CORE . '/components/' . $component . '/views/' . $view . '/tmpl';
     $path2 = PATH_CORE . '/components/' . $component . '/site/views/' . $view . '/tmpl';
     if (Filesystem::exists($path)) {
         $layouts = array_merge($layouts, Filesystem::files($path, '.xml$', false, true));
     } else {
         if (Filesystem::exists($path2)) {
             $layouts = array_merge($layouts, Filesystem::files($path2, '.xml$', false, true));
         } else {
             return $options;
         }
     }
     // build list of standard layout names
     foreach ($layouts as $layout) {
         $layout = trim($layout, '/');
         // Ignore private layouts.
         if (strpos(basename($layout), '_') === false) {
             $file = $layout;
             // Get the layout name.
             $layoutNames[] = Filesystem::name(basename($layout));
         }
     }
     // get the template layouts
     // TODO: This should only search one template -- the current template for this item (default of specified)
     $folders = Filesystem::directories(JPATH_SITE . '/templates', '', false, true);
     // Array to hold association between template file names and templates
     $templateName = array();
     foreach ($folders as $folder) {
         if (Filesystem::exists($folder . '/html/' . $component . '/' . $view)) {
             $template = basename($folder);
             $lang->load('tpl_' . $template . '.sys', JPATH_SITE, null, false, true) || $lang->load('tpl_' . $template . '.sys', JPATH_SITE . '/templates/' . $template, null, false, true);
             $templateLayouts = Filesystem::files($folder . '/html/' . $component . '/' . $view, '.xml$', false, true);
             foreach ($templateLayouts as $layout) {
                 $file = trim($layout, '/');
                 // Get the layout name.
                 $templateLayoutName = Filesystem::name(basename($layout));
                 // add to the list only if it is not a standard layout
                 if (array_search($templateLayoutName, $layoutNames) === false) {
                     $layouts[] = $layout;
                     // Set template name array so we can get the right template for the layout
                     $templateName[$layout] = basename($folder);
                 }
             }
         }
     }
     // Process the found layouts.
     foreach ($layouts as $layout) {
         $layout = trim($layout, '/');
         // Ignore private layouts.
         if (strpos(basename($layout), '_') === false) {
             $file = $layout;
             // Get the layout name.
             $layout = Filesystem::name(basename($layout));
             // Create the menu option for the layout.
             $o = new \Hubzero\Base\Object();
             $o->title = ucfirst($layout);
             $o->description = '';
             $o->request = array('option' => $component, 'view' => $view);
             // Only add the layout request argument if not the default layout.
             if ($layout != 'default') {
                 // If the template is set, add in format template:layout so we save the template name
                 $o->request['layout'] = isset($templateName[$file]) ? $templateName[$file] . ':' . $layout : $layout;
             }
             // Load layout metadata if it exists.
             if (is_file($file)) {
                 // Attempt to load the xml file.
                 if ($xml = simplexml_load_file($file)) {
                     // Look for the first view node off of the root node.
                     if ($menu = $xml->xpath('layout[1]')) {
                         $menu = $menu[0];
                         // If the view is hidden from the menu, discard it and move on to the next view.
                         if (!empty($menu['hidden']) && $menu['hidden'] == 'true') {
                             unset($xml);
                             unset($o);
                             continue;
                         }
                         // Populate the title and description if they exist.
                         if (!empty($menu['title'])) {
                             $o->title = trim((string) $menu['title']);
                         }
                         if (!empty($menu->message[0])) {
                             $o->description = trim((string) $menu->message[0]);
                         }
                     }
                 }
             }
             // Add the layout to the options array.
             $options[] = $o;
         }
     }
     return $options;
 }
예제 #25
0
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
$this->css('badge.css');
switch ($this->action) {
    case 'image':
        // Build the upload path
        $img_location = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/courses'), DS);
        $img_location .= DS . 'badges' . DS . $this->badge->get('id') . DS;
        if (is_dir($img_location)) {
            $file = Filesystem::files($img_location, 'badge');
            if (isset($file[0])) {
                $img_location .= $file[0];
            } else {
                return App::abort(404, Lang::txt('COM_COURSES_FILE_NOT_FOUND'));
            }
        } else {
            return App::abort(404, Lang::txt('COM_COURSES_FILE_NOT_FOUND'));
        }
        // Initiate a new content server and serve up the file
        $xserver = new \Hubzero\Content\Server();
        $xserver->filename($img_location);
        $xserver->disposition('inline');
        $xserver->acceptranges(false);
        if (!$xserver->serve()) {
            // Should only get here on error
예제 #26
0
 /**
  * Get member files (provisioned project)
  *
  * @param   boolean  $recurse
  * @return  array
  */
 protected function _getMemberFiles($recurse = true)
 {
     // Check path format
     $subdir = trim($this->subdir, DS);
     $fullpath = $subdir ? $this->_path . DS . $subdir : $this->_path;
     $get = Filesystem::files($fullpath);
     $files = array();
     if ($get) {
         foreach ($get as $file) {
             if (substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
                 $file = str_replace($this->_path . DS, '', $file);
                 $entry = new \Components\Projects\Models\File(trim($file), $this->_path);
                 $files[] = $entry;
             }
         }
     }
     return $files;
 }
예제 #27
0
    }
}
//check to see if already have subtitles
if (!isset($presentation->subtitles)) {
    $presentation->subtitles = array();
}
// make sure source is full path to assets folder
$subFiles = array();
foreach ($presentation->subtitles as $k => $subtitle) {
    if (!strpos($subtitle->source, DS)) {
        $subtitle->source = $content_folder . DS . $subtitle->source;
    }
    $subFiles[] = $subtitle->source;
}
//get all local subtitles
$localSubtitles = Filesystem::files(PATH_APP . DS . $content_folder, '.srt|.SRT');
// add local subtitles too
foreach ($localSubtitles as $k => $subtitle) {
    $info = pathinfo($subtitle);
    $name = str_replace('-auto', '', $info['filename']);
    $autoplay = strstr($info['filename'], '-auto') ? 1 : 0;
    $source = $content_folder . DS . $subtitle;
    // add each subtitle
    $subtitle = new stdClass();
    $subtitle->type = 'SRT';
    $subtitle->name = ucfirst($name);
    $subtitle->source = $source;
    $subtitle->autoplay = $autoplay;
    // make sure we dont already have this file.
    if (!in_array($subtitle->source, $subFiles)) {
        $presentation->subtitles[] = $subtitle;