/** * Return URL with fingerprint * @param type $sRootPath Path from root */ public static function getStaticProperUrl($sRootPath) { $sFilePath = Filesystem::path($sRootPath); $sFileName = Filesystem::name($sRootPath); $sFileExtension = Filesystem::extension($sRootPath); $sFileLastModificationDate = filemtime($sRootPath); $sUrl = Config::get('app.url') . $sFilePath . Config::get('format.dir.slash') . $sFileName . '_' . $sFileLastModificationDate . '_.' . $sFileExtension; return $sUrl; }
/** * Get a default image for the store item * * @param string $option Component name * @param string $item Item ID * @param string $root Root path * @param string $wpath Base path for files * @param string $alt Image alt text * @param string $category Item category * @return string HTML */ public static function productimage($option, $item, $root, $wpath, $alt, $category) { if ($wpath) { $wpath = DS . trim($wpath, DS) . DS; } $d = @dir($root . $wpath . $item); $images = array(); $html = ''; if ($d) { while (false !== ($entry = $d->read())) { $img_file = $entry; if (is_file($root . $wpath . $item . DS . $img_file) && substr($entry, 0, 1) != '.' && strtolower($entry) !== 'index.html') { if (preg_match("#bmp|gif|jpg|png|swf#i", $img_file)) { $images[] = $img_file; } } } $d->close(); } else { if ($category == 'service') { $html = '<span class="nophoto"></span>'; } else { $html = '<span class="nophoto premium"></span>'; } } sort($images); $els = ''; $k = 0; $g = 0; for ($i = 0, $n = count($images); $i < $n; $i++) { $ext = \Filesystem::extension($images[$i]); $tn = \Filesystem::name($images[$i]) . '-tn.'; if (!is_file($root . $wpath . $item . DS . $tn . $ext)) { $ext = 'gif'; } $tn = $tn . $ext; if (is_file($root . $wpath . $item . DS . $tn)) { $k++; $els .= '<a rel="lightbox" href="' . $wpath . $item . '/' . $images[$i] . '" title="' . $alt . '"><img src="' . $wpath . $item . '/' . $tn . '" alt="' . $alt . '" /></a>'; } } if ($els) { $html .= $els; } return $html; }
protected function getTypeOptionsFromLayouts($component, $view) { // Initialise variables. $options = array(); $layouts = array(); $layoutNames = array(); $templateLayouts = array(); $lang = Lang::getRoot(); // Get the layouts from the view folder. $path = PATH_CORE . '/components/' . $component . '/views/' . $view . '/tmpl'; $path2 = PATH_CORE . '/components/' . $component . '/site/views/' . $view . '/tmpl'; if (Filesystem::exists($path)) { $layouts = array_merge($layouts, Filesystem::files($path, '.xml$', false, true)); } else { if (Filesystem::exists($path2)) { $layouts = array_merge($layouts, Filesystem::files($path2, '.xml$', false, true)); } else { return $options; } } // build list of standard layout names foreach ($layouts as $layout) { $layout = trim($layout, '/'); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $file = $layout; // Get the layout name. $layoutNames[] = Filesystem::name(basename($layout)); } } // get the template layouts // TODO: This should only search one template -- the current template for this item (default of specified) $folders = Filesystem::directories(JPATH_SITE . '/templates', '', false, true); // Array to hold association between template file names and templates $templateName = array(); foreach ($folders as $folder) { if (Filesystem::exists($folder . '/html/' . $component . '/' . $view)) { $template = basename($folder); $lang->load('tpl_' . $template . '.sys', JPATH_SITE, null, false, true) || $lang->load('tpl_' . $template . '.sys', JPATH_SITE . '/templates/' . $template, null, false, true); $templateLayouts = Filesystem::files($folder . '/html/' . $component . '/' . $view, '.xml$', false, true); foreach ($templateLayouts as $layout) { $file = trim($layout, '/'); // Get the layout name. $templateLayoutName = Filesystem::name(basename($layout)); // add to the list only if it is not a standard layout if (array_search($templateLayoutName, $layoutNames) === false) { $layouts[] = $layout; // Set template name array so we can get the right template for the layout $templateName[$layout] = basename($folder); } } } } // Process the found layouts. foreach ($layouts as $layout) { $layout = trim($layout, '/'); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $file = $layout; // Get the layout name. $layout = Filesystem::name(basename($layout)); // Create the menu option for the layout. $o = new \Hubzero\Base\Object(); $o->title = ucfirst($layout); $o->description = ''; $o->request = array('option' => $component, 'view' => $view); // Only add the layout request argument if not the default layout. if ($layout != 'default') { // If the template is set, add in format template:layout so we save the template name $o->request['layout'] = isset($templateName[$file]) ? $templateName[$file] . ':' . $layout : $layout; } // Load layout metadata if it exists. if (is_file($file)) { // Attempt to load the xml file. if ($xml = simplexml_load_file($file)) { // Look for the first view node off of the root node. if ($menu = $xml->xpath('layout[1]')) { $menu = $menu[0]; // If the view is hidden from the menu, discard it and move on to the next view. if (!empty($menu['hidden']) && $menu['hidden'] == 'true') { unset($xml); unset($o); continue; } // Populate the title and description if they exist. if (!empty($menu['title'])) { $o->title = trim((string) $menu['title']); } if (!empty($menu->message[0])) { $o->description = trim((string) $menu->message[0]); } } } } // Add the layout to the options array. $options[] = $o; } } return $options; }
/** * Create thumb name * * @param string $image * @param string $tn * @param string $ext * * @return string */ public static function createThumbName($image = null, $tn = '_thumb', $ext = 'png') { return \Filesystem::name($image) . $tn . '.' . $ext; }
/** * Display an image * * @param integer $id Item ID * @return void */ public function displayTask($id = 0) { $this->view->type = $this->type; // Load the component config $this->view->config = $this->config; // Do have an ID or do we need to get one? $this->view->id = $id ? $id : Request::getInt('id', 0); // Do we have a file or do we need to get one? //$this->view->file = ($file) ? $file : Request::getVar('file', ''); // Build the directory path $this->view->path = DS . trim($this->config->get('webpath', '/site/store'), DS) . DS . $this->view->id; $folders = array(); $docs = array(); $imgs = array(); $path = PATH_APP . $this->view->path; if (is_dir($path)) { // Loop through all files and separate them into arrays of images, folders, and other $dirIterator = new DirectoryIterator($path); foreach ($dirIterator as $file) { if ($file->isDot()) { continue; } if ($file->isDir()) { $name = $file->getFilename(); $folders[$path . DS . $name] = $name; continue; } if ($file->isFile()) { $name = $file->getFilename(); if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) { continue; } if (preg_match("#bmp|gif|jpg|png|swf#i", $name)) { $base = \Filesystem::name($name); if (substr($base, -3) == '-tn') { continue; } $imgs[$path . DS . $name] = $name; } else { $docs[$path . DS . $name] = $name; } } } ksort($folders); ksort($docs); } $this->view->file = array_shift($imgs); // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('display')->display(); }
/** * Generate a thumbnail name from a file name * * @param string $pic File name * @return string */ public static function thumbnail($pic) { return \Filesystem::name($pic) . '-tn.gif'; }
/** * Create a thumbnail name * * @param string $image Image name * @param string $tn Thumbnail prefix * @return string */ public function createThumbName($image = null, $tn = '-tn') { if (!$image) { $image = $this->image; } if (!$image) { $this->setError(Lang::txt('No image set.')); return false; } $ext = \Filesystem::extension($image); $thumb = \Filesystem::name($image) . $tn . '.' . $ext; return $thumb; }
private function exportToJson($sJsonFilePath, array $aData, $bCompress = false) { $sNewJsonContent = Conversion::getJsonFromArray($aData, $bCompress); if (Filesystem::put($sJsonFilePath, $sNewJsonContent) !== false) { return Filesystem::name($sJsonFilePath) . '.' . Filesystem::extension($sJsonFilePath); } else { throw new FileNotCreatedException('File : ' . $sJsonFilePath); } }
/** * Get a list of special pages * * @return array */ public function special() { static $pages; if (!isset($pages)) { $path = PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'site' . DS . 'views' . DS . 'special' . DS . 'tmpl'; $pages = array(); if (is_dir($path)) { // Loop through all files and separate them into arrays of images, folders, and other $dirIterator = new \DirectoryIterator($path); foreach ($dirIterator as $file) { if ($file->isDot() || $file->isDir()) { continue; } if ($file->isFile()) { $name = $file->getFilename(); if (\Filesystem::extension($name) != 'php' || 'cvs' == strtolower($name) || '.svn' == strtolower($name)) { continue; } $pages[] = strtolower(\Filesystem::name($name)); } } sort($pages); } } return $pages; }