/**
  * Generate macro output
  *
  * @return     string
  */
 public function render()
 {
     $et = $this->args;
     $live_site = rtrim(\Request::base(), '/');
     // What pages are we getting?
     if ($et) {
         $et = strip_tags($et);
         // Get pages with a prefix
         $sql = "SELECT * FROM `#__wiki_attachments` WHERE LOWER(filename) LIKE " . $this->_db->quote(strtolower($et) . '%') . " AND pageid=" . $this->_db->quote($this->pageid) . " ORDER BY created ASC";
     } else {
         // Get all pages
         $sql = "SELECT * FROM `#__wiki_attachments` WHERE pageid=" . $this->_db->quote($this->pageid) . " ORDER BY created ASC";
     }
     // Perform query
     $this->_db->setQuery($sql);
     $rows = $this->_db->loadObjectList();
     // Did we get a result from the database?
     if ($rows) {
         $config = Component::params('com_wiki');
         if ($this->filepath != '') {
             $config->set('filepath', $this->filepath);
         }
         // Build and return the link
         $html = '<ul>';
         foreach ($rows as $row) {
             $link = $live_site . DS . trim($config->get('filepath', '/site/wiki'), DS) . DS . $this->pageid . DS . $row->filename;
             $fpath = PATH_APP . DS . trim($config->get('filepath', '/site/wiki'), DS) . DS . $this->pageid . DS . $row->filename;
             $html .= '<li><a href="' . \Route::url($link) . '">' . $row->filename . '</a> (' . (file_exists($fpath) ? \Hubzero\Utility\Number::formatBytes(filesize($fpath)) : '-- file not found --') . ') ';
             $huser = \User::getInstance($row->created_by);
             if ($huser->get('id')) {
                 $html .= '- added by <a href="' . \Route::url('index.php?option=com_members&id=' . $huser->get('id')) . '">' . stripslashes($huser->get('name')) . '</a> ';
             }
             if ($row->created && $row->created != '0000-00-00 00:00:00') {
                 $html .= \Date::of($row->created)->relative() . '. ';
             }
             $html .= $row->description ? '<span>"' . stripslashes($row->description) . '"</span>' : '';
             $html .= '</li>' . "\n";
         }
         $html .= '</ul>';
         return $html;
     } else {
         // Return error message
         //return '(TitleIndex('.$et.') failed)';
         return '(No ' . $et . ' files to display)';
     }
 }
Exemple #2
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $et = $this->args;
     $live_site = rtrim(Request::base(), '/');
     // Get resource by ID
     $attach = \Components\Wiki\Models\Attachment::all()->whereEquals('page_id', $this->pageid);
     if ($et) {
         $et = strip_tags($et);
         $attach->whereLike('filename', strtolower($et) . '%');
     }
     $rows = $attach->rows();
     // Did we get a result from the database?
     if ($rows) {
         $config = Component::params('com_wiki');
         if ($this->filepath != '') {
             $config->set('filepath', $this->filepath);
         }
         $page = \Components\Wiki\Models\Page::oneOrFail($this->pageid);
         if ($page->get('namespace') == 'help') {
             $page->set('path', $page->get('path') ? rtrim($this->scope, '/') . '/' . ltrim($page->get('path'), '/') : $this->scope);
         }
         // Build and return the link
         $html = '<ul>';
         foreach ($rows as $row) {
             $page->set('pagename', $page->get('pagename') . '/' . 'File:' . $row->get('filename'));
             $link = $page->link();
             $fpath = $row->filespace() . DS . $this->pageid . DS . $row->get('filename');
             $html .= '<li><a href="' . Route::url($link) . '">' . $row->get('filename') . '</a> (' . (file_exists($fpath) ? \Hubzero\Utility\Number::formatBytes(filesize($fpath)) : '-- file not found --') . ') ';
             $huser = $row->creator();
             if ($huser->get('id')) {
                 $html .= '- added by <a href="' . Route::url('index.php?option=com_members&id=' . $huser->get('id')) . '">' . stripslashes($huser->get('name')) . '</a> ';
             }
             if ($row->get('created') && $row->get('created') != '0000-00-00 00:00:00') {
                 $html .= Date::of($row->get('created'))->relative() . '. ';
             }
             $html .= $row->get('description') ? '<span>"' . stripslashes($row->get('description')) . '"</span>' : '';
             $html .= '</li>' . "\n";
         }
         $html .= '</ul>';
         return $html;
     }
     // Return error message
     return '(No ' . $et . ' files to display)';
 }
Exemple #3
0
}
?>
 <?php 
echo Lang::txt('COM_WIKI_COL_DESCRIPTION');
?>
						</a>
					</th>
				</tr>
			</thead>
			<tbody>
			<?php 
