// smd_style by Stef Dawson function smd_style($atts, $thing) { global $pretext, $thisarticle, $prefs, $variable; // Plugin options extract(lAtts(array( 'sheets' => '', 'form' => '', 'use_default' => '0', // 0=no; 1=yes as primary sheet 'promote_recent' => '1', // 0=retain order; 1=promote used sheets but honour core sheets; 2=promote at all costs 'skip' => 'auto', 'show_empty' => '0', 'real_sheets' => '0', // 0=no; 1=yes 'sheets_dir' => @$prefs['rvm_css_dir'], 'delim' => ',', 'paramdelim' => ':', 'debug' => '0', ), $atts)); $out = array(); $styles = do_list($sheets, $delim); $expstyles = array(); foreach ($styles as $idx => $opt) { if (strpos($opt, "?") === 0) { $opt = substr(strtolower($opt), 1); $tmpa = array(); if (isset($pretext[$opt]) && $pretext[$opt] != "") { $tmpa = do_list($pretext[$opt], $delim); $expstyles = array_merge($expstyles, $tmpa); } else if (isset($thisarticle[$opt]) && $thisarticle[$opt] != "") { $tmpa = do_list($thisarticle[$opt], $delim); $expstyles = array_merge($expstyles, $tmpa); } else if (isset($variable[$opt]) && $variable[$opt] != "") { $tmpa = do_list($variable[$opt], $delim); $expstyles = array_merge($expstyles, $tmpa); } else if (isset($_GET[$opt]) && $_GET[$opt] != "") { $tmpa = do_list(gps($opt), $delim); $expstyles = array_merge($expstyles, $tmpa); } else if ($show_empty) { $expstyles[] = $opt; } } else { $expstyles[] = $opt; } } $styles = $expstyles; $skip = ($skip=="auto") ? $use_default : $skip; if ($use_default > 0) { $default = safe_row('css', 'txp_section', "name = '".doSlash($pretext['s'])."'", $debug); array_unshift($styles, $default['css']); } // If a previous style has been chosen, move it to the front of the list (if requested). // This forces good browsers to 'flash' less when changing pages $cookiestyle = cs("smd_style"); if ($promote_recent && $cookiestyle) { $rejig = array(); foreach ($styles as $idx => $style) { if (($idx < $skip) && $promote_recent == 1) { $rejig[] = $style; continue; } if (strpos($style, $cookiestyle) !== false) { $rejig[] = $style; break; } } $styles = array_merge($rejig, $styles); $styles = array_unique($styles); } if ($debug) { echo "++ STYLES ++"; dmp($styles); } $stylecnt = 1; $num_styles = count($styles); foreach ($styles as $style) { $styleopts = do_list($style, $paramdelim); $name = (count($styleopts) >= 1) ? $styleopts[0] : ''; $title = (count($styleopts) >= 2) ? $styleopts[1] : $name; $media = (count($styleopts) >= 3) ? $styleopts[2] : 'screen'; $rel = (($stylecnt > $skip) ? "alternate " : '') . "stylesheet"; $url = hu. (($real_sheets && $sheets_dir) ? $sheets_dir . '/' .strtolower(sanitizeForUrl($name)). '.css' : 'textpattern/css.php?n='.$name); // Make up the replacement array $replacements = array( '{smd_style_name}' => $name, '{smd_style_url}' => $url, '{smd_style_media}' => $media, '{smd_style_rel}' => $rel, '{smd_style_title}' => $title, '{smd_style_counter}' => $stylecnt, '{smd_style_total}' => $num_styles, ); if ($debug) { echo "++ REPLACEMENTS ++"; dmp($replacements); } $out[] = ($thing) ? parse(strtr($thing, $replacements)) : (($form) ? strtr(parse_form($form), $replacements) : css(array( "format" => "link", "media" => $media, "n" => $name, "rel" => $rel, "title" => $title, ))); $stylecnt++; } return join("\n", $out); } // ------------------------ // Javascript style switcher function smd_styleswitch($atts, $thing) { // Plugin options extract(lAtts(array( 'wraptag' => 'ul', 'class' => 'smd_switcher', 'break' => 'li', 'break_is_tag' => '1', 'linkclass' => 'smd_styleswitch', 'activeclass' => 'smd_currstyle', 'alt_only' => '0', // 0=No; 1=Yes, only show alternate stylesheets 'sort' => '1', // 0=No; 1=Yes 'case_sensitive' => '0', 'expiry' => '7', // In days 'debug' => '0', ), $atts)); // Make sure there are always jQuery elements to swing off, thus avoiding js errors $class = (trim($class)=="") ? "smd_switcher" : $class; $linkclass = (trim($linkclass)=="") ? 'smd_styleswitch' : $linkclass; $stylematch = (($alt_only) ? 'alternate ' : '').'style'; $out = array(); if ($wraptag) { $out[] = '<'.$wraptag.' class="'.$class.'">'; } $out[] = << EOJS; return join("\n", $out); }