|
|
|
|
|
|
| |
The Web site advertising business became much more profitable to Web site owners, and more effective for advertisers, when Web advertising agencies invested in contextual advertising techniques, like those used by AdSense and IntelliTXT.
Instead of display almost randomly chosen ads, context advertising techniques show ads that are picked automatically by the ad servers to match the topics of the content displayed in each page.
This package implements a solution that can be used to display contextual advertising using PHP.
It can scan the text in the current page and submit it to the server via AJAX. In response to the AJAX request, contextual advertising may be displayed in a pop-up window.
Please see attached file above.
controller.php
| <?PHP
/*
* Thesaurus
*
* @package Thesaurus
* @author $Author: sheiko $
* @version $Id: controller.php, v 1.5 2007/01/2 15:58:15 sheiko Exp $
* @since v.1.5
* @copyright (c) Dmitry Sheiko http://www.cmsdevelopment.com
*/
/**
* Thesaurus Controller Class
* @package Thesaurus
* @author $Author: sheiko $
*/
class Thesaurus {
var $DataSourceFile;
var $Output;
var $BodyContent;
var $Term;
var $ErrorMsg;
var $Length;
var $Tags;
/**
* Class Constructor
* @return object
*/
function Thesaurus() {
$this->DataSourceFile = "sample.csv";
$this->BodyContent = false;
$this->ErrorMsg = false;
$this->Term = false;
$this->Length = 0;
$this->Output = '';
if(isset($_POST["body"])) $this->BodyContent = urldecode($_POST["body"]);
if(isset($_POST["term"])) $this->Term = strtolower($_POST["term"]);
if(!$this->Term AND !$this->BodyContent) $this->ErrorMsg = "Incorrect parameters";
return $this;
}
/**
* Get data and filter data
*
* @return boolean
*/
function getDataAndFitlering() {
$data = file($this->DataSourceFile);
$this->Length = count($data);
foreach ($data as $key => $line) {
$arr = split(";", $line);
if($arr[0]==$this->Term) $this->Output = $arr[1];
unset($data[$key]);
}
}
/**
* Strip tags
*
*/
function stripTags($Term) {
$mathes = array();
preg_match_all("/(<a[^>]*>)(".preg_quote($Term,"/").")([^>]*?)<\/a>/is", $this->BodyContent, $mathes);
$this->Tags = $mathes[0];
preg_match_all("/(<script[^>]*>)(".preg_quote($Term,"/").")([^>]*?)<\/script>/is", $this->BodyContent, $mathes);
$this->Tags = array_merge($this->Tags, $mathes[0]);
preg_match_all("/title=\"([^\"]*?)(".preg_quote($Term,"/").")([^>]*?)\"/is", $this->BodyContent, $mathes);
$this->Tags = array_merge($this->Tags, $mathes[0]);
preg_match_all("/alt=\"([^\"]*?)(".preg_quote($Term,"/").")([^>]*?)\"/is", $this->BodyContent, $mathes);
$this->Tags = array_merge($this->Tags, $mathes[0]);
if($this->Tags) {
foreach($this->Tags as $match) {
$this->BodyContent = preg_replace("/".preg_quote($match,"/")."/s", "{!".md5($match)."!}", $this->BodyContent);
}
}
}
/**
* Restore tags
*
*/
function retoreTags() {
if($this->Tags) {
foreach($this->Tags as $match) {
$this->BodyContent = preg_replace("/\{!".md5($match)."!\}/s", $match, $this->BodyContent);
}
}
}
/**
* Get data and parse body content
*
* @return boolean
*/
function getDataAndParsing() {
$tags = array();
$data = file($this->DataSourceFile);
$this->Length = count($data);
$this->BodyContent = preg_replace("/parseContent();/is", "", stripslashes($this->BodyContent));
foreach ($data as $key => $line) {
$arr = split(";", $line);
$this->stripTags($arr[0]);
// Replace all matches
if(preg_match("/\s/", $arr[0])) {
if( preg_match("/".preg_quote($arr[0])."/is", $this->BodyContent ) )
$this->BodyContent = preg_replace("/(".preg_quote($arr[0]).")/is", "<a class=\"thesaurus\" onmouseover=\"getDefinition('\\1', event);\" onmouseout=\"setTimer();\">\\1</a>", $this->BodyContent);
} elseif( preg_match("/[\s<>]".preg_quote($arr[0])."[\s<>]/is", $this->BodyContent ) ) {
$this->BodyContent = preg_replace("/([\s<>])(".preg_quote($arr[0]).")([\s<>])/is", "\\1<a class=\"thesaurus\" onmouseover=\"getDefinition('\\2', event);\" onmouseout=\"setTimer();\">\\2</a>\\3", $this->BodyContent);
}
$this->retoreTags();
unset($data[$key]);
}
$this->Output = preg_replace("/[\r\n]/", "", $this->BodyContent);
}
/**
* Respond with JSON generation
*
* @return boolean
*/
function execRespond() {
if($this->Term) $this->getDataAndFitlering();
if($this->BodyContent) $this->getDataAndParsing();
if($this->Length==0) return false;
header("Content-type: text/html; charset=UTF-8");
$out = '{
"thlength" : '.$this->Length.',
"errormsg" : "'.$this->ErrorMsg.'",
"content" : "'.addslashes($this->Output).'"
}';
print $out;
}
}
$th = new Thesaurus();
$th->execRespond();
?> | | |
|
| Zephyr: AJAX Based Framework for PHP5 Developers Categories : PHP, AJAX, Frameworks, Java Script, Web Applications | | | Remote Scripting: send form POST data to a script and insert the results into a page without refreshing the page. Categories : PHP, AJAX, HTML and PHP, Java Script | | | ezRemoteScripter - A little remote scripting (AJAX) helper Categories : PHP, Java Script, AJAX | | | AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page. Categories : PHP, AJAX, Databases, MySQL, Java Script | | | The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view. Categories : PHP, PHP Classes, Java Script, AJAX, Databases | | | Array values from javascript to php Categories : PHP, Java Script, Arrays | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | Linked comboboxes with php-mysql & javascript Categories : PHP, Java Script, Databases, MySQL | | | The toll booth Categories : PHP, Java Script, Filesystem | | | MD5 secured login Categories : PHP, Java Script, Authentication, Security | | | Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, Databases | | | JSON File Upload Categories : PHP, AJAX, Filesystem | | | PHP Interaction with Javascript windows Categories : Java Script, PHP | | | Builds JavaScript that updates the contents of one selector based on another. Categories : HTML, Java Script, PHP, Complete Programs, General | | | This is a script that list all image files on a given directory, and displays
the thumbnails nicely formated within an HTML table. It also make use of
JavScript to open pop up windows when the users want to see the full photo. Categories : Graphics, PHP, Complete Programs, Java Script | |
|
|
|