if ($rows->count()) {
    foreach ($rows as $row) {
        $fsize = Lang::txt('COM_WIKI_UNKNOWN');
        if (is_file($row->filespace() . DS . $row->get('page_id') . DS . $row->get('filename'))) {
            $fsize = \Hubzero\Utility\Number::formatBytes(filesize($row->filespace() . DS . $row->get('page_id') . DS . $row->get('filename')));
        }
        $name = $this->escape(stripslashes($row->creator->get('name', Lang::txt('COM_WIKI_UNKNOWN'))));
        if (in_array($row->creator->get('access'), User::getAuthorisedViewLevels())) {
            $name = '<a href="' . Route::url($row->creator->link()) . '">' . $name . '</a>';
        }
        ?>
					<tr>
						<td>
							<time datetime="<?php 
        echo $row->get('created');
        ?>
"><?php 
        echo $row->get('created');
        ?>
</time>
Exemple #4
0
 /**
  * Display memory usage
  *
  * @return  string
  */
 protected function displayMemoryUsage()
 {
     $bytes = App::get('profiler')->memory();
     return \Hubzero\Utility\Number::formatBytes($bytes);
 }
Exemple #5
0
 /**
  * Streaming file upload
  * This is used by AJAX
  *
  * @return  void
  */
 public function ajaxuploadTask()
 {
     Request::checkToken(['get', 'post']);
     //get config
     $config = Component::params('com_media');
     //allowed extensions for uplaod
     $allowedExtensions = array_values(array_filter(explode(',', $config->get('upload_extensions'))));
     // if super group allow archives
     if ($this->group->get('type') == 3) {
         $allowedExtensions[] = 'zip';
         $allowedExtensions[] = 'tar';
         $allowedExtensions[] = 'gz';
     }
     //max upload size
     $sizeLimit = $config->get('upload_maxsize');
     $sizeLimit = $sizeLimit * 1024 * 1024;
     //get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         return;
     }
     //get folder
     $folder = Request::getVar('folder', '');
     // make sure we have an active folder
     if ($folder == '') {
         $folder = '/uploads';
     }
     // regular groups can only access inside /uploads
     if ($this->group->get('type') != 3) {
         $pathInfo = pathinfo($folder);
         if ($pathInfo['dirname'] != '/uploads') {
             $folder = '/uploads';
         }
     }
     // Build the upload path if it doesn't exist
     $uploadDirectory = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/groups'), DS) . DS . $this->group->get('gidNumber') . DS . ltrim($folder, DS);
     //make sure upload directory is writable
     if (!is_dir($uploadDirectory)) {
         if (!Filesystem::makeDirectory($uploadDirectory)) {
             echo json_encode(array('error' => Lang::txt('COM_GROUPS_MEDIA_UNABLE_TO_CREATE_UPLOAD_PATH')));
             return;
         }
     }
     if (!is_writable($uploadDirectory)) {
         echo json_encode(array('error' => Lang::txt('COM_GROUPS_MEDIA_PATH_NOT_WRITABLE')));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('COM_GROUPS_MEDIA_FILE_EMPTY')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('COM_GROUPS_MEDIA_FILE_TOO_BIG', $max)));
         return;
     }
     //check to make sure we have an allowable extension
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     $ext = $pathinfo['extension'];
     if ($allowedExtensions && !in_array(strtolower($ext), $allowedExtensions)) {
         $these = implode(', ', $allowedExtensions);
         echo json_encode(array('error' => Lang::txt('COM_GROUPS_MEDIA_INVALID_FILE', $these)));
         return;
     }
     // clean file path
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     while (file_exists($uploadDirectory . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     //final file
     $file = $uploadDirectory . DS . $filename . '.' . $ext;
     //save file
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     // change file perm
     chmod($file, 0774);
     //scan file for virus if we have enabled scans
     if ($this->config->get('scan_uploads', 1)) {
         //run scan on file
         //scan failed
         if (!Filesystem::isSafe($file)) {
             //delete file
             unlink($file);
             //inform user
             echo json_encode(array('error' => Lang::txt('COM_GROUPS_MEDIA_FILE_CONTAINS_VIRUS')));
             return;
         }
     }
     //return success
     echo json_encode(array('success' => true));
     return;
 }
Exemple #6
0
 /**
  * Set file size
  *
  * @return  mixed
  */
 public function setSize($size = NULL)
 {
     if (intval($size) > 0) {
         $this->set('size', $size);
     }
     if ($this->get('size')) {
         // Already set
         return $this->get('size');
     }
     // Get size for local
     if ($this->exists()) {
         $this->set('size', Filesystem::size($this->get('fullPath')));
     }
     // Formatted size
     if ($this->get('size')) {
         $this->set('formattedSize', \Hubzero\Utility\Number::formatBytes($this->get('size')));
     }
     return $this->get('size');
 }
Exemple #7
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return  string
  */
 public function ajaxUploadTask()
 {
     // Check for request forgeries
     Request::checkToken(['post', 'get']);
     // Ensure we have an ID to work with
     $listdir = Request::getVar('listdir', 0);
     if (!$listdir) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_NO_ID')));
         return;
     }
     // Incoming sub-directory
     $subdir = Request::getVar('subdir', '');
     // Build the path
     $path = $this->_buildUploadPath($listdir, $subdir);
     //allowed extensions for uplaod
     //$allowedExtensions = array("png","jpeg","jpg","gif");
     //max upload size
     $sizeLimit = $this->config->get('maxAllowed', 40000000);
     // get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_FILE_NOT_FOUND')));
         return;
     }
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH')));
             return;
         }
     }
     if (!is_writable($path)) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_UPLOAD_DIRECTORY_IS_NOT_WRITABLE')));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_EMPTY_FILE')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_FILE_TOO_LARGE', $max)));
         return;
     }
     // don't overwrite previous files that were uploaded
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     // Make the filename safe
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     $ext = $pathinfo['extension'];
     while (file_exists($path . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     $file = $path . DS . $filename . '.' . $ext;
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     if (!Filesystem::isSafe($file)) {
         Filesystem::delete($file);
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_FILE_UNSAFE')));
         return;
     }
     //echo result
     echo json_encode(array('success' => true, 'file' => $filename . '.' . $ext, 'directory' => str_replace(PATH_APP, '', $path), 'id' => $listdir));
 }
Exemple #8
0
 /**
  * Streaking file upload
  * This is used by AJAX
  *
  * @return     void
  */
 private function ajaxuploadTask()
 {
     // get config
     $config = Component::params('com_media');
     // Incoming
     $listdir = Request::getInt('listdir', 0);
     // allowed extensions for uplaod
     $allowedExtensions = array_values(array_filter(explode(',', $config->get('upload_extensions'))));
     // max upload size
     $sizeLimit = $config->get('upload_maxsize');
     $sizeLimit = $sizeLimit * 1024 * 1024;
     // get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         return;
     }
     // Build the upload path if it doesn't exist
     $uploadDirectory = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/courses'), DS) . DS . $listdir . DS;
     //make sure upload directory is writable
     if (!is_dir($uploadDirectory)) {
         if (!Filesystem::makeDirectory($uploadDirectory)) {
             echo json_encode(array('error' => "Server error. Unable to create upload directory."));
             return;
         }
     }
     if (!is_writable($uploadDirectory)) {
         echo json_encode(array('error' => "Server error. Upload directory isn't writable."));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => 'File is empty'));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => 'File is too large. Max file upload size is ' . $max));
         return;
     }
     //check to make sure we have an allowable extension
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     $ext = $pathinfo['extension'];
     if ($allowedExtensions && !in_array(strtolower($ext), $allowedExtensions)) {
         $these = implode(', ', $allowedExtensions);
         echo json_encode(array('error' => 'File has an invalid extension, it should be one of ' . $these . '.'));
         return;
     }
     //final file
     $file = $uploadDirectory . $filename . '.' . $ext;
     //save file
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     if (!Filesystem::isSafe($file)) {
         Filesystem::delete($file);
         echo json_encode(array('error' => Lang::txt('File rejected because the anti-virus scan failed.')));
         return;
     }
     //return success
     echo json_encode(array('success' => true));
     return;
 }
Exemple #9
0
 /**
  * Grabs the item size
  *
  * @param   bool    $raw  Whether or not to return raw size (vs formatted size)
  * @return  string|int
  **/
 public function getSize($raw = false)
 {
     if (!isset($this->size)) {
         $this->size = $this->hasAdapterOrFail()->adapter->getSize($this->getPath());
     }
     return $raw ? $this->size : \Hubzero\Utility\Number::formatBytes($this->size);
 }
Exemple #10
0
 *
 */
// No direct access
defined('_HZEXEC_') or die;
// Check used space against quota (percentage)
$inuse = round($this->dirsize / $this->quota * 100, 1);
if ($this->total > 0 && $inuse < 1) {
    $inuse = round($this->dirsize * 100 / $this->quota * 100, 2);
    if ($inuse < 0.1) {
        $inuse = 0.01;
    }
}
$inuse = $inuse > 100 ? 100 : $inuse;
$quota = \Hubzero\Utility\Number::formatBytes($this->quota);
$used = $this->dirsize ? \Hubzero\Utility\Number::formatBytes($this->dirsize) : 0;
$unused = \Hubzero\Utility\Number::formatBytes($this->quota - $this->dirsize);
$unused = $unused <= 0 ? 'none' : $unused;
$approachingQuota = $this->project->config()->get('approachingQuota', 85);
$approachingQuota = intval($approachingQuota) > 0 ? $approachingQuota : 85;
$warning = $inuse > $approachingQuota ? 1 : 0;
?>
<div id="plg-header">
	<h3 class="publications"><a href="<?php 
