Hi again!
I've encountered a new kind of need while playing with Boltwire: the
possibility to use page A instead of page B, e.g. doing {B::infovar} would
call instead {A::infovar}, and if I go to page B, the website should
display instead page A... But... and that's where it goes tricky, I want
{page} to have value "B", not "A". Thus, I want data var, info var and page
content to be replaced, but not system var that may be related to the page.
I can therefore differentiate the pages and rights that apply on these
pages according to the page (fake) hierarchy. User access is not at all my
primary need, as I could have used usergroups for that. I am instead using
aliases for some pages while keeping the alias hierarchy quite rigid.
I have come to replacing the following BOLT functions: BOLTexists,
BOLTpageshortcuts and BOLTcsv with the following ones:
<?php if (!defined('BOLTWIRE')) exit();
function myBOLTexists($page, $dir='') {
if ($page == '') return false;
if (strpos($page, '#')) $page = substr($page, 0, strpos($page, '#'));
if (strpos($page, '&')) $page = substr($page, 0, strpos($page, '&'));
$page = BOLTinternalRedirections($page);//additional line
$fpage = BOLTfolders($page);
global $systemPath, $BOLTpageLibraries;
if ($BOLTpageLibraries != '') {
$index = substr($page, 0, strpos($page, '.'));
if (isset($BOLTpageLibraries[$index])) return file_exists(
"$BOLTpageLibraries[$index]/$page");
}
if ($dir != '') {
switch($dir) {
case 'pages': return file_exists("$dir/$fpage");
case 'system': return file_exists("$systemPath/$page");
default:
if (strpos($dir, '..') !== false) return false;
return file_exists("$dir/$page");
}
}
if (file_exists("pages/$fpage")) return true;
if (file_exists("$systemPath/$page")) return true;
return false;
}
function myBOLTpageshortcuts($link, $basepage='') {
if (strpos($link, '://') !== false) return $link;
global $pageLink, $pageArray, $BOLTid, $BOLTtime;
$link = BOLTinternalRedirections($link);//additional line
if ($basepage != '') {
$myPage = $basepage;
$myArray = explode('.', $basepage);
}
else {
$myPage = $pageLink;
$myArray = $pageArray;
}
if ($link == '') return $myPage;
$link = str_replace('&', '&', $link);
if (strpos($link, "/")) $link = str_replace("/", ".", $link);
$get = '';
if (strpos($link, '&') !== false) {
$get = substr($link, strpos($link, "&"));
$link = substr($link, 0, strpos($link, "&"));
}
if (strpos($link, '#') !== false) {
if (strpos($link, '#') + 1 != strlen($link)) {
$anchor = '#' . BOLTutf2url(substr($link, strpos($link, "#") + 1
));
$link = substr($link, 0, strpos($link, "#"));
}
}
$link = str_replace(' ', '_', $link);
if (BOLTconfig('utfpages', 'true') == 'true') $link = BOLTutf2url($link
);
$link = strtolower(trim($link));
switch (substr($link, 0, 1)) {
case '.':
$dots = strlen($link) - strlen(ltrim($link, '.'));
for ($i=0; $i<$dots; $i++) {
if (isset($myArray[$i])) $temp .= $myArray[$i] . '.';
}
$link = $temp . substr($link, $dots);
break;
case '=': $link = $myPage . '.' . substr($link, 1); break;
case '@': $link = 'group.' . substr($link, 1); break;
case '!': $link = 'action.' . substr($link, 1); break;
case '~': $link = 'member.' . substr($link, 1); break;
}
$rr1 = array('+','..',' ','^');
$rr2 = array($BOLTtime,'.','_',$BOLTid);
$link = trim(str_replace($rr1, $rr2, $link), '.');
if (substr($link, -1) == '#') {
$link = trim(substr($link, 0, -1), '.');
$link = $link . '.' . BOLTthread("$link");
}
return $link . $anchor . $get;
}
function myBOLTcsv($value, $current='') {
$new = ",$current,";
$key = '';
$values = explode(',', $value);
foreach ($values as $v => $vv) {
$vv = BOLTinternalRedirections($vv);//additional line
if (inlist(substr($vv, 0, 1), '+,-')) {
$key = substr($vv, 0, 1);
$vv = substr($vv, 1);
}
$vv = trim($vv);
if ($key == '-') $new = str_replace(",$vv,", ',', $new);
if ($key == '+' && strpos($new, ",$vv,") === false) $new = $new .
"$vv,";
$out[] = $vv;
}
if ($current == '') return implode(',', $out);
return trim($new, ',');
}
function BOLTinternalRedirections($link, $flipped = false) {
global $BOLTinternalRedirections, $BOLTinternalRedirectionsFrom,
$BOLTinternalRedirectionsTo;//these 3 are set in config.php
$link = trim(strtolower($link));
if(!$flipped) {
$out = $BOLTinternalRedirections[$link];
if($out != '') return $out;
$out = preg_replace($BOLTinternalRedirectionsFrom,
$BOLTinternalRedirectionsTo, $link);
if($out != '') return $out;
}
else {
$flippedBOLTinternalRedirections = array_flip(
$BOLTinternalRedirections);
$out = $flippedBOLTinternalRedirections[$link];
/*for($BOLTinternalRedirectionsTo => $to) {
$patBOLTinternalRedirectionsTo[] =
'/'.$BOLTinternalRedirectionsTo.'/';
}
for($BOLTinternalRedirectionsFrom => $to) {
$noPatBOLTinternalRedirectionsFrom[] =
trim(BOLTinternalRedirectionsFrom,'/');
}
$out = preg_replace($patBOLTinternalRedirectionsTo,
$noPatBOLTinternalRedirectionsFrom, $link);*/
if($out != '') return $out;
}
return $link;
}
Then, in config.php, I have things like the following (I am doing some
conditonal checks on {p3} for pages from group character.pc.*, and I am
heavily using the data vars and info vars these pages contain):
$BOLTinternalRedirections['character.pc.elmy.sutherland'] =
"character.pc.junius.sutherland";
$BOLTinternalRedirectionsFrom[]='/character.pc.elmy.sutherland/';
$BOLTinternalRedirectionsTo[] = 'character.pc.junius.sutherland';
Would anyone have another idea on how to achieve that?
In case this would respond to other kind of needs in some less ugly way, I
would be happy to make a nice plugin of it, but I don't think there is much
demand for this.
Cheers,
Tiffany
--
You received this message because you are subscribed to the Google Groups
"BoltWire" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/boltwire.
For more options, visit https://groups.google.com/d/optout.