/** * 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; } }
* 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
/** * Build file path depending on configs * * @return string */ public function getFilePath($path, $id, $configs = NULL, $params = NULL, $suffix = NULL) { if (!$suffix && $params) { // Get file attachment params $fParams = new \Hubzero\Config\Registry($params); $suffix = $fParams->get('suffix'); } // Do we transfer file with subdirectories? if ($configs->dirHierarchy == 1) { $path = trim($path, DS); $name = $suffix ? \Components\Projects\Helpers\Html::fixFileName($path, ' (' . $suffix . ')') : $path; $fpath = $configs->pubPath . DS . $name; } elseif ($configs->dirHierarchy == 2) { // Do not preserve dir hierarchy, but append number for same-name files $name = $suffix ? \Components\Projects\Helpers\Html::fixFileName(basename($path), ' (' . $suffix . ')') : basename($path); $fpath = $configs->pubPath . DS . $name; } else { // Attach record number to file name $name = \Components\Projects\Helpers\Html::fixFileName(basename($path), '-' . $id); $fpath = $configs->pubPath . DS . $name; } return $fpath; }