echo Route::url('index.php?option=' . $this->option . '&alias=' . $this->project->get('alias') . '&active=publications');
?>
"><?php 
echo $this->title;
?>
</a> &raquo; <span class="subheader"><?php 
echo Lang::txt('PLG_PROJECTS_PUBLICATIONS_DISK_USAGE');
?>
Exemple #11
0
 /**
  * Upload a file to the profile via AJAX
  *
  * @return     string
  */
 public function doajaxuploadTask()
 {
     //allowed extensions for uplaod
     $allowedExtensions = array('png', 'jpe', 'jpeg', 'jpg', 'gif');
     //max upload size
     $sizeLimit = $this->config->get('maxAllowed', '40000000');
     // get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         echo json_encode(array('error' => Lang::txt('Please select a file to upload')));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('File is empty')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('File is too large. Max file upload size is ') . $max));
         return;
     }
     //check to make sure we have an allowable extension
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     $ext = $pathinfo['extension'];
     if ($allowedExtensions && !in_array(strtolower($ext), $allowedExtensions)) {
         $these = implode(', ', $allowedExtensions);
         echo json_encode(array('error' => Lang::txt('File has an invalid extension, it should be one of ' . $these . '.')));
         return;
     }
     // Make the filename safe
     $file = Filesystem::clean($file);
     // Check project exists
     if (!$this->model->exists()) {
         echo json_encode(array('error' => Lang::txt('Error loading project')));
         return;
     }
     // Make sure user is authorized (project manager)
     if (!$this->model->access('manager')) {
         echo json_encode(array('error' => Lang::txt('Unauthorized action')));
         return;
     }
     // Build project image path
     $path = PATH_APP . DS . trim($this->config->get('imagepath', '/site/projects'), DS);
     $path .= DS . $this->model->get('alias') . DS . 'images';
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path, 0755, true, true)) {
             echo json_encode(array('error' => Lang::txt('COM_PROJECTS_UNABLE_TO_CREATE_UPLOAD_PATH')));
             return;
         }
     }
     // Delete older file with same name
     if (file_exists($path . DS . $file)) {
         Filesystem::delete($path . DS . $file);
     }
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         if (Helpers\Html::virusCheck($temp)) {
             echo json_encode(array('error' => Lang::txt('Virus detected, refusing to upload')));
             return;
         }
         //move from temp location to target location which is user folder
         $target = fopen($path . DS . $file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $path . DS . $file);
     }
     // Perform the upload
     if (!is_file($path . DS . $file)) {
         echo json_encode(array('error' => Lang::txt('COM_PROJECTS_ERROR_UPLOADING')));
         return;
     } else {
         //resize image to max 200px and rotate in case user didnt before uploading
         $hi = new \Hubzero\Image\Processor($path . DS . $file);
         if (count($hi->getErrors()) == 0) {
             $hi->autoRotate();
             $hi->resize(200);
             $hi->setImageType(IMAGETYPE_PNG);
             $hi->save($path . DS . $file);
         } else {
             echo json_encode(array('error' => $hi->getError()));
             return;
         }
         // Delete previous thumb
         if (file_exists($path . DS . 'thumb.png')) {
             Filesystem::delete($path . DS . 'thumb.png');
         }
         // create thumb
         $hi = new \Hubzero\Image\Processor($path . DS . $file);
         if (count($hi->getErrors()) == 0) {
             $hi->resize(50, false, true, true);
             $hi->save($path . DS . 'thumb.png');
         } else {
             echo json_encode(array('error' => $hi->getError()));
             return;
         }
         // Save picture name
         $this->model->set('picture', $file);
         if (!$this->model->store()) {
             echo json_encode(array('error' => $this->model->getError()));
             return;
         } elseif (!$this->model->inSetup()) {
             // Record activity
             $this->model->recordActivity(Lang::txt('COM_PROJECTS_REPLACED_PROJECT_PICTURE'));
         }
     }
     echo json_encode(array('success' => true));
     return;
 }
Exemple #12
0
 /**
  * Upload a file
  *
  * @return  void
  */
 public function uploadTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $dir = urldecode(Request::getVar('dir', ''));
     // Build upload path
     $path = $this->path . ($dir ? DS . trim($dir, DS) : '');
     $path = Util::normalizePath($path);
     $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_GROUPS_ERROR_DIR_INVALID_CHARACTERS'));
         } else {
             if (!is_dir($path . DS . $foldername)) {
                 if (!Filesystem::makeDirectory($path . DS . $foldername)) {
                     $this->setError(Lang::txt('COM_GROUPS_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH'));
                 }
             } else {
                 $this->setError(Lang::txt('COM_GROUPS_ERROR_DIR_EXISTS'));
             }
         }
         // Directory created
     } else {
         $file = Request::getVar('upload', '', 'files', 'array');
         // max upload size
         $sizeLimit = $this->config->get('maxAllowed', '40000000');
         // make sure we have a file
         if (!$file['name']) {
             $this->setError(Lang::txt('COM_GROUPS_NO_FILE'));
             return $this->displayTask();
         }
         // make sure we have an upload path
         if (!is_dir($path)) {
             if (!Filesystem::makeDirectory($path)) {
                 $this->setError(Lang::txt('COM_GROUPS_UNABLE_TO_CREATE_UPLOAD_PATH'));
                 return $this->displayTask();
             }
         }
         // make sure file is not empty
         if ($file['size'] == 0) {
             $this->setError(Lang::txt('COM_GROUPS_FILE_HAS_NO_SIZE'));
             return $this->displayTask();
         }
         // make sure file is not empty
         if ($file['size'] > $sizeLimit) {
             $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
             $this->setError(Lang::txt('FILE_SIZE_TOO_BIG', $max));
             return $this->displayTask();
         }
         // build needed paths
         $filePath = $path . DS . $file['name'];
         // upload image
         if (!Filesystem::upload($file['tmp_name'], $filePath)) {
             $this->setError(Lang::txt('COM_GROUPS_ERROR_UPLOADING'));
             return $this->displayTask();
         }
     }
     // Push through to the media view
     $this->displayTask();
 }
Exemple #13
0
 /**
  * Display memory usage
  *
  * @return  string
  */
 protected function displayMemoryUsage()
 {
     $html = '';
     $bytes = \App::get('profiler')->memory();
     //$html .= '<code>';
     $html .= \Hubzero\Utility\Number::formatBytes($bytes);
     //$html .= ' (' . number_format($bytes) . ' Bytes)';
     //$html .= '</code>';
     return $html;
 }
