View Full Version : How to write a proper shop page?
parayna
12-14-2014, 05:35 AM
Can someone please help me write a proper shop page? I want to create a custom page that I make myself as that is the only way to get the placement I want for the shopkeepers (I don't know how to do it in the default shop files). So I guess I would like to ask if someone can help me write 'get' and 'getview' pages for items.. and where it deducts the price of the item from their inventory and they can also choose the quantity at some point.
The reason I want this is so that I can have a shopkeeper and then images of items underneath, and when they click the image it takes them to another page where they can maybe select the quantity? They then click buy and it deducts the money set by me in the adminCP and adds it to their inventory..
Kyttias was kind enough to help me with doing this for adoptables so I have included them in spoilers in case anyone wants help with the structure.. sorry for asking but I have already tried what I can think of and it hasn't worked >.< Thank you... I really want to get my shops up and running for my beta testers XD
<?php
use Resource\Native\Integer;
use Resource\Native\String;
class GetController extends AppController{
private $id;
public function __construct(){
parent::__construct("member");
$mysidia = Registry::get("mysidia");
if($mysidia->usergroup->getpermission("canadopt") != "yes"){
throw new NoPermissionException("permission");
}
}
public function index(){
//don't let people access yoursite.com/get
throw new InvalidActionException("global_action");
}
//yoursite.com/get/id
public function id(){
$mysidia = Registry::get("mysidia");
//get ID_NUMBER
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$parts = Explode('/', $pageURL);
$id = $parts[count($parts) - 1];
if(!$id) throw new InvalidIDException("global_id");
//---------- Edit here
/* In this part, we check if the ID is actually part of the IDs available to adopt!
* If you want adoptable 1 and 7 to be available through get/id/number, you gotta add
* 1 and 7 to the array
*/
$id_array = [1,2];//add your OK numbers here
$count = count($id_array);
$found = false;
for($i = 0; $i < $count; $i++)
{
//if ID is inside the array, then it's OK
if($id == $id_array[$i]){
$found = true;
break;
}
}
//the ID wasnt found inside the array, throw error
if(!$found)
throw new NoPermissionException("This adoptable is not available through this method.");
//----------
//after checking:
$this->access = "member";
$this->handleAccess();
//get adoptable information
$adopt = new Adoptable($id);
$conditions = $adopt->getConditions();
if(!$conditions->checkConditions()) throw new NoPermissionException("condition");
$name = $adopt->getType();
$alts = $adopt->getAltStatus();
$code = $adopt->getCode();
$gender = $adopt->getGender();
//insert into database
$mysidia->db->insert("owned_adoptables", array("aid" => NULL, "type" => $name, "name" => $name, "owner" => $mysidia->user->username, "currentlevel" => 0, "totalclicks" => 0, "code" => $code, "imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $gender, "offsprings" => 0, "lastbred" => 0));
//get its info
$aid = $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
$this->setField("aid", new Integer($aid));
$this->setField("name", new String($name));
$this->setField("eggImage", new String($adopt->getEggImage()));
}
}
?>
<?php
class GetView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Adopt a pet");
}
public function id(){
$document = $this->document;
$document->setTitle("Adopt a pet");
$aid = $this->getField("aid")->getValue();
$name = $this->getField("name")->getValue();
$eggImage = $this->getField("eggImage")->getValue();
//display information
$image = new Image($eggImage);
$image->setLineBreak(TRUE);
$document->setTitle("Catching {$id} ");
$document->add($image);
$document->addLangvar("Congratulations! You just adopted {$name}. <br>You can now manage {$name} on the ");
$document->add(new Link("myadopts", "Myadopts Page."));
$document->add(new Comment(""));
$document->add(new Link("myadopts/manage/{$aid}", "Click Here to Manage {$name}"));
$document->add(new Comment(""));
$document->add(new Link("myadopts/bbcode/{$aid}", "Click Here to get BBCodes/HTML Codes for {$name}"));
$document->add(new Comment(""));
$document->addLangvar("Be sure and");
$document->add(new Link("levelup/{$aid}", "feed "));
$document->addLangvar("{$name} with clicks so that they grow!");
}
}
?>
They are both seperate files so I guess items would need to be called getitem and getitemview? Or something like that XD Thanks if someone helps me... this has stumped me for days >.<
(It would also be nice if someone could help me with the 'adopt' shops. Or would it still be the same file? And you just put in their adoptable id? It's just I may not want all of my pets up for free, like they are from the adoptable page at the moment)
Kyttias
12-14-2014, 02:13 PM
Hmm... Well... I modified my default shop pages. Specifically, classes/class_itemshop.php. Outside of that, I really can't help. Shops are tied to three or four other files and having to clone all of them would just be tedious. Save backups of the original classes/class_itemshop.php, and bear with me. (And I assume the class for adoptshop would be similar, but I actually haven't modified mine yet.) Because you add items to shops through the AdminCP, these additional files I'm talking about all work together to display the items that belong in a particular shop, pull up item information, and construct the functionality needed for the buttons. To recreate it all, you'd need exactly the same files already in place -- so you really have no choice but to work with them, else work entirely from scratch with little help from the community.
Inside public function display is where all the important magic is happening for this (http://fc07.deviantart.net/fs71/f/2014/315/4/3/screenshot_beta_nov2014_06_by_kyttias-d8619i6.png). So examine everything going on in this function in its default state and try to wrap your head around it.
If you could draw or create a visual mockup/representation of what you want the finished product to look like, I can try to help from there? I will also need to know the name of at least two item shops to start my example, but the more the merrier. I designed my shops to use tooltips, but any arrangement of information is possible.
You want two things - to render an NPC image based on the shop, and, I assume to change the entire way items are listed.
As a start, in public function display:
# Choose the NPC image based on the name of the shop
switch ($this->shopname) {
case "Crossed Roads":
$npc_img = "http://fc00.deviantart.net/fs71/f/2014/262/a/2/base_npc_60_by_kyttias-d7zqrnf.png";
break;
case "Spectrum":
$npc_img = "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";
break;
default;
$npc_img = "http://placekitten.com/g/200/500";
break;
}
# Now let's render the NPC, use css to position the div with the class name of .shop_npc
$document->add(new Comment("<div class='shop_npc'><img src='{$npc_img}'/></div>", FALSE));
I have two shops, Crossed Roads and Spectrum. If I make a shop and forget to list it here, it will use the default.
The switch statement I've constructed above is using $this->shopname. The word "this" means, literally, defined inside this class. This page. Up at the top you'll find public $shopname;. If you were some other page, you'd need to pull up that information with a function yourself. Why create a page for each shop if each shop is going to need to pull all the same data from the database to construct itself? This is the entire basis of object oriented PHP - to avoid repeating yourself.
So this is why I encourage you to modify the default shop rendering.
If you'll show me how you want items to display, if you don't want the default table that is, I can get to the next step. ^^
-
But, then again, upon reading closer, I think you may also be wanting an entirely new kind of shop? One that uses items, rather than currency? (Possibly multiple items? And currency in addition? How complex.)
If you like the default shops as they are, you can ignore everything I've said. But an entirely new kind of shop that uses items as a currency would need work beyond what I can do in a single night.
I mean, I like the concept, so I can try to tinker over winter break. How many shops of this kind were you wanting? Just one, or many?
parayna
12-14-2014, 03:55 PM
Well, no I kind of wanted a normal shop (money as the currency). Items as a currency would be weird to me XD But that's kind of what I wanted (what you have put) where it displays NPC's above the items (so like yours but below them instead of next to them). I can quickly get a draft of what I would kind of like...
EDIT:http://fc00.deviantart.net/fs70/f/2015/001/5/6/screenshot_1_by_yurash_emc-d8c8ne2.png
Sorry for messy handwriting *^* I can't write with this tablet :eye:
Translations:
Top: *Shop name (like normal)*
Big pink box: Whatever text I want them to say (including links if needed using <a href> tags)
Arrow pointing to box: Wouldn't be pink. Would most likely just be white.
Small pink box: Item image
Text under small pink box: item name, item price, buy button
Arrow 1 leading to small pink box: Maybe also a choice to select how many to buy?
Arrow 2 leading to small pink box: That would then be repeated until the end of the row and carried on underneath (with each different item)
(Also, thank the lord for image editing programs XD)
And the names are not yet fully thought of XD But I take it you can literally just change them to whatever? If so, I guess it wouldn't matter what the example names are ^_^
Thank you for helping me! You've helped a lot! ^_^
~Parayna
Kyttias
12-14-2014, 06:11 PM
Great! This shouldn't be so hard, then. (Though now I do kind of want an item exchange system, but I think I can just squint over the alchemy mod for hints on that.)
My only foreseeable issue with your design above is in the displaying of items, for the user's sake - how will they know what the item does before they buy it? If you can, get me some more detail on what you want there. (Though if each shop has a specific type of item, there is much less confusion overall and descriptions may be irrelevant.)
Let's get done building how we want to display the page in plain HTML first, then I can work on converting it. ^^ As a start, this covers what you have in mind so far, -ish? http://jsbin.com/jabufegula/1/edit?html,css,output (You can turn off tabs for the html/css/output displays at the top, as well as drag the widths of each of these windows. By default, the output window may be narrow, so drag it wider to get the full feel of it.)
parayna
12-14-2014, 06:21 PM
Yeah. That is actually exactly what I had in mind XD For what the items do, I was either thinking of it either telling you before you buy (maybe leading to a seperate page) or having a hover over box thing (forgot the name :P) The only problem though there would be the mobile users thing.. not sure if it would work for them :/ But I dunno... XD I need some sort of description showing as even though the items will be in certain shops, they may increase the click value by different amounts (for example)
Thank you ^_^,
~Parayna
Kyttias
12-14-2014, 06:56 PM
I could probably get these tooltips (http://osvaldas.info/elegant-css-and-jquery-tooltip-responsive-mobile-friendly) to work? They're mobile-friendly, anyway. If you want tooltips in other areas of your site, then I can direct you where to save the files. ^^ Or if not, I can include them all in this one page.
I couldn't seem to find a pure-Javascript version (I didn't have much time to scour the net for a mobile-friendly pure-Javascript version). The jQuery version works just fine, you'll just also need the jQuery library. My Bootstrap theme comes with it, but I don't know that any of the default themes do, or if you included it while building your own. Let me know if you don't have it and I can either help you put it in or find an alternative. (There's a discussion to be had (http://modernweb.com/2014/03/10/is-jquery-too-big-for-mobile/) on whether the jQuery library is too big for mobile browsing, my general conclusion is no, it's not too big. And it'll only have a delay in loading the first time, not every consecutive time. And linking the same copy from the same content delivery network, CDN, that Google/YouTube/other major sites use means there's a chance the users will already have the jQuery library already cached, so there won't be delay at all.)
Do you have any requirements for things you want the NPCs to say? The same thing every time? Or a random thing from a list of several possible things (it can be random for each individual store, that's how I'm doing it)?
parayna
12-14-2014, 07:20 PM
If you could get the tooltips to work that would be amazing! Probably, if they go well, I would like to use them in other places as well (probably the inventory and the world feature when that gets implemented later in the open beta stage of the site) ^_^
I don't think I have the jQuery library.. but I am not totally sure. All of the themes I am using are based on the 'default' default mysidia theme and then I just changed aspects to fit what I wanted (images, colours, and sizes wise). Most of my betas have agreed to test out features cross platform so I would soon be able to figure out if there were any problems to be had on the mobile devices.
And I was kind of thinking of having them say different things, usually based around the same sort of idea as their other sayings (and yeah, for each different shop, as a way of being more varied and easier for people to digest). So probably using an array (which thankfully I sort of know how to do as I learnt how to make a gumball machine using arrays for a school project and that I may implement into my site as a mini game that gives out prizes, when I decide to sort games out of course.. XD)
But yeah. ^_^
Kyttias
12-14-2014, 07:55 PM
^^ I'm almost done but I need to eat dinner first. I'll be back in two hours or so with everything ready to go.
parayna
12-14-2014, 08:02 PM
Thank you! It's actually past midnight here so I will be going to bed now XD But in the morning I can come back online ^_^
Thanks~
Kyttias
12-14-2014, 09:49 PM
Alright! Over in classes/class_itemshop.php, replace public function display with this one:
public function display(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
$document->addLangvar($mysidia->lang->select_item);
if($this->gettotal() == 0){
$document->addLangvar($mysidia->lang->empty);
return FALSE;
}
# Choose the NPC image based on the name of the shop
switch ($this->shopname) {
case "Crossed Roads":
$npc_img = "http://fc00.deviantart.net/fs71/f/2014/262/a/2/base_npc_60_by_kyttias-d7zqrnf.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
case "Spectrum":
$npc_img = "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
default;
$npc_img = "http://placekitten.com/g/200/500";
$npc_text = "Welcome to {$this->shopname}!";
break;
}
# let's begin rendering the page
$document->add(new Comment("
<style>
.s_top {
overflow:hidden;
display: block;
}
.sc_npc_text{
width: 40%;
float: left;
height: 100%;
padding: 10px;
margin: 10px;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
}
.sc_npc_img{
width: 40%;
float: left;
}
.sc_item {
display: inline-block;
padding: 5px;
text-align: center;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 14px;
margin-bottom: 3px;
}
.s_panel {
border-radius: 4px;
border: 1px solid #466ec3;
background-color: #ccf3f6;
}
.s_input { width: 20px; }
</style>
<!-- START Container for Text and NPC -->
<div class='s_top s_container'>
<div class='s_panel sc_npc_text'><p>{$npc_text}</p></div>
<div class='sc_npc_img'><img src='{$npc_img}' height='300'></div>
</div>
<!-- END Container for Text and NPC -->
<!-- START Container for Items -->
<div class='s_container'>
", FALSE));
# Now render each item the store has
foreach($this->items as $stockitem){
$item = $this->getitem($stockitem);
#descriptions of the item functions
switch ($item->function) {
case "Click1": $usage = "<b>use:</b> Feed a pet to give them {$item->value} EXP.";
break;
case "Click2": $usage = "<b>use:</b> Feed a pet to set their EXP to {$item->value}.";
break;
case "Click3": $usage = "<b>use:</b> Resets today's earned EXP to 0.";
break;
case "Level1": $usage = "<b>use:</b> Raises a pet's Level by {$item->value}.";
break;
case "Level2": $usage = "<b>use:</b> Sets your pet's Level to {$item->value}.";
break;
case "Level3": $usage = "<b>use:</b> Makes your pet Level 0 again!";
break;
case "Gender": $usage = "<b>use:</b> Swaps your pet's gender to its opposite!";
break;
default;
$usage = "";
break;
}
# Now let's render each item icon, name, price and tooltip
$document->add(new Comment("
<div class='s_panel sc_item'>
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title=\"{$item->description} <em>{$usage}</em>.\"><img src='{$item->imageurl}'></abbr>
-->
<img src='{$item->imageurl}'>
<br/>
<b>{$item->itemname}</b>
<br/>
{$item->price} Credits<br/>
", FALSE));
# Building the Buy form
$buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
$buyForm->setLineBreak(FALSE);
$buyForm->buildPasswordField("hidden", "action", "purchase")
->buildPasswordField("hidden", "itemname", $item->itemname)
->buildPasswordField("hidden", "shopname", $shop->shopname)
->buildPasswordField("hidden", "shoptype", "itemshop")
->buildPasswordField("hidden", "salestax", $shop->salestax);
$quantity = new TextField("quantity");
$quantity->setSize(3);
$quantity->setMaxLength(3);
$quantity->setLineBreak(FALSE);
$buy = new Button("Buy", "buy", "buy");
$buy->setLineBreak(FALSE);
$buyForm->add($quantity);
$buyForm->add($buy);
# Actually adding in the Quantity field Buy button now
$document->add($buyForm);
# Now we finish off the item by closing its div
$document->add(new Comment("</div>", FALSE));
}
# And that's a wrap
$document->add(new Comment("</div><!-- END Container for Items -->", FALSE));
}
This is my first draft, but does not have tooltips for a description in place functioning yet. But it's definitely 99% done now. Do feel free to move the stylesheet out and join it with your existing template one. I needed it here for testing. ^^;
The usage descriptions have less to do with your item description and everything to do with what item function they have. It detects what category of function the item is stored as in the database and then will display appropriate text based on that. It's basically something I've done in addition to the existing description, but is entirely optional. (And it's not yet apparent, as the tooltips are not implemented yet). It's just something I created for my own site so I wouldn't have to repeat myself in the description of an item, leaving the functionality in a separate variable than the flavor text. ^^
parayna
12-15-2014, 02:07 AM
Thank you! But for some reason it just comes up with a blank page whenever I add it to the place you said. No idea why that could be XD
Kyttias
12-15-2014, 02:14 AM
Really? =/ You sure you copy-pasted the entire thing and replaced the entire display function? It works fine on my end...
Try sending me your entire class/classes_itemshop.php, please?
(In addition, do any of your item names, descriptions, or shop names contain apostrophes or quotes? These could cause potential issues. Nothing that's not fixable, of course.)
Otherwise, here's the whole file:
<?php
use Resource\Collection\LinkedList;
class Itemshop extends Model{
public $sid;
public $category;
public $shopname;
public $shoptype;
public $description;
public $imageurl;
public $status;
public $restriction;
public $salestax;
public $items;
protected $total = 0;
public function __construct($shopname){
// Fetch the database info into object property
$mysidia = Registry::get("mysidia");
$row = $mysidia->db->select("shops", array(), "shopname ='{$shopname}'")->fetchObject();
if(!is_object($row)) throw new Exception("Invalid Shopname specified");
// loop through the anonymous object created to assign properties
foreach($row as $key => $val){
$this->$key = $val;
}
$this->items = $this->getitemnames();
$this->total = (is_array($this->items))?count($this->items):0;
}
public function getcategory(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("shops", array(), "category ='{$this->category}'");
$cate_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
return $cate_exist;
}
public function getshop(){
$mysidia = Registry::get("mysidia");
if(empty($this->shopname)) $shop_exist = FALSE;
else{
$stmt = $mysidia->db->select("shops", array(), "shopname ='{$this->shopname}'");
$shop_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
}
return $shop_exist;
}
public function getitemnames(){
if(!$this->items){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}'");
$items = array();
while($item = $stmt->fetchColumn()){
$items[] = $item;
}
return $items;
}
else return $this->items;
}
public function gettotal(){
return $this->total;
}
public function display(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
$document->addLangvar($mysidia->lang->select_item);
if($this->gettotal() == 0){
$document->addLangvar($mysidia->lang->empty);
return FALSE;
}
# Choose the NPC image based on the name of the shop
switch ($this->shopname) {
case "Crossed Roads":
$npc_img = "http://fc00.deviantart.net/fs71/f/2014/262/a/2/base_npc_60_by_kyttias-d7zqrnf.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
case "Spectrum":
$npc_img = "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
default;
$npc_img = "http://placekitten.com/g/200/500";
$npc_text = "Welcome to {$this->shopname}!";
break;
}
# let's begin rendering the page
$document->add(new Comment("
<style>
.s_top {
overflow:hidden;
display: block;
}
.sc_npc_text{
width: 40%;
float: left;
height: 100%;
padding: 10px;
margin: 10px;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
}
.sc_npc_img{
width: 40%;
float: left;
}
.sc_item {
display: inline-block;
padding: 5px;
text-align: center;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 14px;
margin-bottom: 3px;
}
.s_panel {
border-radius: 4px;
border: 1px solid #466ec3;
background-color: #ccf3f6;
}
.s_input { width: 20px; }
</style>
<!-- START Container for Text and NPC -->
<div class='s_top s_container'>
<div class='s_panel sc_npc_text'><p>{$npc_text}</p></div>
<div class='sc_npc_img'><img src='{$npc_img}' height='300'></div>
</div>
<!-- END Container for Text and NPC -->
<!-- START Container for Items -->
<div class='s_container'>
", FALSE));
# Now render each item the store has
foreach($this->items as $stockitem){
$item = $this->getitem($stockitem);
#descriptions of the item functions
switch ($item->function) {
case "Click1": $usage = "<b>use:</b> Feed a pet to give them {$item->value} EXP.";
break;
case "Click2": $usage = "<b>use:</b> Feed a pet to set their EXP to {$item->value}.";
break;
case "Click3": $usage = "<b>use:</b> Resets today's earned EXP to 0.";
break;
case "Level1": $usage = "<b>use:</b> Raises a pet's Level by {$item->value}.";
break;
case "Level2": $usage = "<b>use:</b> Sets your pet's Level to {$item->value}.";
break;
case "Level3": $usage = "<b>use:</b> Makes your pet Level 0 again!";
break;
case "Gender": $usage = "<b>use:</b> Swaps your pet's gender to its opposite!";
break;
default;
$usage = "";
break;
}
# Now let's render each item icon, name, price and tooltip
$document->add(new Comment("
<div class='s_panel sc_item'>
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title=\"{$item->description} <em>{$usage}</em>.\"><img src='{$item->imageurl}'></abbr>
-->
<img src='{$item->imageurl}'>
<br/>
<b>{$item->itemname}</b>
<br/>
{$item->price} Credits<br/>
", FALSE));
# Building the Buy form
$buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
$buyForm->setLineBreak(FALSE);
$buyForm->buildPasswordField("hidden", "action", "purchase")
->buildPasswordField("hidden", "itemname", $item->itemname)
->buildPasswordField("hidden", "shopname", $shop->shopname)
->buildPasswordField("hidden", "shoptype", "itemshop")
->buildPasswordField("hidden", "salestax", $shop->salestax);
$quantity = new TextField("quantity");
$quantity->setSize(3);
$quantity->setMaxLength(3);
$quantity->setLineBreak(FALSE);
$buy = new Button("Buy", "buy", "buy");
$buy->setLineBreak(FALSE);
$buyForm->add($quantity);
$buyForm->add($buy);
# Actually adding in the Quantity field Buy button now
$document->add($buyForm);
# Now we finish off the item by closing its div
$document->add(new Comment("</div>", FALSE));
}
# And that's a wrap
$document->add(new Comment("</div><!-- END Container for Items -->", FALSE));
}
public function getitem($itemname){
return new StockItem($itemname);
}
public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
else{
$item->quantity = $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
if($moneyleft >= 0 and $item->quantity > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}
public function rent($item, $period){
}
public function execute($action){
}
protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("shops", array($field => $value), "sid='{$this->sid}' and shoptype = 'adoptshop'");
}
}
?>
parayna
12-15-2014, 06:15 AM
Yay! I got it working! No idea why it didn't work the fast time although it was probably because I forgot to copy and past ONE character that ended up breaking the whole thing, knowing me XD Thanks!
Kyttias
12-15-2014, 06:27 AM
Yay! *high fives*
Sorry I couldn't get the tooltips working yet, I'll try to find time later today.
parayna
12-15-2014, 06:28 AM
That's fine ^_^ I'm just glad I have it working now XD It means I can get more functionality on the site and can get more things added :P Thank you for helping me ^_^
parayna
12-15-2014, 01:03 PM
I have a tiny problem, although it isn't major XD The first item on the list seems to be bigger than the others (height wise). Any idea why that might be? It just doesn't look right. XD I have screenshot it to show you.. (and also, how do you allow apostrophes? >.< I decided that I do need them and after attempting to do it myself I have had to give up for fear of breaking the script XD) And one more thing.. how do I position the text box so it is a bit further down the page? If I can't do that then I will just have to make sure I write loads so that it looks neater >.< Sorry if I am bothering you XD
http://fc05.deviantart.net/fs70/f/2015/001/8/e/screenshot_2_by_yurash_emc-d8c8nox.png
And the file class_itemshop:
<?php
use Resource\Collection\LinkedList;
class Itemshop extends Model{
public $sid;
public $category;
public $shopname;
public $shoptype;
public $description;
public $imageurl;
public $status;
public $restriction;
public $salestax;
public $items;
protected $total = 0;
public function __construct($shopname){
// Fetch the database info into object property
$mysidia = Registry::get("mysidia");
$row = $mysidia->db->select("shops", array(), "shopname ='{$shopname}'")->fetchObject();
if(!is_object($row)) throw new Exception("Invalid Shopname specified");
// loop through the anonymous object created to assign properties
foreach($row as $key => $val){
$this->$key = $val;
}
$this->items = $this->getitemnames();
$this->total = (is_array($this->items))?count($this->items):0;
}
public function getcategory(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("shops", array(), "category ='{$this->category}'");
$cate_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
return $cate_exist;
}
public function getshop(){
$mysidia = Registry::get("mysidia");
if(empty($this->shopname)) $shop_exist = FALSE;
else{
$stmt = $mysidia->db->select("shops", array(), "shopname ='{$this->shopname}'");
$shop_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
}
return $shop_exist;
}
public function getitemnames(){
if(!$this->items){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}'");
$items = array();
while($item = $stmt->fetchColumn()){
$items[] = $item;
}
return $items;
}
else return $this->items;
}
public function gettotal(){
return $this->total;
}
public function display(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
if($this->gettotal() == 0){
$document->addLangvar($mysidia->lang->empty);
return FALSE;
}
# Choose the NPC image based on the name of the shop
switch ($this->shopname) {
case "Mais Stand":
$npc_img = "http://i1346.photobucket.com/albums/p696/parayna/MaiForShop_zpse0665685.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Why hello there!"; break;
case 2: $npc_text = "Fruits and vegetables are my expertise."; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Have you checked out all the features yet? I sure hope so!"; break;
case 5: $npc_text = "My name is Mai! How can I help you?"; break;
case 6: $npc_text = "'Tis the season to be jolly, falalalalaaaaa lala lala~"; }
break;
case "Spectrum":
$npc_img = "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
default;
$npc_img = "http://placekitten.com/g/200/500";
$npc_text = "Welcome to {$this->shopname}!";
break;
}
# let's begin rendering the page
$document->add(new Comment("
<style>
.s_top {
overflow:hidden;
display: block;
}
.sc_npc_text{
width: 40%;
float: left;
height: 100%;
padding: 10px;
margin: 10px;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
}
.sc_npc_img{
width: 40%;
float: left;
}
.sc_item {
display: inline-block;
padding: 5px;
text-align: center;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 14px;
margin-bottom: 1px;
}
.s_panel {
border-radius: 4px;
border: 1px solid #466ec3;
background-color: #ccf3f6;
}
.s_input { width: 30px; }
</style>
<!-- START Container for Text and NPC -->
<div class='s_top s_container'>
<div class='s_panel sc_npc_text'><p>{$npc_text}</p></div>
<div class='sc_npc_img'><img src='{$npc_img}' height='450' border='5'></div>
</div>
<!-- END Container for Text and NPC -->
<!-- START Container for Items -->
<div class='s_container'>
", FALSE));
# Now render each item the store has
foreach($this->items as $stockitem){
$item = $this->getitem($stockitem);
#descriptions of the item functions
switch ($item->function) {
case "Click1": $usage = "<b>use:</b> Feed a pet to give them {$item->value} EXP.";
break;
case "Click2": $usage = "<b>use:</b> Feed a pet to set their EXP to {$item->value}.";
break;
case "Click3": $usage = "<b>use:</b> Resets today's earned EXP to 0.";
break;
case "Level1": $usage = "<b>use:</b> Raises a pet's Level by {$item->value}.";
break;
case "Level2": $usage = "<b>use:</b> Sets your pet's Level to {$item->value}.";
break;
case "Level3": $usage = "<b>use:</b> Makes your pet Level 0 again!";
break;
case "Gender": $usage = "<b>use:</b> Swaps your pet's gender to its opposite!";
break;
default;
$usage = "";
break;
}
# Now let's render each item icon, name, price and tooltip
$document->add(new Comment("
<div class='s_panel sc_item'>
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title=\"{$item->description} <em>{$usage}</em>.\"><img src='{$item->imageurl}'></abbr>
-->
<img src='{$item->imageurl}'>
<br/>
<b>{$item->itemname}</b>
<br/>
{$item->price} Credits<br/>
", FALSE));
# Building the Buy form
$buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
$buyForm->setLineBreak(FALSE);
$buyForm->buildPasswordField("hidden", "action", "purchase")
->buildPasswordField("hidden", "itemname", $item->itemname)
->buildPasswordField("hidden", "shopname", $shop->shopname)
->buildPasswordField("hidden", "shoptype", "itemshop")
->buildPasswordField("hidden", "salestax", $shop->salestax);
$quantity = new TextField("quantity");
$quantity->setSize(3);
$quantity->setMaxLength(3);
$quantity->setLineBreak(FALSE);
$buy = new Button("Buy", "buy", "buy");
$buy->setLineBreak(FALSE);
$buyForm->add($quantity);
$buyForm->add($buy);
# Actually adding in the Quantity field Buy button now
$document->add($buyForm);
# Now we finish off the item by closing its div
$document->add(new Comment("</div>", FALSE));
}
# And that's a wrap
$document->add(new Comment("</div><!-- END Container for Items -->", FALSE));
}
public function getitem($itemname){
return new StockItem($itemname);
}
public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
else{
$item->quantity = $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
if($moneyleft >= 0 and $item->quantity > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}
public function rent($item, $period){
}
public function execute($action){
}
protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("shops", array($field => $value), "sid='{$this->sid}' and shoptype = 'adoptshop'");
}
}
?>
I will be removing the CSS part though and adding them to my themes as then I can see about making the colours fit each different coloured theme I have ^_^
Thank you ^_^''
Kyttias
12-15-2014, 02:33 PM
I'm actually a little confused about the height of the first one, too. Can you inspect the html of the loaded page (right click, inspect element) and get me the entire contents of the html we made here? Both s_containers, please?
parayna
12-15-2014, 02:43 PM
You mean these?:
<div class="s_panel sc_npc_text"><p>Welcome to Mais Stand!</p></div>
<div class="sc_npc_img"><img src="http://i1346.photobucket.com/albums/p696/parayna/MaiForShop_zpse0665685.png" border="5" height="450"></div>
<div class="s_panel sc_item">
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title="It\'s a shiny red apple! Raises your adoptables clicks by 5 points. <em><b>use:</b> Feed a pet to give them 5 EXP.</em>."><img src='http://ycadopts.byethost4.com/picuploads/png/c36a93552de2e29e369c9196b47fd19f.png'></abbr>
-->
<img src="http://ycadopts.byethost4.com/picuploads/png/c36a93552de2e29e369c9196b47fd19f.png">
<br>
<b>Red Apple</b>
<br>
10 Credits<br>
<form id="buyform" action="../purchase/Mais Stand" name="buyform" method="post">
<input id="action" name="action" value="purchase" type="hidden">
<input id="itemname" name="itemname" value="Red Apple" type="hidden">
<input id="shopname" name="shopname" type="hidden">
<input id="shoptype" name="shoptype" value="itemshop" type="hidden">
<input id="salestax" name="salestax" type="hidden">
<input id="quantity" size="3" name="quantity" maxlength="3" value="">
<button id="buy" value="buy" name="buy" type="submit">Buy
</button>
</form></div>
<div class="s_panel sc_item">
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title="It\'s a shiny green apple! Raises your adoptables clicks by 5 points. <em><b>use:</b> Feed a pet to give them 5 EXP.</em>."><img src='http://ycadopts.byethost4.com/picuploads/png/1e10d8fdabd1e4514187ca5ef663622d.png'></abbr>
-->
<img src="http://ycadopts.byethost4.com/picuploads/png/1e10d8fdabd1e4514187ca5ef663622d.png">
<br>
<b>Green Apple</b>
<br>
10 Credits<br>
<form id="buyform" action="../purchase/Mais Stand" name="buyform" method="post">
<input id="action" name="action" value="purchase" type="hidden">
<input id="itemname" name="itemname" value="Green Apple" type="hidden">
<input id="shopname" name="shopname" type="hidden">
<input id="shoptype" name="shoptype" value="itemshop" type="hidden">
<input id="salestax" name="salestax" type="hidden">
<input id="quantity" size="3" name="quantity" maxlength="3" value="">
<button id="buy" value="buy" name="buy" type="submit">Buy
</button>
</form></div>
<div class="s_panel sc_item">
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title="It\'s a shiny red and green apple! Raises your adoptables clicks by 5 points. <em><b>use:</b> Feed a pet to give them 5 EXP.</em>."><img src='http://ycadopts.byethost4.com/picuploads/png/117bdee9f79f0f3fefed1355c3eb0f05.png'></abbr>
-->
<img src="http://ycadopts.byethost4.com/picuploads/png/117bdee9f79f0f3fefed1355c3eb0f05.png">
<br>
<b>Red and Green Apple</b>
<br>
10 Credits<br>
<form id="buyform" action="../purchase/Mais Stand" name="buyform" method="post">
<input id="action" name="action" value="purchase" type="hidden">
<input id="itemname" name="itemname" value="Red and Green Apple" type="hidden">
<input id="shopname" name="shopname" type="hidden">
<input id="shoptype" name="shoptype" value="itemshop" type="hidden">
<input id="salestax" name="salestax" type="hidden">
<input id="quantity" size="3" name="quantity" maxlength="3" value="">
<button id="buy" value="buy" name="buy" type="submit">Buy
</button>
</form></div>
<div class="s_panel sc_item">
<!--
// This is where I would get the tooltip working, but it's not currently
<abbr rel='tooltip' title="It\'s a yellow banana! Yummy! Raises your adoptables clicks by 5 points. <em><b>use:</b> Feed a pet to give them 5 EXP.</em>."><img src='http://ycadopts.byethost4.com/picuploads/png/6503a21baa10e46b2f6905ec11085ddf.png'></abbr>
-->
<img src="http://ycadopts.byethost4.com/picuploads/png/6503a21baa10e46b2f6905ec11085ddf.png">
<br>
<b>Yellow Banana</b>
<br>
10 Credits<br>
<form id="buyform" action="../purchase/Mais Stand" name="buyform" method="post">
<input id="action" name="action" value="purchase" type="hidden">
<input id="itemname" name="itemname" value="Yellow Banana" type="hidden">
<input id="shopname" name="shopname" type="hidden">
<input id="shoptype" name="shoptype" value="itemshop" type="hidden">
<input id="salestax" name="salestax" type="hidden">
<input id="quantity" size="3" name="quantity" maxlength="3" value="">
<button id="buy" value="buy" name="buy" type="submit">Buy
</button>
</form></div>
Just tell me if you need anything else. Thanks~
EDIT:
It seems to be for the entire first column :/
http://fc05.deviantart.net/fs70/f/2015/001/8/8/screenshot_3_by_yurash_emc-d8c8nyk.png
Kyttias
12-15-2014, 03:54 PM
That's extremely odd. I literally copy pasted what you gave me to make my next example linked below, and it's not happening for me there. :displeased:
I made some changes to the css here, for the text box, not sure if it's good enough, so I encourage you to play with it yourself - http://jsbin.com/qolixiyopo/1/edit?css,output
What browser are you using? Chrome, Firefox, IE?
EDIT: Actually, WOW, just tested it on my gf's computer, it IS a problem in Firefox, but not in Chrome. Weird. I hate it when that happens. I don't actually have Firefox to be able to test fixes for it, but the problem is entirely with the css/html rendering.
parayna
12-15-2014, 03:58 PM
I am using Firefox. Chrome is too slow for me and IE is rubbish XD And on the example there it still happens for me. So it might be something to do with my browser or something...
EDIT: I downloaded Chrome and it appears to work better... so it's only Firefox? :/
Kyttias
12-15-2014, 04:07 PM
Exactly. You'll need to find a solution that works in all browsers. Try making a css/html design of what you want yourself. The one I made worked in my browser, but I wasn't able to test it. If you need help transferring over your changes to the file we're editing (if you totally redo the divs and such) I'll be more than happy to help get the final file organized.
Kyttias
12-15-2014, 04:20 PM
In the last jsbin I linked, I included your entire theme. If you remove your stylesheet (this one in particular - templates/blueqilin/media/style-blue.css ) the problem is fixed. Obviously you can't just remove your entire stylesheet, but for some reason, the problem is definitely in there. At least, that was what my gf was able to figure out so far on her computer. ><; So now it comes down to be a problem only in Firefox, specifically only with this theme.
In the meanwhile, I'll try to make sure item descriptions that contain apostrophes won't bug anything out. ^^;
parayna
12-15-2014, 04:31 PM
I did it! I changed the 'display: inline-block;' to 'display: inline-table;' And I put it in my CSS file so I can later change the colours for my themes :P Thanks for the offer to help, but I decided I needed to try and do something for myself so I googled different CSS display commands and found one that worked :P
Now to check if it works in Chrome (works in Firefox at the moment)
EDIT: Yup! Works! ^_^ Happy now XD I can finally go to bed >.<
Thanks!
And OK, thank you ^_^
Kyttias
12-15-2014, 04:45 PM
Mm, that definitely works because your theme uses a table. If you ever switch to one that does not, things may break again, but I dunno. In your css (the one I mentioned) very early on there's an area where it defines br? Everything would also be fixed if you removed display: block; from that. At least, that's what my gf found, ahaha. ^^;
parayna
12-15-2014, 05:15 PM
Oh, alright! That might be a tiny bit easier actually... as then it would hopefully not break if I ever get brave and try and create a theme completely from scratch :P Thank them for me ^_^ And also thank you :P
parayna
12-15-2014, 05:53 PM
I have another question >.< Sorry, I am curious D: Would it be possible to make the inventory look like the shop? So it would not have the NPC or text just the item boxes and the item names and how much quantity you have at the moment? (With the tooltips eventually) And with a button to use the item? (And maybe the button leads to the page where you select the pet you wish to use it on)
Kyttias
12-15-2014, 06:39 PM
It's entirely possible! *chuckle* Look, if you can create a fake screenshot of what you want, and even better, make it with html/css in a jsbin and link it to me, then I can try to make it for you.
Keep in mind that not all items are useable, or at least not useable on pets. You may not have plans for any items like this right now, but you may in the future. (Say you need to own 'Shiny Key' to access to a certain page. It has no use, you just have to own it, so there would be no need for there to be a use button. You'll need to show me how you want items that don't need a use button to look, too.) For items with a use button, it does indeed already take users to another page to select a pet.
Items can also be sold. You also get to choose a quantity to sell. (I personally recommend getting rid of the 'toss' button, at that point, if that's alright? Less clutter for something you can essentially already do by selling the item.)
Kyttias
12-15-2014, 11:33 PM
Tooltip time!
In your directory where Mysidia is installed there is a css folder (not talking about anything theme-related in the template folder, this css folder is the one at the root). We're going to add this as tooltip.css -
#tooltip
{
text-align: center;
color: #fff;
background: #111;
position: absolute;
z-index: 100;
padding: 15px;
}
#tooltip:after /* triangle decoration */
{
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #111;
content: '';
position: absolute;
left: 50%;
bottom: -10px;
margin-left: -10px;
}
#tooltip.top:after
{
border-top-color: transparent;
border-bottom: 10px solid #111;
top: -20px;
bottom: auto;
}
#tooltip.left:after
{
left: 10px;
margin: 0;
}
#tooltip.right:after
{
right: 10px;
left: auto;
margin: 0;
}
A nearby folder, also in the heart of things, is called js. Open up this folder and add this as tooltip.js:
/*
TOOLTIP
*/
$( function()
{
var targets = $( '[rel~=tooltip]' ),
target = false,
tooltip = false,
title = false;
targets.bind( 'mouseenter', function()
{
target = $( this );
tip = target.attr( 'title' );
tooltip = $( '<div id="tooltip"></div>' );
if( !tip || tip == '' )
return false;
target.removeAttr( 'title' );
tooltip.css( 'opacity', 0 )
.html( tip )
.appendTo( 'body' );
var init_tooltip = function()
{
if( $( window ).width() < tooltip.outerWidth() * 1.5 )
tooltip.css( 'max-width', $( window ).width() / 2 );
else
tooltip.css( 'max-width', 340 );
var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ),
pos_top = target.offset().top - tooltip.outerHeight() - 20;
if( pos_left < 0 )
{
pos_left = target.offset().left + target.outerWidth() / 2 - 20;
tooltip.addClass( 'left' );
}
else
tooltip.removeClass( 'left' );
if( pos_left + tooltip.outerWidth() > $( window ).width() )
{
pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20;
tooltip.addClass( 'right' );
}
else
tooltip.removeClass( 'right' );
if( pos_top < 0 )
{
var pos_top = target.offset().top + target.outerHeight();
tooltip.addClass( 'top' );
}
else
tooltip.removeClass( 'top' );
tooltip.css( { left: pos_left, top: pos_top } )
.animate( { top: '+=10', opacity: 1 }, 50 );
};
init_tooltip();
$( window ).resize( init_tooltip );
var remove_tooltip = function()
{
tooltip.animate( { top: '-=10', opacity: 0 }, 50, function()
{
$( this ).remove();
});
target.attr( 'title', tip );
};
target.bind( 'mouseleave', remove_tooltip );
tooltip.bind( 'click', remove_tooltip );
});
});
Now, in your theme's header.tpl, add in these lines (before the end of the </head>, of course):
{$header->loadStyle("{$home}{$css}/tooltip.css")}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="{$home}{$js}/tooltip.js"></script>
You now have all the necessary components for tooltips.
To make tooltips elsewhere on your site, from now on, all you need to do is add title="Contents of the tooltip here!" rel="tooltip" to any element you want to have a tooltip. Could be links, divs, spans, images, etc. You can also use some basic html inside them, such as italicies, bold, and linebreaks.
For more reference on the tooltip system I just had you install, visit this link (http://osvaldas.info/elegant-css-and-jquery-tooltip-responsive-mobile-friendly).
-
Moving along, here is the final version of classes/class_itemshop.php:
<?php
use Resource\Collection\LinkedList;
class Itemshop extends Model{
public $sid;
public $category;
public $shopname;
public $shoptype;
public $description;
public $imageurl;
public $status;
public $restriction;
public $salestax;
public $items;
protected $total = 0;
public function __construct($shopname){
// Fetch the database info into object property
$mysidia = Registry::get("mysidia");
$row = $mysidia->db->select("shops", array(), "shopname ='{$shopname}'")->fetchObject();
if(!is_object($row)) throw new Exception("Invalid Shopname specified");
// loop through the anonymous object created to assign properties
foreach($row as $key => $val){
$this->$key = $val;
}
$this->items = $this->getitemnames();
$this->total = (is_array($this->items))?count($this->items):0;
}
public function getcategory(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("shops", array(), "category ='{$this->category}'");
$cate_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
return $cate_exist;
}
public function getshop(){
$mysidia = Registry::get("mysidia");
if(empty($this->shopname)) $shop_exist = FALSE;
else{
$stmt = $mysidia->db->select("shops", array(), "shopname ='{$this->shopname}'");
$shop_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
}
return $shop_exist;
}
public function getitemnames(){
if(!$this->items){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}'");
$items = array();
while($item = $stmt->fetchColumn()){
$items[] = $item;
}
return $items;
}
else return $this->items;
}
public function gettotal(){
return $this->total;
}
public function display(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
$document->addLangvar($mysidia->lang->select_item);
if($this->gettotal() == 0){
$document->addLangvar($mysidia->lang->empty);
return FALSE;
}
# Choose the NPC image based on the name of the shop
switch ($this->shopname) {
case "Crossed Roads":
$npc_img = "http://fc00.deviantart.net/fs71/f/2014/262/a/2/base_npc_60_by_kyttias-d7zqrnf.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
case "Spectrum":
$npc_img = "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Time is money."; break;
case 2: $npc_text = "Isn't icecream super?"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Tomorrow is another day..."; break;
case 6: $npc_text = "PHP is cool!"; }
break;
default;
$npc_img = "http://placekitten.com/g/200/500";
$npc_text = "Welcome to {$this->shopname}!";
break;
}
# let's begin rendering the page
$document->add(new Comment("
<style>
.s_top {
overflow:hidden;
display: block;
margin-bottom: 10px;
}
.sc_npc_text{
width: 300px;
float: left;
position: relative;
height: 100px;
padding: 15px;
margin: 10px;
margin-top: 200px;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
overflow: auto;
}
.sc_npc_img{
width: 40%;
float: left;
}
.sc_item {
display: inline-block;
padding: 5px;
text-align: center;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 14px;
margin-bottom: 3px;
}
.s_panel {
border-radius: 4px;
border: 1px solid #466ec3;
background-color: #ccf3f6;
}
</style>
<!-- START Container for Text and NPC -->
<div class='s_top s_container'>
<div class='s_panel sc_npc_text'>{$npc_text}</div>
<div class='sc_npc_img'><img src='{$npc_img}' border='5' height='450'></div>
</div>
<!-- END Container for Text and NPC -->
<!-- START Container for Items -->
<div class='s_container'>
", FALSE));
# Now render each item the store has
foreach($this->items as $stockitem){
$item = $this->getitem($stockitem);
#descriptions of the item functions
switch ($item->function) {
case "Click1": $usage = "<br/><b>use:</b> Feed a pet to give them {$item->value} EXP.";
break;
case "Click2": $usage = "<br/><b>use:</b> Feed a pet to set their EXP to {$item->value}.";
break;
case "Click3": $usage = "<br/><b>use:</b> Resets EXP earned today to 0.";
break;
case "Level1": $usage = "<br/><b>use:</b> Raises the Level of your pet by {$item->value}.";
break;
case "Level2": $usage = "<br/><b>use:</b> Sets the Level of your pet to {$item->value}.";
break;
case "Level3": $usage = "<br/><b>use:</b> Makes your pet Level 0 again!";
break;
case "Gender": $usage = "<br/><b>use:</b> Swaps the gender of your pet to its opposite!";
break;
default;
$usage = "";
break;
}
# Now let's render each item icon, name, price and tooltip
$document->add(new Comment("
<div class=\"s_panel sc_item\">
<img rel=\"tooltip\" title=\"{$item->description} <em>{$usage}</em>\" src=\"{$item->imageurl}\"/><br/>
<b>{$item->itemname}</b>
<br/>
{$item->price} Credits<br/>
", FALSE));
# Building the Buy form
$buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
$buyForm->setLineBreak(FALSE);
$buyForm->buildPasswordField("hidden", "action", "purchase")
->buildPasswordField("hidden", "itemname", $item->itemname)
->buildPasswordField("hidden", "shopname", $shop->shopname)
->buildPasswordField("hidden", "shoptype", "itemshop")
->buildPasswordField("hidden", "salestax", $shop->salestax);
$quantity = new TextField("quantity");
$quantity->setSize(3);
$quantity->setMaxLength(3);
$quantity->setLineBreak(FALSE);
$buy = new Button("Buy", "buy", "buy");
$buy->setLineBreak(FALSE);
$buyForm->add($quantity);
$buyForm->add($buy);
# Actually adding in the Quantity field Buy button now
$document->add($buyForm);
# Now we finish off the item by closing its div
$document->add(new Comment("</div>", FALSE));
}
# And that's a wrap
$document->add(new Comment("</div><!-- END Container for Items -->", FALSE));
}
public function getitem($itemname){
return new StockItem($itemname);
}
public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
else{
$item->quantity = $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
if($moneyleft >= 0 and $item->quantity > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}
public function rent($item, $period){
}
public function execute($action){
}
protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("shops", array($field => $value), "sid='{$this->sid}' and shoptype = 'adoptshop'");
}
}
?>
Finally, I'm happy to inform you that is absolutely safe to use apostrophes inside of item names, item descriptions, shop names, and the NPC text. However, please refrain from using quotation marks in any of these areas.
So, to clarify, DO NOT:
"Sour" Candy
This is an "official" fanclub hair pin.
The "Best" Shop
"Welcome", says the shopkeeper.
It would, however, okay, to use single quotes instead, as these are just apostrophes and apostrophes are okay!
parayna
12-16-2014, 01:43 AM
I have no time to make a screenshot now, school beckons, but I can when I come home. Thanks for the tooltips! They have slashes in though.. where there are apostrophes. Do we need to add in (stripslashes) codes? It also still happens in the Store name unless that is to do with the admin CP not liking shops with slashes in the name to be created.. (or apostrophes as it automatically adds them in). Do you know where I would put the stripslashes in? I have managed it with many things in the script before, just I can't find where to put it this time XD
Kyttias
12-16-2014, 02:44 AM
That's really odd. I tested with my items, and one of them has an apostrophe in it's description and showed no slash. =| Usually you have to manually put in slashes, not manually remove them. So maybe they were put in when the item was created. Check in the database table for me? I may have found a slash in mine and removed it directly in the database itself, I cant remember.
parayna
12-16-2014, 09:17 AM
OK, I'll check. I remember I had this problem with something else and I fixed it by putting stripslashes in the code.. but I'll look a moment.
OK, these are the screenshots (see if you can make any more sense of them XD)
This is what happens when I create the page:
http://fc01.deviantart.net/fs71/f/2015/001/6/e/screenshot_4_by_yurash_emc-d8c8o93.png
You can see that it has added a slash:
http://fc01.deviantart.net/fs70/f/2015/001/f/7/screenshot_5_by_yurash_emc-d8c8oey.png
I edited the file with the name:
http://fc08.deviantart.net/fs71/f/2015/001/3/2/screenshot_6_by_yurash_emc-d8c8onk.png
Then when I tried to go onto the shop page (the default one where you pick what shop to go to):
http://fc00.deviantart.net/fs71/f/2015/001/0/4/screenshot_7_by_yurash_emc-d8c8orz.png
Then I went into the PHPmyadmin and changed it to get rid of the slash. It still didn't work and came up blank (this is what it was before I changed it):
http://fc00.deviantart.net/fs70/f/2015/001/e/e/screenshot_8_by_yurash_emc-d8c8p0z.png
Then I went back to shop creation (when it had a slash):
http://fc02.deviantart.net/fs70/f/2015/001/a/d/screenshot_9_by_yurash_emc-d8c8p5i.png
And this is what happens when I go into edit:
http://fc06.deviantart.net/fs70/f/2015/001/3/f/screenshot_10_by_yurash_emc-d8c8p8v.png
The name box cuts off everything after the slash. And when I had gotten rid of the slash in the database it just said 'Mai'. No slash nor the rest of the words... >.<
No idea of the problem :/
Kyttias
12-16-2014, 03:04 PM
NPC text - Should be fine.
Item descriptions - Should be fine.
Item names - Where you want an apostrophe to appear, use ' instead:
Creator's Bracelet = Creator's Bracelet
Shop names - I thought of a fix! Where you want an apostrophe to appear, use *** instead. In view/shopview.php, change public function browse to:
public function browse(){
$document = $this->document;
$str_shopname = str_replace("***", "'", $this->lang->welcome);
$document->setTitle($str_shopname);
$shop = $this->getField("shop");
$shop->display();
}
Mai***s Shop = Mai's Shop
parayna
12-16-2014, 07:41 PM
OK.. before I do that, I have another problem. No idea why but I have only just noticed it. Took me about 1 hour and 30 minutes to finally figure out the pattern and what is wrong >.< But everytime I put this in the header:
{$header->loadStyle("{$home}{$css}/tooltip.css")}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="{$home}{$js}/tooltip.js"></script>
It seems to break the user profile! Even though it shouldn't have anything to do with it. And I know that that it the cause as when I remove it it works perfectly normal and then when I put it back in it breaks again...
This is what happens:
http://fc01.deviantart.net/fs70/f/2015/001/3/8/screenshot_11_by_yurash_emc-d8c8pdg.png
Basically the URL shows the supposed to be invisible #visitormessage or #whatever. >.< And then when I remove it, it is fine! D:
I kinda want to move onto the inventory but I can't until I get all the little things sorted XD And I fixed the inventory names etc so thanks for that XD
Kyttias
12-16-2014, 09:03 PM
Open up inc/tabs.php and delete the contents (but not the file). Open up your header.tpl and right after the link to tooltip.css, add in:
<script src="{$home}{$js}/tabs.js"></script>
<script>
$(function() { $("#profile").organicTabs(); });
</script>
I'm not entirely sure what the issue was, but this fixed it. This was one of the only (if not the only) pages that used jQuery of the original site, and I think there was some issue with what order things were loading in.
parayna
12-16-2014, 09:41 PM
Thank you ^_^ It worked! Phew... finally caught up! XD Now I just need to do the inventory and the items aspect (most of it) will be finished finally! (And I saw on another post you say you might put the NPC thing as a mod, and I think you should XD Many people would find it good, I think ^_^)
Could you help me with the inventory in this way, please?
http://fc02.deviantart.net/fs71/f/2015/001/b/e/screenshot_12_by_yurash_emc-d8c8pkr.png
^_^
Kyttias
12-17-2014, 01:43 AM
Perhaps, but it'll take a little bit longer than the shop page did.
On a side note, I'm having a little trouble with an item I created that had an apostrophe, so, something tells me it's not safe to use them either. There should be a work around similar to how we figured out the shop names, though...
So please don't create any item names with apostrophes until I get back to you on this.
Another random fact about Mysidia in general (to be warned about)- If you try to rename an item but someone already owns one, it will also screw up their inventory - you have to rename the item not only in the items table, but also the inventory table for all users who may have it (the Search button at the top of the page will help with this, at least).
parayna
12-17-2014, 06:20 AM
Oh, OK. Thanks for telling me XD I'll be sure to try and avoid it. For now, I am safe. But for future reference thanks :P
Abronsyth
12-22-2014, 03:03 PM
Hey, sorry this isn't to do with helping out...
But I was wondering if either of you would be opposed to releasing the format for the shop page as a mod, or to me using the codes provided here with my own site?
Wanted to ask permission first, hehe. But this is pretty much exactly how I'd like to set up my shop pages (aside from the NPC being centered).
Let me know!
Kyttias
12-22-2014, 04:11 PM
You're definitely welcome to use it. I'll try to tidy up all the information here into a mod so people have less to read through. It's hard to make a code for everyone, so I'll have to try my best to explain what's going on so they know how to implement their own layout plans. I commented my code and all, but I'm really not sure how straightforward it is currently. ^^;
edit: Official mod thread created! (http://www.mysidiaadoptables.com/forum/showthread.php?t=4741)
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.