Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-02-2013, 10:29 PM
Jocla Jocla is offline
Member
 
Join Date: Mar 2013
Posts: 9
Gender: Male
Credits: 1,215
Jocla is on a distinguished road
Lightbulb Problem whit functions.php edition

I'm new and install v1.3.1 and edit only one file (functions.php) (translate sidebar links to spanish), but now online.php, myadopt.php and profile.php are differents, font size is now more larger. (sorry my english is bad )

I Don't install the latest version of script because it's not compatible with my php version.

My functions.php

PHP Code:
<?php

// File ID: functions.php
// Purpose: Provides basic sitewide functions

if(defined("SUBDIR")) include("../inc/config.php");
else include(
"inc/config.php"); 

//Now connecting to the adoptables database 
try{
  
$adopts = new Database(DBNAMEDBHOSTDBUSERDBPASSPREFIX);
}
catch(
PDOException $pe){
  die(
"Could not connect to database, the following error has occurred: <br><b>{$pe->getmessage()}</b>");  
}

//Define the $adopts as super globals, this has to be done since one cannot define an object as constant.
$GLOBALS['adopts'] = $adopts;

startup();
session_start();

//define default attributes for html tables and other stuff...
$attr getattributes(); 

// clean all our data
$_POST array_map('secure',$_POST);
$_GET array_map('secure',$_GET);

$session session_id();
$time time();
$time_check $time 300// Time check, delete after 300 seconds (5 minutes)

