soo_required_files Page 2 of 2

soo_required_files source code

  1 : @require_plugin('soo_plugin_pref');     // optional
  2 : 
  3 : // Plugin init not needed on admin side
  4 : if ( @txpinterface == 'public' )
  5 : {
  6 :     global $soo_required_files;
  7 :     $soo_required_files function_exists('soo_plugin_pref_vals') ?
  8 :         array_merge(soo_required_files_defaults(true), soo_plugin_pref_vals('soo_required_files'))
  9 :         : soo_required_files_defaults(true);
 10 : }
 11 : elseif ( @txpinterface == 'admin' )
 12 : {
 13 :     add_privs('plugin_prefs.soo_required_files','1,2');
 14 :     add_privs('plugin_lifecycle.soo_required_files','1,2');
 15 :     register_callback('soo_required_files_prefs''plugin_prefs.soo_required_files');
 16 :     register_callback('soo_required_files_prefs''plugin_lifecycle.soo_required_files');
 17 : }
 18 : 
 19 : function soo_required_files_prefs$event$step ) {
 20 :     if ( function_exists('soo_plugin_pref') )
 21 :         return soo_plugin_pref($event$stepsoo_required_files_defaults());
 22 :     if ( substr($event012) == 'plugin_prefs' ) {
 23 :         $plugin substr($event13);
 24 :         $message '<p><br /><strong>' gTxt('edit') . " $plugin " .
 25 :             gTxt('edit_preferences') . ':</strong><br />' gTxt('install_plugin') .
 26 :             ' <a href="http://ipsedixit.net/txp/92/soo_plugin_pref">' .
 27 :             'soo_plugin_pref</a></p>';
 28 :         pagetop(gTxt('edit_preferences') . " &#8250; $plugin"$message);
 29 :     }
 30 : }
 31 : 
 32 : function soo_required_files_defaults$vals_only false ) {
 33 :     $defaults = array(
 34 :         'custom_field'      =>  array(
 35 :             'val'   =>  'Requires',
 36 :             'html'  =>  'text_input',
 37 :             'text'  =>  'Custom field name',
 38 :         ),
 39 :         'css_dir'   =>  array(
 40 :             'val'   =>  'css/',
 41 :             'html'  =>  'text_input',
 42 :             'text'  =>  'Default css dir (relative to base URL, with closing slash)',
 43 :         ),
 44 :         'js_dir'    =>  array(
 45 :             'val'   =>  'js/',
 46 :             'html'  =>  'text_input',
 47 :             'text'  =>  'Default js dir (relative to base URL, with closing slash)',
 48 :         ),
 49 :         'form_prefix'   =>  array(
 50 :             'val'   =>  'require_',
 51 :             'html'  =>  'text_input',
 52 :             'text'  =>  'Optional prefix for form names',
 53 :         ),
 54 :         'per_page'  =>  array(
 55 :             'val'   =>  0,
 56 :             'html'  =>  'yesnoradio',
 57 :             'text'  =>  'Load {page}.css and {page}.js?',
 58 :         ),
 59 :         'per_section'   =>  array(
 60 :             'val'   =>  0,
 61 :             'html'  =>  'yesnoradio',
 62 :             'text'  =>  'Load {section}.css and {section}.js?',
 63 :         ),
 64 :     );
 65 :     if ( $vals_only )
 66 :         foreach ( $defaults as $name => $arr )
 67 :             $defaults[$name] = $arr['val'];
 68 :     return $defaults;
 69 : }
 70 : 
 71 : function soo_required_files$atts$thing '' ) {
 72 : 
 73 :     global $soo_required_files$page$s$id;
 74 :     extract($soo_required_files);
 75 :     $required do_list(parse($thing));
 76 : 
 77 :     // tag atts override defaults/prefs
 78 :     foreach ( $atts as $k => $v )
 79 :         if ( array_key_exists($k$soo_required_files) )
 80 :             $$k $v;
 81 : 
 82 :     if ( $per_page )
 83 :         $required array_merge($required_soo_required_files_add($page));
 84 : 
 85 :     if ( $per_section )
 86 :         $required array_merge($required_soo_required_files_add($s));
 87 : 
 88 :     // if individual article, get custom field contents
 89 :     if ( $id and $custom_field )
 90 :         $required array_merge($requireddo_list(custom_field(array(
 91 :             'name'      =>  $custom_field,
 92 :             'escape'    =>  'html',
 93 :             'default'   =>  '',
 94 :         ))));
 95 : 
 96 :     $required array_unique($required);
 97 : 
 98 :     foreach ( $required as $req ) {
 99 :         if ( substr(strtolower($req), -4) === '.css' )
100 :             $out[] = '<link rel="stylesheet" type="text/css" href="' .
101 :             hu $css_dir $req '" />';
102 :         elseif ( substr(strtolower($req), -3) === '.js' )
103 :             $out[] = '<script type="text/javascript" src="' .
104 :             hu $js_dir $req '"></script>';
105 :         elseif ( $req )
106 :             $out[] = parse_form($form_prefix $req);
107 :     }
108 : 
109 :     return isset($out) ? implode("\n"$out) : '';
110 : }
111 : 
112 : function _soo_required_files_add$name ) {
113 :     global $soo_required_files;
114 :     extract($soo_required_files);
115 :     $path_root preg_replace('/index.php/'''$_SERVER['SCRIPT_FILENAME']);
116 :     if ( file_exists($path_root $css_dir $name '.css') )
117 :         $out[] = $name '.css';
118 :     if ( file_exists($path_root $js_dir $name '.js') )
119 :         $out[] = $name '.js';
120 :     return isset($out) ? $out : array();
121 : }