本文整理汇总了PHP中JFile::write方法的典型用法代码示例。如果您正苦于以下问题:PHP JFile::write方法的具体用法?PHP JFile::write怎么用?PHP JFile::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JFile
的用法示例。
在下文中一共展示了JFile::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadPackage
/**
* Downloads a package
*
* @param string $url URL of file to download
* @param string $target Download target filename [optional]
*
* @return mixed Path to downloaded package or boolean false on failure
*
* @since 11.1
*/
public static function downloadPackage($url, $target = false)
{
$config = JFactory::getConfig();
// Capture PHP errors
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Set user agent
$version = new JVersion();
ini_set('user_agent', $version->getUserAgent('Installer'));
$http = JHttpFactory::getHttp();
$response = $http->get($url);
if (200 != $response->code) {
JLog::add(JText::_('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT'), JLog::WARNING, 'jerror');
return false;
}
if ($response->headers['wrapper_data']['Content-Disposition']) {
$contentfilename = explode("\"", $response->headers['wrapper_data']['Content-Disposition']);
$target = $contentfilename[1];
}
// Set the target path if not given
if (!$target) {
$target = $config->get('tmp_path') . '/' . self::getFilenameFromURL($url);
} else {
$target = $config->get('tmp_path') . '/' . basename($target);
}
// Write buffer to file
JFile::write($target, $response->body);
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Bump the max execution time because not using built in php zip libs are slow
@set_time_limit(ini_get('max_execution_time'));
// Return the name of the downloaded package
return basename($target);
}
示例2: _renderStatus
public function _renderStatus()
{
$date = JFactory::getDate();
$jparam = new JConfig();
if (!JFile::exists(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_community' . DS . 'community.xml')) {
return false;
}
if (JFile::exists($jparam->tmp_path . DS . 'jomsocialupdate.ini')) {
$lastcheckdate = JFile::read($jparam->tmp_path . DS . 'jomsocialupdate.ini');
} else {
$lastcheckdate = $date->toFormat();
}
JFile::write($jparam->tmp_path . DS . 'jomsocialupdate.ini', $lastcheckdate);
$dayInterval = 1;
// days
$currentdate = $date->toFormat();
$checkVersion = strtotime($currentdate) > strtotime($lastcheckdate) + $dayInterval * 60 * 60 * 24;
// Load language
$lang = JFactory::getLanguage();
$lang->load('com_community', JPATH_ROOT . DS . 'administrator');
$button = $this->_getButton($checkVersion);
$html = JResponse::getBody();
$html = str_replace('<div id="module-status">', '<div id="module-status">' . $button, $html);
// Load AJAX library for the back end.
$jax = new JAX(rtrim(JURI::root(), '/') . '/plugins/system/pc_includes');
$jax->setReqURI(rtrim(JURI::root(), '/') . '/administrator/index.php');
$jaxScript = $jax->getScript();
JResponse::setBody($html . $jaxScript);
}
示例3: protect
/**
* Applies the back-end protection, creating an appropriate .htaccess and
* .htpasswd file in the administrator directory.
*
* @return bool
*/
public function protect()
{
JLoader::import('joomla.filesystem.file');
$cryptpw = $this->apacheEncryptPassword();
$htpasswd = $this->username . ':' . $cryptpw . "\n";
$status = JFile::write(JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . '.htpasswd', $htpasswd);
if (!$status) {
return false;
}
$path = rtrim(JPATH_ADMINISTRATOR, '/\\') . DIRECTORY_SEPARATOR;
$htaccess = <<<ENDHTACCESS
AuthUserFile "{$path}.htpasswd"
AuthName "Restricted Area"
AuthType Basic
require valid-user
RewriteEngine On
RewriteRule \\.htpasswd\$ - [F,L]
ENDHTACCESS;
$status = JFile::write(JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . '.htaccess', $htaccess);
if (!$status || !is_file($path . '/.htpasswd')) {
JFile::delete(JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . '.htpasswd');
return false;
}
return true;
}
示例4: extract
/**
* Extract a ZIP compressed file to a given path
*
* @access public
* @param string $archive Path to ZIP archive to extract
* @param string $destination Path to extract archive into
* @param array $options Extraction options [unused]
* @return boolean True if successful
* @since 1.5
*/
function extract($archive, $destination, $options = array())
{
// Initialize variables
$this->_data = null;
$this->_metadata = null;
if (!($this->_data = JFile::read($archive))) {
$this->set('error.message', 'Unable to read archive');
return JError::raiseWarning(100, $this->get('error.message'));
}
if (!$this->_getTarInfo($this->_data)) {
return JError::raiseWarning(100, $this->get('error.message'));
}
for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) {
$type = strtolower($this->_metadata[$i]['type']);
if ($type == 'file' || $type == 'unix file') {
$buffer = $this->_metadata[$i]['data'];
$path = JPath::clean($destination . DS . $this->_metadata[$i]['name']);
// Make sure the destination folder exists
if (!JFolder::create(dirname($path))) {
$this->set('error.message', 'Unable to create destination');
return JError::raiseWarning(100, $this->get('error.message'));
}
if (JFile::write($path, $buffer) === false) {
$this->set('error.message', 'Unable to write entry');
return JError::raiseWarning(100, $this->get('error.message'));
}
}
}
return true;
}
示例5: _fixManifest
/**
* Fix Joomsef manifest files, to force upgrade method
*
*/
protected function _fixManifest()
{
jimport('joomla.filesystem.file');
// fix original file
$source = $this->parent->getPath('source');
$path = $source . DS . $this->_getElement() . '.xml';
$fileContent = JFile::read($path);
if (!empty($fileContent)) {
$fileContent = str_replace('type="sef_ext"', 'type="sef_ext" method="upgrade"', $fileContent);
$defaults = array();
$remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false);
$remotes = empty($remoteConfig->config['joomsef_prefixes']) ? array() : $remoteConfig->config['joomsef_prefixes'];
$prefixes = array_unique(array_merge($defaults, $remotes));
foreach ($prefixes as $prefix) {
$fileContent = preg_replace('/function\\s*' . preg_quote($prefix) . '\\s*\\(\\s*\\)\\s*\\{/isU', 'function ' . $prefix . '() { return;', $fileContent);
}
// generic replace
$defaultReplaces = array();
$remoteReplaces = empty($remoteConfig->config['joomsef_prefixes']) ? array() : $remoteConfig->config['joomsef_prefixes'];
$replaces = array_unique(array_merge($defaultReplaces, $remoteReplaces));
foreach ($replaces as $replace) {
$fileContent = preg_replace('/' . $replace['source'] . '/sU', $replace['target'], $fileContent);
}
// group="seo" is of no use for us, so leave it behind
$written = JFile::write($path, $fileContent);
}
// fix in memory object, by killing it, thus prompting recreation
$manifest =& $this->parent->getManifest();
$manifest = null;
$manifest =& $this->parent->getManifest();
$this->manifest =& $manifest->document;
}
示例6: uninstall
/**
* Uninstall Kunena, run from Joomla installer.
*/
public function uninstall()
{
// Put back file that was removed during installation.
$contents = '';
JFile::write(KPATH_ADMIN . '/install.php', $contents);
// Uninstall all plugins.
$this->uninstallPlugin('kunena', 'alphauserpoints');
$this->uninstallPlugin('kunena', 'community');
$this->uninstallPlugin('kunena', 'comprofiler');
$this->uninstallPlugin('kunena', 'gravatar');
$this->uninstallPlugin('kunena', 'joomla');
$this->uninstallPlugin('kunena', 'kunena');
$this->uninstallPlugin('kunena', 'uddeim');
$this->uninstallPlugin('finder', 'kunena');
// Uninstall menu module.
$this->uninstallModule('mod_kunenamenu');
// Remove all Kunena related menu items, including aliases
if (class_exists('KunenaMenuFix')) {
$items = KunenaMenuFix::getAll();
foreach ($items as $item) {
KunenaMenuFix::delete($item->id);
}
}
$this->deleteMenu();
return true;
}
示例7: __construct
/**
* Constructor
*
* @param object An optional KConfig object with configuration options
*/
public function __construct(KConfig $config)
{
parent::__construct($config);
foreach (array('enabled' => true, 'levels' => 3, 'limit' => 0, 'offset' => 0, 'sort' => 'path_sort_ordering') as $key => $val) {
$this->_request->{$key} = $val;
}
//Set model recurse
//if(KRequest::method() == 'GET') KRequest::set('get.recurse', true);
//Set other model states
//KRequest::set('get.enabled', true);
$this->registerCallback(array('before.read', 'before.browse'), array($this, 'setOrdering'));
if ($this->isDispatched()) {
$this->registerCallback('after.read', array($this, 'setCanonical'));
}
$cache = JPATH_ROOT . '/cache/com_' . $this->getIdentifier()->package . '/maintenance.txt';
if (!JFile::exists($cache)) {
if (KFactory::get('admin::com.ninjaboard.controller.maintenance')->topics() && KFactory::get('admin::com.ninjaboard.controller.maintenance')->forums()) {
JFile::write($cache, date('r'));
}
}
$user = KFactory::get('lib.joomla.user');
// User specific maintenance
if (!$user->guest) {
$cache = JPATH_ROOT . '/cache/com_' . $this->getIdentifier()->package . '/maintenance.' . $user->id . '.txt';
if (!JFile::exists($cache)) {
if (KFactory::get('admin::com.ninjaboard.controller.maintenance')->logtopicreads()) {
JFile::write($cache, date('r'));
}
}
}
}
示例8: __construct
function __construct($options = array())
{
static $expiredCacheCleaned;
$this->profile_db = JFactory::getDBO();
$this->db = clone $this->profile_db;
$this->_language = isset($options['language']) ? $options['language'] : 'en-GB';
$this->_lifetime = isset($options['lifetime']) ? $options['lifetime'] : 60;
$this->_now = isset($options['now']) ? $options['now'] : time();
$config = JFactory::getConfig();
$this->_hash = $config->get('config.secret');
// if its not the first instance of the joomfish db cache then check if it should be cleaned and otherwise garbage collect
if (!isset($expiredCacheCleaned)) {
// check a file in the 'file' cache to check if we should remove all our db cache entries since cache manage doesn't handle anything other than file caches
$conf = JFactory::getConfig();
$cachebase = $conf->get('cache_path', JPATH_ROOT . DS . 'cache');
$cachepath = $cachebase . DS . "falang-cache";
if (!JFolder::exists($cachepath)) {
JFolder::create($cachepath);
}
$cachefile = $cachepath . DS . "cachetest.txt";
jimport("joomla.filesystem.file");
if (!JFile::exists($cachefile) || JFile::read($cachefile) != "valid") {
// clean out the whole cache
$this->cleanCache();
//sbou TODO uncomment write and solve problem
JFile::write($cachefile, "valid");
}
$this->gc();
}
$expiredCacheCleaned = true;
}
示例9: map
public function map(&$file, $index, &$contents)
{
// Store the file to a temporary location
$file['tmp_name'] = $this->tmp . '/' . md5($file['name']);
JFile::write($file['tmp_name'], $file['data']);
// Load up media manager now
$mm = EB::mediamanager();
$result = $mm->upload($file, 'user:' . $this->authorId);
$title = $file['name'];
$url = $this->absoluteUrl . '/' . $file['name'];
// Get the properties from media manager result
if (is_object($result) && property_exists($result, 'title')) {
$title = $result->title;
$url = $result->url;
}
// Once the attachment is already uploaded, we want to delete the temporary file now
JFile::delete($file['tmp_name']);
// Check if a file id is provided in the email
if (isset($file['id']) && !empty($file['id'])) {
$fileId = $file['id'];
$fileId = str_replace('<', '', $fileId);
$fileId = str_replace('>', '', $fileId);
$patterns = array('/<div><img[^>]*src="[A-Za-z0-9:^>]*' . $fileId . '"[^>]*\\/><\\/div>/si', '/<img[^>]*src="[A-Za-z0-9:^>]*' . $fileId . '"[^>]*\\/>/si');
$replace = array('', '');
$contents = preg_replace($patterns, $replace, $contents);
}
// Now we need to insert the pdf links into the content
$template = EB::template();
$template->set('title', $title);
$template->set('url', $url);
$output = $template->output('site/mailpublishing/template.pdf');
$contents .= $output;
}
示例10: shrink
/**
* Function that will merge & minify the provided files
*
* @param array $files - array with relative paths to js files
* @param string $cachePath - where to save the new merged & minified file
*
* @return string
*/
public static function shrink(array $files, $cachePath)
{
$times = array();
$md5 = md5(json_encode($files));
$url = $cachePath . '/' . $md5 . '.min.js';
$minFile = JPATH_ROOT . '/' . $url;
// Lets read the times of the files we need to merge
foreach ($files as $file) {
if (file_exists(JPATH_ROOT . '/' . $file)) {
$times[] = filemtime(JPATH_ROOT . '/' . $file);
}
}
// If the minFile doesn't exist or the minFile time is older than any of the times, let's do our job!
if (!file_exists($minFile) || max($times) > filemtime($minFile)) {
$js = '';
foreach ($files as $file) {
if (file_exists(JPATH_ROOT . '/' . $file)) {
$js[] = file_get_contents(JPATH_ROOT . '/' . $file);
}
}
// Do the actual minifying
$minJs = CompojoomMinifier::minify(implode($js));
JFile::write($minFile, $minJs);
}
return $url;
}
示例11: disableInfoMode
/**
*
* Disable JT3 infomode
*
* @return: Save setting to file params.ini
*/
public function disableInfoMode()
{
JSNFactory::localimport('libraries.joomlashine.database');
$template = JSNDatabase::getDefaultTemplate();
$client = JApplicationHelper::getClientInfo($template->client_id);
$file = $client->path . '/templates/' . $template->element . '/params.ini';
$data = JFile::read($file);
$data = explode("\n", $data);
$params = array();
$needChange = false;
foreach ($data as $val) {
$spos = strpos($val, "=");
$key = substr($val, 0, $spos);
$value = substr($val, $spos + 1, strlen($val) - $spos);
if ($key == 'infomode') {
if ($value == '"1"') {
$value = '"0"';
$needChange = true;
}
}
$params[$key] = $value;
}
if ($needChange) {
$data = array();
foreach ($params as $key => $val) {
$data[] = $key . '=' . $val;
}
$data = implode("\n", $data);
if (JFile::exists($file)) {
@chmod($file, 0777);
}
JFile::write($file, $data);
}
}
示例12: postflight
/**
* Method to run after installing the component
*/
function postflight($type, $parent)
{
//Restore the modified language strings by merging to language files
$registry = new JRegistry();
foreach (self::$languageFiles as $languageFile) {
$backupFile = JPATH_ROOT . '/language/en-GB/bak.' . $languageFile;
$currentFile = JPATH_ROOT . '/language/en-GB/' . $languageFile;
if (JFile::exists($currentFile) && JFile::exists($backupFile)) {
$registry->loadFile($currentFile, 'INI');
$currentItems = $registry->toArray();
$registry->loadFile($backupFile, 'INI');
$backupItems = $registry->toArray();
$items = array_merge($currentItems, $backupItems);
$content = "";
foreach ($items as $key => $value) {
$content .= "{$key}=\"{$value}\"\n";
}
JFile::write($currentFile, $content);
}
}
// Restore custom modified css file
if (JFile::exists(JPATH_ROOT . '/components/com_osmembership/assets/css/bak.custom.css')) {
JFile::copy(JPATH_ROOT . '/components/com_osmembership/assets/css/bak.custom.css', JPATH_ROOT . '/components/com_osmembership/assets/css/custom.css');
JFile::delete(JPATH_ROOT . '/components/com_osmembership/assets/css/bak.custom.css');
}
}
示例13: migrateSettings
function migrateSettings()
{
$db =& JFactory::getDBO();
$config =& JFactory::getConfig();
$tables = $db->getTableList();
if (in_array($config->getValue('config.dbprefix') . 'migration_configuration', $tables)) {
$db->setQuery("SELECT `key`,`value` FROM #__migration_configuration");
$results = $db->loadAssocList();
if (!is_array($results)) {
echo $db->getErrorMsg();
return;
}
$cfg = JFactory::getConfig();
foreach ($results as $result) {
$cfg->setValue('config.' . $result['key'], $result['value']);
}
echo '<p>' . JText::_('Updating your configuration file') . '</p>';
//echo '<pre>'.print_r(htmlspecialchars($cfg->toString('PHP', 'config', array('class' => 'JConfig'))),1).'</pre>';
jimport('joomla.filesystem.file');
$fname = JPATH_CONFIGURATION . DS . 'configuration.php';
if (JFile::write($fname, $cfg->toString('PHP', 'config', array('class' => 'JConfig')))) {
$msg = JText::_('The Configuration Details have been updated');
} else {
$msg = JText::_('ERRORCONFIGFILE');
}
} else {
$msg = JText::_('Error') . ': ' . JText::_('Migration Configuration table not found') . '. ' . JText::_('Was this site migrated with Migrator RC7 or greater') . '?';
}
echo '<p>' . $msg . '</p>';
//echo '<p><a href="index.php?option=com_migrationassistant">'. JText::_('Home') .'</a></p>';
}
示例14: fetchElement
/**
* @global gantry used to access the core Gantry class
* @param $name
* @param $value
* @param $node
* @param $control_name
* @return void
*/
function fetchElement($name, $value, &$node, $control_name)
{
global $gantry;
if ($gantry->get('file-inline-js-enabled') && isset($gantry->document->_script)) {
jimport('joomla.filesystem.file');
$filename = JPATH_ADMINISTRATOR.DS.'tmp'.DS.'inline-javascript.js';
$scripts = $gantry->document->_script;
if (is_array($scripts)){
$buffer = "";
foreach($scripts as $jsLine) {
if (is_array($jsLine)) {
foreach($jsLine as $line) $buffer .= $line;
} else {
$buffer .= $jsLine;
}
}
JFile::write($filename, $buffer);
} else {
JFile::write($filename, $gantry->document->_script);
}
// add reference to static file
$gantry->document->addScript('tmp/inline-javascript.js');
// clear out the inline script from document;
$gantry->document->_script = '';
}
}
示例15: createBackUpFileForMigrate
public function createBackUpFileForMigrate()
{
$session = JFactory::getSession();
$preVersion = (double) str_replace('.', '', $session->get('preversion', null, 'jsnimageshow'));
$version400 = (double) str_replace('.', '', '4.0.0');
//$preVersion = 313;
if (!$preVersion) {
return;
}
if ($preVersion < $version400) {
$objJSNISMaintenance = JSNISFactory::getObj('classes.jsn_is_maintenance313', null, 'database');
$xmlString = $objJSNISMaintenance->renderXMLData(true, true);
} else {
if ($preVersion >= $version400) {
$objJSNISData = JSNISFactory::getObj('classes.jsn_is_data');
$xmlString = $objJSNISData->executeBackup(true, true)->asXML();
}
}
$fileBackupName = 'jsn_imageshow_backup_db.xml';
$fileZipName = 'jsn_is_backup_for_migrate_' . $preVersion . '_' . date('YmdHis') . '.zip';
if (JFile::write(JPATH_ROOT . DS . 'tmp' . DS . $fileBackupName, $xmlString)) {
$config = JPATH_ROOT . DS . 'tmp' . DS . $fileZipName;
$zip = JSNISFactory::getObj('classes.jsn_is_archive', 'JSNISZIPFile', $config);
$zip->setOptions(array('inmemory' => 1, 'recurse' => 0, 'storepaths' => 0));
$zip->addFiles(JPATH_ROOT . DS . 'tmp' . DS . $fileBackupName);
$zip->createArchive();
$zip->writeArchiveFile();
$FileDelte = JPATH_ROOT . DS . 'tmp' . DS . $fileBackupName;
$session->set('jsn_is_backup_for_migrate', $fileZipName, 'jsnimageshow');
return true;
}
return false;
}