WordPress.org

Plugin Directory


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

Legend:

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

    r100550 r100990  
    55Description: Integrates TNG (The Next Generation of Genealogy) with Wordpress. 
    66Author: Mark Barnes 
    7 Version: 0.23 
     7Version: 0.24 
    88Author URI: http://www.4-14.org.uk/ 
    99Copyright (c) 2008 Mark Barnes 
     
    4646        mbtng_rewrite_globals(); 
    4747        header('Location: '.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php&updated=globals'); 
     48        die(); 
     49    } 
     50    if (isset($_REQUEST['tng_search'])) { 
     51        mbtng_search_for_tng (dirname(__FILE__)); 
    4852    } 
    4953    if (isset($_REQUEST['tng_template'])) { 
     
    114118        mbtng_update_tng_url(); // Remove these two lines when out of beta 
    115119    session_start(); 
    116     add_action('widgets_init', 'mbtng_widget_init');                    // Initialise the widgets 
    117120    if (get_option('mbtng_integrate_logins')) {                         // Adds integration actions only if needed 
    118121        add_action('login_head', 'mbtng_login_head');                   // Adds styles to login header 
     
    124127    } 
    125128    if (mbtng_display_page()) { 
    126         add_filter('the_posts','mbtng_fake_post');                      // Return the Wordpress TNG page if any TNG page is requested 
     129        add_filter('the_posts','mbtng_fake_post');                      // Return the Wordpress TNG page if any TNG page is requested 
    127130        add_action('template_redirect', 'mbtng_buffer_start');          // Intercept front-end to buffer output 
    128131        add_action('wp_head', 'mbtng_frontend_header');                 // Adds TNG template <head> to WordPress <head> 
     
    145148* mbtng_add_admin_page                          * 
    146149* mbtng_options_reminder                        * 
     150* mbtng_search_for_tng                          * 
    147151* mbtng_rewrite_globals                         * 
    148152* mbtng_options                                 * 
     
    160164function mbtng_options_reminder() { 
    161165    if (isset($_REQUEST['updated']) && $_REQUEST['updated'] == 'true') { 
    162         update_option('mbtng_path', trailingslashit(get_option('mbtng_path'))); 
     166        update_option('mbtng_path', mbtng_folder_trailingslashit(get_option('mbtng_path'))); 
    163167        mbtng_update_tng_url(); 
    164168        mbtng_rewrite_globals(); 
    165169    } 
    166     if (get_option('mbtng_wordpress_page')=='' | get_option('mbtng_path')=='') 
    167         echo '<div id="message" class="updated"><p><b>In order to make TNG visible, you must go to <a href="'.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php">TNG options</a>, and specify a page where TNG will be displayed on your site, and the path to your TNG files.</b></div>'; 
     170    if (get_option('mbtng_wordpress_page')=='') 
     171        echo '<div id="message" class="updated"><p><b>In order to make TNG visible, you must go to <a href="'.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php">TNG options</a>, and specify a page where TNG will be displayed on your site.</b></div>'; 
     172    if (!mbtng_correct_path()) 
     173        echo '<div id="message" class="error"><p><b>Warning:</b> TNG cannot be found in '.get_option('mbtng_path').' - please <a href="'.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php">specify the full (absolute) path</a> to your TNG installation, or <a href="'.get_bloginfo('wpurl').'?tng_search">automatically search for the correct folder</a>.</p></div>'; 
     174} 
     175 
     176//Searches server for TNG files 
     177function mbtng_search_for_tng ($path = '', $go_back = true) { 
     178    global $countit; 
     179    if ($path == '..') 
     180        $oldpath = basename(getcwd()); 
     181    else 
     182        $oldpath = ''; 
     183    if ($path != '') 
     184        if (!@chdir($path)) { 
     185            header('Location: '.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php&updated=notfound'); 
     186            die(); 
     187        } 
     188    $path=getcwd(); 
     189    $dir = @opendir($path); 
     190    if ($dir) { 
     191        $element=readdir($dir); 
     192        while ($element !== false) { 
     193            if (is_dir(mbtng_folder_trailingslashit($path).$element) && $element != "." && $element != ".." && $element != $oldpath) { 
     194                mbtng_search_for_tng(mbtng_folder_trailingslashit($path).$element, FALSE); 
     195                chdir($path); 
     196            } 
     197            elseif ($element != "." && $element != "..") { 
     198                if ($element == 'ahnentafel.php' && mbtng_correct_path($path)) { 
     199                    update_option('mbtng_path', mbtng_folder_trailingslashit($path)); 
     200                    header('Location: '.get_bloginfo('wpurl').'/wp-admin/admin.php?page=tng-wordpress-plugin/tng.php&updated=search'); 
     201                    die(); 
     202                } 
     203            } 
     204        $element=readdir($dir); 
     205        } 
     206        closedir($dir); 
     207    } 
     208    if ($go_back) 
     209        mbtng_search_for_tng('..', TRUE); 
     210    return; 
    168211} 
    169212 
     
    175218    } 
    176219 
    177     $folders[0] = trailingslashit(get_option('mbtng_path')); 
    178     $folders[1] = $folders[0].'admin/'; 
     220    $folders[0] = mbtng_folder_trailingslashit(get_option('mbtng_path')); 
     221    $folders[1] = mbtng_folder_trailingslashit($folders[0].'admin'); 
    179222    $bnn = $keep = array(); 
    180223    foreach ($folders as $folder) { 
     
    206249    echo "<h2>TNG / Wordpress integration</h2>\n"; 
    207250    if (isset($_REQUEST['updated']) && $_REQUEST['updated'] == 'globals') 
    208         echo '<div id="message" class="updated fade"><p>TNG variables updated</p></div>'; 
     251        echo '<div id="message" class="updated fade"><p>TNG variables updated.</p></div>'; 
     252    if (isset($_REQUEST['updated']) && $_REQUEST['updated'] == 'search') 
     253        echo '<div id="message" class="updated fade"><p>TNG path found as '.get_option('mbtng_path').'.</p></div>'; 
     254    if (isset($_REQUEST['updated']) && $_REQUEST['updated'] == 'notfound') 
     255        echo '<div id="message" class="error"><p>Could not find TNG path.</p></div>'; 
    209256    if (isset($_REQUEST['updated']) && $_REQUEST['updated'] == 'true') { 
    210         echo '<div id="message" class="updated fade"><p>TNG settings saved</p></div>'; 
     257        echo '<div id="message" class="updated fade"><p>TNG settings saved.</p></div>'; 
    211258        update_option('mbtng_timestamp', strtotime('now')); 
    212259    } 
     
    215262    if (!isset($_SERVER['REQUEST_URI'])) 
    216263        echo '<div id="message" class="error"><p>Sorry, this site appears to be running on a Windows server, which is not currently compatible with the TNG plugin. Please <a href="http://www.4-14.org.uk/contact">contact the developer</a> if you would like to test a Windows version.</p></div>'; 
    217     if (!mbtng_correct_path()) 
    218         echo '<div id="message" class="error"><p><b>Warning:</b> TNG cannot be found in '.get_option('mbtng_path').' - please specify the full (absolute) path to your TNG installation. This is normally the same as the value of $rootpath in config.php</p></div>'; 
    219264    $pages = get_pages('sort_column=menu_order'); 
    220265    $templates = mbtng_get_template_list(); 
     
    275320    echo "<h3>Advanced</h3>\n"; 
    276321    echo "<form method=\"post\">\n"; 
    277     echo "<p class=\"submit\" style=\"padding:0\"><input type=\"submit\" name=\"update_globals\" value=\"Update TNG variables\" /> (you should press this button if you upgrade your TNG version, or if pages display incorrectly)</p>\n"; 
     322    echo "<table>\n"; 
     323    echo "<tr>\n"; 
     324    echo "<td><p class=\"submit\" style=\"padding:0\"><input type=\"submit\" name=\"tng_search\" value=\"Search for TNG installation\" style=\"margin-right:1em\"/></p></td>\n"; 
     325    echo "<td>Click here to attempt to automatically find your TNG installation folder.</td>\n"; 
     326    echo "</tr><tr>\n"; 
     327    echo "<td><p class=\"submit\" style=\"padding:0\"><input type=\"submit\" name=\"update_globals\" value=\"Update TNG variables\" /></p></td>\n"; 
     328    echo "<td>You should press this button if you upgrade your TNG version, or if pages display incorrectly.</td>\n"; 
     329    echo "</tr>\n"; 
     330    echo "</table>\n"; 
    278331    echo "</form>\n"; 
    279332    echo "</div>\n"; 
     
    316369    include($cms['tngpath'] . "getlang.php"); 
    317370    $textpart = "login"; 
    318     include($cms['tngpath'] . "$mylanguage/text.php"); 
     371    include($cms['tngpath'] . "{$mylanguage}/text.php"); 
    319372    mbtng_db_connect() or exit; 
    320     $query = "SELECT gedcom, treename FROM $trees_table ORDER BY treename"; 
    321     $treeresult = mysql_query($query) or die ("$admtext[cannotexecutequery]: $query"); 
     373    $query = "SELECT gedcom, treename FROM {$trees_table} ORDER BY treename"; 
     374    $treeresult = mysql_query($query) or die ("{$admtext['cannotexecutequery']}: {$query}"); 
    322375    $numtrees = mysql_num_rows( $treeresult ); 
    323     echo "<p><label>$text[realname]<br/><input id =\"realname\" class=\"input\" size=\"25\" name=\"realname\"></label>\n"; 
    324     echo "<p><label>$text[tree]<br/><select id=\"tree\" style=\"margin-bottom: 5px\" name=\"tree\"><option value=\"\"></option>"; 
     376    echo "<p><label>{$text['realname']}<br/><input id =\"realname\" class=\"input\" size=\"25\" name=\"realname\"></label>\n"; 
     377    echo "<p><label>{$text['tree']}<br/><select id=\"tree\" style=\"margin-bottom: 5px\" name=\"tree\"><option value=\"\"></option>"; 
    325378    while($treerow = mysql_fetch_assoc($treeresult)) 
    326             echo "<option value=\"$treerow[gedcom]\">$treerow[treename]</option>\n"; 
    327     echo"</select><br/>$text[leaveblank]</label></p><br/>"; 
     379            echo "<option value=\"{$treerow['gedcom']}\">{$treerow['treename']}</option>\n"; 
     380    echo"</select><br/>{$text['leaveblank']}</label></p><br/>"; 
     381    mbtng_close_tng_table(); 
    328382} 
    329383 
     
    338392        include($cms['tngpath'] . "getlang.php"); 
    339393        $textpart = "login"; 
    340         include($cms['tngpath'] . "$mylanguage/text.php"); 
    341         $errors->add('empty_realname', "<strong>ERROR</strong>: $text[enterrealname]"); 
     394        include($cms['tngpath'] . "{$mylanguage}/text.php"); 
     395        $errors->add('empty_realname', "<strong>ERROR</strong>: {$text['enterrealname']}"); 
    342396    } else { 
    343397        $mbtng_realname = $_POST['realname']; 
     
    358412            $result = mysql_query($query) or die ("Cannot execute query: $query"); 
    359413            $row = mysql_fetch_assoc($result); 
     414            mbtng_close_tng_table(); 
    360415            if ($row){ // Username IS in TNG userlist 
    361                 $tng_password_hash = $row[password]; 
    362                 $tng_admin = $row[allow_edit] && $row[allow_add] && $row[allow_delete]; 
    363                 $tng_email = $row[email]; 
    364                 $tng_nickname = $row[description]; 
    365                 $tng_id = $row[userID]; 
     416                $tng_password_hash = $row['password']; 
     417                $tng_admin = $row['allow_edit'] && $row['allow_add'] && $row['allow_delete']; 
     418                $tng_email = $row['email']; 
     419                $tng_nickname = $row['description']; 
     420                $tng_id = $row['userID']; 
    366421                if($wpdb->get_var("select ID from {$wpdb->prefix}users WHERE user_email='{$tng_email}'")) // TNG user already in WP userlist, but with a different username. 
    367422                    wp_die ('You have logged in with your TNG username, which in your case is different from your Wordpress username. Click back to try again, or use your email address to <a href="?action=lostpassword">retrieve your password</a>.'); 
    368423                else { 
    369                     $password_supplied = $_POST[pwd]; 
     424                    $password_supplied = $_POST['pwd']; 
    370425                    if (md5($password_supplied) === $tng_password_hash | $password_supplied === $tng_password_hash) { // User has attempted to login to WP with correct TNG credentials 
    371426                        include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
     
    381436                        wp_die ('You have attempted to log in with your incorrect TNG credentials. You cannot reset your TNG password, so either click back to try again, or contact your system administrator.'); 
    382437                } 
     438            } 
     439        } 
     440        else { // Username IS in WP userlist, so sync TNG password with Wordpress password 
     441            if (user_pass_ok($username, $_POST['pwd'])) { 
     442                $userdata = get_userdatabylogin($username); 
     443                $tng_user_name = mbtng_check_user($userdata->ID); 
     444                $tng_folder = get_option('mbtng_path'); 
     445                chdir($tng_folder); 
     446                $password_hash = md5($_POST['pwd']); 
     447                $link = mbtng_db_connect() or exit; 
     448                $query = "UPDATE {$users_table} SET password='{$password_hash}' WHERE username='{$tng_user_name}'"; 
     449                $result = mysql_query($query) or die ("Cannot execute query: $query"); 
     450                mbtng_close_tng_table(); 
    383451            } 
    384452        } 
     
    416484        mysql_free_result($result); 
    417485        $newdate = date ("Y-m-d H:i:s", time() + ( 3600 * $time_offset ) ); 
    418         $query = "UPDATE $users_table SET lastlogin=\"$newdate\" WHERE userID=\"$row[userID]\""; 
    419         $uresult = mysql_query($query) or die ("$admtext[cannotexecutequery]: $query"); 
     486        $query = "UPDATE $users_table SET lastlogin=\"$newdate\" WHERE userID=\"{$row['userID']}\""; 
     487        $uresult = mysql_query($query) or die ("{$admtext['cannotexecutequery']}: {$query}"); 
    420488        $newroot = ereg_replace( "/", "", $rootpath ); 
    421489        $newroot = ereg_replace( " ", "", $newroot ); 
    422490        $newroot = ereg_replace( "\.", "", $newroot ); 
    423491        setcookie("tnguser_$newroot", $tngusername, time()+31536000, "/"); 
    424         setcookie("tngpass_$newroot", $row[password], time()+31536000, "/"); 
     492        setcookie("tngpass_$newroot", $row['password'], time()+31536000, "/"); 
    425493        session_register('logged_in'); 
    426494        session_register('allow_admin_db'); 
     
    437505        session_register('currentuserdesc'); 
    438506        session_register('session_rp'); 
    439         $logged_in = $_SESSION[logged_in] = 1; 
    440         $allow_edit_db = $_SESSION[allow_edit_db] = $row[allow_edit]; 
    441         $allow_add_db = $_SESSION[allow_add_db] = $row[allow_add]; 
    442         $tentative_edit_db = $_SESSION[tentative_edit_db] = $row[tentative_edit]; 
    443         $allow_delete_db = $_SESSION[allow_delete_db] = $row[allow_delete]; 
     507        $logged_in = $_SESSION['logged_in'] = 1; 
     508        $allow_edit_db = $_SESSION['allow_edit_db'] = $row['allow_edit']; 
     509        $allow_add_db = $_SESSION['allow_add_db'] = $row['allow_add']; 
     510        $tentative_edit_db = $_SESSION['tentative_edit_db'] = $row['tentative_edit']; 
     511        $allow_delete_db = $_SESSION['allow_delete_db'] = $row['allow_delete']; 
    444512        if( $allow_edit_db || $allow_add_db || $allow_delete_db ) 
    445             $allow_admin_db = $_SESSION[allow_admin_db] = 1; 
     513            $allow_admin_db = $_SESSION['allow_admin_db'] = 1; 
    446514        else 
    447             $allow_admin_db = $_SESSION[allow_admin_db] = 0; 
     515            $allow_admin_db = $_SESSION['allow_admin_db'] = 0; 
    448516        if( !$livedefault ) //depends on permissions 
    449             $allow_living_db = $_SESSION[allow_living_db] = $row[allow_living]; 
     517            $allow_living_db = $_SESSION['allow_living_db'] = $row['allow_living']; 
    450518        elseif( $livedefault == 2 ) //always do living 
    451             $allow_living_db = $_SESSION[allow_living_db] = 1; 
     519            $allow_living_db = $_SESSION['allow_living_db'] = 1; 
    452520        else //never do living 
    453             $allow_living_db = $_SESSION[allow_living_db] = 0; 
    454         $allow_ged_db = $_SESSION[allow_ged_db] = $row[allow_ged]; 
     521            $allow_living_db = $_SESSION['allow_living_db'] = 0; 
     522        $allow_ged_db = $_SESSION['allow_ged_db'] = $row['allow_ged']; 
    455523        if( !$ldsdefault ) //always do lds 
    456             $allow_lds_db = $_SESSION[allow_lds_db] = 1; 
     524            $allow_lds_db = $_SESSION['allow_lds_db'] = 1; 
    457525        elseif( $ldsdefault == 2 )  //depends on permissions 
    458             $allow_lds_db = $_SESSION[allow_lds_db] = $row[allow_lds]; 
     526            $allow_lds_db = $_SESSION['allow_lds_db'] = $row['allow_lds']; 
    459527        else  //never do lds 
    460             $allow_lds_db = $_SESSION[allow_lds_db] = 0; 
    461         $assignedtree = $_SESSION[assignedtree] = $row[gedcom]; 
    462         $assignedbranch = $_SESSION[assignedbranch] = $row[branch]; 
    463         $currentuser = $_SESSION[currentuser] = $row[username]; 
    464         $currentuserdesc = $_SESSION[currentuserdesc] = $row[description]; 
    465         $session_rp = $_SESSION[session_rp] = $rootpath; 
     528            $allow_lds_db = $_SESSION['allow_lds_db'] = 0; 
     529        $assignedtree = $_SESSION['assignedtree'] = $row['gedcom']; 
     530        $assignedbranch = $_SESSION['assignedbranch'] = $row['branch']; 
     531        $currentuser = $_SESSION['currentuser'] = $row['username']; 
     532        $currentuserdesc = $_SESSION['currentuserdesc'] = $row['description']; 
     533        $session_rp = $_SESSION['session_rp'] = $rootpath; 
     534        mbtng_close_tng_table(); 
    466535        return $tngusername; 
    467536    } 
     
    474543    chdir($tng_folder); 
    475544    include("begin.php"); 
    476     if ($_SESSION[currentuser] != '') 
     545    if ($_SESSION['currentuser'] != '') 
    477546        include('logout.php'); 
    478547} 
     
    492561    $tng_folder = get_option('mbtng_path'); 
    493562    chdir($tng_folder); 
     563    $user_info = get_userdata($user_ID); 
    494564    $link = mbtng_db_connect() or exit; 
    495     $user_info = get_userdata($user_ID); 
    496565    $query = "SELECT userID FROM $users_table WHERE email='{$user_info->user_email}'"; 
    497566    $result = mysql_query($query) or die ("Cannot execute query: $query"); 
    498567    $found = mysql_num_rows($result); 
    499568    if ($found == 0) { 
    500         $user_info = get_userdata($user_ID); 
    501         $email = $user_info->user_email; 
     569        mbtng_close_tng_table(); 
    502570        if ($realname == '') 
    503571            $realname = trim(get_usermeta($user_ID, 'nickname')); 
     572        $password = md5(wp_generate_password()); 
     573        $email = $user_info->user_email; 
    504574        $username = $user_info->user_login; 
     575        $time_offset = get_option('gmt_offset'); 
    505576        $gedcom = $tree; 
    506         $password = md5(wp_generate_password()); 
    507577        if (get_magic_quotes_gpc() == 0) { 
    508578            $username = addslashes($username); 
     
    515585        $i=0; 
    516586        $found=1; 
     587        $link = mbtng_db_connect() or exit; 
    517588        while ($found !=0) { 
    518589            if ($i !=0) 
     
    529600        $result = mysql_query($query) or die (mysql_errno($link) . ": " . mysql_error($link). "\n Query:\n".$query); 
    530601        $success = mysql_insert_id($link); 
     602        mbtng_close_tng_table(); 
    531603        update_usermeta($user_ID, 'tng_user_id', $success); 
    532604        return mbtng_login(); 
     
    534606    elseif ($found == 1) { 
    535607        $row = mysql_fetch_assoc($result); 
    536         update_usermeta($user_ID, 'tng_user_id', $row[userID]); 
    537         return $row[userID]; 
     608        mbtng_close_tng_table(); 
     609        update_usermeta($user_ID, 'tng_user_id', $row['userID']); 
     610        return $row['userID']; 
    538611    } 
    539612    else 
     
    553626        $row = mysql_fetch_assoc($result); 
    554627        $found = mysql_num_rows($result); 
     628        mbtng_close_tng_table(); 
    555629        if($found == 0) { 
    556630            delete_usermeta($user_ID, 'tng_user_id'); // Link is invalid 
     
    573647        $query = "DELETE FROM $users_table WHERE userID='{$tng_user_id}'"; 
    574648        $result = mysql_query($query) or die ("Cannot execute query: $query"); 
     649        mbtng_close_tng_table(); 
    575650    } 
    576651} 
     
    592667 
    593668function mbtng_use_tng_homepage() { 
    594     if (get_option('mbtng_use_wordpress_homepage')==TRUE && get_bloginfo('wpurl').trailingslashit(urldecode($_SERVER['REQUEST_URI'])) == get_option('mbtng_url')) 
     669    if (get_option('mbtng_use_wordpress_homepage')==TRUE && mbtng_requested_url() == get_option('mbtng_url')) 
    595670        return false; 
    596671    else 
     
    714789        eval('?>'.get_option('mbtng_globals').'<?php '); 
    715790        ob_start(); 
    716         $code = file_get_contents(trailingslashit($tng_folder).$filename); 
     791        $code = file_get_contents(mbtng_folder_trailingslashit($tng_folder).$filename); 
    717792        if ($admin | $filename == 'pdfform.php') 
    718793            chdir($tng_folder); 
     
    725800        $tng_output = $output; 
    726801    } 
     802    mbtng_close_tng_table(); 
    727803    return $tng_output; 
    728804} 
     
    739815// Returns the requested TNG page or query 
    740816function mbtng_requested ($type = 'url') { 
    741     $requested = get_bloginfo('wpurl').urldecode($_SERVER['REQUEST_URI']); // Won't work with IIS 
     817    $requested = mbtng_requested_url(); 
    742818    $query_pos = strrpos($requested, '?')+1; 
    743819    $query = ''; 
     
    778854*                                               * 
    779855* mbtng_widget_init                             * 
     856* mbtng_check_parent                            * 
     857* mbtng_display_widget                          * 
    780858* mbtng_output_search                           * 
    781859* mbtng_output_menu                             * 
     
    790868} 
    791869 
     870// Returns true if page is descendant of TNG page 
     871function mbtng_check_parent($check_id = -10) { 
     872    global $post, $wpdb; 
     873    if ($check_id == -10) 
     874        $check_id = $post->ID; 
     875    if ($check_id == get_option('mbtng_wordpress_page')) 
     876        return true; 
     877    elseif ($check_id == 0) 
     878        return false; 
     879    else { 
     880        $parent = $wpdb->get_var("SELECT post_parent FROM {$wpdb->prefix}posts WHERE id='{$check_id}'"); 
     881        return mbtng_check_parent($parent); 
     882    } 
     883} 
     884 
     885// Returns true if the widgets should be displayed 
     886function mbtng_display_widget() { 
     887    if (mbtng_display_page()) 
     888        return true; 
     889    else 
     890        return mbtng_check_parent(); 
     891} 
     892 
    792893//Outputs the TNG search in the sidebar 
    793894function mbtng_output_search ($args) { 
    794     global $mylanguage, $language, $rootpath; 
    795     if (mbtng_display_page()) { 
     895    global $mylanguage, $language, $rootpath, $post; 
     896    if (mbtng_display_widget()) { 
    796897        extract($args); 
    797898        $tng_folder = get_option('mbtng_path'); 
     
    804905        echo "<form action=\"search.php\" method=\"post\">\n"; 
    805906        echo "<table class=\"menuback\">\n"; 
    806         echo "<tr><td><span class=\"fieldname\">$text[mnulastname]:<br /><input type=\"text\" name=\"mylastname\" class=\"searchbox\" size=\"14\" /></span></td></tr>\n"; 
    807         echo "<tr><td><span class=\"fieldname\">$text[mnufirstname]:<br /><input type=\"text\" name=\"myfirstname\" class=\"searchbox\" size=\"14\" /></span></td></tr>\n"; 
    808         echo "<tr><td><input type=\"hidden\" name=\"mybool\" value=\"AND\" /><input type=\"submit\" name=\"search\" value=\"$text[mnusearchfornames]\" class=\"small\" /></td></tr>\n"; 
     907        echo "<tr><td><span class=\"fieldname\">{$text['mnulastname']}:<br /><input type=\"text\" name=\"mylastname\" class=\"searchbox\" size=\"14\" /></span></td></tr>\n"; 
     908        echo "<tr><td><span class=\"fieldname\">{$text['mnufirstname']}:<br /><input type=\"text\" name=\"myfirstname\" class=\"searchbox\" size=\"14\" /></span></td></tr>\n"; 
     909        echo "<tr><td><input type=\"hidden\" name=\"mybool\" value=\"AND\" /><input type=\"submit\" name=\"search\" value=\"{$text['mnusearchfornames']}\" class=\"small\" /></td></tr>\n"; 
    809910        echo "</table>\n"; 
    810911        echo "</form>\n"; 
    811912        echo "<ul>\n"; 
    812         echo "<li style=\"font-weight:bold\"><a href=\"searchform.php\">$text[mnuadvancedsearch]</a></li>\n"; 
     913        echo "<li style=\"font-weight:bold\"><a href=\"searchform.php\">{$text['mnuadvancedsearch']}</a></li>\n"; 
    813914        echo "</ul>\n"; 
    814915        echo $after_widget; 
     
    819920function mbtng_output_menu ($args) { 
    820921    global $mylanguage, $language, $rootpath, $allow_admin; 
    821     if (mbtng_display_page()) { 
     922    if (mbtng_display_widget()) { 
    822923        extract($args); 
    823924        $tng_folder = get_option('mbtng_path'); 
     
    829930        echo $before_title.'Genealogy Menu'.$after_title; 
    830931        echo "<ul>\n"; 
    831         echo "<li class=\"surnames\" style=\"font-weight:bold\"><a href=\"surnames.php\">$text[mnulastnames]</a></li>\n"; 
     932        echo "<li class=\"surnames\" style=\"font-weight:bold\"><a href=\"surnames.php\">{$text['mnulastnames']}</a></li>\n"; 
    832933        echo "</ul>\n"; 
    833934        echo "<ul style=\"margin-top:0.75em\">\n"; 
    834         echo "<li class=\"whatsnew\"><a href=\"whatsnew.php\">$text[mnuwhatsnew]</a></li>\n"; 
    835         echo "<li class=\"mostwanted\"><a href=\"mostwanted.php\">$text[mostwanted]</a></li>\n"; 
    836         echo "<li class=\"media\"><a href=\"browsemedia.php\">$text[allmedia]</a>\n"; 
     935        echo "<li class=\"whatsnew\"><a href=\"whatsnew.php\">{$text['mnuwhatsnew']}</a></li>\n"; 
     936        echo "<li class=\"mostwanted\"><a href=\"mostwanted.php\">{$text['mostwanted']}</a></li>\n"; 
     937        echo "<li class=\"media\"><a href=\"browsemedia.php\">{$text['allmedia']}</a>\n"; 
    837938            echo "<ul>\n"; 
    838             echo "<li class=\"photos\"><a href=\"browsemedia.php?mediatypeID=photos\">$text[mnuphotos]</a></li>\n"; 
    839             echo "<li class=\"histories\"><a href=\"browsemedia.php?mediatypeID=histories\">$text[mnuhistories]</a></li>\n"; 
    840             echo "<li class=\"documents\"><a href=\"browsemedia.php?mediatypeID=documents\">$text[documents]</a></li>\n"; 
    841             echo "<li class=\"videos\"><a href=\"browsemedia.php?mediatypeID=videos\">$text[videos]</a></li>\n"; 
    842             echo "<li class=\"recordings\"><a href=\"browsemedia.php?mediatypeID=recordings\">$text[recordings]</a></li>\n"; 
     939            echo "<li class=\"photos\"><a href=\"browsemedia.php?mediatypeID=photos\">{$text['mnuphotos']}</a></li>\n"; 
     940            echo "<li class=\"histories\"><a href=\"browsemedia.php?mediatypeID=histories\">{$text['mnuhistories']}</a></li>\n"; 
     941            echo "<li class=\"documents\"><a href=\"browsemedia.php?mediatypeID=documents\">{$text['documents']}</a></li>\n"; 
     942            echo "<li class=\"videos\"><a href=\"browsemedia.php?mediatypeID=videos\">{$text['videos']}</a></li>\n"; 
     943            echo "<li class=\"recordings\"><a href=\"browsemedia.php?mediatypeID=recordings\">{$text['recordings']}</a></li>\n"; 
    843944            echo "</ul></li>"; 
    844         echo "<li class=\"albums\"><a href=\"browsealbums.php\">$text[albums]</a></li>\n"; 
    845         echo "<li class=\"cemeteries\"><a href=\"cemeteries.php\">$text[mnucemeteries]</a></li>\n"; 
    846         echo "<li class=\"heastones\"><a href=\"browsemedia.php?mediatypeID=headstones\">$text[mnutombstones]</a></li>\n"; 
    847         echo "<li class=\"places\"><a href=\"places.php\">$text[places]</a></li>\n"; 
    848         echo "<li class=\"notes\"><a href=\"browsenotes.php\">$text[notes]</a></li>\n"; 
    849         echo "<li class=\"anniversaries\"><a href=\"anniversaries.php\">$text[anniversaries]</a></li>\n"; 
    850         echo "<li class=\"reports\"><a href=\"reports.php\">$text[mnureports]</a></li>\n"; 
    851         echo "<li class=\"sources\"><a href=\"browsesources.php\">$text[mnusources]</a></li>\n"; 
    852         echo "<li class=\"repos\"><a href=\"browserepos.php\">$text[repositories]</a></li>\n"; 
    853         echo "<li class=\"trees\"><a href=\"browsetrees.php\">$text[mnustatistics]</a></li>\n"; 
    854         echo "<li class=\"language\"><a href=\"changelanguage.php\">$text[mnulanguage]</a></li>\n"; 
     945        echo "<li class=\"albums\"><a href=\"browsealbums.php\">{$text['albums']}</a></li>\n"; 
     946        echo "<li class=\"cemeteries\"><a href=\"cemeteries.php\">{$text['mnucemeteries']}</a></li>\n"; 
     947        echo "<li class=\"heastones\"><a href=\"browsemedia.php?mediatypeID=headstones\">{$text['mnutombstones']}</a></li>\n"; 
     948        echo "<li class=\"places\"><a href=\"places.php\">{$text['places']}</a></li>\n"; 
     949        echo "<li class=\"notes\"><a href=\"browsenotes.php\">{$text['notes']}</a></li>\n"; 
     950        echo "<li class=\"anniversaries\"><a href=\"anniversaries.php\">{$text['anniversaries']}</a></li>\n"; 
     951        echo "<li class=\"reports\"><a href=\"reports.php\">{$text['mnureports']}</a></li>\n"; 
     952        echo "<li class=\"sources\"><a href=\"browsesources.php\">{$text['mnusources']}</a></li>\n"; 
     953        echo "<li class=\"repos\"><a href=\"browserepos.php\">{$text['repositories']}</a></li>\n"; 
     954        echo "<li class=\"trees\"><a href=\"browsetrees.php\">{$text['mnustatistics']}</a></li>\n"; 
     955        echo "<li class=\"language\"><a href=\"changelanguage.php\">{$text['mnulanguage']}</a></li>\n"; 
    855956        if ($allow_admin) { 
    856             echo "<li class=\"showlog\"><a href=\"showlog.php\">$text[mnushowlog]</a></li>\n"; 
    857             echo "<li class=\"admin\"><a href=\"admin/index.php\">$text[mnuadmin]</a></li>\n"; 
    858         } 
    859         echo "<li class=\"bookmarks\"><a href=\"bookmarks.php\">$text[bookmarks]</a></li>\n"; 
    860         echo "<li class=\"suggest\"><a href=\"suggest.php\">$text[contactus]</a></li>\n"; 
     957            echo "<li class=\"showlog\"><a href=\"showlog.php\">{$text['mnushowlog']}</a></li>\n"; 
     958            echo "<li class=\"admin\"><a href=\"admin/index.php\">{$text['mnuadmin']}</a></li>\n"; 
     959        } 
     960        echo "<li class=\"bookmarks\"><a href=\"bookmarks.php\">{$text['bookmarks']}</a></li>\n"; 
     961        echo "<li class=\"suggest\"><a href=\"suggest.php\">{$text['contactus']}</a></li>\n"; 
    861962        echo "</ul>\n"; 
    862963        echo "<ul style=\"margin-top:0.75em\">\n"; 
    863964        if (!is_user_logged_in()) { 
    864             echo "<li class=\"register\" style=\"font-weight:bold\"><a href=\"newacctform.php\">$text[mnuregister]</a></li>\n"; 
    865             echo "<li class=\"login\" style=\"font-weight:bold\"><a href=\"login.php\">$text[mnulogon]</a></li>\n"; 
     965            echo "<li class=\"register\" style=\"font-weight:bold\"><a href=\"newacctform.php\">{$text['mnuregister']}</a></li>\n"; 
     966            echo "<li class=\"login\" style=\"font-weight:bold\"><a href=\"login.php\">{$text['mnulogon']}</a></li>\n"; 
    866967        } else { 
    867968            if (function_exists('wp_logout_url')) 
    868                 echo "<li class=\"logout\" style=\"font-weight:bold\"><a href=\"".html_entity_decode(wp_logout_url())."\">$text[logout]</a></li>\n"; 
     969                echo "<li class=\"logout\" style=\"font-weight:bold\"><a href=\"".html_entity_decode(wp_logout_url())."\">{$text['logout']}</a></li>\n"; 
    869970            else 
    870                 echo "<li class=\"logout\" style=\"font-weight:bold\"><a href=\"".trailingslashit(get_bloginfo('wpurl'))."wp-login.php?action=logout"."\">$text[logout]</a></li>\n"; 
     971                echo "<li class=\"logout\" style=\"font-weight:bold\"><a href=\"".trailingslashit(get_bloginfo('wpurl'))."wp-login.php?action=logout"."\">{$text['logout']}</a></li>\n"; 
    871972        } 
    872973        echo "</ul>"; 
     
    877978//Outputs the TNG theme switcher menu in the sidebar 
    878979function mbtng_output_template_menu ($args) { 
    879     if (mbtng_display_page()) { 
     980    if (mbtng_display_widget()) { 
    880981        extract($args); 
    881982        $templates = mbtng_get_template_list(); 
     
    9021003*                                               * 
    9031004* mbtng_db_connect                              * 
     1005* mbtng_close_tng_table                         * 
     1006* mbtng_requested_url                           * 
     1007* mbtng_is_windows                              * 
    9041008* mbtng_correct_path                            * 
    9051009* mbtng_display_page                            * 
     
    9071011* mbtng_get_template                            * 
    9081012* mbtng_smart_trailingslashit                   * 
     1013* mbtng_folder_trailingslashit                  * 
    9091014* mime_content_type                             * 
    9101015************************************************/ 
     
    9321037    if ($session_charset == 'UTF-8') 
    9331038        @mysql_query("SET NAMES 'utf8'"); 
    934     if( $link && mysql_select_db($database_name)) 
     1039    if( $link && mysql_select_db($database_name, $link)) 
    9351040        return $link; 
    9361041    else { 
     
    9411046} 
    9421047 
     1048// Reselects the Wordpress database table 
     1049function mbtng_close_tng_table () { 
     1050    mysql_select_db (DB_NAME); 
     1051} 
     1052 
     1053//Returns the full URL requested. May need modifying for IIS. 
     1054function mbtng_requested_url () { 
     1055    return "http://".$_SERVER['SERVER_NAME'].urldecode($_SERVER['REQUEST_URI']); 
     1056} 
     1057 
     1058//Returns TRUE if running on Windows 
     1059function mbtng_is_windows () { 
     1060    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') 
     1061        return true; 
     1062    else 
     1063        return false; 
     1064} 
     1065 
    9431066//Returns true if mbtng_path option is correct 
    944 function mbtng_correct_path() { 
     1067function mbtng_correct_path($path='') { 
    9451068    $current_folder = getcwd(); 
    946     @chdir(get_option('mbtng_path')); 
     1069    if ($path == '') 
     1070        $path = get_option('mbtng_path'); 
     1071    @chdir($path); 
    9471072    if (file_exists('begin.php') && file_exists('admin') && file_exists('genlib.php')) { 
    9481073        chdir($current_folder); 
     
    9591084        return false; 
    9601085    else { 
    961         $requested = urldecode($_SERVER['REQUEST_URI']); 
     1086        $requested = mbtng_requested_url(); 
    9621087        $query_pos = strrpos($requested, '?')+1; 
    9631088        if ($query_pos !== 1) 
    9641089            $requested = substr($requested, 0, $query_pos-1); 
    965         if (stripos (get_bloginfo('wpurl').trailingslashit($requested), get_option('mbtng_url')) !== FALSE) { 
     1090        if (stripos ($requested, get_option('mbtng_url')) !== FALSE) { 
    9661091            $template=mbtng_get_template(); 
    9671092            $tng_folder = get_option('mbtng_path'); 
     
    10241149        $url = rtrim($url, '/'); 
    10251150    return $url; 
     1151} 
     1152 
     1153//Adds a server-specific slash for folders 
     1154function mbtng_folder_trailingslashit ($folder) { 
     1155    if (mbtng_is_windows()) 
     1156        return rtrim($folder, '\\').'\\'; 
     1157    else 
     1158        return trailingslashit($folder); 
    10261159} 
    10271160 
     
    10961229/* TO DO 
    10971230======== 
    1098 Get it working with IIS & non-pretty permalinks 
     1231Make it work in a subfolder 
     1232Get it working with non-pretty permalinks 
     1233Fix template switcher when not logged in 
    10991234Find error in cemetries page 
    1100 Intercept WP logins, and update TNG password where appropriate 
    11011235Make it work with the home page 
    11021236Serve default template if template switcher widget not installed 
Note: See TracChangeset for help on using the changeset viewer.