Advertisement
alchymyth

quote source file qs-admin.php

Jan 26th, 2020
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.64 KB | None | 0 0
  1. <?php
  2. add_action('admin_menu', 'qs_config_page');
  3.  
  4. function qs_admin_init() {
  5.     global $wp_version;
  6.     if ( !function_exists('is_multisite') && version_compare( $wp_version, '3.0', '<' ) ) {
  7.         function qs_version_warning() {
  8.             echo "
  9.            <div id='qs-warning' class='updated fade'><p><strong>".sprintf(__('Quote Source %s requires WordPress 3.0 or higher.'), QUOTE_SOURCE_VERSION) ."</strong> ".sprintf(__('Please <a href="%s">upgrade WordPress</a> to a current version.'), 'http://codex.wordpress.org/Upgrading_WordPress'). "</p></div>
  10.            ";
  11.         }
  12.         add_action('admin_notices', 'qs_version_warning');
  13.         return;
  14.     }
  15. }
  16. add_action('admin_init', 'qs_admin_init');
  17.  
  18. function qs_config_page() {
  19.     if (function_exists('add_submenu_page')) {
  20.         add_submenu_page('plugins.php', __('Quote Source'), __('Quote Source'), 'manage_options', 'qs-config', 'qs_config');
  21.     }
  22. }
  23.  
  24. function qs_handle_bool($val, $default='true') {
  25.     if($val == null || $val == '') {
  26.         return '';
  27.     }
  28.     if(is_bool($val)) {
  29.         return (string)$val;
  30.     }
  31.     switch (strtolower($val)) {
  32.         case '1':
  33.         case 'on':
  34.         case 'true':
  35.             return 'true';
  36.             break;
  37.         case '0':
  38.         case 'off':
  39.         case 'false':
  40.             return 'false';
  41.             break;
  42.         default:
  43.             return $default;
  44.     }
  45. }
  46.  
  47. function qs_config() {
  48.         $options = array();
  49.         if(!get_option('qs_mode_single_post')) {
  50.             add_option('qs_mode_single_post', 'true');
  51.             $options['qs_mode_single_post'] = 'true';
  52.         }
  53.        
  54.         if(!get_option('qs_mode_category')) {
  55.             add_option('qs_mode_category', 'false');
  56.             $options['qs_mode_category'] = 'false';
  57.         }
  58.        
  59.         if(!get_option('qs_mode_page')) {
  60.             add_option('qs_mode_page', 'false');
  61.             $options['qs_mode_page'] = 'false';
  62.         }
  63.        
  64.         if(!get_option('qs_mode_summary')) {
  65.             add_option('qs_mode_summary', 'false');
  66.             $options['qs_mode_summary'] = 'false';
  67.         }
  68.        
  69.         if(!get_option('qs_text_color')) {
  70.             add_option('qs_text_color', '000000');
  71.             $options['qs_text_color'] = '000000';
  72.         }
  73.        
  74.         if(!get_option('qs_layout')) {
  75.             add_option('qs_layout', '1');
  76.             $options['qs_layout'] = '1';
  77.         }
  78.  
  79.     if(isset($_POST['submit'])) {
  80.         if(function_exists('current_user_can') && !current_user_can('manage_options')) {
  81.             die('You have no rights to access');
  82.         }
  83.         // =========================================
  84.         $hex_color = $_POST['txt_text_color'];
  85.         if(preg_match('/^[a-f0-9]{6}$/i', $hex_color)) {
  86.             update_option('qs_text_color', $hex_color);
  87.         } else {
  88.             update_option('qs_text_color', 'FFFFFF');
  89.         }
  90.         // =========================================
  91.         $qs_layout = (int)$_POST['radio_layout'];
  92.         if($qs_layout <= 0 || $qs_layout > 3) {
  93.             $qs_layout = 1;
  94.         }
  95.         update_option('qs_layout', $qs_layout);
  96.         // =========================================
  97.        
  98.         if( isset( $_POST['qs_mode_single_post'] ) ) $qs_mode_single_post = $_POST['qs_mode_single_post'];
  99.         if( isset( $_POST['qs_mode_category'] ) ) $qs_mode_category = $_POST['qs_mode_category'];      
  100.         if( isset( $_POST['qs_mode_page'] ) ) $qs_mode_page = $_POST['qs_mode_page'];
  101.         if( isset( $_POST['qs_mode_summary'] ) ) $qs_mode_summary = $_POST['qs_mode_summary'];
  102.        
  103.         update_option('qs_mode_single_post' , isset( $_POST['qs_mode_single_post'] )$_POST['qs_mode_single_post'] : 'false');
  104.         update_option('qs_mode_category'    , isset( $_POST['qs_mode_category'] ) ? $_POST['qs_mode_category'] : 'false');
  105.         update_option('qs_mode_page'        , isset( $_POST['qs_mode_page'] ) ? $_POST['qs_mode_page'] : 'false');
  106.         update_option('qs_mode_summary'     , isset( $_POST['qs_mode_summary'] )$_POST['qs_mode_summary'] : 'false');
  107.        
  108.         echo '<h3>Update Successful</h3>';
  109.         echo '<p>Settings are saved and applied.</p>';
  110.         echo '<p><a href="plugins.php?page=qs-config">Back to Config page</a></p>';
  111.     } else {
  112.         // option page -- START
  113.         // setup default options
  114.         if(!get_option('qs_mode_single_post')) {
  115.             add_option('qs_mode_single_post', 'true');
  116.             $options['qs_mode_single_post'] = 'true';
  117.         } else {
  118.             $options['qs_mode_single_post'] = qs_handle_bool(get_option('qs_mode_single_post'));
  119.         }
  120.        
  121.         if(!get_option('qs_mode_category')) {
  122.             add_option('qs_mode_category', 'false');
  123.             $options['qs_mode_category'] = 'false';
  124.         } else {
  125.             $options['qs_mode_category'] = qs_handle_bool(get_option('qs_mode_category'));
  126.         }
  127.        
  128.         if(!get_option('qs_mode_page')) {
  129.             add_option('qs_mode_page', 'false');
  130.             $options['qs_mode_page'] = 'false';
  131.         } else {
  132.             $options['qs_mode_page'] = qs_handle_bool(get_option('qs_mode_page'));
  133.         }
  134.        
  135.         if(!get_option('qs_mode_summary')) {
  136.             add_option('qs_mode_summary', 'false');
  137.             $options['qs_mode_summary'] = 'false';
  138.         } else {
  139.             $options['qs_mode_summary'] = qs_handle_bool(get_option('qs_mode_summary'));
  140.         }
  141.        
  142.         if(!get_option('qs_text_color')) {
  143.             add_option('qs_text_color', '000000');
  144.             $options['qs_text_color'] = '000000';
  145.         } else {
  146.             $options['qs_text_color'] = get_option('qs_text_color');
  147.         }
  148.        
  149.         if(!get_option('qs_layout')) {
  150.             add_option('qs_layout', '1');
  151.             $options['qs_layout'] = '1';
  152.         } else {
  153.             $options['qs_layout'] = get_option('qs_layout');
  154.         }
  155.         /*
  156.         Option List
  157.         ===================================================
  158.         qs_mode_single_post : toggle display in single post (default: true)
  159.         qs_mode_category    : toggle display in categories  (default: false)
  160.         qs_mode_page        : toggle display in page        (default: false)
  161.         qs_mode_summary     : toggle display in summary     (default: false)
  162.         qs_text_color       : select text color             (default: 000000)
  163.         qs_layout           : select layout                 (default: 1)
  164.         */
  165. ?>
  166. <form action="" method="POST" id="qs-config">
  167.     <h2><?php _e('Quote Source Configuration'); ?></h2>
  168.     <table width="650" border="0" cellpadding="3" cellspacing="0">
  169.         <tr>
  170.             <td valign="top">Show quoted sources on:</td>
  171.             <td>
  172.                 <table width="100%" border="0" cellpadding="5" cellspacing="0">
  173.                     <tr>
  174.                         <td valign="top"><input name="qs_mode_single_post" type="checkbox" value="true" <?php if($options['qs_mode_single_post'] == 'true') { echo 'checked="checked"'; } ?> /></td>
  175.                         <td>Single Post<br /><span class="quote_source_desc">the page after user clicks the title of your post</span></td>
  176.                     </tr>
  177.                     <tr>
  178.                         <td valign="top"><input name="qs_mode_category" type="checkbox" value="true" <?php if($options['qs_mode_category'] == 'true') { echo 'checked="checked"'; } ?> /></td>
  179.                         <td>Categories<br /><span class="quote_source_desc">the page after user clicks on one of your categories</span></td>
  180.                     </tr>
  181.                     <tr>
  182.                         <td valign="top"><input name="qs_mode_page" type="checkbox" value="true" <?php if($options['qs_mode_page'] == 'true') { echo 'checked="checked"'; } ?> /></td>
  183.                         <td>Pages<br /><span class="quote_source_desc">the page after user clicks your page</span></td>
  184.                     </tr>
  185.                     <tr>
  186.                         <td valign="top"><input name="qs_mode_summary" type="checkbox" value="true" <?php if($options['qs_mode_summary'] == 'true') { echo 'checked="checked"'; } ?> /></td>
  187.                         <td>Summary, Front Page and Older Posts<br /><span class="quote_source_desc">the page which lists out the posts</span></td>
  188.                     </tr>
  189.                 </table>
  190.             </td>
  191.         </tr>
  192.         <tr>
  193.             <td colspan="2" style="border-bottom: 1px solid #999; margin-bottom: 15px"><b>Look &amp; Feel</b></td>
  194.         </tr>
  195.         <tr>
  196.             <td valign="top">Text Color</td>
  197.             <td>#<input type="text" name="txt_text_color" maxlength="6" value="<?php echo $options['qs_text_color'] ?>" /><br />&nbsp;</td>
  198.         </tr>
  199.         <tr>
  200.             <?php
  201.             $site1_url = 'http://raptor.hk';
  202.             $site1_title = 'Raptor Talks';
  203.             $site2_url = 'http://raptor.hk/plugin-quote-source/';
  204.             $site2_title = 'Quote Source Plugin in Raptor Talks';
  205.             ?>
  206.             <td valign="top">Layout</td>
  207.             <td>
  208.                 <table width="100%" border="0" cellpadding="5" cellspacing="0">
  209.                     <tr>
  210.                         <td width="30"><input type="radio" name="radio_layout" value="1" <?php if($options['qs_layout'] == '1') { echo 'checked="checked"'; } ?> /></td>
  211.                         <td>
  212.                             <fieldset style="border: 1px solid #999; padding: 10px;">
  213.                                 <legend>Type A&nbsp;</legend>
  214.                                     <a href="<?php echo $site1_url; ?>" target="_blank" title="<?php echo $site1_title; ?>"><?php echo $site1_title; ?></a></br>
  215.                                     <a href="<?php echo $site2_url; ?>" target="_blank" title="<?php echo $site2_title; ?>"><?php echo $site2_title; ?></a></br>
  216.                                 </br>
  217.                             </fieldset>
  218.                         </td>
  219.                     </tr>
  220.                     <tr>
  221.                         <td><input type="radio" name="radio_layout" value="3" <?php if($options['qs_layout'] == '3') { echo 'checked="checked"'; } ?> /></td>
  222.                         <td>
  223.                             <fieldset style="border: 1px solid #999; padding: 10px;">
  224.                                 <legend>Type B</legend>
  225.                                 <?php echo $site1_title; ?>: <a href="<?php echo $site1_url; ?>" target="_blank" title="<?php echo $site1_title; ?>"><?php echo $site1_url; ?></a><br />
  226.                                 <?php echo $site2_title; ?>: <a href="<?php echo $site2_url; ?>" target="_blank" title="<?php echo $site2_title; ?>"><?php echo $site2_url; ?></a><br />
  227.                             </fieldset>
  228.                         </td>
  229.                     </tr>
  230.                     <tr>
  231.                         <td><input type="radio" name="radio_layout" value="2" <?php if($options['qs_layout'] == '2') { echo 'checked="checked"'; } ?> /></td>
  232.                         <td>
  233.                                
  234.                             <fieldset style="border: 1px solid #999; padding: 10px;">
  235.                                 <legend>Type C</legend>
  236.                                 <ul style="list-style-type: square; list-style-position: inside;">
  237.                                     <li style="padding-left: 5px"><a href="<?php echo $site1_url; ?>" target="_blank" title="<?php echo $site1_title; ?>"><?php echo $site1_title; ?></a></li>
  238.                                     <li style="padding-left: 5px"><a href="<?php echo $site2_url; ?>" target="_blank" title="<?php echo $site2_title; ?>"><?php echo $site2_title; ?></a></li>
  239.                                 </ul>
  240.                             </fieldset>
  241.                         </td>
  242.                     </tr>
  243.                 </table>
  244.             </td>
  245.         </tr>
  246.         <tr>
  247.             <td>&nbsp;</td>
  248.             <td>&nbsp;<br /><input type="submit" name="submit" value="Apply Changes" /><br />&nbsp;</td>
  249.         </tr>
  250.         <tr>
  251.             <td colspan="2" style="border-bottom: 1px solid #999; margin-bottom: 15px"><b>Layout when only 1 source quoted</b></td>
  252.         </tr>
  253.         <tr>
  254.             <td colspan="2">
  255.                 <fieldset style="border: 1px solid #999; padding: 10px;">
  256.                     <legend>Example</legend>
  257.                     <p><i>Source</i> : <a href="<?php echo $site1_url; ?>" title="<?php echo $site1_title; ?>" target="_blank"><?php echo $site1_title; ?></a></p>
  258.                 </fieldset>
  259.             </td>
  260.         </tr>
  261.         <tr>
  262.             <td colspan="2"><hr />If you like Quote Source, please consider <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K4M78TFRBFZUC">donate US$5</a> to us. Report bugs <a href="mailto:findme@raptor.hk?subject=Quote%20Source%20Report%20Bug">here</a>.</td>
  263.         </tr>
  264.     </table>
  265. </form>
  266.  
  267. <?php
  268.         // option page -- END
  269.     }
  270. }
  271. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement