get('username',$_SERVER['PHP_AUTH_USER']); } if (!isset($_SERVER['PHP_AUTH_USER']) || !$a->N || !$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; } var $wikiPage; var $wiki; var $page; var $isAdd = false; // is add page. var $isPreview = false; // is preview var $preview = ''; // preview text var $isEdit = false; // is edit. var $menu; // the menu object. function post($p) { if (strpos($p,'/dev/null')) { // prevent hacking of posts. $this->errors['required_fields'] = 1; return $this->get($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); if (!$this->menu->selectedNode) { return $this->get($p); } // hacking with bbcode... //if (!empty($_POST['body']) && strpos($_POST['body'],'url=')) { // $this->errors['required_fields'] = 1; // return $this->get($p); //} /* comment creation code */ $d = DB_DataObject::factory('comments'); //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 = DB_DataObject::factory('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->wikifile = $this->menu->selectedNode->attributes['flexywiki:href'];
if (!$d->setUrl($_POST['comment']['url']) || !$d->setBody($_POST['comment']['body'])) {
$this->errors['invalidurl'] = 1;
return $this->get($p);
}
$d->setFrom($_POST['comment']);
$d->entry_id = 0;
$d->type='NORMAL';
$d->timestamp = time();
$d->ip = $_SERVER['REMOTE_ADDR'];
//echo '';print_r($d);
$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 'FlexyWiki/MenuParser.php';
$this->menu = new FlexyWiki_MenuParser;
$this->menu->baseURL = $this->baseURL;
$this->menu->currentPage = $p;
$this->menu->parseMenu();
}
var $comments = array();
function loadComments() {
if (isset($_GET['comment']['delete'])) {
// assume authentication must have happened as it's check in getAuth()
$d = DB_DataObject::factory('comments');
$d->get($_GET['comment']['delete']);
$d->delete();
}
if (!$this->menu->selectedNode) {
return;
}
$d = DB_DataObject::factory('comments');
$d->wikifile = $this->menu->selectedNode->attributes['flexywiki:href'];
$d->entry_id = 0;
$d->orderBy('id ASC');
$d->find();
while ($d->fetch()) {
$this->comments[] = clone($d);
}
}
function get($p,$args=array()) {
$o = PEAR::getStaticProperty('FlexyWiki','options');
//$folder = $o['store'];
if (!$p) {
$p= $o['default'] . '/HomePage';
}
$this->loadMenu($p);
$this->loadComments();
$onMenu = false;
if (!$this->menu->selectedNode) {
// cant find stuff..
// get referer..
// should be an error page really
$this->wikiPage = 'akbkhome/HomePage';
} else {
$onMenu = true;
//echo'';print_r($this->menu->selectedNode);
$this->title = $this->menu->selectedNode->content;
}
// lets pick a folder:
$this->wikiPage = $p;
$bits = explode('/',$p);
$this->wiki = $bits[0];
if (isset($bits[1])) {
$this->page = $bits[1];
}
// echo "";print_r($this);
/*
Not used = stuff for editing AFAIR
$view = isset($_GET['view']) ? $_GET['view'] : @$args['view'];
if ($view && method_exists($this,'action'.$view)) {
echo "USING VIEW? $view";
$this->{'action'.$view}();
}
*/
$bits = explode('/',$p);
//$this->getWikiPages('akbkhome/Menu.txt');
//$this->getWikiPages($bits[0].'/Menu.txt');
if (!$onMenu && !$this->sourceExists($this->wikiPage)) {
header("HTTP/1.0 404 Not Found");
echo "Page Not Found Page Not Found
";
exit;
}
}
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);
if (!$text) {
$text = "lost : $this->wikiPage?";
}
return htmlspecialchars($text);
}
}
function outputWikiBody() {
/*
if ($this->isAdd) {
return;
}
*/
$tbits = explode('.',$this->page);
$tbits[1] = isset($tbits[1]) ? $tbits[1] : '';
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('FlexyWiki','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;
}
//echo "TEXT WIKI NOT SUPPORTED?";;
//require_once 'Text/Wiki.php';
//$wiki =& new Text_Wiki();
$pages = array('HomePage', 'AnotherPage', 'SomeOtherPage');
//$wiki->setRuleConf('wikilink', 'view_url', "{$this->baseURL}/{$bits[0]}/");
//$wiki->setRuleConf('wikilink', 'pages', $pages);
$text= $this->getSource($this->wikiPage.'/images.txt');
$this->text = $text;
$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.'';
}
}
function sourceExists($wikiPage) {
$o = PEAR::getStaticProperty('FlexyWiki','options');
$tbits = explode('.',$this->page);
$tbits[1] = isset($tbits[1]) ? $tbits[1] : '';
if ($tbits[1] == 'img') {
$pbits = explode('/',$wikiPage);
// display an image..
if (isset($pbits[2])) {
if (!file_exists($o['store'].'/'.$wikiPage.'.html') && (!file_exists($o['store'].'/'.$wikiPage.'.txt'))) {
return false;
}
$wikiPage.='/images.txt';
if (!file_exists($o['store'].'/'.$wikiPage.'.html') && (!file_exists($o['store'].'/'.$wikiPage.'.txt'))) {
return false;
}
return true;
}
}
if (!file_exists($o['store'].'/'.$wikiPage.'.html') && (!file_exists($o['store'].'/'.$wikiPage.'.txt'))) {
return false;
}
return true;
}
function getSource($wikiPage)
{
// check for HTML first!! - wiki was a bad mistake..
$o = PEAR::getStaticProperty('FlexyWiki','options');
if (!file_exists($o['store'].'/'.$wikiPage.'.html')) {
if (!file_exists($o['store'].'/'.$wikiPage.'.txt')) {
return htmlspecialchars('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);
}
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__) . '/FlexyWiki/templates';
parent::outputBody();
}
function getFirstImage($dir) {
if (!is_dir($dir)) {
return false;
}
$dh = opendir($dir);
while (false !== ($file = readdir($dh))) {
if ($file{0} == '.') {
continue;
}
closedir($dh);
if (preg_match('/\.jpg$/i',$file)) {
return $file;
}
return false;
}
}
function getImagesData() {
// grab the images from the folder..
$o = PEAR::getStaticProperty('FlexyWiki','options');
$dir = $o['store'].'/'. $this->wikiPage;
$dh = opendir($dir);
$imgs = array();
while (($file = readdir($dh)) !== false) {
if ($file{0} == '.') {
continue;
}
$files[] = $file;
}
asort($files);
foreach($files as $file) {
$bits = explode('.',$file);
$ext = $bits[count($bits)-1];
switch(strtolower($ext)) {
case 'png':
case 'jpg':
$img = new StdClass;
// it's not a thumbnail...
$img->info = getimagesize("$dir/$file");
if ($img->info[0] > 150) {
// techncally we should make a thumnail
// and show that..
require_once 'FlexyWiki/ImageCache.php';
$info = FlexyWiki_ImageCache::createThumbnail($o['store'].'/'.$this->wikiPage .'/'. $file);
$img->info = $info;
$img->name = basename($file);
$img->size = sprintf("%0.2f",filesize("$dir/$file") / 1000000);
$img->url = $this->baseURL . $info['url'];
$img->link = $this->baseURL . '/'.$this->wikiPage .'/'.$file;
$imgs[] = $img;
continue;
}
continue;
$img->url = $this->baseURL .'/Image/'.$this->wikiPage . '/'.$file;
$imgs[] = $img;
break;
case 'mpg':
continue;
$img = new StdClass;
$img->url = $this->baseURL.'/'.$this->wikiPage . '/'.$file;
$img->url = $this->baseURL.'/'.$this->wikiPage . '/'.$file;
$imgs[] = $img;
break;
}
}
$ret = array();
$this->imagecols = $imgs;
while($imgs) {
$ret[] = array_splice($imgs,0,3);
}
return $ret;
}
}