Skip to content

Instantly share code, notes, and snippets.

@scottux
Created November 20, 2013 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottux/7568579 to your computer and use it in GitHub Desktop.
Save scottux/7568579 to your computer and use it in GitHub Desktop.
QCubed Wiki
<?php
/**
* QCubed Wiki
*/
// Include prepend.inc to load Qcodo
require('includes/prepend.inc.php');
class WikiForm extends QForm
{
protected $objWikiPage;
protected $lblTitle;
protected $lblContents;
protected $txtEditContents;
protected $btnEditPage;
protected $btnSavePage;
protected $btnCancelEdit;
protected function Form_Create()
{
$strPageNotFound = "This page does not exist yet.";
$strPage = (QApplication::QueryString('page') === '') ? 'WikiStart' : QApplication::QueryString('page');
$this->objWikiPage = Page::LoadByTitle($strPage);
$this->lblTitle = new QLabel($this);
$this->lblTitle->Text = $strPage;
$this->lblContents = new QLabel($this);
$this->lblContents->HtmlEntities = false;
$this->lblContents->Text = ($this->objWikiPage) ? $this->FindWikiWords($this->objWikiPage->Contents) : $strPageNotFound;
$this->txtEditContents = new QTextBox($this);
$this->txtEditContents->Text = ($this->objWikiPage) ? $this->objWikiPage->Contents : $strPageNotFound;
$this->txtEditContents->Visible = false;
$this->btnEditPage = new QButton($this);
$this->btnEditPage->Text = "Edit";
$this->btnEditPage->AddAction(new QClickEvent(), new QServerAction('btnEditPage_Click'));
$this->btnSavePage = new QButton($this);
$this->btnSavePage->Text = "Save";
$this->btnSavePage->Visible = false;
$this->btnSavePage->AddAction(new QClickEvent(), new QServerAction('btnSavePage_Click'));
$this->btnCancelEdit = new QButton($this);
$this->btnCancelEdit->Text = "Cancel";
$this->btnCancelEdit->Visible = false;
$this->btnCancelEdit->AddAction(new QClickEvent(), new QServerAction('btnCancelEdit_Click'));
}
protected function btnEditPage_Click($strFormId, $strControlId, $strParameter)
{
$this->txtEditContents->Visible = true;
$this->lblContents->Visible = false;
$this->btnEditPage->Visible = false;
$this->btnCancelEdit->Visible = true;
$this->btnSavePage->Visible = true;
}
protected function btnSavePage_Click($strFormId, $strControlId, $strParameter)
{
if (!$this->objWikiPage){
$this->objWikiPage = new Page();
}
$this->objWikiPage->Title = $this->lblTitle->Text;
$this->objWikiPage->Contents = $this->txtEditContents->Text;
$this->objWikiPage->Save();
$this->lblContents->Text = $this->FindWikiWords($this->objWikiPage->Contents);
$this->btnCancelEdit_Click($strFormId, $strControlId, $strParameter);
}
protected function btnCancelEdit_Click($strFormId, $strControlId, $strParameter)
{
$this->txtEditContents->Visible = false;
$this->lblContents->Visible = true;
$this->btnEditPage->Visible = true;
$this->btnCancelEdit->Visible = false;
$this->btnSavePage->Visible = false;
}
protected function FindWikiWords($contents)
{
$page = $_SERVER["SCRIPT_NAME"];
$contents = preg_replace("/( ){1}(([A-Z][a-z0-9]+){2,})/", ' <a href="' . $page . '?page=$2">$2</a>', $contents);
return $contents;
}
}
WikiForm::Run('WikiForm');
<!doctype html>
<html>
<head>
<meta charset="<?php _p(QApplication::$EncodingType); ?>" />
<title>QCubed Wiki Example</title>
<style type="text/css">@import url("<?php _p(__VIRTUAL_DIRECTORY__ . __CSS_ASSETS__); ?>/styles.css");</style>
</head>
<body>
<?php $this->RenderBegin(); ?>
<?php $this->lblTitle->Render(); ?>
<?php $this->lblContents->Render(); ?>
<?php $this->txtEditContents->Render(); ?>
<?php $this->btnEditPage->Render(); ?>
<?php $this->btnSavePage->Render(); ?>
<?php $this->btnCancelEdit->Render(); ?>
<?php $this->RenderEnd(); ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment