Changeset 45315

Show
Ignore:
Timestamp:
05/11/08 23:25:49 (2 months ago)
Author:
danillonunes
Message:

Changes in options and widget interfaces

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • login-box/trunk/login-box-options.php

    r44267 r45315  
    11<?php 
     2function loginbox_options() { 
     3      // First, get the options from WordPress database 
     4      $options = get_option('loginbox'); 
    25 
    3 // /* UNCOMMENT HERE (REMOVE THIS LINE) TO EDIT OPTIONS MANUALLY 
     6      // If Login-box options are empty, get the default values 
     7      if ($options == '') { 
     8            loginbox_set_default_options(); 
     9            $options = get_option('loginbox'); 
     10      } 
    411 
    5 @define("LB_THEME", "widget"); 
    6 // Type the Login-box theme 
     12      // If a from was sended, update the options 
     13      if ($_POST['submit']) { 
     14            $newoptions['theme'] = strip_tags(stripslashes($_POST['loginbox-theme'])); 
     15            $newoptions['key'] = strip_tags(stripslashes($_POST['loginbox-key'])); 
     16            $newoptions['ctrl'] = strip_tags(stripslashes($_POST['loginbox-ctrl'])); 
     17            $newoptions['backtopage'] = strip_tags(stripslashes($_POST['loginbox-backtopage'])); 
     18            $newoptions['fade'] = strip_tags(stripslashes($_POST['loginbox-fade'])); 
    719 
    8 @define("LB_KEY", "e"); 
    9 // Choose the key (case insensitive) that will be open/close Login-box with Ctrl or Alt 
    10 // Note that this may cancel the default function of the Ctrl/Alt + key of the browser 
    11 // Ex: If you choose A, users cannot use Ctrl + A to select all texts in your blog 
     20            // Merge new and old options 
     21            // To use a unique database key for LB options and LB widget options 
     22            $newoptions = array_merge($options, $newoptions); 
     23            update_option('loginbox', $newoptions); 
    1224 
    13 @define("LB_CTRL", true); 
    14 // Also, you can disable Ctrl + key functions in Login-box defining this as false 
    15 // So, Login-box only will be open with Alt + key 
     25            // ...and show a nice message to user 
     26            echo '<div class="updated"><p><strong>'.__('Options saved.').'</strong></p></div>'; 
     27      } 
    1628 
    17 @define("LB_BACKTOPAGE", true); 
    18 // true: When login, you will be redirected to the actual page 
    19 // false: When login, you will be redirected to the WordPress Dashboard 
     29    echo '<div class="wrap">'; 
     30    echo '<h2>Login-box</h2>'; 
     31?> 
     32<form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> 
    2033 
    21 @define("LB_FADE", true); 
    22 // true: Show/hide Login-box with fadeIn/fadeOut 
    23 // false: Without fadeIn/fadeOut 
     34<p> 
     35<strong><?php _e('Login-box theme', 'login-box'); ?></strong> 
    2436 
    25 // Only for development, you don't need change this 
    26 //@define("LB_WPDIR", "/home/danillo/htdocs/wordpress/"); 
     37<?php 
     38function loginbox_get_themes() { 
     39      $options = get_option('loginbox'); 
     40      $olddir = getcwd(); 
     41      chdir(ABSPATH.'/wp-content/plugins/login-box'); 
     42      if ($dh = opendir('.')) { 
     43            while (($file = readdir($dh)) !== false) { 
     44                  if (is_file($file.'/style.css')) { ?> 
     45                        <br/> 
     46                        <label> 
     47                        <input type="radio" name="loginbox-theme" value="<?php echo $file; ?>" 
     48                        <?php if ($options['theme'] == $file) echo 'checked="checked"'; ?> 
     49                        > 
     50                        <?php echo $file; ?> 
     51                        </label> 
     52                        <?php 
     53                  } 
     54            } 
     55      closedir($dh); 
     56      } 
     57      chdir($olddir); 
     58
    2759 
    28 // */ 
    29 // YOU CAN STOP EDIT BELOW THIS LINE 
     60loginbox_get_themes(); 
    3061?> 
     62</p> 
     63 
     64<p> 
     65<label><?php _e('Open with <strong>Alt</strong> +', 'login-box'); ?>  
     66<input type="text" name="loginbox-key" value="<?php echo $options['key']; ?>" size="1"> 
     67</label> 
     68 
     69<br/> 
     70<label> 
     71<input type="checkbox" name="loginbox-ctrl" value="1" <?php if ($options['ctrl']) echo 'checked="checked"'; ?>> 
     72<?php printf(__('Also open with <strong>Ctrl</strong> + <span>%s</span>', 'login-box'), $options['key']); ?> 
     73</label> 
     74</p> 
     75 
     76<p> 
     77<strong><?php _e('When login', 'login-box'); ?></strong>, 
     78 
     79<br/> 
     80<label> 
     81<input type="radio" name="loginbox-backtopage" value="1" <?php if ($options['backtopage']) echo 'checked="checked"'; ?>> 
     82<?php _e('Back to page', 'login-box'); ?> 
     83</label> 
     84 
     85<br/> 
     86<label> 
     87<input type="radio" name="loginbox-backtopage" value="0" <?php if ($options['backtopage'] == 0) echo 'checked="checked"'; ?>> 
     88<?php _e('Go to Dashboard', 'login-box'); ?> 
     89</label> 
     90</p> 
     91 
     92<p> 
     93<label> 
     94<input type="checkbox" name="loginbox-fade" value="1" <?php if ($options['fade']) echo 'checked="checked"'; ?>> 
     95<?php _e('Use <strong>fadeIn/fadeOut</strong> effects', 'login-box'); ?> 
     96</label> 
     97</p> 
     98 
     99<hr /> 
     100<p class="submit"> 
     101<input type="submit" id="submit" name="submit" value="<?php _e('Update Options ยป') ?>" /> 
     102</p> 
     103 
     104</form> 
     105</div> 
     106 
     107<?php 
     108} 
     109 
     110// Add the function above as a new page in WordPress panel 
     111function loginbox_add_page() { 
     112      add_submenu_page('themes.php', 'Login-box', 'Login-box', 'edit_themes', 'login-box', 'loginbox_options'); 
     113} 
     114 
     115add_action('admin_menu', 'loginbox_add_page'); 
     116 
     117// Function to set default options and update in database 
     118function loginbox_set_default_options() { 
     119      $options['theme']      = 'wp25'; 
     120      $options['key']        = 'E'; 
     121      $options['ctrl']       = '1'; 
     122      $options['backtopage'] = '1'; 
     123      $options['fade']       = '1'; 
     124 
     125      update_option('loginbox', $options); 
     126} 
     127 
     128// Now, defines the options as constants, to be used by Login-box core 
     129function loginbox_set_options() { 
     130      $options = get_option('loginbox'); 
     131 
     132      if (!defined('LB_THEME'))      define("LB_THEME", $options['theme']); 
     133      if (!defined('LB_KEY'))        define("LB_KEY", $options['key']); 
     134      if (!defined('LB_CTRL'))       define("LB_CTRL", $options['ctrl']); 
     135      if (!defined('LB_BACKTOPAGE')) define("LB_BACKTOPAGE", $options['backtopage']); 
     136      if (!defined('LB_AUTO'))       define("LB_AUTO", true); 
     137} 
     138 
     139loginbox_set_options(); 
     140?> 
  • login-box/trunk/login-box-widget.php

    r44267 r45315  
    1616      function loginbox_widget($args) { 
    1717            extract($args); 
    18             $options = get_option('loginbox_widget'); 
    19             $title = empty($options['title']) ? 'Login-box' : $options['title']; 
     18            $options = get_option('loginbox'); 
     19            $title = empty($options['widget_title']) ? 'Login-box' : $options['widget_title']; 
    2020 
    2121            if (!is_user_logged_in()) { 
    2222                  echo $before_widget; 
    2323                  echo $before_title . $title . $after_title; 
     24                  echo '<ul>'; 
    2425                  echo '<li><a href="'; 
    2526                  bloginfo('wpurl'); 
     
    3132                  loginbox(); 
    3233                  echo '</li>'; 
    33        
     34                 if ($options['widget_register']) { 
    3435                        echo '<li><a href="'; 
    3536                        bloginfo('wpurl'); 
    3637                        echo '/wp-login.php?action=register" title="'.__('Register').'">'.__('Register').'</a></li>'; 
     38                  } 
     39                  echo '</ul>'; 
    3740                  echo $after_widget; 
    3841            } 
     
    4043 
    4144      function loginbox_widget_control() { 
    42             $options = get_option('loginbox_widget'); 
    43             if ( $_POST['loginbox-submit'] ) { 
    44                   $newoptions['title'] = strip_tags(stripslashes($_POST['loginbox-title'])); 
    45                   $newoptions['register'] = strip_tags(stripslashes($_POST['loginbox-register'])); 
     45            $options = get_option('loginbox'); 
     46            if ($_POST['loginbox-submit']) { 
     47                  $newoptions['widget_title'] = strip_tags(stripslashes($_POST['loginbox-title'])); 
     48                  $newoptions['widget_register'] = strip_tags(stripslashes($_POST['loginbox-register'])); 
     49 
     50                  $newoptions = array_merge($options, $newoptions); 
     51                  update_option('loginbox', $newoptions); 
    4652            } 
    4753 
    48             if ( $options != $newoptions ) { 
    49                   $options = $newoptions; 
    50                   update_option('loginbox_widget', $options); 
    51             } 
    52  
    53       $title = htmlspecialchars($options['title'], ENT_QUOTES); 
    54       $register = htmlspecialchars($options['register'], ENT_QUOTES); 
     54      $title = htmlspecialchars($options['widget_title'], ENT_QUOTES); 
     55      $register = htmlspecialchars($options['widget_register'], ENT_QUOTES); 
    5556?> 
    5657        <div> 
     
    5960            <input class="widefat" type="text" id="loginbox-title" name="loginbox-title" value="<?php echo $title; ?>" /> 
    6061      </label> 
    61  
     62      <br/> 
    6263        <label for="loginbox-register"> 
    6364            <input class="checkbox" type="checkbox" id="loginbox-register" name="loginbox-register" value="1" <?php if ($register) echo 'checked="checked"'; ?> /> 
  • login-box/trunk/login-box.php

    r44267 r45315  
    33Plugin Name: Login-box 
    44Plugin URI: http://danillonunes.net/wordpress/login-box 
    5 Version: 1.0 
     5Version: 2.0 alpha 
    66Description: Inserts in all pages a hidden login box, that you can open pressing Ctrl + E (or Alt + E) 
    77Author: Marcus Danillo 
     
    2626*/ 
    2727 
    28 require_once "login-box-options.php"; 
     28// Get the Login-box definitions 
     29@include "login-box-config.php"; 
     30include "login-box-options.php"; 
    2931 
     32// The primary Login-box function 
    3033function loginbox($force = false) { 
    31 if (!is_user_logged_in() && (!defined("LB_USED") || $force)) { ?> 
     34 
     35// Login-box is showed only if the user isn't logged, of course 
     36// The constant 
     37if (!is_user_logged_in() && (!defined("LB_USED") || $force)) { 
     38 
     39?> 
    3240 
    3341