protected function onAfterSave(&$table) { if ($table->body_source == 'file' && $table->body_source_file != '-1') { jimport('joomla.filesystem.file'); $app = JFactory::getApplication(); $fileName = $table->body_source_file; $filePath = JPath::clean(JPATH_ADMINISTRATOR . '/components/com_j2store/views/emailtemplate/tpls/' . $fileName); // Include the extension plugins for the save events. JPluginHelper::importPlugin('extension'); $user = get_current_user(); chown($filePath, $user); JPath::setPermissions($filePath, '0644'); // Try to make the template file writable. if (!is_writable($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'), 'warning'); $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_PERMISSIONS' . JPath::getPermissions($filePath)), 'warning'); if (!JPath::isOwner($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_CHECK_FILE_OWNERSHIP'), 'warning'); } return false; } $source = JFactory::getApplication()->input->get('source', '', 'RAW'); jimport('joomla.filter.filterinput'); $filter = JFilterInput::getInstance(null, null, 1, 1); $value = $filter->clean($source, 'raw'); $return = true; if (!empty($value)) { $return = JFile::write($filePath, $value); } // Try to make the template file unwritable. if (JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0644')) { $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'), 'error'); return false; } elseif (!$return) { $app->enqueueMessage(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName), 'error'); return false; } } }
/** * Method to store the source file contents. * * @param array $data The source data to save. * * @return boolean True on success, false otherwise and internal error set. * * @since 1.6 */ public function save($data) { jimport('joomla.filesystem.file'); // Get the template. $template = $this->getTemplate(); if (empty($template)) { return false; } $app = JFactory::getApplication(); $fileName = base64_decode($app->input->get('file')); $client = JApplicationHelper::getClientInfo($template->client_id); $filePath = JPath::clean($client->path . '/templates/' . $template->element . '/' . $fileName); // Include the extension plugins for the save events. JPluginHelper::importPlugin('extension'); $user = get_current_user(); chown($filePath, $user); JPath::setPermissions($filePath, '0644'); // Try to make the template file writable. if (!is_writable($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'), 'warning'); $app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_PERMISSIONS' . JPath::getPermissions($filePath)), 'warning'); if (!JPath::isOwner($filePath)) { $app->enqueueMessage(JText::_('COM_TEMPLATES_CHECK_FILE_OWNERSHIP'), 'warning'); } return false; } // Make sure EOL is Unix $data['source'] = str_replace(array("\r\n", "\r"), "\n", $data['source']); $return = JFile::write($filePath, $data['source']); if (!$return) { $app->enqueueMessage(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName), 'error'); return false; } $explodeArray = explode('.', $fileName); $ext = end($explodeArray); if ($ext == 'less') { $app->enqueueMessage(JText::sprintf('COM_TEMPLATES_COMPILE_LESS', $fileName)); } return true; }
/** * Method to check if the permissions of Phpthumb cache folder * * @access public * @return boolean True on success */ function getCacheThumbChmod() { static $return; if ($return === null) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.jpath'); $phpthumbcache = JPath::clean(JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'phpthumb' . DS . 'cache'); // CHECK phpThumb cache exists and create the folder if (!JFolder::exists($phpthumbcache) && !JFolder::create($phpthumbcache)) { JError::raiseWarning(100, 'Error: Unable to create phpThumb folder: ' . $phpthumbcache . ' image thumbnail will not work properly'); return true; // Cancel task !! to allow user to continue } // CHECK phpThumb cache permissions $return = preg_match('/rwxr.xr.x/i', JPath::getPermissions($phpthumbcache)) ? true : false; // If permissions not good check if we can change them if (!$return && !JPath::canChmod($phpthumbcache)) { JError::raiseWarning(100, 'Error: Unable to change phpThumb folder permissions: ' . $phpthumbcache . ' there maybe a wrong owner of the folder. Correct permissions are important for proper thumbnails and for -security-'); return true; // Cancel task !! to allow user to continue } } return $return; }
function _getDirInfo($folder, $relative = 1, $text = '') { jimport('joomla.filesystem.path'); $ret = ""; $writeable = 'Writable'; $unwriteable = 'Unwritable'; $ret .= $text; if ($relative) { $path = "../{$folder}"; } else { $path = $folder; } $ret .= $path; if (is_dir($path)) { $ret .= '/'; } if (file_exists($path)) { $ret .= " - "; $ret .= is_writable($path) ? $writeable : $unwriteable; $ret .= " - Owner: "; $ret .= JPath::isOwner($path) ? "Yes" : "No"; $ret .= " - Permissions: " . JPath::getPermissions($path); } else { $ret .= " - Does Not Exist"; } return $ret; }
function _generateFiles(&$element) { $app = JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.path'); if ($element->payment_params->debug == 1) { $debug = 'YES'; } else { $debug = 'NO'; } if (empty($element->payment_params->merchant_id)) { return true; } $message = $this->_getLanguage(); $logoPath = JURI::base(true) . $element->payment_params->logo_folder_relative; $logoPath = str_replace('administrator', '', $logoPath); $safe_mode = ini_get('safe_mode') == 1 || !strcasecmp(ini_get('safe_mode'), 'On'); if (str_replace(JPATH_ROOT, '', $element->payment_params->upload_folder) != $element->payment_params->upload_folder) { $path = $element->payment_params->upload_folder; } else { $path = JPATH_ROOT . DS . $element->payment_params->upload_folder; } $lang =& JFactory::getLanguage(); $locale = strtolower(substr($lang->get('tag'), 0, 2)); $atos = '<?php $_GET[\'option\']=\'com_hikashop\'; $_GET[\'tmpl\']=\'component\'; $_GET[\'ctrl\']=\'checkout\'; $_GET[\'task\']=\'notify\'; $_GET[\'notif_payment\']=\'atos\'; $_GET[\'lang\']=\'' . $locale . '\'; $_REQUEST[\'option\']=\'com_hikashop\'; $_REQUEST[\'tmpl\']=\'component\'; $_REQUEST[\'ctrl\']=\'checkout\'; $_REQUEST[\'task\']=\'notify\'; $_REQUEST[\'notif_payment\']=\'atos\'; $_REQUEST[\'lang\']=\'' . $locale . '\'; include(\'index.php\'); '; $success = '<?php header("Location: ' . hikashop_frontendLink('index.php?option=com_hikashop&ctrl=checkout&task=after_end') . '");'; $path = $this->_addLastSlash($path); $os = substr(PHP_OS, 0, 3); $os = strtolower($os); if ($os == 'win') { $logoPath = str_replace('/', DS, $logoPath); } $pathfile = 'DEBUG!' . $debug . '!' . "\r\n" . 'D_LOGO!' . $logoPath . '!' . "\r\n" . 'F_DEFAULT!' . $path . 'pc.x!' . "\r\n" . 'F_PARAM!' . $path . 'pc!' . "\r\n" . 'F_CERTIFICATE!' . $path . 'b' . DS . 'ct!' . "\r\n"; $parcom = 'TEMPLATE!' . $element->payment_params->template . '!' . "\r\n"; $pc = ''; JFile::write($path . 'pc.x', $parcom); JFile::write($path . 'pc.' . $element->payment_params->merchant_id, $pc); JFile::write($path . 'pathfile', $pathfile); $rights = JPath::getPermissions(JPATH_ROOT); if ($rights[1] != 'w' && !JFile::exists(JPATH_ROOT . DS . 'atos.php')) { $app->enqueueMessage($message['autoresponse_cannot_be_created'], 'error'); return true; } JFile::write(JPATH_ROOT . DS . 'atos.php', $atos); JFile::write(JPATH_ROOT . DS . 'success.php', $success); }
function _sipsExecError($vars) { $message = JText::_('TIENDA_SIPS_REQUEST_EXEC_ERROR') . "<br />"; $message .= JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG') . "<br />"; $error = false; $message .= JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_PATH'); $message .= $vars->bin_request; if (!file_exists($vars->bin_request)) { $message .= "<br />\t" . JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_FILE_EXIST_KO'); $error = true; } else { $message .= "<br />\t" . JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_FILE_EXIST_OK'); } $message .= "<br /><br />" . JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_FILEPERMISSIONS') . " " . $vars->bin_request . " : "; $message .= JPath::getPermissions($vars->bin_request); if (!$this->checkPermissionsExecute($vars->bin_request)) { if (!JPath::setPermissions($vars->bin_request, '0755')) { $message .= JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_COULD_NOT_CHANNGEFILEPERMISSIONS'); } else { $message .= JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_FILEPERMISSIONS_CHANGED'); } $error = true; } else { $message .= "<br />" . JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_CGI_FILEPERMISSIONS_OK'); } if ($error) { $message .= "<br /><br />" . JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_ERROR_FOUND'); } else { $message .= "<br /><br />" . JText::_('TIENDA_SIPS_REQUEST_EXEC_DIAG_ERROR_NOT_FOUND'); } if ($this->params->get('payment_server') != 'production') { echo $message; JError::raiseWarning('', JText::_('TIENDA_SIPS_REQUEST_EXEC_ERROR')); } else { $this->_sendErrorEmail($message, ''); } }
public function prepareAudio($data, $file = null, $_copy = false) { $copy = $_copy; if ($this->tztask) { $copy = true; } if ($data) { if (isset($data['jform'])) { $data = $data['jform']; } if ($data['audio_soundcloud_id']) { $fileTypes = array('image/jpeg', 'image/jpg', 'image/bmp', 'image/gif', 'image/png', 'image/ico'); $params = $this->getState('params'); $_data = null; $_data = $this->_db->quote($data['audio_soundcloud_id']); $id = $this->getState($this->getName() . '.id'); if (!$id) { $id = $data['id']; } // Create folder to save thumb if this folder isn't created. $audioPath = $this->imageUrl . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR . $this->audioFolder; if (!JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath)) { JFolder::create(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath); } if (JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath)) { if (!JFile::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath . DIRECTORY_SEPARATOR . 'index.html')) { JFile::write(JPATH_SITE . DIRECTORY_SEPARATOR . $audioPath . DIRECTORY_SEPARATOR . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>')); } } // Check and set chmod folder again $chmodFolder = JPath::getPermissions($audioPath); if ($chmodFolder != 'rwxrwxrwx' || $chmodFolder != 'rwxr-xr-x') { JPath::setPermissions($audioPath); } // Prepare data (Return string to save the database) //// Delete old thumbnail if delete checkbox input is checked if ($data['audio_soundcloud_delete_image'] && ($hiddenImage = $data['audio_soundcloud_hidden_image'])) { $this->deleteThumb(null, $hiddenImage); // // Delete old original thumbnail // $org_path = JPATH_SITE.DIRECTORY_SEPARATOR.$org_audioPath.DIRECTORY_SEPARATOR // .JFile::getName($data['audio_soundcloud_hidden_image']); // if(JFile::exists($org_path)){ // JFile::delete($org_path); // } } if ($file && !empty($file['name'])) { // If choose thumbnail from client $destName = (!$data['alias'] ? uniqid() . 'tz_portfolio_' . time() : $data['alias']) . '-' . $id . '.' . JFile::getExt($file['name']); $image = $this->uploadImageClient($file, $destName, $audioPath, $fileTypes, $this->_getImageSizes($params), $data['audio_soundcloud_hidden_image']); } elseif (!empty($data['audio_soundcloud_image_server'])) { // If choose thumbnail from server $destName = (!$data['alias'] ? uniqid() . 'tz_portfolio_' . time() : $data['alias']) . '-' . $id . '.' . JFile::getExt($data['audio_soundcloud_image_server']); $image = $this->uploadImageServer($data['audio_soundcloud_image_server'], $destName, $audioPath, $this->_getImageSizes($params), $data['audio_soundcloud_hidden_image'], $copy); } else { // Get thumbnail from soundcloud page if ($data['audio_soundcloud_delete_image'] && ($hiddenImage = $data['audio_soundcloud_hidden_image'])) { $data['audio_soundcloud_hidden_image'] = ''; } if (!isset($data['audio_soundcloud_hidden_image']) || empty($data['audio_soundcloud_hidden_image'])) { if ($client_id = $params->get('soundcloud_client_id', '4a24c193db998e3b88c34cad41154055')) { // Register fetch object $fetch = new Services_Yadis_PlainHTTPFetcher(); $url = 'http://api.soundcloud.com/tracks/' . $data['audio_soundcloud_id'] . '.json?client_id=' . $client_id; if ($content = $fetch->get($url)) { $content = json_decode($content->body); $thumbUrl = null; if ($content->artwork_url && !empty($content->artwork_url)) { $thumbUrl = $content->artwork_url; } else { $audioUser = $content->user; if ($audioUser->avatar_url && !empty($audioUser->avatar_url)) { $thumbUrl = $audioUser->avatar_url; } } if ($thumbUrl) { if (JString::strrpos($thumbUrl, '-', 0) != false) { $thumbUrl = JString::substr($thumbUrl, 0, JString::strrpos($thumbUrl, '-', 0) + 1) . 't500x500.' . JFile::getExt($thumbUrl); } // Create folder tmp if not exists if (!JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder)) { JFolder::create(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder); } if (JFolder::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder)) { if (!JFile::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder . 'index.html')) { JFile::write(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $this->tzfolder . 'index.html', htmlspecialchars_decode('<!DOCTYPE html><title></title>')); } } // Save image from other server to this server (temp file) $fetch2 = new Services_Yadis_PlainHTTPFetcher(); $audioTempPath = null; if ($audioTemp = $fetch2->get($thumbUrl)) { if (in_array($audioTemp->headers['Content-Type'], $fileTypes)) { $audioType = JFile::getExt($thumbUrl); if (preg_match('/(.*)(\\|\\/|\\:|\\*|\\?|\\"|\\<|\\>|\\|.*?)/i', $audioType, $match)) { $audioType = $match[1]; } $audioTempPath = 'media' . DIRECTORY_SEPARATOR . $this->tzfolder . DIRECTORY_SEPARATOR . uniqid() . time() . '.' . $audioType; JFile::write(JPATH_SITE . DIRECTORY_SEPARATOR . $audioTempPath, $audioTemp->body); } } if ($audioTempPath) { $destName = (!$data['alias'] ? uniqid() . 'tz_portfolio_' . time() : $data['alias']) . '-' . $id . '.' . JFile::getExt($audioTempPath); $image = $this->uploadImageServer($audioTempPath, $destName, $audioPath, $this->_getImageSizes($params)); if (JFile::exists(JPATH_SITE . DIRECTORY_SEPARATOR . $audioTempPath)) { JFile::delete(JPATH_SITE . DIRECTORY_SEPARATOR . $audioTempPath); } } } } } } else { $image = $data['audio_soundcloud_hidden_image']; } } $_data .= ','; if ($image) { $_data .= $this->_db->quote($image); } else { $_data .= $this->_db->quote(''); } $_data .= ','; if ($data['audio_soundcloud_title']) { $_data .= $this->_db->quote($data['audio_soundcloud_title']); } else { $_data .= $this->_db->quote(''); } return $_data; } if ($data['audio_soundcloud_hidden_image']) { $this->deleteThumb(null, $data['audio_soundcloud_hidden_image']); } return $this->_db->quote('') . ',' . $this->_db->quote('') . ',' . $this->_db->quote(''); } return $this->_db->quote('') . ',' . $this->_db->quote('') . ',' . $this->_db->quote(''); }
function newMediaObject($blogid, $username, $password, $file) { global $xmlrpcStruct, $xmlrpcArray; if (!plgXMLRPCmetaWeblogHelper::authenticateUser($username, $password)) { return new xmlrpcresp(0, $xmlrpcerruser + 1, "Login Failed"); } $user =& JUser::getInstance($username); $access = new stdClass(); $access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own'); if (strpos($file['name'], '/') !== FALSE) { $file['name'] = substr($file['name'], strrpos($file['name'], '/') + 1); } elseif (strpos($file['name'], '\\' !== FALSE)) { $file['name'] = substr($file['name'], strrpos($file['name'], '\\') + 1); } $dir = JPATH_ROOT . DS . 'media' . DS . $user->name . DS; $tmp_dir = JPATH_ROOT . DS . 'tmp' . DS; if (!is_dir($dir)) { mkdir($dir); } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $dirPrevPermission = JPath::getPermissions($dir); $tmp_dirPrevPermission = JPath::getPermissions($tmp_dir); jimport('joomla.filesystem.file'); $return = JFile::write($file, $filecontent); $file['name'] = JFile::makesafe($file['name']); $file['name'] = substr($file['name'], 0, -4) . rand() . '.' . JFile::getExt($file['name']); $file['tmp_name'] = $tmp_dir . $file['name']; JFile::write($file['tmp_name'], $file['bits']); jimport('joomla.application.component.helper'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_media' . DS . 'helpers' . DS . 'media.php'; if (!MediaHelper::canUpload($file, $error)) { JFile::delete($file['tmp_name']); return new xmlrpcresp(0, $xmlrpcerruser + 1, 'The file is not valid'); } JFile::write($dir . $file['name'], $file['bits']); JFile::delete($file['tmp_name']); return new xmlrpcresp(new xmlrpcval(array('url' => new xmlrpcval(JURI::root() . 'media/' . $user->name . '/' . $file['name'])), 'struct')); }
/** * Method to store the source file contents. * * @param array $data The source data to save. * * @return boolean True on success, false otherwise and internal error set. * * @since 1.6 */ public function save($data) { jimport('joomla.filesystem.file'); // Get the extension. $extension = $this->getExtension(); if (empty($extension)) { return false; } $app = JFactory::getApplication(); $fileName = base64_decode($app->input->get('file')); $filePath = JPath::clean(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'com_visforms' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $fileName); // Include the extension plugins for the save events. JPluginHelper::importPlugin('extension'); $user = get_current_user(); chown($filePath, $user); JPath::setPermissions($filePath, '0644'); // Try to make the css file writable. if (!is_writable($filePath)) { $app->enqueueMessage(JText::_('COM_VISFORMS_ERROR_SOURCE_FILE_NOT_WRITABLE'), 'warning'); $app->enqueueMessage(JText::_('COM_VISFORMS_FILE_PERMISSIONS' . JPath::getPermissions($filePath)), 'warning'); if (!JPath::isOwner($filePath)) { $app->enqueueMessage(JText::_('COM_VISFORMS_CHECK_FILE_OWNERSHIP'), 'warning'); } return false; } $return = JFile::write($filePath, $data['source']); // Try to make the css file unwritable. if (JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0444')) { $app->enqueueMessage(JText::_('COM_VISFORMS_ERROR_SOURCE_FILE_NOT_UNWRITABLE'), 'error'); return false; } elseif (!$return) { $app->enqueueMessage(JText::sprintf('COM_VISFORMS_ERROR_FAILED_TO_SAVE_FILENAME', $fileName), 'error'); return false; } $explodeArray = explode('.', $fileName); $ext = end($explodeArray); return true; }
/** * Helper wrapper method for getPermissions * * @param string $path The path of a file/folder. * * @return string Filesystem permissions. * * @see JPath::getPermissions() * @since 3.4 */ public function getPermissions($path) { return JPath::getPermissions($path); }