Example #1
0
 /**
  * Constructor
  *
  * @param      integer $scope_id Scope ID (group, course, etc.)
  * @return     void
  */
 public function __construct($scope_id = 0)
 {
     $this->set('scope_id', $scope_id);
     $this->_segments['id'] = $scope_id;
     $this->_segments['active'] = 'blog';
     $this->_item = Profile::getInstance($scope_id);
     $config = Plugin::params('members', 'blog');
     $id = String::pad($this->get('scope_id'));
     $this->set('path', str_replace('{{uid}}', $id, $config->get('uploadpath', '/site/members/{{uid}}/blog')));
     $this->set('scope', $this->get('scope_id') . '/blog');
     $this->set('option', $this->_segments['option']);
 }
Example #2
0
 /**
  * Display a form for uploading an image and any data for current uploaded image
  *
  * @param   string   $file  Image name
  * @param   integer  $id    User ID
  * @return  void
  */
 public function displayTask($file = '', $id = 0)
 {
     // Do have an ID or do we need to get one?
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     $dir = String::pad($id);
     // Do we have a file or do we need to get one?
     $file = $file ?: Request::getVar('file', '');
     // Build the directory path
     $path = $this->path . DS . $dir;
     // Output view
     $this->view->set('title', $this->_title)->set('webpath', $this->config->get('uploadpath', '/site/quotes'))->set('default_picture', $this->config->get('defaultpic', '/core/components/com_feedback/site/assets/img/contributor.gif'))->set('path', $dir)->set('file', $file)->set('file_path', $path)->set('id', $id)->setErrors($this->getErrors())->setLayout('display')->display();
 }
Example #3
0
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
$database = App::get('db');
$jt = new \Components\Jobs\Tables\JobType($database);
$jc = new \Components\Jobs\Tables\JobCategory($database);
$profile = \Hubzero\User\Profile::getInstance($this->seeker->uid);
$jobtype = $jt->getType($this->seeker->sought_type, strtolower(Lang::txt('COM_JOBS_TYPE_ANY')));
$jobcat = $jc->getCat($this->seeker->sought_cid, strtolower(Lang::txt('COM_JOBS_CATEGORY_ANY')));
$title = Lang::txt('COM_JOBS_ACTION_DOWNLOAD') . ' ' . $this->seeker->name . ' ' . ucfirst(Lang::txt('COM_JOBS_RESUME'));
// Get the configured upload path
$base_path = DS . trim($this->params->get('webpath', '/site/members'), DS);
$path = $base_path . DS . \Hubzero\Utility\String::pad($this->seeker->uid);
if (!is_dir(PATH_APP . $path)) {
    if (!Filesystem::makeDirectory(PATH_APP . $path)) {
        $path = '';
    }
}
$resume = is_file(PATH_APP . $path . DS . $this->seeker->filename) ? $path . DS . $this->seeker->filename : '';
?>
<div class="aboutme<?php 
echo $this->seeker->mine && $this->list ? ' mine' : '';
echo isset($this->seeker->shortlisted) && $this->seeker->shortlisted ? ' shortlisted' : '';
?>
">
	<div class="thumb">
		<img src="<?php 
