[[EtoWiki]]

V tejto téme sa nachádzajú snippety (rozšírenia) pre Etomite.

Moderátor: Moderators

Užívateľov profilový obrázok
churchyard
Czech LT
Czech LT
Príspevky: 181
Dátum registrácie: Ne Nov 06, 2005 4:40 pm
Bydlisko: Praha [CZ]
Kontaktovať užívateľa:

[[EtoWiki]]

Príspevok od užívateľa churchyard » So Dec 15, 2007 12:37 am

Kód: Vybrať všetko

/*
Snippet: EtoWiki
Author: Jason Coward <etowiki@opengeek.com>
Version: 0.1 [2005-03-16]
Based on...
	roWiki
	Author: Marc Rohlfing <rowiki@rowlff.de>
	Version: 1.02 (2005-01-04)
	Home/Docs/Licensing: www.rowlff.de/rowiki/
*/
if (!isset($id)) { $id=$etomite->documentIdentifier; }
$alias = $etomite->documentObject['alias'];
$wikiTemplateDir = "assets/snippets/etowiki/templates/";
$wikiTemplateFile = !isset($tpl) ? 'default.tpl' : $tpl;
$wikiTemplateFile = $wikiTemplateDir . $wikiTemplateFile;

$wikiDocLink = "[~$id~]";

$wikiStartPage = "Home";
$wikiHomeLink = "Home";
$wikiHelpLink = "Help";
$wikiTimeFormat = "%d.%m.%y %R";
$wikiPagesDir = "assets/snippets/etowiki/pages/";
$wikiHistoryDir = "assets/snippets/etowiki/history/";

if($page=="svk") {
$wikiEditLink = "Začať prekladať";
$wikiDoneLink = "Uložiť";
$wikiCancel = "Zahodiť";
$wikiLockedPage = "Zamčená stránka";
$wikiSearchLink = "Hledat";
$wikiSearchResults = "Výsledky hledání pro";
$wikiNewPage = "Nová stránka";
$wikiRecentChanges = "Poslední změny";
$wikiUpraveno = "Posledná úprava";
}
else {
$wikiEditLink = "Začít překládat";
$wikiDoneLink = "Uložit";
$wikiCancel = "Zahodit";
$wikiLockedPage = "Zamčená stránka";
$wikiSearchLink = "Hledat";
$wikiSearchResults = "Výsledky hledání pro";
$wikiNewPage = "Nová stránka";
$wikiRecentChanges = "Poslední změny";
$wikiUpraveno = "Poslední úprava";
}


// Determine page to display
if (! $wikiPageTitle = stripslashes($page))
{
if ($_GET["action"] == "search") { $wikiPageTitle = "$wikiSearchResults \"$_GET[query]\""; }
elseif ($_GET["action"] == "recent") { $wikiPageTitle = "$wikiRecentChanges"; }
else { $wikiPageTitle = "$wikiStartPage"; }
}

// Catch malicious paths
if (preg_match("/\//", $wikiPageTitle)) { $wikiPageTitle = $wikiStartPage; }

// Write changes to page, if there are any
$wikiAction = $_GET["action"];
if ($_SERVER["REQUEST_METHOD"] == "POST") 
{
if (! $wikiFile = fopen($wikiPagesDir . stripslashes($page) . ".txt", "w")) { return ("Could not write page!"); }
fputs($wikiFile, trim(stripslashes($_POST["wikiContent"])));
fclose($wikiFile);
if ($wikiHistoryDir <> '') {
if (! $wikiFile = fopen($wikiHistoryDir . $_POST["page"] . ".bak", "a"))
fclose ("Could not write backup of page!");
fputs($wikiFile, "\n\n\n--------------------\n" . strftime("$wikiTimeFormat", time()) . " / " . $_SERVER['REMOTE_ADDR'] . "\n--------------------\n");
fputs($wikiFile, trim(stripslashes($_POST["wikiContent"])));
fclose($wikiFile);
}
$redirectUrl = $etomite->makeURL( $id,$alias,"?page=" . urlencode(stripslashes($_POST[page])) );
$etomite->sendRedirect( "$redirectUrl" );
}

