Page 1 of 2

Search Engine Melodrama

Posted: Thu Mar 04, 2021 1:46 am
by Midnighter
Glad to see the forum back online, but the search is still broken! :?

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 11:40 am
by Russ Chappell
Alas, the search may be over, unless some enterprising niece or nephew out there wants to take a deep dive into it.

The search program was originally written by Jimmy Petersson in an old-old version of python to build a script in an old, old version of php, and I've learned enough about php to cobble together updates, as we've changed the structures of the listings. But that older version of php is no longer available, and I don't have the time to devote to rewrite it for php 7.0, which is what the site operates under now (and at some point in the not distant future, you can expect us to migrate to php 8.0).

If some enterprising soul wants to develop something, I'll be glad to send you the source code that we've been using to scrape the data and build a search database (but be forewarned: you need to know a little bit about python, and more than a little bit about php). Barring that, it may be a fond farewell to the search.

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:18 pm
by Russ Chappell
Here's some of the relevant parts:

Code: Select all

Search for characters:
<FORM METHOD="get" ACTION="xzsearchthemcp.php">
<INPUT TYPE="text" SIZE="20" NAME="searchForCharacters">
<INPUT TYPE="submit" VALUE="Search">
</FORM>
Go to comic:
<FORM ID="comicform" METHOD="get" NAME="gocomic" ACTION="xzsearchthemcp.php">
<INPUT TYPE="text" SIZE="20" NAME="searchForComic" ID="comic" VALUE=""/>
<INPUT TYPE="submit" VALUE="Go">
</FORM>
...more to come

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:19 pm
by Russ Chappell

Code: Select all

<?php
$figure = $_GET["figure"];
$searchForFigures = $_GET["searchForCharacters"];
$searchForComic = $_GET["searchForComic"];
$comic = $_GET["comic"];
include("mcpfunctions.php");
if($figure != NULL)
   getFigure($figure);
elseif($searchForFigures != NULL)
   searchForFigures($searchForFigures);
elseif($searchForComic != NULL)
   searchForComic($searchForComic);
elseif($comic != NULL)
   getComic($comic)
?>

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:21 pm
by Russ Chappell

Code: Select all

function openConnection() {
   $host = "blahbahblah";
   $login = "blahblahblah";
   $dbname = "blahblahblah";
   $password = "blahblahblah";
   $db = mysqli_connect($host, $login, $password, $dbname) or errorManagement();
   return $db;
}


Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:22 pm
by Russ Chappell

Code: Select all

function errorManagement($db = "") {
   if (!empty($db)) {
      if ($db->connect_errno) {
         echo "<p>Failed to connect to MySQL: ({$db->connect_errno}){$db->connect_error}</p>";
      }
   }
   echo "<p><a href=\"javascript:history.go(-1)\">Back</a><p>";
   exit();
}

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:23 pm
by Russ Chappell

Code: Select all

function searchForComic($comic) {
   $db = openConnection();
   $comic = $db->real_escape_string($comic);
   $sql = "SELECT * FROM mcp_comics WHERE abbreviation='{$comic}' ORDER BY appendix,figid,entry_index";
   $result = $db->query($sql) or errorManagement($db);
   publishComic($result, $db);
   $result->close();
   $db->close();
}

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:24 pm
by Russ Chappell

Code: Select all

function searchForFigures($searchString) {
   $db = openConnection();
   $searchString = $db->real_escape_string($searchString);
   $sql = "SELECT name,link,dimension FROM mcp_figures WHERE search_name LIKE '%{$searchString}%' OR name LIKE '%{$searchString}%'";
   $result = $db->query($sql) or errorManagement($db);
   echo "<p>Results for '{$searchString}':</p>";
   while($figureobj = $result->fetch_object()) {
      if($figureobj->dimension != "standard") {
         echo "<a href=\"{$figureobj->link}\">{$figureobj->name} ({$figureobj->dimension})</a><br>";
      }
      else {
         echo "<a href=\"{$figureobj->link}\">{$figureobj->name}</a><br>";
      }
   }
   $result->close();
   $db->close();
}

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:25 pm
by Russ Chappell

Code: Select all

function getFigure($index) {
   $db = openConnection();
   $index = $db->real_escape_string($index);
   $sql = "SELECT * FROM figures3 WHERE ind IN ({$index})";
   $result = $db->query($sql) or errorManagement($db);
   if($figureobj = $result->fetch_object()) {
      echo str_replace("\'", "\"", $figureobj->html);
      echo str_replace("\'", "\"", "{$figureobj->list}</b>");
   }
   else
      echo "Could not find the figure.<br>";
   echo "<p>";
   $result->close();
   $db->close();
}

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:25 pm
by Russ Chappell

