Lien vers l'imageCode : Tout sélectionner
/libs
/JavascriptTag
JavascriptTagBase.class.php
JavascriptTagFactory.class.php
/tags
GoogleAnalyticsTag.class.php
AdLedgeTag.class.php
Ok merci voilà donc ce que j'ai fais dis moi si tu vois pour l'instant une manière de l'améliorer.Non, je n'ai aucun code, c'est juste un jet de conception que je te donne.
<?php
/**
* Manage e-commerce Javascript Tags.
*
* @package JavascriptTag
* @author //
*/
class JavascriptTagFactory extends sfFilter
{
public
$aFinalTag = array(),
$aTags = array('Criteo');
/**
* Constructor
*
* @param parent class $filterChain
*/
public function execute($filterChain)
{
$filterChain->execute();
foreach($this->aTags as $tag) {
$tag = $this->addTag(ucfirst($tag));
}
$response = $this->getContext()->getResponse();
$response->setContent(str_ireplace('</body>',$this->getTags().'</body>',$response->getContent()));
}
/**
* Instance of all tags class needed, push to array
*
* @param string $tag
*/
public function addTag($tag)
{
if(class_exists($tag)) {
array_push($this->aFinalTag, new $tag());
}
}
/**
* Get all tags from the array
*
* @param string $display
* @return string $display
*/
public function getTags($display = '')
{
foreach($this->aFinalTag as $oTag) {
$display .= $oTag->getTag();
}
return $display;
}
}
?>
<?php
/**
* Prototypes for javascript tags
*
* @package JavascriptTag
* @author //
*/
abstract class JavascriptTagPrototype
{
const JS_START = '<script type="text/javascript">';
const JS_STOP = '</script>';
const CDATA_START = "//<![CDATA[";
const CDATA_STOP = '//]]>';
/**
* Add div with class and content
*
* @param string $class
* @param string $param
* @return string
*/
public function addDivWithClass($class,$param) {
return '<div class=\"'.$class.'\">'.$param.'</div>';
}
}
?>
class Criteo : <?php
/**
* Criteo (http://widget.criteo.com)
*
* @package JavascriptTag
* @author //
*
*/
class Criteo extends JavascriptTagPrototype
{
const ID = 'TEST';
public
$tag,
$module;
/**
* Constructor
*/
function __construct()
{
sfContext::getInstance()->getConfiguration()->loadHelpers(array('Helper','Tag','Javascript'));
$this->module = sfContext::getInstance()->getModuleName();
// Comment
$criteo[] = "<!-- ".$this." -->";
// Load Criteo javascript file
$criteo[] .= '<script type="text/javascript" src="http://ld2.criteo.com/criteo_ld.js"></script>';
// Start Tag
$criteo[] .= parent::JS_START;
$criteo[] .= parent::CDATA_START;
$criteo[] .= 'document.write(\'<div id=\"'.self::ID.'\" style=\"display:none\">\')';
$criteo[] .= $this->addDivWithClass('ctoWidgetServer','http://widget.criteo.com/pvx');
$criteo[] .= $this->addDivWithClass('ctoDataType',$this->getCtoDataType());
$criteo[] .= $this->addDivWithClass('ctoParams',$this->getCtoParams());
$criteo[] .= "document.write('<\/div>')";
// End Tag
$criteo[] .= parent::CDATA_STOP;
$criteo[] .= parent::JS_STOP;
// Set the tag
$this->setTag(join("\n", $criteo));
}
/**
* Return class name
*/
public function __toString() {
return "CRITEO";
}
/**
* Setter for the tag
*
* @param $string $tag
*/
public function setTag($tag) {
$this->tag = $tag;
}
/**
* Getter for the tag
*
* @return string $tag
*/
public function getTag() {
return $this->tag;
}
/**
* (non-PHPdoc)
* @see lib/JavascripTag/JavascriptTagPrototype#addDivWithClass($class, $param)
*/
public function addDivWithClass($class,$param)
{
return "document.write('".parent::addDivWithClass($class,$param)."');";
}
/**
* Return ctoDataType for the module
*
* @return string $ctoDataType
*/
public function getCtoDataType()
{
switch($this->module)
{
case 'order':
$ctoDataType = 'transaction';
break;
default:
$ctoDataType = 'sendEvent';
break;
}
return $ctoDataType;
}
/**
* Return ctoParams for the module
*
* @return string $ctoParms
*/
public function getCtoParams()
{
switch($this->module)
{
case 'order':
$ctoParams = 'transaction';
break;
case 'sells':
$ctoParams = 'wi=7708871&pt1=0&pt2=1&s=1&si=1';
break;
default:
$ctoParams = 'wi=7708871&pt1=0&pt2=1&si=1';
break;
}
return $ctoParams;
}
}
?>
En gros avec une première class de tag.