extension() public static method

public static extension ( $file )
Esempio n. 1
0
 protected function filename($filename)
 {
     if (is_null(Filesystem::extension($filename))) {
         $filename .= '.htm';
     }
     return $filename . '.php';
 }
Esempio n. 2
0
 public function extension($file, $ext)
 {
     if (strpos($file, '?') === false && Filesystem::extension($file) != $ext) {
         $file .= '.' . $ext;
     }
     return $file;
 }
Esempio n. 3
0
 /**
  * Return URL with fingerprint
  * @param type $sRootPath Path from root
  */
 public static function getStaticProperUrl($sRootPath)
 {
     $sFilePath = Filesystem::path($sRootPath);
     $sFileName = Filesystem::name($sRootPath);
     $sFileExtension = Filesystem::extension($sRootPath);
     $sFileLastModificationDate = filemtime($sRootPath);
     $sUrl = Config::get('app.url') . $sFilePath . Config::get('format.dir.slash') . $sFileName . '_' . $sFileLastModificationDate . '_.' . $sFileExtension;
     return $sUrl;
 }
Esempio n. 4
0
function migrate($migration, $connection)
{
    echo 'importing ' . $migration . '... ';
    $ext = Filesystem::extension($migration);
    if ($ext == 'php') {
        require_once 'db/migrations/' . $migration;
        $classname = get_migration_name($migration);
        $classname::migrate($connection);
    } else {
        $connection->query(utf8_decode(Filesystem::read('db/migrations/' . $migration)));
    }
    $connection->create(array('table' => 'schema_migrations', 'values' => array('version' => get_migration_version($migration))));
    echo 'done' . PHP_EOL;
}
Esempio n. 5
0
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  * @since	1.6
  */
 protected function populateState()
 {
     // Load the User state.
     $id = User::getState('com_templates.edit.source.id');
     // Parse the template id out of the compound reference.
     $temp = explode(':', base64_decode($id));
     $this->setState('extension.id', (int) array_shift($temp));
     $fileName = array_shift($temp);
     $this->setState('filename', $fileName);
     // Save the syntax for later use
     User::setState('editor.source.syntax', Filesystem::extension($fileName));
     // Load the parameters.
     $params = Component::params('com_templates');
     $this->setState('params', $params);
 }
Esempio n. 6
0
 /**
  * Checks if the file can be uploaded
  * @param array File information
  * @param string An error message to be returned
  * @return boolean
  */
 function canUpload($file, &$err)
 {
     $params = Component::params('com_media');
     $format = Filesystem::extension($file['name']);
     $allowable = explode(',', $params->get('upload_extensions'));
     if (!in_array($format, $allowable)) {
         $err = Lang::txt('COM_MEDIA_ERROR_WARNFILETYPE');
         return false;
     }
     $maxSize = (int) ($params->get('upload_maxsize', 0) * 1024 * 1024);
     if ($maxSize > 0 && (int) $file['size'] > $maxSize) {
         $err = Lang::txt('COM_MEDIA_ERROR_WARNFILETOOLARGE');
         return false;
     }
     return true;
 }
Esempio n. 7
0
 /**
  * Get a default image for the store item
  *
  * @param      string $option   Component name
  * @param      string $item     Item ID
  * @param      string $root     Root path
  * @param      string $wpath    Base path for files
  * @param      string $alt      Image alt text
  * @param      string $category Item category
  * @return     string HTML
  */
 public static function productimage($option, $item, $root, $wpath, $alt, $category)
 {
     if ($wpath) {
         $wpath = DS . trim($wpath, DS) . DS;
     }
     $d = @dir($root . $wpath . $item);
     $images = array();
     $html = '';
     if ($d) {
         while (false !== ($entry = $d->read())) {
             $img_file = $entry;
             if (is_file($root . $wpath . $item . DS . $img_file) && substr($entry, 0, 1) != '.' && strtolower($entry) !== 'index.html') {
                 if (preg_match("#bmp|gif|jpg|png|swf#i", $img_file)) {
                     $images[] = $img_file;
                 }
             }
         }
         $d->close();
     } else {
         if ($category == 'service') {
             $html = '<span class="nophoto"></span>';
         } else {
             $html = '<span class="nophoto premium"></span>';
         }
     }
     sort($images);
     $els = '';
     $k = 0;
     $g = 0;
     for ($i = 0, $n = count($images); $i < $n; $i++) {
         $ext = \Filesystem::extension($images[$i]);
         $tn = \Filesystem::name($images[$i]) . '-tn.';
         if (!is_file($root . $wpath . $item . DS . $tn . $ext)) {
             $ext = 'gif';
         }
         $tn = $tn . $ext;
         if (is_file($root . $wpath . $item . DS . $tn)) {
             $k++;
             $els .= '<a rel="lightbox" href="' . $wpath . $item . '/' . $images[$i] . '" title="' . $alt . '"><img src="' . $wpath . $item . '/' . $tn . '" alt="' . $alt . '" /></a>';
         }
     }
     if ($els) {
         $html .= $els;
     }
     return $html;
 }
Esempio n. 8
0
 public function validates($file)
 {
     $this->errors = array();
     if (empty($file) && !isset($file['name'])) {
         return $this->error('InvalidParam');
     }
     if ($this->maxSize && filesize($file['tmp_name']) > $this->maxSize * 1024 * 1024) {
         return $this->error('FileSizeExceeded');
     }
     $ext = Filesystem::extension($file['name']);
     if (!empty($this->allowedTypes) && !in_array($ext, $this->allowedTypes)) {
         return $this->error('FileTypeNotAllowed');
     }
     if ($uploadError = $this->uploadError($file['error'])) {
         return $this->error($uploadError);
     }
     return true;
 }
Esempio n. 9
0
 /**
  * loadConfig 
  * 
  * @param string $name 
  * @access public
  * @return void
  */
 public function loadConfig($name = '')
 {
     $baseDir = PATH_APP . DS . 'config' . DS . 'search' . DS . 'types';
     if ($name == '') {
         $configFiles = Filesystem::listContents($baseDir);
         $config = array();
         foreach ($configFiles as $file) {
             if (Filesystem::extension($baseDir . $file['path']) == 'php') {
                 $typeConfig = (require_once $baseDir . $file['path']);
                 array_push($config, $typeConfig);
             }
         }
         return $config;
     } elseif ($name != '') {
         $filename = $baseDir . DS . $name . '.php';
         if (Filesystem::exists($filename)) {
             $config = (include $filename);
         } else {
             $config = false;
         }
         return $config;
     }
     return false;
 }
