/addons/DynamicMTML.pack/php/init.dynamicmtml.php

https://github.com/GunioRobot/DynamicMTML · PHP · 191 lines · 185 code · 5 blank · 1 comment · 58 complexity · cfb8ed6e4faa9d89ec4c897fb116229d MD5 · raw file

  1. <?php
  2. global $app;
  3. global $mt;
  4. global $ctx;
  5. global $dmtml_exception;
  6. // init plugins tags
  7. if ( isset( $app ) ) {
  8. $tags_kind = array( 'block', 'function' );
  9. $block_methods = array();
  10. $function_methods = array();
  11. foreach ( $tags_kind as $kind ) {
  12. $kind_tags = $app->stash( "{$kind}_tags" );
  13. if (! $kind_tags || ! is_array( $kind_tags ) ) {
  14. break;
  15. }
  16. foreach ( $kind_tags as $tag => $funcs ) {
  17. foreach ( $funcs as $plugin => $meth ) {
  18. $component = $app->component( $plugin );
  19. if ( $component && is_object( $component ) ) {
  20. $class_name = get_class( $component );
  21. if ( method_exists( $component, $meth ) ) {
  22. if ( $kind == 'block' ) {
  23. if ( preg_match( '/^if/i', $tag ) ) {
  24. $app->ctx->add_conditional_tag( $tag, 'smarty_block_mtif_mtml_block' );
  25. } else {
  26. $app->ctx->add_container_tag( $tag, 'smarty_block_mt_mtml_block' );
  27. }
  28. $block_methods[ $tag ] = array( $plugin, $meth );
  29. } elseif ( $kind == 'function' ) {
  30. $app->ctx->add_tag( $tag, 'smarty_function_mt_mtml_function' );
  31. $function_methods[ $tag ] = array( $plugin, $meth );
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. $app->stash( 'block_methods', $block_methods );
  39. $app->stash( 'function_methods', $function_methods );
  40. $modifiers = $app->stash( 'modifiers' );
  41. if (! $modifiers ) return 1;
  42. if ( $blog = $app->blog ) {
  43. $templates_c = $blog->site_path() . DIRECTORY_SEPARATOR . 'templates_c';
  44. } else {
  45. $templates_c = dirname( $app->root . $_SERVER[ 'PHP_SELF' ] ) . DIRECTORY_SEPARATOR . 'templates_c';
  46. }
  47. $app->stash( 'templates_c', $templates_c );
  48. if ( $templates_c ) $lib = $templates_c . DIRECTORY_SEPARATOR . 'smarty_modifier_dynamicmtml_global.php';
  49. if ( $templates_c && is_writable( $templates_c ) ) {
  50. $modifier_methods = array();
  51. if ( $modifiers && is_array( $modifiers ) ) {
  52. foreach ( $modifiers as $tag => $funcs ) {
  53. if ( is_array( $funcs ) ) {
  54. foreach ( $funcs as $plugin => $modifier ) {
  55. $component = $app->component( $plugin );
  56. if ( $component && is_object( $component ) ) {
  57. $class_name = get_class( $component );
  58. if ( method_exists( $component, $modifier ) ) {
  59. if ( (! function_exists( "smarty_modifier_{$modifier}" ) ) &&
  60. (! function_exists( "smarty_modifier_{$plugin}_{$modifier}" ) ) ) {
  61. $modifier = "smarty_modifier_{$plugin}_{$modifier}";
  62. $app->ctx->add_global_filter( $tag, $modifier );
  63. $modifier_methods[ $modifier ] = $tag;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. if ( $modifier_methods ) {
  72. if (! file_exists( $lib ) || $ctx->force_compile || $app->config( 'DynamicForceCompile' ) ) {
  73. $code = "<?php\n";
  74. $func = '__FUNCTION__';
  75. foreach ( $modifier_methods as $meth => $tag ) {
  76. $code .= " function {$meth} ( \$text, \$arg ) {\n";
  77. $code .= " return smarty_modifier_mt_mtml_modifier( {$func}, \$text, \$arg );\n";
  78. $code .= " }\n";
  79. }
  80. $code .= "?>";
  81. if ( $app->content_is_updated( $lib, $code ) ) {
  82. $app->put_data( $code, $lib );
  83. }
  84. }
  85. $app->stash( 'modifier_methods', $modifier_methods );
  86. }
  87. }
  88. if ( $lib && file_exists( $lib ) ) {
  89. require_once( $lib );
  90. }
  91. return 1;
  92. }
  93. $mt_config = $mt->cfg_file;
  94. $static_path = $mt->config[ 'staticfilepath' ];
  95. if (! preg_match( "/DIRECTORY_SEPARATOR$/", $static_path ) ) {
  96. $static_path .= DIRECTORY_SEPARATOR;
  97. }
  98. $mt_dir = dirname( $mt_config );
  99. $blog_id = $mt->blog_id;
  100. $blog = $mt->db()->fetch_blog( $blog_id );
  101. $size_limit = 524288;
  102. $server_cache = $blog->search_cache_expiration;
  103. $indexes = $blog->index_files;
  104. $excludes = $blog->exclude_extension;
  105. if (! isset( $server_cache ) ) $server_cache = 7200;
  106. if (! $indexes ) $indexes = 'index.html,index.mtml';
  107. if (! $excludes ) $excludes ='php,cgi,fcgi';
  108. $plugin_path = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
  109. $powercms_files = $mt->config[ 'PowerCMSFilesDir' ];
  110. if (! $powercms_files ) {
  111. $powercms_files = $mt_dir . DIRECTORY_SEPARATOR . 'powercms_files' . DIRECTORY_SEPARATOR;
  112. } else {
  113. if (! preg_match( "/DIRECTORY_SEPARATOR$/", $powercms_files ) ) {
  114. $powercms_files .= DIRECTORY_SEPARATOR;
  115. }
  116. }
  117. $cache_dir = $powercms_files . 'cache';
  118. $extension = $blog->file_extension;
  119. $use_cache = $blog->search_cache;
  120. $conditional = $blog->search_conditional;
  121. $dynamic_caching = $blog->dynamic_cache;
  122. $dynamic_conditional = $blog->dynamic_conditional;
  123. $require_login = NULL;
  124. if ( $blog->has_column( 'is_members' ) ) {
  125. if ( $blog->is_members ) {
  126. $require_login = 1;
  127. }
  128. }
  129. if ( $blog->dynamic_mtml ) {
  130. $dmtml_exception = 1;
  131. }
  132. require_once ( $plugin_path . 'dynamicmtml.run.php' );
  133. return 1;
  134. function smarty_block_mt_mtml_block ( $args, $content, &$ctx, &$repeat ) {
  135. return smarty_dynamic_tag_dynamicmtml( 'block', $args, $content, $ctx, $repeat );
  136. }
  137. function smarty_block_mtif_mtml_block ( $args, $content, &$ctx, &$repeat ) {
  138. return smarty_dynamic_tag_dynamicmtml( 'block', $args, $content, $ctx, $repeat );
  139. }
  140. function smarty_function_mt_mtml_function ( $args, &$ctx ) {
  141. return smarty_dynamic_tag_dynamicmtml( 'function', $args, $ctx );
  142. }
  143. function smarty_modifier_mt_mtml_modifier ( $function, &$text, &$arg ) {
  144. global $mt;
  145. $ctx = &$mt->context();
  146. $app = $ctx->stash( 'bootstrapper' );
  147. $target_tags = $app->stash( 'modifier_methods' );
  148. if ( $target_tags && $target_tags[ $function ] ) {
  149. $path = explode( '_', $function );
  150. $plugin = $path[2];
  151. $meth = preg_replace( "/^smarty_modifier_{$plugin}_/", '', $function );
  152. $component = $app->component( $plugin );
  153. if ( $component && $meth && method_exists( $component, $meth ) ) {
  154. return $component->$meth( $text, $arg );
  155. }
  156. }
  157. }
  158. function smarty_dynamic_tag_dynamicmtml ( $kind, &$arg1, &$arg2, &$arg3 = NULL, &$arg4 = NULL ) {
  159. $args = NULL;
  160. $content = NULL;
  161. $ctx = NULL;
  162. $repeat = NULL;
  163. if ( $kind == 'block' ) {
  164. $ctx = $arg3;
  165. } elseif ( $kind == 'function' ) {
  166. $ctx = $arg2;
  167. }
  168. $app = $ctx->stash( 'bootstrapper' );
  169. $this_tag = $ctx->this_tag();
  170. if (! $this_tag ) return;
  171. $this_tag = preg_replace( '/^mt/i', '', $this_tag );
  172. $target_tags = $app->stash( "{$kind}_methods" );
  173. if ( $target_tags && $target_tags[ $this_tag ] ) {
  174. $plugin = $target_tags[ $this_tag ][0];
  175. $meth = $target_tags[ $this_tag ][1];
  176. $component = $app->component( $plugin );
  177. if ( $component && $meth && method_exists( $component, $meth ) ) {
  178. if ( $kind == 'block' ) {
  179. return $component->$meth( $arg1, $arg2, $arg3, $arg4 );
  180. } elseif ( $kind == 'function' ) {
  181. return $component->$meth( $arg1, $arg2 );
  182. }
  183. }
  184. }
  185. }
  186. ?>