echo $profile->getPicture();
Example #4
0
 /**
  * Download a file
  *
  * @return  void
  */
 public function downloadTask()
 {
     //get vars
     $id = Request::getInt('id', 0);
     //check to make sure we have an id
     if (!$id || $id == 0) {
         return;
     }
     //Load member profile
     $member = Member::oneOrFail($id);
     // check to make sure we have member profile
     if (!$member) {
         return;
     }
     //get the file name
     // make sure to leave out any query params (ex. ?v={timestamp})
     $uri = Request::getVar('SCRIPT_URL', '', 'server');
     if (strstr($uri, 'Image:')) {
         $file = str_replace('Image:', '', strstr($uri, 'Image:'));
     } elseif (strstr($uri, 'File:')) {
         $file = str_replace('File:', '', strstr($uri, 'File:'));
     }
     //decode file name
     $file = urldecode($file);
     // build base path
     $base_path = $this->filespace() . DS . \Hubzero\Utility\String::pad($member->get('id'), 5);
     //if we are on the blog
     if (Request::getVar('active', 'profile') == 'blog') {
         // @FIXME Check still needs to occur for non-public entries
         //authorize checks
         /*if ($this->_authorize() != 'admin')
         		{
         			if (User::get('id') != $member->get('id'))
         			{
         				App::abort(403, Lang::txt('You are not authorized to download the file: ') . ' ' . $file);
         			}
         		}*/
         //get the params from the members blog plugin
         $blog_params = Plugin::params('members', 'blog');
         //build the base path to file based of upload path param
         $base_path = str_replace('{{uid}}', \Hubzero\Utility\String::pad($member->get('id'), 5), $blog_params->get('uploadpath'));
     }
     //build file path
     $file_path = $base_path . DS . $file;
     // Ensure the file exist
     if (!file_exists(PATH_APP . DS . $file_path)) {
         App::abort(404, Lang::txt('The requested file could not be found: ') . ' ' . $file);
         return;
     }
     // Serve up the image
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename(PATH_APP . DS . $file_path);
     $xserver->disposition('attachment');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     //serve up file
     if (!$xserver->serve()) {
         // Should only get here on error
         App::abort(404, Lang::txt('An error occured while trying to output the file'));
     }
     exit;
 }
Example #5
0
 /**
  * Get path to member dir (for provisioned projects)
  *
  * @return  string
  */
 public function getMembersPath()
 {
     // Get members config
     $mconfig = Component::params('com_members');
     // Build upload path
     $dir = \Hubzero\Utility\String::pad($this->_uid);
     $path = DS . trim($mconfig->get('webpath', '/site/members'), DS) . DS . $dir . DS . 'files';
     if (!is_dir(PATH_APP . $path)) {
         if (!Filesystem::makeDirectory(PATH_APP . $path, 0755, true, true)) {
             $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH'));
             return;
         }
     }
     return PATH_APP . $path;
 }
Example #6
0
 /**
  * Get disk space
  *
  * @param      array  	$rows		Publications objet array
  *
  * @return     integer
  */
 public static function getDiskUsage($rows = array())
 {
     $used = 0;
     if (!empty($rows)) {
         $pubconfig = Component::params('com_publications');
         $base = trim($pubconfig->get('webpath'), DS);
         foreach ($rows as $row) {
             $path = DS . $base . DS . \Hubzero\Utility\String::pad($row->id);
             $used = $used + self::computeDiskUsage($path, PATH_APP, false);
         }
     }
     return $used;
 }
Example #7
0
 /**
  * Get a path or URL to a user pciture
  *
  * @param   integer  $id
  * @param   string   $name
  * @param   string   $email
  * @param   bool     $thumbnail
  * @return  string
  */
 public function picture($id, $name, $email, $thumbnail = true)
 {
     $processor = new Processor();
     $size = $this->pictureSize;
     $file = $this->pictureName;
     if ($thumbnail) {
         $size = $this->thumbnailSize;
         $file = $this->thumbnailName;
     }
     $dir = $this->path . DIRECTORY_SEPARATOR . String::pad($id, 5) . DIRECTORY_SEPARATOR;
     $path = $dir . $file;
     if (file_exists($path)) {
         return with(new Moderator($path))->getUrl();
     }
     // If the name has a space
     if (strstr($name, ' ')) {
         $parts = explode(' ', $name);
         $first = array_shift($parts);
         $last = array_pop($parts);
         $initials = substr($first, 0, 1) . substr($last, 0, 1);
     } else {
         $initials = substr($name, 0, 2);
     }
     $initials = strtoupper(trim($initials));
     $image = $processor->getImageData($initials, $size, $this->color);
     if (!is_dir($dir)) {
         @mkdir($dir, 0755, true);
     }
     @file_put_contents($path, $image);
     if (!file_exists($path)) {
         return sprintf('data:image/png;base64,%s', base64_encode($image));
     }
     return with(new Moderator($path))->getUrl();
 }
