PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/mem_admin_parse/mem_admin_parse.php

https://bitbucket.org/Manfre/txp-plugins
PHP | 199 lines | 128 code | 53 blank | 18 comment | 23 complexity | 7ad6daa33b2a2d9e764c257184ad63fc MD5 | raw file
  1. <?php
  2. // Copy this file to a new name like abc_myplugin.php. Edit the code, then
  3. // run this file at the command line to produce a plugin for distribution:
  4. // $ php abc_myplugin.php > abc_myplugin-0.1.txt
  5. // Plugin name is optional. If unset, it will be extracted from the current
  6. // file name. Uncomment and edit this line to override:
  7. $plugin['name'] = 'mem_admin_parse';
  8. $plugin['version'] = '0.2.4';
  9. $plugin['author'] = 'Michael Manfre';
  10. $plugin['author_uri'] = 'http://manfre.net/';
  11. $plugin['description'] = 'Provides functions to parse txp tags in the admin interface.';
  12. $plugin['type'] = 1; // 0 for regular plugin; 1 if it includes admin-side code
  13. @include_once('../zem_tpl.php');
  14. if (0) {
  15. ?>
  16. # --- BEGIN PLUGIN HELP ---
  17. h2. mem_admin_parse
  18. p. This plugin allows other plugins to parse text for txp tags, in a fashion similar to public side plugins. This plugin is designed to only be used by other plugins.
  19. h3. Function: admin_parse(string text, bool use_textile)
  20. p. Param text is the text string that will be parsed for tags.
  21. p. Param use_textile specifies whether or not text is Textile formatted and should be converted to html before being parsed. Default is not to parse.
  22. h3. Admin Tag: mem_gps
  23. p. This tag will output the POST or GET parameter value, and is designed to be a generic postback tag for relaying information to the user after submitting a form.
  24. p. <code><txp:mem_gps name="_argname_" /></code>
  25. h3. mem_if_query name="url_param_name" value="url_param_value"
  26. h3. mem_if_step name="step_name"
  27. # --- END PLUGIN HELP ---
  28. <?php
  29. }
  30. # --- BEGIN PLUGIN CODE ---
  31. ////////////////////////////////////////////////////////////
  32. // Plugin mem_admin_parse
  33. // Author: Michael Manfre (http://manfre.net/)
  34. ////////////////////////////////////////////////////////////
  35. if (@txpinterface == 'admin') {
  36. $no_tag = array( 'admin', 'article', 'auth', 'category', 'css', 'diag', 'discuss',
  37. 'file', 'form', 'image', 'import', 'link', 'list', 'log', 'page',
  38. 'plugin', 'prefs', 'preview', 'section', 'tag' );
  39. global $event;
  40. if (!in_array($event, $no_tag))
  41. include_once txpath.'/publish/taghandlers.php';
  42. function admin_parse($text,$use_textile=false)
  43. {
  44. if ($use_textile===true) {
  45. include_once txpath.'/lib/classTextile.php';
  46. $textile = new Textile();
  47. $text = $textile->TextileThis($text);
  48. }
  49. $f = '/<txp:(\S+)\b(.*)(?:(?<!br )(\/))?'.chr(62).'(?(3)|(.+)<\/txp:\1>)/sU';
  50. return preg_replace_callback($f, 'admin_processTags', $text);
  51. }
  52. // -------------------------------------------------------------
  53. function admin_processTags($matches)
  54. {
  55. global $pretext, $production_status, $txptrace, $txptracelevel, $txp_current_tag;
  56. $tag = $matches[1];
  57. $trouble_makers = array(
  58. 'link'
  59. );
  60. if (in_array($tag, $trouble_makers))
  61. {
  62. $tag = 'tpt_'.$tag;
  63. }
  64. $atts = isset($matches[2]) ? splat($matches[2]) : '';
  65. $thing = isset($matches[4]) ? $matches[4] : null;
  66. $old_tag = @$txp_current_tag;
  67. $txp_current_tag = '<txp:'.$tag.
  68. ($atts ? $matches[2] : '').
  69. ($thing ? '>' : '/>');
  70. trace_add($txp_current_tag);
  71. @++$txptracelevel;
  72. if ($production_status == 'debug')
  73. {
  74. maxMemUsage(trim($matches[0]));
  75. }
  76. $out = '';
  77. if (function_exists($tag))
  78. {
  79. $out = $tag($atts, $thing, $matches[0]);
  80. }
  81. // deprecated, remove in crockery
  82. elseif (isset($pretext[$tag]))
  83. {
  84. $out = escape_output($pretext[$tag]);
  85. trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE);
  86. }
  87. else
  88. {
  89. trigger_error(gTxt('unknown_tag'), E_USER_WARNING);
  90. }
  91. @--$txptracelevel;
  92. if (isset($matches[4]))
  93. {
  94. trace_add('</txp:'.$tag.'>');
  95. }
  96. $txp_current_tag = $old_tag;
  97. return $out;
  98. }
  99. } else {
  100. if (function_exists('parse')) {
  101. function admin_parse($text,$use_textile=false) {
  102. return parse($text);
  103. }
  104. }
  105. }
  106. // -------------------------------------------------------------
  107. function mem_gps($atts) {
  108. extract(lAtts(array(
  109. 'name' => '',
  110. 'class' => '',
  111. 'wraptag' => 'div',
  112. 'formatting' => 'none'
  113. ),$atts));
  114. $val = gps($name);
  115. if ($formatting=='textile') {
  116. include_once txpath.'/lib/classTextile.php';
  117. $t = new Textile();
  118. $val = $t->TextileThis($val);
  119. } else if ($formatting=='linebreaks') {
  120. $val = nl2br(trim($val));
  121. } else if ($formatting=='category_title') {
  122. $val = fetch_category_title($val);
  123. } else if ($formatting=='section_title') {
  124. $val = fetch_section_title($val);
  125. }
  126. if (isset($name))
  127. return doTag( $val, $wraptag, $class);
  128. }
  129. // -------------------------------------------------------------
  130. function mem_if_step($atts,$thing) {
  131. global $step;
  132. $cond = $step==$atts['name'];
  133. return admin_parse(EvalElse($thing,$cond));
  134. }
  135. // -------------------------------------------------------------
  136. function mem_if_query($atts,$thing) {
  137. extract(lAtts(array(
  138. 'name' => '',
  139. 'value' => ''
  140. ),$atts));
  141. $name = gps($name);
  142. $cond = $name==$value;
  143. return admin_parse(EvalElse($thing,$cond));
  144. }
  145. # --- END PLUGIN CODE ---
  146. ?>