/** * Download file or folder from project (non-default connection providers only) * * @apiMethod GET * @apiUri /projects/{id}/files/connections/{cid}/download * @apiParameter { * "name": "id", * "description": "Project identifier (numeric ID or alias)", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "cid", * "description": "Connection identifier (numeric ID)", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "asset", * "description": "Array of file paths.", * "type": "array", * "required": true, * "default": "" * } * @apiParameter { * "name": "folder", * "description": "Array of folder paths.", * "type": "array", * "required": false, * "default": "" * } * @apiParameter { * "name": "subdir", * "description": "Directory path within project repo, if not already included in the asset file path.", * "type": "string", * "required": false, * "default": "", * "allowedValues": "" * } * @return void */ public function downloadTask() { $items = $this->_getCollection(); // Check items if (!$items || count($items) == 0) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_SHOW_HISTORY')); return; } if (count($items) > 1) { $archive = $items->compress(); $result = $archive->serve('project_files_' . \Components\Projects\Helpers\Html::generateCode(6, 6, 0, 1, 1) . '.zip'); // Delete the tmp file for serving $archive->delete(); } else { $result = $items->first()->serve(); } if (!$result) { // Should only get here on error throw new Exception(Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'), 404); } else { exit; } }
echo Route::url($this->model->link()); ?> "><?php echo \Hubzero\Utility\String::truncate($this->model->get('title'), 65); ?> </a> </span> <?php } ?> <span class="actor"><?php echo $a->admin == 1 ? Lang::txt('COM_PROJECTS_ADMIN') : $a->name; ?> </span> <span class="item-time">· <?php echo \Components\Projects\Helpers\Html::showTime($a->recorded, true); ?> </span> <?php if ($edit && $a->commentable) { ?> <?php if ($this->model->access('content')) { ?> <span class="item-comment">· <a href="#commentform_<?php echo $a->id; ?> " id="addc_<?php echo $a->id; ?> " data-inactive="<?php
/** * Suggest alias name (AJAX) * * @param int $ajax * @param string $name * @param int $pid * @return void */ public function suggestaliasTask() { // Incoming $title = isset($this->_text) ? $this->_text : trim(Request::getVar('text', '')); $title = urldecode($title); $suggested = Helpers\Html::suggestAlias($title); $maxLength = $this->config->get('max_name_length', 30); $maxLength = $maxLength > 30 ? 30 : $maxLength; $this->model->check($suggested, $maxLength); if ($this->model->getError()) { return false; } echo $suggested; return; }
/** * Compiles PDF/image preview for any kind of file * * @return string */ public function compile() { // Combine file and folder data $items = $this->getCollection(); // Incoming $download = Request::getInt('download', 0); // Check that we have compile enabled // @FIXME: why are latex and compiled preview tied together? // presumedly we are also 'compiling' pdfs? if (!$this->params->get('latex')) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_COMPILE_NOTALLOWED')); return; } // Output HTML $view = new \Hubzero\Plugin\View(['folder' => 'projects', 'element' => 'files', 'name' => 'connected', 'layout' => 'compiled']); // Make sure we have an item if (count($items) == 0) { $view->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_COMPILE')); $view->loadTemplate(); return; } // We can only handle one file at a time $file = $items->first(); // Build path for storing temp previews $imagePath = trim($this->model->config()->get('imagepath', '/site/projects'), DS); $outputDir = DS . $imagePath . DS . strtolower($this->model->get('alias')) . DS . 'compiled'; // Make sure output dir exists if (!is_dir(PATH_APP . $outputDir)) { if (!Filesystem::makeDirectory(PATH_APP . $outputDir)) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_UNABLE_TO_CREATE_UPLOAD_PATH')); return; } } // Get LaTeX helper $compiler = new \Components\Projects\Helpers\Compiler(); // Tex compiler path $texPath = DS . trim($this->params->get('texpath'), DS); // Set view args and defaults $view->file = $file; $view->oWidth = '780'; $view->oHeight = '460'; $view->url = $this->model->link('files'); $cExt = 'pdf'; // Tex file? $tex = $compiler->isTexFile($file->getName()); // Build temp name $tempBase = $tex ? 'temp__' . \Components\Projects\Helpers\Html::takeOutExt($file->getName()) : $file->getName(); $tempBase = str_replace(' ', '_', $tempBase); $view->data = $file->isImage() ? NULL : $file->read(); // LaTeX file? if ($tex && !empty($view->data)) { // Clean up data from Windows characters - important! $view->data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $view->data); // Store file locally $tmpfile = PATH_APP . $outputDir . DS . $tempBase; file_put_contents($tmpfile, $view->data); // Compile and get path to PDF $contentFile = $compiler->compileTex($tmpfile, $view->data, $texPath, PATH_APP . $outputDir, 1, $tempBase); // Read log (to show in case of error) $logFile = $tempBase . '.log'; if (file_exists(PATH_APP . $outputDir . DS . $logFile)) { $view->log = Filesystem::read(PATH_APP . $outputDir . DS . $logFile); } if (!$contentFile) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_TEX_FAILED')); } $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile); } else { // Make sure we can handle preview of this type of file if ($file->hasExtension('pdf') || $file->isImage() || !$file->isBinary()) { $origin = $this->connection->provider->alias . '://' . $file->getPath(); $dest = 'compiled://' . $tempBase; // Do the copy Manager::adapter('local', ['path' => PATH_APP . $outputDir . DS], 'compiled'); Manager::copy($origin, $dest); $contentFile = $tempBase; } } // Parse output if (!empty($contentFile) && file_exists(PATH_APP . $outputDir . DS . $contentFile)) { // Get compiled content mimetype $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile); // Is image? if (strpos($cType, 'image/') !== false) { // Fix up object width & height list($width, $height, $type, $attr) = getimagesize(PATH_APP . $outputDir . DS . $contentFile); $xRatio = $view->oWidth / $width; $yRatio = $view->oHeight / $height; if ($xRatio * $height < $view->oHeight) { // Resize the image based on width $view->oHeight = ceil($xRatio * $height); } else { // Resize the image based on height $view->oWidth = ceil($yRatio * $width); } } // Download compiled file? if ($download) { $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile); // Serve up file $server = new \Hubzero\Content\Server(); $server->filename(PATH_APP . $outputDir . DS . $contentFile); $server->disposition('attachment'); $server->acceptranges(false); $server->saveas($pdfName); $result = $server->serve(); if (!$result) { // Should only get here on error throw new Exception(Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'), 404); } else { exit; } } // Generate preview image for browsers that cannot embed pdf if ($cType == 'application/pdf') { // GS path $gspath = trim($this->params->get('gspath'), DS); if ($gspath && file_exists(DS . $gspath . DS . 'gs')) { $gspath = DS . $gspath . DS; $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile); $pdfPath = PATH_APP . $outputDir . DS . $contentFile; $exportPath = PATH_APP . $outputDir . DS . $tempBase . '%d.jpg'; exec($gspath . "gs -dNOPAUSE -sDEVICE=jpeg -r300 -dFirstPage=1 -dLastPage=1 -sOutputFile={$exportPath} {$pdfPath} 2>&1", $out); if (is_file(PATH_APP . $outputDir . DS . $tempBase . '1.jpg')) { $hi = new \Hubzero\Image\Processor(PATH_APP . $outputDir . DS . $tempBase . '1.jpg'); if (count($hi->getErrors()) == 0) { $hi->resize($view->oWidth, false, false, true); $hi->save(PATH_APP . $outputDir . DS . $tempBase . '1.jpg'); } else { return false; } } if (is_file(PATH_APP . $outputDir . DS . $tempBase . '1.jpg')) { $image = $tempBase . '1.jpg'; } } } } elseif (!$this->getError()) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_PREVIEW_FAILED')); } $view->file = $file; $view->outputDir = $outputDir; $view->embed = $contentFile; $view->cType = $cType; $view->subdir = $this->subdir; $view->option = $this->_option; $view->image = !empty($image) ? $image : NULL; $view->model = $this->model; $view->repo = $this->repo; $view->connection = $this->connection; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Update attachment record * * @return void */ public function saveItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0) { $aid = $aid ? $aid : Request::getInt('aid', 0); // Load classes $row = new \Components\Publications\Tables\Author($this->_parent->_db); $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); // We need attachment record if (!$aid || !$row->load($aid) || $row->publication_version_id != $pub->version_id) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_LOAD_AUTHOR')); return false; } // Instantiate a new registration object include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'registration.php'; $xregistration = new \Components\Members\Models\Registration(); // Get current owners $owners = $objO->getIds($pub->_project->get('id'), 'all', 1); $email = Request::getVar('email', '', 'post'); $firstName = Request::getVar('firstName', '', 'post'); $lastName = Request::getVar('lastName', '', 'post'); $org = Request::getVar('organization', '', 'post'); $credit = Request::getVar('credit', '', 'post'); $sendInvite = 0; $code = \Components\Projects\Helpers\Html::generateCode(); $uid = Request::getInt('uid', 0, 'post'); $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/'; $email = preg_match($regex, $email) ? $email : ''; if (!$firstName || !$lastName) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED')); return false; } $row->organization = $org; $row->firstName = $firstName; $row->lastName = $lastName; $row->name = $row->firstName . ' ' . $row->lastName; $row->credit = $credit; $row->modified_by = $actor; $row->modified = Date::toSql(); // Check that profile exists if ($uid) { $profile = User::getInstance($uid); $uid = $profile->get('id') ? $uid : 0; } // Tying author to a user account? if ($uid && !$row->user_id) { // Do we have an owner with this user id? $owner = $objO->getOwnerId($pub->_project->get('id'), $uid); if ($owner) { // Update owner assoc $row->project_owner_id = $owner; } else { // Update associated project owner account if ($objO->load($row->project_owner_id) && !$objO->userid) { $objO->userid = $uid; $objO->status = 1; $objO->store(); } } } $row->user_id = $uid; if ($row->store()) { $this->set('_message', Lang::txt('Author record saved')); // Reflect the update in curation record $this->_parent->set('_update', 1); } else { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_AUTHORS_ERROR_SAVING_AUTHOR_INFO')); return false; } // Update project owner (invited) if ($email && !$row->user_id && $objO->load($row->project_owner_id)) { $invitee = $objO->checkInvited($pub->_project->get('id'), $email); // Do we have a registered user with this email? $user = $xregistration->getEmailId($email); if ($invitee && $invitee != $row->project_owner_id) { // Stop, must have owner record } elseif (in_array($user, $owners)) { // Stop, already in team } elseif ($email != $objO->invited_email) { $objO->invited_email = $email; $objO->invited_name = $row->name; $objO->userid = $row->user_id; $objO->invited_code = $code; $objO->store(); $sendInvite = 1; } } // (Re)send email invitation if ($sendInvite && $email) { // Get project model $project = new \Components\Projects\Models\Project($pub->_project->get('id')); // Plugin params $plugin_params = array(0, $email, $code, 2, $project, 'com_projects'); // Send invite $output = Event::trigger('projects.sendInviteEmail', $plugin_params); $result = json_decode($output[0]); } return true; }
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ // No direct access defined('_HZEXEC_') or die; if ($this->getError()) { echo '<p class="error">' . $this->getError() . '</p>'; return; } $name = $this->file->get('name'); // Is this a duplicate remote? if ($this->file->get('remote') && $this->file->get('name') != $this->file->get('remoteTitle')) { $append = \Components\Projects\Helpers\Html::getAppendedNumber($this->file->get('name')); if ($append > 0) { $name = \Components\Projects\Helpers\Html::fixFileName($this->file->get('remoteTitle'), ' (' . $append . ')', $this->file->get('ext')); } } // Do not display Google native extension $native = \Components\Projects\Helpers\Google::getGoogleNativeExts(); if (in_array($this->file->get('ext'), $native)) { $name = preg_replace("/." . $this->file->get('ext') . "\\z/", "", $name); } ?> <h4><img src="<?php echo $this->file->getIcon(); ?> " alt="<?php echo $this->file->get('ext'); ?> " /> <?php
/** * Process parsed data * * @access public * @return string */ public function processRecord($item, &$out) { // Create publication record if (!$item['publication']->store()) { return false; } $pid = $item['publication']->id; // Create version record $item['version']->publication_id = $pid; $item['version']->version_number = 1; $item['version']->created_by = $this->_uid; $item['version']->created = Date::toSql(); $item['version']->secret = strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1)); $item['version']->access = 0; $item['version']->main = 1; $item['version']->state = 3; if (!$item['version']->store()) { // Roll back $item['publication']->delete(); return false; } $vid = $item['version']->id; // Build pub object $pub = new stdClass(); $pub = $item['version']; $pub->id = $pid; $pub->version_id = $vid; // Build version object $version = new stdClass(); $version->secret = $item['version']->secret; $version->id = $vid; $version->publication_id = $pid; // Create attachments records and attach files foreach ($item['files'] as $fileRecord) { $this->processFileData($fileRecord, $pub, $version); } // Create author records foreach ($item['authors'] as $authorRecord) { $this->processAuthorData($authorRecord['author'], $pid, $vid); } // Build tags string if ($item['tags']) { $tags = ''; $i = 0; foreach ($item['tags'] as $tag) { $i++; $tags .= trim($tag); $tags .= $i == count($item['tags']) ? '' : ','; } // Add tags $tagsHelper = new \Components\Publications\Helpers\Tags($this->database); $tagsHelper->tag_object($this->_uid, $pid, $tags, 1); } // Display results $out .= '<p class="publication">#' . $pid . ': <a href="' . trim($this->site, DS) . '/publications/' . $pid . DS . '1" rel="external">' . $item['version']->title . ' v.' . $item['version']->version_label . '</a></p>'; return true; }
/** * Build local path for remote items with the same name * * @param string $id Remote ID * @param string $fpath File path * @param string $format mime type * @param array $connections Array of local-remote connections * @param array &$remotes Collector array for active items * @param array &$duplicates Collector array for duplicates * * @return void */ public static function buildDuplicatePath($id = 0, $fpath, $format = '', $connections, &$remotes, &$duplicates) { // Do we have a record with another ID linked to the same path? $pathTaken = isset($connections['paths'][$fpath]) && $connections['paths'][$fpath]['remote_id'] != $id && $connections['paths'][$fpath]['format'] == $format ? true : false; // Deal with duplicate names if (isset($remotes[$fpath]) && $remotes[$fpath]['mimeType'] == $format || $pathTaken == true) { if (isset($duplicates[$fpath])) { $duplicates[$fpath][] = $id; } else { $duplicates[$fpath] = array(); $duplicates[$fpath][] = $id; } // Append duplicate count to file name $appended = \Components\Projects\Helpers\Html::getAppendedNumber($fpath); $num = $appended ? $appended + 1 : 1; if ($appended) { $fpath = \Components\Projects\Helpers\Html::cleanFileNum($fpath, $appended); } $fpath = \Components\Projects\Helpers\Html::fixFileName($fpath, '-' . $num); // Check that new path isn't used either return self::buildDuplicatePath($id, $fpath, $format, $connections, $remotes, $duplicates); } else { return $fpath; } }
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * HUBzero is a registered trademark of Purdue University. * * @package hubzero-cms * @author Sam Wilson <*****@*****.**> * @copyright Copyright 2005-2015 HUBzero Foundation, LLC. * @license http://opensource.org/licenses/MIT MIT */ // No direct access defined('_HZEXEC_') or die; // Directory path breadcrumbs $bc = \Components\Projects\Helpers\Html::buildFileBrowserCrumbs($this->subdir, $this->url, $parent, false, $this->connection->adapter()); $bcEnd = $this->item->isDir() ? '<span class="folder">' . $this->item->getName() . '</span>' : '<span class="file">' . $this->item->getName() . '</span>'; $lang = $this->item->isDir() ? 'folder' : 'file'; ?> <div id="abox-content"> <h3> <?php echo Lang::txt('PLG_PROJECTS_FILES_RENAME') . ' ' . $lang . ' ' . $bc . ' ' . $bcEnd; ?> </h3> <?php if ($this->getError()) { ?> <p class="witherror"><?php $this->getError();
?> " title="<?php echo $this->escape($file->get('name')); ?> "><?php echo $file->drawIcon($ext); ?> <?php echo \Components\Projects\Helpers\Html::shortenFileName($file->get('name')); ?> </a> <span class="block faded mini"> <?php echo $file->getSize('formatted'); ?> · <?php echo Date::of($file->get('date'))->toLocal('M d, Y'); ?> · <?php echo \Components\Projects\Helpers\Html::shortenName($file->get('author')); ?> </span> </li> <?php } ?> </ul><?php } ?> </div>
/** * Save updated CSV file with headers * * @param integer $id Database ID * @return void */ public function _save_csv($id) { $db = $this->get_ds_db($this->model->get('id')); // Get project database object $objPD = new \Components\Projects\Tables\Database($this->_database); // Get project path $path = \Components\Projects\Helpers\Html::getProjectRepoPath($this->model->get('alias')); $path .= DS; if ($objPD->loadRecord($id)) { $db = $this->get_ds_db($objPD->project); $table = $objPD->database_name; $title = $objPD->title; $file = $objPD->source_file; $dir = $objPD->source_dir != '' ? $objPD->source_dir . DS : ''; $dd = json_decode($objPD->data_definition, true); $header = array(); $field_list = array(); foreach ($dd['cols'] as $field => $prop) { $field_list[] = $field; $header[0][] = $prop['label']; unset($prop['label']); unset($prop['idx']); unset($prop['styles']); $header[1][] = rtrim(ltrim(str_replace('","', "\",\r\n\"", json_encode($prop)), '{'), '}'); } $header[2] = array('DATASTART'); $path .= $dir; $fp = fopen($path . $file, 'w+'); foreach ($header as $h) { fputcsv($fp, $h); } $sql = "SELECT " . implode(', ', $field_list) . " FROM {$table}"; $db->setQuery($sql); $res = $db->query(); while ($row = $res->fetch_array(MYSQLI_NUM)) { fputcsv($fp, $row); } fclose($fp); // Commit update file $commit_message = Lang::txt('PLG_PROJECTS_DATABASES_UPDATED_FILE') . ' ' . escapeshellarg($file); $author = escapeshellarg(User::get('name') . ' <' . User::get('email') . '> '); chdir($path); exec($this->gitpath . ' add ' . escapeshellarg($file)); exec($this->gitpath . ' commit ' . escapeshellarg($file) . ' -m "' . $commit_message . '"' . ' --author="' . $author . '" 2>&1'); // Update source_revision with the current commit hash chdir($path); exec($this->gitpath . ' log --pretty=format:%H ' . escapeshellarg($file) . '|head -1', $hash); $hash = isset($hash[0]) ? $hash[0] : 0; $objPD->source_revision = $hash; $objPD->store(); $msg = Lang::txt('PLG_PROJECTS_DATABASES_UPDATED_FILE') . ' "' . $file . '"' . Lang::txt('PLG_PROJECTS_DATABASES_IN_PROJECT'); $this->model->recordActivity(str_replace("'", "\\'", $msg), $file, 'files', Route::url('index.php?option=' . $this->_option . '&alias=' . $this->model->get('alias') . '&active=files'), 'files', 1); ob_clean(); } }
/** * Get disk space * * @param object $model * * @return string */ public function pubDiskSpace($model) { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'diskspace')); // Include styling and js \Hubzero\Document\Assets::addPluginStylesheet('projects', 'files', 'diskspace'); \Hubzero\Document\Assets::addPluginScript('projects', 'files', 'diskspace'); $database = App::get('db'); // Build query $filters = array(); $filters['limit'] = Request::getInt('limit', 25); $filters['start'] = Request::getInt('limitstart', 0); $filters['sortby'] = Request::getVar('t_sortby', 'title'); $filters['sortdir'] = Request::getVar('t_sortdir', 'ASC'); $filters['project'] = $model->get('id'); $filters['ignore_access'] = 1; $filters['dev'] = 1; // get dev versions // Instantiate project publication $objP = new \Components\Publications\Tables\Publication($database); // Get all publications $view->rows = $objP->getRecords($filters); // Get used space $view->dirsize = \Components\Publications\Helpers\Html::getDiskUsage($view->rows); $view->params = $model->params; $view->quota = $view->params->get('pubQuota') ? $view->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b'); // Get total count $view->total = $objP->getCount($filters); $view->project = $model; $view->option = $this->_option; $view->title = isset($this->_area['title']) ? $this->_area['title'] : ''; return $view->loadTemplate(); }
} else { if ($row->state == 0) { $status = '<span class="faded italic">' . Lang::txt('Inactive/Suspended') . '</span> '; } else { if ($row->state == 5) { $status = '<span class="inactive">' . Lang::txt('Pending approval') . '</span> '; } } } } } $cloud = new \Components\Projects\Models\Tags($row->id); $tags = $cloud->render('cloud'); $params = new \Hubzero\Config\Registry($row->params); $quota = $params->get('quota', $this->defaultQuota); $quota = \Components\Projects\Helpers\Html::convertSize($quota, 'b', 'GB', 2); ?> <tr class="<?php echo "row{$k}"; ?> "> <td><?php echo Html::grid('id', $i, $row->id, false, 'id'); ?> </td> <td class="priority-5"><?php echo $row->id; ?> </td> <td class="priority-5"><?php echo '<img src="' . rtrim($base, DS) . DS . 'projects' . DS . $row->alias . '/media' . '" width="30" height="30" alt="' . $this->escape($row->alias) . '" />';
/** * Check for required formats * * @return object */ public function checkRequired($attachments, $formats = array()) { if (empty($attachments)) { return true; } if (empty($formats)) { return true; } $i = 0; foreach ($attachments as $attach) { $file = isset($attach->path) ? $attach->path : $attach; $ext = \Components\Projects\Helpers\Html::getFileExtension($file); if ($ext && in_array(strtolower($ext), $formats)) { $i++; } } if ($i < count($formats)) { return false; } return true; }
public static function listDirHtml($dir = null, $currentDir = '') { if ($dir == null) { $dir = new stdClass(); } $leftMargin = $dir->depth * 15 . 'px'; $html = '<li style="margin-left:'; $html .= $leftMargin; $html .= '"><input type="radio" name="newpath" value="'; $html .= urlencode($dir->path); $html .= '"'; if ($currentDir == $dir->path) { $html .= 'disabled="disabled" '; } $html .= '/> <span><span class="folder '; if ($currentDir == $dir->path) { $html .= 'prominent '; } $html .= '">'; $html .= $dir->name; $html .= '</span></span></li>'; if (count($dir->subdirs) > 0) { foreach ($dir->subdirs as $subdir) { $html .= \Components\Projects\Helpers\Html::listDirHtml($subdir, $currentDir); } } return $html; }
<?php echo \Components\Projects\Helpers\Html::shortenFileName($item->getName(), 60); ?> </a> <?php } ?> </td> <td class="shrinked"></td> <td class="shrinked"><?php echo $item->isFile() ? $item->getSize() : ''; ?> </td> <td class="shrinked"> <?php echo $item->getTimestamp() ? \Components\Projects\Helpers\Html::formatTime(Date::of($item->getTimestamp())->toSql()) : 'N/A'; ?> </td> <td class="shrinked"> <?php echo $item->getOwner() == User::get('id') ? Lang::txt('PLG_PROJECTS_FILES_ME') : User::getRoot()->getInstance($item->getOwner())->get('name'); ?> </td> <td class="shrinked nojs"> <?php if ($this->model->access('content')) { ?> <a href="<?php echo Route::url($this->model->link('files') . '&action=delete' . $subdirPath . '&asset=' . urlencode($item->getName())); ?> " title="<?php
/** * Get project thumbnail source * * @return string */ public function getThumbSrc() { if (!$this->model->exists()) { return false; } $src = ''; $path = PATH_APP . DS . trim($this->config->get('imagepath', '/site/projects'), DS) . DS . $this->model->get('alias') . DS . 'images'; if (file_exists($path . DS . 'thumb.png')) { return $path . DS . 'thumb.png'; } if ($this->model->get('picture')) { $thumb = Helpers\Html::createThumbName($this->model->get('picture')); $src = $thumb && file_exists($path . DS . $thumb) ? $path . DS . $thumb : NULL; } if (!$src) { $path = trim($this->config->get('defaultpic', 'components/com_projects/site/assets/img/project.png'), DS); if ($path == 'components/com_projects/assets/img/project.png') { $path = 'components/com_projects/site/assets/img/project.png'; } $src = PATH_CORE . DS . $path; } return $src; }
?> <td class="mini"><?php echo $info; ?> </td> <td class="mini"><?php if (!$params->get('grant_approval') && $params->get('grant_status', 0) == 0) { echo '<span class="italic pending">' . Lang::txt('COM_PROJECTS_STATUS_PENDING_SPS') . '</span>'; } else { if ($params->get('grant_approval') || $params->get('grant_status') == 1) { echo '<span class="active green">' . Lang::txt('COM_PROJECTS_APPROVAL_CODE') . ': ' . $params->get('grant_approval', '(N/A)') . '</span>'; } else { if ($params->get('grant_status') == '2') { echo '<span class="italic dark">' . Lang::txt('COM_PROJECTS_STATUS_SPS_REJECTED') . '</span>'; } } } if ($this->row->get('admin_notes')) { echo \Components\Projects\Helpers\Html::getLastAdminNote($this->row->get('admin_notes'), 'sponsored'); } ?> </td> <td class="faded actions"><?php echo '<span class="manage mini"><a href="' . Route::url('index.php?option=' . $this->option . '&task=process&id=' . $this->row->get('id')) . '?reviewer=' . $this->filters['reviewer'] . '&filterby=' . $this->filters['filterby'] . '" class="showinbox">' . Lang::txt('COM_PROJECTS_MANAGE') . '</a></span>'; ?> </td> <?php } } ?> </tr>
?> "> <?php if ($item->get('type') == 'folder') { ?> <span class="collapsor"> </span><?php } ?> <img src="<?php echo $item->get('icon'); ?> " alt="" /> <span title="<?php echo $item->get('localPath'); ?> "><?php echo \Components\Projects\Helpers\Html::shortenFileName($item->get('name'), 50); ?> </span> </span> </li> <?php } } else { ?> <li class="noresults <?php echo ($parent = Request::getString('parent', '')) ? 'parent-' . $parent : ''; ?> "><?php echo $this->model->isProvisioned() ? Lang::txt('PLG_PROJECTS_FILES_SELECTOR_NO_FILES_FOUND_PROV') : Lang::txt('PLG_PROJECTS_FILES_SELECTOR_NO_FILES_FOUND'); ?>
?> Master Repository</span> </span> </li> <?php foreach ($this->connections as $connection) { ?> <?php $imgRel = '/plugins/filesystem/' . $connection->provider->alias . '/assets/img/icon.png'; ?> <?php $img = is_file(PATH_APP . DS . $imgRel) ? '/app' . $imgRel : '/core' . $imgRel; ?> <?php $id = 'dir-' . strtolower(\Components\Projects\Helpers\Html::generateCode(5, 5, 0, 1, 1)); ?> <li class="type-folder collapsed connection" id="<?php echo $id; ?> " data-connection="<?php echo $connection->id; ?> " data-path="."> <span class="item-info"></span> <span class="item-wrap collapsor"> <span class="collapsor-indicator"> </span> <img src="<?php echo $img; ?> " alt="" />
echo ucfirst(Lang::txt('PLG_PROJECTS_TEAM_RECENT_VISITS')); ?> </a></h4> <ul> <?php foreach ($show as $owner) { // Do not show more than 5 if ($i >= 5) { break; } // Get profile thumb image $profile = User::getInstance($owner->userid); $actor = User::getInstance(User::get('id')); $thumb = $profile->get('id') ? $profile->picture() : $actor->picture(true); $timecheck = date('Y-m-d H:i:s', time() - 15 * 60); $lastvisit = $owner->lastvisit && $owner->lastvisit != '0000-00-00 00:00:00' ? \Components\Projects\Helpers\Html::timeAgo($owner->lastvisit) . ' ' . Lang::txt('PLG_PROJECTS_TEAM_AGO') : Lang::txt('PLG_PROJECTS_TEAM_NEVER'); $lastvisit = $owner->userid == User::get('id') || !empty($owner->online) && $owner->lastvisit > $timecheck ? '<span class="online">' . Lang::txt('PLG_PROJECTS_TEAM_ONLINE_NOW') . '</span>' : $lastvisit; $i++; ?> <li> <span class="pub-thumb"><img src="<?php echo $thumb; ?> " alt=""/></span> <span class="pub-details"> <span class="block"><a href="/members/<?php echo $owner->userid; ?> "><?php echo $owner->fullname; ?>
/** * Get File Previews * * @param string $ref Reference to files * @return mixed */ protected function _getFilesPreview($ref = '') { if (!$ref) { return false; } if (!$this->_path) { // Get project file path $this->_path = \Components\Projects\Helpers\Html::getProjectRepoPath($this->model->get('alias')); } // We do need project file path if (!$this->_path || !is_dir($this->_path)) { return false; } $files = explode(',', $ref); $selected = array(); $maxHeight = 0; $minHeight = 0; $minWidth = 0; $maxWidth = 0; $imagepath = trim($this->_config->get('imagepath', '/site/projects'), DS); $to_path = DS . $imagepath . DS . strtolower($this->model->get('alias')) . DS . 'preview'; foreach ($files as $item) { $parts = explode(':', $item); $file = count($parts) > 1 ? $parts[1] : $parts[0]; $hash = count($parts) > 1 ? $parts[0] : NULL; if ($hash) { // Only preview mid-size images from now on $hashed = md5(basename($file) . '-' . $hash) . '.png'; if (is_file(PATH_APP . $to_path . DS . $hashed)) { $preview['image'] = $hashed; $preview['url'] = NULL; $preview['title'] = basename($file); // Get image properties list($width, $height, $type, $attr) = getimagesize(PATH_APP . $to_path . DS . $hashed); $preview['width'] = $width; $preview['height'] = $height; $preview['orientation'] = $width > $height ? 'horizontal' : 'vertical'; // Record min and max width and height to build image grid if ($height >= $maxHeight) { $maxHeight = $height; } if ($height && $height <= $minHeight) { $minHeight = $height; } else { $minHeight = $height; } if ($width > $maxWidth) { $maxWidth = $width; } $selected[] = $preview; } } } // No files for preview if (empty($selected)) { return false; } // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => $this->_name, 'name' => 'preview', 'layout' => 'files')); $view->maxHeight = $maxHeight; $view->maxWidth = $maxWidth; $view->minHeight = $minHeight > 400 ? 400 : $minHeight; $view->selected = $selected; $view->option = $this->_option; $view->model = $this->model; return $view->loadTemplate(); }
/** * Is binary? * * @return mixed */ public function isBinary() { return Helpers\Html::isBinary($this->get('fullPath')); }
<?php echo $this->subdir ? Lang::txt('PLG_PROJECTS_FILES_THIS_DIRECTORY_IS_EMPTY') : Lang::txt('PLG_PROJECTS_FILES_PROJECT_HAS_NO_FILES'); ?> </p> <?php } ?> <p class="extras"> <?php if ($this->repo->get('name') == 'local') { ?> <span class="leftfloat"> <?php // Used disk space and remaining quota $dirsize = $this->repo->call('getDiskUsage', $params = array('git' => $this->fileparams->get('disk_usage'))); $quota = $this->model->params->get('quota') ? $this->model->params->get('quota') : \Components\Projects\Helpers\Html::convertSize(floatval($this->model->config()->get('defaultQuota', '1')), 'GB', 'b'); // Disc space indicator $this->view('_mini', 'diskspace')->set('quota', $quota)->set('dirsize', $dirsize)->set('config', $this->model->config())->set('url', Route::url($this->model->link('files')))->display(); ?> </span> <?php } ?> <?php if ($this->model->access('content')) { ?> <span class="rightfloat"> <a href="<?php echo Route::url($this->model->link('files')) . '?action=trash'; ?> " class="showinbox"><?php
/** * Event call after file update * * @param object $model * @param array $changes * @return void */ public function onAfterUpdate($model = NULL, $changes = array()) { $activity = ''; $message = ''; $ref = ''; $sync = 0; $model = $model ? $model : $this->model; if (empty($changes)) { // Get session $jsession = App::get('session'); // Get values from session $updated = $jsession->get('projects.' . $model->get('alias') . '.updated'); $uploaded = $jsession->get('projects.' . $model->get('alias') . '.uploaded'); $failed = $jsession->get('projects.' . $model->get('alias') . '.failed'); $deleted = $jsession->get('projects.' . $model->get('alias') . '.deleted'); $restored = $jsession->get('projects.' . $model->get('alias') . '.restored'); $expanded = $jsession->get('projects.' . $model->get('alias') . '.expanded'); // Clean up session values $jsession->set('projects.' . $model->get('alias') . '.failed', ''); $jsession->set('projects.' . $model->get('alias') . '.updated', ''); $jsession->set('projects.' . $model->get('alias') . '.uploaded', ''); $jsession->set('projects.' . $model->get('alias') . '.deleted', ''); $jsession->set('projects.' . $model->get('alias') . '.restored', ''); $jsession->set('projects.' . $model->get('alias') . '.expanded', ''); } else { $updated = !empty($changes['updated']) ? $changes['updated'] : NULL; $uploaded = !empty($changes['uploaded']) ? $changes['uploaded'] : NULL; $failed = !empty($changes['failed']) ? $changes['failed'] : NULL; $deleted = !empty($changes['deleted']) ? $changes['deleted'] : NULL; $restored = !empty($changes['restored']) ? $changes['restored'] : NULL; $expanded = !empty($changes['expanded']) ? $changes['expanded'] : NULL; } // Provisioned project? if ($model->isProvisioned() || !$model->get('id')) { return false; } // Pass success or error message if (!empty($failed) && !$uploaded && !$uploaded) { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ERROR_FAILED_TO_UPLOAD') . $failed, 'error', 'projects'); } elseif ($uploaded || $updated || $expanded) { $uploadParts = explode(',', $uploaded); $updateParts = explode(',', $updated); $sync = 1; if ($uploaded) { if (count($uploadParts) > 2) { $message = 'uploaded ' . basename($uploadParts[0]) . ' and ' . (count($uploadParts) - 1) . ' more files '; } else { $message = 'uploaded '; $u = 0; foreach ($uploadParts as $part) { $message .= basename($part); $u++; $message .= count($uploadParts) == $u ? '' : ', '; } } // Save referenced files $ref = $uploaded; } if ($updated) { $message .= $uploaded ? '. Updated ' : 'updated '; if (count($updateParts) > 2) { $message .= basename($updateParts[0]) . ' and ' . (count($updateParts) - 1) . ' more files '; } else { $u = 0; foreach ($updateParts as $part) { $message .= basename($part); $u++; $message .= count($updateParts) == $u ? '' : ', '; } } } $activity = $message . ' ' . strtolower(Lang::txt('PLG_PROJECTS_FILES_IN_PROJECT_FILES')); $message = 'Successfully ' . $message; $message .= $failed ? ' There was a problem uploading ' . $failed : ''; \Notify::message($message, 'success', 'projects'); } elseif ($deleted) { // Save referenced files $ref = $deleted; $sync = 1; $delParts = explode(',', $deleted); $what = count($delParts) == 1 ? $deleted : count($delParts) . ' ' . Lang::txt('PLG_PROJECTS_FILES_ITEMS'); // Output message \Notify::message(Lang::txt('PLG_PROJECTS_FILES_SUCCESS_DELETED') . ' ' . $what, 'success', 'projects'); } elseif ($restored) { // Save referenced files $ref = $restored; $sync = 1; $resParts = explode(',', $restored); $activity = 'restored deleted file ' . basename($resParts[0]); // Output message \Notify::message(Lang::txt('PLG_PROJECTS_FILES_SUCCESS_RESTORED') . ' ' . basename($resParts[0]), 'success', 'projects'); } // Add activity to feed if ($activity && $model->repo()->isLocal()) { $refParts = explode(',', $ref); $parsedRef = ''; $selected = array(); foreach ($refParts as $item) { $file = $model->repo()->getMetadata(trim($item)); $params = array('file' => $file); if ($file->exists()) { $hash = $model->repo()->getLastRevision($params); if ($hash) { $selected[] = substr($hash, 0, 10) . ':' . trim($file->get('localPath')); // Generate preview (regular and medium-size) $file->getPreview($model, $hash); $file->getPreview($model, $hash, '', 'medium'); } } } // Save hash and file name in a reference if ($selected) { foreach ($selected as $sel) { if (strlen($parsedRef) + strlen($sel) <= 254) { $parsedRef .= $sel . ','; } else { break; } } $parsedRef = substr($parsedRef, 0, strlen($parsedRef) - 1); } // Check to make sure we are not over in char length if (strlen($parsedRef) > 255) { $parsedRef = \Components\Projects\Helpers\Html::shortenText($parsedRef); } // Force sync if ($sync) { //$this->model->saveParam('google_sync_queue', 1); $this->set('forceSync', 1); } // Record activity $aid = $model->recordActivity($activity, $parsedRef, 'files', Route::url($model->link('files')), 'files', 1); } }
</tr> <tr> <th><?php echo Lang::txt('COM_PROJECTS_LAST_ACTIVITY'); ?> :</th> <td><?php if ($this->last_activity) { $activity = preg_replace('/said/', "posted an update", $this->last_activity->activity); $activity = preg_replace('/:/', "", $activity); ?> <?php echo $this->last_activity->recorded; ?> (<?php echo \Components\Projects\Helpers\Html::timeAgo($this->last_activity->recorded) . ' ' . Lang::txt('COM_PROJECTS_AGO'); ?> ) <br /> <span class="actor"><?php echo $this->last_activity->name; ?> </span> <?php echo $activity; ?> <?php } else { echo Lang::txt('COM_PROJECTS_NA'); } ?> </td> </tr> </tbody>
if ($this->row->comments() && $this->row->comments() instanceof \Hubzero\Base\ItemList) { ?> <ul id="td-comments"> <?php foreach ($this->row->comments() as $comment) { ?> <li> <p><?php echo $comment->content('parsed'); ?> </p> <p class="todo-assigned"><?php echo $comment->creator('name'); ?> <span class="date"> · <?php echo \Components\Projects\Helpers\Html::timeAgo($comment->get('created')) . ' ' . Lang::txt('PLG_PROJECTS_TODO_AGO'); ?> </span> <?php if ($comment->get('created_by') == $this->uid) { ?> <a href="<?php echo Route::url($url . '&action=deletecomment') . '/?todoid=' . $this->row->get('id') . '&cid=' . $comment->get('id'); ?> " id="delc-<?php echo $comment->get('id'); ?> " class="confirm-it">[<?php echo Lang::txt('PLG_PROJECTS_TODO_DELETE'); ?> ]</a><?php }
/** * Return a formatted timestamp * * @param string $key Field to return * @param string $as What data to return * @return string */ protected function _date($key, $as = '') { if ($this->get($key) == $this->_db->getNullDate()) { return NULL; } switch (strtolower($as)) { case 'date': return Date::of($this->get($key))->toLocal(Lang::txt('DATE_FORMAT_HZ1')); break; case 'time': return Date::of($this->get($key))->toLocal(Lang::txt('TIME_FORMAT_HZ1')); break; case 'datetime': return $this->_date($key, 'date') . ' @ ' . $this->_date($key, 'time'); break; case 'timeago': return \Components\Projects\Helpers\Html::timeAgo($this->get($key)); break; default: return $this->get($key); break; } }
/** * Unlock sync and view sync log for project * * @return void */ public function fixsyncTask() { $id = Request::getVar('id', 0); $service = 'google'; // Initiate extended database class $obj = new Tables\Project($this->database); if (!$id or !$obj->loadProject($id)) { App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error'); return; } // Unlock sync $obj->saveParam($id, $service . '_sync_lock', ''); // Get log file $repodir = Helpers\Html::getProjectRepoPath($obj->alias, 'logs'); $sfile = $repodir . DS . 'sync.' . Date::format('Y-m') . '.log'; if (file_exists($sfile)) { // Serve up file $server = new \Hubzero\Content\Server(); $server->filename($sfile); $server->disposition('attachment'); $server->acceptranges(false); $server->saveas('sync.' . Date::format('Y-m') . '.txt'); $result = $server->serve_attachment($sfile, 'sync.' . Date::format('Y-m') . '.txt', false); exit; } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false), Lang::txt('Sync log unavailable')); }
</span> <?php } ?> <img class="comment-author" src="<?php echo $creator->getPicture($comment->admin); ?> " alt="" /> <div class="comment-show"> <span class="comment-details"> <span class="actor"><?php echo $comment->admin == 1 ? Lang::txt('COM_PROJECTS_ADMIN') : $comment->author; ?> </span> <span class="item-time">· <?php echo \Components\Projects\Helpers\Html::showTime($comment->created, true); ?> </span> </span> <?php echo '<div class="body">' . $shortComment; if ($shorten) { echo ' <a href="#" class="more-content">' . Lang::txt('COM_PROJECTS_MORE') . '</a>'; } echo '</div>'; ?> <?php if ($shorten) { echo '<div class="fullbody hidden">' . $longComment . '</div>'; } ?>