Exemple #14
0
" onclick="Joomla.isChecked(this.checked);" />
					</td>
					<td>
						<strong><?php 
    echo $item->group;
    ?>
</strong>
					</td>
					<td class="center priority-2">
						<?php 
    echo $item->count;
    ?>
					</td>
					<td class="center">
						<?php 
    echo \Hubzero\Utility\Number::formatBytes($item->size * 1024);
    ?>
					</td>
				</tr>
			<?php 
    $i++;
}
?>
		</tbody>
	</table>

	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="client" value="<?php 
echo $this->client->id;
?>
Exemple #15
0
/core/plugins/projects/files/assets/js/jquery.fileuploader.js"></script>
					<script src="<?php 
    echo rtrim(Request::base(true), '/');
    ?>
/core/plugins/projects/files/assets/js/jquery.queueuploader.js"></script>
					<script src="<?php 
    echo rtrim(Request::base(true), '/');
    ?>
/core/plugins/projects/files/assets/js/fileupload.jquery.js"></script>
		<?php 
} else {
    ?>
				<label class="addnew">
					<input name="upload[]" type="file" class="option uploader" id="uploader" multiple="multiple" />
					<p class="hint ipadded"><?php 
    echo Lang::txt('PLG_PROJECTS_FILES_MAX_UPLOAD') . ' ' . \Hubzero\Utility\Number::formatBytes($this->sizelimit);
    ?>
</p>
				</label>
		<?php 
}
?>
			</div>
		</div>
		<div id="upload-csize">
		</div>
		<?php 
