Example #1
0
/**
 * Update to v1.4
 * @since 1.4
 */
function qa_update_14()
{
    $version = get_option('qa_installed_version');
    if ($version == QA_VERSION) {
        return;
    }
    // Just update version number if theme is already supported
    if (strpos(qa_supported_themes(), get_template()) !== false) {
        $supported_theme = true;
    } else {
        $supported_theme = false;
    }
    if (!($options = get_option(QA_OPTIONS_NAME))) {
        $options = array();
    }
    $changed = false;
    if (!isset($options["general_settings"]["page_layout"])) {
        if (isset($options["general_settings"]["full_width"]) && $options["general_settings"]["full_width"]) {
            $options["general_settings"]["page_layout"] = 'content';
        } else {
            $options["general_settings"]["page_layout"] = 'content-sidebar';
        }
        unset($options["general_settings"]["full_width"]);
        $changed = true;
    }
    if (!isset($options["general_settings"]["page_width"]) && !$supported_theme) {
        $options["general_settings"]["page_width"] = 1000;
        $changed = true;
    }
    if (!isset($options["general_settings"]["content_width"]) && !$supported_theme) {
        $options["general_settings"]["content_width"] = 600;
        $changed = true;
    }
    if (!isset($options["general_settings"]["sidebar_width"]) && !$supported_theme) {
        $options["general_settings"]["sidebar_width"] = 300;
        $changed = true;
    }
    if (!isset($options["general_settings"]["content_alignment"])) {
        $options["general_settings"]["content_alignment"] = 'center';
        $changed = true;
    }
    if ($changed || empty($options)) {
        update_option(QA_OPTIONS_NAME, $options);
        update_option('qa_installed_version', QA_VERSION);
    }
}
" id="qa_display">
	<h3 class='hndle'><span><?php 
_e('Theme Adaptation Settings', QA_TEXTDOMAIN);
?>
</span></h3>
	
	
	<div class="inside">

		<table class="form-table">
		
			<tr>
			<td colspan="2">
			<span class="description">
			<?php 
printf(__('Q&A supports these themes as default: <b>%s</b>. For the rest of themes, the look of the Q&A pages should be adapted to your theme. This can be done by editing the templates or by adjusting the below settings. If you are not having any display issues you can leave them as they are.', QA_TEXTDOMAIN), qa_supported_themes());
?>
			</span>
			</td>
			</tr>
			
			<tr>
				<th>
					<label for="page_layout"><?php 
_e('Page Layout', QA_TEXTDOMAIN);
?>
</label>
				</th>
				<td>
					<?php 
qa_settings_field_layout();
Example #3
0
 /**
  * Estimate css rules
  * @since 1.4
  * @return json_encoded result
  */
 function estimate()
 {
     if (!current_user_can('manage_options')) {
         die(json_encode(array('error' => esc_js(__('You are not authorised to do this', QA_TEXTDOMAIN)))));
     }
     $c_theme = get_template();
     // Current theme
     if (strpos(qa_supported_themes(), $c_theme) !== false) {
         die(json_encode(array('error' => sprintf(__('Your current theme %s is already supported by Q&A. No additional css rules are necessary.', QA_TEXTDOMAIN), $c_theme))));
     }
     $css = '';
     $changed = false;
     global $qa_general_settings;
     if (!isset($_POST['page_layout']) || !isset($_POST['page_width']) || !isset($_POST['content_width']) || !isset($_POST['sidebar_width']) || !isset($_POST['content_alignment'])) {
         die(json_encode(array('error' => esc_js(__('At least One of the variables is missing', QA_TEXTDOMAIN)))));
     }
     $qa_general_settings['page_layout'] = $page_layout = $_POST['page_layout'];
     $qa_general_settings['page_width'] = $page_width = $_POST['page_width'];
     $qa_general_settings['content_width'] = $content_width = $_POST['content_width'];
     $qa_general_settings['sidebar_width'] = $sidebar_width = $_POST['sidebar_width'];
     $qa_general_settings['content_alignment'] = $content_alignment = $_POST['content_alignment'];
     // Post variables are right, so save them.
     update_option(QA_OPTIONS_NAME, $qa_general_settings);
     $right_margin = $left_margin = 0;
     switch ($page_layout) {
         case 'content-sidebar':
             switch ($content_alignment) {
                 case 'center':
                     $right_margin = $left_margin = (int) (($page_width - $content_width - $sidebar_width) / 2);
                     break;
                 case 'left':
                     $right_margin = $page_width - $content_width - $sidebar_width;
                     break;
                 case 'right':
                     $left_margin = $page_width - $content_width - $sidebar_width;
                     break;
                 default:
                     $right_margin = $left_margin = (int) (($page_width - $content_width - $sidebar_width) / 2);
                     break;
             }
             $css .= '#qa-page-wrapper{float:left !important; width:100% !important;margin-right:-' . ($sidebar_width + 1) . 'px !important;} ';
             $css .= '#qa-content-wrapper{margin:0 ' . $right_margin . 'px 0 ' . $left_margin . 'px !important;}';
             break;
         case 'sidebar-content':
             switch ($content_alignment) {
                 case 'center':
                     $left_margin = (int) (($page_width - $sidebar_width - $content_width) / 2) + $sidebar_width;
                     break;
                 case 'left':
                     $left_margin = $sidebar_width;
                     break;
                 case 'right':
                     $left_margin = $page_width - $content_width;
                     break;
                 default:
                     $left_margin = (int) (($page_width - $sidebar_width - $content_width) / 2) + $sidebar_width;
                     break;
             }
             $css .= '#qa-page-wrapper{float:right !important; width:100% !important;margin-left:-' . ($sidebar_width + 1) . 'px !important;} ';
             $css .= '#qa-content-wrapper{margin:0 ' . $right_margin . 'px 0 ' . $left_margin . 'px !important;}';
             break;
         case 'content':
             switch ($content_alignment) {
                 case 'center':
                     $right_margin = $left_margin = (int) (($page_width - $content_width) / 2);
                     break;
                 case 'left':
                     $right_margin = $page_width - $content_width;
                     break;
                 case 'right':
                     $left_margin = $page_width - $content_width;
                     break;
                 default:
                     $right_margin = $left_margin = (int) (($page_width - $content_width) / 2);
                     break;
             }
             $css .= '#qa-page-wrapper{width:100% !important;} ';
             $css .= '#qa-content-wrapper{margin:0 ' . $right_margin . 'px 0 ' . $left_margin . 'px !important;}';
             break;
         default:
             die(json_encode(array('error' => esc_js(__('Page layout is not selected', QA_TEXTDOMAIN)))));
             break;
     }
     if ($css) {
         $qa_general_settings['additional_css'] = $css;
         if (update_option(QA_OPTIONS_NAME, $qa_general_settings)) {
             die(json_encode(array('css' => $css)));
         } else {
             die(json_encode(array('error' => esc_js(__('Nothing has been changed. Please double check your settings.', QA_TEXTDOMAIN)))));
         }
     }
     // Something went wrong
     die(json_encode(array('error' => esc_js(__('Page layout is not selected', QA_TEXTDOMAIN)))));
 }