Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Remove "already leveled creature today" text? (http://www.mysidiaadoptables.com/forum/showthread.php?t=4941)

tahbikat 12-18-2015 08:55 PM

Remove "already leveled creature today" text?
 
I'm making simple profile pages for the adoptables on my site using their levelup pages, but the text that pops up when a member has already leveled a creature kind of removes the whole thing.

Basically what I've done is added new comments to the levelup view file, and I want that to display even if a member has clicked the adoptable that day, so is there an easy way to disable the "already leveled creature today" text?

I still want the adopts to only be clicked once per user though.

Kyttias 12-19-2015 03:51 AM

My work around for this was way too hacky in bypassing the 'error' of 'already leveled creature today'. I'm curious as to HoF's answer.

Perhaps you can glean something out of what I've got (though I toned down the message variable to cut out most of my profile stuff that'd be too custom, left in the usual data) -

Note that this is JUST the click function in levelup.php, not the whole file. Don't use it as is, try to understand it. @w@ Good luck!

  Spoiler: hidden 

PHP Code:

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"; } 

        if (
$mysidia->user->username == $this->adopt->getOwner()){ $manage_btn "<a class='btn btn-sm btn-info' href='../../yournovu/manage/{$this->adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage Your Novu</a>"; } 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 "<b>For Trade</b>"; } 
        else { 
$tradestatus "<b>Not For Trade</b>"; }

        
$message "<div class='adopt_profile'>    <h2>{$this->adopt->getName()}</h2>    ";
        
        
// If you've already seen the pet today:
        
if ($this->adopt->hasVoter($mysidia->user$date)){
            
$message .= "<div style='float: right; margin-right: 15%; margin-top: -15px;'><b>Thanks!</b>  You played with this Novu 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'><i class='fa fa-paw'></i> Play</span></div>";
        }
            
$message .= "{$manage_btn}
                        <ul>
                        <li>Travels With: <a href='/profile/view/
{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
                        <li>Birthday: 
{$this->adopt->birthday}</li>
                        <li>Species: 
{$this->adopt->getType()}</li>
                        <li>Gender: 
{$gender}</li>
                        <li>LVL: 
{$this->adopt->getCurrentLevel()} {$toNext}</li>
                        <li>Total EXP: 
{$this->adopt->getTotalClicks()}</li> 
                        <li>Trade Status: 
{$tradestatus}</li> 
                        </ul>
                        "
;

        throw new 
LevelupException($message);
    } 

    
/*... But do this if the pet is frozen! ...*/
    
elseif($this->adopt->isFrozen() == "yes") { throw new LevelupException("frozen"); }

    
/*... 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));            
    }




There are numerous reasons you can't use this as-is, mostly because some of it's been modified in ways unique to my site. I've change a few core page urls, so this part, for example -

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

- has things linking to a yournovu/manage/ page, because my adoptables are called Novu, rather than whatever the original url for that link should be. I forgot. @w@ Stuff like that is different. I also don't know if the system originally kept track of pet birthdays, so that may break, etc.

And, all in all, I DON'T recommend what I've done to get the profile page to work. (I also added in some Javascript elsewhere that deletes the error title itself but that's not included.)

And why don't I like my solution? Because it's still using what was there -

throw new LevelupException($message);

- and I just changed the $message. It's still an Exception being thrown and I'd love to rewrite the entire thing and avoid using exceptions but I don't know how. It's expecting an error to be thrown if things are just so, and I'm just making it look like there wasn't an error.

.

.

.

Basically, HoF, I think what we want (for future releases) are profile pages for our pets that are the same no matter what - whether you've visited the pet or not, whether it's yours or not, and whether it's frozen or not. Rather than change the entire page, just add in a small memo to the pet's profile that says "Thanks for visiting this pet", a link back to the management page if it's your pet, and/or a notification that the pet didn't gain experience because the owner has it frozen.

Abronsyth 12-19-2015 08:37 AM

I'm very curious about this as well as I've been trying to do this for a bit now (but 96% fail with understanding PHP).

tahbikat 12-20-2015 02:15 AM

Thank you Kyttias! I'm definitely going to see if I can incorporate any of this into my own site's code! (:

Abronsyth 12-21-2015 06:12 PM

Nevermind, I got it working! For anyone who, like me, is not super code savvy but trying to get the image to display in the levelup.php file I used this (I'm sure I could have done something more effective but this works perfectly fine so *shrug*!):
PHP Code:

<img src='{$this->adopt->getImage()}'/> 


tahbikat 12-24-2015 05:30 AM

Installed it onto my site but haven't had a chance to change much. Super late right now. Gonna fiddle with it more tomorrow! Thanks so much Kyttias! And thanks Abronsyth for the image code. c:

Kyttias 12-24-2015 02:58 PM

Basically, the error is still being thrown. You could use a bit of jQuery to cover it up (just add it alongside the rest - it's in script element tags, so it won't be seen like ordinary html - I included it after the last </div> I'm using on my pet's profiles before even closing the message variable). Of course, this'll only work if you have jQuery as part of your theme's template (Bootstrap theme definitely does):
Code:

<script>$(\"h2:contains('An error has occurred.')\").remove();</script>
The code literally removes any h2 element that contains the words "An error has occurred." - gotta love jQuery. The quotes are backslashed as they need to be going into the $message variable. Can't have quotes inside other quotes inside other quotes without the system getting confused, so, backslashes. Yay. -_- (It originally took me a while to figure out.)

And, incidentally, you can change your error message text site-wide from lang/lang_global.php -- so if you happen to change it there, be sure to update the snippet I just provided to reflect that.

(** And yeah, Abronsyth, I forgot to include a pet image -- my pet images are rendered with some custom code, so I took my bit out but couldn't remember the original -- thanks for providing that snippet of code!!)

tahbikat 12-25-2015 12:35 AM

Thanks so much Kyttias! I'm having trouble with removing the error part. I think the jquery isn't being enabled maybe. How exactly do I enable jquery on my site?

I've tried adding this to my theme's header.tpl but it's not working:
HTML Code:

<script src="{$home}/jquery/jquery-1.11.3.min.js"></script>
I've made a jquery folder with the jquery library in it, so that's why I was using that. ^
I've also tried the hosted links from google and microsoft but they're not working either. :c

Kyttias 12-25-2015 10:50 AM

Weird, but, check that the jQuery library is being loaded with your pages. This really is as simple as linking it and using it. Is the link you added to your header shower up when a page loads/you sure you added it to the right theme? The file does seem to exist in that location on the live version of your site, but a link to it does not appear when I load a page - but maybe you're testing elsewhere.

But, perhaps more to the point, your page titles seem to be in h1 not in h2. Change the code I gave you so it knows to check an h1 tag instead.

tahbikat 12-26-2015 04:53 AM

Oh GAWD that was probably the problem. They were h2 and not h1.

I removed the jquery link because i noticed my pages loaded slow after it was added... Like really slow. But that's probably why you didn't see the link anymore.
Ahh, thanks! I'll see if it works now. But if it's still slow I think I'll just change the error message instead... Unless there's a way to make it not cause pages to be loaded so slow? Lol

Thanks again, you're amazing! <3


All times are GMT -5. The time now is 04:06 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.