New Report Function help

Forum
Last Post
Threads / Messages

tahbikat

Member
Member
Joined
Feb 11, 2014
Messages
408
Points
16
Age
30
Location
Louisiana
Mysidian Dollar
32,360
I'm wondering if it would be possible to make a new report function to report, say, an adopt's name or bio field on its public profile (which would be located at levelup.php)

I ask because I've made a bio field for pets on my site. Members can write their own bios for the pet and have it display publicly on the profile (levelup.php). It's working great, but I'm having trouble figuring out how to make a report function for it. :c Essentially a user would just be reporting a specific adopt's value in its "petbio" column in the db.

Any help? I'd love to make a tutorial out of this so other Mysidia game owners can utilize this feature too. If anyone needs me to post any code I'm using for this in order to help with the report function, let me know!
 
I was considering making a pet bio field, too, but I hadn't considered that it would need a report button! There are always bad eggs that spoil the bunch, isn't there? Do you want the report PM'd to the Admin?
 
Pretty much, yes! I'm actually using your modified version of the PM report function, and it works great. Basically the same thing I want for the pet's bio report function. :)

To make the pet bios, I simply modified the rename functions and classes. :p Working like a charm so far.
 
Oh no, I do LOL. I don't know how to make the report function work with the pet bio, is what I meant. xc

So yea I have the actual bios done. Only thing left is the reporting part. I'm clueless about it. I tried to copy and modify the original report function, but tis hard. :<
 
Update: Also noticed slashes are butchering bios when apostrophe's are used. :L I tried my best to remedy it but can't figure it out. The 'stripslashes($message);' string I have only works if I echo it, but then it displays above the whole layout of the site and not where it's supposed to.

I'm not sure how to make stripslashes work with 'throw new LevelupException($message);'
 
I know how to fix that. I've got another site project (not Mysidia-related, something custom coded) where I had to create fields for users to post bio data and I've got a whole function on hand ready to check for slashes and that will allow for some safe levels of html while stripping out anything potentially harmful. I haven't gotten around to upgrading the profile bio area in Mysidia, but of course we'd want it the same as the pet one.

Like, at minimum this one should solve the slashes(probably):
PHP:
public function validate($data){
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;    
}

