Index: trunk/in-bulletin/emoticon.php =================================================================== diff -u -N --- trunk/in-bulletin/emoticon.php (revision 12744) +++ trunk/in-bulletin/emoticon.php (revision 0) @@ -1,269 +0,0 @@ -clsParsedItem(); - $this->tablename=GetTablePrefix()."Emoticon"; - $this->NoResourceId=1; - $this->id_field = "EmoticonId"; - $this->TagPrefix = "smiley"; - - if($id) - $this->LoadFromDatabase($id); - } - - function Delete() - { - $i = $this->GetImageObject(); - if(is_object($i)) - $i->Delete(); - parent::Delete(); - } - - function LoadFromDatabase($Id) - { - global $Errors; - - if(!isset($Id)) - { - $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase"); - return false; - } - $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ".$this->IdField()." = '%s'",$Id); - // echo $sql; - $result = $this->adodbConnection->Execute($sql); - if ($result === false) - { - $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase"); - return false; - } - $data = $result->fields; - $this->SetFromArray($data); - $this->Clean(); - return true; - } - - function &GetImageObject() - { - if(!is_object($this->Image)) - { - $this->Image = new clsImage($this->Get("ImageId")); - } - return $this->Image; - } - - function GetURL() - { - $img =& $this->GetImageObject(); - return $img->FullURL(); - } - - function ParseObject($element) - { - $extra_attribs = ExtraAttributes($element->attributes); - if(strtolower($element->name)==$this->TagPrefix) - { - $field = strtolower($element->attributes["_field"]); - switch($field) - { - case "name": - /* - @field:smiley.name - @description:text name of the smiley image - */ - $ret = $this->Get("Name"); - break; - case "keystroke": - /* - @field:smiley.keystroke - @description:keystroke equivelent of the smiley - */ - $ret = $this->Get("KeyStroke"); - break; - case "url": - /* - @field:smiley.url - @description:Image URL pointing to the smiley image - @attrib:_fulltag:bool:If set, returns a complete image tag, otherwise just the url is returned - */ - $src = $this->GetURL(); - if($element->attributes["_fulltag"]) - { - $ret = ""; - } - else - $ret = $src; - break; - } - } - return $ret; - } -} - -class clsEmoticonList extends clsItemCollection -{ - var $UrlCache; - var $SmileyIndex = Array(); // used for quick smiley conversion - - - function clsEmoticonList() - { - $this->clsItemCollection(); - $this->classname = "clsEmoticon"; - $this->SourceTable = GetTablePrefix()."Emoticon"; - $this->AdminSearchFields = array($this->SourceTable.".Name","KeyStroke"); - $this->UrlCache = Array(); - } - - function AddEmoticon($Name,$KeyStroke,$ImageId,$Enabled=1) - { - $e = new clsEmoticon(); - $e->Set(array("Name","KeyStroke","ImageId","Enabled"), - array($Name,$KeyStroke,$ImageId,$Enabled)); - $e->Create(); - return $e; - } - - function EditEmoticon($EmotionId,$Name,$KeyStroke,$ImageId=-1,$Enabled=1) - { - $e = $this->GetItem($EmotionId); - if($ImageId==-1) - $ImageId=$e->Get("ImageId"); - $e->Set(array("Name","KeyStroke","ImageId","Enabled"), - array($Name,$KeyStroke,$ImageId,$Enabled)); - $e->Update(); - return $e; - } - - function DeleteEmoticon($EmoticonId) - { - $e = $this->GetItem($EmoticonId,TRUE); - if(is_object($e)) - { - if($e->Get("EmoticonId")==$EmoticonId) - $e->Delete(); - } - } - - function UploadEmoticon($file,$Name,$KeyStroke,$Enabled,$IsUpload=TRUE) - { - $objImageList = new clsImageList(); - $LocalImage = 1; - - $LocalThumb = 1; - if (strlen($_POST["imgThumbURL"])==0) - $LocalThumb = 1; - - $img = $objImageList->Add($Name, $Name, 0, 1, 1, "", "", $Enabled, 0, 0, 0,1); - $localpath = $img->StoreUploadedImage($file,1, "in-bulletin/images/emoticons/",0,$IsUpload); - $img->Set("LocalPath",$localpath); - $img->Set("ThumbPath",$localpath); - $img->Update(); - $e = $this->AddEmoticon($Name,$KeyStroke,$img->Get("ImageId"),$Enabled); - return $e; - } - - function &LoadEmoticons($where=NULL,$orderBy=NULL) - { - $this->Clear(); - $etable = $this->SourceTable; - $itable = GetTablePrefix()."Images"; - - $sql = "SELECT ".$this->SourceTable.".*,$itable.LocalPath FROM $etable LEFT JOIN $itable ON ($etable.ImageId=$itable.ImageId)"; - //echo $sql."
"; - if(strlen(trim($where))>0) - $sql .= " WHERE $where"; - if(strlen(trim($orderBy))>0) - $sql .= " ORDER BY $orderBy"; - //$sql = str_replace(" ORDER BY ".GetTablePrefix()."Emoticon.Image", " ORDER BY ".GetTablePrefix()."Emoticon.ImageId", $sql); - //echo $sql; - $this->Query_Item($sql); - - // create Smiley Index - $i = 0; $sm_count = $this->NumItems(); - while($i < $sm_count) - { - $this->SmileyIndex[ $this->Items[$i]->Get('KeyStroke') ] = $this->GetEmoticonUrl( $this->Items[$i]->UniqueId() ); - $i++; - } - - return $this->Items; - } - - function &LoadActiveEmoticons() - { - $order = "CHAR_LENGTH(KeyStroke) DESC"; - return $this->LoadEmoticons($this->SourceTable.".Enabled=1",$order); - } - - function GetEmoticonUrl($id) - { - global $rootURL, $pathtoroot; - - $url = isset($this->UrlCache[$id]) ? trim($this->UrlCache[$id]) : ''; - if(!strlen($url)) - { - $i =& $this->GetItem($id); - - $url = $i->Get("LocalPath"); -// if(file_exists($pathtoroot.$url)) -// { - if(strlen($url)) - { - $url = $rootURL.$url; - } - else - $url = " "; - $this->UrlCache[$id] = $url; - return trim($url); -// } -// else -// return ""; - } - else - return $url; - } - - function ParseText($src) - { - if($this->NumItems()==0) - { - $this->LoadActiveEmoticons(); - } - $ret = $src; - for($x=0;$x<$this->NumItems();$x++) - { - $i =& $this->Items[$x]; - $url = $this->GetEmoticonUrl($i->Get("EmoticonId")); - if(strlen($url)) - { - $tag = ''; - } - else - $tag=""; - $ret = str_replace($i->Get("KeyStroke"),$tag,$ret); -// echo "Replacing ".$i->Get("KeyStroke")." with ".htmlentities($tag)."
\n"; - } - - return $ret; - } - - /** - * @return string - * @param string $text - * @desc Remove smiley images html back with their codes - */ - function UndoSmileys($text) - { - foreach($this->SmileyIndex as $KeyStoke => $SmileURL) - { - $text = str_replace('',$KeyStoke,$text); - } - return $text; - } -} - -