Example #8
0
 /**
  * Get a path or URL to a user pciture
  *
  * @param   integer  $id
  * @param   string   $name
  * @param   string   $email
  * @param   bool     $thumbnail
  * @return  string
  */
 public function picture($id, $name, $email, $thumbnail = true)
 {
     $file = $this->pictureName;
     if ($thumbnail) {
         $file = $this->thumbnailName;
     }
     $path = $this->path . DIRECTORY_SEPARATOR . String::pad($id, 5) . DIRECTORY_SEPARATOR . $file;
     if (file_exists($path)) {
         return with(new Moderator($path))->getUrl();
     }
     return '';
 }
Example #9
0
 /**
  * Display a user's profile picture
  *
  * @param      string  $file File name
  * @param      integer $id   User ID
  * @return     void
  */
 public function displayTask($file = '', $id = 0)
 {
     // Incoming
     if (!$id) {
         $id = Request::getInt('id', 0, 'get');
     }
     $this->view->id = $id;
     if (!$file) {
         $file = Request::getVar('file', '', 'get');
     }
     $this->view->file = $file;
     // Build the file path
     $dir = \Hubzero\Utility\String::pad($id);
     $path = PATH_APP . DS . $this->filespace() . DS . $dir;
     // Output HTML
     $this->view->webpath = '/' . $this->filespace();
     $this->view->default_picture = $this->config->get('defaultpic', '/core/components/com_members/site/assets/img/profile.gif');
     $this->view->path = $dir;
     $this->view->file_path = $path;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setLayout('display');
     $this->view->display();
 }
Example #10
0
 /**
  * Build a path from a creation date (0000-00-00 00:00:00)
  *
  * @param      string  $date Resource created date
  * @param      integer $id   Resource ID
  * @param      string  $base Base path to prepend
  * @return     string
  */
 private function _buildPathFromDate($date, $id, $base = '')
 {
     if ($date && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $date, $regs)) {
         $date = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
     }
     if ($date) {
         $dir_year = Date::of($date)->format('Y');
         $dir_month = Date::of($date)->format('m');
     } else {
         $dir_year = Date::format('Y');
         $dir_month = Date::format('m');
     }
     $dir_id = String::pad($id);
     $path = $base . DS . $dir_year . DS . $dir_month . DS . $dir_id;
     return $path;
 }
Example #11
0
 /**
  * Build and return the relative path to resource file storage
  *
  * @return  string
  */
 public function relativepath()
 {
     $date = $this->get('created');
     if ($date && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $date, $regs)) {
         $date = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
     }
     if ($date) {
         $dir_year = Date::of($date)->format('Y');
         $dir_month = Date::of($date)->format('m');
         if (!is_dir($this->basepath() . DS . $dir_year . DS . $dir_month . DS . String::pad($this->get('id'))) && intval($dir_year) <= 2013 && intval($dir_month) <= 11) {
             $dir_year = Date::of($date)->toLocal('Y');
             $dir_month = Date::of($date)->toLocal('m');
         }
     } else {
         $dir_year = Date::of('now')->format('Y');
         $dir_month = Date::of('now')->format('m');
     }
     return $dir_year . DS . $dir_month . DS . String::pad($this->get('id'));
 }