But also these (to allow for some, but not all html... and I made some exceptions that will still allow for some faces to render... and <3 is replaced with ♥ so the bracket is accounted for:
PHP:
public function removeStyles($data){
    $list = array('cursor', 'position','font','z-index','font-family','font-size','border','border-left','border-right','border-top','border-bottom','border-radius');
    $patterns = array();
    foreach ($list as $v){
        $patterns[]= '/'.$v.'\s*:\s*[^;"]*;?/';
    }
    return preg_replace($patterns,'', $data);
}

(I have no idea why the syntax highlighting is borked on this one.)
PHP:
public function purify($data){
    $data = removeStyles($data);
    
    $data = html_entity_decode($data);

    $data = str_ireplace('<3','♥',$data);
    $data = str_ireplace('_<','_<',$data); 
    $data = str_replace('D<','D<',$data);
    $data = str_replace('D:<','D:<',$data);    
    $data = str_replace('u<','u<',$data);
    $data = str_replace('w<','w<',$data);
    $data = str_replace('o<','o<',$data);
    $data = str_replace('U<','U<',$data);
    $data = str_replace('W<','W<',$data);
    $data = str_replace('O<','O<',$data);
    $data = str_ireplace('</','</',$data);

    $data = str_ireplace('<a href="j','<a href="## ',$data);
    $data = str_ireplace('onclick=',' ',$data);
    $data = str_ireplace('<a ','<a target="_BLANK" ',$data);
    $data = str_ireplace('<strike>','<s>',$data); $data = str_ireplace('</strike>','</s>',$data);
    $data = preg_replace('/(<br>){1,}$/', '', $data);   

    $doc = new DOMDocument();
    $doc->loadHTML('<?xml encoding="UTF-8">' . $data);
    $data = $doc->saveHTML();
    
    $data = strip_tags($data,'<a><pre><code><b><i><center><u><s><em><sub><sup><strong><br><span><small>'); 

    $data = trim($data);  

    /* BEGIN URL PARSE*/
    $pattern = '/((http|www\.)+(s)?:\/\/[^"\s]+)(?![^<]*>)/';
    preg_match_all($pattern, $data, $output);
    foreach ($output[0] as $values){ $urls[] = $values; }
    foreach($urls as $url) {
        $parser = '<a class="chatlink" target="_blank" href="'.$url.'">'.$url."</a>";
        $data = str_ireplace($url, $parser, $data);
    }
    /* END URL PARSE */
}

Run the bio through each of these functions in that order (that's my recommendation, anyway).








Anyway, as far as the Report feature, I've got some free time so I'll put some thought into over the next couple days. :meow:
 
Last edited:
Okay, sorry, I'm a little confused as to where/how to add this lol. ;-;

Do I add it to the class where I call the bio, or in the levelup.php where it's displayed? Or where the actual set bio function itself is? I'll go ahead and post the whole code for the bio. :p

Here's my codes:

class_ownedadopt pet bio section
PHP:
<?php

class OwnedAdoptable extends Adoptable{

    protected $aid;
	protected $name;
	protected $owner;
	protected $currentlevel;
	protected $totalclicks;
	protected $code;
	protected $imageurl;
	protected $usealternates;
	protected $tradestatus;
	protected $isfrozen;  
    protected $gender;
	protected $offsprings;
    protected $lastbred;
	protected $nextlevel;
	protected $voters;
	protected $adoptablepersonality;
	protected $obtainedfrom;
	protected $obtainedon;
	protected $magic;
	protected $petbio;
  
    public function __construct($aid, $owner = ""){	  
	    $mysidia = Registry::get("mysidia");
		$whereClause = "aid ='{$aid}'";
		if(!empty($owner)) $whereClause .= " and owner = '{$owner}'";
	    $row = $mysidia->db->select("owned_adoptables", array(), $whereClause)->fetchObject();
        if(!is_object($row)) throw new AdoptNotfoundException("Adoptable ID {$aid} does not exist or does not belong to the owner specified...");
		
		parent::__construct($row->type);
        foreach($row as $key => $val){
            $this->$key = $val;     		 
        }	  
    }

    public function getAdoptID(){
        return $this->aid;
    }

    public function getName(){
        return $this->name;
    }
    
   public function getPetBio(){
        return $this->petbio;
    }
	
	public function setName($name, $assignMode = ""){
		if($assignMode == Model::UPDATE) $this->save("name", $name);
	    $this->name = $name;
	}
	
	public function setPetBio($petbio, $assignMode = ""){
		if($assignMode == Model::UPDATE) $this->save("petbio", $petbio);
	    $this->petbio = $petbio;
	}
            
}
?>

myadopts.php pet bio part haven't cleaned this up yet lol
PHP:
public function petbio(){
		$mysidia = Registry::get("mysidia");		
		if($mysidia->input->post("submit")){
		    $poundsettings = getpoundsettings();
		    $poundpet = $mysidia->db->select("pounds", array(), "aid='{$this->adopt->getAdoptID()}'")->fetchObject();
			if($poundpet and $poundsettings->rename->active == "yes"){
			    if(!empty($poundpet->firstowner) and $mysidia->user->username != $poundpet->firstowner){
				    $this->setFlags("petbio_error", "petbio_owner");
                    return;	
                }				
            }			
			$this->adopt->setPetBio($mysidia->input->post("petbio"), "update");
		}
        $this->setField("adopt", $this->adopt);		
		$this->setField("image", $this->image);			
	}

myadoptsview.php
PHP:
public function petbio(){
		$mysidia = Registry::get("mysidia");
		$adopt = $this->getField("adopt");		
		$image = $this->getField("image");		
		$document = $this->document;
		
		if($mysidia->input->post("submit")){
			$document->setTitle($this->lang->petbio_success_title);
			$document->add($image);
			$message = "<br>{$this->lang->petbio_success}{$adopt->getName()}. 
					    You can now manage {$adopt->getName()} on the";
			$document->addLangvar($message);
			$document->add(new Link("myadopts/manage/{$adopt->getAdoptID()}", "My Creatures Page"));
			return;
		}
		
		$document->setTitle($this->lang->petbio.$adopt->getName());
		$document->add($image);
		$document->addLangvar("<br />{$this->lang->petbio_default}{$adopt->getName()}{$this->lang->petbio_details}<br />");
		
		$petbioForm = new FormBuilder("petbioform", "", "post");
		$petbioForm->buildTextArea("petbio")->buildButton("Submit Bio", "submit", "submit");
		$document->add($petbioForm);		   
	}


levelup.php
PHP:
<?php

use Resource\Native\Integer;
use Resource\Collection\ArrayList;
use Resource\Utility\Curl;

class LevelupController extends AppController{

    const PARAM = "aid";
	private $adopt;
    private $settings;

    public function __construct(){
        parent::__construct();
        $this->settings = new LevelSetting;
		$mysidia = Registry::get("mysidia");

		if($mysidia->input->action() == "click" or $mysidia->input->action() == "siggy") $this->adopt = new OwnedAdoptable($mysidia->input->get("aid"));
		if($mysidia->user instanceof Member){
		    $status = $mysidia->user->getstatus();   
			if($status->canlevel == "no") throw new InvalidActionException("banned");
		}	
    }
	
	public function index(){
		throw new InvalidActionException("global_action");
	}
	
public function click(){
    $mysidia = Registry::get("mysidia");
    $date = new DateTime;
    $ip = secure($_SERVER['REMOTE_ADDR']);

    /*... First check if the system to levelup pets is enabled ...*/
    if($this->settings->system != "enabled") { throw new NoPermissionException("disabled"); }

    /*... Then check if the user has already visited the pet today ...*/
    elseif($this->adopt->hasVoter($mysidia->user, $date)){
        if($this->adopt->hasNextLevel()){
            $nextLevel = $this->adopt->getNextLevel();
            $requiredClicks = $nextLevel->getRequiredClicks();
        }

        $gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
        if ($gender_lookup == "m") { $gender = "Male"; $pronoun = "him"; } else { $gender = "Female"; $pronoun = "her"; } 
        
        $alternates_lookup = $mysidia->db->select("owned_adoptables", array("usealternates"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
        if ($alternates_lookup == "yes") { $usealternates = "Variant"; } else { $usealternates = "Normal"; }

        if ($mysidia->user->username == $this->adopt->getOwner()){ $manage_btn = "<i><a class='btn btn-sm btn-info' href='../../myadopts/manage/{$this->adopt->getAdoptID()}'> Manage {$this->adopt->getName()}</a></i><br /><br />"; } else { $manage_btn = ""; }

        if($this->adopt->hasNextLevel()){
            $level = $this->adopt->getNextLevel();
            $levelupClicks = $this->adopt->getLevelupClicks();
            $toNext = "(LVL ".$level->getLevel()." in ".$levelupClicks." more EXP)"; 
        } 
        else { $toNext = "(MAX)"; }

        if($this->adopt->getTradeStatus() == "fortrade") { $tradestatus = "For Trade"; } 
        else { $tradestatus = "Not For Trade"; }

        $message = "<div class='adopt_profile'>    <h2>{$this->adopt->getName()} (#{$this->adopt->getAdoptID()})</h2>    ";
        
        // If you've already seen the pet today:
        if ($this->adopt->hasVoter($mysidia->user, $date)){
            $message .= "<div class='already-seen-msg'><b>Thanks!</b>  You already visited this creature today!</div>";
        }
        // If you haven't seen the pet today:
        if (!$this->adopt->hasVoter($mysidia->user, $date)){
            $message .= "<div style='display: inline;'><span class='button'>Play</span></div>";
        }
        if ($this->adopt->getCurrentLevel() == 0){
        /*if current level is less than three do this*/
            $message .= "<div class='pet-img'>{$manage_btn}
            <img src='{$this->adopt->getImage()}'/><br /><br />
            <img src='/picuploads/{$this->adopt->getRarity()}.png' title='{$this->adopt->getRarity()} Species, ???' style='margin-right: -3px;' /><br /><br />
            
            <hr id='pethr'>
            <p style='text-align: left;'><b>{$this->adopt->getName()}'s Bio:</b> Not available until hatched.</p>
            </div>
            <div class='pet-stats'>
                        <ul class='profile-list'>
                        <li class='statsFloat'><b>Owner</b>: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
                        <li class='statsFloat'><b>Species</b>: {$this->adopt->getType()}</li>
                        <li class='statsFloat'><b>Obtained From</b>: {$this->adopt->getObtainedFrom()}</li>
                        <li class='statsFloat'><b>Total Points</b>: {$this->adopt->getTotalClicks()}</li>
                        <li class='statsFloat'><b>Obtained On</b>: {$this->adopt->getObtainedOn()}</li>
                        <li class='statsFloat'><b>Level</b>: {$this->adopt->getCurrentLevel()}</li>
                        <li class='statsFloat'><b>Trade Status</b>: {$tradestatus}</li> 

                        </ul>
                        <b>Description</b>: {$this->adopt->getDescription()}<br /><br />
                        </div>";

        throw new LevelupException($message);
        }
                if ($this->adopt->getCurrentLevel() == 1){
        /*if current level is less than three do this*/
            $message .= "<div class='pet-img'>{$manage_btn}
            <img src='{$this->adopt->getImage()}'/><br /><br />
            <img src='/picuploads/{$this->adopt->getRarity()}.png' title='{$this->adopt->getRarity()} Species, ???' style='margin-right: -3px;' /><br /><br />
            
            <hr id='pethr'>
            <p style='text-align: left;'><b>{$this->adopt->getName()}'s Bio:</b> Not available until hatched.</p>
            </div>
            <div class='pet-stats'>
                        <ul class='profile-list'>
                        <li class='statsFloat'><b>Owner</b>: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
                        <li class='statsFloat'><b>Species</b>: {$this->adopt->getType()}</li>
                        <li class='statsFloat'><b>Obtained From</b>: {$this->adopt->getObtainedFrom()}</li>
                        <li class='statsFloat'><b>Total Points</b>: {$this->adopt->getTotalClicks()}</li>
                        <li class='statsFloat'><b>Obtained On</b>: {$this->adopt->getObtainedOn()}</li>
                        <li class='statsFloat'><b>Level</b>: {$this->adopt->getCurrentLevel()}</li>
                        <li class='statsFloat'><b>Trade Status</b>: {$tradestatus}</li> 

                        </ul>
                        <b>Description</b>: {$this->adopt->getDescription()} It has started to shake! It must be very close to hatching.<br /><br />
                        </div>";

        throw new LevelupException($message);
        }
         if ($this->adopt->getCurrentLevel() == 2){
        /*if current level is less than three do this*/ 
            $message .= "<div class='pet-img'>{$manage_btn}
            <img src='{$this->adopt->getImage()}'/><br /><br />
            <img src='/picuploads/{$this->adopt->getRarity()}.png' title='{$this->adopt->getRarity()} Species, {$usealternates}' style='margin-right: -3px;' /> <img src='/picuploads/{$usealternates}.png' title='{$this->adopt->getRarity()} Species, {$usealternates}' /><br /><br />
            
            <hr id='pethr'>
            <p style='text-align: left;'><b>{$this->adopt->getName()}'s Bio:</b> {$this->adopt->getPetBio()}</p>
            <p style='text-align: right; margin: 0; padding: 0;'><a href='' class='reportexclam'><img src='/picuploads/reportimg.png' title='Report this bio' /></a></p>
            </div>
            <div class='pet-stats'>
                        <ul class='profile-list'>
                        <li class='statsFloat'><b>Owner</b>: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
                        <li class='statsFloat'><b>Personality</b>: {$this->adopt->getAdoptPersonality()}</li>
                        <li class='statsFloat'><b>Species</b>: {$this->adopt->getType()}</li>
                        <li class='statsFloat'><b>Magic Skill</b>: {$this->adopt->getMagic()}/100</li>
                        <li class='statsFloat'><b>Gender</b>: {$gender}</li>
                        <li class='statsFloat'><b>Obtained From</b>: {$this->adopt->getObtainedFrom()}</li>
                        <li class='statsFloat'><b>Total Points</b>: {$this->adopt->getTotalClicks()}</li>
                        <li class='statsFloat'><b>Obtained On</b>: {$this->adopt->getObtainedOn()}</li>
                        <li class='statsFloat'><b>Level</b>: {$this->adopt->getCurrentLevel()}</li>
                        <li class='statsFloat'><b>Trade Status</b>: {$tradestatus}</li> 

                        </ul>
                        <b>Description</b>: Oh look! Your egg has hatched into a little creature. {$this->adopt->getHatchyDescription()}<br /><br />
                        </div>";
              
        throw new LevelupException($message);
        }else {
/*well else it must be three or greater, so do this*/
            $message .= "<div class='pet-img'>{$manage_btn}
            <img src='{$this->adopt->getImage()}'/><br /><br />
            <img src='/picuploads/{$this->adopt->getRarity()}.png' title='{$this->adopt->getRarity()} Species, {$usealternates}' style='margin-right: -3px;' /> <img src='/picuploads/{$usealternates}.png' title='{$this->adopt->getRarity()} Species, {$usealternates}' /><br /><br />
            
            <hr id='pethr'>
            <p style='text-align: left;'><b>{$this->adopt->getName()}'s Bio:</b> {$this->adopt->getPetBio()}</p>
            <p style='text-align: right; margin: 0; padding: 0;'><a href='' class='reportexclam'><img src='/picuploads/reportimg.png' title='Report this bio' /></a></p>
            </div>
            <div class='pet-stats'>
                        <ul class='profile-list'>
                        <li class='statsFloat'><b>Owner</b>: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
                        <li class='statsFloat'><b>Personality</b>: {$this->adopt->getAdoptPersonality()}</li>
                        <li class='statsFloat'><b>Species</b>: {$this->adopt->getType()}</li>
                        <li class='statsFloat'><b>Magic Skill</b>: {$this->adopt->getMagic()}/100</li>
                        <li class='statsFloat'><b>Gender</b>: {$gender}</li>
                        <li class='statsFloat'><b>Obtained From</b>: {$this->adopt->getObtainedFrom()}</li>
                        <li class='statsFloat'><b>Total Points</b>: {$this->adopt->getTotalClicks()}</li>
                        <li class='statsFloat'><b>Obtained On</b>: {$this->adopt->getObtainedOn()}</li>
                        <li class='statsFloat'><b>Level</b>: {$this->adopt->getCurrentLevel()}</li>
                        <li class='statsFloat'><b>Trade Status</b>: {$tradestatus}</li> 

                        </ul>
                        <b>Description</b>: {$this->adopt->getAdultDescription()}<br /><br />
                        </div>";
 
        throw new LevelupException($message); 

}  
     
 }
    /*... But do this if the pet is frozen! ...*/
    elseif($this->adopt->isFrozen() == "yes") {  $gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
        if ($gender_lookup == "m") { $gender = "Male"; $pronoun = "him"; } else { $gender = "Female"; $pronoun = "her"; } 
        
        $alternates_lookup = $mysidia->db->select("owned_adoptables", array("usealternates"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
        if ($alternates_lookup == "yes") { $usealternates = "Variant"; } else { $usealternates = "Normal"; }
        
        if ($mysidia->user->username == $this->adopt->getOwner()){ $manage_btn = "<i><a class='btn btn-sm btn-info' href='../../myadopts/manage/{$this->adopt->getAdoptID()}'> Manage {$this->adopt->getName()}</a></i><br /><br />"; } else { $manage_btn = ""; }
        
        if($this->adopt->getTradeStatus() == "fortrade") { $tradestatus = "For Trade"; } 
        else { $tradestatus = "Not For Trade"; }
        
        $message = "<div class='adopt_profile'>    <h2>{$this->adopt->getName()} (#{$this->adopt->getAdoptID()})</h2>    ";
        $message .= "<div class='already-seen-msg'><img src='/picuploads/yes.png' /> This creature is frozen, your click has not been counted.</div>";
        
        $message .= "<div class='pet-img'>{$manage_btn}
            <img src='{$this->adopt->getImage()}'/><br /><br />
            <img src='/picuploads/{$this->adopt->getRarity()}.png' title='{$this->adopt->getRarity()} Species, {$usealternates}' style='margin-right: -3px;' /> <img src='/picuploads/{$usealternates}.png' title='{$this->adopt->getRarity()} Species, {$usealternates}' /><br /><br />
            
            <hr id='pethr'>
            <p style='text-align: left;'><b>{$this->adopt->getName()}'s Bio:</b> Not available when frozen.</p>
            </div>
            <div class='pet-stats'>
                        <ul class='profile-list'>
                        <li class='statsFloat'><b>Owner</b>: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
                        <li class='statsFloat'><b>Species</b>: {$this->adopt->getType()}</li>
                        <li class='statsFloat'><b>Gender</b>: {$gender}</li>
                        <li class='statsFloat'><b>Obtained From</b>: {$this->adopt->getObtainedFrom()}</li>
                        <li class='statsFloat'><b>Total Points</b>: {$this->adopt->getTotalClicks()}</li>
                        <li class='statsFloat'><b>Obtained On</b>: {$this->adopt->getObtainedOn()}</li>
                        <li class='statsFloat'><b>Level</b>: {$this->adopt->getCurrentLevel()}</li>
                        <li class='statsFloat'><b>Trade Status</b>: {$tradestatus}</li> 

                        </ul>

                        </div>";
                        
                        throw new LevelupException($message);
                        }
                        
                         

    /*... This one, if enabled, would prevent users from visiting a pet too much a day ...*/
    # elseif($mysidia->user->getVotes() > $this->settings->number) { throw new LevelupException("number"); }

    /*... If this setting were on in the backend, it would prevent the users from visiting their own pets ...*/
    # elseif($this->settings->owner == "disabled" and $this->adopt->getOwner() == $mysidia->user->username){ throw new LevelupException("owner");}
    
    /*... If the visitor has not seen the pet today, this will be displayed and the pet will level up! ...*/
    else{
        $newClicks = $this->adopt->getTotalClicks() + 1;
        $this->adopt->setTotalClicks($newClicks, "update");
        $mysidia->db->insert("vote_voters", array("void" => NULL, "date" => $date->format('Y-m-d'), "username" => $mysidia->user->username, "ip" => $ip, "adoptableid" => $mysidia->input->get("aid")));         
        
        $ago = date('Y-m-d', strtotime('-40 days'));
        $mysidia->db->delete("vote_voters", "date < '{$ago}'");    

        if($this->adopt->hasNextLevel()){
            $nextLevel = $this->adopt->getNextLevel();
            $requiredClicks = $nextLevel->getRequiredClicks();
            if($requiredClicks and $newClicks >= $requiredClicks) { $this->adopt->setCurrentLevel($nextLevel->getLevel(), "update"); }
        }
        
        $reward = $mysidia->user->clickreward($this->settings->reward);
        $mysidia->user->changecash($reward);            
        $this->setField("adopt", $this->adopt);
        $this->setField("reward", new Integer($reward));            
    }
}  


	public function siggy(){
	    $mysidia = Registry::get("mysidia");
        // The adoptable is available, let's collect its info
	    $usingimage = "no";
	    $image = $this->adopt->getImage(); 
	  
	    $usegd = $mysidia->settings->gdimages;
	    $imageinfo = @getimagesize($image);
	    $imagemime = $imageinfo["mime"]; // Mime type of the image file, should be a .gif file...

	    if(function_exists('imagegif') and $usegd == "yes" and $imagemime == "image/gif"){
	        $usingimage = "yes"; //Turn the template system off
            $type = $this->adopt->getType();
            list($width, $height, $type, $attr) = getimagesize($image); // The size of the original adoptable image

	        // Lets create the new target image, with a size big enough for the text for the adoptable
	        $newheight = $height + 72;
            $newwidth = ($newwidth < 250)?250:$width;
            $img_temp = imagecreatetruecolor($newwidth, $newheight); 
            $alphablending = true;  
		 
    	    // Lets create the image and save its transparency  
            $img_old = @imagecreatefromgif($image);  
            imagealphablending($img_old, true);  
            imagesavealpha($img_old, true);
   
            // Lets copy the old image into the new image with  
            ImageCopyResampled($img_temp, $img_old, 0, 0, 0, 0, $width, $height, $width, $height);    
	        $textheight = $width + 2;
	        $image = $img_temp;
            $bgi = imagecreatetruecolor($newwidth, $newheight);
            $color = imagecolorallocate($bgi, 51, 51, 51);
		 
		    // Build text for siggy
            $str1 = "Name: ".$this->adopt->getName();
            $str2 = "Owner: ".$this->adopt->getOwner();
	        $str3 = "Click Here to Feed Me!";
	        $str4 = "More Adopts at:";
	        $str5 = "www.".constant("DOMAIN");

            // Renger Image
	        imagestring ($image, 12, 0, $textheight,  $str1, $color);
	        imagestring ($image, 12, 0, $textheight + 13,  $str2, $color);
	        imagestring ($image, 12, 0, $textheight + 26,  $str3, $color);
	        imagestring ($image, 12, 0, $textheight + 42,  $str4, $color);
	        imagestring ($image, 12, 0, $textheight + 55,  $str5, $color);
	        $background = imagecolorallocate($image, 0, 0, 0);  
            ImageColorTransparent($image, $background);  
 
            // At the very last, let's clean up temporary files
	        header("Content-Type: image/GIF");
	        ImageGif ($image);
	        imagedestroy($image);
	        imagedestroy($img_temp);
	        imagedestroy($img_old);
	        imagedestroy($bgi);

	    }
	    else{  	
	            // We are going to try and get this image the old fashioned way...
            $extList = array();
	        $extList['gif'] = 'image/gif';
	        $extList['jpg'] = 'image/jpeg';
	        $extList['jpeg'] = 'image/jpeg';
	        $extList['png'] = 'image/png';

	        //Define the output file type
	        $contentType = 'Content-type: '.$extList[ $imageinfo['extension'] ];

	        if($imageinfo['extension'] =! "image/gif" and $imageinfo['extension'] =! "image/jpeg" and $imageinfo['extension'] =! "image/png"){	         
	            throw new InvalidIDException("The file Extension is not allowed!");
	        }
	        else{
                // File type is allowed, so proceed
	            $status = "";
	            header($contentType);
                $curl = new Curl($image);
				$curl->setHeader();
				$curl->exec();
				$curl->close();
	        } 
	    }
	}
	
	public function daycare(){		
		$daycare = new Daycare;
		$adopts = $daycare->getAdopts();
		$this->setField("daycare", $daycare);
	}
}
?>
 
Last edited:
*shrug* I haven't built a pet bio field myself. I mean... you could do it all without functions, if you wanted...? You want to filter the bio variable immediately before storing it in the database, so whatever file you're doing that in.
 
Ooohhh, I see what you mean. I think I understand now. Gonna try adding it soon and report back. c:
 
Yeah, it should. I just haven't tried yet.... at all.... I don't have time and it's not a change I've made to my site.

Personally I was going to do an even heavier overhaul on my bio field to allow for some WYSIWYG controls (buttons for bold, italic, etc). I also know from working on my other site that if I use a div with contenteditable=true it'll respect keyboard shortcuts. Unfortunately, I have to seriously look into that because I'm used to using ajax and a div is not a true form input element, despite respecting keyboard shortcuts in html5 and for whatever reason textarea elements still do not... but I digress!
 
...okay, so before I can build the report feature I need to actually make a pet bio setup for myself. Ah... still, look it over so our database fields are the same and so you can get the filters in place that will fix the slashes and allow some html to render!!

.
.
.
.


Pet Profile Mod: Biography Field
If you don't know what a pet profile is, see THIS THREAD to understand how such a thing can be done and find some loose instructions on how to begin with that sort of thing. Already have one? Great!

Step One: Database
Access your database with phpMyAdmin and open the table adopts_owned_adoptables. You can either manually add a VARCHAR 1500 field by the name of 'bio' yourself or open the Structure tab and enter in this SQL:
Code:
ALTER TABLE `adopts_owned_adoptables` ADD `bio` VARCHAR(1500) NULL DEFAULT NULL AFTER `owner`;

Step Two: Management Link
Inside view/myadoptsview.php's public function manage() add:
PHP:
$document->add(new Image("templates/icons/title.gif")); // This could be whatever.
$document->add(new Link("myadopts/editbio/{$aid}", " Edit {$name}'s Bio", TRUE));

Step Three: Bio Edit Page
Add into view/myadoptsview.php:
PHP:
public function editbio(){
	$mysidia = Registry::get("mysidia");
	$adopt = $this->getField("adopt");		
	$image = $this->getField("image");		
	$document = $this->document;
	
	if($mysidia->input->post("submit")){
		$document->setTitle("Biography Field Updated");
		$document->add($image);
		$document->add(new Comment("<br/>You've successfully modified {$adopt->getName()}'s biography. <br/> Would you like to <a href='../../myadopts/manage/{$adopt->getAdoptID()}'>continue to manage</a> {$adopt->getName()} or <a href='../../levelup/click/{$adopt->getAdoptID()}'>view their profile</a>?"));
		return;
	}
	
	$document->setTitle("Biography of ".$adopt->getName());
	$document->add($image);
	$document->addLangvar("<br/>Write a little something about {$adopt->getName()}! Try to keep it under 1500 characters.<br/>");
	
	$editBioForm = new FormBuilder("editbioform", "", "post");
	$editBioForm->buildTextArea("adoptsbio", $value="{$adopt->getPetBio()}")->buildButton("Edit Bio", "submit", "submit");
	$document->add($editBioForm);		   
}

Add into myadopts.php:
PHP:
public function editbio(){
	$mysidia = Registry::get("mysidia");		
	if($mysidia->input->post("submit")){			
		$this->adopt->setPetBio($mysidia->input->post("adoptsbio"), "update");
	}
    $this->setField("adopt", $this->adopt);		
	$this->setField("image", $this->image);			
}

Step Four: Send and Receive Bio
** The filters in these functions will fix slashes after apostrophes AND allow basic HTML elements to render.

Add into classes/class_ownedadoptable.php:
PHP:
public function setPetBio($bio, $assignMode = ""){
	$bio = trim($bio); 
    $bio = stripslashes($bio); 
    $bio = htmlspecialchars($bio);

    /* Remove CSS styles that may allow for malicious edits. */
    $list = array('position','float','z-index','font-size'); 
    $patterns = array(); 
    foreach ($list as $v){ 
        $patterns[]= '/'.$v.'\s*:\s*[^;"]*;?/'; 
    } 
    $bio = preg_replace($patterns,'', $bio);

    $bio = html_entity_decode($bio); 

    /* Because of the way DOMDocument() works below, unclosed HTML angle brackets will be considered errors and removed. */
    /* Many emoticon faces and even the common <3 symbol utilize angle brackets! We're going to give a few safe harbor below... */
    $bio = str_ireplace('<3','♥',$bio); 
    $bio = str_ireplace('_<','_<',$bio);  
    $bio = str_replace('D<','D<',$bio); 
    $bio = str_replace('D:<','D:<',$bio);     
    $bio = str_replace('u<','u<',$bio); 
    $bio = str_replace('w<','w<',$bio); 
    $bio = str_replace('o<','o<',$bio); 
    $bio = str_replace('U<','U<',$bio); 
    $bio = str_replace('W<','W<',$bio); 
    $bio = str_replace('O<','O<',$bio); 

    /* This will help prevent malicious Javascript inclusion so users don't click links that activate code. */
    $bio = str_ireplace('<a href="j','<a href="## ',$bio); 
    $bio = str_ireplace('onclick=',' ',$bio); 

    /* This will make sure all links open a new tab. */
    $bio = str_ireplace('<a ','<a target="_BLANK" ',$bio); 
    $bio = str_ireplace('<strike>','<s>',$bio); $bio = str_ireplace('</strike>','</s>',$bio); 
    $bio = preg_replace('/(<br>){1,}$/', '', $bio);    

    $doc = new DOMDocument(); 
    $doc->loadHTML('<?xml encoding="UTF-8" >' . $bio); 
    $bio = $doc->saveHTML(); 

    /* This contains HTML tags that are exceptions: therefore ALLOWED and AREN'T going to be stripped out. */ 
    $bio = strip_tags($bio,'<a><pre><code><b><i><img><center><u><s><em><sub><sup><strong><br><span><small>');  

    $bio = trim($bio);   

    /*Okay NOW we can put it in the database!! ^_^;; */
	if($assignMode == Model::UPDATE) $this->save("bio", $bio);
    $this->bio = $bio;
}

public function getPetBio(){
    return htmlspecialchars_decode($this->bio);
}

Step Five: Render to Pet Profile
Again, if you don't know what a pet profile is, see THIS THREAD to understand how such a thing can be done and find some loose instructions on how to begin with that sort of thing. Already have one? Great!

Inside view/levelupview.php you can access the pet bio with {$adopt->getPetBio()}. Inside levelup.php, the same variable must be accessed with {$this->adopt->getPetBio()}. If it is empty, nothing should render.

However, say you want to render it inside a div with a header above it that says "Biography". You don't need these elements to render if the bio field is empty, therefore, you need to create an if statement. (This version for view/levelupview.php:)
PHP:
if ($adopt->getPetBio() != ""){
	$bio = "<h4>Biography</h4><div class='well'>{$adopt->getPetBio()}</div>";
}

You should then render {$bio} inside the $message variable as you would other stats.

To test the system thus far, give a pet a bio that says:
Code:
Hello! <3 We're going to do some "interesting" things like <b>bold</b> and make text <small>smaller</small>.

Step Seven: Dealing With Malicious Users
We're going to now create a page users can go to if they want to report a pet with an inappropriate profile!

Inside levelup.php's public function __construct() we need to ADD the following as a condition to the first if statement (on a fresh install it should be around line 18 or so??):
PHP:
or $mysidia->input->action() == "report"

Also here in levelup.php, we're going to create:
PHP:
public function report(){
    $mysidia = Registry::get("mysidia");
	$admin = new Admin($mysidia->settings->systemuser);
	$reason = $mysidia->input->post("reason");

	if($mysidia->input->post("reason")){
		$pm = new PrivateMessage(); 
		$pm->setsender($mysidia->user->username); // Will appear to be sent by the reporter.
		$pm->setrecipient($admin->username);
		$pm->setmessage("<b>⚠ </b> "."Pet Profile Reported", "<b>Offending Pet:</b> (#{$this->adopt->getAdoptID()}) <a target=\"_BLANK\" href=\"../../levelup/click/{$this->adopt->getAdoptID()}\">{$this->adopt->getName()}</a> <br/><b>Pet Owner:</b> <a href=\"../../profile/view/{$this->adopt->getOwner()}\" target=\"_BLANK\">{$this->adopt->getOwner()}</a><br/><b>Reason For Report:</b> ".$reason."<br><b>Message Being Reported:</b><br><blockquote>".$this->adopt->getPetBio()."</blockquote><br><b>Report Delivered By:</b> {$mysidia->user->username}");
		$pm->post();  
	}

	return TRUE;  
}

Now, open up view/levelupview.php and create:
PHP:
public function report(){
    $mysidia = Registry::get("mysidia");
    $document = $this->document;        
    if($mysidia->input->post("submit")){        
        $document->setTitle("Pet Profile Reported");
        $document->addLangvar("Thank you for your report! An admin will look over it soon. Please do not contact the offending party about this incident. Instead, let us handle it!");
        return;
    }                
    
    $reportForm = new Form("reportform", "", "post");
    $reportForm->add(new Comment("<b>Reason:</b>"));
    $reportForm->add(new TextArea("reason", "(Enter a reason here!)"));
    $reportForm->add(new Button("Report", "submit", "submit"));    
    
    $document->setTitle("Reporting a Pet Profile");
    $document->addLangvar("Valid reasons for a report include but are not limited to excessive use of swear words, defamation/harassment, and the mention or depiction of activities inappropriate for children.<br/>");
    $document->add($reportForm); 		
}

The report page for any given pet, say a pet with adoptable id # of 8, would be located at yoursite.com/levelup/report/8. You'll want to add a link to the adoptable's report page on their profiles. Inside public function click() of view/levelupview.php you can use:
PHP:
if(($mysidia->user->username != NULL) && ($mysidia->user->username != $adopt->getOwner())){
	$reportlink = "<a href='../../levelup/report/{$adopt->getAdoptID()}'>Report!</a>";
}
And you can then include {$reportlink} inside $message wherever you feel would be best. Be sure to go do that now!

Inside levelup.php's public function click() you'll want to do the same (it's similar, but we need to specify $this):
PHP:
if(($mysidia->user->username != NULL) && ($mysidia->user->username != $this->adopt->getOwner())){
	$reportlink = "<a href='../../levelup/report/{$this->adopt->getAdoptID()}'>Report!</a>";
}

Both of these are checking if the user has a username first to prevent guests from filing reports -- not just for the sake of spam, but also because you wouldn't be able to open a PM sent from a nonexistent user, anyway. These report links also will not show up if the pet is the user's own.
 
Last edited:
Kyttias this is great! *o* That's totally fine, I would attempt it myself but have been busy with other things and I think it might be too advanced for me to figure out. ;-;

But yes, this is awesome and working great so far! <3 Hardly had to edit anything. Thank you so much!
 
edit: Done! The report feature is now included as step seven above. :3
 
Last edited:
Oh my gosh that was so quick! *o* Awesome! I'm gonna get it added asap and report back!

EDIT: it's beautiful! ;-; Thank you Kyttias! <33
 
Last edited:
Been following this as I've been trying to make pet bios as well, haha...I tried to follow your steps, Kyttias, but as usual for some reason it hates me and will not display anything, and when trying to edit (by going to .../myadopts/editbio/ID) I get this error;
You specified an invalid action that cannot be completed.

I followed steps 1 through 5 exactly (wanted to get them displaying before worrying about the report function) :mii:

I added;
PHP:
	public function editbio(){
    $mysidia = Registry::get("mysidia");
    $adopt = $this->getField("adopt");        
    $image = $this->getField("image");        
    $document = $this->document;
    
    if($mysidia->input->post("submit")){
        $document->setTitle("Biography Field Updated");
        $document->add($image);
        $document->add(new Comment("<br/>You've successfully modified {$adopt->getName()}'s biography. <br/> Would you like to <a href='../../myadopts/manage/{$adopt->getAdoptID()}'>continue to manage</a> {$adopt->getName()} or <a href='../../levelup/click/{$adopt->getAdoptID()}'>view their profile</a>?"));
        return;
    }
    
    $document->setTitle("Biography of ".$adopt->getName());
    $document->add($image);
    $document->addLangvar("<br/>Write a little something about {$adopt->getName()}! Keep it under 1500 characters.<br/>");
    
    $editBioForm = new FormBuilder("editbioform", "", "post");
    $editBioForm->buildTextArea("adoptsbio", $value="{$adopt->getPetBio()}")->buildButton("Edit Bio", "submit", "submit");
    $document->add($editBioForm);           
	}

To the bottom of the file in myadoptsview.php (before the closing view bracket and PHP tag)...could the error have to do with placement..?
 
Hmm... I just put mine between the rename() and trade() functions that already existed. *shrug* At the end of the file the function will end, then class will end, and then the file will end, so:
PHP:
class MyadoptsView extends View{ # this is actually at the start of the file

	public function editbio(){ 
		/*....*/
	} # ends the function

} # ends the class that begins at the start of the file
?>

Ah, but the second part of step three, there is a version of editBio() in the non-view version of the file. Without it, I think you'd get the error you have, too.
 
Last edited:
OK, I have bios working perfectly now <3

Just tried to add the report feature and I get this error when actually trying to submit the report:
Fatal error: Call to a member function getAdoptID() on null in /home/arieng/catisserie.net/levelup.php on line 271
 
It doesn't sound like it's getting the adoptable's ID right... can you give me what's on line 271 and around it?
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,132
Members
1,603
Latest member
Monako
BETA

Latest Threads

Top