Mys 1.3.4 Public Profile Mod

Forum
Last Post
Threads / Messages

KatFennec

Member
Member
Joined
Apr 21, 2017
Messages
57
Points
0
Age
30
Mysidian Dollar
4,476
The following is a mod that extends the functionality of levelup.php to create a profile for each pet, viewable by other users.

profile_by_katherinefennec-db8xoon.png


This mod is heavily based on code provided by Kyttias

To get started, open levelup.php and change
PHP:
if($mysidia->input->action() == "click" or $mysidia->input->action() == "siggy" $this->adopt = new OwnedAdoptable($mysidia->input->get("aid"));
to
PHP:
if($mysidia->input->action() == "click" or $mysidia->input->action() == "siggy" or $mysidia->input->action() == "publicprofile") $this->adopt = new OwnedAdoptable($mysidia->input->get("aid"));
, t
at the bottom paste the following:
PHP:
public function publicprofile(){
#begin profile code
$mysidia = Registry::get("mysidia");
$date = new DateTime;
$this->setField("adopt", $this->adopt);
$ip = secure($_SERVER['REMOTE_ADDR']);

Next, open levelupview.php, found in your views folder.
again, scroll down to the bottom and paste:
PHP:
public function publicprofile(){
			$mysidia = Registry::get("mysidia");
			$adopt = $this->getField("adopt");			
			$adoptcurrentlevel = $adopt->currentlevel;
		    $document = $this->document;
            $document->setTitle("Viewing {$adopt->getName()}'s profile");
		if($adopt->hasNextLevel()){
			$nextLevel = $adopt->getNextLevel();
			#$requiredClicks = $nextLevel->getRequiredClicks();
$thisisauniqueid = new OwnedAdoptable($adopt->getAdoptID());
$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$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 = '{$adopt->getAdoptID()}'")->fetchColumn();
if ($mysidia->user->username == $adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../myadopts/manage/{$adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage</a>"; } else { $manage_btn = ""; }

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

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



// If you've already seen the pet today:
if ($adopt->hasVoter($mysidia->user, $date)){
$document->add(new Comment("<a class='btn btn-sm btn-info disabled' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Already Fed</a>"));
}
// If you haven't seen the pet today:
else {
$document->add(new Comment("<a class='btn btn-sm btn-info' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Feed</a>"));
};
}
$document->add(new Comment("{$manage_btn}
<br> <br>
<img src='{$thisisauniqueid->getImage()}'><br>"));
$adoptabletype = $mysidia->db->select("adoptables", array(), "type='{$adopt->getType()}'")->fetchObject();
$diet = $adoptabletype->Diet;
$level = $adopt->getCurrentLevel();
$document->add(new Comment("<ul>
<li>Lives With: <a href='/profile/view/{$adopt->getOwner()}'>{$adopt->getOwner()}</a></li>
<li>Species: {$adopt->getType()}</li>
<li>Gender: {$gender}</li>

<li>LVL: {$adopt->getCurrentLevel()} {$toNext}</li>
<li>Total EXP: {$adopt->getTotalClicks()}</li> 
<li>Trade Status: {$tradestatus}</li>

"));
		}

This essentially creates a new page under levelup, yoursite.com/levelup/publicprofile/(adoptable ID number), but there isn't anything that links to it yet! We'll fix that next. Open myadoptsview.php and under the line reading
PHP:
$document->add(new Link("levelup/click/{$aid}", " LevelUp {$name}", TRUE));
,
add
PHP:
$document->add(new Link("levelup/publicprofile/{$aid}", " View {$name}'s Profile", TRUE));
.

Now you can view your pets' profiles. But what about other people? If you want them to see the pet's info, go back to levelup.php and replace
PHP:
$message = ($mysidia->user instanceof Member)?"already_leveled_member":"already_leveled_guest";
with
PHP:
$message .= "You already clicked this adoptable today.  Try again tomorrow. <br>
		<a class='btn btn-sm btn-info' href='../../levelup/publicprofile/{$this->adopt->getAdoptID()}'><i class='fa fa-chevron-left'></i> Back to Profile</a>";

Finally, open class_adoptablehelper.php, in your classes folder, and replace
PHP:
public function getLevelupLink(OwnedAdoptable $adopt){	
        return new Link("levelup/click/{$adopt->getAdoptID()}", $adopt->getImage("gui"));
with
PHP:
public function getLevelupLink(OwnedAdoptable $adopt){	
        return new Link("levelup/publicprofile/{$adopt->getAdoptID()}", $adopt->getImage("gui"));
And you're done~!
 
Last edited:
Just noticed I forgot something: Go into classes/class_ownedadoptable and change all of the protected variables to public.
 
Oh so this is a pet profile mod? It looks interesting, adoptables profile is among the next few things I will add for Mysidia's next release. Your mod will be especially helpful for those who cannot upgrade to newer script due to heavily customized scripts, I am sure a lot of users will appreciate this. ^^
 
It's especially helpful for sites that want a nonstandard experience/level system, as it doesn't depend on exceptions to operate. Hopefully, folks get some good use out of it.
 
you can also create a new page well 2 pages, the petprofile.php and the petprofilelview.php, that's how i made the profile for my site =), but i think this can also be added to the profile.php and profileview.php instead of the levelup pages.
Still thanks for sharing how you manage to make it work in the levelup page ^^... i must say that i tried to do that but never manage to make it work, that's why i ended making a new page.
 
I'm having an issue with this code I believe. All pets at level 2 (final level at this point) don't show their tradestatus or gender.

Any ideas why?
 
I'm having an issue with this code I believe. All pets at level 2 (final level at this point) don't show their tradestatus or gender.

Any ideas why?

Can you post a copy of your levelupview.php?
 
PHP:
?php

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

class LevelupView extends View{
	
	public function click(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;				
        $adopt = $this->getField("adopt");			
		$reward = $this->getField("reward")->getValue();
		$document->setTitle("{$this->lang->gave} {$adopt->getName()} one {$this->lang->unit}");

		$image = $adopt->getImage("gui");  
		$image->setLineBreak(TRUE);		
		$summary = new Division;
		$summary->setAlign(new Align("center"));
        $summary->add($image);	
        $summary->add(new Comment("{$this->lang->gave}{$adopt->getName()} one {$this->lang->unit}."));
        $summary->add(new Comment($this->lang->encourage));
        $summary->add(new Comment("<br> You have earned {$reward} {$mysidia->settings->cost} for leveling up this adoptable. "));
        $summary->add(new Comment("You now have {$mysidia->user->getcash()} {$mysidia->settings->cost}"));
        $document->add($summary);	
	
	}

	public function siggy(){
	
	}
	
	public function daycare(){
		$mysidia = Registry::get("mysidia");
		$document = $this->document;	
        $document->setTitle($this->lang->daycare_title);
        $document->addLangvar($this->lang->daycare, TRUE);
		
		$daycare = $this->getField("daycare");
        $adopts = $daycare->getAdopts();
		$daycareTable = new Table("daycare", "", FALSE);
		$daycareTable->setBordered(FALSE);
		$total = $daycare->getTotalAdopts();
        $index = 0;

		for($row = 0; $row < $daycare->getTotalRows(); $row++){
	        $daycareRow = new TRow("row{$row}");
            for($column = 0; $column < $daycare->getTotalColumns(); $column++){
			    $adopt = new OwnedAdoptable($adopts[$index]);
				$cell = new ArrayList;
				$cell->add(new Link("levelup/click/{$adopt->getAdoptID()}", $adopt->getImage("gui"), TRUE));
				$cell->add(new Comment($daycare->getStats($adopt)));
				$daycareCell = new TCell($cell, "cell{$index}");
                $daycareCell->setAlign(new Align("center", "center"));
				$daycareRow->add($daycareCell);
				$index++;
				if($index == $total) break;
            }
            $daycareTable->add($daycareRow);			
		}
		
        $document->add($daycareTable);
		if($pagination = $daycare->getPagination()) $document->addLangvar($pagination->showPage());
	}
	public function publicprofile(){
            $mysidia = Registry::get("mysidia");
            $adopt = $this->getField("adopt");            
            $adoptcurrentlevel = $adopt->currentlevel;
            $document = $this->document;
            $document->setTitle("Viewing {$adopt->getName()}'s profile");
        if($adopt->hasNextLevel()){
            $nextLevel = $adopt->getNextLevel();
            #$requiredClicks = $nextLevel->getRequiredClicks();
$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$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 = '{$adopt->getAdoptID()}'")->fetchColumn();
if ($mysidia->user->username == $adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../myadopts/manage/{$adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage</a>"; } else { $manage_btn = ""; }

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

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



// If you've already seen the pet today:
if ($adopt->hasVoter($mysidia->user, $date)){
$document->add(new Comment("<a class='btn btn-sm btn-info disabled' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Already Fed</a>"));
}
// If you haven't seen the pet today:
else {
$document->add(new Comment("<a class='btn btn-sm btn-info' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Feed</a>"));
};
}
$document->add(new Link("myadopts", $adopt->getImage("gui")));
$adoptabletype = $mysidia->db->select("adoptables", array(), "type='{$adopt->getType()}'")->fetchObject();
$level = $adopt->getCurrentLevel();
$bio = $adopt->getPetbio();
$document->add(new Comment("<ul>
<li>Lives With: <a href='/profile/view/{$adopt->getOwner()}'>{$adopt->getOwner()}</a></li>
<li>Species: {$adopt->getType()}</li>
<li>Gender: {$gender}</li>
<li>LVL: {$adopt->getCurrentLevel()} {$toNext}</li>
<li>Total EXP: {$adopt->getTotalClicks()}</li>
<li>Trade Status: {$tradestatus}</li>
<li>Bio: {$bio}</li>
")) ;
}
      
 }

?>

Here it is. I'm also trying to figure out how to put a button in on the lvl up page (you've fed blah blah and earned this much cash) that links to the public profile as well as it's only available if you've already fed them.
 
Here it is. I'm also trying to figure out how to put a button in on the lvl up page (you've fed blah blah and earned this much cash) that links to the public profile as well as it's only available if you've already fed them.

OK, I found the problem, and it looks like it was a mistake I made in the original.

Where it says
PHP:
if($adopt->hasNextLevel()){ 
            $nextLevel = $adopt->getNextLevel();
Add a new line after it, and put };
Then go down to where it says:
PHP:
$document->add(new Comment("<a class='btn btn-sm btn-info' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Feed</a>")); 
}; 
}
And remove the last }
That should fix your problem.
 
awesome, thanks :) That works!

Any ideas on a link back to the public profile when they're clicking the pet rather than if they've clicked? (both would be nice)
 
awesome, thanks :) That works!

Any ideas on a link back to the public profile when they're clicking the pet rather than if they've clicked? (both would be nice)

Put
PHP:
<a class='btn btn-sm btn-info' href='../../levelup/publicprofile/{$adopt->getAdoptID()}'><i class='fa fa-chevron-left'></i> Back to Profile</a>
in the click function, wherever you want it (Kat and my site has it under the display of what you've obtained).
 
After installing this, I ran into a "call to member function" error because it couldn't get the image of the pet. I found that using:
<img src='{$adopt->getImage()}'><br>"));
Works just fine rather than using the unique id variable, since $adopt is already defined and the image can be retrieved from there. Just putting this out there for others that might run into it.
 
Thanks for the mod and Dino, thanks for the alternative code for the image. I couldn't get it work before. LOVE YOU BOTH!
 
What is the 1.3.6 equivalent to levelup.php? Is it just level.php? If so, that code must have changed a lot as I cannot find the line mentioned.......
 
What is the 1.3.6 equivalent to levelup.php? Is it just level.php? If so, that code must have changed a lot as I cannot find the line mentioned.......
The equivalent to levelup.php is levelupcontroller.php. level.php is for the adminCP, adding levels to your adopts and such
 
Ugh.... And I'm stuck again......
Keep getting this error on every single critter, but it's better than the white page I was getting:
1699935990613.png
PHP:
//This is just the publicprofile section, not the full levelupview.php
public function publicprofile(){
            $mysidia = Registry::get("mysidia");
            $document = $this->document;
            $adopt = $this->getField("adopt");
            $currentlevel = $adopt->getField("currentlevel");
            
            $document->setTitle("Viewing {$adopt->getName()}'s profile");
            
        if($adopt->hasNextLevel()){
            $nextLevel = $adopt->getNextLevel();
            $requiredClicks = $nextLevel->getRequiredClicks();
            $adoptid = new OwnedAdoptable($adopt->getAdoptID());
            $gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$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 = '{$adopt->getAdoptID()}'")->fetchColumn();
            if ($mysidia->user->username == $adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../myadopts/manage/{$adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage</a>"; } else { $manage_btn = ""; }
            if($adopt->hasNextLevel()){
                $level = $adopt->getNextLevel();
                $levelupClicks = $adopt->getLevelupClicks();
                $document->add(new Comment("(LVL ".$level->getLevel()." in ".$levelupClicks." more EXP)"));
            } else { $document->add(new Comment("(MAX)")); }
            if($adopt->getTradeStatus() == "fortrade") { $tradestatus = "<b>For Trade</b>"; }
            else { $tradestatus = "<b>Not For Trade</b>"; }
            // If you've already seen the pet today:
            if ($adopt->hasVoter($mysidia->user, $date)){
                $document->add(new Comment("<a class='btn btn-sm btn-info disabled' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Already Fed</a>"));
            }
            // If you haven't seen the pet today:
            else {
                $document->add(new Comment("<a class='btn btn-sm btn-info' href='../../levelup/click/{$adopt->getAdoptID()}'><i class='fa fa-paw'></i> Feed</a>"));
            }
        }
            
            $document->add(new Comment("{$manage_btn}
            <br> <br>
            <img src='{$adoptid->getImage()}'><br>"));
            $adoptabletype = $mysidia->db->select("adoptables", array(), "type='{$adopt->getType()}'")->fetchObject();
            $level = $adopt->getCurrentLevel();
            $document->add(new Comment("<ul>
            <li>Lives With: <a href='/profile/view/{$adopt->getOwner()}'>{$adopt->getOwner()}</a></li>
            <li>Species: {$adopt->getType()}</li>
            <li>Gender: {$gender}</li>

            <li>LVL: {$adopt->getCurrentLevel()} {$toNext}</li>
            <li>Total EXP: {$adopt->getTotalClicks()}</li>
            <li>Trade Status: {$tradestatus}</li>
            "));
    }
PHP:
//Here's just the publicprofile section of levelupcontroller.php
    public function publicProfile(){
        $mysidia=Registry::get("mysidia");
        $this->adopt = new OwnedAdoptable($aid);
        $date=new Date;
        $ip=$mysidia->secure($_SERVER['REMOTE_ADDR']);
    }

The other sections seem to work.... It directs me to https://ashenblade.click/levelup/publicprofile/{$aid} and there's also a link when I click one I've already clicked for the day.
 
Okay I can have a look later on today, I've never used this mod before so will have to sit down and work my way through it haha
 
Okay I got it lol. Well, in so far as the page works, there's no information displayed but it worked for the owner and for another user viewing it. If you want help with adding information, especially different if the owner is viewing it or not, just let me know and I can try to cobble together an actual profile :LOL: Pulled an all nighter as I couldn't sleep so I am tiirreeddd lol. But this might be a good starting point for you. Change 'public function profile' to 'publicprofile' if you want it back to that.

levelupview:

PHP:
    public function profile(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;              
        $adopt = $this->getField("adopt");          
        $document->setTitle("Viewing {$adopt->getName()}'s Profile");

        $image = $adopt->getImage(Model::GUI);      
        $image->setLineBreak(TRUE);      
        $profile = new Division;
        $profile->setAlign(new Align("center"));
        $profile->add($image);
        $profile->add(new Comment("Viewing Profile Of This Adopt!!!"));
        $profile->add(new Comment("Profile info here"));
        $document->add($profile);          
    }

levelupcontroller:

PHP:
public function profile($aid){
        $mysidia = Registry::get("mysidia");
        $this->adopt = new OwnedAdoptable($aid);
        $this->setField("adopt", $this->adopt);
    }
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,267
Messages
33,048
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top