Example #12
0
 /**
  * Removes a profile entry, associated picture, and redirects to main listing
  *
  * @return     void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('ids', array());
     // Do we have any IDs?
     if (!empty($ids)) {
         // Loop through each ID and delete the necessary items
         foreach ($ids as $id) {
             $id = intval($id);
             // Delete any associated pictures
             $path = PATH_APP . DS . trim($this->config->get('webpath', '/site/members'), DS) . DS . \Hubzero\Utility\String::pad($id);
             if (!file_exists($path . DS . $file) or !$file) {
                 $this->setError(Lang::txt('COM_MEMBERS_FILE_NOT_FOUND'));
             } else {
                 unlink($path . DS . $file);
             }
             // Remove any contribution associations
             $assoc = new \Components\Members\Tables\Association($this->database);
             $assoc->authorid = $id;
             $assoc->deleteAssociations();
             // Remove the profile
             $profile = new Profile();
             $profile->load($id);
             $profile->delete();
         }
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_MEMBERS_REMOVED'));
 }
Example #13
0
 /**
  * Delete a file
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     // Incoming member ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('COM_MEMBERS_NO_ID'));
         return $this->displayTask($id);
     }
     // Incoming file
     $file = Request::getVar('file', '');
     if (!$file) {
         $this->setError(Lang::txt('COM_MEMBERS_NO_FILE'));
         return $this->displayTask($id);
     }
     // Build the file path
     $dir = String::pad($id);
     $path = PATH_APP . DS . trim($this->config->get('webpath', '/site/members'), DS) . DS . $dir;
     // if we have file
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('COM_MEMBERS_FILE_NOT_FOUND'));
     } else {
         $ih = new \Components\Members\Helpers\ImgHandler();
         // Attempt to delete the file
         if (!Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('COM_MEMBERS_UNABLE_TO_DELETE_FILE'));
             return $this->displayTask($id);
         }
         // Get the file thumbnail name
         if ($file == 'profile.png') {
             $curthumb = 'thumb.png';
         }
         // Remove the thumbnail
         if (file_exists($path . DS . $curthumb)) {
             if (!Filesystem::delete($path . DS . $curthumb)) {
                 $this->setError(Lang::txt('COM_MEMBERS_UNABLE_TO_DELETE_FILE'));
                 return $this->displayTask($file, $id);
             }
         }
     }
     $this->displayTask($id);
 }
Example #14
0
    echo $current->datetime;
    ?>
"><?php 
    echo Date::of($current->datetime)->toLocal('M Y');
    ?>
</time></span></span>
				</p>
			</div>
			<div class="col span9 omega usage-stat">
				<div class="chart-wrap">
					<div id="chart-downloads" class="chart line"><?php 
    $sparkline = '<span class="sparkline">' . "\n";
    foreach ($results as $result) {
        $height = $downhighest ? round($result->primary_accesses / $downhighest * 100) : 0;
        $sparkline .= "\t" . '<span class="index">';
        $sparkline .= '<span class="count" style="height: ' . $height . '%;" title="20' . $result->year . '-' . \Hubzero\Utility\String::pad($result->month, 2) . ': ' . $result->primary_accesses . '">';
        $sparkline .= number_format($result->primary_accesses);
        $sparkline .= '</span> ';
        $sparkline .= '</span>' . "\n";
    }
    $sparkline .= '</span>' . "\n";
    echo $sparkline;
    ?>
</div>
				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		if (!jq) {
Example #15
0
 /**
  * Get a path or URL to a user pciture
  *
  * @param   integer  $id
  * @param   string   $name
  * @param   string   $email
  * @param   bool     $thumbnail
  * @return  string
  */
 public function picture($id, $name, $email, $thumbnail = true)
 {
     $processor = new Processor();
     $size = $this->pictureSize;
     $file = $this->pictureName;
     if ($thumbnail) {
         $size = $this->thumbnailSize;
         $file = $this->thumbnailName;
     }
     $dir = $this->path . DIRECTORY_SEPARATOR . String::pad($id, 5) . DIRECTORY_SEPARATOR;
     $path = $dir . $file;
     if (file_exists($path)) {
         return with(new Moderator($path))->getUrl();
     }
     $image = $processor->getImageData($email, $size, $this->color);
     if (!is_dir($dir)) {
         @mkdir($dir, 0755, true);
     }
     @file_put_contents($path, $image);
     if (!file_exists($path)) {
         return sprintf('data:image/png;base64,%s', base64_encode($image));
     }
     return with(new Moderator($path))->getUrl();
 }