if (!$this->ajax || $basic) {
    ?>
		<div class="sharing-option-extra" id="archiveCheck">
			<label class="sharing-option">
Exemple #16
0
 /**
  * Collect overall projects stats
  *
  * @return  array
  */
 public function getStats($model, $cron = false, $publishing = false, $period = 'alltime', $limit = 3)
 {
     // Incoming
     $period = Request::getVar('period', $period);
     $limit = Request::getInt('limit', $limit);
     if ($cron == true) {
         $publicOnly = false;
         $saveLog = true;
     } else {
         $publicOnly = $model->reviewerAccess('admin') ? false : true;
         $saveLog = false;
     }
     // Collectors
     $stats = array();
     $updated = NULL;
     $lastLog = NULL;
     $pastMonth = Date::of(time() - 32 * 24 * 60 * 60)->toSql('Y-m-d');
     $thisYearNum = Date::format('y');
     $thisMonthNum = Date::format('m');
     $thisWeekNum = Date::format('W');
     // Pull recent stats
     if ($this->loadLog($thisYearNum, $thisMonthNum, $thisWeekNum)) {
         $lastLog = json_decode($this->stats, true);
         $updated = $this->processed;
     } else {
         // Save stats
         $saveLog = true;
     }
     // Get project table class
     $tbl = $model->table();
     // Get inlcude /exclude lists
     $exclude = $tbl->getProjectsByTag('test', true, 'id');
     $include = $tbl->getProjectsByTag('test', false, 'id');
     $validProjects = $tbl->getProjectsByTag('test', false, 'alias');
     $validCount = count($validProjects) > 0 ? count($validProjects) : 1;
     // Collect overview stats
     $stats['general'] = array('total' => $tbl->getCount(array('exclude' => $exclude, 'all' => 1), true), 'setup' => $tbl->getCount(array('exclude' => $exclude, 'setup' => 1), true), 'active' => $tbl->getCount(array('exclude' => $exclude, 'active' => 1), true), 'public' => $tbl->getCount(array('exclude' => $exclude, 'private' => '0'), true), 'sponsored' => $tbl->getCount(array('exclude' => $exclude, 'reviewer' => 'sponsored'), true), 'sensitive' => $tbl->getCount(array('exclude' => $exclude, 'reviewer' => 'sensitive'), true), 'new' => $tbl->getCount(array('exclude' => $exclude, 'created' => date('Y-m', time()), 'all' => 1), true));
     $active = $stats['general']['active'] ? $stats['general']['active'] : 1;
     $total = $stats['general']['total'] ? $stats['general']['total'] : 1;
     // Activity stats
     $objAA = new Activity($this->_db);
     $recentlyActive = $tbl->getCount(array('exclude' => $exclude, 'timed' => $pastMonth, 'active' => 1), true);
     $perc = round($recentlyActive * 100 / $active) . '%';
     $stats['activity'] = array('total' => $objAA->getActivityStats($include, 'total'), 'average' => $objAA->getActivityStats($include, 'average'), 'usage' => $perc);
     $stats['topActiveProjects'] = $objAA->getTopActiveProjects($exclude, 5, $publicOnly);
     // Collect team stats
     $objO = new Owner($this->_db);
     $multiTeam = $objO->getTeamStats($exclude, 'multi');
     $activeTeam = $objO->getTeamStats($exclude, 'registered');
     $invitedTeam = $objO->getTeamStats($exclude, 'invited');
     $multiProjectUsers = $objO->getTeamStats($exclude, 'multiusers');
     $teamTotal = $activeTeam + $invitedTeam;
     $perc = round($multiTeam * 100 / $total) . '%';
     $stats['team'] = array('total' => $teamTotal, 'average' => $objO->getTeamStats($exclude, 'average'), 'multi' => $perc, 'multiusers' => $multiProjectUsers);
     $stats['topTeamProjects'] = $objO->getTopTeamProjects($exclude, $limit, $publicOnly);
     // Collect files stats
     if ($lastLog) {
         $stats['files'] = $lastLog['files'];
     } else {
         // Get repo model
         require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'repo.php';
         // Compute
         $repo = new \Components\Projects\Models\Repo();
         $fTotal = $repo->getStats($validProjects);
         $fAverage = number_format($fTotal / $validCount, 0);
         $fUsage = $repo->getStats($validProjects, 'usage');
         $fDSpace = $repo->getStats($validProjects, 'diskspace');
         $fCommits = $repo->getStats($validProjects, 'commitCount');
         $pDSpace = $repo->getStats($validProjects, 'pubspace');
         $perc = round($fUsage * 100 / $active) . '%';
         $stats['files'] = array('total' => $fTotal, 'average' => $fAverage, 'usage' => $perc, 'diskspace' => \Hubzero\Utility\Number::formatBytes($fDSpace), 'commits' => $fCommits, 'pubspace' => \Hubzero\Utility\Number::formatBytes($pDSpace));
     }
     // Collect publication stats
     if ($publishing) {
         $objP = new \Components\Publications\Tables\Publication($this->_db);
         $objPV = new \Components\Publications\Tables\Version($this->_db);
         $prPub = $objP->getPubStats($include, 'usage');
         $perc = round($prPub * 100 / $total) . '%';
         $stats['pub'] = array('total' => $objP->getPubStats($include, 'total'), 'average' => $objP->getPubStats($include, 'average'), 'usage' => $perc, 'released' => $objP->getPubStats($include, 'released'), 'versions' => $objPV->getPubStats($include));
     }
     // Save weekly stats
     if ($saveLog) {
         $this->year = $thisYearNum;
         $this->month = $thisMonthNum;
         $this->week = $thisWeekNum;
         $this->processed = Date::toSql();
         $this->stats = json_encode($stats);
         $this->store();
     }
     $stats['updated'] = $updated ? $updated : NULL;
     return $stats;
 }
Exemple #17
0
 /**
  * Get the file attributes (type, size) of a file
  *
  * @param      string $path      Path to get file info fore
  * @param      string $base_path Base path to prepend to $path
  * @return     string
  */
 public static function getFileAttribs($path, $base_path = '')
 {
     // Return nothing if no path provided
     if (!$path) {
         return '';
     }
     if ($base_path) {
         // Strip any trailing slash
         $base_path = DS . trim($base_path, DS);
     }
     // Ensure a starting slash
     $path = DS . trim($path, DS);
     // Does the beginning of the path match the base path?
     if (substr($path, 0, strlen($base_path)) != $base_path) {
         $path = $base_path . $path;
     }
     $path = PATH_APP . $path;
     $type = strtoupper(Filesystem::extension($path));
     $fs = '';
     // Get the file size if the file exist
     if (file_exists($path)) {
         $fs = filesize($path);
     }
     $html = $type;
     if ($fs) {
         switch ($type) {
             case 'HTM':
             case 'HTML':
             case 'PHP':
             case 'ASF':
             case 'SWF':
                 $fs = '';
                 break;
             default:
                 $fs = \Hubzero\Utility\Number::formatBytes($fs);
                 break;
         }
         $html .= $fs ? ', ' . $fs : '';
     }
     return $html;
 }
Exemple #18
0
 <?php 
echo Lang::txt('COM_WIKI_COL_DESCRIPTION');
?>
						</a>
					</th>
				</tr>
			</thead>
			<tbody>
			<?php 
if ($rows) {
    $database = \App::get('db');
    $asset = new \Components\Wiki\Tables\Attachment($database);
    foreach ($rows as $row) {
        $fsize = Lang::txt('COM_WIKI_UNKNOWN');
        if (is_file($asset->filespace() . DS . $row->pageid . DS . $row->filename)) {
            $fsize = \Hubzero\Utility\Number::formatBytes(filesize($asset->filespace() . DS . $row->pageid . DS . $row->filename));
        }
        $name = Lang::txt('COM_WIKI_UNKNOWN');
        $xprofile = \Hubzero\User\Profile::getInstance($row->created_by);
        if (is_object($xprofile)) {
            $name = $this->escape(stripslashes($xprofile->get('name')));
            $name = $xprofile->get('public') ? '<a href="' . Route::url($xprofile->getLink()) . '">' . $name . '</a>' : $name;
        }
        ?>
				<tr>
					<td>
						<time datetime="<?php 
        echo $row->created;
        ?>
"><?php 
        echo $row->created;
Exemple #19
0
    echo JUtility::getToken();
    ?>
=1"
							   title="<?php 
    echo Lang::txt('Delete');
    ?>
">[ x ]</a>
						</td>
					</tr>
					<tr>
						<th><?php 
    echo Lang::txt('COM_STOREFRONT_PICTURE_SIZE');
    ?>
:</th>
						<td><span id="img-size"><?php 
    echo \Hubzero\Utility\Number::formatBytes($this_size);
    ?>
</span>
						</td>
						<td></td>
					</tr>
					<tr>
						<th><?php 
    echo Lang::txt('COM_STOREFRONT_PICTURE_WIDTH');
    ?>
:</th>
						<td><span id="img-width"><?php 
    echo $width;
    ?>
</span> px</td>
						<td></td>
Exemple #20
0
 /**
  * Upload file
  *
  * @param   string  $name
  * @param   string  $temp
  * @return  bool
  */
 public function upload($name, $temp, $size)
 {
     $destination = $this->getUploadDir() . ($this->get('subdir') ? DS . $this->get('subdir') : '');
     // Make sure destination directory exists
     if (!is_dir($destination)) {
         if (!Filesystem::makeDirectory($destination)) {
             $this->setError('COM_GROUPS_MEDIA_UNABLE_TO_CREATE_UPLOAD_PATH');
             return false;
         }
     }
     if (!is_writable($destination)) {
         $this->setError(Lang::txt('COM_GROUPS_MEDIA_PATH_NOT_WRITABLE'));
         return false;
     }
     $config = \Component::params('com_media');
     // Check for allowed file types
     $ext = Filesystem::extension($name);
     $allowedExtensions = array_values(array_filter(explode(',', $config->get('upload_extensions'))));
     if ($allowedExtensions && !in_array($ext, $allowedExtensions)) {
         $this->setError(Lang::txt('COM_GROUPS_MEDIA_INVALID_FILE', implode(', ', $allowedExtensions)));
         return false;
     }
     // Max upload size
     $sizeLimit = $config->get('upload_maxsize');
     $sizeLimit = $sizeLimit * 1024 * 1024;
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', Number::formatBytes($sizeLimit));
         $this->setError(Lang::txt('COM_GROUPS_MEDIA_FILE_TOO_BIG', $max));
         return false;
     }
     // Make sure there are no filename conflicts
     $filename = $this->uniqueFilename(array('filename' => $name, 'subdir' => $this->get('subdir')));
     $destination .= DS . $filename;
     if (!Filesystem::upload($temp, $destination)) {
         $this->setError('COM_GROUPS_MEDIA_ERROR_UPLOADING');
         return false;
     }
     // Change file perm
     chmod($destination, 0774);
     // Scan file for viruses and other nasty bits
     if (!Filesystem::isSafe($destination)) {
         // Delete file
         unlink($destination);
         $this->setError(Lang::txt('COM_GROUPS_MEDIA_FILE_CONTAINS_VIRUS'));
         return false;
     }
     $this->set('filename', $filename);
     return true;
 }
Exemple #21
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return  string
  */
 public function ajaxUploadTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_ERROR_LOGIN_REQUIRED')));
         return;
     }
     // Ensure we have an ID to work with
     $listdir = strtolower(Request::getVar('dir', ''));
     if (!$listdir) {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_NO_ID')));
         return;
     }
     if (substr($listdir, 0, 3) == 'tmp') {
         $item = new Item($listdir);
         if (!$item->exists()) {
             $item->set('state', 0);
             $item->set('title', $listdir);
             if (!$item->store()) {
                 echo json_encode(array('error' => $item->getError()));
                 return;
             }
         }
         $listdir = $item->get('id');
     }
     //max upload size
     $sizeLimit = $this->config->get('maxAllowed', 40000000);
     // get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_FILE_NOT_FOUND')));
         return;
     }
     $asset = new Asset();
     //define upload directory and make sure its writable
     $path = $asset->filespace() . DS . $listdir;
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_ERROR_UNABLE_TO_CREATE_UPLOAD_DIR')));
             return;
         }
     }
     if (!is_writable($path)) {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_ERROR_UPLOAD_DIR_NOT_WRITABLE')));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_ERROR_EMPTY_FILE')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('COM_COLLECTIONS_ERROR_FILE_TOO_LARGE', $max)));
         return;
     }
     // don't overwrite previous files that were uploaded
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     // Make the filename safe
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     $ext = $pathinfo['extension'];
     while (file_exists($path . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     $file = $path . DS . $filename . '.' . $ext;
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     // Create database entry
     $asset->set('item_id', intval($listdir));
     $asset->set('filename', $filename . '.' . $ext);
     $asset->set('description', Request::getVar('description', '', 'post'));
     $asset->set('state', 1);
     $asset->set('type', 'file');
     if (!$asset->store()) {
         echo json_encode(array('error' => $asset->getError()));
         return;
     }
     $view = new \Hubzero\Component\View(array('name' => 'media', 'layout' => '_asset'));
     $view->i = Request::getInt('i', 0);
     $view->option = $this->_option;
     $view->controller = $this->_controller;
     $view->asset = $asset;
     $view->no_html = 1;
     //echo result
     echo json_encode(array('success' => true, 'file' => $filename . '.' . $ext, 'directory' => str_replace(PATH_APP, '', $path), 'id' => $listdir, 'html' => str_replace('>', '&gt;', $view->loadTemplate())));
 }
Exemple #22
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return  string
  */
 public function _ajaxUpload()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         ob_clean();
         header('Content-type: text/plain');
         echo json_encode(array('error' => Lang::txt('PLG_COURSES_PAGES_ERROR_LOGIN_NOTICE')));
         exit;
     }
     //max upload size
     $sizeLimit = $this->params->get('maxAllowed', 40000000);
     // get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         ob_clean();
         header('Content-type: text/plain');
         echo json_encode(array('error' => Lang::txt('PLG_COURSES_PAGES_ERROR_NO_FILE_PROVIDED')));
         exit;
     }
     //define upload directory and make sure its writable
     $path = $this->_path();
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             ob_clean();
             header('Content-type: text/plain');
             echo json_encode(array('error' => Lang::txt('PLG_COURSES_PAGES_ERROR_UNABLE_TO_UPLOAD')));
             exit;
         }
     }
     if (!is_writable($path)) {
         ob_clean();
         header('Content-type: text/plain');
         echo json_encode(array('error' => Lang::txt('PLG_COURSES_PAGES_ERROR_UPLOAD_DIR_NOT_WRITABLE')));
         exit;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         ob_clean();
         header('Content-type: text/plain');
         echo json_encode(array('error' => Lang::txt('File is empty')));
         exit;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         ob_clean();
         header('Content-type: text/plain');
         echo json_encode(array('error' => Lang::txt('PLG_COURSES_PAGES_ERROR_FILE_TOO_LARG', $max)));
         exit;
     }
     // Don't overwrite previous files that were uploaded
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     // Make the filename safe
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     $ext = $pathinfo['extension'];
     while (file_exists($path . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     $file = $path . DS . $filename . '.' . $ext;
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     if (!Filesystem::isSafe($file)) {
         Filesystem::delete($file);
         ob_clean();
         header('Content-type: text/plain');
         echo json_encode(array('error' => Lang::txt('File rejected because the anti-virus scan failed.')));
         return;
     }
     ob_clean();
     header('Content-type: text/plain');
     echo json_encode(array('success' => true, 'file' => $filename . '.' . $ext, 'directory' => str_replace(PATH_CORE, '', $path)));
     exit;
 }
Exemple #23
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     // Include needed files
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'asset.association.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'asset.php';
     require_once dirname(__DIR__) . DS . 'asset.php';
     // Get the file
     if (isset($_FILES['files'])) {
         $file = $_FILES['files']['name'][0];
         $size = (int) $_FILES['files']['size'];
         // Get the file extension
         $pathinfo = pathinfo($file);
         $filename = $pathinfo['filename'];
         $ext = $pathinfo['extension'];
     } else {
         return array('error' => 'No files provided');
     }
     // @FIXME: should these come from the global settings, or should they be courses specific
     // Get config
     $config = Component::params('com_media');
     // Max upload size
     $sizeLimit = (int) $config->get('upload_maxsize');
     $sizeLimit = $sizeLimit * 1024 * 1024;
     // Check to make sure we have a file and its not too big
     if ($size == 0) {
         return array('error' => 'File is empty');
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         return array('error' => "File is too large. Max file upload size is {$max}");
     }
     // Create our asset table object
     $assetObj = new Tables\Asset($this->db);
     $this->asset['title'] = $filename;
     $this->asset['type'] = !empty($this->asset['type']) ? $this->asset['type'] : 'file';
     $this->asset['subtype'] = !empty($this->asset['subtype']) ? $this->asset['subtype'] : 'file';
     $this->asset['url'] = $file;
     $this->asset['created'] = Date::toSql();
     $this->asset['created_by'] = App::get('authn')['user_id'];
     $this->asset['course_id'] = Request::getInt('course_id', 0);
     // Save the asset
     if (!$assetObj->save($this->asset)) {
         return array('error' => 'Asset save failed');
     }
     // Create asset assoc object
     $assocObj = new Tables\AssetAssociation($this->db);
     $this->assoc['asset_id'] = $assetObj->get('id');
     $this->assoc['scope'] = Request::getCmd('scope', 'asset_group');
     $this->assoc['scope_id'] = Request::getInt('scope_id', 0);
     // Save the asset association
     if (!$assocObj->save($this->assoc)) {
         return array('error' => 'Asset association save failed');
     }
     // Get courses config
     $cconfig = Component::params('com_courses');
     // Build the upload path if it doesn't exist
     $uploadDirectory = PATH_APP . DS . trim($cconfig->get('uploadpath', '/site/courses'), DS) . DS . $this->asset['course_id'] . DS . $this->assoc['asset_id'] . DS;
     // Make sure upload directory exists and is writable
     if (!is_dir($uploadDirectory)) {
         if (!Filesystem::makeDirectory($uploadDirectory, 0755, true)) {
             return array('error' => 'Server error. Unable to create upload directory');
         }
     }
     if (!is_writable($uploadDirectory)) {
         return array('error' => 'Server error. Upload directory isn\'t writable');
     }
     // Get the final file path
     $target_path = $uploadDirectory . $filename . '.' . $ext;
     // Move the file to the site folder
     set_time_limit(60);
     // Scan for viruses
     if (!Filesystem::isSafe($_FILES['files']['tmp_name'][0])) {
         // Scan failed, delete asset and association and return an error
         $assetObj->delete();
         $assocObj->delete();
         Filesystem::deleteDirectory($uploadDirectory);
         return array('error' => 'File rejected because the anti-virus scan failed.');
     }
     if (!($move = move_uploaded_file($_FILES['files']['tmp_name'][0], $target_path))) {
         // Move failed, delete asset and association and return an error
         $assetObj->delete();
         $assocObj->delete();
         Filesystem::deleteDirectory($uploadDirectory);
         return array('error' => 'Move file failed');
     }
     // Get the url to return to the page
     $course_id = Request::getInt('course_id', 0);
     $offering_alias = Request::getCmd('offering', '');
     $course = new \Components\Courses\Models\Course($course_id);
     $url = Route::url('index.php?option=com_courses&controller=offering&gid=' . $course->get('alias') . '&offering=' . $offering_alias . '&asset=' . $assetObj->get('id'));
     $url = rtrim(str_replace('/api', '', Request::root()), '/') . '/' . ltrim($url, '/');
     $return_info = array('asset_id' => $this->assoc['asset_id'], 'asset_title' => $this->asset['title'], 'asset_type' => $this->asset['type'], 'asset_subtype' => $this->asset['subtype'], 'asset_url' => $url, 'course_id' => $this->asset['course_id'], 'offering_alias' => Request::getCmd('offering', ''), 'scope_id' => $this->assoc['scope_id'], 'asset_ext' => $ext, 'upload_path' => $uploadDirectory, 'target_path' => $target_path);
     // Return info
     return array('assets' => $return_info);
 }
