本文整理汇总了PHP中gpFiles::Save方法的典型用法代码示例。如果您正苦于以下问题:PHP gpFiles::Save方法的具体用法?PHP gpFiles::Save怎么用?PHP gpFiles::Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpFiles
的用法示例。
在下文中一共展示了gpFiles::Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put_contents
function put_contents($file, $contents, $type = '')
{
if (!gpFiles::Save($file, $contents)) {
return false;
}
//the gpEasy core does not need to be world writable
@chmod($file, FS_CHMOD_FILE);
return true;
}
示例2: GetRemote
/**
* Get the remote package
*
*/
function GetRemote()
{
global $langmessage, $dataDir;
includeFile('tool/RemoteGet.php');
// check values
if (empty($this->type) || empty($this->id) || !is_numeric($this->id)) {
$this->message($langmessage['OOPS'] . ' (Invalid Request)');
return false;
}
// allowed to remote install?
switch ($this->type) {
case 'plugin':
if (!gp_remote_plugins) {
$this->message($langmessage['OOPS'] . ' (Can\'t remote install plugins)');
return false;
}
break;
case 'theme':
if (!gp_remote_themes) {
$this->message($langmessage['OOPS'] . ' (Can\'t remote install themes)');
return false;
}
break;
default:
$this->message($langmessage['OOPS'] . ' (Invalid Type)');
return false;
}
// able to remote install?
if (!admin_tools::CanRemoteInstall()) {
$this->message($langmessage['OOPS'] . ' (Can\'t remote install)');
return false;
}
// download
$download_link = addon_browse_path;
if ($this->type == 'theme') {
$download_link .= '/Themes';
} else {
$download_link .= '/Plugins';
}
$download_link .= '?cmd=install&id=' . rawurlencode($this->id);
// purchase order id
if (!$this->order) {
$this->order = $this->GetOrder($this->id);
}
if ($this->order) {
$download_link .= '&order=' . rawurlencode($this->order);
}
// get package from remote
$full_result = gpRemoteGet::Get($download_link);
if ((int) $full_result['response']['code'] < 200 && (int) $full_result['response']['code'] >= 300) {
$this->message($langmessage['download_failed'] . ' (1)');
return false;
}
// download failed and a message was sent
if (isset($full_result['headers']['x-error'])) {
$this->message(htmlspecialchars($full_result['headers']['x-error']));
$this->message(sprintf($langmessage['download_failed_xerror'], 'href="' . $this->DetailUrl($_POST['type'], $_POST['id']) . '" data-cmd="remote"'));
return false;
}
$result = $full_result['body'];
$md5 =& $full_result['headers']['x-md5'];
//check md5
$package_md5 = md5($result);
if ($package_md5 != $md5) {
$this->message($langmessage['download_failed_md5'] . ' <br/> (Package Checksum ' . $package_md5 . ' != Expected Checksum ' . $md5 . ')');
return false;
}
//save contents
$tempfile = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon', '.zip');
if (!gpFiles::Save($tempfile, $result)) {
$this->message($langmessage['download_failed'] . ' (Package not saved)');
return false;
}
$this->source = $this->TempFile();
$success = $this->ExtractArchive($tempfile);
unlink($tempfile);
return $success;
}
示例3: GenArchiveGadget
/**
* Regenerate the static content used to display the archive gadget
*
*/
static function GenArchiveGadget()
{
global $addonPathData;
//get list of posts and times
$list = SimpleBlogCommon::AStrToArray('post_times');
if (!count($list)) {
return;
}
//get year counts
$archive = array();
foreach ($list as $post_id => $time) {
$ym = date('Y-m', $time);
//year&month
$archive[$ym][] = $post_id;
}
ob_start();
$prev_year = false;
echo '<ul>';
foreach ($archive as $ym => $posts) {
$y = substr($ym, 0, 4);
$m = substr($ym, -2);
if ($y != $prev_year) {
if ($prev_year !== false) {
echo '</li>';
}
echo '<li><div class="simple_blog_gadget_year">' . $y . '</div>';
$prev_year = $y;
}
$sum = count($posts);
if (!$sum) {
continue;
}
echo '<ul>';
echo '<li><a class="blog_gadget_link">';
$time = strtotime($ym . '-01');
echo strftime('%B', $time);
echo ' (' . $sum . ')</a>';
echo '<ul class="simple_blog_category_posts nodisplay">';
foreach ($posts as $post_id) {
$post_title = SimpleBlogCommon::AStrGet('titles', $post_id);
echo '<li>';
echo SimpleBlogCommon::PostLink($post_id, $post_title);
echo '</li>';
}
echo '</ul>';
echo '</li>';
echo '</ul>';
}
echo '</li></ul>';
$content = ob_get_clean();
$gadgetFile = $addonPathData . '/gadget_archive.php';
gpFiles::Save($gadgetFile, $content);
}
示例4: CacheLess
/**
* Convert a .less file to .css and include it in the page
* @param mixed $less_files A strin or array of less filesThe absolute or relative path of the .less file
*
*/
static function CacheLess($less_files)
{
global $dataDir;
//generage the name of the css file from the modified times and content length of each imported less file
$files_hash = common::ArrayHash($less_files);
$list_file = $dataDir . '/data/_cache/less_' . $files_hash . '.list';
if (file_exists($list_file)) {
$list = explode("\n", file_get_contents($list_file));
//pop the etag
$etag = array_pop($list);
if (!ctype_alnum($etag)) {
$list[] = $etag;
$etag = false;
}
// generate an etag if needed or if logged in
if (!$etag || common::LoggedIn()) {
$etag = common::FilesEtag($list);
}
$compiled_name = 'less_' . $files_hash . '_' . $etag . '.css';
$compiled_file = '/data/_cache/' . $compiled_name;
if (file_exists($dataDir . $compiled_file)) {
//msg('not using cache');
return $compiled_file;
}
}
$less_files = (array) $less_files;
$compiled = gpOutput::ParseLess($less_files, $files_hash);
if (!$compiled) {
return false;
}
// generate the file name
$etag = common::FilesEtag($less_files);
$compiled_name = 'less_' . $files_hash . '_' . $etag . '.css';
$compiled_file = '/data/_cache/' . $compiled_name;
// save the cache
// use the last line for the etag
$less_files[] = $etag;
$cache = implode("\n", $less_files);
if (!gpFiles::Save($list_file, $cache)) {
return false;
}
//save the css
if (file_put_contents($dataDir . $compiled_file, $compiled)) {
return $compiled_file;
}
return false;
}
示例5: RemoteBrowse
/**
* Get addon data from gpEasy.com and display to user
*
*/
function RemoteBrowse()
{
global $langmessage, $config, $dataDir, $gpversion;
//search options
if (isset($_GET['search_option'])) {
$save = true;
switch ($_GET['search_option']) {
case 'version':
unset($config['search_version']);
break;
case 'noversion':
$config['search_version'] = false;
break;
default:
$save = false;
break;
}
if ($save) {
admin_tools::SaveConfig();
}
}
//make a list of installed addon id's
$this->installed_ids = array();
if (isset($config['addons']) && is_array($config['addons'])) {
foreach ($config['addons'] as $addon_info) {
if (isset($addon_info['id'])) {
$this->installed_ids[] = $addon_info['id'];
}
}
}
includeFile('tool/RemoteGet.php');
$orderby = array();
$orderby['rating_score'] = $langmessage['Highest Rated'];
$orderby['downloads'] = $langmessage['Most Downloaded'];
$orderby['modified'] = $langmessage['Recently Updated'];
$orderby['created'] = $langmessage['Newest'];
$_GET += array('q' => '');
$this->searchPage = 0;
if (isset($_REQUEST['page']) && ctype_digit($_REQUEST['page'])) {
$this->searchPage = $_REQUEST['page'];
}
$this->searchQuery = 'cmd=remote';
//version specific search
$search_version = false;
if (!isset($config['search_version']) || $config['search_version']) {
$this->searchQuery .= '&ug=' . rawurlencode($gpversion);
$search_version = true;
}
if (!empty($_GET['q'])) {
$this->searchQuery .= '&q=' . rawurlencode($_GET['q']);
}
if (isset($_GET['order']) && isset($orderby[$_GET['order']])) {
$this->searchOrder = $_GET['order'];
$this->searchQuery .= '&order=' . rawurlencode($_GET['order']);
} else {
reset($orderby);
$this->searchOrder = key($orderby);
}
$slug = 'Special_Addon_Plugins';
if ($this->config_index == 'themes') {
$slug = 'Special_Addon_Themes';
}
$src = $GLOBALS['addonBrowsePath'] . '/' . $slug . '?' . $this->searchQuery . '&page=' . $this->searchPage;
//check cache
$cache_file = $dataDir . '/data/_remote/' . sha1($src) . '.txt';
$use_cache = false;
if (file_exists($cache_file) && filemtime($cache_file) + 26100 > time()) {
$result = file_get_contents($cache_file);
$use_cache = true;
} else {
$result = gpRemoteGet::Get_Successful($src);
}
if (!$result) {
echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f1)</p>';
return;
}
if (strpos($result, 'a:') !== 0) {
echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f2)</p>';
return;
}
$data = unserialize($result);
if (count($data) == 0) {
echo '<p>' . $langmessage['Sorry, data not fetched'] . ' (f3)</p>';
return;
}
//save the cache
if (!$use_cache) {
gpFiles::Save($cache_file, $result);
}
$this->searchMax = $data['max'];
if (isset($data['per_page']) && $data['per_page']) {
$this->searchPerPage = $data['per_page'];
} else {
$this->searchPerPage = count($data['rows']);
}
$this->searchOffset = $this->searchPage * $this->searchPerPage;
//.........这里部分代码省略.........
示例6: GenGadget
/**
* Regenerate the static content used to display the gadget
*
*/
function GenGadget()
{
global $langmessage;
$posts = array();
$show_posts = $this->WhichPosts(0, $this->blogData['gadget_entries']);
ob_start();
$label = gpOutput::SelectText('Blog');
if (!empty($label)) {
echo '<h3>';
echo common::Link('Special_Blog', $label);
echo '</h3>';
}
foreach ($show_posts as $post_index) {
//get $posts
if (!isset($posts[$post_index])) {
$posts = $this->GetPostFile($post_index, $post_file);
}
if (!isset($posts[$post_index])) {
continue;
}
$post =& $posts[$post_index];
$header = '<b class="simple_blog_title">';
$label = str_replace('_', ' ', $post['title']);
$header .= common::Link('Special_Blog', $label, 'id=' . $post_index);
$header .= '</b>';
$this->BlogHead($header, $post_index, $post, true);
$content = strip_tags($post['content']);
if ($this->blogData['gadget_abbrev'] > 6 && strlen($content) > $this->blogData['gadget_abbrev']) {
$cut = $this->blogData['gadget_abbrev'];
//php4 strpos
//$pos = strpos($content,' ',$cut-5);
$temp = substr($content, $cut - 5);
$pos = strpos($temp, ' ') + $cut - 5;
if ($pos > 0 && $cut + 20 > $pos) {
$cut = $pos;
}
$content = substr($content, 0, $cut) . ' ... ';
$label = gpOutput::SelectText('Read More');
$content .= common::Link('Special_Blog', $label, 'id=' . $post_index);
}
echo '<p class="simple_blog_abbrev">';
echo $content;
echo '</p>';
}
if ($this->blogData['post_count'] > 3) {
$label = gpOutput::SelectText('More Blog Entries');
echo common::Link('Special_Blog', $label);
}
$gadget = ob_get_clean();
$gadgetFile = $this->addonPathData . '/gadget.php';
gpFiles::Save($gadgetFile, $gadget);
}
示例7: PutFiles
/**
* Put the files in $file_list in the destination folder
* If the second destination folder is set, use gpFiles methods
*
* @param array $file_list List of files
* @param string $dest_rel The relative destination directory for $file_list
* @param bool $gpfiles False to use $gp_filesystem for file replacement, True for gpFiles methods
* @return bool
*/
function PutFiles($file_list, $dest_rel, $gpfiles = false)
{
global $gp_filesystem, $langmessage, $dataDir;
$dest_fs = $gp_filesystem->get_base_dir() . $dest_rel;
if ($gpfiles) {
$dest = $dataDir . $dest_rel;
}
//create destination
if (!$gp_filesystem->mkdir($dest_fs)) {
message($langmessage['revert_failed'] . ' Directory not created (0)');
return false;
}
foreach ($file_list as $file_info) {
$path =& $file_info['filename'];
$flag = (int) $file_info['typeflag'];
$full_fs = $dest_fs . $file_info['relative_path'];
$full = false;
if ($gpfiles) {
$full = $dest . $file_info['relative_path'];
}
//create directories
if ($flag === 5) {
if ($full) {
if (!gpFiles::CheckDir($full, false)) {
message($langmessage['revert_failed'] . ' Directory not created (1)');
return false;
}
continue;
}
if (!$gp_filesystem->mkdir($full_fs)) {
message($langmessage['revert_failed'] . ' Directory not created (2)');
return false;
}
continue;
}
//create files
if ($flag === 0) {
$contents = $this->GetImportContents($path);
if ($full) {
if (!gpFiles::Save($full, $contents)) {
message($langmessage['revert_failed'] . ' File not created (1)');
return false;
}
}
if (!$gp_filesystem->put_contents($full_fs, $contents)) {
message($langmessage['revert_failed'] . ' File not created (2)');
return false;
}
continue;
}
//symbolic link
if ($flag === 2) {
$target = $this->FixLink($file_info['link']);
/*
* This is too restrictive
* Can't even check the new folders being created in case the target hasn't been prepared yet
*
if( !file_exists($target) ){
message($langmessage['revert_failed'].' Symlink target doesn\'t exist.');
return false;
}
*/
if (!symlink($target, $full)) {
message($langmessage['revert_failed'] . ' Symlink not created (1)');
return false;
}
}
}
return true;
}
示例8: DownloadSource
function DownloadSource(&$package)
{
global $langmessage, $addonBrowsePath;
/* for testing
* $download = 'http://test.gpeasy.com/gpEasy_test.zip';
* $download = 'http://gpeasy.loc/rocky/x_gpEasy_test.zip';
*/
$download = $addonBrowsePath . '/Special_gpEasy?cmd=download&version=' . urlencode($package['version']) . '&file=' . urlencode($package['zip']);
echo '<li>Downloading version ' . $package['version'] . ' from gpEasy.com.</li>';
$contents = gpRemoteGet::Get_Successful($download);
if (!$contents || empty($contents)) {
echo '<li>' . $langmessage['download_failed'] . ' (1)</li>';
return false;
}
echo '<li>' . $langmessage['package_downloaded'] . '</li>';
$md5 = md5($contents);
if ($md5 != $package['md5']) {
echo '<li>' . $langmessage['download_failed_md5'];
echo '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $package['md5'] . ')';
echo '</li>';
return false;
}
echo '<li>' . $langmessage['download_verified'] . '</li>';
//save contents
$tempfile = $this->tempfile();
if (!gpFiles::Save($tempfile, $contents)) {
message($langmessage['download_failed'] . ' (2)');
return false;
}
$package['file'] = $tempfile;
return true;
}
示例9: CheckDir
/**
* Check recursively to see if a directory exists, if it doesn't attempt to create it
*
* @param string $dir The directory path
* @param bool $index Whether or not to add an index.hmtl file in the directory
* @return bool True on success
*/
function CheckDir($dir, $index = true)
{
global $config, $checkFileIndex;
if (!file_exists($dir)) {
$parent = dirname($dir);
gpFiles::CheckDir($parent, $index);
//ftp mkdir
if (isset($config['useftp'])) {
if (!gpFiles::FTP_CheckDir($dir)) {
return false;
}
} else {
if (!@mkdir($dir, gp_chmod_dir)) {
return false;
}
@chmod($dir, gp_chmod_dir);
//some systems need more than just the 0755 in the mkdir() function
}
}
//make sure there's an index.html file
if ($index && $checkFileIndex) {
$indexFile = $dir . '/index.html';
if (!file_exists($indexFile)) {
gpFiles::Save($indexFile, '<html></html>', false);
}
}
return true;
}
示例10: CacheCSS
function CacheCSS($file)
{
global $dataDir;
$cache_info = array();
$cache_info['min'] = md5($file) . '.css';
$cache_file = $dataDir . '/data/_cache/' . $cache_info['min'];
//echo "\n cache file: ".$cache_file;
//get all the cached files
$temp = new gp_combine_css($file);
//print_r($temp);
gpFiles::Save($cache_file, $temp->content);
$full_path = $dataDir . $file;
$cache_info['mod'] = filemtime($full_path);
$cache_info['len'] = filesize($full_path);
if (is_array($temp->files) && count($temp->files) > 0) {
$cache_info['import'] = $temp->files;
}
$this->css_data[$file] = $cache_info;
$this->css_data_changed = true;
return $cache_info;
}
示例11: SaveCommentData
/**
* Save the comment data for a blog post
*
*/
function SaveCommentData($post_index, $data)
{
global $langmessage;
// check directory
$dir = $this->addonPathData . '/comments';
if (!gpFiles::CheckDir($dir)) {
return false;
}
$commentDataFile = $dir . '/' . $post_index . '.txt';
$dataTxt = serialize($data);
if (!gpFiles::Save($commentDataFile, $dataTxt)) {
return false;
}
// clean pre 1.7.4 files
$commentDataFile = $this->addonPathData . '/comments_data_' . $post_index . '.txt';
if (file_exists($commentDataFile)) {
unlink($commentDataFile);
}
SimpleBlogCommon::AStrValue('comment_counts', $post_index, count($data));
$this->SaveIndex();
//clear comments cache
$cache_file = $this->addonPathData . '/comments/cache.txt';
if (file_exists($cache_file)) {
unlink($cache_file);
}
return true;
}
示例12: SaveCommentData
/**
* Save the comment data for a blog post
*
*/
public static function SaveCommentData($post_index, $data)
{
global $langmessage;
// check directory
$dir = self::$data_dir . '/comments';
if (!gpFiles::CheckDir($dir)) {
return false;
}
$commentDataFile = $dir . '/' . $post_index . '.txt';
$dataTxt = serialize($data);
if (!gpFiles::Save($commentDataFile, $dataTxt)) {
return false;
}
// clean pre 1.7.4 files
$commentDataFile = self::$data_dir . '/comments_data_' . $post_index . '.txt';
if (file_exists($commentDataFile)) {
unlink($commentDataFile);
}
SimpleBlogCommon::AStrSet('comment_counts', $post_index, count($data));
SimpleBlogCommon::SaveIndex();
SimpleBlogCommon::ClearCommentCache();
return true;
}
示例13: UseRevision
/**
* Revert the file data to a previous revision
*
*/
public function UseRevision()
{
global $langmessage;
$time = $_REQUEST['time'];
$full_path = $this->BackupFile($time);
if (is_null($full_path)) {
return false;
}
if (strpos($full_path, '.gze') !== false) {
ob_start();
readgzfile($full_path);
$contents = ob_get_clean();
} else {
$contents = file_get_contents($full_path);
}
$this->SaveBackup();
if (!gpFiles::Save($this->draft_file, $contents)) {
//restore to the draft file
msg($langmessage['OOPS'] . ' (Draft not saved)');
return false;
}
$this->draft_exists = true;
$this->GetFile();
$this->SaveThis(false);
//save again to update the mod time and username
msg($langmessage['SAVED']);
}
示例14: ExtractArchive
/**
* Write Archive
*
*/
function ExtractArchive($dir, $archive_path)
{
global $langmessage;
// Unzip uses a lot of memory, but not this much hopefully
@ini_set('memory_limit', '256M');
includeFile('thirdparty/pclzip-2-8-2/pclzip.lib.php');
$archive = new PclZip($archive_path);
$archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
if (!gpFiles::CheckDir($dir)) {
$this->message(sprintf($langmessage['COULD_NOT_SAVE'], $folder));
return false;
}
//get archive root
$archive_root = false;
foreach ($archive_files as $file) {
if (strpos($file['filename'], '/Addon.ini') !== false) {
$root = dirname($file['filename']);
if (!$archive_root || strlen($root) < strlen($archive_root)) {
$archive_root = $root;
}
}
}
$archive_root_len = strlen($archive_root);
foreach ($archive_files as $file_info) {
$filename = $file_info['filename'];
if ($archive_root) {
if (strpos($filename, $archive_root) !== 0) {
continue;
}
$filename = substr($filename, $archive_root_len);
}
$filename = '/' . trim($filename, '/');
$full_path = $dir . '/' . $filename;
if ($file_info['folder']) {
$folder = $full_path;
} else {
$folder = dirname($full_path);
}
if (!gpFiles::CheckDir($folder)) {
$this->message(sprintf($langmessage['COULD_NOT_SAVE'], $folder));
return false;
}
if ($file_info['folder']) {
continue;
}
if (!gpFiles::Save($full_path, $file_info['content'])) {
$this->message(sprintf($langmessage['COULD_NOT_SAVE'], $full_path));
return false;
}
}
return true;
}
示例15: GetRecent
function GetRecent()
{
if (!file_exists($this->dir)) {
return false;
}
$new_entries = false;
$files = scandir($this->dir);
foreach ($files as $file) {
if ($file == '.' || $file == '..') {
continue;
}
list($post_id, $ext) = explode('.', $file, 2);
if (!is_numeric($post_id)) {
continue;
}
//should already be part of the cache
$full_path = $this->dir . '/' . $file;
$mod_time = filemtime($full_path);
if ($mod_time < $this->cache_mod) {
continue;
}
$data = SimpleBlogCommon::FileData($full_path);
foreach ($data as $comment) {
if ($comment['time'] < $this->cache_mod) {
continue;
}
$unique = $post_id . '.' . $comment['time'];
$comment['post_id'] = $post_id;
$this->cache[$unique] = $comment;
$new_entries = true;
}
}
if ($new_entries) {
uasort($this->cache, array('SimpleBlogComments', 'Sort'));
$dataTxt = serialize($this->cache);
gpFiles::Save($this->cache_file, $dataTxt);
}
}