Example #16
0
 /**
  * Removes a publication
  * Redirects to main listing
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array(0));
     $erase = Request::getInt('erase', 1);
     // Ensure we have some IDs to work with
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_ERROR_LOAD_PUBLICATION'), 'notice');
         return;
     }
     $version = count($ids) == 1 ? Request::getVar('version', 'all') : 'all';
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'activity.php';
     foreach ($ids as $id) {
         // Load publication
         $objP = new Tables\Publication($this->database);
         if (!$objP->load($id)) {
             throw new Exception(Lang::txt('COM_PUBLICATIONS_NOT_FOUND'), 404);
         }
         $projectId = $objP->project_id;
         $row = new Tables\Version($this->database);
         // Get versions
         $versions = $row->getVersions($id, $filters = array('withdev' => 1));
         if ($version != 'all' && count($versions) > 1) {
             // Check that version exists
             $version = $row->checkVersion($id, $version) ? $version : 'dev';
             // Load version
             if (!$row->loadVersion($id, $version)) {
                 throw new Exception(Lang::txt('COM_PUBLICATIONS_VERSION_NOT_FOUND'), 404);
             }
             // Cannot delete main version if other versions exist
             if ($row->main) {
                 throw new Exception(Lang::txt('COM_PUBLICATIONS_VERSION_MAIN_ERROR_DELETE'), 404);
             }
             if ($erase == 1) {
                 // Delete the version
                 if ($row->delete()) {
                     // Delete associations to the version
                     $this->deleteVersionExistence($row->id, $id);
                 }
             } else {
                 $row->state = 2;
                 $row->store();
             }
         } else {
             // Delete all versions
             $i = 0;
             foreach ($versions as $v) {
                 $objV = new Tables\Version($this->database);
                 if ($objV->loadVersion($id, $v->version_number)) {
                     if ($erase == 1) {
                         // Delete the version
                         if ($objV->delete()) {
                             // Delete associations to the version
                             $this->deleteVersionExistence($v->id, $id);
                             $i++;
                         }
                     } else {
                         $objV->state = 2;
                         $objV->store();
                     }
                 }
             }
             // All versions deleted?
             if ($i == count($versions)) {
                 // Delete pub record and all associations
                 $objP->delete($id);
                 $objP->deleteExistence($id);
                 // Delete related publishing activity from feed
                 $objAA = new \Components\Projects\Tables\Activity($this->database);
                 $objAA->deleteActivityByReference($projectId, $id, 'publication');
                 // Build publication path
                 $path = PATH_APP . DS . trim($this->config->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($id);
                 // Delete all files
                 if (is_dir($path)) {
                     Filesystem::deleteDirectory($path);
                 }
             }
         }
     }
     // Redirect
     $output = $version != 'all' ? Lang::txt('COM_PUBLICATIONS_SUCCESS_VERSION_DELETED') : Lang::txt('COM_PUBLICATIONS_SUCCESS_RECORDS_DELETED') . ' (' . count($ids) . ')';
     App::redirect($this->buildRedirectURL(), $output);
     return;
 }
Example #17
0
 /**
  * Create resume archive
  *
  * @param      string $pile Resumes to return
  * @return     mixed File path if successful, false if not
  */
 private function _archiveResumes($pile = 'all')
 {
     // Get available resume files
     $resume = new Resume($this->database);
     $files = $resume->getResumeFiles($pile, User::get('id'), $this->_masterAdmin);
     $batch = array();
     if (count($files) > 0) {
         if (!extension_loaded('zip')) {
             throw new Exception(Lang::txt('COM_JOBS_ERROR_MISSING_PHP_LIBRARY'), 500);
         }
         $pile .= $pile != 'all' ? '_' . User::get('id') : '';
         $zipname = Lang::txt('Resumes') . '_' . $pile . '.zip';
         $mconfig = Component::params('com_members');
         $base_path = $mconfig->get('webpath', '/site/members');
         if ($base_path) {
             $base_path = DS . trim($base_path, DS);
         }
         $base_path .= DS . \Hubzero\Utility\String::pad(User::get('id'));
         $i = 0;
         $zip = new ZipArchive();
         if ($zip->open(PATH_APP . $base_path . DS . $zipname, ZipArchive::OVERWRITE) === TRUE) {
             foreach ($files as $avalue => $alabel) {
                 $apath = Event::trigger('members.build_path', array($avalue));
                 $path = is_array($apath) ? $apath[0] : '';
                 $file = $path ? PATH_APP . $path . DS . $alabel : '';
                 if (!is_file($file)) {
                     continue;
                 }
                 $zip->addFile($file, basename($file));
                 $i++;
             }
             $zip->close();
         } else {
             App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 'error');
         }
         if ($i == 0) {
             App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 'error');
         } else {
             $archive = array();
             $archive['path'] = PATH_APP . $base_path . DS . $zipname;
             $archive['name'] = $zipname;
             return $archive;
         }
     }
     return false;
 }