Esempio n. 10
0
		<div id="transcript-container">
			<div id="transcript-toolbar">
				<div id="transcript-select"></div>
				<input type="text" id="transcript-search" placeholder="Search Transcript..." />
				<a href="javascript:void(0);" id="font-bigger"></a>
				<a href="javascript:void(0);" id="font-smaller"></a>
			</div>
			<div id="transcripts"></div>
		</div>
	</div>
<?php 
} elseif ($type == 'standalone') {
    ?>
	<?php 
    $path = DS . trim(substr(PATH_APP, strlen(PATH_ROOT)), DS) . DS . ltrim($path . DS . $this->model->get('url'), DS);
    $ext = strtolower(Filesystem::extension(PATH_ROOT . $path));
    Document::addStyleSheet('//releases.flowplayer.org/5.4.2/skin/minimalist.css');
    Document::addScript('//releases.flowplayer.org/5.4.2/flowplayer.min.js');
    ?>
	<div class="flowplayer">
		<video id="movie<?php 
    echo rand(0, 1000);
    ?>
" preload controls>
			<?php 
    switch ($ext) {
        case 'mov':
        case 'mp4':
        case 'm4v':
            echo '<source src="' . $path . '" type="video/mp4" />';
            break;
Esempio n. 11
0
 /**
  * Uploads a file to a given directory and returns an attachment string
  * that is appended to report/comment bodies
  *
  * @param      string $listdir Directory to upload files to
  * @return     string A string that gets appended to messages
  */
 public function upload($listdir, $post_id)
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return;
     }
     if (!$listdir) {
         $this->setError(Lang::txt('PLG_GROUPS_FORUM_NO_UPLOAD_DIRECTORY'));
         return;
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file['name']) {
         return;
     }
     // Incoming
     $description = trim(Request::getVar('description', ''));
     // Construct our file path
     $path = PATH_APP . DS . trim($this->params->get('filepath', '/site/forum'), DS) . DS . $listdir;
     if ($post_id) {
         $path .= DS . $post_id;
     }
     // Build the path if it doesn't exist
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('PLG_GROUPS_FORUM_UNABLE_TO_CREATE_UPLOAD_PATH'));
             return;
         }
     }
     // Make the filename safe
     $file['name'] = Filesystem::clean($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     $ext = strtolower(Filesystem::extension($file['name']));
     // Perform the upload
     if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('PLG_GROUPS_FORUM_ERROR_UPLOADING'));
         return;
     } else {
         // File was uploaded
         // Create database entry
         $row = new \Components\Forum\Tables\Attachment($this->database);
         $row->bind(array('id' => 0, 'parent' => $listdir, 'post_id' => $post_id, 'filename' => $file['name'], 'description' => $description));
         if (!$row->check()) {
             $this->setError($row->getError());
         }
         if (!$row->store()) {
             $this->setError($row->getError());
         }
     }
 }
Esempio n. 12
0
 /**
  * Edit Newsletter Story Task
  *
  * @return 	void
  */
 public function editTask()
 {
     //get request vars
     $this->view->type = strtolower(Request::getVar("type", "primary"));
     $this->view->id = Request::getInt("id", 0);
     $this->view->sid = Request::getInt("sid", 0);
     //load campaign
     $this->view->newsletter = new Newsletter($this->database);
     $this->view->newsletter->load($this->view->id);
     //default object
     $this->view->story = new stdClass();
     $this->view->story->id = null;
     $this->view->story->order = null;
     $this->view->story->title = null;
     $this->view->story->story = null;
     $this->view->story->readmore_title = null;
     $this->view->story->readmore_link = null;
     //are we editing
     if ($this->view->sid) {
         if ($this->view->type == "primary") {
             $this->view->story = new PrimaryStory($this->database);
         } else {
             $this->view->story = new SecondaryStory($this->database);
         }
         $this->view->story->load($this->view->sid);
     }
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     // If we are creating an auto-generated newsletter
     if ($this->view->type == 'autogen') {
         // Load available sources
         $this->view->enabledSources = Event::trigger('newsletter.onGetEnabledDigests');
         /* It should be noted that these are not served via the CMS, per se. Rather they
          * JavaScript will manipulate the DOM and save the HTML as a string into the Primary
          * Story content field.
          */
         // The path where the Story Template Layouts are.
         $viewPath = dirname(__DIR__) . DS . 'views' . DS . 'storytemplates' . DS . 'tmpl';
         // Get available layouts
         $contents = Filesystem::listContents($viewPath);
         // Empty bucket to hold layout names;
         $this->view->layouts = array();
         // Make sure we aren't including any cruft.
         foreach ($contents as $file) {
             // Check for php extention
             if (Filesystem::extension($viewPath . DS . $file['path']) == 'php' && $file['path'] != '/index.php') {
                 // Some trimming of the leading / and the .php; push into bucket
                 array_push($this->view->layouts, rtrim(ltrim($file['path'], "//"), ".php"));
             }
         }
         // Display the alternative layout
         $this->view->setLayout('_autogen')->display();
     } else {
         // Output the HTML
         $this->view->setLayout('edit')->display();
     }
 }
