get('username',$_SERVER['PHP_AUTH_USER']); } if (!isset($_SERVER['PHP_AUTH_USER']) || !$a->info('rows') || !$a->checkPassword($_SERVER['PHP_AUTH_PW'])) { header('WWW-Authenticate: Basic realm="AKBKHOME"'); header('HTTP/1.0 401 Unauthorized'); echo "Not authenticated";exit; return false; } return true; } return true; } public $wikiPage; public $wiki; public $page; public $isAdd = false; // is add page. public $isPreview = false; // is preview public $preview = ''; // preview text public $isEdit = false; // is edit. public $menu; // the menu object. function post($p) { if (!isset($_POST['comment'])) { return $this->get($p); } require_once 'HTML/Template/Flexy/Factory.php'; $this->elements = HTML_Template_Flexy_Factory::fromArray($_POST); // do comments... $this->loadMenu($p); //echo '
';print_r($this->menu);exit;
if (!$this->menu->selectedNode) {
return $this->get($p);
}
/* comment creation code */
//echo '';print_r($_POST['comment']);
foreach(array('author','body') as $e) {
if (empty($_POST['comment'][$e])) {
$this->errors['required_fields'] = 1;
return $this->get($p);
}
}
// to many in one day..
$old = DBDO::factory('blog','comments');
$old->ip = $_SERVER['REMOTE_ADDR'];
$old->whereAdd("timestamp > " . (time() - (60 * 60 * 24)));
if ($old->count() > 1) {
$this->errors['to_many_posts'] = 1;
return $this->get($p);
}
if (empty($_POST['chk']) && $_POST['chk'] != 'ok') {
$this->errors['no_javascript'] = 1;
return $this->get($p);
}
// echo''; print_r($GLOBALS['_DB_DATAOBJECT']);print_r($d);
//
$d = DBDO::factory('blog','comments');
$d->wikifile = $this->menu->selectedNode->getAttribute('flexywiki:href');
if (!$d->setUrl($_POST['comment']['url']) || !$d->setBody($_POST['comment']['body'])) {
$this->errors['invalidurl'] = 1;
return $this->get($p);
}
$d->assignFrom($_POST['comment']);
//echo '';print_r($d);exit;
$d->entry_id = 0;
$d->type='NORMAL';
$d->timestamp = time();
$d->ip = $_SERVER['REMOTE_ADDR'];
$this->elements = array();
$d->insert();
// mail them!!!
$e= $d->sendToEntryAuthor('wikiemail.txt');
return $this->get($p);
}
function loadMenu($p) {
if ($this->menu) {
return;
}
require_once 'FlexyWiki2/MenuParser.php';
$this->menu = new FlexyWiki2_MenuParser;
$this->menu->baseURL = $this->baseURL;
$this->menu->currentPage = $p;
$this->menu->parseMenu();
}
public $comments = array();
function loadComments() {
if (isset($_GET['comment']['delete'])) {
// assume authentication must have happened as it's check in getAuth()
$d = DBDO::factory('blog','comments');
try {
$d->get($_GET['comment']['delete']);
$d->delete();
} catch (Exception $e) {
// ignore errors?
// print_r($e);
}
}
if (!$this->menu->selectedNode) {
return;
}
//DBDO::debugLevel(DBDO::E_ALL);
$d = DBDO::factory('blog', 'comments');
// $d = DB_DataObject::factory('comments');
$d->wikifile = $this->menu->selectedNode->getAttribute('flexywiki:href');
$d->entry_id = 0;
$d->orderBy('id ASC');
//phpinfo();
//echo '';print_r($d->info());
$d->query();
//try {
$this->comments = $d->fetchAll();
//} catch (Exception $e) {
//echo "oops". $e->toString();
//}
//echo '';print_r($this->comments);echo "
";
}
function get($p,$args=array()) {
$o = PEAR::getStaticProperty('FlexyWiki2','options');
//$folder = $o['store'];
if (!$p) {
$p= $o['default'] . '/HomePage';
}
$this->loadMenu($p);
$this->loadComments();
if (!$this->menu->selectedNode) {
// cant find stuff..
// get referer..
// should be an error page really
$this->wikiPage = $this->defaultPage;
} else {
//echo'';print_r($this->menu->selectedNode);
$this->title = $this->menu->nodeGetContents($this->menu->selectedNode);
// var_dump($this->title);
}
// lets pick a folder:
$this->wikiPage = $p;
$bits = explode('/',$p);
$this->wiki = $bits[0];
$this->page = $bits[1];
$bits = explode('/',$p);
}
function determineType() {
// use the directory name extension to render in different formats
// (eg. photos/xxxx.img)
$tbits = explode('.',$this->page);
$tbits[1] = isset($tbits[1]) ? $tbits[1] : '';
switch ($tbits[1]) {
case 'img':
$this->format = 'imageIndex';
$pbits = explode('/',$this->wikiPage);
// display an image..
if (isset($pbits[2])) {
$this->format = 'imageView';
}
default:
$text = $this->getSource($this->wikiPage);
// eak what to do here!!!
echo $text;
}
}
function outputWikiBody() {
$tbits = explode('.',$this->page);
$tbits[1] = isset($tbits[1]) ? $tbits[1] : '';
var_dump($tbits);
switch ($tbits[1]) {
case 'img':
$pbits = explode('/',$this->wikiPage);
// display an image..
if (isset($pbits[2])) {
$this->text = $this->getSource($this->wikiPage);
$xbits = explode('.',basename($_SERVER["REQUEST_URI"]));
$ext = preg_replace('/[^a-z]/i','',$xbits[1]);
$ext = preg_replace('/\?.*/i','',$xbits[1]);
$o = PEAR::getStaticProperty('FlexyWiki2','options');
//echo $ext;
if ($ext == 'html') {
foreach(array('jpg','jpeg','png','gif') as $ext) {
//echo "TEST: {$this->wikiPage}.{$ext}";
if (file_exists($o['store'].'/'.$this->wikiPage.'.'.$ext)) {
break;
}
}
}
// load the info..
$this->info = getimagesize($o['store'].'/'.$this->wikiPage.'.'.$ext);
$this->imageURL = $this->baseURL.'/Image/'.$this->wikiPage.'.'.$ext;
$template_engine = new HTML_Template_Flexy;
$template_engine->compile('image_view_only.html');
$template_engine->outputObject($this);
return;
}
$this->text = $this->getSource($this->wikiPage.'/images.txt');
$this->images = $this->getImagesData();
//echo ''; print_r($this->images);
$template_engine = new HTML_Template_Flexy;
$template_engine->compile('image_view.html');
$template_engine->outputObject($this);
default:
$text = $this->getSource($this->wikiPage);
if (!preg_match('/.txt$/', $this->webdavUrl)) {
$this->text = $text;
return $this->outputWikiTemplate();
}
return ''.$text.'';
// only do the wiki stuff for .txt files.
/*
$text = $this->isPreview ? $this->preview :
if (!$text) {
if ($text = $this->getHtmlSource($this->wikiPage)) {
return $text;
}
$text = "lost : $this->wikiPage?";
}
*/
echo "WIKI NOT SUPPORTED ANYMORE?";
return;
}
}
function getSource($wikiPage)
{
// check for HTML first!! - wiki was a bad mistake..
$o = PEAR::getStaticProperty('FlexyWiki2','options');
if (!file_exists($o['store'].'/'.$wikiPage.'.html')) {
if (!file_exists($o['store'].'/'.$wikiPage.'.txt')) {
return 'lost: '.$o['store'].'/'.$wikiPage.'.html';
}
$this->webdavUrl = "{$o['webdavUrl']}/{$wikiPage}.txt";
return file_get_contents($o['store'].'/'.$wikiPage.'.txt');
}
$this->webdavUrl = "{$o['webdavUrl']}/{$wikiPage}.html";
$ot = PEAR::getStaticProperty('HTML_Template_Flexy','options');
$t = new HTML_Template_Flexy(array(
'compileDir' => $ot ['compileDir'].'Data',
'templateDir' => $o['store'],
));
//echo '';print_R($t);
$t->compile($wikiPage.'.html');
return $t->bufferedOutputObject($this);
return file_get_contents($o['store'].'/'.$wikiPage.'.html');
}
function outputWikiTemplate()
{
$template_engine = new HTML_Template_Flexy();
$template_engine->compile('wiki.html');
$template_engine->outputObject($this,$this->elements);
}
function outputBody()
{
$o = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
$o['templateDir'] = dirname(__FILE__) . '/FlexyWiki2/templates';
parent::outputBody();
}
function customFilters($str) {
$o = PEAR::getStaticProperty('FlexyWiki2','options');
// [somepage.xxxx: the title]
// maps to an image + link + ....
$matches = array();
preg_match_all('/\[(\S+):([^\]\n]+)\]([^\[]+)/',$str,$matches);
//echo '';print_r($matches);
foreach($matches[0] as $i=>$m) {
$link = $this->baseURL.'/'.$this->wiki.'/'.$matches[1][$i].'.html';
$title = $matches[2][$i];
$img = '';
$notes = '';
//echo "checking :".$o['store'].'/'. $this->wiki.'/'.$matches[1][$i].'/image.jpg';
if (file_exists($o['store'].'/'. $this->wiki.'/'.$matches[1][$i].'/image.jpg')) {
$img = '
';
}
if (!$img && ($img = $this->getFirstImage($o['store'].'/'. $this->wiki.'/'.$matches[1][$i]))) {
$img = '
';
}
$notes = $matches[3][$i];//htmlspecialchars(print_r($matches,true));;
$str = str_replace($m,
"| rootURL}/FlexyWiki2/templates/images/negative.jpg\" align=\"center\" valign=\"middle\" width=\"200\" height=\"200\">{$img} | {$title}{$notes} |