<?php
/*
Copyright (C) 2004 The Liki Programming Team.
This file is part of Liki.
Liki is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published byre
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Liki is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Liki; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
ini_set("include_path", ini_get("include_path").":./pear");
require_once('lib/likiconfig.php');
require_once('lib/auth.php');
require_once('lib/ParseEngine.php');
require_once('lib/WikiDB.php');
require_once('lib/checkout.php');
define('DEBUG',0);
$index = new index($_GET,$_POST,$_SESSION);
$index->startTimer();
$index->checkUpdates();
$index->showUpload(true);//check for uploads
$index->servePages();
$index->showFiles();
$index->doFooter();
$index->cleanup();
class index{
function index($_GET,$_POST,&$_SESSION){
$this->likiconfig = likiconfig::getConfig();
$this->liki = $this->likiconfig['liki'];
$this->html = $this->likiconfig['html'];
$this->users = $this->likiconfig['users'];
$this->dbparms = $this->likiconfig['dbparms'];
$this->latex = $this->likiconfig['latex'];
$this->auth = new auth($_GET,$_POST,$_SESSION,$this->likiconfig);
$this->db = WikiDB::open($this->dbparms);
$this->pe = new ParseEngine($this->db,$this->auth);
}
function refreshConfig(){
$this->likiconfig = likiconfig::getConfig();
$this->liki = $this->likiconfig['liki'];
$this->html = $this->likiconfig['html'];
$this->users = $this->likiconfig['users'];
$this->dbparms = $this->likiconfig['dbparms'];
$this->latex = $this->likiconfig['latex'];
$this->auth->updateAuth($_GET,$_POST,$_SESSION,$this->likiconfig);
}
function startTimer(){
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$this->starttime = $mtime;
}
function getTime(){
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
return ($endtime - $this->starttime);
}
function cleanup(){
//Close our DB connection
$this->db->close();
}
function checkUpdates(){
if($this->auth->loggedin && isset($_GET['update'])){
$ret = likiconfig::doUpdate($_POST,$this->auth,$this->db);
$this->refreshConfig();
}
}
function showFiles(){
$files = $this->pe->scan(true,$this->latex['basedir']);
if($files)
foreach($files as $filename) {
$page = $this->db->getPage($filename);
//free up the file lock
if(!(isset($_GET['action'])) || $_GET['action'] != 'edit'){
$md5 = substr($page->get('locked'),0,32);
$temp = substr($page->get('locked'),32,42);
if($this->auth->loggedin && $this->auth->user == $md5){
echo '<br\>'.$filename.' released from lock.';
$page->set('locked',false);
}
}
$links = $page->getPageLinks();
$backs = $page->getBackLinks();
/*echo '<br/>'.$filename;
while($p = $backs->next())
echo $p->getName();
$backs = $page->getBackLinks();*/
//if($filename == "new.tex") echo $backs->count();
if (!$backs->count()){ // root doc
if(!preg_match('/\.bib$/',$filename))
check(substr($filename, 0, -4),'.dvi',$this->latex,false);
$this->pe->doRoot($page);
}
}
else {} //print welcome to liki message???
}
function servePages(){
if(!isset($_GET['action']) || ($_GET['action']!='checkout' && 'rss' != $_GET['action'])){
if (isset($_GET['filename'])) $this->doHeader($this->html,$this->liki,$_GET['filename']);
else $this->doHeader($this->html,$this->liki);
}
if(isset($_GET['action']))
switch ($_GET['action']){
case 'rss' :
require_once('lib/changes.php');
if(isset($_GET['filename'])) changes_display($this->db,$this->auth,'xml',$_GET['filename']);
else changes_display($this->db,$this->auth,'xml');
exit();
break;
case 'checkout' :
require_once('lib/checkout.php');
if(isset($_GET['filename']) && isset($_GET['type'])){
if($_GET['type'] == 'raw'){
$suffix = substr($_GET['filename'], strlen($_GET['filename'])-3,strlen($_GET['filename']));
if($suffix == 'tex' || $suffix == 'bib'){
if(!$this->auth->authTex('read',$this->db->getPage($_GET['filename']))) {
exit();
}
}
else if (!$this->auth->loggedin) exit();
}
display($_GET['filename'],$_GET['type'],$this->latex);
exit();
}
break;
case 'changes' :
require_once('lib/changes.php');
if (isset($_GET['filename'])) changes_display($this->db,$this->auth,'html',$_GET['filename']);
else changes_display($this->db,$this->auth,'html');
break;
case 'update' :
if(isset($_POST['source']) && isset($_GET['filename'])){
require_once('lib/edit.php');
update($this->db,$this->auth,$_GET['filename'],$_POST['source']);
}
if(isset($_POST['file_upload']) && $_POST['file_upload'] != ''){
require_once('lib/edit.php');
doUpload();
}
break;
case 'edit' :
require_once('lib/edit.php');
if(isset($_GET['filename']) && isset($_GET['graphic']))
displayGraphic($this->db,$this->auth,$_GET['graphic'],$_GET['filename']);
elseif(isset($_GET['filename'])){
if (isset($_GET['revision'])) edit_display($this->db,$this->auth,$_GET['filename'],$_GET['revision']);
else edit_display($this->db,$this->auth,$_GET['filename']);
}
//else echo "Please log in to edit.";
break;
case 'config' :
if($this->auth->loggedin){
if(!isset($_GET['update']))
if(isset($_GET['newuser']))
likiconfig::doConfigHTML($this->auth,$this->db,'newuser');
else if (isset($_GET['changeDetails']))
likiconfig::doConfigHTML($this->auth,$this->db,'changeDetails');
else if (isset($_GET['filename']))
likiconfig::doFileConfig($_GET['filename'],$this->auth,$this->db);
else
likiconfig::doConfigHTML($this->auth,$this->db,'');
else if(isset($ret)) echo $ret;
else echo "New configuration saved.";
}
else echo "Please log in to edit configuration";
break;
}
if(isset($_GET['error']))
echo $_GET['error'];
}
function doHeader($html,$liki,$filename = ''){
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>'.$html['title'];
if ($filename != '') echo ' : '.$filename;
echo '</title>
<link title="Pretty" rel="stylesheet" type="text/css" href="'.$html['style'].'">
<link rel="alternate" type="application/rss+xml" title="'.$html['title'].' : '.$filename.' Recent Changes" href="'.$liki['baseurl'].'/index.php?action=rss';
if ($filename != '') echo '&filename='.$filename;
echo'">
<meta name="description" content="Liki, the open source Wiki for LaTeX documents">
<meta name="keywords" content="liki,liki-liki,latex,wiki,wiki-wiki,tex">
</head>
<body>
<br/>
<table class="content">
<tr>
<td class="link" align="left">
<a href="index.php">Home</a> ·
<a href="index.php?action=changes';
if ($filename != '') echo '&filename='.$filename; echo '">Recent Changes</a> ·
<a title="RSS 2.0 Feed" href="index.php?action=rss';
if ($filename != '') echo '&filename='.$filename;
echo '" class="rss">RSS</a> ·
</td>
<td class="link" align="right">
<!-- Insert Right-aligned links here -->
<a href="http://liki.sf.net"> Liki Home Page</a> ·
<!--<a href="http://sf.net/project/showfiles.php?group_id=123646">Downloads</a>-->
</td>
</tr>
<tr>
<td class="content" colspan="2" align="left" valign="top" height="400">
<h3 align=right ><a href="http://liki.sf.net" ><font color=black><span class="latex">
Liki - The L<span class="A">A</span>T<span class="E">E</span>X Wiki</span></font></a>
</h3>
<b>'.$html['name'].'</b>
<br/>';
}
function doFooter(){
$this->showUpload(); echo '</td>';
echo '</tr></table>
<table class=content >
<tr><td class="link" align="left">';
echo 'PHP Execution : '.$this->getTime().' seconds.<br/>';
if($this->auth->loggedin) {
echo 'Logged in as <b>'.$this->auth->username.'</b>
<a title="Change user details, such as name" href="index.php?action=config&changeDetails=true">Change Details</a>';
if($this->auth->authCfg())
echo '<br/><a title="Liki configuration page" href="index.php?action=config"> Edit Configuration</a> ';
if($this->auth->authUsers())
echo '<br/><a title="Create a new user of Liki" href="index.php?action=config&newuser=true"> Add User </a>';
echo'</td>
<td class="link" align="right"><a href="index.php?logout=true">Log Out.</a>';
}
else{
echo 'Not Logged In</td><td class="link" align="right"><form action="index.php" method="post">
<input id="p" type="text" name="user" value="user"/>
<label for="pw"></label> <input id="pw" type="password" name="password" value="pass"/>
<input type="submit" value="Login"/>
</form>';
}
echo'</td>
</tr>
</table>
</body>
<!--- PHP Execution : '.$this->getTime().' seconds. -->
</html>';
}
function showUpload($prescan = false){
if(!$this->auth->loggedin || !$this->auth->authFileUpload()) return;
require_once "HTML/QuickForm.php";
$uploadForm = new HTML_QuickForm('upload_form', 'post', 'index.php?action=upload&type=newfile');
$path = ".";
$uploadForm->addElement('hidden', 'path', $path);
$file =& $uploadForm->addElement('file', 'filename');
$uploadForm->addElement('submit', 'uploadFileBtn', 'Upload File');
$dataFile = $uploadForm->getSubmitValues();
//print_r($dataFile);
if (isset($dataFile['uploadFileBtn']) && $dataFile['uploadFileBtn']) {
if ($file->isUploadedFile()) {
$file->moveUploadedFile($dataFile['path']); //move to .
echo '<br/>Saved.';
}
//else echo "No file uploaded<br/>";
}
if(!$prescan) {
$uploadForm->display();
}
}
}
?>