private function readFileList($path) { $filter = '^[wW][^\\.].*\\.([Pp][Nn][Gg]|[Jj][Pp][Ee]?[Gg])'; $recurse = true; $excludefiles = array(); $excludeexts = array(); jimport('joomla.filesystem.folder'); $filelist = JFolder::files($path, $filter, $recurse, true, $excludefiles); $files = array(); $files[] =& $this->getFile(null); $count = 0; while (list($i, $file) = each($filelist)) { $count++; if ($count > 500) { break; } if (in_array(JFile::getName($file), $excludefiles)) { continue; } if (in_array(JFile::getExt($file), $excludeexts)) { continue; } $file =& $this->getFile($file); $files[] = $file; } $this->fileSort($files); return $files; }
function onPromoteList($uid) { if ($uid) { $user = JFactory::getUser($uid); } else { $user = JFactory::getUser(); } jimport('joomla.filesystem.file'); $db = JFactory::getDBO(); $name = JFile::getName(__FILE__); $name = JFile::stripExt($name); //$name = $this->params->get('plugin_name'); $sobichk = $this->_sobichk(); if (!empty($sobichk)) { $query = "SELECT CONCAT_WS('|', '" . $name . "', s.itemid) as value, s.title as text FROM #__sobi2_item AS s\n\t\t\t\t\t\t\t\t LEFT JOIN #__users AS u ON s.updating_user = u.id\n\t\t\t\t\t\t\t\t WHERE u.id=" . $user->id . "\n\t\t\t\t\t\t\t\t ORDER BY itemid"; $db->setQuery($query); $itemlist = $db->loadObjectlist(); if (empty($itemlist)) { $list[0]->value = $name . '|' . '0'; $list[0]->text = JText::_("NO_SOBILIST"); return $list; } else { return $itemlist; } } }
function onPromoteList($uid) { jimport('joomla.filesystem.file'); $db = JFactory::getDBO(); if ($uid) { $user = JFactory::getUser($uid); } else { $user = JFactory::getUser(); } $name = JFile::getName(__FILE__); $name = JFile::stripExt($name); $jschk = $this->_chkextension(); if (!empty($jschk)) { $query = "SELECT CONCAT_WS('|', '" . $name . "', e.id) as value, e.title AS text FROM #__community_events AS e\n\t\t\t\t\t\t\t\tLEFT JOIN #__users AS u ON e.creator = u.id\n\t\t\t\t\t\t\t\tWHERE u.id =" . $user->id; $db->setQuery($query); $itemlist = $db->loadObjectlist(); if (empty($itemlist)) { $list = array(); //$list[0]->value=$name.'|'.'0'; // $list[0]->text=JText::_("NO_EVENTS"); return $list; } else { return $itemlist; } } }
public static function createThumb($path, $width = 100, $height = 100, $crop = 2) { $myImage = new JImage(); $myImage->loadFile(JPATH_SITE . DS . $path); if ($myImage->isLoaded()) { // $filename = end(explode('/', $path)); $filename = JFile::getName($path); $filefolder = substr(md5(self::getFolderPath($path)), 1, 10); $newfilename = $width . 'x' . $height . '_' . $filefolder . '_' . JFile::makeSafe($filename); $fileExists = JFile::exists(JPATH_CACHE . '/' . $newfilename); if (!$fileExists) { $resizedImage = $myImage->resize($width, $height, true, $crop); $properties = $myImage->getImageFileProperties($path); $mime = $properties->mime; if ($mime == 'image/jpeg') { $type = IMAGETYPE_JPEG; } elseif ($mime = 'image/png') { $type = IMAGETYPE_PNG; } elseif ($mime = 'image/gif') { $type = IMAGETYPE_GIF; } $resizedImage->toFile(JPATH_CACHE . '/' . $newfilename, $type); } return $newfilename; } else { return "My file is not loaded"; } }
/** * Upload Simple File Manager files in the right folder. * * @param string $tmp_name * Temporary path of the uploaded file on the server * @param string $file_name * Name of the uploaded file * @return uploaded file path (in case of success) or false (in case of error) */ public static function uploadFile($tmp_name, $file_name) { jimport('joomla.filesystem.file'); $src = $tmp_name; $dest = JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . uniqid("", true) . DIRECTORY_SEPARATOR . JFile::makeSafe(JFile::getName($file_name)); return JFile::upload($src, $dest) ? $dest : false; }
/** * Add a download. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $path * @param string $description * * @throws Exception * @throws DomainException * @return mixed * */ public function add($user, $repo, $path, $description = '') { /* * First part: Create the download resource */ // Build the request data. $fileName = JFile::getName($path); $data = json_encode(array('name' => $fileName, 'size' => filesize($path), 'description' => $description)); // Build the request path. $repoPath = '/repos/' . $user . '/' . $repo . '/downloads'; // Send the request. $response = $this->client->post($this->fetchUrl($repoPath), $data); // Validate the response code. if (201 != $response->code) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } /* * Second part: Upload the file * * For the second part we use plain curl - JHttp seems to add some unnecessary stuff... */ $respData = json_decode($response->body); if (!$respData) { throw new Exception('Invalid response'); } $data = array('key' => $respData->path, 'acl' => $respData->acl, 'success_action_status' => 201, 'Filename' => $respData->name, 'AWSAccessKeyId' => $respData->accesskeyid, 'Policy' => $respData->policy, 'Signature' => $respData->signature, 'Content-Type' => $respData->mime_type, 'file' => '@' . $path); $ch = curl_init(); $curlOptions = array(CURLOPT_URL => $respData->s3_url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER, true); curl_setopt_array($ch, $curlOptions); $result = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (201 != $responseCode) { throw new DomainException($result, $responseCode); } /* $this->options->set('api.url', $respData->s3_url); // Unset credentials $this->options->set('api.username', ''); $this->options->set('api.password', ''); $headers = array( // 'Expires' => time() + 300, ); $response = $this->client->post($this->fetchUrl(''), $data, $headers); // Validate the response code. if(201 != $response->code) { // Decode the error response and throw an exception. throw new DomainException($response->body, $response->code); } return json_decode($response->body); */ return $this; }
/** * @param $array * @return array */ function getCleanArray($array) { $newArray = array(); foreach ($array as $value) { array_push($newArray, JFile::stripExt(JFile::getName($value))); } return $newArray; }
function getCleanArray($array) { jimport('joomla.filesystem.file'); $newArray = array(); foreach($array as $value) array_push($newArray, JFile::stripExt(JFile::getName($value))); return $newArray; }
function postflight($type, $parent) { if (version_compare(JVERSION, '3.0.0', '>')) { $messages = array(); // Import required modules jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); jimport('joomla.filesystem.file'); //$db = JFactory::getDBO(); //$query = "ALTER TABLE #__k2_items ADD FULLTEXT(extra_fields)"; //$db->setQuery($query); //$db->query(); // Get packages $p_dir = JPath::clean(JPATH_SITE . DS . 'components' . DS . 'com_jak2filter' . DS . 'packages'); // Did you give us a valid directory? if (!is_dir($p_dir)) { $messages[] = JText::_('Package directory(Related modules, plugins) is missing'); } else { $subpackages = JFolder::files($p_dir); $result = true; $installer = new JInstaller(); if ($subpackages) { $app = JFactory::getApplication(); $templateDir = 'templates/' . $app->getTemplate(); foreach ($subpackages as $zpackage) { if (JFile::getExt($p_dir . DS . $zpackage) != "zip") { continue; } $subpackage = JInstallerHelper::unpack($p_dir . DS . $zpackage); if ($subpackage) { $type = JInstallerHelper::detectType($subpackage['dir']); if (!$type) { $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::_($zpackage . " Not valid package") . '</span>'; $result = false; } if (!$installer->install($subpackage['dir'])) { // There was an error installing the package $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Error')) . '</span>'; } else { $messages[] = '<img src="' . $templateDir . '/images/admin/tick.png" alt="" width="16" height="16" /> <span style="color:#00FF00;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Success')) . '</span>'; } if (!is_file($subpackage['packagefile'])) { $subpackage['packagefile'] = $p_dir . DS . $subpackage['packagefile']; } if (is_dir($subpackage['extractdir'])) { JFolder::delete($subpackage['extractdir']); } if (is_file($subpackage['packagefile'])) { JFile::delete($subpackage['packagefile']); } } } } JFolder::delete($p_dir); } } }
public function zipLiveTemplate(&$model) { jimport('joomla.filesystem.archive'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $item =& $model->getItem(); $item->name = strtolower($item->name); //Create TempFolders if (JFolder::exists($model->getTempPath(true))) { JFolder::delete($model->getTempPath(true)); } JFolder::create($model->getTempPath()); //Copy the template if (JFolder::exists(JPATH_SITE . DS . 'templates' . DS . $item->name)) { JFolder::copy(JPATH_SITE . DS . 'templates' . DS . $item->name, $model->getTempPath(), '', true); } elseif (JFolder::exists(JPATH_ADMINISTRATOR . DS . 'templates' . DS . $item->name)) { JFolder::copy(JPATH_ADMINISTRATOR . DS . 'templates' . DS . $item->name, $model->getTempPath(), '', true); } else { JFolder::delete($model->getTempPath()); return -2; } //Create Language Folders if (!JFolder::exists($model->getTempPath() . DS . 'language')) { JFolder::create($model->getTempPath() . DS . 'language'); } //Find Language Files $langs_site = JLanguage::getKnownLanguages(JPATH_SITE); $langs_admin = JLanguage::getKnownLanguages(JPATH_ADMINISTRATOR); $langfiles_site = array(); $langfiles_admin = array(); foreach ($langs_site as $lang) { $langfiles_site = array_merge(JFolder::files(JPATH_SITE . DS . 'language' . DS . $lang['tag'], $item->name, true, true), $langfiles_site); } foreach ($langs_admin as $lang) { $langfiles_admin = array_merge(JFolder::files(JPATH_ADMINISTRATOR . DS . 'language' . DS . $lang['tag'], $item->name, true, true), $langfiles_admin); } //Copy Language Files if (count($langfiles_site)) { foreach ($langfiles_site as $file) { JFile::copy($file, $model->getTempPath() . DS . 'language' . DS . JFile::getName($file)); } } if (count($langfiles_admin)) { foreach ($langfiles_admin as $file) { JFile::copy($file, $model->getTempPath() . DS . 'language' . DS . JFile::getName($file)); } } $model->readinFiles(); $model->buildArchiveContent(); //create archive $model->createArchive(); //delete tmp folder if (JFolder::exists(JPATH_SITE . DS . 'tmp' . DS . 'jctmp')) { JFolder::delete(JPATH_SITE . DS . 'tmp' . DS . 'jctmp'); } }
/** * Downloads the backup file of a specific backup attempt, * if it's available * */ function download() { $cid = JRequest::getVar('cid', array(), 'default', 'array'); $id = JRequest::getInt('id'); $part = JRequest::getInt('part', 999); if (empty($id)) { if (is_array($cid) && !empty($cid)) { $id = $cid[0]; } else { $id = -1; } } if ($id <= 0) { $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=buadmin', JText::_('STATS_ERROR_INVALIDID'), 'error'); parent::display(); return; } $model =& $this->getModel('statistics'); $model->setId($id); $statentry =& $model->getStatistic(); if ($statentry->multipart == 0) { // Single part backup $filename = $model->getFilename($id); } else { // Multi-part backup $allFilenames = $model->getAllFilenames($id); if (!(@count($allFilenames) > 0)) { $filename = null; } else { if ($part <= count($allFilenames)) { $filename = $allFilenames[$part]; } else { $filename = null; } } } jimport('joomla.filesystem.file'); if (is_null($filename) || empty($filename) || !JFile::exists($filename)) { $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=buadmin', JText::_('STATS_ERROR_INVALIDDOWNLOAD'), 'error'); parent::display(); return; } else { $basename = @JFile::getName($filename); JRequest::setVar('format', 'raw'); @ob_end_clean(); @clearstatcache(); header('Content-Disposition: attachment; filename=' . $basename); header('MIME-Version: 1.0'); header('Content-Transfer-Encoding: binary'); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); header('Cache-Control: no-cache'); @readfile($filename); die; } }
/** * @static * @return int|mixed */ public function deployPackage() { $input = JFactory::getApplication()->input; $files = $input->get('file', array(), 'array'); foreach ($files as $file) { JLog::add('| >> ' . sprintf(jgettext('Uploading %s ...'), JFile::getName($file))); $this->github->downloads->add($input->get('owner'), $input->get('repo'), $file); } return count($files); }
function listFiles($path, $regex = '.') { $files = array(); // Make sure path is valid $path = JPath::clean($path); if (empty($path) || JString::strpos($path, JPATH_ROOT) === false) { return $files; } $list = JFolder::files($path, $regex, false, true); if (empty($list)) { return $files; } foreach ($list as $filename) { $f = new JObject(); $f->name = JFile::getName($filename); $f->path = $filename; $f->src = JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f->path); $f->src = str_replace(DS, '/', $f->src); $f->size = LinkrHelper::parseSize($f->path); $f->ext = strtolower(JFile::getExt($f->name)); switch ($f->ext) { // Image case 'bmp': case 'gif': case 'jpg': case 'jpeg': case 'odg': case 'png': case 'xcf': list($w, $h) = @getimagesize($f->path); $size = LinkrHelper::imageResize($w, $h, 32); $f->width = $size['width']; $f->height = $size['height']; $f->icon = JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f->path); $f->icon = str_replace(DS, '/', $f->icon); $f->type = JText::_('Image'); break; // Other files // Other files default: $f->type = strtoupper($f->ext); $f->width = 32; $f->height = 32; $icon = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_media' . DS . 'images' . DS . 'mime-icon-32' . DS . $f->ext . '.png'; if (file_exists($icon)) { $f->icon = JURI::root() . 'administrator/components/com_media/images/mime-icon-32/' . $f->ext . '.png'; } else { $f->icon = JURI::root() . 'administrator/components/com_media/images/con_info.png'; } break; } $files[] = $f; } return $files; }
/** * Get large avatar use for cropping * @return string */ public function getLargeAvatar() { $config = CFactory::getConfig(); $largeAvatar = $config->getString('imagefolder') . '/avatar/profile-' . JFile::getName($this->avatar); if (JFile::exists(JPATH_ROOT . '/' . $largeAvatar)) { return CUrlHelper::avatarURI($largeAvatar) . '?' . md5(time()); /* adding random param to prevent browser caching */ } else { return $this->getAvatar(); } }
/** * Get large avatar use for cropping * @return string */ public function getLargeAvatar() { $config = CFactory::getConfig(); $largeAvatar = $config->getString('imagefolder') . '/avatar/profile-' . JFile::getName($this->avatar); $current = CStorage::getStorage($this->storage); if ($current->exists($largeAvatar)) { return $current->getURI($largeAvatar); } else { return $this->getAvatar(); } }
function com_install() { JAVoiceHelpers::Install_Db(); $messages = array(); // Import required modules jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); jimport('joomla.filesystem.file'); // Get packages $p_dir = JPath::clean(JPATH_SITE . '/components/com_javoice/packages'); // Did you give us a valid directory? if (!is_dir($p_dir)) { $messages[] = JText::_('Package directory(Related modules, plugins) is missing'); } else { $subpackages = JFolder::files($p_dir); $result = true; $installer = new JInstaller(); if ($subpackages) { $app = JFactory::getApplication(); $templateDir = 'templates/' . $app->getTemplate(); foreach ($subpackages as $zpackage) { if (JFile::getExt($p_dir . DS . $zpackage) != "zip") { continue; } $subpackage = JInstallerHelper::unpack($p_dir . DS . $zpackage); if ($subpackage) { $type = JInstallerHelper::detectType($subpackage['dir']); if (!$type) { $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::_($zpackage . " Not valid package") . '</span>'; $result = false; } if (!$installer->install($subpackage['dir'])) { // There was an error installing the package $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Error')) . '</span>'; } else { $messages[] = '<img src="' . $templateDir . '/images/admin/tick.png" alt="" width="16" height="16" /> <span style="color:#00FF00;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Success')) . '</span>'; } if (!is_file($subpackage['packagefile'])) { $subpackage['packagefile'] = $p_dir . DS . $subpackage['packagefile']; } if (is_dir($subpackage['extractdir'])) { JFolder::delete($subpackage['extractdir']); } if (is_file($subpackage['packagefile'])) { JFile::delete($subpackage['packagefile']); } } } } JFolder::delete($p_dir); } }
public function getHeadshotImage() { $currentHeadshot = $this->getCurrentHeadshot(); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName(array('b.headshot_image')))->from($db->quoteName('#__content', 'a'))->join('INNER', $db->quoteName('#__cck_store_form_headshot', 'b') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('b.id') . ')')->where($db->quoteName('a.id') . " = " . $db->quote($currentHeadshot)); $db->setQuery($query); $result = $db->loadResult(); $fileName = JFile::getName($result); $path = substr($result, 0, strrpos($result, '/')) . '/'; $thumb = $path . '_thumb1/' . $fileName; return $thumb; }
public static function createThumb($path, $width = 100, $height = 100, $crop = 2, $cachefolder = 'hgimages', $external = 0) { $myImage = new JImage(); if (!$external) { $myImage->loadFile(JPATH_SITE . DS . $path); } else { $myImage->loadFile($path); } if ($myImage->isLoaded()) { // $filename = end(explode('/', $path)); $filename = JFile::getName($path); $filefolder = substr(md5(self::getFolderPath($path)), 1, 10); $newfilename = $width . 'x' . $height . 'x' . $crop . '_' . $filefolder . '_' . JFile::makeSafe($filename); $hgimages = JPATH_CACHE . '/' . $cachefolder . '/'; if (!JFolder::exists($hgimages)) { JFolder::create($hgimages); } $fileExists = JFile::exists($hgimages . $newfilename); if (!$fileExists) { switch ($crop) { // Case for self::CROP case 4: $resizedImage = $myImage->crop($width, $height, null, null, true); break; // Case for self::CROP_RESIZE // Case for self::CROP_RESIZE case 5: $resizedImage = $myImage->cropResize($width, $height, true); break; default: $resizedImage = $myImage->resize($width, $height, true, $crop); break; } $properties = $myImage->getImageFileProperties($path); $mime = $properties->mime; if ($mime == 'image/jpeg') { $type = IMAGETYPE_JPEG; } elseif ($mime = 'image/png') { $type = IMAGETYPE_PNG; } elseif ($mime = 'image/gif') { $type = IMAGETYPE_GIF; } $resizedImage->toFile($hgimages . $newfilename, $type); } return $newfilename; } else { return "My file is not loaded"; } }
public static function getSources($video_path) { $filename = JFile::getName($video_path); $folder = JPATH_ROOT . DS . self::getFolderPath($video_path); $videosArr = array(); $allowed_ext = array('mp4', 'webm', 'ogg', 'ogv'); if (JFolder::exists($folder)) { foreach ($allowed_ext as $k => $v) { $thefile = $filename . '.' . $v; if (in_array($thefile, JFolder::files($folder))) { $videosArr[] = $v; } } } return $videosArr; }
/** * Install component * * @param string $file Path to extension archive * @param boolean $update True if extension should be updated, false if it is new */ public static function install($file, $update = false) { $installer = JInstaller::getInstance(); $tmp = JDeveloperINSTALL . "/" . JFile::stripExt(JFile::getName($file)); JArchive::getAdapter('zip')->extract($file, $tmp); if ($update) { if (!$installer->update($tmp)) { return false; } } else { if (!$installer->install($tmp)) { return false; } } self::cleanInstallDir(); return true; }
/** * @static * * @throws Exception * @return int|mixed */ public function deployPackage() { $input = JFactory::getApplication()->input; $files = $input->get('file', array(), 'array'); JLog::add('| ' . sprintf(jgettext('Upload directory: %s'), $this->credentials->downloads)); foreach ($files as $file) { $fName = JFile::getName($file); JLog::add('| >> ' . sprintf(jgettext('Uploading %s ...'), $fName)); if (!$this->ftp->chdir($this->credentials->downloads)) { throw new Exception(jgettext('Download directory not found on server')); } if (!$this->ftp->store($file, $this->credentials->downloads . '/' . $fName)) { throw new Exception(JError::getError()); } } return count($files); }
function __construct($filename = "") { parent::__construct(); if (!empty($filename)) { if (!JFile::exists($filename)) { $this->setError("Image does not exist"); return; } $this->full_path = $filename; $this->setDirectory(substr($this->full_path, 0, strrpos($this->full_path, DS))); $this->proper_name = JFile::getName($filename); if (!empty($this->full_path)) { $image_info = getimagesize($this->full_path); $this->type = $image_info[2]; } } }
public function update(JAdapterInstance $adapter) { $src = $adapter->getParent()->getPath('source'); $site = $adapter->getParent()->getPath('extension_site'); $admin = $adapter->getParent()->getPath('extension_administrator'); $attributes = $adapter->getParent()->get('manifest')->media->attributes(); $attributes = reset($attributes); $extension = \Joomla\Utilities\ArrayHelper::getValue($attributes, 'destination'); $exclude = array(); $exclude[] = $adapter->get('manifest_script'); $exclude[] = JFile::getName($adapter->getParent()->getPath('manifest')); $this->removeRedundantFiles($site, $src . '/site'); $this->removeRedundantFiles($admin, $src . '/admin', $exclude); if ($extension) { $media = JPATH_ROOT . '/media/' . $extension; $this->removeRedundantFiles($media, $src . '/media', $exclude); } }
/** * Upload file. * * @param string $dest target directory to upload * @param string $field request fieldname * @param stdClass $file property where sets ouptput with this format: * $file->tmp ... request template file name * $file->name ... uploaded file name * $file->apath ... absolute path to file * $file->rpath ... real path to file * @param string $error property to set error messages * @param boolean $unpackZip wheater unpack zip files * @return boolean */ function upload($dest, $field, &$file, &$error, $unpackZip = false) { $adir = $dest; $rdir = JURI::root() . str_replace(DS, '/', $dest); $rdir = str_replace('//', '/', $dest); if (!file_exists($adir)) { if (!@mkdir($adir, 0775, true)) { $mainframe =& JFactory::getApplication(); /* @var $mainframe JApplication */ $mainframe->enqueueMessage(sprintf(JText::_('Unable create directory %s'), $adir), 'error'); return false; } } if (isset($_FILES[$field])) { $request =& $_FILES[$field]; $file = new stdClass(); $file->tmp = $request['tmp_name']; $file->name = $request['name']; if ($request['error'] == 0) { $zip = new JArchiveZip(); $data = JFile::read($file->tmp); $isZip = $zip->checkZipData($data); unset($data); if ($isZip && $unpackZip) { $tmpDir = AFile::getTmpDir(); $zip->extract($file->tmp, $tmpDir); unset($zip); $files =& JFolder::files($tmpDir, '.', true, true); $count = count($files); for ($i = 0; $i < $count; $i++) { $file->tmp = $files[$i]; $file->name = JFile::getName($file->tmp); AFile::save($file, $adir, $rdir); } JFolder::delete($tmpDir); return true; } else { unset($zip); return AFile::save($file, $adir, $rdir); } } } return false; }
/** * Custom update method for JDeveloper * * @param object $parent The installer adapter * * @return void */ public function update($parent) { // Compare directories, delete files and folders which don't exists in the new version $src = $parent->get("parent")->getPath('source'); $dest = $parent->get("parent")->getPath('extension_administrator'); $dirs = array("assets", "controllers", "create", "helpers", "layouts", "library", "models", "tables", "templates", "views"); // Delete folders that don't exists in the new version any more foreach ($dirs as $dir) { foreach (JFolder::folders($dest . "/" . $dir, ".", true, true) as $folder) { if (!JFolder::exists($src . "/admin" . str_replace($dest, "", $folder))) { if (JFolder::exists($folder)) { JFolder::delete($folder); } } } } // Delete files that don't exists in the new version any more foreach ($dirs as $dir) { foreach (JFolder::files($dest . "/" . $dir, ".", true, true) as $file) { if (!JFile::exists($src . "/admin" . str_replace($dest, "", $file)) && $file != "/install.php") { if (JFile::exists($file)) { JFile::delete($file); } } } } foreach (JFolder::files($dest, '.', false, true) as $file) { if (!JFile::exists($src . "/admin" . str_replace($dest, "", $file)) && $file != "/install.php") { if (JFile::exists($file)) { JFile::delete($file); } } } // Get version specific updates JFolder::create(JPATH_ADMINISTRATOR . "/components/com_jdeveloper/updates"); foreach (JFolder::files($src . "/update", ".php", true, true) as $file) { $version = str_replace(".php", "", JFile::getName($file)); if (version_compare($version, $parent->get("manifest")->version) < 1) { JFile::copy($file, JPATH_ADMINISTRATOR . "/components/com_jdeveloper/updates/" . $version . ".php", null, true); } } include $src . "/install/template_update.php"; }
/** * Document edit page. * * @param string $tpl used template name * @return void */ public function display($tpl = null) { $mainframe = JFactory::getApplication(); /* @var $mainframe JAdministrator */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $model = $this->getModel(); /* @var $model JoomDOCModelDocument */ $this->form = $model->getForm(); $this->document = $model->getItem(); $this->state = $model->getState(); $this->access = new JoomDOCAccessHelper($this->document); if (!isset($this->document->id) || empty($this->document->id)) { $this->form->setValue('path', null, $mainframe->getUserState('path')); $this->form->setValue('title', null, JFile::getName($mainframe->getUserState('path'))); } $this->addToolbar(); parent::display($tpl); }
/** * Get large avatar use for cropping * @return string */ public function getLargeAvatar() { $config = CFactory::getConfig(); /* Some profile type avatar are stored directly to the avatar with this format avatar_[id] * So, if we have this kind of format, we will take this as priority * Used by JSPT */ if (count(explode('_', $this->avatar)) > 1) { $largeAvatar = $this->avatar; } else { $largeAvatar = $config->getString('imagefolder') . '/avatar/profile-' . JFile::getName($this->avatar); } $current = CStorage::getStorage($this->storage); if ($current->exists($largeAvatar)) { return $current->getURI($largeAvatar); } else { return $this->getAvatar(); } }
function onPromoteList($uid) { jimport('joomla.filesystem.file'); $db = JFactory::getDBO(); if ($uid) { $user = JFactory::getUser($uid); } else { $user = JFactory::getUser(); } $name = JFile::getName(__FILE__); $name = JFile::stripExt($name); $jschk = $this->_chkextension(); if (!empty($jschk)) { $query = "SELECT CONCAT_WS('|', '" . $name . "', u.id) as value, u.name AS text FROM #__users AS u\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN #__community_users AS c ON u.id = c.userid\n\t\t\t\t\t\t\t\t\t\tWHERE u.id =" . $user->id; $db->setQuery($query); $itemlist = $db->loadObjectlist(); return $itemlist; } }
/** * Checks to see if an image exists in the current templates image directory * if it does it loads this image. Otherwise the default image is loaded. * Also can be used in conjunction with the menulist param to create the chosen image * load the default or use no image * * @param string The file name, eg foobar.png * @param string The path to the image * @param int empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder * @param string Another path. Only used for the contact us form based on the value of the imagelist parm * @param string Alt text * @param array An associative array of attributes to add * @param boolean True (default) to display full tag, false to return just the path */ function site($file, $folder = '/images/M_images/', $altFile = NULL, $altFolder = '/images/M_images/', $alt = NULL, $attribs = null, $asTag = 1) { static $paths; global $mainframe; jimport('joomla.filesystem.file'); if (!$paths) { $paths = array(); } if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $cur_template = $mainframe->getTemplate(); if ($altFile) { // $param allows for an alternative file to be used $src = $altFolder . $altFile; } else { if ($altFile == -1) { // Comes from an image list param field with 'Do not use' selected return ''; } else { $path = JPATH_SITE . '/templates/' . $cur_template . '/images/' . $file; if (!isset($paths[$path])) { if (file_exists(JPATH_SITE . '/templates/' . $cur_template . '/images/' . $file)) { $paths[$path] = 'templates/' . $cur_template . '/images/' . $file; } else { // outputs only path to image $paths[$path] = $folder . $file; } } $src = $paths[$path]; } } if (substr($src, 0, 1) == "/") { $src = substr_replace($src, '', 0, 1); } // Prepend the base path $src = JURI::base(true) . '/' . $src; // outputs actual html <img> tag if ($asTag) { return '<span class="icon ' . JFile::stripExt(JFile::getName($src)) . '"></span>'; } return $src; }
public static function getJoomlaTemplate($view = 'category') { $clientId = 0; $client = JApplicationHelper::getClientInfo($clientId); $extn = 'com_judirectory'; $lang = JFactory::getLanguage(); $items = array(); if ($extn && $view && $client) { $lang->load($extn . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($extn . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false) || $lang->load($extn . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extn . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false); $component_path = JPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl'); $groups = array(); $groups['inherit'] = array(); $groups['inherit']['id'] = 'layout_inherit'; $groups['inherit']['text'] = '---' . JText::_('COM_JUDIRECTORY_INHERIT') . '---'; $groups['inherit']['items'] = array(); if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\\.xml$', false, true))) { $groups['_'] = array(); $groups['_']['id'] = 'layout__'; $groups['_']['text'] = JText::sprintf('JOPTION_FROM_COMPONENT'); $groups['_']['items'] = array(); foreach ($component_layouts as $i => $file) { if (!($xml = simplexml_load_file($file))) { unset($component_layouts[$i]); continue; } if (!($menu = $xml->xpath('layout[1]'))) { unset($component_layouts[$i]); continue; } $menu = $menu[0]; $value = JFile::stripext(JFile::getName($file)); $component_layouts[$i] = $value; $text = isset($menu['option']) ? JText::_($menu['option']) : (isset($menu['title']) ? JText::_($menu['title']) : $value); $groups['_']['items'][] = JHtml::_('select.option', '_:' . $value, $text); $items['_'][$value] = $text; } } } return $items; }