WordPress.org

Plugin Directory


Ignore:
Timestamp:
03/10/09 23:12:43 (9 years ago)
Author:
mark8barnes
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tng-wordpress-plugin/trunk/tng.php

    r100990 r101128  
    55Description: Integrates TNG (The Next Generation of Genealogy) with Wordpress. 
    66Author: Mark Barnes 
    7 Version: 0.24 
     7Version: 0.25 
    88Author URI: http://www.4-14.org.uk/ 
    99Copyright (c) 2008 Mark Barnes 
     
    4343// Serves static files, if requested. Runs initialisation if not. 
    4444function mbtng_serve_static_files () { 
     45    session_start(); 
    4546    if (isset($_REQUEST['update_globals'])) { 
    4647        mbtng_rewrite_globals(); 
     
    117118    if (get_option('mbtng_url') == '' && get_option('mbtng_wordpress_page') != '') 
    118119        mbtng_update_tng_url(); // Remove these two lines when out of beta 
    119     session_start(); 
     120    if (get_option('mbtng_redirect_login')) 
     121        add_filter('login_redirect','mbtng_redirect_login', 10, 3);     // Redirects user back to referrer page, not dashboard 
    120122    if (get_option('mbtng_integrate_logins')) {                         // Adds integration actions only if needed 
    121123        add_action('login_head', 'mbtng_login_head');                   // Adds styles to login header 
     
    155157 
    156158//Adds the TNG menu to Wordpress admin 
     159//Icon from FamFamFam: http://www.famfamfam.com/lab/icons/silk/ 
    157160function mbtng_add_admin_page () { 
    158     add_menu_page('TNG', 'TNG', 'manage_options', __FILE__, 'mbtng_options'); 
     161    add_menu_page('TNG', 'TNG', 'manage_options', __FILE__, 'mbtng_options', plugins_url('tng-wordpress-plugin/icon.png')); 
    159162    add_submenu_page (__FILE__, 'Options', 'Options', 'manage_options', __FILE__, 'mbtng_options'); 
    160     add_submenu_page (__FILE__, 'Admin', 'Admin', 'manage_options', 'tng/admin.php', 'mbtng_display_tng_admin'); 
     163    add_submenu_page (__FILE__, 'Admin', 'Admin', 'manage_options', 'tng-wordpress-plugin/admin.php', 'mbtng_display_tng_admin'); 
    161164} 
    162165 
     
    246249// Displays options page 
    247250function mbtng_options () { 
     251    global $wp_version; 
    248252    echo "<div class=\"wrap\">\n"; 
    249253    echo "<h2>TNG / Wordpress integration</h2>\n"; 
     
    303307    echo "\></td>\n"; 
    304308    echo "\t\t</tr>\n"; 
     309    if (version_compare($wp_version, '2.6.2', '>=')) { 
     310        echo "\t\t<tr>\n"; 
     311        echo "\t\t\t<td  style=\"padding: 0.5em 0\"valign=\"top\">Redirect successful login to referrer page:&nbsp;</td>\n"; 
     312        echo "\t\t\t<td style=\"padding: 0.5em 0\"><input type=\"checkbox\" name=\"mbtng_redirect_login\""; 
     313        if (get_option('mbtng_redirect_login')) echo "checked='checked'"; 
     314        echo "\></td>\n"; 
     315        echo "\t\t</tr>\n"; 
     316    } 
    305317    echo "\t\t<tr>\n"; 
    306318    echo "\t\t\t<td  style=\"padding: 0.5em 0\"valign=\"top\">Replace TNG homepage with Wordpress page:&nbsp;</td>\n"; 
     
    315327    wp_nonce_field('update-options'); 
    316328    echo "<input type=\"hidden\" name=\"action\" value=\"update\" />"; 
    317     echo "<input type=\"hidden\" name=\"page_options\" value=\"mbtng_wordpress_page, mbtng_template, mbtng_path, mbtng_integrate_logins, mbtng_use_wordpress_homepage\" />"; 
     329    echo "<input type=\"hidden\" name=\"page_options\" value=\"mbtng_wordpress_page, mbtng_template, mbtng_path, mbtng_integrate_logins, mbtng_redirect_login, mbtng_use_wordpress_homepage\" />"; 
    318330    echo "</form>\n"; 
    319331    echo "\t</table>\n"; 
     
    354366* mbtng_login                                   * 
    355367* mbtng_logout                                  * 
     368* mbtng_redirect_login                          * 
    356369************************************************/ 
    357370 
     
    431444                            update_usermeta($wp_id, 'wp_user_level', '10'); 
    432445                            update_usermeta($wp_id, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}'); 
     446                        } else { 
     447                            update_usermeta($wp_id, 'wp_capabilities', 'a:1:{s:10:"subscriber";b:1;}'); 
    433448                        } 
    434449                    } 
     
    547562} 
    548563 
     564// Redirects the user back to the referrer page, rather than the dashboard 
     565function mbtng_redirect_login ($link, $request_link, $user) { 
     566    if (isset($_SERVER['HTTP_REFERER']) && strtolower(substr($_SERVER['HTTP_REFERER'], -12)) != 'wp-login.php') 
     567        return $_SERVER['HTTP_REFERER']; 
     568    else 
     569        return $link; 
     570} 
     571 
    549572/************************************************ 
    550573*                                               * 
     
    594617            $i++; 
    595618        } 
    596         if ($user_info->user_level == 10) 
     619        if (isset($user_info->user_level) && $user_info->user_level == 10) 
    597620            $query = "INSERT INTO $users_table (description,username,password,realname,email,gedcom,allow_edit,allow_add,allow_delete,allow_lds,allow_ged,allow_living,dt_registered) VALUES (\"$realname\",\"$username\",\"$password\",\"$realname\",\"$email\",\"$gedcom\",1,1,1,1,1,1,\"$today\")"; 
    598621        else 
     
    644667        chdir($tng_folder); 
    645668        $link = mbtng_db_connect() or exit; 
    646         $user_info = get_userdata($user_ID); 
    647669        $query = "DELETE FROM $users_table WHERE userID='{$tng_user_id}'"; 
    648670        $result = mysql_query($query) or die ("Cannot execute query: $query"); 
     
    11231145// Returns the appropriate template 
    11241146function mbtng_get_template() { 
    1125     $output['template'] = FALSE; 
    11261147    if (is_user_logged_in()) { 
    11271148        global $current_user; 
     
    11301151        $output['timestamp'] = get_usermeta($current_user->ID, 'tng_timestamp'); 
    11311152    } 
    1132     if ($output['template'] === FALSE && isset($_SESSION['mbtng_template'])) { 
     1153    elseif (isset($_SESSION['mbtng_template'])) { 
    11331154        $output['template'] = $_SESSION['mbtng_template']; 
    11341155        $output['timestamp'] = $_SESSION['mbtng_timestamp']; 
    11351156    } 
    1136     if ($output['template'] === FALSE) { 
     1157    else { 
    11371158        $output['template'] = get_option('mbtng_template'); 
    11381159        $output['timestamp'] = get_option('mbtng_timestamp'); 
Note: See TracChangeset for help on using the changeset viewer.