Exemple #24
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return  string
  */
 public function ajaxUploadTask()
 {
     // Check if they're logged in
     /*if (User::isGuest())
     		{
     			echo json_encode(array('error' => Lang::txt('Must be logged in.')));
     			return;
     		}*/
     // Ensure we have an ID to work with
     $ticket = Request::getInt('ticket', 0);
     $comment = Request::getInt('comment', 0);
     if (!$ticket) {
         echo json_encode(array('error' => Lang::txt('COM_SUPPORT_NO_ID'), 'ticket' => $ticket));
         return;
     }
     //max upload size
     $sizeLimit = $this->config->get('maxAllowed', 40000000);
     // get the file
     if (isset($_GET['qqfile']) && isset($_SERVER["CONTENT_LENGTH"])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile']) && isset($_FILES['qqfile']['size'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         echo json_encode(array('error' => Lang::txt('File not found')));
         return;
     }
     //define upload directory and make sure its writable
     $path = PATH_APP . DS . trim($this->config->get('webpath', '/site/tickets'), DS) . DS . $ticket;
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             echo json_encode(array('error' => Lang::txt('Error uploading. Unable to create path.')));
             return;
         }
     }
     if (!is_writable($path)) {
         echo json_encode(array('error' => Lang::txt('Server error. Upload directory isn\'t writable.')));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('File is empty')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('File is too large. Max file upload size is %s', $max)));
         return;
     }
     // don't overwrite previous files that were uploaded
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     // Make the filename safe
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     $ext = $pathinfo['extension'];
     while (file_exists($path . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     //make sure that file is acceptable type
     if (!in_array(strtolower($ext), explode(',', $this->config->get('file_ext')))) {
         echo json_encode(array('error' => Lang::txt('COM_SUPPORT_ERROR_INCORRECT_FILE_TYPE')));
         return;
     }
     $file = $path . DS . $filename . '.' . $ext;
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     if (!\Filesystem::isSafe($file)) {
         if (\Filesystem::delete($file)) {
             echo json_encode(array('success' => false, 'error' => Lang::txt('ATTACHMENT: File rejected because the anti-virus scan failed.')));
             return;
         }
     }
     // Create database entry
     $asset = new Attachment();
     $asset->bind(array('id' => 0, 'ticket' => $ticket, 'comment_id' => $comment, 'filename' => $filename . '.' . $ext, 'description' => Request::getVar('description', '')));
     if (!$asset->store(true)) {
         echo json_encode(array('success' => false, 'error' => $asset->getError()));
         return;
     }
     $view = new View(array('name' => 'media', 'layout' => '_asset'));
     $view->option = $this->_option;
     $view->controller = $this->_controller;
     $view->asset = $asset;
     $view->no_html = 1;
     //echo result
     echo json_encode(array('success' => true, 'file' => $filename . '.' . $ext, 'directory' => str_replace(PATH_APP, '', $path), 'ticket' => $ticket, 'comment_id' => $comment, 'html' => str_replace('>', '&gt;', $view->loadTemplate())));
 }
Exemple #25
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return  string
  */
 public function ajaxUploadTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Ensure we have an ID to work with
     $id = Request::getInt('id', 0);
     if (!$id) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_NO_ID')));
         return;
     }
     // Build the path
     $type = strtolower(Request::getWord('type', ''));
     $path = $this->_path($type, $id);
     if (!$path) {
         echo json_encode(array('error' => $this->getError()));
         return;
     }
     // allowed extensions for uplaod
     $allowedExtensions = array('png', 'jpeg', 'jpg', 'gif');
     // max upload size
     $sizeLimit = $this->config->get('maxAllowed', 40000000);
     // get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_NO_FILE_FOUND')));
         return;
     }
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH')));
             return;
         }
     }
     if (!is_writable($path)) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_UPLOAD_DIRECTORY_IS_NOT_WRITABLE')));
         return;
     }
     //check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_EMPTY_FILE')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_FILE_TOO_LARGE', $max)));
         return;
     }
     // don't overwrite previous files that were uploaded
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     // Make the filename safe
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     $ext = $pathinfo['extension'];
     if (!in_array(strtolower($ext), $allowedExtensions)) {
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_UNKNOWN_FILE_TYPE')));
         return;
     }
     $file = $path . DS . $filename . '.' . $ext;
     if ($stream) {
         //read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         //move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     if (!Filesystem::isSafe($file)) {
         Filesystem::delete($file);
         echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_FILE_UNSAFE')));
         return;
     }
     // Do we have an old file we're replacing?
     if ($curfile = Request::getVar('currentfile', '')) {
         // Remove old image
         if (file_exists($path . DS . $curfile)) {
             if (!Filesystem::delete($path . DS . $curfile)) {
                 echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_UNABLE_TO_DELETE_FILE')));
                 return;
             }
         }
     }
     switch ($type) {
         case 'section':
             // Instantiate a model, change some info and save
             $model = \Components\Courses\Models\Section::getInstance($id);
             $model->params()->set('logo', $filename . '.' . $ext);
             $model->set('params', $model->params()->toString());
             break;
         case 'offering':
             // Instantiate a model, change some info and save
             $model = \Components\Courses\Models\Offering::getInstance($id);
             $model->params()->set('logo', $filename . '.' . $ext);
             $model->set('params', $model->params()->toString());
             break;
         case 'course':
             // Instantiate a model, change some info and save
             $model = \Components\Courses\Models\Course::getInstance($id);
             $model->set('logo', $filename . '.' . $ext);
             break;
         default:
             echo json_encode(array('error' => Lang::txt('COM_COURSES_ERROR_INVALID_TYPE')));
             return;
             break;
     }
     if (!$model->store()) {
         echo json_encode(array('error' => $model->getError()));
         return;
     }
     $this_size = filesize($file);
     list($width, $height, $type, $attr) = getimagesize($file);
     //echo result
     echo json_encode(array('success' => true, 'file' => $filename . '.' . $ext, 'directory' => str_replace(PATH_ROOT, '', $path), 'id' => $id, 'size' => \Hubzero\Utility\Number::formatBytes($this_size), 'width' => $width, 'height' => $height));
 }