Example #18
0
 /**
  * Display a file and its info
  *
  * @param   string   $file  File name
  * @param   integer  $id    User ID
  * @return  void
  */
 public function displayTask($file = '', $id = 0)
 {
     // Load the component config
     $this->view->config = $this->config;
     // Incoming
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     $this->view->id = $id;
     if (!$file) {
         $file = Request::getVar('file', '');
     }
     $this->view->file = $file;
     // Build the file path
     $this->view->dir = \Hubzero\Utility\String::pad($id);
     $this->view->path = PATH_APP . DS . trim($this->config->get('webpath', '/site/members'), DS) . DS . $this->view->dir;
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->setLayout('display')->display();
 }
Example #19
0
 /**
  * Build a path to a resource's files
  *
  * @param      string  $date Resource date
  * @param      integer $id   Resource ID
  * @param      string  $base Base path to prepend
  * @return     string
  */
 private function _buildPath($date, $id, $base = '')
 {
     if ($date && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $date, $regs)) {
         $date = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
     }
     if ($date) {
         $dir_year = date('Y', $date);
         $dir_month = date('m', $date);
     } else {
         $dir_year = date('Y');
         $dir_month = date('m');
     }
     $dir_id = \Hubzero\Utility\String::pad($id);
     return $base . DS . $dir_year . DS . $dir_month . DS . $dir_id;
 }
Example #20
0
 /**
  * Get a path or URL to a user pciture
  *
  * @param   integer  $id
  * @param   string   $name
  * @param   string   $email
  * @param   bool     $thumbnail
  * @return  string
  */
 public function picture($id, $name, $email, $thumbnail = true)
 {
     $member = Profile::getInstance($id);
     if (!$member) {
         return '';
     }
     // If member has a picture set
     if ($file = $member->get('picture')) {
         $path = $this->path . DIRECTORY_SEPARATOR . String::pad($id, 5) . DIRECTORY_SEPARATOR;
         $file = ltrim($file, DIRECTORY_SEPARATOR);
         // Does the file exist?
         if ($file != 'profile.png' && file_exists($path . $file)) {
             try {
                 // Attempt to rename and resize to 'profile.png'
                 $hi = new Processor($path . $file);
                 if (count($hi->getErrors()) == 0) {
                     $hi->autoRotate();
                     $hi->resize(400);
                     $hi->setImageType(IMAGETYPE_PNG);
                     $hi->save($path . $this->pictureName);
                 }
                 // If we sucessfully made a 'profile.png',
                 // attempt to rename and resize to 'thumb.png'
                 if (file_exists($path . $this->pictureName)) {
                     $hi = new Processor($path . $this->pictureName);
                     if (count($hi->getErrors()) == 0) {
                         $hi->resize(50, false, true, true);
                         $hi->save($path . $this->thumbnailName);
                     }
                 }
             } catch (\Exception $e) {
                 return '';
             }
         }
         $file = $this->pictureName;
         if ($thumbnail) {
             $file = $this->thumbnailName;
         }
         $path .= $file;
         if (file_exists($path)) {
             return with(new Moderator($path))->getUrl();
         }
     }
     return '';
 }
Example #21
0
 /**
  * Get path to specific publication directory
  *
  * @param      string $type The type of link to return
  * @return     boolean
  */
 public function path($type = '', $root = false)
 {
     if (!isset($this->_basePath)) {
         $this->_basePath = DS . trim($this->config('webpath'), DS) . DS . \Hubzero\Utility\String::pad($this->get('id')) . DS . \Hubzero\Utility\String::pad($this->get('version_id'));
     }
     switch (strtolower($type)) {
         case 'base':
             $path = $this->_basePath;
             break;
         case 'data':
             $path = $this->_basePath . DS . 'data';
             break;
         case 'logs':
             $path = $this->_basePath . DS . 'logs';
             break;
         case 'content':
         default:
             $path = $this->_basePath . DS . $this->get('secret');
             break;
     }
     return $root ? PATH_APP . $path : $path;
 }
