/**
* Returns a <fieldset> for editing post editor styles
*
* @param	string	Item title
* @param	string	Item varname
*
* @return	string
*/
function construct_posteditor_style_code($title, $varname)
{
    global $template_cache, $vbphrase, $stylevar, $vbulletin;
    $template = $template_cache['template']["{$varname}"];
    $color = fetch_inherited_color($template['styleid'], $vbulletin->GPC['dostyleid']);
    $revertcode = construct_revert_code($template['styleid'], 'template', $varname);
    $item = fetch_posteditor_styles($template['template_un']);
    $out = "\n\t<fieldset title=\"{$title}\">\n\t\t<legend>{$title}</legend>\n\t\t<div class=\"smallfont\" style=\"padding: 2px\">\n\t\t<table cellpadding=\"0\" cellspacing=\"2\" border=\"0\" width=\"100%\">\n\t\t<col width=\"50\"></col>\n\t\t<col></col>\n\t\t<col align=\"{$stylevar['right']}\"></col>\n\t\t<tr>\n\t\t\t<td rowspan=\"5\"><img src=\"control_examples/" . substr($varname, 14) . ".gif\" alt=\"\" title=\"{$title}\" /></td>\n\t\t\t" . construct_color_row($vbphrase['background'], "commontemplate[{$varname}][background]", htmlspecialchars_uni($item['background']), $color, 12, false) . "\n\t\t</tr>\n\t\t<tr>\n\t\t\t" . construct_color_row($vbphrase['font_color'], "commontemplate[{$varname}][color]", htmlspecialchars_uni($item['color']), $color, 12, false) . "\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>{$vbphrase['padding']}</td>\n\t\t\t<td><input type=\"text\" class=\"{$color}\" name=\"commontemplate[{$varname}][padding]\" size=\"20\" value=\"" . htmlspecialchars_uni($item['padding']) . "\" tabindex=\"1\" dir=\"ltr\" /></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>{$vbphrase['border']}</td>\n\t\t\t<td><input type=\"text\" class=\"{$color}\" name=\"commontemplate[{$varname}][border]\" size=\"20\" value=\"" . htmlspecialchars_uni($item['border']) . "\" tabindex=\"1\" dir=\"ltr\" /></td>\n\t\t</tr>";
    if ($revertcode['info']) {
        $out .= "\n\t\t<tr>\n\t\t\t<td>{$revertcode['info']}</td>\n\t\t\t<td>{$revertcode['revertcode']}</td>\n\t\t</tr>";
    } else {
        $out .= "\n\t\t<tr>\n\t\t\t<td colspan=\"2\">&nbsp;</td>\n\t\t</tr>";
    }
    $out .= "\n\t\t</table>\n\t\t</div>\n\t</fieldset>";
    return $out;
}
Example #2
0
 /**
  *	Internal function to handle the recursion for buildStyle.
  *
  */
 private function buildStyleInternal($styleid, $title = '', $actions = array(), $parentlist = '', $resetcache = false)
 {
     $assertor = vB::getDbAssertor();
     require_once DIR . '/includes/adminfunctions.php';
     require_once DIR . '/includes/adminfunctions_template.php';
     static $csscache = array();
     if (($actions['doreplacements'] or $actions['docss'] or $actions['dostylevars']) and vB::getDatastore()->getOption('storecssasfile')) {
         $actions['docss'] = true;
         $actions['doreplacements'] = true;
     }
     if ($styleid != -1) {
         unset($this->stylesById[$styleid]);
         // build the templateid cache
         if (!$parentlist) {
             $parentlist = $this->fetchTemplateParentlist($styleid);
         }
         $templatelist = $this->buildTemplateIdCache($styleid, 1, $parentlist);
         $styleupdate = array();
         $styleupdate['templatelist'] = $templatelist;
         // cache special templates
         if ($actions['docss'] or $actions['dostylevars'] or $actions['doreplacements'] or $actions['doposteditor']) {
             // get special templates for this style
             $template_cache = array();
             $templateids = unserialize($templatelist);
             $specials = vB_Api::instanceInternal('template')->fetchSpecialTemplates();
             if ($templateids) {
                 $templates = vB::getDbAssertor()->assertQuery('vBForum:fetchtemplatewithspecial', array('templateids' => $templateids, 'specialtemplates' => $specials));
                 foreach ($templates as $template) {
                     $template_cache["{$template['templatetype']}"]["{$template['title']}"] = $template;
                 }
             }
         }
         // style vars
         if ($actions['dostylevars']) {
             if ($template_cache['stylevar']) {
                 // rebuild the stylevars field for this style
                 $stylevars = array();
                 foreach ($template_cache['stylevar'] as $template) {
                     $stylevars["{$template['title']}"] = $template['template'];
                 }
             }
             // new stylevars
             static $master_stylevar_cache = null;
             if ($resetcache) {
                 $resetcachedone = true;
                 $master_stylevar_cache = null;
             }
             if ($master_stylevar_cache === null) {
                 $master_stylevar_cache = array();
                 $master_stylevars = vB::getDbAssertor()->assertQuery('vBForum:getDefaultStyleVars', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED));
                 foreach ($master_stylevars as $master_stylevar) {
                     $tmp = unserialize($master_stylevar['value']);
                     if (!is_array($tmp)) {
                         $tmp = array('value' => $tmp);
                     }
                     $master_stylevar_cache[$master_stylevar['stylevarid']] = $tmp;
                     $master_stylevar_cache[$master_stylevar['stylevarid']]['datatype'] = $master_stylevar['datatype'];
                 }
             }
             $newstylevars = $master_stylevar_cache;
             if (substr(trim($parentlist), 0, -3) != '') {
                 $data = array('stylelist' => explode(',', substr(trim($parentlist), 0, -3)), 'parentlist' => $parentlist);
                 $new_stylevars = vB::getDbAssertor()->getRows('vBForum:getStylesFromList', $data);
                 foreach ($new_stylevars as $new_stylevar) {
                     ob_start();
                     $newstylevars[$new_stylevar['stylevarid']] = unserialize($new_stylevar['value']);
                     if (ob_get_clean() or !is_array($newstylevars[$new_stylevar['stylevarid']])) {
                         continue;
                     }
                     $newstylevars[$new_stylevar['stylevarid']]['datatype'] = $master_stylevar_cache[$new_stylevar['stylevarid']]['datatype'];
                 }
             }
             $styleupdate['newstylevars'] = serialize($newstylevars);
         }
         // replacements
         if ($actions['doreplacements']) {
             // rebuild the replacements field for this style
             $replacements = array();
             if (is_array($template_cache['replacement'])) {
                 foreach ($template_cache['replacement'] as $template) {
                     // set the key to be a case-insentitive preg find string
                     $replacementkey = '#' . preg_quote($template['title'], '#') . '#si';
                     $replacements["{$replacementkey}"] = $template['template'];
                 }
                 $styleupdate['replacements'] = serialize($replacements);
             } else {
                 $styleupdate['replacements'] = "''";
             }
         }
         // css -- old style css
         if ($actions['docss'] and $template_cache['css']) {
             // build a quick cache with the ~old~ contents of the css fields from the style table
             if (empty($csscache)) {
                 $fetchstyles = vB::getDbAssertor()->assertQuery('vBForum:style', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT));
                 foreach ($fetchstyles as $fetchstyle) {
                     $fetchstyle['css'] .= "\n";
                     $csscache["{$fetchstyle['styleid']}"] = $fetchstyle['css'];
                 }
             }
             // rebuild the css field for this style
             $css = array();
             foreach ($template_cache['css'] as $template) {
                 $css["{$template['title']}"] = unserialize($template['template']);
             }
             // build the CSS contents
             $csscolors = array();
             $css = construct_css($css, $styleid, $title, $csscolors);
             // attempt to delete the old css file if it exists
             delete_css_file($styleid, $csscache["{$styleid}"]);
             $adblock_is_evil = str_replace('ad', 'be', substr(md5(microtime()), 8, 8));
             $cssfilename = DIR . vB_Api::instanceInternal('style')->fetchCssLocation() . '/style-' . $adblock_is_evil . '-' . str_pad($styleid, 5, '0', STR_PAD_LEFT) . '.css';
             // if we are going to store CSS as files, run replacement variable substitution on the file to be saved
             if (vB::getDatastore()->getOption('storecssasfile')) {
                 $css = process_replacement_vars($css, array('styleid' => $styleid, 'replacements' => serialize($replacements)));
                 $css = preg_replace_callback('#(?<=[^a-z0-9-]|^)url\\((\'|"|)(.*)\\1\\)#iU', function ($matches) {
                     return rewrite_css_file_url($matches[2], $matches[1]);
                 }, $css);
                 if (write_css_file($cssfilename, $css)) {
                     $css = "@import url(\"{$cssfilename}\");";
                 }
             }
         }
         // post editor styles
         if ($actions['doposteditor'] and $template_cache['template']) {
             $editorstyles = array();
             if (!empty($template_cache['template'])) {
                 foreach ($template_cache['template'] as $template) {
                     if (substr($template['title'], 0, 13) == 'editor_styles') {
                         $title = 'pi' . substr($template['title'], 13);
                         $item = fetch_posteditor_styles($template['template']);
                         $editorstyles["{$title}"] = array($item['background'], $item['color'], $item['padding'], $item['border']);
                     }
                 }
             }
         }
         // do the style update query
         if (!empty($styleupdate)) {
             $styleupdate['styleid'] = $styleid;
             $styleupdate[vB_dB_Query::TYPE_KEY] = vB_dB_Query::QUERY_UPDATE;
             vB::getDbAssertor()->assertQuery('vBForum:style', $styleupdate);
         }
         //write out the new css -- do this *after* we update the style record
         if (vB::getDatastore()->getOption('storecssasfile')) {
             if (!write_style_css_directory($styleid, $parentlist, 'ltr')) {
                 return fetch_error("rebuild_failed_to_write_css");
             } else {
                 if (!write_style_css_directory($styleid, $parentlist, 'rtl')) {
                     return fetch_error("rebuild_failed_to_write_css");
                 }
             }
         }
     }
     $childsets = vB::getDbAssertor()->getRows('style', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array('parentid' => $styleid)));
     if (count($childsets)) {
         foreach ($childsets as $childset) {
             if ($error = $this->buildStyleInternal($childset['styleid'], $childset['title'], $actions, $childset['parentlist'], false)) {
                 return $error;
             }
         }
     }
     //We want to force a fastDS rebuild, but we can't just call rebuild. There may be dual web servers,
     // and calling rebuild only rebuilds one of them.
     $options = vB::getDatastore()->getValue('miscoptions');
     $options['tmtdate'] = vB::getRequest()->getTimeNow();
     vB::getDatastore()->build('miscoptions', serialize($options), 1);
 }