Exemple #26
0
        ?>
" id="sync-lock-<?php 
        echo $service;
        ?>
" value="<?php 
        echo $this->model->params->get($service . '_sync_lock');
        ?>
" />
		<?php 
    }
}
?>
	</fieldset>
	<?php 
// Connections to external services
$this->view('link', 'connect')->set('option', $this->option)->set('model', $this->model)->set('uid', $this->uid)->set('database', $this->database)->set('connect', $this->connect)->set('oparams', $this->oparams)->set('params', $this->fileparams)->set('sizelimit', \Hubzero\Utility\Number::formatBytes($this->fileparams->get('maxUpload', '104857600')))->display();
?>
	<div class="list-editing">
		<p>
			<?php 
if ($this->model->access('content')) {
    ?>
			<span id="manage_assets">
				<a href="<?php 
    echo Route::url($this->model->link('files') . '&action=upload' . $subdirlink);
    ?>
" class="fmanage" id="a-upload" title="<?php 
    echo Lang::txt('PLG_PROJECTS_FILES_UPLOAD_TOOLTIP');
    ?>
"><span><?php 
    echo Lang::txt('PLG_PROJECTS_FILES_UPLOAD');
            } else {
                $UrlPtn = "(?:https?:|mailto:|ftp:|gopher:|news:|file:)" . "(?:[^ |\\/\"\\']*\\/)*[^ |\\t\\n\\/\"\\']*[A-Za-z0-9\\/?=&~_]";
                if (preg_match("/{$UrlPtn}/", $asset->get('filename'))) {
                    echo Lang::txt('PLG_MEMBERS_COLLECTIONS_LINK_EXTERNAL');
                } else {
                    echo Lang::txt('PLG_MEMBERS_COLLECTIONS_LINK_INTERNAL');
                }
            }
            ?>
						</span>
						<?php 
            if ($asset->get('description')) {
                ?>
							<span class="file-description">
								<?php 
                echo \Hubzero\Utility\Number::formatBytes(filesize($path . DS . ltrim($asset->get('filename'), DS)));
                ?>
							</span>
						<?php 
            }
            ?>
					</span>
				</li>
				<?php 
        }
        ?>
		</ul>