Example #22
0
 /**
  * Download a citation for a resource
  *
  * @return     void
  */
 public function citationTask()
 {
     $yearFormat = 'Y';
     $monthFormat = 'M';
     // Get contribtool params
     $tconfig = Component::params('com_tools');
     // Incoming
     $id = Request::getInt('id', 0);
     $format = Request::getVar('format', 'bibtex');
     // Append DOI handle
     $revision = Request::getVar('rev', 0);
     $handle = '';
     if ($revision) {
         $rdoi = new Doi($this->database);
         $rdoi->loadDoi($id, $revision);
         if (isset($rdoi->doi) && $rdoi->doi && $tconfig->get('doi_shoulder')) {
             $handle = 'doi:' . $tconfig->get('doi_shoulder') . DS . strtoupper($rdoi->doi);
         } else {
             if ($rdoi->doi_label) {
                 $handle = 'doi:10254/' . $tconfig->get('doi_prefix') . $id . '.' . $rdoi->doi_label;
             }
         }
     }
     // Load the resource
     $row = new Resource($this->database);
     $row->load($id);
     $thedate = $row->publish_up != '0000-00-00 00:00:00' ? $row->publish_up : $row->created;
     $helper = new Helper($row->id, $this->database);
     $helper->getUnlinkedContributors();
     $row->author = $helper->ul_contributors;
     // Build the download path
     $path = PATH_APP . $this->config->get('cachepath', '/cache/resources');
     $date = $row->created;
     $dir_resid = \Hubzero\Utility\String::pad($row->id);
     if ($date && preg_match("#([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})#", $date, $regs)) {
         $date = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
     }
     $dir_year = date('Y', $date);
     $dir_month = date('m', $date);
     $path .= DS . $dir_year . DS . $dir_month . DS . $dir_resid . DS;
     if (!is_dir($path)) {
         if (!\Filesystem::makeDirectory($path)) {
             $this->setError('Error. Unable to create path.');
         }
     }
     // Build the URL for this resource
     $sef = Route::url('index.php?option=' . $this->_option . '&id=' . $row->id);
     $url = Request::base() . ltrim($sef, '/');
     // Choose the format
     switch ($format) {
         case 'endnote':
             $doc = '';
             switch ($row->type) {
                 case 'misc':
                 default:
                     $doc .= "%0 " . Lang::txt('COM_RESOURCES_GENERIC') . "\r\n";
                     break;
                     // generic
             }
             $doc .= "%D " . Date::of($thedate)->toLocal($yearFormat) . "\r\n";
             $doc .= "%T " . trim(stripslashes($row->title)) . "\r\n";
             $author_array = explode(';', $row->author);
             foreach ($author_array as $auth) {
                 $auth = preg_replace('/{{(.*?)}}/s', '', $auth);
                 if (!strstr($auth, ',')) {
                     $bits = explode(' ', $auth);
                     $n = array_pop($bits) . ', ';
                     $bits = array_map('trim', $bits);
                     $auth = $n . trim(implode(' ', $bits));
                 }
                 $doc .= "%A " . trim($auth) . "\r\n";
             }
             $doc .= "%U " . $url . "\r\n";
             if ($thedate) {
                 $doc .= "%8 " . Date::of($thedate)->toLocal($monthFormat) . "\r\n";
             }
             //$doc .= "\r\n";
             if ($handle) {
                 $doc .= "%1 " . 'doi:' . $handle;
                 $doc .= "\r\n";
             }
             $file = 'resource_' . $id . '.enw';
             $mime = 'application/x-endnote-refer';
             break;
         case 'bibtex':
         default:
             include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'BibTex.php';
             $bibtex = new \Structures_BibTex();
             $addarray = array();
             $addarray['type'] = 'misc';
             $addarray['cite'] = $this->_config['sitename'] . $row->id;
             $addarray['title'] = stripslashes($row->title);
             $auths = explode(';', $row->author);
             for ($i = 0, $n = count($auths); $i < $n; $i++) {
                 $author = trim($auths[$i]);
                 $author = preg_replace('/\\{\\{(.+)\\}\\}/i', '', $author);
                 if (strstr($author, ',')) {
                     $author_arr = explode(',', $author);
                     $author_arr = array_map('trim', $author_arr);
                     $addarray['author'][$i]['first'] = isset($author_arr[1]) ? trim($author_arr[1]) : '';
                     $addarray['author'][$i]['last'] = isset($author_arr[0]) ? trim($author_arr[0]) : '';
                 } else {
                     $author_arr = explode(' ', $author);
                     $author_arr = array_map('trim', $author_arr);
                     $last = array_pop($author_arr);
                     $addarray['author'][$i]['first'] = count($author_arr) > 0 ? implode(' ', $author_arr) : '';
                     $addarray['author'][$i]['last'] = $last ? trim($last) : '';
                 }
             }
             $addarray['month'] = Date::of($thedate)->toLocal($monthFormat);
             $addarray['url'] = $url;
             $addarray['year'] = Date::of($thedatez)->toLocal($yearFormat);
             if ($handle) {
                 $addarray['doi'] = $handle;
             }
             $bibtex->addEntry($addarray);
             $file = 'resource_' . $id . '.bib';
             $mime = 'application/x-bibtex';
             $doc = $bibtex->bibTex();
             break;
     }
     // Write the contents to a file
     $fp = fopen($path . $file, "w") or die("can't open file");
     fwrite($fp, $doc);
     fclose($fp);
     $this->_serveup(false, $path, $file, $mime);
     die;
     // REQUIRED
 }
