XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
wiki.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
23 defined('XOOPS_ROOT_PATH') or die('Restricted access');
24 
26 {
27  function encode($textarea_id)
28  {
29  $config = parent::loadConfig(dirname(__FILE__));
30  $code = "<img src='{$this->image_path}/wiki.gif' alt='" . _XOOPS_FORM_ALTWIKI . "' onclick='xoopsCodeWiki(\"{$textarea_id}\",\"" . htmlspecialchars(_XOOPS_FORM_ENTERWIKITERM, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;";
31  $javascript = <<<EOH
32  function xoopsCodeWiki(id, enterWikiPhrase){
33  if (enterWikiPhrase == null) {
34  enterWikiPhrase = "Enter the word to be linked to Wiki:";
35  }
36  var selection = xoopsGetSelect(id);
37  if (selection.length > 0) {
38  var text = selection;
39  }else {
40  var text = prompt(enterWikiPhrase, "");
41  }
42  var domobj = xoopsGetElementById(id);
43  if ( text != null && text != "" ) {
44  var result = "[[" + text + "]]";
45  xoopsInsertText(domobj, result);
46  }
47  domobj.focus();
48  }
49 EOH;
50  return array(
51  $code ,
52  $javascript);
53  }
54 
55  function load(&$ts)
56  {
57  $ts->patterns[] = "/\[\[([^\]]*)\]\]/esU";
58  $ts->replacements[] = __CLASS__ . "::decode( '\\1' )";
59  }
60 
61  function decode($text)
62  {
63  $config = parent::loadConfig(dirname(__FILE__));
64  if (empty($text) || empty($config['link'])) {
65  return $text;
66  }
67  $charset = !empty($config['charset']) ? $config['charset'] : "UTF-8";
68  xoops_load('XoopsLocal');
69  $ret = "<a href='" . sprintf($config['link'], urlencode(XoopsLocal::convert_encoding($text, $charset))) . "' rel='external' title=''>{$text}</a>";
70  return $ret;
71  }
72 }
73 ?>