本文整理汇总了PHP中gpFiles::Rename方法的典型用法代码示例。如果您正苦于以下问题:PHP gpFiles::Rename方法的具体用法?PHP gpFiles::Rename怎么用?PHP gpFiles::Rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpFiles
的用法示例。
在下文中一共展示了gpFiles::Rename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PageFile
/**
* Return the data file location for a title
* Since v4.6, page files are within a subfolder
* As of v2.3.4, it defaults to an index based file name but falls back on title based file name for installation and backwards compatibility
*
*
* @param string $title
* @return string The path of the data file
*/
public static function PageFile($title)
{
global $dataDir, $config, $gp_index;
$index_path = false;
if (gp_index_filenames && isset($gp_index[$title]) && isset($config['gpuniq'])) {
// page.php
$index_path = $dataDir . '/data/_pages/' . substr($config['gpuniq'], 0, 7) . '_' . $gp_index[$title] . '/page.php';
if (file_exists($index_path)) {
return $index_path;
}
// without folder -> rename it
$old_index = $dataDir . '/data/_pages/' . substr($config['gpuniq'], 0, 7) . '_' . $gp_index[$title] . '.php';
if (file_exists($old_index)) {
if (gpFiles::Rename($old_index, $index_path)) {
return $index_path;
}
return $old_index;
}
}
//using file name instead of index
$normal_path = $dataDir . '/data/_pages/' . str_replace('/', '_', $title) . '/page.php';
if (!$index_path || gpFiles::Exists($normal_path)) {
return $normal_path;
}
//without folder -> rename it
$old_path = $dataDir . '/data/_pages/' . str_replace('/', '_', $title) . '.php';
if (gpFiles::Exists($old_path)) {
if ($index_path && gpFiles::Rename($old_path, $index_path)) {
return $index_path;
}
if (gpFiles::Rename($old_path, $normal_path)) {
return $normal_path;
}
return $old_path;
}
return $index_path;
}
示例2: UploadedArchive
/**
* Get an archive object from the uploaded file
*
*/
function UploadedArchive()
{
global $langmessage;
if (empty($_FILES['plugin'])) {
msg($langmessage['OOPS'] . ' (No File)');
return;
}
$plugin_file = $_FILES['plugin'];
if (strpos($plugin_file['name'], '.zip') === false) {
msg($langmessage['OOPS'] . ' (Not a zip file)');
return;
}
//rename tmp file to have zip extenstion
if (!gpFiles::Rename($plugin_file['tmp_name'], $plugin_file['tmp_name'] . '.zip')) {
msg($langmessage['OOPS'] . ' (Not renamed)');
return;
}
$plugin_file['tmp_name'] .= '.zip';
return new \gp\tool\Archive($plugin_file['tmp_name']);
}
示例3: RenameFileWorker
static function RenameFileWorker($title)
{
global $langmessage, $dataDir, $gp_index;
//use new_label or new_title
if (isset($_POST['new_title'])) {
$new_title = admin_tools::PostedSlug($_POST['new_title']);
} else {
$new_title = admin_tools::LabelToSlug($_POST['new_label']);
}
//title unchanged
if ($new_title == $title) {
return $title;
}
$special_file = false;
if (common::SpecialOrAdmin($title)) {
$special_file = true;
}
if (!admin_tools::CheckTitle($new_title, $message)) {
msg($message);
return false;
}
$old_gp_index = $gp_index;
//re-index: make the new title point to the same data index
$old_file = gpFiles::PageFile($title);
$file_index = $gp_index[$title];
unset($gp_index[$title]);
$gp_index[$new_title] = $file_index;
//rename the php file
if (!$special_file) {
$new_file = gpFiles::PageFile($new_title);
//we don't have to rename files if we're using the index naming convention. See gpFiles::PageFile() for more info
if ($new_file == $old_file) {
//if the file being renamed doesn't use the index naming convention, then we'll still need to rename it
} else {
$new_dir = dirname($new_file);
$old_dir = dirname($old_file);
if (!gpFiles::Rename($old_dir, $new_dir)) {
msg($langmessage['OOPS'] . ' (N3)');
$gp_index = $old_gp_index;
return false;
}
}
//gallery rename
includeFile('special/special_galleries.php');
special_galleries::RenamedGallery($title, $new_title);
}
//create a 301 redirect
if (isset($_POST['add_redirect']) && $_POST['add_redirect'] == 'add') {
includeFile('admin/admin_missing.php');
admin_missing::AddRedirect($title, $new_title);
}
gpPlugin::Action('RenameFileDone', array($file_index, $title, $new_title));
return $new_title;
}
示例4: RestoreTitles
/**
* Restore $titles and return array with menu information
* @param array $titles An array of titles to be restored. After completion, it will contain only the titles that were prepared successfully
* @return array A list of restored titles that can be used for menu insertion
*
*/
static function RestoreTitles(&$titles)
{
global $dataDir, $gp_index, $gp_titles, $config;
$new_menu = array();
$restored = array();
foreach ($titles as $trash_index) {
//get trash info about file
$title_info = admin_trash::GetInfo($trash_index);
if ($title_info === false) {
continue;
}
$new_title = admin_tools::CheckPostedNewPage($title_info['title'], $message);
if (!$new_title) {
continue;
}
//make sure the page_file exists
if (!gpFiles::Exists($title_info['page_file'])) {
continue;
}
//add to $gp_index before PageFile()
if (isset($title_info['index'])) {
$index = $title_info['index'];
$gp_index[$new_title] = $index;
} else {
$index = common::NewFileIndex();
$gp_index[$new_title] = $index;
}
// move the trash file to the /_pages directory if needed
$new_file = gpFiles::PageFile($new_title);
if (!gpFiles::Exists($new_file)) {
if (!gpFiles::Rename($title_info['page_file'], $new_file)) {
unset($gp_index[$new_title]);
continue;
}
}
//add to $gp_titles
$gp_titles[$index] = array();
$gp_titles[$index]['label'] = $title_info['label'];
$gp_titles[$index]['type'] = $title_info['type'];
$new_menu[$index] = array();
$restored[$trash_index] = $title_info;
admin_trash::RestoreFile($new_title, $new_file, $title_info);
}
$titles = $restored;
return $new_menu;
}