Source for file User.class.php

Documentation is available at User.class.php

  1. <?php
  2. /**
  3.  * R.E. Login 2.0 - Felhasználó - class/User.class.php
  4.  *
  5.  * Felhasználót megvalósító osztály<br />
  6.  * <br />
  7.  * <b>Dátum:</b> 2010.04.02.
  8.  *
  9.  * <b>Szerző weboldala:</b> {@link http://rimelek.hu/}<br />
  10.  * <b>Login weblapja:</b> {@link http://rimelek.hu/meghivos-loginrendszer-r-e-login-v2-0 R.E. Login v2.0}
  11.  *
  12.  * @author Takács Ákos (Rimelek), programmer [at] rimelek [dot] hu
  13.  * @copyright Copyright (C) 2010, Takács Ákos
  14.  * @license http://www.gnu.org/licenses/gpl.html
  15.  * @package RELogin
  16.  * @version 2.0
  17.  */
  18.  
  19. /**
  20.  * @ignore
  21.  */
  22. require_once System::getIncLoginDir().'classes/System.class.php';
  23.  
  24.  
  25. /**
  26.  * Felhasználót reprezentáló osztály
  27.  *
  28.  * <b>Dátum:</b> 2010.04.02.
  29.  *
  30.  * <b>Szerző weboldala:</b> {@link http://rimelek.hu/}<br />
  31.  * <b>Login weblapja:</b> {@link http://rimelek.hu/meghivos-loginrendszer-r-e-login-v2-0 R.E. Login v2.0}
  32.  *
  33.  * @property int $T_users_userid Felhasználó azonosítója
  34.  * @property string $username Felhasználó neve
  35.  * @property string $userpass Felhasználó jelszavának hash-e
  36.  * @property int $rank Rang azonosítója
  37.  * @property string $regtime Lásd {@link System::getTimeStamp()}
  38.  * @property string $refreshtime Lásd {@link System::getTimeStamp()}
  39.  * @property string $logintime Lásd {@link System::getTimeStamp()}
  40.  * @property int $onlinetime Online idő másodpercekben
  41.  * @property char $onlinestatus '1', Ha kilépett a kilépés funkcióval a user.
  42.  *                     És '0', ha nem lépett ki.
  43.  * @property int $invitations Meghívóinak száma
  44.  * @property string $T_users_useremail Felhasználó aktivált e-mail címe.
  45.  * @property string $newsreadtime Mikor olvasott utoljára hírt.
  46.  *                     Lásd {@link System::getTimeStamp()}
  47.  * @property int $T_profiles_userid Felhasználó azonosítója a profiles táblában
  48.  * @property string $firstname Keresztnév
  49.  * @property string $lastname Vezetéknév
  50.  * @property string $birthdate Születési idő. Y-m-d formátumban
  51.  * @property char $sex 'm', ha nő. 'f', ha férfi. NULL? ha nincs beállítva.
  52.  * @property string $country Ország
  53.  * @property string $city Város
  54.  * @property string $T_profiles_useremail Felhasználó e-mail címe a profiljában.
  55.  *                     Még nem biztos, hogy meg van erősítve.
  56.  * @property char $public_mail '1', ha publikus a megadottemail címe. Egyébként '0'
  57.  * @property string $website Weboldal címe
  58.  * @property string $msn MSN cím
  59.  * @property string $skype Skype név
  60.  * @property string $other Egyéb információ a felhasználóról. (Bemutatkozás)
  61.  *
  62.  * @author Takács Ákos (Rimelek), programmer [at] rimelek [dot] hu
  63.  * @copyright Copyright (C) 2010, Takács Ákos
  64.  * @license http://www.gnu.org/licenses/gpl.html
  65.  * @package RELogin
  66.  * @version 2.0
  67.  */
  68. class User extends IsMySQLClass
  69. {
  70.     /**
  71.      * Létező vagy új felhasználó létrehozása
  72.      *
  73.      * @param mixes $userName User neve, ha a második paraméter is meg van adva. (Létező felhasználó)
  74.      *                 ha nincs meg adva második paraméter, akkor a táblalista a mezőlistákkal (Új felhasználó)
  75.      * @param string $userPass User jelszava
  76.      */
  77.     public function __construct($userName,$userPass=null)
  78.     {
  79.         $pref Config::DBPREF;
  80.         $config System::$config;
  81.         $properties array(
  82.             $pref.'users as users'=>array('*'),
  83.             $pref.'profiles as profiles'=>array('*')
  84.         );
  85.  
  86.         if (is_array($userName))
  87.         {
  88.             parent::__construct($userName);
  89.             return;
  90.         }
  91.         else if (!is_string($userPass))
  92.         {
  93.             parent::__construct($properties);
  94.             $this->keyName = 'userid';
  95.             parent::init($userName);
  96.             return;
  97.         }
  98.  
  99.         if ($userPass === null)
  100.         {
  101.             return;
  102.         }
  103.  
  104.         parent::__construct($properties);
  105.  
  106.         $userName mysql_real_escape_string($userName);
  107.         $sql 
  108.             $pref."users as users left join ".
  109.             $pref."profiles as profiles using(userid) where username = '".
  110.             mysql_real_escape_string($userName).
  111.             "' and userpass = '".mysql_real_escape_string($userPass)."'";
  112.  
  113.         $this->init($sql);
  114.     }
  115.  
  116.     /**
  117.      * User inicializálása
  118.      *
  119.      * @param string $sql Sql lekérdezés from utáni része
  120.      */
  121.     public function init($sql)
  122.     {
  123.         parent::init($sql,true);
  124.     }
  125.  
  126.     /**
  127.      * Kor meghatározása
  128.      *
  129.      * 
  130.      * @param string $bdtimestamp Szletési id Y-m-d formátumban.
  131.      * @return int A felhasználó kora
  132.      */
  133.     public static function getAge($bdtimestamp)
  134.     {
  135.         $szarray explode('-',$bdtimestamp);
  136.         $time System::getTime();
  137.         $szmonth $szarray[1];
  138.         $mmonth date('m',$time);
  139.         $szday $szarray[2];
  140.         $mday date('d',$time);
  141.         $age date('Y',$time$szarray[0];
  142.         if( ($szmonth $mmonth )
  143.         or ($szmonth == $mmonth and $szday $mday) ) {
  144.             $age--;
  145.         }
  146.         return $age;
  147.     }
  148.  
  149.     /**
  150.      *
  151.      * @param int $sec Online idő másodpercben
  152.      * @param string $str eredmény sablonja. Amiben a következő helyettesítők
  153.      *             használhatók:
  154.      *             <ul>
  155.      *                 <li>{day}: Nap</li>
  156.      *                 <li>{hour}: Óra</li>
  157.      *                 <li>{min}: Perc</li>
  158.      *                 <li>{sec}: másodperc</li>
  159.      *             </ul>
  160.      *             <code>print User::getOnlineTime($sec, '{day} nap, {hour} óra');</code>
  161.      * @return string 
  162.      */
  163.     public static function getOnlineTime($sec,$str=null)
  164.     {
  165.         $ret array();
  166.         $ret['sec'$sec 60;
  167.         $tmpmin floor($sec 60);    
  168.         $ret['min'$tmpmin %  60;
  169.         $tmphour floor($tmpmin 60);    
  170.         $ret['hour'$tmphour 24;
  171.         $ret['day'floor($tmphour 24);
  172.         if (!$str)
  173.         {
  174.             return $ret;
  175.         }
  176.  
  177.         return str_replace(array(
  178.             '{day}','{hour}','{min}','{sec}'
  179.         ),array(
  180.             $ret['day']$ret['hour']$ret['min']$ret['sec']
  181.         )$str);
  182.     }
  183.  
  184.     /**
  185.      * Online van-e a user
  186.      *
  187.      * @return bool 
  188.      */
  189.     public function isOnline()
  190.     
  191.         return ($this->onlinestatus and    $this->refreshtime and
  192.             strtotime($this->refreshtime>= System::getTime(Config::MAX_ONLINE_TIME );
  193.     }
  194.  
  195.     /**
  196.      *
  197.      * @return User rangjának neve
  198.      */
  199.     public function rankName()
  200.     {
  201.         require_once System::getIncLoginDir().'classes/Ranks.class.php';
  202.         return Ranks::getRank('name''rankid'$this->rank());
  203.     }
  204.  
  205.     /**
  206.      * Rang lekérdezése, vizsgálata
  207.      *
  208.      * 
  209.      *
  210.      * @param mixed $rank Ha nincs megadva, akkor visszaadja a user rangjának
  211.      *             azonosítóját. Ha nincs neki megfelelő a ranks táblában, akkor
  212.      *             választ egyet az alapján, hogy az éppen böngésző felhasználóról van
  213.      *             szó, vagy valakiről a felhasználó listában.
  214.      *             Ha meg van adva, akkor vagy egy rang változó, vagy azok tömbje.
  215.      *             Bármelyik illik a userre, true-t ad vissza. Egyébként false-t.
  216.      *             <code>
  217.      *             if (System::$user->rank( array('admin','owner') ))
  218.      *             {
  219.      *                 print "Te admin, vagy tulajdonos ranggal rendelkezel. "
  220.      *             }
  221.      *             </code>
  222.      * @return mixed Vizsgálat esetén bool, egyébként nincs visszatérési érték.
  223.      */
  224.     public function rank($rank=null)
  225.     {
  226.         require_once System::getIncLoginDir().'classes/Ranks.class.php';
  227.         $var Ranks::getRank('varname''rankid'$this->rank);
  228.         if (!$var and $this == System::$user and !System::$logged)
  229.         {
  230.             $var 'guest';
  231.         }
  232.         else if (!$var)
  233.         {
  234.             $var 'user';
  235.         }
  236.         if(is_null($rank))
  237.         {
  238.             return Ranks::getIdByVar($var);
  239.         }
  240.         else if (is_string($rank))
  241.         {
  242.             return $var == $rank;
  243.         }
  244.         else if (is_array($rank))
  245.         {
  246.             foreach ($rank as &$item)
  247.             {
  248.                 if (strtolower($var== strtolower($item))
  249.                 {
  250.                     return true;
  251.                 }
  252.             }
  253.             return false;
  254.         }
  255.     }
  256.  
  257.     /**
  258.      * User profiljának url-je
  259.      * 
  260.      * @param int $userid Felhasználó azonosítója
  261.      * @return string 
  262.      */
  263.     public static function profileUrl($userid)
  264.     {
  265.         $url System::getSitedir().Config::FILE_PROFILE;
  266.         return Url::set(array(
  267.             'uid' => $userid
  268.         )$url'&amp;');
  269.     }
  270.  
  271.     /**
  272.      * Gravatar url-je.
  273.      *
  274.      * @param int $size Avatar mérete
  275.      * @return string 
  276.      */
  277.     public function gravatar($size)
  278.     {
  279.         $email empty($this->T_users_useremail'' $this->T_users_useremail;
  280.         return "http://www.gravatar.com/avatar/"
  281.             . md5strtolower$email ) )
  282.             ."?d="
  283.             .urlencodeself::defaultAvatar($this->sex) )
  284.             ."&amp;s=" $size
  285.             ."&amp;r=g";
  286.  
  287.     }
  288.  
  289.     /**
  290.      * Alapértelmezett avatar url-je
  291.      *
  292.      * @param char $sex 'f', ha nő, 'm', ha férfi
  293.      * @return string 
  294.      */
  295.     public static function defaultAvatar($sex)
  296.     {
  297.         $default System::getLoginDirWithHTTP().'images/';
  298.         $default .= (empty($sexor $sex == 'm')
  299.                 ? 'male.png' 'female.png';
  300.         return $default;
  301.     }
  302.  
  303.     /**
  304.      * MKAvatar url-je
  305.      *
  306.      * @param int $size Egész szám. maximum 80-ig
  307.      * @return string 
  308.      */
  309.     public function mkavatar($size)
  310.     {
  311.         $email empty($this->T_users_useremail'' $this->T_users_useremail;
  312.         return "http://www.mkavatar.hu/avatar.php?email="
  313.             . md5strtolower$email ) )
  314.             ."&amp;default="
  315.             .urlencodeself::defaultAvatar($this->sex) )
  316.             ."&amp;size=" $size
  317.             ."&amp;rating=g";
  318.     }
  319.  
  320.     /**
  321.      * User által kiválasztott avatar megjelenítése
  322.      *
  323.      * @param int $size Avatar mérete
  324.      * @return string 
  325.      */
  326.     public function avatar($size)
  327.     {
  328.         if ($this->avatar == 'gravatar')
  329.         {
  330.             return $this->gravatar($size);
  331.         }
  332.         else if ($this->avatar == 'mkavatar')
  333.         {
  334.             return $this->mkavatar($size);
  335.         }
  336.         else
  337.         {
  338.             return $this->defaultAvatar($this->sex);
  339.         }
  340.     }
  341. }
  342. ?>

Documentation generated on Sun, 04 Apr 2010 22:43:53 +0200 by phpDocumentor 1.4.1