// Read and parse template
if (! $wikiTFile = @fopen("$wikiTemplateFile", "r"))
return ("'$wikiTemplateFile' is missing!");
$wikiTemplate = @fread($wikiTFile, @filesize("$wikiTemplateFile"));
@fclose($wikiTFile);

// Read page contents and time of last change
if ($wikiAction == '' && !file_exists($wikiPagesDir . $wikiPageTitle . ".txt")) 
{
// create a new page and prepare for editing
$wikiAction = "edit";
$TIME = "$wikiNewPage";
if (!($wikiFile = @fopen($wikiPagesDir . $wikiPageTitle . ".txt", "w"))) { return "Could not create new page $wikiPageTitle!"; }
}
else if ($wikiAction == '' || $wikiAction == 'edit')
{
// open the existing page for reading
$wikiFile = @fopen($wikiPagesDir . $wikiPageTitle . ".txt", "r");
$TIME = strftime("$wikiTimeFormat", @filemtime($wikiPagesDir . $wikiPageTitle . ".txt"));
$wikiOutput = "\n" . @fread($wikiFile, @filesize($wikiPagesDir . $wikiPageTitle . ".txt")) . "\n";
@fclose($wikiFile);
$wikiOutput = preg_replace("/\\$/Umsi", "$", $wikiOutput);
}

// Determine access mode
if ($wikiAction == "edit" )
$snippetOutput = preg_replace('/{EDIT}/', "$wikiEditLink", $wikiTemplate);
elseif (is_writable($wikiPagesDir . $wikiPageTitle . ".txt"))
$snippetOutput = preg_replace('/{EDIT}/', "<a href=\"$wikiDocLink?page=$wikiPageTitle&action=edit\">$wikiEditLink</a>", $wikiTemplate);
else
$snippetOutput = preg_replace('/{EDIT}/', "$wikiLockedPage", $wikiTemplate);

if ($wikiAction == "recent")
$snippetOutput = preg_replace('/{RECENT_CHANGES}/', "$wikiRecentChanges", $snippetOutput);
else
$snippetOutput = preg_replace('/{RECENT_CHANGES}/', "<a href=\"$wikiDocLink?action=recent\">$wikiRecentChanges</a>", $snippetOutput);

// Put values into template
$snippetOutput = preg_replace('/{PAGE_TITLE}/', "$wikiPageTitle", $snippetOutput);
$snippetOutput = preg_replace('/{UPRAVENO}/', "$wikiUpraveno", $snippetOutput);

if ($wikiPageTitle == $wikiStartPage && $wikiAction <> "search")
$snippetOutput = preg_replace('/{HOME}/', "$wikiHomeLink", $snippetOutput);
else
$snippetOutput = preg_replace('/{HOME}/', "<a href=\"[~$id~]\">$wikiHomeLink</a>", $snippetOutput);

if ($wikiPageTitle == $wikiHelpLink)
$snippetOutput = preg_replace('/{HELP}/', "$wikiHelpLink", $snippetOutput);    
else
$snippetOutput = preg_replace('/{HELP}/', "<a href=\"$wikiDocLink?page=$wikiHelpLink\">$wikiHelpLink</a>", $snippetOutput);
$snippetOutput = preg_replace('/{SEARCH}/', "<form method=\"get\" action=\"$wikiDocLink\"><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$_GET[query]\" /> <input type=\"submit\" value=\"$wikiSearchLink\" /></form>", $snippetOutput);

if ($wikiAction == "edit")
$wikiOutput = "<div align=\"center\"><form method=\"post\" action=\"$wikiDocLink\"><textarea name=\"wikiContent\" cols=\"67\" rows=\"30\" align=\"left\">$wikiOutput</textarea><input type=\"hidden\" name=\"page\" value=\"$wikiPageTitle\" /><br /><input type=\"submit\" class=\"button\" value=\"$wikiDoneLink\" />&nbsp;<input type=\"button\" class=\"button\" value=\"" . $wikiCancel . "\" onclick=\"window.location.href='[~" . $etomite->documentIdentifier . "~]'\" /></form></div>";

