rename function
This commit is contained in:
parent
d184b3fa86
commit
6a786342f9
@ -245,7 +245,7 @@ function wiki_create_page($name, $resource_id) {
|
|||||||
return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false);
|
return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)) . wiki_get_mimetype($w));
|
$page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)) . wiki_get_file_ext($w));
|
||||||
$page_path = $w['path'] . '/' . $page['fileName'];
|
$page_path = $w['path'] . '/' . $page['fileName'];
|
||||||
if (is_file($page_path)) {
|
if (is_file($page_path)) {
|
||||||
return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false);
|
return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false);
|
||||||
@ -267,11 +267,11 @@ function wiki_rename_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Wiki not found.', 'success' => false);
|
return array('message' => 'Wiki not found.', 'success' => false);
|
||||||
}
|
}
|
||||||
$page_path_old = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w);
|
$page_path_old = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
|
||||||
if (!is_readable($page_path_old) === true) {
|
if (!is_readable($page_path_old) === true) {
|
||||||
return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false);
|
return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false);
|
||||||
}
|
}
|
||||||
$page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)) . wiki_get_mimetype($w));
|
$page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)) . wiki_get_file_ext($w));
|
||||||
$page_path_new = $w['path'] . '/' . $page['fileName'] ;
|
$page_path_new = $w['path'] . '/' . $page['fileName'] ;
|
||||||
if (is_file($page_path_new)) {
|
if (is_file($page_path_new)) {
|
||||||
return array('message' => 'Page already exists.', 'success' => false);
|
return array('message' => 'Page already exists.', 'success' => false);
|
||||||
@ -292,7 +292,7 @@ function wiki_get_page_content($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('content' => null, 'message' => 'Error reading wiki', 'success' => false);
|
return array('content' => null, 'message' => 'Error reading wiki', 'success' => false);
|
||||||
}
|
}
|
||||||
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w);
|
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
|
||||||
if (is_readable($page_path) === true) {
|
if (is_readable($page_path) === true) {
|
||||||
if(filesize($page_path) === 0) {
|
if(filesize($page_path) === 0) {
|
||||||
$content = '';
|
$content = '';
|
||||||
@ -314,7 +314,7 @@ function wiki_page_history($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('history' => null, 'message' => 'Error reading wiki', 'success' => false);
|
return array('history' => null, 'message' => 'Error reading wiki', 'success' => false);
|
||||||
}
|
}
|
||||||
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w);
|
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
|
||||||
if (!is_readable($page_path) === true) {
|
if (!is_readable($page_path) === true) {
|
||||||
return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false);
|
return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false);
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ function wiki_save_page($arr) {
|
|||||||
return array('message' => 'Error reading wiki', 'success' => false);
|
return array('message' => 'Error reading wiki', 'success' => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileName = $pageUrlName . wiki_get_mimetype($w);
|
$fileName = $pageUrlName . wiki_get_file_ext($w);
|
||||||
$page_path = $w['path'] . '/' . $fileName;
|
$page_path = $w['path'] . '/' . $fileName;
|
||||||
if (is_writable($page_path) === true) {
|
if (is_writable($page_path) === true) {
|
||||||
if(!file_put_contents($page_path, $content)) {
|
if(!file_put_contents($page_path, $content)) {
|
||||||
@ -359,7 +359,7 @@ function wiki_delete_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Error reading wiki', 'success' => false);
|
return array('message' => 'Error reading wiki', 'success' => false);
|
||||||
}
|
}
|
||||||
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w);
|
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
|
||||||
if (is_writable($page_path) === true) {
|
if (is_writable($page_path) === true) {
|
||||||
if(!unlink($page_path)) {
|
if(!unlink($page_path)) {
|
||||||
return array('message' => 'Error deleting page file', 'success' => false);
|
return array('message' => 'Error deleting page file', 'success' => false);
|
||||||
@ -381,7 +381,7 @@ function wiki_revert_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false);
|
return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false);
|
||||||
}
|
}
|
||||||
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w);
|
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
|
||||||
if (is_writable($page_path) === true) {
|
if (is_writable($page_path) === true) {
|
||||||
|
|
||||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
||||||
@ -393,7 +393,7 @@ function wiki_revert_page($arr) {
|
|||||||
try {
|
try {
|
||||||
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
||||||
foreach ($git->git->tree($commitHash) as $object) {
|
foreach ($git->git->tree($commitHash) as $object) {
|
||||||
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) {
|
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) {
|
||||||
$content = $git->git->cat->blob($object['hash']);
|
$content = $git->git->cat->blob($object['hash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ function wiki_compare_page($arr) {
|
|||||||
if (!$w['path']) {
|
if (!$w['path']) {
|
||||||
return array('message' => 'Error reading wiki', 'success' => false);
|
return array('message' => 'Error reading wiki', 'success' => false);
|
||||||
}
|
}
|
||||||
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_mimetype($w);
|
$page_path = $w['path'] . '/' . $pageUrlName . wiki_get_file_ext($w);
|
||||||
if (is_readable($page_path) === true) {
|
if (is_readable($page_path) === true) {
|
||||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
||||||
if($reponame === '') {
|
if($reponame === '') {
|
||||||
@ -428,12 +428,12 @@ function wiki_compare_page($arr) {
|
|||||||
$compareContent = $currentContent = '';
|
$compareContent = $currentContent = '';
|
||||||
try {
|
try {
|
||||||
foreach ($git->git->tree($currentCommit) as $object) {
|
foreach ($git->git->tree($currentCommit) as $object) {
|
||||||
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) {
|
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) {
|
||||||
$currentContent = $git->git->cat->blob($object['hash']);
|
$currentContent = $git->git->cat->blob($object['hash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($git->git->tree($compareCommit) as $object) {
|
foreach ($git->git->tree($compareCommit) as $object) {
|
||||||
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_mimetype($w)) {
|
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName . wiki_get_file_ext($w)) {
|
||||||
$compareContent = $git->git->cat->blob($object['hash']);
|
$compareContent = $git->git->cat->blob($object['hash']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -565,7 +565,7 @@ function wiki_bbcode($s) {
|
|||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wiki_get_mimetype($arr) {
|
function wiki_get_file_ext($arr) {
|
||||||
if($arr['mimeType'] == 'text/bbcode')
|
if($arr['mimeType'] == 'text/bbcode')
|
||||||
return '.bb';
|
return '.bb';
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user