PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/e107_plugins/tagwords/tagwords_shortcodes.php

https://github.com/CasperGemini/e107
PHP | 416 lines | 347 code | 41 blank | 28 comment | 24 complexity | 072e4d9a262d8f20b525b3e563d110b1 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * Tagwords Shortcodes
  10. *
  11. */
  12. if (!defined('e107_INIT')) { exit; }
  13. /*
  14. $codes = array(
  15. 'tag_search', 'tag_area_heading', 'tag_link', 'tag_cloud', 'tag_word', 'tag_number', 'tag_sort', 'tag_type', 'tag_area', 'tag_button', 'tag_options', 'tag_opt_min', 'tag_opt_class', 'tag_opt_default_sort', 'tag_opt_default_style', 'tag_opt_view_sort', 'tag_opt_view_style', 'tag_opt_view_area', 'tag_opt_view_search', 'tag_opt_view_freq', 'tag_opt_caption', 'tag_opt_seperator', 'tag_opt_activeareas', 'tag_opt_button'
  16. );
  17. */
  18. $codes = array();
  19. /*
  20. $tmp = get_class_methods('tagwords_shortcodes');
  21. foreach($tmp as $c)
  22. {
  23. if(strpos($c, 'sc_') === 0)
  24. {
  25. $codes[] = substr($c, 3);
  26. }
  27. }
  28. */
  29. // register_shortcode('tagwords_shortcodes', TRUE);
  30. // initShortcodeClass('tagwords_shortcodes');
  31. class tagwords_shortcodes extends e_shortcode
  32. {
  33. var $e107;
  34. function tagwords_shortcodes()
  35. {
  36. $this->e107 = e107::getInstance();
  37. }
  38. function sc_tag_search($parm, $sc_mode)
  39. {
  40. global $tag;
  41. $value = (isset($_GET['q']) ? e107::getParser()->toForm($_GET['q']) : '');
  42. switch($sc_mode)
  43. {
  44. case 'menu':
  45. if(varsettrue($tag->pref['tagwords_menu_view_search'])!=1)
  46. {
  47. return;
  48. }
  49. $id = 'tagwords_searchform_menu';
  50. return "
  51. <form id='".$id."' method='get' action='".e_PLUGIN_ABS."tagwords/tagwords.php'>
  52. <div>
  53. <input class='tbox' style='width:100px;' type='text' name='q' size='35' value='".$value."' maxlength='50' />
  54. <input class='btn btn-default button' type='submit' name='se' value='".LAN_TAG_SEARCH_2."' />
  55. </div>
  56. </form>";
  57. break;
  58. case 'search':
  59. if(varsettrue($tag->pref['tagwords_view_search'])!=1)
  60. {
  61. return;
  62. }
  63. $id = 'tagwords_searchform';
  64. return "
  65. <form id='".$id."' method='get' action='".e_PLUGIN_ABS."tagwords/tagwords.php'>
  66. <div>
  67. <input class='tbox' style='width:100px;' type='text' name='q' size='35' value='".$value."' maxlength='50' />
  68. <input class='btn btn-default button' type='submit' name='s' value='".LAN_TAG_SEARCH_2."' />
  69. </div>
  70. </form>";
  71. break;
  72. default:
  73. if(varsettrue($tag->pref['tagwords_view_search'])!=1)
  74. {
  75. return;
  76. }
  77. return "
  78. <input class='tbox' style='width:100px;' type='text' name='q' size='35' value='".$value."' maxlength='50' />
  79. <input class='btn btn-default button' type='submit' name='s' value='".LAN_TAG_SEARCH_2."' />";
  80. break;
  81. }
  82. }
  83. function sc_tag_area_heading()
  84. {
  85. global $tag;
  86. return (varsettrue($tag->area->settings['caption']) ? defset($tag->area->settings['caption'], $tag->area->settings['caption']) : '');
  87. }
  88. function sc_tag_link($parm, $sc_mode)
  89. {
  90. global $tag;
  91. switch($sc_mode)
  92. {
  93. case 'menu':
  94. return "<a href='".e107::getUrl()->create('tagwords')."'>".LAN_TAG_MENU_1."</a>";
  95. break;
  96. case 'home':
  97. return "<a href='".e107::getUrl()->create('tagwords')."'>".LAN_TAG_7."</a>";
  98. break;
  99. default:
  100. if(method_exists($tag->area, 'getLink'))
  101. {
  102. return $tag->area->getLink($tag->id);
  103. }
  104. break;
  105. }
  106. }
  107. function sc_tag_cloud($parm, $sc_mode)
  108. {
  109. global $tag;
  110. switch($sc_mode)
  111. {
  112. case 'menu':
  113. return $tag->TagCloud('menu');
  114. break;
  115. case 'list':
  116. return $tag->TagCloudList();
  117. break;
  118. default:
  119. return $tag->TagCloud();
  120. break;
  121. }
  122. }
  123. function sc_tag_word($parm, $sc_mode)
  124. {
  125. global $tag;
  126. switch($sc_mode)
  127. {
  128. case 'result':
  129. return "<b>".$tag->num."</b> ".($tag->num==1 ? LAN_TAG_8 : LAN_TAG_9)." '<b>".e107::getParser()->toHTML($_GET['q'],true)."</b>'";
  130. break;
  131. case 'form':
  132. default:
  133. return $tag->word;
  134. break;
  135. }
  136. }
  137. function sc_tag_number($parm, $sc_mode)
  138. {
  139. global $tag;
  140. switch($sc_mode)
  141. {
  142. case 'list':
  143. return $tag->number;
  144. break;
  145. case 'menu':
  146. if(varsettrue($tag->pref['tagwords_menu_view_freq'])==1)
  147. {
  148. return $tag->number;
  149. }
  150. break;
  151. default:
  152. if(varsettrue($tag->pref['tagwords_view_freq'])==1)
  153. {
  154. return $tag->number;
  155. }
  156. break;
  157. }
  158. }
  159. function sc_tag_sort()
  160. {
  161. global $tag;
  162. if(varsettrue($tag->pref['tagwords_view_sort'])==1)
  163. {
  164. $s = varset($_GET['sort'],'');
  165. switch($s)
  166. {
  167. case 'alpha':
  168. $sel = 'alpha';
  169. break;
  170. case 'freq':
  171. $sel = 'freq';
  172. break;
  173. default:
  174. $sel = '';
  175. break;
  176. }
  177. $text = "
  178. <select id='sort' name='sort' class='tbox'>
  179. <option value=''>".LAN_TAG_19."</option>
  180. <option value='alpha' ".($sel=='alpha' ? "selected='selected'" : '')." >".LAN_TAG_10."</option>
  181. <option value='freq' ".($sel=='freq' ? "selected='selected'" : '')." >".LAN_TAG_11."</option>
  182. </select>";
  183. return $text;
  184. }
  185. return;
  186. }
  187. function sc_tag_type()
  188. {
  189. global $tag;
  190. if(varsettrue($tag->pref['tagwords_view_style'])==1)
  191. {
  192. $t = varset($_GET['type'],'');
  193. switch($t)
  194. {
  195. case 'cloud':
  196. $sel = 'cloud';
  197. break;
  198. case 'list':
  199. $sel = 'list';
  200. break;
  201. default:
  202. $sel = '';
  203. break;
  204. }
  205. $text = "
  206. <select id='type' name='type' class='tbox'>
  207. <option value=''>".LAN_TAG_20."</option>
  208. <option value='cloud' ".($sel=='cloud' ? "selected='selected'" : '')." >".LAN_TAG_13."</option>
  209. <option value='list' ".($sel=='list' ? "selected='selected'" : '')." >".LAN_TAG_12."</option>
  210. </select>";
  211. return $text;
  212. }
  213. return;
  214. }
  215. function sc_tag_area()
  216. {
  217. global $tag;
  218. if(varsettrue($tag->pref['tagwords_view_area'])==1)
  219. {
  220. $text = "
  221. <select id='area' name='area' class='tbox'>
  222. <option value='' >".LAN_TAG_15."</option>";
  223. foreach($tag->tagwords as $area)
  224. {
  225. if(array_key_exists($area,$tag->pref['tagwords_activeareas']))
  226. {
  227. $name = "e_tagwords_{$area}";
  228. $selected = (varsettrue($_GET['area'])==$area ? "selected=selected" : '');
  229. $text .= "<option value='".$area."' ".$selected." >".defset($tag->$name->settings['caption'], $tag->$name->settings['caption'])."</option>";
  230. }
  231. }
  232. $text .= "
  233. </select>";
  234. return $text;
  235. }
  236. return;
  237. }
  238. function sc_tag_button()
  239. {
  240. global $tag;
  241. if(varsettrue($tag->pref['tagwords_view_sort']) || varsettrue($tag->pref['tagwords_view_style']) || varsettrue($tag->pref['tagwords_view_area']))
  242. return "<input class='btn btn-default button' type='submit' name='so' value='".LAN_TAG_SEARCH_3."' />";
  243. return '';
  244. }
  245. function sc_tag_options()
  246. {
  247. global $tag;
  248. if( varsettrue($tag->pref['tagwords_view_search'])==1 || varsettrue($tag->pref['tagwords_view_sort'])==1 || varsettrue($tag->pref['tagwords_view_style'])==1 || varsettrue($tag->pref['tagwords_view_area'])==1 )
  249. {
  250. return e107::getParser()->parseTemplate($tag->template['options'], true, $tag->shortcodes);
  251. }
  252. }
  253. function sc_tag_url($parm)
  254. {
  255. return e107::getUrl()->create('tagwords', $parm);
  256. }
  257. //##### ADMIN OPTIONS -------------------------
  258. function sc_tag_opt_min($parm, $sc_mode)
  259. {
  260. global $tag;
  261. $id = ($sc_mode=='menu' ? 'tagwords_menu_min' : 'tagwords_min');
  262. return "<input class='tbox' type='text' id='".$id."' name='".$id."' value='".$tag->pref[$id]."' size='3' maxlength='3' />";
  263. }
  264. function sc_tag_opt_class()
  265. {
  266. global $tag;
  267. $id = 'tagwords_class';
  268. return r_userclass($id,$tag->pref[$id],"","admin,public,guest,nobody,member,classes");
  269. }
  270. function sc_tag_opt_default_sort($parm, $sc_mode)
  271. {
  272. global $tag;
  273. $id = ($sc_mode=='menu' ? 'tagwords_menu_default_sort' : 'tagwords_default_sort');
  274. return "<label><input type='radio' name='".$id."' value='1' ".($tag->pref[$id] ? "checked='checked'" : "")." /> ".LAN_TAG_OPT_5."</label>&nbsp;&nbsp;
  275. <label><input type='radio' name='".$id."' value='0' ".($tag->pref[$id] ? "" : "checked='checked'")." /> ".LAN_TAG_OPT_6."</label>";
  276. }
  277. function sc_tag_opt_default_style()
  278. {
  279. global $tag;
  280. $id = 'tagwords_default_style';
  281. return "<label><input type='radio' name='".$id."' value='1' ".($tag->pref[$id] ? "checked='checked'" : "")." /> ".LAN_TAG_OPT_8."</label>&nbsp;&nbsp;
  282. <label><input type='radio' name='".$id."' value='0' ".($tag->pref[$id] ? "" : "checked='checked'")." /> ".LAN_TAG_OPT_9."</label>";
  283. }
  284. function sc_tag_opt_view_sort()
  285. {
  286. global $tag;
  287. $id = 'tagwords_view_sort';
  288. $sel = (isset($tag->pref[$id]) && $tag->pref[$id] ? "checked='checked'" : "");
  289. return "
  290. <label for='".$id."'>
  291. <input type='checkbox' name='".$id."' id='".$id."' value='1' ".$sel." /> ".LAN_TAG_OPT_12."
  292. </label>";
  293. }
  294. function sc_tag_opt_view_style()
  295. {
  296. global $tag;
  297. $id = 'tagwords_view_style';
  298. $sel = (isset($tag->pref[$id]) && $tag->pref[$id] ? "checked='checked'" : "");
  299. return "
  300. <label for='".$id."'>
  301. <input type='checkbox' name='".$id."' id='".$id."' value='1' ".$sel." /> ".LAN_TAG_OPT_13."
  302. </label>";
  303. }
  304. function sc_tag_opt_view_area()
  305. {
  306. global $tag;
  307. $id = 'tagwords_view_area';
  308. $sel = (isset($tag->pref[$id]) && $tag->pref[$id] ? "checked='checked'" : "");
  309. return "
  310. <label for='".$id."'>
  311. <input type='checkbox' name='".$id."' id='".$id."' value='1' ".$sel." /> ".LAN_TAG_OPT_14."
  312. </label>";
  313. }
  314. function sc_tag_opt_view_search($parm, $sc_mode)
  315. {
  316. global $tag;
  317. $id = ($sc_mode=='menu' ? 'tagwords_menu_view_search' : 'tagwords_view_search');
  318. $sel = (isset($tag->pref[$id]) && $tag->pref[$id] ? "checked='checked'" : "");
  319. return "
  320. <label for='".$id."'>
  321. <input type='checkbox' name='".$id."' id='".$id."' value='1' ".$sel." /> ".LAN_TAG_OPT_19."
  322. </label>";
  323. }
  324. function sc_tag_opt_view_freq($parm, $sc_mode)
  325. {
  326. global $tag;
  327. if($sc_mode=='menu')
  328. {
  329. $id = 'tagwords_menu_view_freq';
  330. }
  331. else
  332. {
  333. $id = 'tagwords_view_freq';
  334. }
  335. $sel = (isset($tag->pref[$id]) && $tag->pref[$id] ? "checked='checked'" : "");
  336. return "
  337. <label for='".$id."'>
  338. <input type='checkbox' name='".$id."' id='".$id."' value='1' ".$sel." /> ".LAN_TAG_OPT_20."
  339. </label>";
  340. }
  341. function sc_tag_opt_caption()
  342. {
  343. global $tag;
  344. $id = 'tagwords_menu_caption';
  345. return "<input class='tbox' type='text' id='".$id."' name='".$id."' value='".e107::getParser()->toForm($tag->pref[$id],"","defs")."' size='30' maxlength='100' />";
  346. }
  347. function sc_tag_opt_seperator()
  348. {
  349. global $tag;
  350. $id = 'tagwords_word_seperator';
  351. return "<input class='tbox' type='text' id='".$id."' name='".$id."' value='".e107::getParser()->toForm($tag->pref[$id])."' size='3' maxlength='10' />";
  352. }
  353. function sc_tag_opt_activeareas()
  354. {
  355. global $tag;
  356. $id = 'tagwords_activeareas';
  357. $text = "";
  358. foreach($tag->tagwords as $area)
  359. {
  360. $sel = (array_key_exists($area,$tag->pref[$id]) ? "checked='checked'" : '');
  361. $name = "e_tagwords_{$area}";
  362. $text .= "
  363. <label for='".$id."-".$area."'>
  364. <input type='checkbox' name='".$id."[".$area."]' id='".$id."-".$area."' value='1' ".$sel." />
  365. ".defset($tag->$name->settings['caption'], $tag->$name->settings['caption'])."
  366. </label><br />";
  367. }
  368. return $text;
  369. }
  370. function sc_tag_opt_button()
  371. {
  372. return "<input class='btn btn-default button' type='submit' name='updatesettings' value='".LAN_UPDATE."' />";
  373. }
  374. }
  375. ?>