// Search pages
if ($wikiAction == "search")
{
$wikiDir = opendir(getcwd() . "/$wikiPagesDir");
while ($wikiFile = readdir($wikiDir))
{
if (preg_match("/.txt/", $wikiFile))
{
$handle = @fopen($wikiPagesDir . $wikiFile, "r");
$wikiContent = @fread($handle, @filesize($wikiPagesDir . $wikiFile));
@fclose($handle);
if (preg_match("/$_GET[query]/i", $wikiContent) || preg_match("/$_GET[query]/i", "pages/$wikiFile")) 
{
$wikiFile = substr($wikiFile, 0, strlen($wikiFile) - 4);
$wikiOutput .= "<p><a href=\"$wikiDocLink?page=$wikiFile\">$wikiFile</a></p>";
}
}
}
$TIME = "-";
}

// Recent changes
elseif ($wikiAction == "recent")
{
$wikiDir = opendir(getcwd() . "/$wikiPagesDir");
while ($wikiFile = readdir($wikiDir)) { if (preg_match("/.txt/", $wikiFile)) $wikiFileTime[$wikiFile] = filemtime($wikiPagesDir . $wikiFile); }
arsort($wikiFileTime);
$wikiFileTime = array_slice($wikiFileTime, 0, 10);
foreach ($wikiFileTime as $wikiFileName => $timestamp) 
{
$wikiFileName = substr($wikiFileName, 0, strlen($wikiFileName) - 4);
$wikiOutput .= "<p><a href=\"$wikiDocLink?page=$wikiFileName\">$wikiFileName</a> (" . strftime("$wikiTimeFormat", $timestamp) . ")</p>";
}
$TIME = "-";
}

// Prepare wiki page formatting via regular expressions
elseif ($wikiAction <> "edit") 
{
// $wikiOutput = htmlentities($wikiOutput);
$wikiOutput = preg_replace("/&#036;/Umsi", "$", $wikiOutput);
$wikiOutput = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&,\+]*)\]#U', '<a href="xx$2">$1</a>', $wikiOutput);
$wikiOutput = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $wikiOutput);
$wikiOutput = preg_replace('#(https?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*)#i', '<a href="$0">$1</a>', $wikiOutput);
$wikiOutput = preg_replace('#xxttp#', 'http', $wikiOutput);
$wikiOutput = preg_replace("/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U", "<a href=\"$wikiDocLink?page=$1\">$1</a>", $wikiOutput);
// $wikiOutput = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $wikiOutput);
$wikiOutput = preg_replace('/^\*(.*)\n/Um', "<ul><li>$1</li></ul>", $wikiOutput);
$wikiOutput = preg_replace('/^\#(.*)\n/Um', "<ol><li>$1</li></ol>", $wikiOutput);
$wikiOutput = preg_replace('/(<\/ol><ol>|<\/ul><ul>)/', "", $wikiOutput);
$wikiOutput = preg_replace('/^!!!(.*)(\n)/Um', '<h4>$1</h4>$2', $wikiOutput);
$wikiOutput = preg_replace('/^!!(.*)(\n)/Um', '<h5>$1</h5>$2', $wikiOutput);
$wikiOutput = preg_replace('/^!(.*)(\n)/Um', '<h6>$1</h6>$2', $wikiOutput);
$wikiOutput = preg_replace('/----(\r\n|\r|\n)/m', '<hr />', $wikiOutput);
$wikiOutput = preg_replace('/\n/', '<br />', $wikiOutput);
$wikiOutput = preg_replace('#(</h[123]>)<br />#', "$1", $wikiOutput);
$wikiOutput = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $wikiOutput);
$wikiOutput = preg_replace("/'''(.*)'''/Um", '<strong>$1</strong>', $wikiOutput);
$wikiOutput = preg_replace("/''(.*)''/Um", '<em>$1</em>', $wikiOutput); 
$wikiOutput = substr($wikiOutput, 6, strlen($wikiOutput) - 6);
}

// Return page output
$snippetOutput = preg_replace("/{CONTENT}/", "$wikiOutput", $snippetOutput);
$snippetOutput = preg_replace('/{TIME}/', $TIME, $snippetOutput);

return $snippetOutput;
  • The Neverhood - Československý web o Neverhoodovi
  • P.R.D.I. - nejlepší folkrock široko daleko
  • Yozzefy - hudební gulášek známých písní

Napísať odpoveď