Example #23
0
 /**
  * Build the path for uploading a resume to
  *
  * @param   integer  $uid  User ID
  * @return  mixed    False if errors, string otherwise
  */
 public function build_path($uid)
 {
     // Get the configured upload path
     $base_path = $this->params->get('webpath', '/site/members');
     $base_path = DS . trim($base_path, DS);
     $dir = \Hubzero\Utility\String::pad($uid);
     $listdir = $base_path . DS . $dir;
     if (!is_dir(PATH_APP . $listdir)) {
         if (!Filesystem::makeDirectory(PATH_APP . $listdir)) {
             return false;
         }
     }
     // Build the path
     return $listdir;
 }
Example #24
0
 /**
  * Format an ID by prefixing 0s.
  * This is used for directory naming
  *
  * @param      integer $someid ID to format
  * @return     string
  */
 public static function niceidformat($someid)
 {
     return \Hubzero\Utility\String::pad($someid);
 }
Example #25
0
 /**
  * Display a form for uploading an image and any data for current uploaded image
  *
  * @param      string  $file Image name
  * @param      integer $id   User ID
  * @return     void
  */
 public function displayTask($file = '', $id = 0)
 {
     // Do have an ID or do we need to get one?
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     $dir = String::pad($id);
     // Do we have a file or do we need to get one?
     $file = $file ? $file : Request::getVar('file', '');
     // Build the directory path
     $path = $this->path . DS . $dir;
     // Output form with error messages
     $this->view->title = $this->_title;
     $this->view->webpath = $this->config->get('uploadpath', '/site/quotes');
     $this->view->default_picture = $this->config->get('defaultpic', '/core/components/com_feedback/site/assets/img/contributor.gif');
     $this->view->path = $dir;
     $this->view->file = $file;
     $this->view->file_path = $path;
     $this->view->id = $id;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setLayout('display')->display();
 }
Example #26
0
 * @package   hubzero-cms
 * @author    Christopher Smoak <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
//default all pic vars
$picture = new stdClass();
$picture->src = $this->config->get('defaultpic');
$picture->name = 'n/a';
$picture->size = 'n/a';
$picture->width = 'n/a';
$picture->height = 'n/a';
//get user id in nice format
$uid = \Hubzero\Utility\String::pad($this->profile->get('uidNumber'));
//get profile pic and path to picture
$pic = $this->profile->get("picture");
$path = DS . trim($this->config->get("webpath", '/site/members'), DS) . DS . $uid . DS;
//if we have a picture and it exists in the file system
if ($pic && file_exists(PATH_APP . $path . $pic)) {
    $size = filesize(PATH_APP . $path . $pic);
    list($width, $height, $type, $attr) = getimagesize(PATH_APP . $path . $pic);
    $picture->src = substr(PATH_APP, strlen(PATH_ROOT)) . $path . $pic;
    $picture->name = $pic;
    $picture->size = \Hubzero\Utility\Number::formatBytes($size);
    $picture->width = $width . ' <abbr title="pixels">px</abbr>';
    $picture->height = $height . ' <abbr title="pixels">px</abbr>';
}
$default = $this->config->get('defaultpic', '/core/components/com_members/site/assets/img/profile.gif');
if ($default == '/components/com_members/assets/img/profile.gif') {