Code: Select all

function getComic($index) {
   $db = openConnection();
   $index = $db->real_escape_string($index);
   $sql = "SELECT * FROM mcp_comics WHERE comicid='{$index}' ORDER BY appendix,figid,entry_index";
   $result = $db->query($sql) or errorManagement($db);
   publishComic($result, $db);
   $result->close();
   $db->close();
}

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:26 pm
by Russ Chappell

Code: Select all

function addLinksToRaw($comicobj, $rawstr, $comics, $linkCurrent) {
   if ($rawstr == "") {
      return "&nbsp;";
   }
   $linkstr = $rawstr;
   for ( $c = 0; $c < sizeof($comics); $c += 1) {
      $ca = preg_split("/\|/", $comics[$c]);
      if (!($ca[0] == $comicobj->abbreviation && $ca[2] == $comicobj->appendix && ! $linkCurrent)) {
         $linkstr = str_replace($ca[0], "<a href=\"?comic={$ca[1]}#{$ca[2]}{$comicobj->figid}\">{$ca[0]}</a>", $linkstr);
      }
   }
   return $linkstr;
}

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:28 pm
by Russ Chappell

Code: Select all

function publishComic($comic, $db) {

   $comicFound = false;
   $current_appendix = -1;
   $color = false;
   while($comicobj = $comic->fetch_object()) {
      if (!$comicFound) {
         $comicFound = true;
         echo "<table class=\"comictable\" cellspacing=0 cellpadding=4><tr><th></th><th>Previous</th><th colspan=2>Current</th><th>Next</th></tr>";
         $comicid = $db->real_escape_string($comicobj->comicid);
         $sql = "SELECT full_name FROM mcp_comics_fullname WHERE comicid='{$comicid}'";
         $result = $db->query($sql) or errorManagement($db);
         if($fullname = $result->fetch_object()) {
            echo "<b>{$fullname->full_name}</b>";
         }
         $result->close();
      }
      if( $comicobj->appendix != $current_appendix ) {
         if ($current_appendix != -1) {
             echo "<tr class=\"space_row\"><td colspan=5>&nbsp;</td></tr>";
         }
         $current_appendix = $comicobj->appendix;
         $color = false;
         echo "<tr id=\"{$current_appendix}\" class=\"comic_title_row\"><td><b>{$comicobj->abbreviation} {$comicobj->appendix}</b></td><td colspan=4>&nbsp;</td></tr>";
      }

      if( $color ) {
              echo "<tr id=\"{$current_appendix}{$comicobj->figid}\" class=\"color_row figrow\">";
      }
      else {
        echo "<tr id=\"{$current_appendix}{$comicobj->figid}\" class=\"figrow\">";
      }
      $figid = $db->real_escape_string($comicobj->figid);
      $sql = "SELECT name,link,dimension FROM mcp_figures WHERE figid='{$figid}'";
      $figresult = $db->query($sql) or errorManagement($db);
      if($figureobj = $figresult->fetch_object()) {
         if($figureobj->dimension != "standard") {
            echo "<td><a href=\"{$figureobj->link}\">{$figureobj->name} ({$figureobj->dimension})</a></td>";
         }
         else {
            echo "<td><a href=\"{$figureobj->link}\">{$figureobj->name}</a></td>";
         }
      }
      $figresult->close();

      $prev_str = addLinksToRaw($comicobj, $comicobj->previous_raw, explode("#", $comicobj->previous_comics), true);
      echo "<td>{$prev_str}</td>";

      $current_str = addLinksToRaw($comicobj, $comicobj->current_raw, explode("#", $comicobj->current_comics), false);
	  $entryindplus = $comicobj->entry_index+1;
	  echo "<td alight=\"right\">{$entryindplus}</td><td>{$current_str}</td>";

      $next_str = addLinksToRaw($comicobj, $comicobj->next_raw, explode("#", $comicobj->next_comics), true);
      echo "<td>{$next_str}</td>";

      $color = !$color;

   }
   if(!$comicFound) {
      echo "<table><tr><td>Could not find the comic.</td></tr>";
   }
   echo "</table>";

}

D'ja miss me?

Posted: Thu Mar 04, 2021 3:28 pm
by Russ Chappell
This worked under php 5, but php 7? :(

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 3:35 pm
by michel
Which PHP version did last work ? Have you any error message pointing to the code that doesn't work ?

Edit : you just answered, php 5.0

Re: D'ja miss me?

Posted: Thu Mar 04, 2021 4:34 pm
by Russ Chappell
No error at all, it just...doesn't work. You can try it yourself. No matter what you search for, you just get a link that takes you back to the search page.