soo_required_files Page 2 of 2

soo_required_files source code

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