Changeset 505

Show
Ignore:
Timestamp:
07/16/07 00:36:17 (16 months ago)
Author:
michiel
Message:

make the AJAX based search work again without the normal multi-blog common/hosts.php
Also some whitespace fixes, that's why the commit is so damn huge
Re #139 and #140

Location:
team/michiel/remove_multi_blog/common
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • team/michiel/remove_multi_blog/common/js/liveRequest.js

    r1 r505  
    1 var inputId = 'search';  
     1var inputId = 'search'; 
    22                                        // This is the id on the input/textarea that you want to use as the query. 
    3                                                                          
     3 
    44var outputId = 'searchresults'; 
    55                                        // use this to have the results populate your own ID'd tag. 
    66                                        // leave it blank and a div tag will automatically be added 
    77                                        // with an id="liveSearchResults" 
    8                                                                          
     8 
    99var processURI    = 'common/livesearch.php'; 
    1010                                        // this is the file that you request data from. 
    11                                                                          
     11 
    1212var emptyString   = ''; 
    1313                                        // What to display in the results field when there's nothing 
     
    4747 
    4848function liveReqInit() { 
    49          
     49 
    5050        inputElement  = document.getElementById(inputId); 
    5151        outputElement = document.getElementById(outputId); 
    52          
    53         if( inputElement == null || outputElement == null )  
     52 
     53        if( inputElement == null || outputElement == null ) 
    5454                return; 
    55          
    56          
     55 
     56 
    5757        if (navigator.userAgent.indexOf("Safari") > 0) { 
    5858                inputElement.addEventListener("keydown",liveReqStart,false); 
    59                  
     59 
    6060        } else if (navigator.product == "Gecko") { 
    6161                inputElement.addEventListener("keypress",liveReqStart,false); 
    62                  
     62 
    6363        } else { 
    6464                inputElement.attachEvent('onkeydown',liveReqStart); 
    6565                isIE = true; 
    6666        } 
    67          
     67 
    6868        if(emptyString == '') { 
    6969                // set the result field to hidden, or to default string 
     
    9393                        liveReq = new ActiveXObject("Microsoft.XMLHTTP"); 
    9494                } 
    95                  
     95 
    9696                liveReq.onreadystatechange = liveReqProcessReqChange; 
     97                var uri = processURI + "?s=" + encodeURI(inputElement.value); 
    9798                liveReq.open("GET", processURI + "?s=" + encodeURI(inputElement.value)); 
    9899                liveReqLast = inputElement.value; 
  • team/michiel/remove_multi_blog/common/livesearch.php

    r504 r505  
    1818 * @copyright 2005-2007 Michiel van Baak 
    1919 */ 
    20 function db_init() { 
    21         session_start(); 
    22         require("MDB2.php"); 
    23         require("hosts.php"); 
     20require("mvblog.php"); 
     21$mvblog = new MvBlog(); 
     22//get all the authors in an array 
     23$res =& $mvblog->db->query("SELECT * FROM authors"); 
    2424 
    25         $options = array( 
    26                 "debug"       => 2, 
    27                 "portability" => MDB2_PORTABILITY_ALL, 
    28         ); 
     25if (PEAR::isError($res)) { 
     26        die($res->getMessage()); 
     27} 
    2928 
    30         $db =& MDB2::connect($dsn, $options); 
    31         if (PEAR::isError($db)) { 
    32                 die($db->getMessage()); 
    33         } 
    34         $_SESSION["filepath"] = $filepath; 
    35         return $db; 
     29while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { 
     30        $authors[$row["id"]]["fullname"] = $row["fullname"]; 
     31        $authors[$row["id"]]["email"]    = $row["email"]; 
    3632} 
    37 ob_start(); 
    38 $db = db_init(); 
    39  
    40  
    4133 
    4234$searchstring = urldecode($_REQUEST["s"]); 
     
    4941$query .= " ORDER BY date DESC"; 
    5042 
    51 $db->setLimit(5); 
    52 $res =& $db->query($query); 
     43$mvblog->db->setLimit(5); 
     44$res =& $mvblog->db->query($query); 
    5345$ret = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
    5446$ret .= "<channel>\n"; 
  • team/michiel/remove_multi_blog/common/mvblog_common.php

    r490 r505  
    258258        protected function _init_db($settings = "") { 
    259259                require_once("MDB2.php"); 
    260                 if (!is_array($settings)) { 
    261                         require_once("hosts.php"); 
     260                //sqlite has a different scheme, because it's filebased 
     261                if ($settings["type"] == "sqlite") { 
     262                        if (is_dir("db")) 
     263                                $dsn = sprintf("%s:///db/%s.db?mode=0666", $settings["type"], $settings["database"]); 
     264                        elseif (is_dir("../db")) 
     265                                $dsn = sprintf("%s:///../db/%s.db?mode=0666", $settings["type"], $settings["database"]); 
    262266                } else { 
    263                         //sqlite has a different scheme, because it's filebased 
    264                         if ($settings["type"] == "sqlite") { 
    265                                 if (is_dir("db")) 
    266                                         $dsn = sprintf("%s:///db/%s.db?mode=0666", $settings["type"], $settings["database"]); 
    267                                 elseif (is_dir("../db")) 
    268                                         $dsn = sprintf("%s:///../db/%s.db?mode=0666", $settings["type"], $settings["database"]); 
    269                         } else { 
    270                                 $dsn = $settings["type"]."://".$settings["username"].":".$settings["password"]."@tcp(".$settings["hostname"].")/".$settings["database"]; 
    271                                 $dsn = sprintf("%s://%s:%s@tcp(%s)/%s", 
    272                                         $settings["type"], $settings["username"], $settings["password"], 
    273                                         $settings["hostname"], $settings["database"]); 
    274                         } 
     267                        $dsn = $settings["type"]."://".$settings["username"].":".$settings["password"]."@tcp(".$settings["hostname"].")/".$settings["database"]; 
     268                        $dsn = sprintf("%s://%s:%s@tcp(%s)/%s", 
     269                                $settings["type"], $settings["username"], $settings["password"], 
     270                                $settings["hostname"], $settings["database"]); 
    275271                } 
    276272 
     
    498494                if (array_key_exists("style", $_REQUEST)) { 
    499495                        /* Overwrite the style set in the session from the request */ 
    500                         $_SESSION["style"] = $this->_sanitize($_REQUEST["style"]);  
     496                        $_SESSION["style"] = $this->_sanitize($_REQUEST["style"]); 
    501497                } 
    502498                if (!array_key_exists("style", $_SESSION)) {