PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/gforge/plugins/wiki/www/lib/Theme.php

https://github.com/neymanna/fusionforge
PHP | 1803 lines | 1300 code | 138 blank | 365 comment | 164 complexity | d9028b0bb16cb279d24d1b730fce45ab MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php rcs_id('$Id: Theme.php,v 1.131 2005/06/10 06:09:06 rurban Exp $');
  2. /* Copyright (C) 2002,2004,2005 $ThePhpWikiProgrammingTeam
  3. *
  4. * This file is part of PhpWiki.
  5. *
  6. * PhpWiki is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PhpWiki is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with PhpWiki; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. /**
  21. * Customize output by themes: templates, css, special links functions,
  22. * and more formatting.
  23. */
  24. require_once(dirname(__FILE__).'/HtmlElement.php');
  25. /**
  26. * Make a link to a wiki page (in this wiki).
  27. *
  28. * This is a convenience function.
  29. *
  30. * @param mixed $page_or_rev
  31. * Can be:<dl>
  32. * <dt>A string</dt><dd>The page to link to.</dd>
  33. * <dt>A WikiDB_Page object</dt><dd>The page to link to.</dd>
  34. * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page to link to.</dd>
  35. * </dl>
  36. *
  37. * @param string $type
  38. * One of:<dl>
  39. * <dt>'unknown'</dt><dd>Make link appropriate for a non-existant page.</dd>
  40. * <dt>'known'</dt><dd>Make link appropriate for an existing page.</dd>
  41. * <dt>'auto'</dt><dd>Either 'unknown' or 'known' as appropriate.</dd>
  42. * <dt>'button'</dt><dd>Make a button-style link.</dd>
  43. * <dt>'if_known'</dt><dd>Only linkify if page exists.</dd>
  44. * </dl>
  45. * Unless $type of of the latter form, the link will be of class 'wiki', 'wikiunknown',
  46. * 'named-wiki', or 'named-wikiunknown', as appropriate.
  47. *
  48. * @param mixed $label (string or XmlContent object)
  49. * Label for the link. If not given, defaults to the page name.
  50. *
  51. * @return XmlContent The link
  52. */
  53. function WikiLink ($page_or_rev, $type = 'known', $label = false) {
  54. global $WikiTheme, $request;
  55. if ($type == 'button') {
  56. return $WikiTheme->makeLinkButton($page_or_rev, $label);
  57. }
  58. $version = false;
  59. if (isa($page_or_rev, 'WikiDB_PageRevision')) {
  60. $version = $page_or_rev->getVersion();
  61. if ($page_or_rev->isCurrent())
  62. $version = false;
  63. $page = $page_or_rev->getPage();
  64. $pagename = $page->getName();
  65. $wikipage = $pagename;
  66. $exists = true;
  67. }
  68. elseif (isa($page_or_rev, 'WikiDB_Page')) {
  69. $page = $page_or_rev;
  70. $pagename = $page->getName();
  71. $wikipage = $pagename;
  72. }
  73. elseif (isa($page_or_rev, 'WikiPageName')) {
  74. $wikipage = $page_or_rev;
  75. $pagename = $wikipage->name;
  76. if (!$wikipage->isValid('strict'))
  77. return $WikiTheme->linkBadWikiWord($wikipage, $label);
  78. }
  79. else {
  80. $wikipage = new WikiPageName($page_or_rev, $request->getPage());
  81. $pagename = $wikipage->name;
  82. if (!$wikipage->isValid('strict'))
  83. return $WikiTheme->linkBadWikiWord($wikipage, $label);
  84. }
  85. if ($type == 'auto' or $type == 'if_known') {
  86. if (isset($page)) {
  87. $exists = $page->exists();
  88. }
  89. else {
  90. $dbi =& $request->_dbi;
  91. $exists = $dbi->isWikiPage($wikipage->name);
  92. }
  93. }
  94. elseif ($type == 'unknown') {
  95. $exists = false;
  96. }
  97. else {
  98. $exists = true;
  99. }
  100. // FIXME: this should be somewhere else, if really needed.
  101. // WikiLink makes A link, not a string of fancy ones.
  102. // (I think that the fancy split links are just confusing.)
  103. // Todo: test external ImageLinks http://some/images/next.gif
  104. if (isa($wikipage, 'WikiPageName') and
  105. ! $label and
  106. strchr(substr($wikipage->shortName,1), SUBPAGE_SEPARATOR))
  107. {
  108. $parts = explode(SUBPAGE_SEPARATOR, $wikipage->shortName);
  109. $last_part = array_pop($parts);
  110. $sep = '';
  111. $link = HTML::span();
  112. foreach ($parts as $part) {
  113. $path[] = $part;
  114. $parent = join(SUBPAGE_SEPARATOR, $path);
  115. if ($WikiTheme->_autosplitWikiWords)
  116. $part = " " . $part;
  117. if ($part)
  118. $link->pushContent($WikiTheme->linkExistingWikiWord($parent, $sep . $part));
  119. $sep = $WikiTheme->_autosplitWikiWords
  120. ? ' ' . SUBPAGE_SEPARATOR : SUBPAGE_SEPARATOR;
  121. }
  122. if ($exists)
  123. $link->pushContent($WikiTheme->linkExistingWikiWord($wikipage, $sep . $last_part,
  124. $version));
  125. else
  126. $link->pushContent($WikiTheme->linkUnknownWikiWord($wikipage, $sep . $last_part));
  127. return $link;
  128. }
  129. if ($exists) {
  130. return $WikiTheme->linkExistingWikiWord($wikipage, $label, $version);
  131. }
  132. elseif ($type == 'if_known') {
  133. if (!$label && isa($wikipage, 'WikiPageName'))
  134. $label = $wikipage->shortName;
  135. return HTML($label ? $label : $pagename);
  136. }
  137. else {
  138. return $WikiTheme->linkUnknownWikiWord($wikipage, $label);
  139. }
  140. }
  141. /**
  142. * Make a button.
  143. *
  144. * This is a convenience function.
  145. *
  146. * @param $action string
  147. * One of <dl>
  148. * <dt>[action]</dt><dd>Perform action (e.g. 'edit') on the selected page.</dd>
  149. * <dt>[ActionPage]</dt><dd>Run the actionpage (e.g. 'BackLinks') on the selected page.</dd>
  150. * <dt>'submit:'[name]</dt><dd>Make a form submission button with the given name.
  151. * ([name] can be blank for a nameless submit button.)</dd>
  152. * <dt>a hash</dt><dd>Query args for the action. E.g.<pre>
  153. * array('action' => 'diff', 'previous' => 'author')
  154. * </pre></dd>
  155. * </dl>
  156. *
  157. * @param $label string
  158. * A label for the button. If ommited, a suitable default (based on the valued of $action)
  159. * will be picked.
  160. *
  161. * @param $page_or_rev mixed
  162. * Which page (& version) to perform the action on.
  163. * Can be one of:<dl>
  164. * <dt>A string</dt><dd>The pagename.</dd>
  165. * <dt>A WikiDB_Page object</dt><dd>The page.</dd>
  166. * <dt>A WikiDB_PageRevision object</dt><dd>A specific version of the page.</dd>
  167. * </dl>
  168. * ($Page_or_rev is ignored for submit buttons.)
  169. */
  170. function Button ($action, $label = false, $page_or_rev = false) {
  171. global $WikiTheme;
  172. if (!is_array($action) && preg_match('/^submit:(.*)/', $action, $m))
  173. return $WikiTheme->makeSubmitButton($label, $m[1], $page_or_rev);
  174. else
  175. return $WikiTheme->makeActionButton($action, $label, $page_or_rev);
  176. }
  177. class WikiTheme {
  178. var $HTML_DUMP_SUFFIX = '';
  179. var $DUMP_MODE = false, $dumped_images, $dumped_css;
  180. function WikiTheme ($theme_name = 'default') {
  181. $this->_name = $theme_name;
  182. $this->_themes_dir = NormalizeLocalFileName("themes");
  183. $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
  184. $this->_theme = "themes/$theme_name";
  185. if ($theme_name != 'default')
  186. $this->_default_theme = new WikiTheme;
  187. // by pixels
  188. if ((is_object($GLOBALS['request']) // guard against unittests
  189. and $GLOBALS['request']->getPref('doubleClickEdit'))
  190. or ENABLE_DOUBLECLICKEDIT)
  191. $this->initDoubleClickEdit();
  192. // will be replaced by acDropDown
  193. if (ENABLE_LIVESEARCH) { // by bitflux.ch
  194. $this->initLiveSearch();
  195. }
  196. $this->_css = array();
  197. }
  198. function file ($file) {
  199. return $this->_path . "$this->_theme/$file";
  200. }
  201. function _findFile ($file, $missing_okay = false) {
  202. if (file_exists($this->file($file)))
  203. return "$this->_theme/$file";
  204. // FIXME: this is a short-term hack. Delete this after all files
  205. // get moved into themes/...
  206. if (file_exists($this->_path . $file))
  207. return $file;
  208. if (isset($this->_default_theme)) {
  209. return $this->_default_theme->_findFile($file, $missing_okay);
  210. }
  211. else if (!$missing_okay) {
  212. if (DEBUG & function_exists('debug_backtrace')) { // >= 4.3.0
  213. echo "<pre>", printSimpleTrace(debug_backtrace()), "</pre>\n";
  214. }
  215. trigger_error("$this->_theme/$file: not found", E_USER_NOTICE);
  216. }
  217. return false;
  218. }
  219. function _findData ($file, $missing_okay = false) {
  220. $path = $this->_findFile($file, $missing_okay);
  221. if (!$path)
  222. return false;
  223. if (defined('DATA_PATH'))
  224. return DATA_PATH . "/$path";
  225. return $path;
  226. }
  227. ////////////////////////////////////////////////////////////////
  228. //
  229. // Date and Time formatting
  230. //
  231. ////////////////////////////////////////////////////////////////
  232. // Note: Windows' implemetation of strftime does not include certain
  233. // format specifiers, such as %e (for date without leading zeros). In
  234. // general, see:
  235. // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strftime.2c_.wcsftime.asp
  236. // As a result, we have to use %d, and strip out leading zeros ourselves.
  237. var $_dateFormat = "%B %d, %Y";
  238. var $_timeFormat = "%I:%M %p";
  239. var $_showModTime = true;
  240. /**
  241. * Set format string used for dates.
  242. *
  243. * @param $fs string Format string for dates.
  244. *
  245. * @param $show_mod_time bool If true (default) then times
  246. * are included in the messages generated by getLastModifiedMessage(),
  247. * otherwise, only the date of last modification will be shown.
  248. */
  249. function setDateFormat ($fs, $show_mod_time = true) {
  250. $this->_dateFormat = $fs;
  251. $this->_showModTime = $show_mod_time;
  252. }
  253. /**
  254. * Set format string used for times.
  255. *
  256. * @param $fs string Format string for times.
  257. */
  258. function setTimeFormat ($fs) {
  259. $this->_timeFormat = $fs;
  260. }
  261. /**
  262. * Format a date.
  263. *
  264. * Any time zone offset specified in the users preferences is
  265. * taken into account by this method.
  266. *
  267. * @param $time_t integer Unix-style time.
  268. *
  269. * @return string The date.
  270. */
  271. function formatDate ($time_t) {
  272. global $request;
  273. $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
  274. // strip leading zeros from date elements (ie space followed by zero)
  275. return preg_replace('/ 0/', ' ',
  276. strftime($this->_dateFormat, $offset_time));
  277. }
  278. /**
  279. * Format a date.
  280. *
  281. * Any time zone offset specified in the users preferences is
  282. * taken into account by this method.
  283. *
  284. * @param $time_t integer Unix-style time.
  285. *
  286. * @return string The time.
  287. */
  288. function formatTime ($time_t) {
  289. //FIXME: make 24-hour mode configurable?
  290. global $request;
  291. $offset_time = $time_t + 3600 * $request->getPref('timeOffset');
  292. return preg_replace('/^0/', ' ',
  293. strtolower(strftime($this->_timeFormat, $offset_time)));
  294. }
  295. /**
  296. * Format a date and time.
  297. *
  298. * Any time zone offset specified in the users preferences is
  299. * taken into account by this method.
  300. *
  301. * @param $time_t integer Unix-style time.
  302. *
  303. * @return string The date and time.
  304. */
  305. function formatDateTime ($time_t) {
  306. return $this->formatDate($time_t) . ' ' . $this->formatTime($time_t);
  307. }
  308. /**
  309. * Format a (possibly relative) date.
  310. *
  311. * If enabled in the users preferences, this method might
  312. * return a relative day (e.g. 'Today', 'Yesterday').
  313. *
  314. * Any time zone offset specified in the users preferences is
  315. * taken into account by this method.
  316. *
  317. * @param $time_t integer Unix-style time.
  318. *
  319. * @return string The day.
  320. */
  321. function getDay ($time_t) {
  322. global $request;
  323. if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($time_t))) {
  324. return ucfirst($date);
  325. }
  326. return $this->formatDate($time_t);
  327. }
  328. /**
  329. * Format the "last modified" message for a page revision.
  330. *
  331. * @param $revision object A WikiDB_PageRevision object.
  332. *
  333. * @param $show_version bool Should the page version number
  334. * be included in the message. (If this argument is omitted,
  335. * then the version number will be shown only iff the revision
  336. * is not the current one.
  337. *
  338. * @return string The "last modified" message.
  339. */
  340. function getLastModifiedMessage ($revision, $show_version = 'auto') {
  341. global $request;
  342. if (!$revision) return '';
  343. // dates >= this are considered invalid.
  344. if (! defined('EPOCH'))
  345. define('EPOCH', 0); // seconds since ~ January 1 1970
  346. $mtime = $revision->get('mtime');
  347. if ($mtime <= EPOCH)
  348. return fmt("Never edited");
  349. if ($show_version == 'auto')
  350. $show_version = !$revision->isCurrent();
  351. if ($request->getPref('relativeDates') && ($date = $this->_relativeDay($mtime))) {
  352. if ($this->_showModTime)
  353. $date = sprintf(_("%s at %s"),
  354. $date, $this->formatTime($mtime));
  355. if ($show_version)
  356. return fmt("Version %s, saved %s", $revision->getVersion(), $date);
  357. else
  358. return fmt("Last edited %s", $date);
  359. }
  360. if ($this->_showModTime)
  361. $date = $this->formatDateTime($mtime);
  362. else
  363. $date = $this->formatDate($mtime);
  364. if ($show_version)
  365. return fmt("Version %s, saved on %s", $revision->getVersion(), $date);
  366. else
  367. return fmt("Last edited on %s", $date);
  368. }
  369. function _relativeDay ($time_t) {
  370. global $request;
  371. if (is_numeric($request->getPref('timeOffset')))
  372. $offset = 3600 * $request->getPref('timeOffset');
  373. else
  374. $offset = 0;
  375. $now = time() + $offset;
  376. $today = localtime($now, true);
  377. $time = localtime($time_t + $offset, true);
  378. if ($time['tm_yday'] == $today['tm_yday'] && $time['tm_year'] == $today['tm_year'])
  379. return _("today");
  380. // Note that due to daylight savings chages (and leap seconds), $now minus
  381. // 24 hours is not guaranteed to be yesterday.
  382. $yesterday = localtime($now - (12 + $today['tm_hour']) * 3600, true);
  383. if ($time['tm_yday'] == $yesterday['tm_yday']
  384. and $time['tm_year'] == $yesterday['tm_year'])
  385. return _("yesterday");
  386. return false;
  387. }
  388. /**
  389. * Format the "Author" and "Owner" messages for a page revision.
  390. */
  391. function getOwnerMessage ($page) {
  392. if (!ENABLE_PAGEPERM or !class_exists("PagePermission"))
  393. return '';
  394. $dbi =& $GLOBALS['request']->_dbi;
  395. $owner = $page->getOwner();
  396. if ($owner) {
  397. /*
  398. if ( mayAccessPage('change',$page->getName()) )
  399. return fmt("Owner: %s", $this->makeActionButton(array('action'=>_("chown"),
  400. 's' => $page->getName()),
  401. $owner, $page));
  402. */
  403. if ( $dbi->isWikiPage($owner) )
  404. return fmt("Owner: %s", WikiLink($owner));
  405. else
  406. return fmt("Owner: %s", '"'.$owner.'"');
  407. }
  408. }
  409. function getAuthorMessage ($revision, $only_authenticated = true) {
  410. if (!$revision) return '';
  411. $dbi =& $GLOBALS['request']->_dbi;
  412. $author = $revision->get('author_id');
  413. if ( $author or $only_authenticated ) {
  414. if (!$author) $author = $revision->get('author');
  415. if (!$author) return '';
  416. if ( $dbi->isWikiPage($author) )
  417. return fmt("by %s", WikiLink($author));
  418. else
  419. return fmt("by %s", '"'.$author.'"');
  420. }
  421. }
  422. ////////////////////////////////////////////////////////////////
  423. //
  424. // Hooks for other formatting
  425. //
  426. ////////////////////////////////////////////////////////////////
  427. //FIXME: PHP 4.1 Warnings
  428. //lib/Theme.php:84: Notice[8]: The call_user_method() function is deprecated,
  429. //use the call_user_func variety with the array(&$obj, "method") syntax instead
  430. function getFormatter ($type, $format) {
  431. $method = strtolower("get${type}Formatter");
  432. if (method_exists($this, $method))
  433. return $this->{$method}($format);
  434. return false;
  435. }
  436. ////////////////////////////////////////////////////////////////
  437. //
  438. // Links
  439. //
  440. ////////////////////////////////////////////////////////////////
  441. var $_autosplitWikiWords = false;
  442. function setAutosplitWikiWords($autosplit=true) {
  443. $this->_autosplitWikiWords = $autosplit ? true : false;
  444. }
  445. function maybeSplitWikiWord ($wikiword) {
  446. if ($this->_autosplitWikiWords)
  447. return SplitPagename($wikiword);
  448. else
  449. return $wikiword;
  450. }
  451. var $_anonEditUnknownLinks = true;
  452. function setAnonEditUnknownLinks($anonedit=true) {
  453. $this->_anonEditUnknownLinks = $anonedit ? true : false;
  454. }
  455. function linkExistingWikiWord($wikiword, $linktext = '', $version = false) {
  456. global $request;
  457. if ($version !== false and !$this->HTML_DUMP_SUFFIX)
  458. $url = WikiURL($wikiword, array('version' => $version));
  459. else
  460. $url = WikiURL($wikiword);
  461. // Extra steps for dumping page to an html file.
  462. if ($this->HTML_DUMP_SUFFIX) {
  463. $url = preg_replace('/^\./', '%2e', $url); // dot pages
  464. }
  465. $link = HTML::a(array('href' => $url));
  466. if (isa($wikiword, 'WikiPageName'))
  467. $default_text = $wikiword->shortName;
  468. else
  469. $default_text = $wikiword;
  470. if (!empty($linktext)) {
  471. $link->pushContent($linktext);
  472. $link->setAttr('class', 'named-wiki');
  473. $link->setAttr('title', $this->maybeSplitWikiWord($default_text));
  474. }
  475. else {
  476. $link->pushContent($this->maybeSplitWikiWord($default_text));
  477. $link->setAttr('class', 'wiki');
  478. }
  479. if ($request->getArg('frame'))
  480. $link->setAttr('target', '_top');
  481. return $link;
  482. }
  483. function linkUnknownWikiWord($wikiword, $linktext = '') {
  484. global $request;
  485. // Get rid of anchors on unknown wikiwords
  486. if (isa($wikiword, 'WikiPageName')) {
  487. $default_text = $wikiword->shortName;
  488. $wikiword = $wikiword->name;
  489. }
  490. else {
  491. $default_text = $wikiword;
  492. }
  493. if ($this->DUMP_MODE) { // HTML, PDF or XML
  494. $link = HTML::u( empty($linktext) ? $wikiword : $linktext);
  495. $link->addTooltip(sprintf(_("Empty link to: %s"), $wikiword));
  496. $link->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
  497. return $link;
  498. } else {
  499. // if AnonEditUnknownLinks show "?" only users which are allowed to edit this page
  500. if (! $this->_anonEditUnknownLinks and
  501. ( ! $request->_user->isSignedIn()
  502. or ! mayAccessPage('edit', $request->getArg('pagename'))))
  503. {
  504. $text = HTML::span( empty($linktext) ? $wikiword : $linktext);
  505. $text->setAttr('class', empty($linktext) ? 'wikiunknown' : 'named-wikiunknown');
  506. return $text;
  507. } else {
  508. $url = WikiURL($wikiword, array('action' => 'create'));
  509. $button = $this->makeButton('?', $url);
  510. $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
  511. }
  512. }
  513. $link = HTML::span();
  514. if (!empty($linktext)) {
  515. $link->pushContent(HTML::u($linktext));
  516. $link->setAttr('class', 'named-wikiunknown');
  517. }
  518. else {
  519. $link->pushContent(HTML::u($this->maybeSplitWikiWord($default_text)));
  520. $link->setAttr('class', 'wikiunknown');
  521. }
  522. if (!isa($button, "ImageButton"))
  523. $button->setAttr('rel', 'nofollow');
  524. $link->pushContent($button);
  525. if ($request->getPref('googleLink')) {
  526. $gbutton = $this->makeButton('G', "http://www.google.com/search?q="
  527. . urlencode($wikiword));
  528. $gbutton->addTooltip(sprintf(_("Google:%s"), $wikiword));
  529. $link->pushContent($gbutton);
  530. }
  531. if ($request->getArg('frame'))
  532. $link->setAttr('target', '_top');
  533. return $link;
  534. }
  535. function linkBadWikiWord($wikiword, $linktext = '') {
  536. global $ErrorManager;
  537. if ($linktext) {
  538. $text = $linktext;
  539. }
  540. elseif (isa($wikiword, 'WikiPageName')) {
  541. $text = $wikiword->shortName;
  542. }
  543. else {
  544. $text = $wikiword;
  545. }
  546. if (isa($wikiword, 'WikiPageName'))
  547. $message = $wikiword->getWarnings();
  548. else
  549. $message = sprintf(_("'%s': Bad page name"), $wikiword);
  550. $ErrorManager->warning($message);
  551. return HTML::span(array('class' => 'badwikiword'), $text);
  552. }
  553. ////////////////////////////////////////////////////////////////
  554. //
  555. // Images and Icons
  556. //
  557. ////////////////////////////////////////////////////////////////
  558. var $_imageAliases = array();
  559. var $_imageAlt = array();
  560. /**
  561. *
  562. * (To disable an image, alias the image to <code>false</code>.
  563. */
  564. function addImageAlias ($alias, $image_name) {
  565. // fall back to the PhpWiki-supplied image if not found
  566. if ($this->_findFile("images/$image_name", true))
  567. $this->_imageAliases[$alias] = $image_name;
  568. }
  569. function addImageAlt ($alias, $alt_text) {
  570. $this->_imageAlt[$alias] = $alt_text;
  571. }
  572. function getImageAlt ($alias) {
  573. return $this->_imageAlt[$alias];
  574. }
  575. function getImageURL ($image) {
  576. $aliases = &$this->_imageAliases;
  577. if (isset($aliases[$image])) {
  578. $image = $aliases[$image];
  579. if (!$image)
  580. return false;
  581. }
  582. // If not extension, default to .png.
  583. if (!preg_match('/\.\w+$/', $image))
  584. $image .= '.png';
  585. // FIXME: this should probably be made to fall back
  586. // automatically to .gif, .jpg.
  587. // Also try .gif before .png if browser doesn't like png.
  588. $path = $this->_findData("images/$image", 'missing okay');
  589. if (!$path) // search explicit images/ or button/ links also
  590. $path = $this->_findData("$image", 'missing okay');
  591. if ($this->DUMP_MODE) {
  592. if (empty($this->dumped_images)) $this->dumped_images = array();
  593. $path = "images/". basename($path);
  594. if (!in_array($path,$this->dumped_images))
  595. $this->dumped_images[] = $path;
  596. }
  597. return $path;
  598. }
  599. function setLinkIcon($proto, $image = false) {
  600. if (!$image)
  601. $image = $proto;
  602. $this->_linkIcons[$proto] = $image;
  603. }
  604. function getLinkIconURL ($proto) {
  605. $icons = &$this->_linkIcons;
  606. if (!empty($icons[$proto]))
  607. return $this->getImageURL($icons[$proto]);
  608. elseif (!empty($icons['*']))
  609. return $this->getImageURL($icons['*']);
  610. return false;
  611. }
  612. var $_linkIcon = 'front'; // or 'after' or 'no'.
  613. // maybe also 'spanall': there is a scheme currently in effect with front, which
  614. // spans the icon only to the first, to let the next words wrap on line breaks
  615. // see stdlib.php:PossiblyGlueIconToText()
  616. function getLinkIconAttr () {
  617. return $this->_linkIcon;
  618. }
  619. function setLinkIconAttr ($where) {
  620. $this->_linkIcon = $where;
  621. }
  622. function addButtonAlias ($text, $alias = false) {
  623. $aliases = &$this->_buttonAliases;
  624. if (is_array($text))
  625. $aliases = array_merge($aliases, $text);
  626. elseif ($alias === false)
  627. unset($aliases[$text]);
  628. else
  629. $aliases[$text] = $alias;
  630. }
  631. function getButtonURL ($text) {
  632. $aliases = &$this->_buttonAliases;
  633. if (isset($aliases[$text]))
  634. $text = $aliases[$text];
  635. $qtext = urlencode($text);
  636. $url = $this->_findButton("$qtext.png");
  637. if ($url && strstr($url, '%')) {
  638. $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
  639. }
  640. if (!$url) {// Jeff complained about png not supported everywhere.
  641. // This was not PC until 2005.
  642. $url = $this->_findButton("$qtext.gif");
  643. if ($url && strstr($url, '%')) {
  644. $url = preg_replace('|([^/]+)$|e', 'urlencode("\\1")', $url);
  645. }
  646. }
  647. if ($url and $this->DUMP_MODE) {
  648. if (empty($this->dumped_buttons)) $this->dumped_buttons = array();
  649. $file = $url;
  650. if (defined('DATA_PATH'))
  651. $file = substr($url,strlen(DATA_PATH)+1);
  652. $url = "images/buttons/".basename($file);
  653. if (!array_key_exists($text, $this->dumped_buttons))
  654. $this->dumped_buttons[$text] = $file;
  655. }
  656. return $url;
  657. }
  658. function _findButton ($button_file) {
  659. if (empty($this->_button_path))
  660. $this->_button_path = $this->_getButtonPath();
  661. foreach ($this->_button_path as $dir) {
  662. if ($path = $this->_findData("$dir/$button_file", 1))
  663. return $path;
  664. }
  665. return false;
  666. }
  667. function _getButtonPath () {
  668. $button_dir = $this->_findFile("buttons");
  669. $path_dir = $this->_path . $button_dir;
  670. if (!file_exists($path_dir) || !is_dir($path_dir))
  671. return array();
  672. $path = array($button_dir);
  673. $dir = dir($path_dir);
  674. while (($subdir = $dir->read()) !== false) {
  675. if ($subdir[0] == '.')
  676. continue;
  677. if ($subdir == 'CVS')
  678. continue;
  679. if (is_dir("$path_dir/$subdir"))
  680. $path[] = "$button_dir/$subdir";
  681. }
  682. $dir->close();
  683. // add default buttons
  684. $path[] = "themes/default/buttons";
  685. $path_dir = $this->_path . "themes/default/buttons";
  686. $dir = dir($path_dir);
  687. while (($subdir = $dir->read()) !== false) {
  688. if ($subdir[0] == '.')
  689. continue;
  690. if ($subdir == 'CVS')
  691. continue;
  692. if (is_dir("$path_dir/$subdir"))
  693. $path[] = "themes/default/buttons/$subdir";
  694. }
  695. $dir->close();
  696. return $path;
  697. }
  698. ////////////////////////////////////////////////////////////////
  699. //
  700. // Button style
  701. //
  702. ////////////////////////////////////////////////////////////////
  703. function makeButton ($text, $url, $class = false) {
  704. // FIXME: don't always try for image button?
  705. // Special case: URLs like 'submit:preview' generate form
  706. // submission buttons.
  707. if (preg_match('/^submit:(.*)$/', $url, $m))
  708. return $this->makeSubmitButton($text, $m[1], $class);
  709. $imgurl = $this->getButtonURL($text);
  710. if ($imgurl)
  711. return new ImageButton($text, $url, $class, $imgurl);
  712. else
  713. return new Button($this->maybeSplitWikiWord($text), $url, $class);
  714. }
  715. function makeSubmitButton ($text, $name, $class = false) {
  716. $imgurl = $this->getButtonURL($text);
  717. if ($imgurl)
  718. return new SubmitImageButton($text, $name, $class, $imgurl);
  719. else
  720. return new SubmitButton($text, $name, $class);
  721. }
  722. /**
  723. * Make button to perform action.
  724. *
  725. * This constructs a button which performs an action on the
  726. * currently selected version of the current page.
  727. * (Or anotherpage or version, if you want...)
  728. *
  729. * @param $action string The action to perform (e.g. 'edit', 'lock').
  730. * This can also be the name of an "action page" like 'LikePages'.
  731. * Alternatively you can give a hash of query args to be applied
  732. * to the page.
  733. *
  734. * @param $label string Textual label for the button. If left empty,
  735. * a suitable name will be guessed.
  736. *
  737. * @param $page_or_rev mixed The page to link to. This can be
  738. * given as a string (the page name), a WikiDB_Page object, or as
  739. * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
  740. * object, the button will link to a specific version of the
  741. * designated page, otherwise the button links to the most recent
  742. * version of the page.
  743. *
  744. * @return object A Button object.
  745. */
  746. function makeActionButton ($action, $label = false, $page_or_rev = false) {
  747. extract($this->_get_name_and_rev($page_or_rev));
  748. if (is_array($action)) {
  749. $attr = $action;
  750. $action = isset($attr['action']) ? $attr['action'] : 'browse';
  751. }
  752. else
  753. $attr['action'] = $action;
  754. $class = is_safe_action($action) ? 'wikiaction' : 'wikiadmin';
  755. if ( !$label )
  756. $label = $this->_labelForAction($action);
  757. if ($version)
  758. $attr['version'] = $version;
  759. if ($action == 'browse')
  760. unset($attr['action']);
  761. return $this->makeButton($label, WikiURL($pagename, $attr), $class);
  762. }
  763. /**
  764. * Make a "button" which links to a wiki-page.
  765. *
  766. * These are really just regular WikiLinks, possibly
  767. * disguised (e.g. behind an image button) by the theme.
  768. *
  769. * This method should probably only be used for links
  770. * which appear in page navigation bars, or similar places.
  771. *
  772. * Use linkExistingWikiWord, or LinkWikiWord for normal links.
  773. *
  774. * @param $page_or_rev mixed The page to link to. This can be
  775. * given as a string (the page name), a WikiDB_Page object, or as
  776. * WikiDB_PageRevision object. If given as a WikiDB_PageRevision
  777. * object, the button will link to a specific version of the
  778. * designated page, otherwise the button links to the most recent
  779. * version of the page.
  780. *
  781. * @return object A Button object.
  782. */
  783. function makeLinkButton ($page_or_rev, $label = false, $action = false) {
  784. extract($this->_get_name_and_rev($page_or_rev));
  785. $args = $version ? array('version' => $version) : false;
  786. if ($action) $args['action'] = $action;
  787. return $this->makeButton($label ? $label : $pagename,
  788. WikiURL($pagename, $args), 'wiki');
  789. }
  790. function _get_name_and_rev ($page_or_rev) {
  791. $version = false;
  792. if (empty($page_or_rev)) {
  793. global $request;
  794. $pagename = $request->getArg("pagename");
  795. $version = $request->getArg("version");
  796. }
  797. elseif (is_object($page_or_rev)) {
  798. if (isa($page_or_rev, 'WikiDB_PageRevision')) {
  799. $rev = $page_or_rev;
  800. $page = $rev->getPage();
  801. if (!$rev->isCurrent()) $version = $rev->getVersion();
  802. }
  803. else {
  804. $page = $page_or_rev;
  805. }
  806. $pagename = $page->getName();
  807. }
  808. elseif (is_numeric($page_or_rev)) {
  809. $version = $page_or_rev;
  810. }
  811. else {
  812. $pagename = (string) $page_or_rev;
  813. }
  814. return compact('pagename', 'version');
  815. }
  816. function _labelForAction ($action) {
  817. switch ($action) {
  818. case 'edit': return _("Edit");
  819. case 'diff': return _("Diff");
  820. case 'logout': return _("Sign Out");
  821. case 'login': return _("Sign In");
  822. case 'lock': return _("Lock Page");
  823. case 'unlock': return _("Unlock Page");
  824. case 'remove': return _("Remove Page");
  825. default:
  826. // I don't think the rest of these actually get used.
  827. // 'setprefs'
  828. // 'upload' 'dumpserial' 'loadfile' 'zip'
  829. // 'save' 'browse'
  830. return gettext(ucfirst($action));
  831. }
  832. }
  833. //----------------------------------------------------------------
  834. var $_buttonSeparator = "\n | ";
  835. function setButtonSeparator($separator) {
  836. $this->_buttonSeparator = $separator;
  837. }
  838. function getButtonSeparator() {
  839. return $this->_buttonSeparator;
  840. }
  841. ////////////////////////////////////////////////////////////////
  842. //
  843. // CSS
  844. //
  845. // Notes:
  846. //
  847. // Based on testing with Galeon 1.2.7 (Mozilla 1.2):
  848. // Automatic media-based style selection (via <link> tags) only
  849. // seems to work for the default style, not for alternate styles.
  850. //
  851. // Doing
  852. //
  853. // <link rel="stylesheet" type="text/css" href="phpwiki.css" />
  854. // <link rel="stylesheet" type="text/css" href="phpwiki-printer.css" media="print" />
  855. //
  856. // works to make it so that the printer style sheet get used
  857. // automatically when printing (or print-previewing) a page
  858. // (but when only when the default style is selected.)
  859. //
  860. // Attempts like:
  861. //
  862. // <link rel="alternate stylesheet" title="Modern"
  863. // type="text/css" href="phpwiki-modern.css" />
  864. // <link rel="alternate stylesheet" title="Modern"
  865. // type="text/css" href="phpwiki-printer.css" media="print" />
  866. //
  867. // Result in two "Modern" choices when trying to select alternate style.
  868. // If one selects the first of those choices, one gets phpwiki-modern
  869. // both when browsing and printing. If one selects the second "Modern",
  870. // one gets no CSS when browsing, and phpwiki-printer when printing.
  871. //
  872. // The Real Fix?
  873. // =============
  874. //
  875. // We should probably move to doing the media based style
  876. // switching in the CSS files themselves using, e.g.:
  877. //
  878. // @import url(print.css) print;
  879. //
  880. ////////////////////////////////////////////////////////////////
  881. function _CSSlink($title, $css_file, $media, $is_alt = false) {
  882. // Don't set title on default style. This makes it clear to
  883. // the user which is the default (i.e. most supported) style.
  884. if ($is_alt and isBrowserKonqueror())
  885. return HTML();
  886. $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet',
  887. 'type' => 'text/css',
  888. 'charset' => $GLOBALS['charset'],
  889. 'href' => $this->_findData($css_file)));
  890. if ($is_alt)
  891. $link->setAttr('title', $title);
  892. if ($media)
  893. $link->setAttr('media', $media);
  894. if ($this->DUMP_MODE) {
  895. if (empty($this->dumped_css)) $this->dumped_css = array();
  896. if (!in_array($css_file,$this->dumped_css)) $this->dumped_css[] = $css_file;
  897. $link->setAttr('href', basename($link->getAttr('href')));
  898. }
  899. return $link;
  900. }
  901. /** Set default CSS source for this theme.
  902. *
  903. * To set styles to be used for different media, pass a
  904. * hash for the second argument, e.g.
  905. *
  906. * $theme->setDefaultCSS('default', array('' => 'normal.css',
  907. * 'print' => 'printer.css'));
  908. *
  909. * If you call this more than once, the last one called takes
  910. * precedence as the default style.
  911. *
  912. * @param string $title Name of style (currently ignored, unless
  913. * you call this more than once, in which case, some of the style
  914. * will become alternate (rather than default) styles, and then their
  915. * titles will be used.
  916. *
  917. * @param mixed $css_files Name of CSS file, or hash containing a mapping
  918. * between media types and CSS file names. Use a key of '' (the empty string)
  919. * to set the default CSS for non-specified media. (See above for an example.)
  920. */
  921. function setDefaultCSS ($title, $css_files) {
  922. if (!is_array($css_files))
  923. $css_files = array('' => $css_files);
  924. // Add to the front of $this->_css
  925. unset($this->_css[$title]);
  926. $this->_css = array_merge(array($title => $css_files), $this->_css);
  927. }
  928. /** Set alternate CSS source for this theme.
  929. *
  930. * @param string $title Name of style.
  931. * @param string $css_files Name of CSS file.
  932. */
  933. function addAlternateCSS ($title, $css_files) {
  934. if (!is_array($css_files))
  935. $css_files = array('' => $css_files);
  936. $this->_css[$title] = $css_files;
  937. }
  938. /**
  939. * @return string HTML for CSS.
  940. */
  941. function getCSS () {
  942. $css = array();
  943. $is_alt = false;
  944. foreach ($this->_css as $title => $css_files) {
  945. ksort($css_files); // move $css_files[''] to front.
  946. foreach ($css_files as $media => $css_file) {
  947. $css[] = $this->_CSSlink($title, $css_file, $media, $is_alt);
  948. if ($is_alt) break;
  949. }
  950. $is_alt = true;
  951. }
  952. return HTML($css);
  953. }
  954. function findTemplate ($name) {
  955. if ($tmp = $this->_findFile("templates/$name.tmpl", 1))
  956. return $this->_path . $tmp;
  957. else {
  958. $f1 = $this->file("templates/$name.tmpl");
  959. trigger_error("pwd: ".getcwd(), E_USER_ERROR);
  960. if (isset($this->_default_theme)) {
  961. $f2 = $this->_default_theme->file("templates/$name.tmpl");
  962. trigger_error("$f1 nor $f2 found", E_USER_ERROR);
  963. } else
  964. trigger_error("$f1 not found", E_USER_ERROR);
  965. return false;
  966. }
  967. }
  968. var $_MoreHeaders = array();
  969. function addMoreHeaders ($element) {
  970. array_push($this->_MoreHeaders, $element);
  971. }
  972. function getMoreHeaders () {
  973. if (empty($this->_MoreHeaders))
  974. return '';
  975. $out = '';
  976. //$out = "<!-- More Headers -->\n";
  977. foreach ($this->_MoreHeaders as $h) {
  978. if (is_object($h))
  979. $out .= printXML($h);
  980. else
  981. $out .= "$h\n";
  982. }
  983. return $out;
  984. }
  985. var $_MoreAttr = array();
  986. // new arg: named elements to be able to remove them. such as DoubleClickEdit for htmldumps
  987. function addMoreAttr ($tag, $name, $element) {
  988. // protect from duplicate attr (body jscript: themes, prefs, ...)
  989. static $_attr_cache = array();
  990. $hash = md5($tag."/".$element);
  991. if (!empty($_attr_cache[$hash])) return;
  992. $_attr_cache[$hash] = 1;
  993. if (empty($this->_MoreAttr) or !is_array($this->_MoreAttr[$tag]))
  994. $this->_MoreAttr[$tag] = array($name => $element);
  995. else
  996. $this->_MoreAttr[$tag][$name] = $element;
  997. }
  998. function getMoreAttr ($tag) {
  999. if (empty($this->_MoreAttr[$tag]))
  1000. return '';
  1001. $out = '';
  1002. foreach ($this->_MoreAttr[$tag] as $name => $element) {
  1003. if (is_object($element))
  1004. $out .= printXML($element);
  1005. else
  1006. $out .= "$element";
  1007. }
  1008. return $out;
  1009. }
  1010. /**
  1011. * Custom UserPreferences:
  1012. * A list of name => _UserPreference class pairs.
  1013. * Rationale: Certain themes should be able to extend the predefined list
  1014. * of preferences. Display/editing is done in the theme specific userprefs.tmpl
  1015. * but storage/sanification/update/... must be extended to the Get/SetPreferences methods.
  1016. * These values are just ignored if another theme is used.
  1017. */
  1018. function customUserPreferences($array) {
  1019. global $customUserPreferenceColumns; // FIXME: really a global?
  1020. if (empty($customUserPreferenceColumns)) $customUserPreferenceColumns = array();
  1021. //array('wikilens' => new _UserPreference_wikilens());
  1022. foreach ($array as $field => $prefobj) {
  1023. $customUserPreferenceColumns[$field] = $prefobj;
  1024. }
  1025. }
  1026. /** addPageListColumn(array('rating' => new _PageList_Column_rating('rating', _("Rate"))))
  1027. * Register custom PageList types for special themes, like
  1028. * 'rating' for wikilens
  1029. */
  1030. function addPageListColumn ($array) {
  1031. global $customPageListColumns;
  1032. if (empty($customPageListColumns)) $customPageListColumns = array();
  1033. foreach ($array as $column => $obj) {
  1034. $customPageListColumns[$column] = $obj;
  1035. }
  1036. }
  1037. // Works only on action=browse. Patch #970004 by pixels
  1038. // Usage: call $WikiTheme->initDoubleClickEdit() from theme init or
  1039. // define ENABLE_DOUBLECLICKEDIT
  1040. function initDoubleClickEdit() {
  1041. if (!$this->HTML_DUMP_SUFFIX)
  1042. $this->addMoreAttr('body', 'DoubleClickEdit', HTML::Raw(" ondblclick=\"url = document.URL; url2 = url; if (url.indexOf('?') != -1) url2 = url.slice(0, url.indexOf('?')); if ((url.indexOf('action') == -1) || (url.indexOf('action=browse') != -1)) document.location = url2 + '?action=edit';\""));
  1043. }
  1044. // Immediate title search results via XMLHTML(HttpRequest
  1045. // by Bitflux GmbH, bitflux.ch. You need to install the livesearch.js seperately.
  1046. // Google's or acdropdown is better.
  1047. function initLiveSearch() {
  1048. if (!$this->HTML_DUMP_SUFFIX) {
  1049. $this->addMoreAttr('body', 'LiveSearch',
  1050. HTML::Raw(" onload=\"liveSearchInit()"));
  1051. $this->addMoreHeaders(JavaScript('var liveSearchURI="'
  1052. .WikiURL(_("TitleSearch"),false,true).'";'));
  1053. $this->addMoreHeaders(JavaScript('', array
  1054. ('src' => $this->_findData('livesearch.js'))));
  1055. }
  1056. }
  1057. };
  1058. /**
  1059. * A class representing a clickable "button".
  1060. *
  1061. * In it's simplest (default) form, a "button" is just a link associated
  1062. * with some sort of wiki-action.
  1063. */
  1064. class Button extends HtmlElement {
  1065. /** Constructor
  1066. *
  1067. * @param $text string The text for the button.
  1068. * @param $url string The url (href) for the button.
  1069. * @param $class string The CSS class for the button.
  1070. */
  1071. function Button ($text, $url, $class = false) {
  1072. global $request;
  1073. //php5 workaround
  1074. if (check_php_version(5)) {
  1075. $this->_init('a', array('href' => $url));
  1076. } else {
  1077. $this->__construct('a', array('href' => $url));
  1078. }
  1079. if ($class)
  1080. $this->setAttr('class', $class);
  1081. if ($request->getArg('frame'))
  1082. $this->setAttr('target', '_top');
  1083. // Google honors this
  1084. if (in_array(strtolower($text), array('edit','create','diff','pdf'))
  1085. and !$request->_user->isAuthenticated())
  1086. $this->setAttr('rel', 'nofollow');
  1087. $this->pushContent($GLOBALS['WikiTheme']->maybeSplitWikiWord($text));
  1088. }
  1089. };
  1090. /**
  1091. * A clickable image button.
  1092. */
  1093. class ImageButton extends Button {
  1094. /** Constructor
  1095. *
  1096. * @param $text string The text for the button.
  1097. * @param $url string The url (href) for the button.
  1098. * @param $class string The CSS class for the button.
  1099. * @param $img_url string URL for button's image.
  1100. * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
  1101. */
  1102. function ImageButton ($text, $url, $class, $img_url, $img_attr = false) {
  1103. $this->__construct('a', array('href' => $url));
  1104. if ($class)
  1105. $this->setAttr('class', $class);
  1106. // Google honors this
  1107. if (in_array(strtolower($text), array('edit','create','diff','pdf'))
  1108. and !$GLOBALS['request']->_user->isAuthenticated())
  1109. $this->setAttr('rel', 'nofollow');
  1110. if (!is_array($img_attr))
  1111. $img_attr = array();
  1112. $img_attr['src'] = $img_url;
  1113. $img_attr['alt'] = $text;
  1114. $img_attr['class'] = 'wiki-button';
  1115. $img_attr['border'] = 0;
  1116. $this->pushContent(HTML::img($img_attr));
  1117. }
  1118. };
  1119. /**
  1120. * A class representing a form <samp>submit</samp> button.
  1121. */
  1122. class SubmitButton extends HtmlElement {
  1123. /** Constructor
  1124. *
  1125. * @param $text string The text for the button.
  1126. * @param $name string The name of the form field.
  1127. * @param $class string The CSS class for the button.
  1128. */
  1129. function SubmitButton ($text, $name = false, $class = false) {
  1130. $this->__construct('input', array('type' => 'submit',
  1131. 'value' => $text));
  1132. if ($name)
  1133. $this->setAttr('name', $name);
  1134. if ($class)
  1135. $this->setAttr('class', $class);
  1136. }
  1137. };
  1138. /**
  1139. * A class representing an image form <samp>submit</samp> button.
  1140. */
  1141. class SubmitImageButton extends SubmitButton {
  1142. /** Constructor
  1143. *
  1144. * @param $text string The text for the button.
  1145. * @param $name string The name of the form field.
  1146. * @param $class string The CSS class for the button.
  1147. * @param $img_url string URL for button's image.
  1148. * @param $img_attr array Additional attributes for the &lt;img&gt; tag.
  1149. */
  1150. function SubmitImageButton ($text, $name = false, $class = false, $img_url) {
  1151. $this->__construct('input', array('type' => 'image',
  1152. 'src' => $img_url,
  1153. 'value' => $text,
  1154. 'alt' => $text));
  1155. if ($name)
  1156. $this->setAttr('name', $name);
  1157. if ($class)
  1158. $this->setAttr('class', $class);
  1159. }
  1160. };
  1161. /**
  1162. * A sidebar box with title and body, narrow fixed-width.
  1163. * To represent abbrevated content of plugins, links or forms,
  1164. * like "Getting Started", "Search", "Sarch Pagename",
  1165. * "Login", "Menu", "Recent Changes", "Last comments", "Last Blogs"
  1166. * "Calendar"
  1167. * ... See http://tikiwiki.org/
  1168. *
  1169. * Usage:
  1170. * sidebar.tmpl:
  1171. * $menu = SidebarBox("Menu",HTML::dl(HTML::dt(...))); $menu->format();
  1172. * $menu = PluginSidebarBox("RecentChanges",array('limit'=>10)); $menu->format();
  1173. */
  1174. class SidebarBox {
  1175. function SidebarBox($title, $body) {
  1176. require_once('lib/WikiPlugin.php');
  1177. $this->title = $title;
  1178. $this->body = $body;
  1179. }
  1180. function format() {
  1181. return WikiPlugin::makeBox($this->title, $this->body);
  1182. }
  1183. }
  1184. /**
  1185. * A sidebar box for plugins.
  1186. * Any plugin may provide a box($args=false, $request=false, $basepage=false)
  1187. * method, with the help of WikiPlugin::makeBox()
  1188. */
  1189. class PluginSidebarBox extends SidebarBox {
  1190. var $_plugin, $_args = false, $_basepage = false;
  1191. function PluginSidebarBox($name, $args = false, $basepage = false) {
  1192. $loader = new WikiPluginLoader();
  1193. $plugin = $loader->getPlugin($name);
  1194. if (!$plugin) {
  1195. return $loader->_error(sprintf(_("Plugin %s: undefined"),
  1196. $name));
  1197. }/*
  1198. if (!method_exists($plugin, 'box')) {
  1199. return $loader->_error(sprintf(_("%s: has no box method"),
  1200. get_class($plugin)));
  1201. }*/
  1202. $this->_plugin =& $plugin;
  1203. $this->_args = $args ? $args : array();
  1204. $this->_basepage = $basepage;
  1205. }
  1206. function format($args = false) {
  1207. return $this->_plugin->box($args ? array_merge($this->_args, $args) : $this->_args,
  1208. $GLOBALS['request'],
  1209. $this->_basepage);
  1210. }
  1211. }
  1212. // Various boxes which are no plugins
  1213. class RelatedLinksBox extends SidebarBox {
  1214. function RelatedLinksBox($title = false, $body = '', $limit = 20) {
  1215. global $request;
  1216. $this->title = $title ? $title : _("Related Links");
  1217. $this->body = HTML($body);
  1218. $page = $request->getPage($request->getArg('pagename'));
  1219. $revision = $page->getCurrentRevision();
  1220. $page_content = $revision->getTransformedContent();
  1221. //$cache = &$page->_wikidb->_cache;
  1222. $counter = 0;
  1223. $sp = HTML::Raw('&middot; ');
  1224. foreach ($page_content->getWikiPageLinks() as $link) {
  1225. if (!$request->_dbi->isWikiPage($link)) continue;
  1226. $this->body->pushContent($sp, WikiLink($link), HTML::br());
  1227. $counter++;
  1228. if ($limit and $counter > $limit) continue;
  1229. }
  1230. }
  1231. }
  1232. class RelatedExternalLinksBox extends SidebarBox {
  1233. function RelatedExternalLinksBox($title = false, $body = '', $limit = 20) {
  1234. global $request;
  1235. $this->title = $title ? $title : _("External Links");
  1236. $this->body = HTML($body);
  1237. $page = $request->getPage($request->getArg('pagename'));
  1238. $cache = &$page->_wikidb->_cache;
  1239. $counter = 0;
  1240. $sp = HTML::Raw('&middot; ');
  1241. foreach ($cache->getWikiPageLinks() as $link) {
  1242. if ($link) {
  1243. $this->body->pushContent($sp, WikiLink($link), HTML::br());
  1244. $counter++;
  1245. if ($limit and $counter > $limit) continue;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. function listAvailableThemes() {
  1251. $available_themes = array();
  1252. $dir_root = 'themes';
  1253. if (defined('PHPWIKI_DIR'))
  1254. $dir_root = PHPWIKI_DIR . "/$dir_root";
  1255. $dir = dir($dir_root);
  1256. if ($dir) {
  1257. while($entry = $dir->read()) {
  1258. if (is_dir($dir_root.'/'.$entry)
  1259. && (substr($entry,0,1) != '.')
  1260. && $entry != 'CVS') {
  1261. array_push($available_themes, $entry);
  1262. }
  1263. }
  1264. $dir->close();
  1265. }
  1266. return $available_themes;
  1267. }
  1268. function listAvailableLanguages

Large files files are truncated, but you can click here to view the full file