<?php 
    }
}
if ($content) {
Exemple #28
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;
    }
Exemple #29
0
 /**
  * Takes recieved files and saves them to a temporary directory specific
  * directory then returns a json object with those file names.
  *
  * @return  void
  */
 public function uploadImageTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         echo json_encode(array('error' => Lang::txt('COM_FEEDBACK_STORY_LOGIN')));
         return;
     }
     // Max upload size
     $sizeLimit = $this->config->get('maxAllowed', 40000000);
     // Get the file
     if (isset($_GET['qqfile'])) {
         $stream = true;
         $file = $_GET['qqfile'];
         $size = (int) $_SERVER["CONTENT_LENGTH"];
     } elseif (isset($_FILES['qqfile'])) {
         $stream = false;
         $file = $_FILES['qqfile']['name'];
         $size = (int) $_FILES['qqfile']['size'];
     } else {
         echo json_encode(array('error' => Lang::txt('COM_FEEDBACK_ERROR_FILE_NOT_FOUND')));
         return;
     }
     // Define upload directory and make sure its writable
     $path = rtrim($this->tmpPath(), DS) . DS . User::get('id');
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             echo json_encode(array('error' => Lang::txt('COM_FEEDBACK_ERROR_UNABLE_TO_CREATE_UPLOAD_PATH')));
             return;
         }
     }
     if (!is_writable($path)) {
         echo json_encode(array('error' => Lang::txt('COM_FEEDBACK_ERROR_UPLOAD_PATH_IS_NOT_WRITABLE')));
         return;
     }
     // Check to make sure we have a file and its not too big
     if ($size == 0) {
         echo json_encode(array('error' => Lang::txt('COM_FEEDBACK_ERROR_EMPTY_FILE')));
         return;
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', Number::formatBytes($sizeLimit));
         echo json_encode(array('error' => Lang::txt('COM_FEEDBACK_ERROR_FILE_TOO_LARGE', $max)));
         return;
     }
     // Don't overwrite previous files that were uploaded
     $pathinfo = pathinfo($file);
     $filename = $pathinfo['filename'];
     // Make the filename safe
     $filename = urldecode($filename);
     $filename = Filesystem::clean($filename);
     $filename = str_replace(' ', '_', $filename);
     $ext = $pathinfo['extension'];
     while (file_exists($path . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     $file = $path . DS . $filename . '.' . $ext;
     if ($stream) {
         // Read the php input stream to upload file
         $input = fopen("php://input", "r");
         $temp = tmpfile();
         $realSize = stream_copy_to_stream($input, $temp);
         fclose($input);
         // Move from temp location to target location which is user folder
         $target = fopen($file, "w");
         fseek($temp, 0, SEEK_SET);
         stream_copy_to_stream($temp, $target);
         fclose($target);
     } else {
         move_uploaded_file($_FILES['qqfile']['tmp_name'], $file);
     }
     if (!Filesystem::isSafe($file)) {
         if (Filesystem::delete($file)) {
             echo json_encode(array('success' => false, 'error' => Lang::txt('COM_FEEDBACK_ERROR_FILE_FAILED_VIRUS_SCAN')));
             return;
         }
     }
     // Output result
     echo json_encode(array('success' => true, 'file' => $filename . '.' . $ext, 'directory' => str_replace(PATH_ROOT, '', $path)));
 }
Exemple #30
0
    echo Lang::txt('PLG_PROJECTS_PUBLICATIONS_DISK_USAGE_TOOLTIP');
    ?>
"><span id="indicator-wrapper" <?php 
    if ($warning) {
        echo 'class="quota-warning"';
    }
    ?>
><span id="indicator-area" class="used:<?php 
    echo $inuse;
    ?>
">&nbsp;</span><span id="indicator-value"><span><?php 
    echo $inuse . '% ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_DISK_USAGE_USED');
    ?>
</span></span></span></a>
		 <span class="show-quota"><?php 
    echo Lang::txt('PLG_PROJECTS_PUBLICATIONS_DISK_USAGE_QUOTA') . ': ' . \Hubzero\Utility\Number::formatBytes($this->quota);
    ?>
</span>
	</span>
</p>
<?php 
    if ($showStats) {
        ?>
<p class="viewallstats mini"><a href="<?php 
        echo Route::url($this->project->link('publications') . '&action=stats');
        ?>
"><?php 
        echo Lang::txt('PLG_PROJECTS_PUBLICATIONS_VIEW_USAGE_STATS');
        ?>
 &raquo;</a></p>
<?php