|
|
|
|
|
|
| |
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();
?> | | |
|
| 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 | | | 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 | | | Activate an Ajax.Autocompleter with an onLoad Command Categories : Java Script, AJAX | | | Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS Categories : PHP, Databases, MySQL, Java Script, User Interface | | | day and week grid with clickable fields on/off and possibility to insert in DB Categories : PHP, Java Script, CSS | | | Newbie Notes #9 - Hyperlinking a post Categories : PHP, Java Script, HTML and PHP, Beginner Guides | | | This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field Categories : PHP, MySQL, Java Script, HTML and PHP | | | enhanced date picker with jcript checking for a dynamic date input Categories : PHP, Java Script, Date Time, Calendar, Arrays | | | Password using php, Javascript, and html form Categories : Security, PHP, Authentication, Java Script | | | Easy alert box pop-up function Categories : PHP, Java Script, Beginner Guides | | | PHP code for a directory treeview with DTREE free JavaScript TREE utility Categories : PHP, Directories, Java Script | | | Complete NotePad application for Websites (Like Yahoo Notepad) Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs | |
|
|