| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Implementation of hook_help.
|
| 5 |
*/
|
| 6 |
function liquid_moveref_help($section ='') {
|
| 7 |
$output = '';
|
| 8 |
|
| 9 |
switch($section) {
|
| 10 |
case 'admin/modules#description':
|
| 11 |
$output = t('Move references for the Liquid Wiki Engine.');
|
| 12 |
break;
|
| 13 |
case 'admin/help#liquid':
|
| 14 |
$output = t('Move references for the Liquid Wiki Engine.');
|
| 15 |
break;
|
| 16 |
}
|
| 17 |
|
| 18 |
return $output;
|
| 19 |
}
|
| 20 |
|
| 21 |
function liquid_moveref_wikiapi($op, $nid, $wid=NULL, $old_wid=NULL) {
|
| 22 |
switch ($op) {
|
| 23 |
case "insert":
|
| 24 |
// remove move references from this wiki id
|
| 25 |
liquid_moveref_remove_src($wid);
|
| 26 |
|
| 27 |
break;
|
| 28 |
|
| 29 |
case "move":
|
| 30 |
// set move referense
|
| 31 |
liquid_moveref_setref($old_wid, $wid);
|
| 32 |
|
| 33 |
// remove move references from the new wiki id
|
| 34 |
liquid_moveref_remove_src($wid);
|
| 35 |
|
| 36 |
break;
|
| 37 |
|
| 38 |
case "remove":
|
| 39 |
// remove referenses
|
| 40 |
liquid_moveref_remove_dest($wid);
|
| 41 |
|
| 42 |
}
|
| 43 |
}
|
| 44 |
|
| 45 |
function liquid_moveref_wikihook($wid) {
|
| 46 |
if (liquid_moveref_getref($wid))
|
| 47 |
return array('moveref' => array('weight' => 10,
|
| 48 |
'callback' => 'liquid_moveref_page',
|
| 49 |
'params' => array($wid),
|
| 50 |
'menu_callback' => 'liquid_emptymenu'
|
| 51 |
)
|
| 52 |
);
|
| 53 |
}
|
| 54 |
|
| 55 |
function liquid_moveref_page($wid) {
|
| 56 |
$mref = liquid_moveref_getref($wid);
|
| 57 |
// if the page has been moved and we are allowed to redirect...
|
| 58 |
if (!$mref->isNull() && $_GET['redirect']!='no') {
|
| 59 |
drupal_set_message(t("(Redirected from ").
|
| 60 |
l($wid->toURLString(), "wiki/".$wid->identifier(), NULL, "redirect=no"). ')');
|
| 61 |
|
| 62 |
drupal_goto("wiki/".$mref->toURLString());
|
| 63 |
}
|
| 64 |
|
| 65 |
drupal_set_title($wid->toTitleString());
|
| 66 |
|
| 67 |
if (variable_get(PREF_LIQUID_SET_BREADCRUMB, LIQUID_SET_BREADCRUMB_DEFAULT))
|
| 68 |
liquid_set_breadcrumb($wid);
|
| 69 |
|
| 70 |
return t("The node has been moved to ") . l($mref->identifier(), "wiki/".$mref->toURLString()) . '.';
|
| 71 |
}
|
| 72 |
|
| 73 |
function liquid_moveref_remove_src($src) {
|
| 74 |
db_query("DELETE FROM {wiki_moveref} WHERE src='%s'", $src->identifier());
|
| 75 |
}
|
| 76 |
|
| 77 |
function liquid_moveref_remove_dest($dest) {
|
| 78 |
db_query("DELETE FROM {wiki_moveref} WHERE dest='%s'", $dest->identifier());
|
| 79 |
}
|
| 80 |
|
| 81 |
function liquid_moveref_getref($src) {
|
| 82 |
$result = db_query("SELECT * FROM {wiki_moveref} WHERE src='%s'", $src->identifier());
|
| 83 |
|
| 84 |
if (db_num_rows($result) == 0)
|
| 85 |
return NULL;
|
| 86 |
|
| 87 |
$resobj = db_fetch_object($result);
|
| 88 |
|
| 89 |
return new WikiId($resobj->dest);
|
| 90 |
}
|
| 91 |
|
| 92 |
function liquid_moveref_setref($src, $dest) {
|
| 93 |
$count = db_result(db_query("SELECT COUNT(src) FROM {wiki_moveref} WHERE src='%s'", $src->identifier()));
|
| 94 |
if ($countSrc >= 1) {
|
| 95 |
db_query("UPDATE {wiki_moveref} SET dest='%s' WHERE src='%s'", $dest->identifier(), $src->identifier());
|
| 96 |
} else {
|
| 97 |
db_query("INSERT INTO {wiki_moveref} VALUES ('%s', '%s')", $src->identifier(), $dest->identifier());
|
| 98 |
}
|
| 99 |
}
|