Esempio n. 13
0
 $base = $this->model->params->get('uploadpath');
 $i = 0;
 $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
 $usersgroups = array();
 if (!empty($xgroups)) {
     foreach ($xgroups as $group) {
         if ($group->regconfirmed) {
             $usersgroups[] = $group->cn;
         }
     }
 }
 $allowedgroups = $this->model->resource->getGroups();
 foreach ($children as $child) {
     if ($child->access == 0 || $child->access == 1 && !User::isGuest() || $child->access == 3 && in_array($this->model->resource->group_owner, $usersgroups)) {
         $i++;
         $ftype = Filesystem::extension($child->path);
         if (substr($child->path, 0, 4) == 'http') {
             $ftype = 'html';
         }
         $class = '';
         $action = '';
         if ($child->standalone == 1) {
             $liclass = ' class="html"';
             $title = stripslashes($child->title);
         } else {
             $rt = \Components\Resources\Tables\Type::getRecordInstance($child->type);
             $tparams = new \Hubzero\Config\Registry($rt->params);
             $lt = \Components\Resources\Tables\Type::getRecordInstance($child->logicaltype);
             $ltparams = new \Hubzero\Config\Registry($lt->params);
             // Check the link action by child's type
             if ($child->logicaltype) {
Esempio n. 14
0
    /**
     * Generates HTML to either embed a file or link to file for download
     *
     * @param      string $file File to embed
     * @param      array  $attr Attributes to apply to the HTML
     * @return     string
     */
    private function _embed($file, $attr = array())
    {
        $ext = strtolower(Filesystem::extension($file));
        switch ($ext) {
            case 'unity3d':
                $attr['width'] = isset($attr['width']) && $attr['width'] ? $attr['width'] : 400;
                $attr['height'] = isset($attr['height']) && $attr['height'] ? $attr['height'] : 400;
                if (isset($attr['style']['width'])) {
                    $attr['width'] = intval($attr['style']['width']);
                }
                if (isset($attr['style']['height'])) {
                    $attr['height'] = intval($attr['style']['height']);
                }
                $attr['href'] = isset($attr['href']) && $attr['href'] && $attr['href'] != 'none' ? $attr['href'] : $this->_link($file);
                /*if (!array_key_exists('alt', $attr)
                		 && array_key_exists('altimage', $attr)
                		 && $attr['altimage'] != ''
                		 && file_exists($this->_path($attr['altimage'])))
                		{
                			//$attr['href'] = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                			$althref = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                			$attr['alt']  = '<a class="attachment" rel="internal" href="' . $althref . '" title="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '">';
                			$attr['alt'] .= '<img src="' . $this->_link($attr['altimage']) . '" alt="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '" />';
                			$attr['alt'] .= '</a>';
                		}
                		else
                		{
                			$althref = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                			$attr['alt']  = (isset($attr['alt'])) ? $attr['alt'] : '';
                			$attr['alt'] .= '<a class="attachment" rel="internal" href="' . $althref . '" title="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '">' . $attr['desc'] . '</a>';
                		}*/
                $rand = rand(0, 100000);
                $html = '<script type="text/javascript" src="' . (\Request::scheme() == 'https' ? 'https://ssl-' : 'http://') . 'webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js"></script>' . "\n";
                $html .= '<div id="unityPlayer' . $rand . '">
							<div class="missing">
								<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
									<img alt="Unity Web Player. Install now!" src="' . (\Request::scheme() == 'https' ? 'https://ssl-' : 'http://') . 'webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
								</a>
							</div>
						</div>' . "\n";
                $html .= '<script type="text/javascript">' . "\n";
                $html .= '<!--
							var config = {
								width: ' . intval($attr['width']) . ',
								height: ' . intval($attr['height']) . ',
								params: { enableDebugging:"0" }
							}
							var u = new UnityObject2(config);
							var unityObject = $("#unityPlayer' . $rand . '");
							u.initPlugin(unityObject, "' . $attr['href'] . '");
							-->' . "\n";
                $html .= '</script>' . "\n";
                break;
            case 'cdf':
                $attr['width'] = isset($attr['width']) && $attr['width'] ? $attr['width'] : 400;
                $attr['height'] = isset($attr['height']) && $attr['height'] ? $attr['height'] : 400;
                if (isset($attr['style']['width'])) {
                    $attr['width'] = intval($attr['style']['width']);
                }
                if (isset($attr['style']['height'])) {
                    $attr['height'] = intval($attr['style']['height']);
                }
                $attr['href'] = isset($attr['href']) && $attr['href'] && $attr['href'] != 'none' ? $attr['href'] : $this->_link($file);
                $rand = rand(0, 100000);
                if (!array_key_exists('alt', $attr) && array_key_exists('altimage', $attr) && $attr['altimage'] != '' && file_exists($this->_path($attr['altimage']))) {
                    //$attr['href'] = (array_key_exists('althref', $attr) && $attr['althref'] != '') ? $attr['althref'] : $attr['href'];
                    $althref = array_key_exists('althref', $attr) && $attr['althref'] != '' ? $attr['althref'] : $attr['href'];
                    $attr['alt'] = '<a href="http://www.wolfram.com/cdf-player/" title="CDF Web Player. Install now!">';
                    $attr['alt'] .= '<img src="' . $this->_link($attr['altimage']) . '" alt="' . htmlentities($attr['desc'], ENT_COMPAT, 'UTF-8') . '" />';
                    $attr['alt'] .= '</a>';
                } else {
                    $attr['alt'] = '<div class="embedded-plugin" style="width: ' . intval($attr['width']) . 'px; height: ' . intval($attr['height']) . 'px;"><a class="missing-plugin" href="http://www.wolfram.com/cdf-player/" title="CDF Web Player. Install now!"><img alt="CDF Web Player. Install now!" src="' . $juri->getScheme() . '://www.wolfram.com/cdf/images/cdf-player-black.png" width="187" height="41" /></a></div>';
                }
                $html = '<script type="text/javascript" src="' . \Request::scheme() . '://www.wolfram.com/cdf-player/plugin/v2.1/cdfplugin.js"></script>';
                $html .= '<script type="text/javascript">';
                //$html .= '<!--';
                $html .= '	var cdf = new cdfplugin();';
                $html .= "var defaultContent = '" . $attr['alt'] . "';";
                $html .= '	if (defaultContent!= "") {';
                $html .= '		cdf.setDefaultContent(defaultContent);';
                $html .= '	}';
                $html .= '	cdf.embed(\'' . $attr['href'] . '\', ' . intval($attr['width']) . ', ' . intval($attr['height']) . ');';
                //$html .= ' -->';
                $html .= '</script>' . "\n";
                $html .= '<noscript>';
                $html .= '<div class="embedded-plugin" style="width: ' . intval($attr['width']) . 'px; height: ' . intval($attr['height']) . ';">';
                $html .= $attr['alt'];
                $html .= '</div>';
                $html .= '</noscript>' . "\n";
                break;
            default:
                $attr['alt'] = isset($attr['alt']) ? htmlentities($attr['alt'], ENT_COMPAT, 'UTF-8') : $attr['desc'];
                if (!$attr['alt']) {
                    $attr['alt'] = $file;
                }
                if (in_array($ext, $this->imgs)) {
                    $styles = '';
                    if (count($attr['style']) > 0) {
                        $s = array();
                        foreach ($attr['style'] as $k => $v) {
                            $s[] = strtolower($k) . ':' . $v;
                        }
                        $styles = implode('; ', $s);
                    }
                    $attr['style'] = '';
                    $attribs = array();
                    foreach ($attr as $k => $v) {
                        $k = strtolower($k);
                        if ($k != 'href' && $k != 'rel' && $k != 'desc' && $v) {
                            $attribs[] = $k . '="' . trim($v, '"') . '"';
                        }
                    }
                    $html = '<span class="figure"' . ($styles ? ' style="' . $styles . '"' : '') . '>';
                    $img = '<img src="' . $this->_link($file) . '" ' . implode(' ', $attribs) . ' />';
                    if ($attr['href'] == 'none') {
                        $html .= $img;
                    } else {
                        $attr['href'] = $attr['href'] ? $attr['href'] : $this->_link($file);
                        $attr['rel'] = isset($attr['rel']) ? $attr['rel'] : 'lightbox';
                        $html .= '<a rel="' . $attr['rel'] . '" href="' . $attr['href'] . '">' . $img . '</a>';
                    }
                    if (isset($attr['desc']) && $attr['desc']) {
                        $html .= '<span class="figcaption">' . $attr['desc'] . '</span>';
                    }
                    $html .= '</span>';
                } else {
                    $attr['details'] = isset($attr['details']) ? $attr['details'] : true;
                    $attr['href'] = isset($attr['href']) && $attr['href'] != '' ? $attr['href'] : $this->_link($file);
                    $attr['rel'] = isset($attr['rel']) ? $attr['rel'] : 'internal';
                    $size = null;
                    if (file_exists($this->_path($file))) {
                        $size = filesize($this->_path($file));
                    } else {
                        if (file_exists($this->_path($file, true))) {
                            $size = filesize($this->_path($file, true));
                        }
                    }
                    $attr['title'] = !isset($attr['title']) || !$attr['title'] ? $attr['alt'] : $attr['title'];
                    $html = '<a class="attachment" rel="' . $attr['rel'] . '" href="' . $attr['href'] . '" title="' . $attr['title'] . '">' . $attr['desc'] . '</a>';
                    if ($size !== null && $attr['details']) {
                        $html .= ' (<span class="file-atts">' . \Hubzero\Utility\Number::formatBytes($size);
                        if (isset($attr['created_by'])) {
                            $user = User::getInstance($attr['created_by']);
                            $html .= ', ' . Lang::txt('uploaded by %s ', stripslashes($user->get('name')));
                        }
                        if (isset($attr['created'])) {
                            $html .= ' ' . Date::of($attr['created'])->relative();
                        }
                        $html .= '</span>)';
                    }
                }
                break;
        }
        return $html;
    }
Esempio n. 15
0
 /**
  * Save an Import
  *
  * @return  void
  */
 public function saveTask()
 {
     // check token
     Session::checkToken();
     // get request vars
     $import = Request::getVar('import', array());
     $hooks = Request::getVar('hooks', array());
     $params = Request::getVar('params', array());
     $file = Request::getVar('file', array(), 'FILES');
     // create import model object
     $this->import = new Models\Import();
     // set our hooks
     $this->import->set('hooks', json_encode($hooks));
     // load current params
     $iparams = new \Hubzero\Config\Registry($this->import->get('params'));
     // bind incoming params
     $iparams->parse($params);
     // set params on import object
     $this->import->set('params', $iparams->toString());
     // bind input to model
     if (!$this->import->bind($import)) {
         $this->setError($this->import->getError());
         return $this->editTask();
     }
     // is this a new import
     $isNew = false;
     if (!$this->import->get('id')) {
         $isNew = true;
         // set the created by/at
         $this->import->set('created_by', User::get('id'));
         $this->import->set('created_at', Date::toSql());
     }
     // do we have a data file
     if ($this->import->get('file')) {
         // get record count
         $importImporter = new Importer();
         $count = $importImporter->count($this->import);
         $this->import->set('count', $count);
     }
     // attempt to save
     if (!$this->import->store(true)) {
         $this->setError($this->import->getError());
         return $this->editTask();
     }
     // is this a new import
     if ($isNew) {
         // create folder for files
         $this->_createImportFilespace($this->import);
     }
     // if we have a file
     if (is_array($file) && $file['size'] > 0 && $file['error'] == 0) {
         $ext = strtolower(Filesystem::extension($file['name']));
         if (!in_array($ext, array('csv', 'xml'))) {
             $this->setError(Lang::txt('COM_RESOURCES_IMPORT_UNSUPPORTED_FILE_TYPE'));
             return $this->editTask();
         }
         if (!is_dir($this->import->fileSpacePath())) {
             Filesystem::makeDirectory($this->import->fileSpacePath());
         }
         move_uploaded_file($file['tmp_name'], $this->import->fileSpacePath() . DS . $file['name']);
         $this->import->set('file', $file['name']);
     }
     // do we have a data file
     if ($this->import->get('file')) {
         // get record count
         $importImporter = new Importer();
         $count = $importImporter->count($this->import);
         $this->import->set('count', $count);
     }
     // save again with import count
     if (!$this->import->store(true)) {
         $this->setError($this->import->getError());
         return $this->editTask();
     }
     //inform user & redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=display', false), Lang::txt('COM_RESOURCES_IMPORT_CREATED'), 'passed');
 }
Esempio n. 16
0
 /**
  * Generate a link to a file
  * If $file starts with (http|https|mailto|ftp|gopher|feed|news|file), then it's an external URL and returned
  *
  * @param      $file  Filename
  * @return     string
  */
 private function _link($file)
 {
     $urlPtrn = "[^=\"\\'](https?:|mailto:|ftp:|gopher:|feed:|news:|file:)" . "([^ |\\/\"\\']*\\/)*([^ |\\t\\n\\/\"\\']*[A-Za-z0-9\\/?=&~_])";
     if (preg_match("/{$urlPtrn}/", $file) || substr($file, 0, 1) == DS) {
         return $file;
     }
     $file = trim($file, DS);
     $link = DS . substr($this->option, 4, strlen($this->option)) . DS;
     if ($this->scope) {
         $scope = trim($this->scope, DS);
         $link .= $scope . DS;
     }
     $type = 'File';
     $this->imgs = array('jpg', 'jpe', 'jpeg', 'gif', 'png');
     if (in_array(strtolower(Filesystem::extension($file)), $this->imgs)) {
         if (Request::getVar('format') == 'pdf') {
             return $this->_path($file);
         }
         $type = 'Image';
     }
     $link .= $this->pagename . DS . $type . ':' . $file;
     return Route::url($link);
 }
Esempio n. 17
0
/**
 * @package		Joomla.Administrator
 * @subpackage	com_media
 * @copyright	Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access.
defined('_HZEXEC_') or die;
$params = new \Hubzero\Config\Registry();
Event::trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_doc, &$params));
?>
		<div class="imgOutline">
			<div class="imgTotal">
				<div class="imgBorder">
					<a class="doc-item <?php 
echo Filesystem::extension($this->_tmp_doc->name);
?>
" title="<?php 
echo $this->_tmp_doc->name;
?>
" >
						<?php 
echo $this->_tmp_doc->title;
?>
					</a>
				</div>
			</div>
			<div class="controls">
			<?php 
if (User::authorise('core.delete', 'com_media')) {
    ?>
Esempio n. 18
0
						<?php 
                foreach ($comment->attachments() as $attachment) {
                    if (!trim($attachment->get('description'))) {
                        $attachment->set('description', $attachment->get('filename'));
                    }
                    if ($attachment->isImage()) {
                        if ($attachment->width() > 400) {
                            $img = '<p><a href="' . Route::url($attachment->link()) . '"><img src="' . Route::url($attachment->link()) . '" alt="' . $attachment->get('description') . '" width="400" /></a></p>';
                        } else {
                            $img = '<p><img src="' . Route::url($attachment->link()) . '" alt="' . $attachment->get('description') . '" /></p>';
                        }
                        echo $img;
                    } else {
                        ?>
								<a class="attachment <?php 
                        echo Filesystem::extension($attachment->get('filename'));
                        ?>
" href="<?php 
                        echo Route::url($attachment->link());
                        ?>
" title="<?php 
                        echo $attachment->get('description');
                        ?>
">
									<p class="attachment-description"><?php 
                        echo $attachment->get('description');
                        ?>
</p>
									<p class="attachment-meta">
										<span class="attachment-size"><?php 
                        echo Hubzero\Utility\Number::formatBytes($attachment->size());
Esempio n. 19
0
 /**
  * Checks if the file can be uploaded
  *
  * @param array File information
  * @param string An error message to be returned
  * @return  boolean
  */
 public static function canUpload($file, &$err)
 {
     $params = Component::params('com_media');
     if (empty($file['name'])) {
         $err = 'COM_MEDIA_ERROR_UPLOAD_INPUT';
         return false;
     }
     if ($file['name'] !== Filesystem::clean($file['name'])) {
         $err = 'COM_MEDIA_ERROR_WARNFILENAME';
         return false;
     }
     $format = strtolower(Filesystem::extension($file['name']));
     // Media file names should never have executable extensions buried in them.
     $executable = array('php', 'js', 'exe', 'phtml', 'java', 'perl', 'py', 'asp', 'dll', 'go', 'ade', 'adp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'hta', 'ins', 'isp', 'jse', 'lib', 'mde', 'msc', 'msp', 'mst', 'pif', 'scr', 'sct', 'shb', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh');
     $explodedFileName = explode('.', $file['name']);
     if (count($explodedFileName > 2)) {
         foreach ($executable as $extensionName) {
             if (in_array($extensionName, $explodedFileName)) {
                 $app->enqueueMessage(Lang::txt('JLIB_MEDIA_ERROR_WARNFILETYPE'), 'notice');
                 return false;
             }
         }
     }
     $allowable = explode(',', $params->get('upload_extensions'));
     $ignored = explode(',', $params->get('ignore_extensions'));
     if ($format == '' || $format == false || !in_array($format, $allowable) && !in_array($format, $ignored)) {
         $err = 'COM_MEDIA_ERROR_WARNFILETYPE';
         return false;
     }
     $maxSize = (int) ($params->get('upload_maxsize', 0) * 1024 * 1024);
     if ($maxSize > 0 && (int) $file['size'] > $maxSize) {
         $err = 'COM_MEDIA_ERROR_WARNFILETOOLARGE';
         return false;
     }
     $imginfo = null;
     if ($params->get('restrict_uploads', 1)) {
         $images = explode(',', $params->get('image_extensions'));
         if (in_array($format, $images)) {
             // if its an image run it through getimagesize
             // if tmp_name is empty, then the file was bigger than the PHP limit
             if (!empty($file['tmp_name'])) {
                 if (($imginfo = getimagesize($file['tmp_name'])) === FALSE) {
                     $err = 'COM_MEDIA_ERROR_WARNINVALID_IMG';
                     return false;
                 }
             } else {
                 $err = 'COM_MEDIA_ERROR_WARNFILETOOLARGE';
                 return false;
             }
         } elseif (!in_array($format, $ignored)) {
             // if its not an image...and we're not ignoring it
             $allowed_mime = explode(',', $params->get('upload_mime'));
             $illegal_mime = explode(',', $params->get('upload_mime_illegal'));
             if (function_exists('finfo_open') && $params->get('check_mime', 1)) {
                 // We have fileinfo
                 $finfo = finfo_open(FILEINFO_MIME);
                 $type = finfo_file($finfo, $file['tmp_name']);
                 if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
                     $err = 'COM_MEDIA_ERROR_WARNINVALID_MIME';
                     return false;
                 }
                 finfo_close($finfo);
             } elseif (function_exists('mime_content_type') && $params->get('check_mime', 1)) {
                 // we have mime magic
                 $type = mime_content_type($file['tmp_name']);
                 if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
                     $err = 'COM_MEDIA_ERROR_WARNINVALID_MIME';
                     return false;
                 }
             } elseif (!User::authorise('core.manage')) {
                 $err = 'COM_MEDIA_ERROR_WARNNOTADMIN';
                 return false;
             }
         }
     }
     $xss_check = Filesystem::read($file['tmp_name'], false, 256);
     $html_tags = array('abbr', 'acronym', 'address', 'applet', 'area', 'audioscope', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blackface', 'blink', 'blockquote', 'body', 'bq', 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'comment', 'custom', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'fn', 'font', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'iframe', 'ilayer', 'img', 'input', 'ins', 'isindex', 'keygen', 'kbd', 'label', 'layer', 'legend', 'li', 'limittext', 'link', 'listing', 'map', 'marquee', 'menu', 'meta', 'multicol', 'nobr', 'noembed', 'noframes', 'noscript', 'nosmartquotes', 'object', 'ol', 'optgroup', 'option', 'param', 'plaintext', 'pre', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'server', 'shadow', 'sidebar', 'small', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var', 'wbr', 'xml', 'xmp', '!DOCTYPE', '!--');
     foreach ($html_tags as $tag) {
         // A tag is '<tagname ', so we need to add < and a space or '<tagname>'
         if (stristr($xss_check, '<' . $tag . ' ') || stristr($xss_check, '<' . $tag . '>')) {
             $err = 'COM_MEDIA_ERROR_WARNIEXSS';
             return false;
         }
     }
     return true;
 }
Esempio n. 20
0
}
if (count($this->docs) == 0) {
    ?>
			<p><?php 
    echo Lang::txt('COM_WIKI_ERROR_NO_FILES_FOUND');
    ?>
</p>
<?php 
} else {
    ?>
			<table>
				<tbody>
				<?php 
    if ($this->docs) {
        foreach ($this->docs as $path => $name) {
            $ext = Filesystem::extension($name);
            ?>
					<tr>
						<td>
							<span><?php 
            echo $this->escape(stripslashes($name));
            ?>
</span>
						</td>
						<td>
							<a class="icon-delete delete" href="<?php 
            echo $base;
            ?>
/index.php?option=<?php 
            echo $this->option;
            ?>
Esempio n. 21
0
 /**
  * Get remote folder changes
  *
  * @param	   array		$items			Remote items
  * @param	   string		$folderID		Folder ID
  * @param	   array		&$remotes		Collector array for active items
  * @param	   array		&$deletes		Collector array for deleted items
  * @param	   string		$path			Path
  * @param	   array		$connections	Array of local-remote connections
  * @param	   array		&$duplicates	Collector array for duplicates
  *
  * @return	 void
  */
 public static function getFolderChange($items, $folderID = 0, &$remotes, &$deletes, $path = '', $connections, &$duplicates)
 {
     $lpath = $path ? $path : '';
     $conIds = $connections['ids'];
     $conPaths = $connections['paths'];
     // Get all changes in a folder
     foreach ($items as $item) {
         if ($item['deleted'] && $item['fileId']) {
             $deletes[] = $item['fileId'];
         } elseif (!$item['deleted'] && $item['file']) {
             $doc = $item['file'];
             if ($doc['kind'] != 'drive#file') {
                 continue;
             }
             if (empty($doc['parents'])) {
                 continue;
             }
             foreach ($doc['parents'] as $parent) {
                 if ($parent['id'] != $folderID) {
                     continue;
                 }
                 $status = $doc['labels']['trashed'] ? 'D' : 'A';
                 $converted = preg_match("/google-apps/", $doc['mimeType']) && !preg_match("/.folder/", $doc['mimeType']) ? 1 : 0;
                 $url = isset($doc['downloadUrl']) ? $doc['downloadUrl'] : '';
                 $original = isset($doc['originalFilename']) ? $doc['originalFilename'] : '';
                 $time = strtotime($doc['modifiedDate']);
                 $thumb = isset($doc['thumbnailLink']) ? $doc['thumbnailLink'] : NULL;
                 $author = isset($doc['lastModifyingUserName']) ? utf8_encode($doc['lastModifyingUserName']) : utf8_encode($doc['ownerNames'][0]);
                 if (!preg_match("/.folder/", $doc['mimeType'])) {
                     $title = Filesystem::clean($doc['title']);
                     // Get file extention
                     $ext = Filesystem::extension($title);
                     if ($converted) {
                         $g_ext = self::getGoogleConversionFormat($doc['mimeType'], false, true);
                         if ($g_ext && $ext != $g_ext) {
                             $title = $title . '.' . $g_ext;
                         }
                     }
                     $type = 'file';
                 } else {
                     $title = Filesystem::cleanPath($doc['title']);
                     $type = 'folder';
                 }
                 $fpath = $lpath ? $lpath . DS . $title : $title;
                 $synced = isset($conIds[$doc['id']]) ? $conIds[$doc['id']]['synced'] : NULL;
                 $md5Checksum = isset($doc['md5Checksum']) ? $doc['md5Checksum'] : NULL;
                 $fileSize = isset($doc['fileSize']) ? $doc['fileSize'] : NULL;
                 // Make sure path is not already used (Google allows files with same name in same dir, Git doesn't)
                 $fpath = self::buildDuplicatePath($doc['id'], $fpath, $doc['mimeType'], $connections, $remotes, $duplicates);
                 // Detect a rename or move
                 $rename = '';
                 if (isset($conIds[$doc['id']])) {
                     $oFilePath = $conIds[$doc['id']]['path'];
                     $oDirPath = $conIds[$doc['id']]['dirpath'];
                     $nDirPath = dirname($fpath) == '.' ? '' : dirname($fpath);
                     $nFilePath = $fpath;
                     if ($oDirPath != $nDirPath && $oFilePath != $nFilePath) {
                         $status = 'W';
                         $rename = $oFilePath;
                     } elseif ($oFilePath != $nFilePath) {
                         $status = 'R';
                         $rename = $oFilePath;
                     }
                 }
                 $remotes[$fpath] = array('status' => $status, 'time' => $time, 'modified' => gmdate('Y-m-d H:i:s', $time), 'type' => $type, 'local_path' => $fpath, 'remoteid' => $doc['id'], 'title' => $doc['title'], 'converted' => $converted, 'rParent' => self::getParentID($doc['parents']), 'url' => $url, 'original' => $original, 'author' => $author, 'synced' => $synced, 'md5' => $md5Checksum, 'mimeType' => $doc['mimeType'], 'thumb' => $thumb, 'rename' => $rename, 'fileSize' => $fileSize);
                 if (preg_match("/.folder/", $doc['mimeType'])) {
                     // Recurse
                     self::getFolderChange($items, $doc['id'], $remotes, $deletes, $fpath, $connections, $duplicates);
                 }
             }
         }
     }
 }
Esempio n. 22
0
 /**
  * Generate macro output based on passed arguments
  *
  * @return     string HTML image tag on success or error message on failure
  */
 public function render()
 {
     $content = $this->args;
     // args will be null if the macro is called without parenthesis.
     if (!$content) {
         return '';
     }
     // Parse arguments
     // We expect the 1st argument to be a filename
     $args = explode(',', $content);
     $file = array_shift($args);
     $this->attr = array();
     $this->attr['href'] = '';
     $this->attr['style'] = array();
     // Get single attributes
     // EX: [[Image(myimage.png, nolink, right)]]
     $argues = preg_replace_callback('/[, ](left|right|top|center|bottom|[0-9]+(px|%|em)?)(?:[, ]|$)/i', array(&$this, 'parseSingleAttribute'), $content);
     // Get quoted attribute/value pairs
     // EX: [[Image(myimage.png, desc="My description, contains, commas")]]
     $argues = preg_replace_callback('/[, ](alt|altimage|desc|title|width|height|align|border|longdesc|class|id|usemap|link)=(?:["\'])([^"]*)(?:["\'])/i', array(&$this, 'parseAttributeValuePair'), $content);
     // Get non-quoted attribute/value pairs
     // EX: [[Image(myimage.png, width=100)]]
     $argues = preg_replace_callback('/[, ](alt|altimage|desc|title|width|height|align|border|longdesc|class|id|usemap|link)=([^"\',]*)(?:[, ]|$)/i', array(&$this, 'parseAttributeValuePair'), $content);
     $attr = $this->attr;
     // Get wiki config
     $this->config = Component::params('com_wiki');
     if ($this->filepath != '') {
         $this->config->set('filepath', $this->filepath);
     }
     $imgs = explode(',', $this->config->get('img_ext', 'jpg, jpeg, jpe, gif, png'));
     $imgs = array_map('trim', $imgs);
     $imgs = array_map('strtolower', $imgs);
     $this->imgs = $imgs;
     $ret = false;
     // Is it numeric?
     if (is_numeric($file)) {
         // Get resource by ID
         $attach = \Components\Wiki\Models\Attachment::oneOrNew(intval($file));
         // Check for file existence
         if ($attach->get('filename') && file_exists($this->_path($attach->get('filename'))) || file_exists($this->_path($attach->get('filename'), true))) {
             $attr['desc'] = isset($attr['desc']) ? $attr['desc'] : '';
             if (!$attr['desc']) {
                 $attr['desc'] = $attach->get('description', '');
             }
             $ret = true;
         }
     } else {
         if (preg_match("/^(https?:|mailto:|ftp:|gopher:|news:|file:)/", $file)) {
             $attr['desc'] = $file;
             $ret = true;
         } else {
             if (file_exists($this->_path($file)) || file_exists($this->_path($file, true))) {
                 $attr['desc'] = isset($attr['desc']) ? $attr['desc'] : '';
                 $ret = true;
             }
         }
     }
     // Does the file exist?
     if ($ret) {
         if (!in_array(strtolower(Filesystem::extension($file)), $this->imgs)) {
             return '(Image(' . $content . ') failed - File provided is not an allowed image type)';
         }
         // Return HTML
         return $this->_embed($file, $attr);
     }
     // Return error message
     return '(Image(' . $content . ') failed - File not found)';
 }
Esempio n. 23
0
			</div>
			<div class="comment-attachments">
				<?php 
foreach ($this->comment->attachments()->whereEquals('state', Components\Forum\Models\Attachment::STATE_PUBLISHED)->rows() as $attachment) {
    if (!trim($attachment->get('description'))) {
        $attachment->set('description', $attachment->get('filename'));
    }
    $link = $this->comment->link() . '/' . $attachment->get('post_id') . '/' . $attachment->get('filename');
    if ($attachment->isImage()) {
        if ($attachment->width() > 400) {
            $html = '<p><a href="' . Route::url($link) . '"><img src="' . Route::url($link) . '" alt="' . $this->escape($attachment->get('description')) . '" width="400" /></a></p>';
        } else {
            $html = '<p><img src="' . Route::url($link) . '" alt="' . $this->escape($attachment->get('description')) . '" /></p>';
        }
    } else {
        $html = '<a class="attachment ' . Filesystem::extension($attachment->get('filename')) . '" href="' . Route::url($link) . '" title="' . $this->escape($attachment->get('description')) . '">';
        $html .= '<p class="attachment-description">' . $attachment->get('description') . '</p>';
        $html .= '<p class="attachment-meta">';
        $html .= '<span class="attachment-size">' . Hubzero\Utility\Number::formatBytes($attachment->size()) . '</span>';
        $html .= '<span class="attachment-action">' . Lang::txt('Click to download') . '</span>';
        $html .= '</p>';
        $html .= '</a>';
    }
    echo $html;
}
?>
			</div><!-- / .comment-attachments -->
			<p class="comment-options">
			<?php 
if ($this->config->get('access-manage-thread') || $this->config->get('access-delete-thread') || $this->config->get('access-edit-thread') || $this->config->get('access-delete-post') || $this->config->get('access-edit-post')) {
    ?>
Esempio n. 24
0
							</a>
						</td>
					</tr>
				<?php 
    }
    ?>
				<?php 
    foreach ($this->docs as $k => $doc) {
        ?>
					<tr>
						<td width="100%">
							<a download target="_blank" href="<?php 
        echo Route::url('index.php?option=' . $this->option . '&controller=' . $this->controller . '&gidNumber=' . $this->group->get('gidNumber') . '&task=download&file=' . urlencode(substr($k, strlen(PATH_ROOT))) . '&' . Session::getFormToken() . '=1');
        ?>
" class="icon-file file <?php 
        echo Filesystem::extension($doc);
        ?>
">
								<?php 
        $k = substr($k, strlen($this->path));
        echo $this->escape(trim($k, DS));
        ?>
							</a>
						</td>
						<td>
							<a class="icon-delete delete" href="<?php 
        echo Route::url('index.php?option=' . $this->option . '&controller=' . $this->controller . '&task=deletefile&file=' . urlencode($k) . '&gidNumber=' . $this->group->get('gidNumber') . '&tmpl=component&' . Session::getFormToken() . '=1');
        ?>
" target="media" onclick="return deleteFile('<?php 
        echo basename($doc);
        ?>
Esempio n. 25
0
 /**
  * Upload a resume
  *
  * @param   object  $database  Database
  * @param   string  $option    Component name
  * @param   object  $member    Profile
  * @return  string
  */
 protected function _upload($database, $option, $member)
 {
     $path = $this->build_path($member->get('id'));
     $emp = Request::getInt('emp', 0);
     if (!$path) {
         $this->setError(Lang::txt('PLG_MEMBERS_RESUME_SUPPORT_NO_UPLOAD_DIRECTORY'));
         return $this->_view($database, $option, $member, $emp);
     }
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming file
     $file = Request::getVar('uploadres', '', 'files', 'array');
     if (!$file['name']) {
         $this->setError(Lang::txt('PLG_MEMBERS_RESUME_SUPPORT_NO_FILE'));
         return $this->_view($database, $option, $member, $emp);
     }
     // Incoming
     $title = Request::getVar('title', '');
     $default_title = $member->get('firstname') ? $member->get('firstname') . ' ' . $member->get('lastname') . ' ' . ucfirst(Lang::txt('PLG_MEMBERS_RESUME_RESUME')) : $member->get('name') . ' ' . ucfirst(Lang::txt('PLG_MEMBERS_RESUME_RESUME'));
     $path = PATH_APP . $path;
     // Replace file title with user name
     $file_ext = substr($file['name'], strripos($file['name'], '.'));
     $file['name'] = $member->get('firstname') ? $member->get('firstname') . ' ' . $member->get('lastname') . ' ' . ucfirst(Lang::txt('PLG_MEMBERS_RESUME_RESUME')) : $member->get('name') . ' ' . ucfirst(Lang::txt('PLG_MEMBERS_RESUME_RESUME'));
     $file['name'] .= $file_ext;
     // Make the filename safe
     $file['name'] = Filesystem::clean($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     $ext = strtolower(Filesystem::extension($file['name']));
     if (!in_array($ext, explode(',', $this->params->get('file_ext', 'jpg,jpeg,jpe,bmp,tif,tiff,png,gif,pdf,txt,rtf,doc,docx,ppt')))) {
         $this->setError(Lang::txt('Disallowed file type.'));
         return $this->_view($database, $option, $member, $emp);
     }
     $row = new \Components\Jobs\Tables\Resume($database);
     if (!$row->loadResume($member->get('id'))) {
         $row = new \Components\Jobs\Tables\Resume($database);
         $row->id = 0;
         $row->uid = $member->get('id');
         $row->main = 1;
     } else {
         if (file_exists($path . DS . $row->filename)) {
             Filesystem::delete($path . DS . $row->filename);
             // Remove stats for prev resume
             $jobstats = new \Components\Jobs\Tables\JobStats($database);
             $jobstats->deleteStats($member->get('id'), 'seeker');
         }
     }
     // Perform the upload
     if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('ERROR_UPLOADING'));
     } else {
         $fpath = $path . DS . $file['name'];
         if (!Filesystem::isSafe($fpath)) {
             Filesystem::delete($fpath);
             $this->setError(Lang::txt('File rejected because the anti-virus scan failed.'));
             return $this->_view($database, $option, $member, $emp);
         }
         // File was uploaded, create database entry
         $title = htmlspecialchars($title);
         $row->created = Date::toSql();
         $row->filename = $file['name'];
         $row->title = $title ? $title : $default_title;
         if (!$row->check()) {
             $this->setError($row->getError());
         }
         if (!$row->store()) {
             $this->setError($row->getError());
         }
     }
     return $this->_view($database, $option, $member, $emp);
 }
Esempio n. 26
0
 /**
  * Get the resource child type from the file extension
  *
  * @param      string $filename File to check
  * @return     integer Numerical file type
  */
 private function _getChildType($filename)
 {
     $ftype = strtolower(Filesystem::extension($filename));
     switch ($ftype) {
         case 'mov':
             $type = 15;
             break;
         case 'swf':
             $type = 32;
             break;
         case 'ppt':
             $type = 35;
             break;
         case 'asf':
             $type = 37;
             break;
         case 'asx':
             $type = 37;
             break;
         case 'wmv':
             $type = 37;
             break;
         case 'zip':
             $type = 38;
             break;
         case 'tar':
             $type = 38;
             break;
         case 'pdf':
             $type = 33;
             break;
         default:
             $type = 13;
             break;
     }
     return $type;
 }
Esempio n. 27
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;
 }
Esempio n. 28
0
        ?>
</time>
					</td>
					<td>
						<a href="<?php 
        echo Route::url('index.php?option=' . $this->option . '&scope=' . $row->scope . '/' . $row->pagename . '/File:' . $row->filename);
        ?>
">
							<?php 
        echo $this->escape(stripslashes($row->filename));
        ?>
						</a>
					</td>
					<td>
						<?php 
        if (in_array(strtolower(Filesystem::extension($row->filename)), array('png', 'gif', 'jpg', 'jpeg', 'jpe'))) {
            ?>
						<a rel="lightbox" href="<?php 
            echo Route::url('index.php?option=' . $this->option . '&scope=' . $row->scope . '/' . $row->pagename . '/File:' . $row->filename);
            ?>
">
							<img src="<?php 
            echo Route::url('index.php?option=' . $this->option . '&scope=' . $row->scope . '/' . $row->pagename . '/File:' . $row->filename);
            ?>
" width="50" alt="<?php 
            echo $this->escape(stripslashes($row->filename));
            ?>
" />
						</a>
						<?php 
        }
Esempio n. 29
0
// File path
$path = $this->model->path($this->course->get('id'));
// Ensure we have a path
if (empty($path)) {
    App::abort(404, Lang::txt('COM_COURSES_FILE_NOT_FOUND'));
    return;
}
// Add PATH_APP
$filename = PATH_APP . $path;
// Ensure the file exist
if (!file_exists($filename)) {
    App::abort(404, Lang::txt('COM_COURSES_FILE_NOT_FOUND') . ' ' . $filename);
    return;
}
// Force certain extensions to the 'attachment' disposition
$ext = strtolower(Filesystem::extension($filename));
if (!in_array($ext, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'pdf', 'htm', 'html', 'txt', 'json', 'xml'))) {
    $d = 'attachment';
}
// Initiate a new content server and serve up the file
$xserver = new \Hubzero\Content\Server();
$xserver->filename($filename);
//$xserver->saveas($this->model->get('title') . '.' . $ext);
$xserver->disposition($d);
$xserver->acceptranges(false);
// @TODO fix byte range support
if (!$xserver->serve()) {
    // Should only get here on error
    App::abort(500, Lang::txt('COM_COURSES_SERVER_ERROR'));
} else {
    // Just exit (i.e. no template)
Esempio n. 30
0
 /**
  * Clean out old system CSS files
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function cleanSystemCss(\Components\Cron\Models\Job $job)
 {
     if (!is_dir($this->_path)) {
         return;
     }
     $docs = array();
     $dirIterator = new DirectoryIterator($this->_path);
     foreach ($dirIterator as $file) {
         if ($file->isDot() || $file->isDir()) {
             continue;
         }
         if ($file->isFile()) {
             $name = $file->getFilename();
             $ext = Filesystem::extension($name);
             if ('cvs' == strtolower($name) || '.svn' == strtolower($name) || $ext != 'css') {
                 continue;
             }
             if (substr($name, 0, strlen('system-')) != 'system-') {
                 continue;
             }
             $docs[$this->_path . DS . $name] = $name;
         }
     }
     if (count($docs) > 1) {
         foreach ($docs as $p => $n) {
             Filesystem::delete($p);
         }
     }
     return true;
 }