Jump to content

rtrdogs

New Members
  • Posts

    7
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

rtrdogs's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. My site has been working fine for years but, all of a sudden, is throwing server errors on the pages that call for PHP includes. My provider isn't saying whether there's been an update but the fact that the site has always worked fine and now isn't, well... So, here's some sample code from a .html page that calls for the TPL file: <?php include('/home/MyPath/public_html/MySite.com/tpl/footer.tpl'); ?> A long time ago, I was told to put this in my htaccess file: AddType application/x-httpd-php5 .html AddHandler application/x-httpd-php5 .html If I delete both of these lines from the htaccess file, the site will load without the internal server error but my includes don't work at all. There's just an empty space where the content from the tpl file is supposed to be. I know they installed php 5.4 but my site was automatically put on 5.2 as a default. I submitted a ticket with my provider and this was the response. This is the error message as it is being recorded from the server itself when the domain returns a 500 error: [root@provider /home1/MyPath/public_html/mysite.com]# grep mysite.com /usr/local/apache/logs/error_log |tail -6 [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Cannot load the ionCube PHP Loader - it was built with configuration 2.2.0, whereas running engine is API220100525,NTS, referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Zend Optimizer requires Zend Engine API version 220060519., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] The Zend Engine API version 220100525 which is installed, is newer., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Optimizer., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] , referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] malformed header from script. Bad header=<br />: index.html, referer: http://www.mysite.com/ This will be because there is a mismatch between the php version being called and the php.ini that is being loaded for the domain. Reviewing the mod_rewrite statements that call the various php versions within the direct file path to your domain shows the following: [root@provider /home1/MyPath/public_html/mysite.com]# grep -H -A 3 -B 1 'AddHand' /home1/MyPath/.htaccess /home1/MyPath/public_html/.htaccess /home1/MyPath/public_html/mysite.com/.htaccess /home1/MyPath/.htaccess-# Use PHP52 as default /home1/MyPath/.htaccess:AddHandler application/x-httpd-php52 .php /home1/MyPath/.htaccess-<IfModule mod_suphp.c> /home1/MyPath/.htaccess- suPHP_ConfigPath /opt/php52/lib /home1/MyPath/.htaccess-</IfModule> -- /home1/MyPath/public_html/mysite.com/.htaccess-#AddType application/x-httpd-php5 .html /home1/MyPath/public_html/mysite.com/.htaccess:#AddHandler application/x-httpd-php5 .html /home1/MyPath/public_html/mysite.com/.htaccess- /home1/MyPath/public_html/mysite.com/.htaccess- /home1/MyPath/public_html/mysite.com/.htaccess-## You would need to also declare the suphp for the php.ini to be used and upload a version matching php.ini to that location. I am completely lost as to what this means. I don't even know where to begin. Can someone please help me so I can get my site back to normal? Thank you in advance!
  2. Just following a suggestion I read on another forum from someone who had a similar problem to mine. It didn't work for them either.
  3. I have 3 files I'm working with from a news management script. I'm trying to get a PHP file that shows three news headlines to appear on a TPL file. Includes aren't working in TPL files within this news management system, although I have PHP includes in my own TPL files that are parsing just fine throughout my site. So what I've got here is index.php, header.php and then an index.tpl file. I've created booknews.php that shows the newest three headlines. First, a snippet from the index.php file that I've added the $booknews value to but not sure if it's doing anything. I've added stars like: ***** around the code so you can see what I've changed. function main($offset, $limit) { global $logo, $adminarea, $skin, $home, $recent, ***** $booknews, ***** $bookauthor, $catslink, $authors, $help, $search, $login, $titles, $logout, $itemsperpage, $columns; include ("header.php"); $result = mysql_query("SELECT welcome, copyright from news_settings"); $settings = mysql_fetch_array($result); //make a new TemplatePower object $tpl = new TemplatePower( "skins/$skin/index.tpl" ); $tpl->assignInclude( "newsbox", "./skins/$skin/newsbox.tpl" ); //let TemplatePower do its thing, parsing etc. $tpl->prepare(); //assign a value to {name} $tpl->assign( "welcome", $settings[welcome] ); $tpl->assign( "footer", $settings[copyright] ); $tpl->assign( "logo", $logo ); $tpl->assign( "home", $home ); $tpl->assign( "recent", $recent ); ***** $tpl->assign( "booknews", $booknews ); ***** $tpl->assign( "bookauthor", $bookauthor ); $tpl->assign( "catslink", $catslink ); $tpl->assign( "authors", $authors ); $tpl->assign( "help", $help ); $tpl->assign( "search", $search ); $tpl->assign( "login", $login ); $tpl->assign( "adminarea", $adminarea ); $tpl->assign( "titles", $titles ); $tpl->assign( "logout", $logout ); if (empty($offset) || $offset < 0) { $offset=0; } if (empty($index)) $index=0; $limit = $itemsperpage; $result2 = mysql_query("SELECT *,DATE_FORMAT(time, '%m/%d/%Y - %h:%i%p') as date FROM news_news ORDER BY nid DESC LIMIT $offset,$limit"); $count = mysql_query("SELECT count(*) FROM news_news ORDER BY nid DESC"); list($numrows)= mysql_fetch_array($count); $index++; while($stories = mysql_fetch_array($result2)) { //create a new number_row block $tpl->newBlock("newsbox"); //assign values $tpl->assign("newstitle" , $stories[title] ); $tpl->assign("newsstory" , $stories[story] ); $tpl->assign("newsauthor", $stories[author] ); $tpl->assign("newsdate", $stories[date] ); } (I truncated the code here for length purposes but if you need to see the rest, just let me know.) Snippet from header.php include ($databasepath."/dbconfig.php"); include ("lib/class.TemplatePower.inc.php"); include ("languser.php"); $home = "<a class=\"menu\" href=\"index.php\">"._HOME."</a>"; $catslink = "<a class=\"menu\" href=\"categories.php\">"._CATEGORIES."</a>"; $bookauthor = "<a class=\"menu\" href=\"byauthor.php\">"._BOOKAUTHOR."</a>"; ***** $booknews = "<a class=\"menu\" href=\"booknews.php\">"._BOOKNEWS."</a>"; ***** $recent = "<a class=\"menu\" href=\"search.php?action=recent\">"._RECENTLYADDED."</a>"; $authors = "<a class=\"menu\" href=\"authors.php?action=list\">"._AUTHORS."</a>"; $help = "<a class=\"menu\" href=\"help.php\">"._HELP."</a>"; $search = "<a class=\"menu\" href=\"search.php\">"._SEARCH."</a>"; $titles = "<a class=\"menu\" href=\"titles.php\">"._TITLES."</a>"; The code above, displays the _BOOKNEWS link just fine. I've tried a few variations to show the booknews.php include file. Like: $booknews = require_once("booknews.php"); or $booknews = include ("booknews.php"); Nothing shows up in the area where the link shows up just fine. How index.tpl calls for booknews: {booknews} Not really sure where to go from here. I've searched for hours, tried variations and I'm just completely stumped.
  4. Unfortunately, that gives me the error: Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE or T_CONST in /path/to/search/api.php on line 288 When I change the code to: function separate($roots, $urls,) &$int_pages = Array(), &$int_loads = Array(), &$ext_pages = Array(), &$ext_loads = Array(), &$extensions = Array('', 'asp', 'aspx', 'cgi', 'htm', 'html', 'php') Without the second ')' at the end of the last line, I get: Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE or T_CONST in /path/to/api.php on line 288 I'm not sure what the problem is. I've tried the developer's demo and it works fine. I've contacted him to see if I can get a file replacement because it's obviously working on his site. Any other changes you can see that need to be made before I ditch the script and search for a new one?
  5. Hmm, well that gives me: Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE or T_CONST in /path/to/api.php on line 288
  6. Hi there, The error I posted is: Parse error: syntax error, unexpected '=', expecting ')' in path/to/api.php on line 289 Hope that helps and thanks!
  7. Hello, I just downloaded a script from hotscripts and when I upload the files, I get this error: Parse error: syntax error, unexpected '=', expecting ')' in path/to/api.php on line 289 Can someone help me locate the unexpected "=" please? I don't have dreamweaver to find the line # and when I went through all of the "=" signs in wordpad, I couldn't identify the bad code it was referring to. I appreciate the help in advance. <?php // Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved. // Technical support: http://www.php-development.ru/ // // YOU MAY NOT // (1) Remove or modify this copyright notice. // (2) Distribute this code, any part or any modified version of it. // Instead, you can link to the homepage of this code: // http://www.php-development.ru/php-scripts/search-engine.php // (3) Use this code as a part of another product. // If you want to do it you should receive my permission. // // YOU MAY // (1) Use this code on your website. // // NO WARRANTY // This code is provided "as is" without warranty of any kind, either // expressed or implied, including, but not limited to, the implied warranties // of merchantability and fitness for a particular purpose. You expressly // acknowledge and agree that use of this code is at your own risk. // ***** Parse HTML ************************************************************ function enclose($start, $end1, $end2) { return "$start((?:[^$end1]|$end1(?!$end2))*)$end1$end2"; } function parse($html, &$title, &$text, &$anchors, $start = false, $end = false) { $pstring1 = "'[^']*'"; $pstring2 = '"[^"]*"'; $pnstring = "[^'\">]"; $pintag = "(?:$pstring1|$pstring2|$pnstring)*"; $pattrs = "(?:\\s$pintag){0,1}"; $pcomment = enclose("<!--", "-", "->"); $pscript = enclose("<script$pattrs>", "<", "\\/script>"); $pstyle = enclose("<style$pattrs>", "<", "\\/style>"); $pexclude = "(?:$pcomment|$pscript|$pstyle)"; $ptitle = enclose("<title$pattrs>", "<", "\\/title>"); $panchor = "<a(?:\\s$pintag){0,1}>"; $phref = "href\\s*=[\\s'\"]*([^\\s'\">]*)"; if ($title !== false) $title = preg_match("/$ptitle/iX", $html, $title) ? $title[1] : ''; if ($text !== false) { $text = $html; if ($start !== false && ($pos = strpos($text, $start)) !== false) $text = substr($text, $pos+strlen($start)); if ($end !== false && ($pos = strpos($text, $end )) !== false) $text = substr($text, 0, $pos); $text = preg_replace("/$pexclude/iX", " ", $text); $text = preg_replace("/<$pintag>/iX", " ", $text); $text = preg_replace("/\\s+| /iX", " ", $text); } if ($anchors !== false) { $html = preg_replace("/$pexclude/iX", " ", $html); preg_match_all("/$panchor/iX", $html, $anchors); $anchors = $anchors[0]; reset($anchors); while (list($i, $x) = each($anchors)) $anchors[$i] = preg_match("/$phref/iX", $x, $x) ? $x[1] : ''; $anchors = array_unique($anchors); } } // ***** URL Functions ********************************************************* // ***** Parse URL ***** function url_parse($url) { $error_reporting = error_reporting(E_ERROR | E_PARSE); $url = parse_url($url); error_reporting($error_reporting); return $url; } // ***** Extract Scheme ***** function url_scheme($url, $scheme = 'http') { if(!($url = url_parse($url))) return $scheme; return isset($url['scheme']) ? $url['scheme'] : $scheme; } // ***** Extract Host ***** define('URL_HOST_DEFAULT', 0); define('URL_HOST_APPEND', 1); define('URL_HOST_STRIP', 2); function url_host($url, $www = 0, $lower = true) { if(!($url = url_parse($url))) return ''; $url = $lower ? strtolower($url['host']) : $url['host']; if ($www == URL_HOST_APPEND && strpos($url, 'www.') !== 0) return 'www.' . $url; if ($www == URL_HOST_STRIP && strpos($url, 'www.') === 0) return substr($url, 4); return $url; } // ***** Extract Path ***** function url_path($url) { if(!($url = url_parse($url))) return ''; $url = isset($url['path']) ? explode('/', $url['path']) : Array(); if (reset($url) === '') array_shift($url); if (end ($url) === '' || strpos(end($url), '.') !== false) array_pop($url); return implode('/', $url); } // ***** Extract Filename ***** function url_file($url, $convert = Array()) { if(!($url = url_parse($url))) return ''; $url = isset($url['path']) ? end(explode('/', $url['path'])) : ''; $url = (strpos($url, '.') !== false) ? $url : ''; foreach ($convert as $i => $x) $url = preg_replace($i, $x, $url); return $url; } // ***** Extract Extension ***** function url_ext($url, $convert = Array()) { if(!($url = url_parse($url))) return ''; $url = isset($url['path']) ? end(explode('/', $url['path'])) : ''; $url = (strpos($url, '.') !== false) ? end(explode('.', $url)) : ''; foreach ($convert as $i => $x) $url = preg_replace($i, $x, $url); return $url; } // ***** Extract Query ***** define('URL_QUERY_NOESCAPE', 0); define('URL_QUERY_ESCAPE', 1); function url_query($url, $escape = 0, $exclude = Array()) { if(!($url = url_parse($url))) return ''; if (!isset($url['query'])) return ''; $url = preg_split('/(&(?!amp;)|&)/', $url['query']); foreach ($url as $i => $x) { $x = explode('=', $x); if (!in_array($x[0], $exclude)) unset($url[$i]); } sort($url); return implode($escape ? '&' : '&', $url); } // ***** Concat ***** function url_concat($base, $rel) { $scheme = url_scheme($base); $host = url_host ($base); $path = url_path ($base); if ($rel{0} == '/') return "$scheme://$host$rel"; else if ($path === '') return "$scheme://$host/$rel"; else return "$scheme://$host/$path/$rel"; } // ***** Normalize ***** function url_normalize($url, $scheme = 'http', $www = 0, $convert = Array(), $escape = 0, $exclude = Array()) { $scheme = url_scheme($url, $scheme); $host = url_host ($url, $www); $path = url_path ($url); $file = url_file ($url, $convert); $query = url_query ($url, $escape, $exclude); if ($scheme === '' || $host === '') return ''; if ($path === '') return "$scheme://$host/$file" . ($query ? "?$query" : ""); else return "$scheme://$host/$path/$file" . ($query ? "?$query" : ""); } // ***** Index Website ********************************************************* define('INDEX_HOST_DEFAULT', 0); define('INDEX_HOST_APPEND', 1); define('INDEX_HOST_STRIP', 2); function index($roots, &$urls, $max, $ext_parse, $www, $convert, $exclude, &$titles, &$texts, $extensions, $start, $end) { $time = microtime(true); $parsed = 0; foreach ($urls as $i => $url) $urls[$i] = url_normalize($url, 'http', $www, $convert, URL_QUERY_NOESCAPE, $exclude); for ($ind = 0; isset($urls[$ind]); $ind++) { if (trim($urls[$ind]) === '') { unset($urls[$ind]); continue; } // ***** Check URL ***** $in_root = false; foreach ($roots as $i => $root) $in_root = $in_root || strpos($urls[$ind], $root) === 0; if (!$in_root) { if (!$ext_parse) continue; if ($titles === false && $texts === false) continue; } if (!in_array(url_ext($urls[$ind]), $extensions)) continue; // ***** Get Contents ***** $error_reporting = error_reporting(E_ERROR | E_PARSE); $html = file_get_contents($urls[$ind]); error_reporting($error_reporting); if ($html === false) { unset($urls[$ind]); continue; } // ***** Parse URL ***** $parsed++; $title = $titles !== false; $text = $texts !== false; parse($html, $title, $text, $anchors, $start, $end); if ($titles !== false) $titles[$ind] = $title; if ($texts !== false) $texts [$ind] = $text; // ***** Extract Anchors ***** if (!$in_root ||count($urls) > $max) continue; foreach ($anchors as $i => $x) { $x = preg_replace("/#.*/X", "", $x); if ($x == '' || preg_match("/^(\\w)+?!\/\/)/X", $x)) continue; if (!preg_match("/^(\\w)+:\/\//X", $x)) $x = url_concat($urls[$ind], $x); $x = url_normalize($x, 'http', $www, $convert, URL_QUERY_NOESCAPE, $exclude); if (!in_array($x, $urls) && (count($urls) < $max)) $urls[] = $x; } } return Array("time" => microtime(true)-$time, "parsed" => $parsed); } // ***** Separate Links ******************************************************** function separate($roots, $urls, &$int_pages = Array(), &$int_loads = Array(), &$ext_pages = Array(), &$ext_loads = Array(), $extensions = Array('', 'asp', 'aspx', 'cgi', 'htm', 'html', 'php')) { foreach ($urls as $i => $url) { if (trim($url) === '') continue; $in_root = false; foreach ($roots as $j => $root) $in_root = $in_root || strpos($url, $root) === 0; if ($in_root) { if (in_array(url_ext($url), $extensions)) $int_pages[$i] = $url; else $int_loads[$i] = $url; } else { if (in_array(url_ext($url), $extensions)) $ext_pages[$i] = $url; else $ext_loads[$i] = $url; } } } // ***** Debug Query *********************************************************** function mysql_query_debug($str) { $result = mysql_query($str); if (mysql_error()) echo "<hr /><b>Message:</b> " . mysql_error() . "<br /><b>Query:</b> $str<hr />"; return $result; } // ***** TMySQL_KeyVal ********************************************************* class TMySQL_KeyVal { var $tbl = null; var $prefix = null; // ***** Init ***** function Init($tbl, $prefix) { $this->tbl = $tbl; $this->prefix = $prefix; } // ***** CreateTable ***** function CreateTable($drop = false) { if ($drop) mysql_query_debug("drop table if exists {$this->tbl}"); mysql_query_debug( "create table {$this->tbl} ({$this->prefix}id integer unsigned not null auto_increment, {$this->prefix}hash integer unsigned not null default 0, {$this->prefix}key varchar(255) not null unique, {$this->prefix}val text not null, {$this->prefix}weight integer unsigned not null default 0, {$this->prefix}time integer unsigned not null default 0, index {$this->prefix}hash ({$this->prefix}hash), primary key ({$this->prefix}id), fulltext ({$this->prefix}val)) engine = myisam"); } // ***** Set ***** function Set($key, $val, $weight = false) { $hash = '0x' . substr(md5($key), 0, ; $key = mysql_real_escape_string($key); $val = mysql_real_escape_string($val); $time = time(); $result = mysql_query_debug( "select * from {$this->tbl} where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); if (!mysql_num_rows($result)) { mysql_query_debug( "insert into {$this->tbl} ({$this->prefix}hash, {$this->prefix}key, {$this->prefix}val, {$this->prefix}time) values ($hash, '$key', '', $time)"); $result = mysql_query_debug( "select * from {$this->tbl} where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); } $id = mysql_fetch_assoc($result); $id = $id["{$this->prefix}id"]; if ($weight === false) { mysql_query_debug("update {$this->tbl} set {$this->prefix}val = '$val' where {$this->prefix}id = $id"); return $id; } if ($weight === true) { mysql_query_debug("update {$this->tbl} set {$this->prefix}val = '$val', {$this->prefix}weight = {$this->prefix}weight+1 where {$this->prefix}id = $id"); return $id; } $weight = (integer)$weight; mysql_query_debug("update {$this->tbl} set {$this->prefix}val = '$val', {$this->prefix}weight = $weight where {$this->prefix}id = $id"); return $id; } // ***** Get ***** function Get($key, $weight = false) { $val = $this->GetByKey($key, $weight); return $val ? $val['val'] : false; } // ***** GetById ***** function GetById($id, $weight = false) { $id = (integer)$id; $result = mysql_query_debug( "select {$this->prefix}id 'id', {$this->prefix}key 'key', {$this->prefix}val 'val', {$this->prefix}weight 'weight', {$this->prefix}time 'time' from {$this->tbl} where {$this->prefix}id = $id"); $result = mysql_fetch_assoc($result); if ($result && $weight) mysql_query_debug("update {$this->tbl} set {$this->prefix}weight = {$this->prefix}weight+1 where {$this->prefix}id = {$result['id']}"); return $result; } // ***** GetByIds ***** function GetByIds($ids) { if (count($ids) == 0) return Array(); $ids = "(" . implode(",", $ids) . ")"; $result = mysql_query_debug( "select {$this->prefix}id 'id', {$this->prefix}key 'key', {$this->prefix}val 'val', {$this->prefix}weight 'weight', {$this->prefix}time 'time' from {$this->tbl} where {$this->prefix}id in $ids"); $data = Array(); while($row = mysql_fetch_assoc($result)) $data[$row['id']] = $row; return $data; } // ***** GetByKey ***** function GetByKey($key, $weight = false) { $hash = '0x' . substr(md5($key), 0, ; $key = mysql_real_escape_string($key); $result = mysql_query_debug( "select {$this->prefix}id 'id', {$this->prefix}key 'key', {$this->prefix}val 'val', {$this->prefix}weight 'weight', {$this->prefix}time 'time' from {$this->tbl} where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); $result = mysql_fetch_assoc($result); if ($result && $weight) mysql_query_debug("update {$this->tbl} set {$this->prefix}weight = {$this->prefix}weight+1 where {$this->prefix}id = {$result['id']}"); return $result; } // ***** GetAll ***** function GetAll() { $result = mysql_query_debug( "select {$this->prefix}id 'id', {$this->prefix}key 'key', {$this->prefix}val 'val', {$this->prefix}weight 'weight', {$this->prefix}time 'time' from {$this->tbl} order by {$this->prefix}weight desc, {$this->prefix}id"); $data = Array(); while($row = mysql_fetch_assoc($result)) $data[$row['id']] = $row; return $data; } // ***** Clear ***** function Clear($key) { $hash = '0x' . substr(md5($key), 0, ; $key = mysql_real_escape_string($key); mysql_query_debug( "delete from {$this->tbl} where {$this->prefix}hash = $hash && {$this->prefix}key = '$key'"); } // ***** Clear Id ***** function ClearId($id) { $id = (integer)$id; mysql_query_debug("delete from {$this->tbl} where {$this->prefix}id = $id"); } // ***** Clear All ***** function ClearAll($key) { mysql_query_debug("delete from {$this->tbl}"); } } // ***** TMySQL_WordId ********************************************************* class TMySQL_WordId { var $tbl = null; var $prefix = null; // ***** Init ***** function Init($tbl, $prefix) { $this->tbl = $tbl; $this->prefix = $prefix; } // ***** CreateTable ***** function CreateTable($drop = false) { if ($drop) mysql_query_debug("drop table if exists {$this->tbl}"); mysql_query_debug( "create table {$this->tbl} ({$this->prefix}word varchar(255) not null default '', {$this->prefix}id integer unsigned not null default 0, {$this->prefix}count integer unsigned not null default 0, unique index {$this->prefix}ind ({$this->prefix}word, {$this->prefix}id)) engine = myisam"); } // ***** Fill ***** function Fill($id, $word2count) { foreach ($word2count as $i => $x) if ($i != '') $word2count[$i] = "(\"$i\",$id,$x)"; else unset($word2count[$i]); $word2count = implode(",", $word2count); mysql_query_debug("insert into {$this->tbl} values $word2count;"); } // ***** Count Entries ***** function CountEntries() { $result = mysql_query_debug("select count(*) n from {$this->tbl};"); $row = mysql_fetch_assoc($result); return $row['n']; } // ***** Count Words ***** function CountWords() { $result = mysql_query_debug( "select count(distinct {$this->prefix}word) n from {$this->tbl};"); $row = mysql_fetch_assoc($result); return $row['n']; } // ***** Count Ids ***** function CountIds() { $result = mysql_query_debug( "select count(distinct {$this->prefix}id) n from {$this->tbl};"); $row = mysql_fetch_assoc($result); return $row['n']; } // ***** Clear Id ***** function ClearId($id) { $id = (integer)$id; mysql_query_debug("delete from {$this->tbl} where {$this->prefix}id = $id;"); } } // ***** Word forms ************************************************************ function wordforms($words) { if (!$GLOBALS["src_word_forms"]) return $words; $forms = Array(); foreach ($words as $i => $word) { $word = strtolower(trim($word)); $forms[] = $word; if (preg_match("/^(.*([^aeiou]))$/", $word, $matches)) array_push($forms, "{$matches[1]}s", "{$matches[1]}{$matches[2]}ed", "{$matches[1]}{$matches[2]}ing"); if (preg_match("/^(.*)e$/", $word, $matches)) array_push($forms, "{$matches[1]}es", "{$matches[1]}ed", "{$matches[1]}ing"); } return array_unique($forms); } // ***** Excerpt *************************************************************** function excerpt($words, $exact, $text, $maxlen) { $bolds = "([^a-zA-Z>])(" . implode("|", $words) . ")([^a-zA-Z<])"; $words = "[^a-zA-Z](?:" . implode("|", $words) . ")[^a-zA-Z]"; if (count($exact) > 0) { $exact = "[^a-zA-Z](?:" . implode("[^a-zA-Z]+", $exact) . ")[^a-zA-Z]"; $large = preg_split("/($exact)/iX", " $text ", -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $parts = Array(); for ($i = 0; $i < count($large); $i++) if (preg_match("/($exact)/iX", $large[$i])) $parts[] = $large[$i]; else $parts = array_merge($parts, preg_split("/($words)/iX", " {$large[$i]} ", -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); } else { $exact = ".*"; $parts = preg_split("/($words)/iX", " $text ", -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); } $start = 0; $count = 0; for ($i = 0; $i < count($parts); $i++) { $flag = false; $len = 0; for ($j = $i; $j < count($parts); $j++) { $flag = $flag || preg_match("/($exact)/iX", $parts[$j]); $len += strlen($parts[$j]); if ($len >= $maxlen) break; } if ($flag && $j-$i > $count) { $start = $i; $count = $j-$i; } } $result = ''; for ($i = $start; $i < $start+$count; $i++) $result .= $parts[$i]; if ($start-1 >= 0) { $part = preg_split("/([^a-z])/iX", $parts[$start-1], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); for ($i = count($part)-1; $i > count($part)-10 && $i >= 0; $i--) $result = $part[$i] . $result; } if ($start+$count < count($parts)) { $part = preg_split("/([^a-z])/iX", $parts[$start+$count], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); for ($i = 0; $i < count($part) && $i <= 10; $i++) $result .= $part[$i]; } $result = preg_replace("/$bolds/iX", "$1<b>$2</b>$3", $result); $result = preg_replace("/$bolds/iX", "$1<b>$2</b>$3", $result); $result = preg_replace("/$bolds/iX", "$1<b>$2</b>$3", $result); return trim($result); } // ***** Search **************************************************************** function search($words, $allwords, $nowords, $exact, $offset, $limit, &$numrows) { $words = wordforms(array_merge($words, $allwords, $exact)); $count = count($allwords); $somewords = wordforms($words); $somewords[] = '-=-=-=-=-=-=-=-=-=-='; $somewords = "('" . implode("','", $somewords) . "')"; $allwords [] = '-=-=-=-=-=-=-=-=-=-='; $allwords = "('" . implode("','", $allwords ) . "')"; $nowords [] = '-=-=-=-=-=-=-=-=-=-='; $nowords = "('" . implode("','", $nowords ) . "')"; if (count($exact) > 0) $phrase = "urls_val regexp '.*" . implode("[^a-zA-Z]+", $exact) . ".*'"; else $phrase = "1"; $result = mysql_query_debug( "select sql_calc_found_rows urls_key, urls_val, sum(index_count) word_weight, sum(index_word in $somewords) somewords_count, sum(index_word in $allwords) allwords_count, sum(index_word in $nowords) nowords_count from {$GLOBALS['src_index']->tbl}, {$GLOBALS['src_urls']->tbl} where (index_word in $somewords || index_word in $allwords || index_word in $nowords ) && urls_id = index_id group by index_id having somewords_count > 0 && allwords_count = $count && nowords_count = 0 && $phrase order by word_weight desc limit $offset, $limit"); $numrows = mysql_query_debug("select found_rows() NN"); $numrows = mysql_fetch_assoc($numrows); $numrows = $numrows["NN"]; $pages = Array(); while($page = mysql_fetch_assoc($result)) { $url = $page['urls_key']; $val = unserialize($page['urls_val']); $title = $val['title']; $text = $val['text' ]; $pages[] = Array("url" => $url, "title" => $title, "excerpt" => excerpt($words, $exact, $text, 100)); } return $pages; } // ***** Display *************************************************************** function display($results, $words, $allwords, $nowords, $exact, $q, $offset, $limit, $numrows, $time, $template_all, $template_ind, $template_cur, $template_ref, $template_non) { if ($numrows == 0) { echo $template_non; return; } $ind = ""; for ($i = 0; $i < (integer)(($numrows+$limit-1)/$limit); $i++) { $trans = Array("%%page%%" => $i+1, "%%offset%%" => $i*$limit, "%%words%%" => urlencode(implode(' ', $words )), "%%allwords%%" => urlencode(implode(' ', $allwords)), "%%nowords%%" => urlencode(implode(' ', $nowords )), "%%exact%%" => urlencode(implode(' ', $exact )), "%%q%%" => urlencode($q)); if ($i*$limit == $offset) $ind .= strtr($template_cur, $trans); else $ind .= strtr($template_ind, $trans); } $ref = ""; foreach ($results as $i => $result) { $trans = Array("%%url%%" => $result["url"], "%%title%%" => $result["title"], "%%excerpt%%" => $result["excerpt"]); $ref .= strtr($template_ref, $trans); } $trans = Array("%%ind%%" => $ind, "%%ref%%" => $ref, "%%numrows%%" => $numrows, "%%time%%" => $time); echo strtr($template_all, $trans); } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.