if($isloggedin != "yes"$loggedinname "Visitor";

$row $adopts->select("online", array(), "username = '{$loggedinname}'")->fetchObject();

if(!
is_object($row)) $adopts->insert("online", array("username" => $loggedinname"session" => $session"time" => $time));
else 
$adopts->update("online", array("time" => $time"session" => $session"username" => $loggedinname), "username = '{$loggedinname}'");

// if over 5 minute, delete session
$adopts->delete("online""time < {$time_check}");

// Begin functions definition:

function __autoload($name) {
  
// The autoload function, a bit messy if you ask me
  
$classpath strtolower("classes/class_{$name}");
  if(
defined("SUBDIR")) include_once ("../{$classpath}.php");
  else include_once (
"{$classpath}.php");
}

function 
is_assoc($arr) {
   
// From php.net, will help a lot in future
   
return (is_array($arr) && count(array_filter(array_keys($arr),'is_string')) == count($arr));
}

function 
checkrb($field$value){
   
$button = ($field == $value)?" checked":"";
   return 
$button;
}
function 
startup() {
    
// get all of our default settings, like title and stuff
    
$stmt $GLOBALS['adopts']->select("settings", array());
    while(
$row $stmt->fetchObject()){
      
$GLOBALS['settings'][$row->name] = $row->value;
    }
    
// set up our log in stuff so we always have it
    
logincheck();
}

function 
secure($data) {
    
//This function performs security checks on all incoming form data
    
if(is_array($data) and SUBDIR != "AdminCP") die("Hacking Attempt!");
    
$data htmlentities($data);   
    
$data strip_tags($data'');
    return 
$data;
}

function 
getsitecontent($page) {
    
$row $GLOBALS['adopts']->select("content", array(), "page = '{$page}'")->fetchObject();
    
$title stripslashes($row->title);
    
$content stripslashes($row->content);
    
$value[content] = $content;
    
$value[title] = $title;
    return 
$value;
}

function 
replace($old$new$template) {
    
//This function replaces template values
    
$template str_replace($old$new$template);
    return 
$template;
}

function 
codegen($length$symbols 0){
    
$set = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
    
$str '';
    
    if(
$symbols == 1){
      
$symbols = array("~","`","!","@","$","#","%","^","+","-","*","/","_","(","[","{",")","]","}");
      
$set array_merge($set$symbols);
    }

    for(
$i 1$i <= $length; ++$i)
    {
        
$ch mt_rand(0count($set)-1);
        
$str .= $set[$ch];
    }

    return 
$str;
}

function 
passencr($username$password$salt){
    
$pepper grabanysetting("peppercode");
    
$password md5($password);
    
$newpassword sha1($username.$password);
    
$finalpassword hash('sha512'$pepper.$newpassword.$salt);
    return 
$finalpassword;
}     

// NOTE - make sure this is only run once in a whole page load - not multiple times!
function logincheck() {
    
//Set up our login info...
    
$uid "";
    
$password "";
    
    
//Check for cookie
    
if (isset($_COOKIE['mysuid']) and isset($_COOKIE['myssession'])) {
        
$uid $_COOKIE['mysuid'];
        
$session $_COOKIE['myssession'];
        
$uid secure($uid);
        
$password secure($session);

        
//Run login operation
        
$GLOBALS['usersettings'] = $GLOBALS['adopts']->join("groups""groups.gid = users.usergroup")
                                                     ->
join("users_options""users_options.uid = users.uid")
                                                     ->
select("users", array(), constant("PREFIX")."users.uid = '{$uid}'")
                                                     ->
fetch(PDO::FETCH_ASSOC);
        
$luid=$GLOBALS['usersettings']['uid'];
        
$lsess=$GLOBALS['usersettings']['session'];
        
$usergroup=$GLOBALS['usersettings']['usergroup'];
    
        if(
$uid == $luid and $session == $lsess$isloggedin "yes";
        else{
            if (isset(
$_COOKIE['mysuid'])) {
                
$past time() - 10
                
setcookie("mysuid"$uid$past);
            }
            if (isset(
$_COOKIE['myssession'])) {
                
$past time() - 10
                
setcookie("myssession"$session$past);
            }
            
$isloggedin "no";
        }

    }
    else 
$isloggedin "no";

    
// return our user data

    
$row $GLOBALS['adopts']->select("users", array(), "uid = '{$uid}'")->fetchObject();
    
$username=$row->username
    
$GLOBALS['isloggedin'] = $isloggedin;
    
$GLOBALS['username'] = $username;
    
$GLOBALS['loggedinname'] = $username;
    
$GLOBALS['money'] = $GLOBALS['usersettings']['money'];
    
$GLOBALS['group'] = $usergroup;
}

function 
ipgen($ip){
    
$ip_long ip2long($ip);

    if(!
$ip_long){
        
$ip_long sprintf("%u"ip2long($ip));        
        if(!
$ip_long){
            return 
0;
        }
    }

    if(
$ip_long >= 2147483648$ip_long -= 4294967296;
    return 
$ip_long;
}

function 
timeconverter($unit){
    switch(
$unit){
        case 
"secs":
            
$converter 1;
            break;
        case 
"minutes":    
            
$converter 60;
            break;
        case 
"hours":    
            
$converter 3600;
            break;
        case 
"weeks":
            
$converter 604800;
            break; 
        case 
"months":
            
$converter 2592000;
            break;
        case 
"years":
            
$converter 31536000;
            break;    
        default:
             
$converter 86400;               
    }
    return 
$converter;    
}

function 
grabanysetting($where) {
    
$value stripslashes($GLOBALS['settings'][$where]);    
    return 
$value;
}

function 
getlinks(){

//This function gets the links for the top bar from the database 
// We will be getting our links from the database...
    
$links "<div class='ddmenu'>\n
             <ul>"
;
             
    
$stmt $GLOBALS['adopts']->select("links", array(), "linkparent < 1 ORDER BY id ASC");
        
    while (
$category $stmt->fetchObject()) {
        
$links .= "\n<li><a class='hide' href='{$category->linkurl}'>{$category->linktext}</a>
               \n<ul>"
;
        
$stmt2 $GLOBALS['adopts']->select("links", array(), "linkparent='{$category->id}' ORDER BY id ASC");
        while(
$item $stmt2->fetchObject()){
            
$links .= "<li><a href='{$item->linkurl}' title='{$item->linktext}'>{$item->linktext}</a></li>";      
        }
        
$links .= "</ul>
              \n</li>"
;
    }
    
    
$links .= "\n</ul>";
    return 
$links;
}

function 
getsidebar() {
    
//This function determines what shows in the side bar of the template
    
$isloggedin $GLOBALS['isloggedin'];
    
$loggedinname $GLOBALS['loggedinname'];
    if(
$isloggedin == "yes") {
        
$msgctr "<a href='messages.php'>Messages</a>";        
        
$data $GLOBALS['adopts']->select("messages", array(), "touser='{$loggedinname}' and status='unread'")->fetchAll();

        if(
count($data) > 0) {
            
$msgctr "<a href='messages.php'>Messages <b>(".count($data).")</b></a>";
        }
        
$sidebar "&nbsp;&nbsp;&nbsp;&nbsp;Tienes {$GLOBALS['money']} {$GLOBALS['settings']['cost']}.<br />
        
        <br /><strong>&nbsp;&nbsp;&nbsp;Secciones:</strong><br />
        <ul><li><a href='adopt.php'>Adoptar</a></li>
        <li><a href='pound.php'>Adoptables</a></li>
        <li><a href='myadopts.php'>Administrar pets</a></li>
        <li><a href='account.php'>Config. Cuenta</a></li>
        <li>
{$msgctr}
        <li><a href='changestyle.php'>Change Theme</a></li>
        <li><a href='donate.php'>Hacer donacion</a></li>
        <li><a href='logout.php'>Cerrar sesion</a></li>"
;

        
$row $GLOBALS['adopts']->select("users", array(), "username='{$loggedinname}' and usergroup='1'")->fetchObject();        
        if(
is_object($row)) $sidebar .= "<li><a href='admincp/index.php'>Administrar</a></li><br />";

        
$row1 $GLOBALS['adopts']->select("online", array(), "username != 'Visitor'")->fetchAll();
        
$total1 count($row1);
        
$row2 $GLOBALS['adopts']->select("online", array(), "username = 'Visitor'")->fetchAll();
        
$total2 count($row2);
        
$sidebar .= "<a href='online.php'>Hay {$total1} usuario(s) y {$total2} visita(s) online.</a></ul>";
    }
    else {
        
$sidebar "<b><u>Iniciar sesion:</u></b><br />
        <form name='form1' method='post' action='login.php'>
          <p>Usuario: 
            <input name='username' type='text' id='username'>
        </p>
          <p>Password: 
        <p>    <input name='password' type='password' id='password'>
        </p>
          <p>
            <input type='submit' name='Submit' value='Log In'>
          </p>
        </form>Aun no te registras?<br /><a href='register.php'>Crea tu cuenta</a><br /><a href='forgotpass.php'>Has olvidado el password?</a>"
;
        
$row1 $GLOBALS['adopts']->select("online", array(), "username != 'Visitor'")->fetchAll();
        
$total1 count($row1);
        
$row2 $GLOBALS['adopts']->select("online", array(), "username = 'Visitor'")->fetchAll();
        
$total2 count($row2);
        
$sidebar .= "<br />Hay {$total1} usuario(s) y {$total2} visita(s) online.";

    }
    return 
$sidebar;
}

function 
dologin($username$password$session) {
    
$row $GLOBALS['adopts']->select("users", array(), "username = '{$username}'")->fetchObject();    
    
$uid=$row->uid;
    
$luser=$row->username;
    
$lpass=$row->password;

    if(
$username == $luser and $password == $lpass) {
        
$status "success";
        
//If the cookie already exists for some reason, delete it
        
if (isset($_COOKIE['mysuid']) and isset($_COOKIE['myssession'])) {
            
$past time() - 10
            
setcookie("mysuid"$uid$past);
            
setcookie("myssession"$session$past);
        }
        
// Set the cookie
        
$Month 2592000 time();
        
setcookie("mysuid"$uid$Month);
        
setcookie("myssession"$session$Month);
        
$GLOBALS['adopts']->update("users", array("session" => $session), "username = '{$username}'");
        
        
//Now log our user into the forum account if forum integration is enabled...
        
include("../inc/config_forums.php");
        if(
$mybbenabled == 1){
           include_once(
"functions_forums.php");
           
$forums = new Database($mybbdbname$mybbhost$mybbuser$mybbpass$mybbprefix) or die("Cannot connect to forum database, please contact an admin immediately.");
           
$mybbuser $forums->select("users", array("uid""loginkey"), "username = '{$username}'")->fetchObject();
           
$cookiesettings = array();
           
$cookiesettings['cookiedomain'] = $forums->select("settings", array("value"), "name = 'cookiedomain'")->fetchColumn();
           
$cookiesettings['cookiepath'] = $forums->select("settings", array("value"), "name = 'cookiepath'")->fetchColumn();
           
$cookiesettings['cookieprefix'] = $forums->select("settings", array("value"), "name = 'cookieprefix'")->fetchColumn();
           
mybbsetcookie("mybbuser"$mybbuser->uid."_".$mybbuser->loginkeyNULLtrue$cookiesettings);

           
$mybbsid mybb_random_str(32); 
           
mybbsetcookie("sid"$mybbsid, -1true); 
        }
    }

    else{
        
$status "error";
    }

    return 
$status;
}

function 
getadmlinks() {
    
//This function shows special links to the site admin

    
$links "<li><a href='index.php'>Home</a></li>
    <li><a href='adopt.php'>Administrar adoptables</a></li>
    <li><a href='content.php'>Editar contenido</a></li>
    <li><a href='users.php'>Usuarios</a></li>
    <li><a href='items.php'>Items</a></li>
    <li><a href='settings.php'>Ajustes generales</a></li>
    <li><a href='ads.php'>Avisos</a></li>"
;

    return 
$links;
}

function 
getadmimages() {
    
$formcontent "";
    
$stmt $GLOBALS['adopts']->select("filesmap", array());
    while(
$row $stmt->fetchObject()) {
        
$wwwpath $row->wwwpath;   
        
$friendlyname$row->friendlyname
        
$formcontent .= "<option value='{$wwwpath}'>{$friendlyname}</option>";
    }
    return 
$formcontent;
}

// MESSY - I believe this still runs if there are no ads. There should be an option to turn it off.
function getads($page) {
    
// Function to display site advertisements
    
    
if($page == "any"$page "";    
    
$row $GLOBALS['adopts']->select("ads", array(), "page = '{$page}' and status = 'active' ORDER BY RAND() LIMIT 1")->fetchObject();        
    if(
is_object($row)) {
        
$value$row->text;
        
$value stripslashes($value);
        
$aid$row->id;
        
$actualimpressions$row->actualimpressions;
        
$impressions$row->impressions;

        if(
$impressions == ""$impressions 0;
        
$actualimpressions $actualimpressions 1;

        
//Update the impressions count
        
$GLOBALS['adopts']->update("ads", array("actualimpressions" => $actualimpressions), "id='{$aid}'");
        
//Check that ad is not over max impressions...
        
if ($actualimpressions >= $impressions and $impressions != 0$GLOBALS['adopts']->update("ads", array("status" => "inactive"), "id='{$aid}'");
    }
    else 
$value "";
    return 
$value;
}

function 
getlinkname($lid){
    
$row $GLOBALS['adopts']->select("links", array(), "id='{$lid}'")->fetchObject();    
    
$linkname$row->linktext;
    return 
$linkname;   
}

// NEW - a function to get a page from the database
function getpage($name) {
    
$row $GLOBALS['adopts']->select("content", array(), "page='{$name}' LIMIT 1")->fetchObject();    
    
$GLOBALS['article_content'] = $row->content;
    
$GLOBALS['article_title'] = $row->title;
    
$GLOBALS['date'] = $row->date;
    return;
}

function 
getattributes(){
    
// This function defines default attributes for html table, form and other stuff...
    
$attr = new stdclass;

    
// Get default attributes for html tables...    
    
$attr->table = new stdclass;
    
$attr->table->align "center";
    
$attr->table->style "";
    
$attr->table->background = array();
    
$attr->table->border 1;
    
$attr->table->cellpadding "";
    
$attr->table->cellspacing "";
    
$attr->table->frame "";
    
$attr->table->rules "";
    
$attr->table->summary "";
    
$attr->table->width "";    
    
    
// Get default attributes for html forms...
    
$attr->form = new stdclass;
    
$attr->form->action "index.php";
    
$attr->form->accept "";
    
$attr->form->enctype "";
    
$attr->form->method "post";
    
$attr->form->name "form";
    
$attr->form->target "";
    
    
// All done, at least for this time being... 
    
return $attr;    
}

function 
getpoundsettings(){
    
// This function defines default attributes for html table, form and other stuff...
    
$settings = new stdclass
       
$stmt $GLOBALS['adopts']->select("pound_settings", array());
    while(
$row $stmt->fetchObject()){
      
$property $row->varname;
      foreach(
$row as $key => $val){       
        
$settings->$property->$key $val;
      }
    }
    return 
$settings;
}

// NEW - a function to show the page
function showpage($title$content$date) {
    
$theme $GLOBALS['usersettings']['theme'];
    if (
$theme == ''$theme grabanysetting("theme");
    
$acpthemeurl "../templates/acp/template.html";
    
$themeurl "templates/{$theme}/template.html";
    
$patterns = array("/:ARTICLETITLE:/","/:ARTICLECONTENT:/""/:ARTICLEDATE:/""/:BROWSERTITLE:/""/:SITENAME:/""/:SLOGAN:/""/:LINKSBAR:/""/:SIDEFEED:/""/:ADS:/");
    
// if we have said we are in an admin area, don't show ads and show admin links
    
if (defined("SUBDIR") and SUBDIR == "AdminCP") {
        
$replacements = array($title$content$dategrabanysetting("browsertitle")." ".$titlegrabanysetting("sitename"), grabanysetting("slogan"), getadmlinks(), getsidebar(), "");
         
$template file_get_contents($acpthemeurl);
    }
    else {
        
$replacements = array($title$content$dategrabanysetting("browsertitle")." ".$titlegrabanysetting("sitename"), grabanysetting("slogan"), getlinks(), getsidebar(), getads("any"));
         
$template file_get_contents($themeurl);
    }
    
// now that we have our stuff, let's start making it all into a webpage

    
$template =  preg_replace($patterns$replacements$template);
    return 
$template;
}

function 
getpostbar ($name) {
    
$row $GLOBALS['adopts']->join("users_profile""users_profile.uid = users.uid")
                             ->
select("users", array(), constant("PREFIX")."users.username = '{$name}'")->fetchObject();    
    
    
$postbar "<table><tr>
             <td>
             <img src='
{$row->avatar}'>
             </td>
             <td>
             <b>Member Since: </b><br>
{$row->membersince}<br> 
             <b>Bio:</b><br>
{$row->bio}<br> 
             </td>
             <td>
             <b>Nickname:</b> 
{$row->nickname}<br> 
             <b>Gender:</b> 
{$row->gender}<br>
             <b>Cash:</b> <a href='forum.php?do=donate&from=
{$row->uid}&am={$row->money}'>{$row->money}</a><br> 
             </td></table>"

    return 
$postbar
}

?>

Last edited by Jocla; 03-02-2013 at 10:41 PM. Reason: add info
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database functions? Infernette Questions and Supports 8 07-10-2013 12:13 PM
Something wrong in my functions.php Abronsyth Questions and Supports 2 04-29-2012 03:01 PM
image under functions.php PokePets Questions and Supports 4 08-09-2010 07:46 AM
YouTube Gallery -Non Donator Edition- Bloodrun Addons/Mods Graveyard 16 05-29-2009 08:20 PM
A 'limited edition' Christmas pet Quillink Questions and Supports 4 12-27-2008 07:37 AM


All times are GMT -5. The time now is 06:49 AM.

Currently Active Users: 3626 (0 members and 3626 guests)
Threads: 4,081, Posts: 32,032, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636