Code Search for Developers
 
 
  

user.php from ECP (EliteCore Project) at Krugle


Show user.php syntax highlighted

<?php


/**
 * User object stores all informations about the user which is currently logged in, there are also some default variables which are setted for every user (eg. which group is assigned for guests etc).
 *
 * @package User
 * @author Luke Satin <cyberluk@seznam.cz>
 * @version 0.9.8
 */

class User {
	const ACTIVE = 'active';
	const INACTIVE = 'inactive';

	public static $profile = false;
	public static $SID = false;
	public static $cookie = null;
	/**
	 *
	 * @access private
	 */
	private static $is_author = false;
	private static $id = false;
	private static $groups = array ();

	public static function getSID() {
		try {
			if (self :: $SID !== false)
				return self :: $SID;
			return Storage :: Load('session_id', Storage :: USER);
		} catch (StorageException $e) {
			return false;
		}
	}

	public static function setSID($sid) {
		self :: $SID = $sid;
	}

	public static function hasSession() {
		if (self :: $SID === false)
			return false;
		else
			return true;
	}

	public static function hasSessionData() {
		$result = DB :: Select('ecp_engine_sessions', j('id:'.String :: Escape(self :: getSID())));
		if (!$result)
			return false;
		return true;
	}

	public static function getSessionData() {
		if (!self :: hasSession())
			return false;

		$result = DB :: Select('ecp_engine_sessions', j('id:'.self :: getSID()));
		if (!$result)
			return false;
		return unserialize(String :: Unescape($result->data));
	}

	/**
	 * This method tries to load information about given user = it sets his profile.
	 *
	 * @param int $uid
	 */
	public static function setProfile($uid, $nick) {
		if (self :: $profile || !$uid)
			return false;
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_ranks");
		$TA->Execute();
		while ($object = $TA->Result()->FetchObject()) {
			self :: $groups[] = $object;
		}
		$TA->removeQuery();

		$TA->addQuery(TA :: SELECT, "ecp_engine_authors");
		$TA->addParam("admin");
		$TA->addParam("scope");
		$TA->WHERE("`nick`='" . $nick . "'");
		$TA->Execute();
		$object = $TA->Result()->FetchObject();
		$TA->removeQuery();
		$TA->addQuery(TA :: SELECT, "ecp_engine_users");
		$TA->WHERE("id=" . $uid);
		$TA->Execute();
		self :: $profile = $TA->Result()->FetchObject();
		if (!self :: $profile) {
			$TA->removeQuery();
			$TA->addQuery(TA :: SELECT, "ecp_engine_users");
			$TA->addParam("id");
			$TA->addParam("nick");
			$TA->addParam("name");
			$TA->addParam("email");
			$TA->addParam("group");
			$TA->addParam("language");
			$TA->addParam("www");
			$TA->addParam("country");
			$TA->addParam("city");
			$TA->addParam("gender");
			$TA->addParam("interests");
			$TA->addParam("status");
			$TA->addParam("lastAccess");
			$TA->addParam("credit");
			$TA->WHERE("id=" . $uid);
			$TA->LIMIT(1);
			$TA->Execute();
			self :: $profile = $TA->Result()->FetchObject();
		} else {
			self :: setAuthor(true);
			self :: $profile->admin = $object->admin;
			self :: $profile->scope = $object->scope;
		}

		if (!isset (self :: $profile->admin))
			self :: $profile->admin = 0;
		$TA->End();
		UserCache :: Init();
	}

	/**
	 * @return bool Returns true if you are properly logged and validated user and if you are currently in system administration.
	 */
	public static function inAdmin() {
		$retval = false;
		if ($_GET['file'] == 'admin') {
			if (Session :: isValid() && self :: isAuthor())
				$retval = true;
		}
		return $retval;
	}
	/**
	 *
	 * @return bool Returns true if current user is not a normal user and have some special rights such as administrating the system,publishing content etc.
	 */
	public static function isAuthor() {
		return self :: $is_author;
	}
	public static function setAuthor($isAuthor) {
		self :: $is_author = $isAuthor;
	}

	/**
	 * This method sets 'blank' profile for guests and all who are not logged in.
	 *
	 */
	public static function setBlank() {
		global $XCS;
		if (self :: $profile)
			return false;
		self :: $profile->nick = $XCS->localeString("engine", "guest");
		self :: $profile->id = 0;
		self :: $profile->admin = 0;
		self :: $profile->group = 0;
		self :: $profile->name = '';
		self :: $profile->www = '';
		self :: $profile->email = '';
		self :: $profile->language = i18n :: getDefaultLanguage();
	}
	public static function getID() {
		return self :: $profile->id;
	}
	public static function goodLogin() {
		DB :: UpdateById('ecp_engine_users', User :: $profile->id, array (
			'retries' => 0
		));
		return true;
	}
	public static function wrongLogin() {
		if (!isset (User :: $profile->retries))
			return true;
		if (User :: $profile->retries >= Storage :: Load("login_retries")) {
			DB :: UpdateById('ecp_engine_users', User :: $profile->id, array (
				'status' => User :: INACTIVE
			));
			return true;
		} else {
			DB :: UpdateById('ecp_engine_users', User :: $profile->id, array (
				'retries' => User :: $profile->retries + 1
			));
			return false;
		}
	}
	/**
	* Searches for user's name by ID and returns this name as a string.
	*
	*
	* @param int $user_id User ID
	* @return string Returns the user name(nick) or FALSE
	*/
	public static function getName($id) {
		if ($id < 1)
			return i18n :: Translate("engine", "nobody");
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_users");
		$TA->addParam("nick");
		$TA->WHERE("`id`=" . $id);
		$TA->LIMIT(1);
		$TA->Execute();
		$object = $TA->Result()->FetchObject();

		if ($object)
			$retval = $object->nick;
		else
			$retval = i18n :: Translate("engine", "nobody");

		return $retval;
	}

	public function getById($id) {
		try {
			return Cache :: getObject('engine_users', $id);
		} catch (NoCacheException $e) {
			return false;
		}
	}
	public function getUsers() {
		return self::getById(false);
	}
	public static function getGroup() {
		return self::$profile->group;
	}
	public function getAuthors() {
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_authors");
		$TA->addParam("nick");
		$TA->Execute();
		$authors = array ();
		while ($object = $TA->Result()->FetchObject()) {
			$authors[] = $object;
		}
		return $authors;
	}
}
?>



See more files for this project here

ECP (EliteCore Project)

EliteCore Project is a PHP5.1/Javascript/AJAX/XHTML/CSS framework for creating WEB 2.0 applications and services.The basic open-source instalation can be also used as an interactive personal page or BLOG.This project uses the latest features available.

Project homepage: http://sourceforge.net/projects/elitecore
Programming language(s): JavaScript,PHP,XML
License: cpl

  debug/
    content.php
  exceptions/
    ajaxflush.php
    nomodule.php
    undefineddata.php
  interface/
    encryption.php
    form.php
    module_class.php
    session_interface.php
  renderers/
    default.php
  sql/
    mysql.php
    mysqli.php
  themes/
    ECP/
      accept.png
      add.png
      alt_star.gif
      anchor.png
      arrow_refresh.png
      asterisk_orange.png
      asterisk_yellow.png
      attach.png
      back.png
      cog_error.png
      cog_go.png
      comment.png
      comment_add.png
      comment_delete.png
      comment_edit.png
      comments.png
      comments_add.png
      comments_delete.png
      control_play_blue.png
      drive.png
      gnome-fs-directory.png
      gnome-mime-audio.png
      layers.png
      layout.png
      layout_add.png
      layout_content.png
      layout_delete.png
      layout_edit.png
      layout_error.png
      layout_header.png
      layout_link.png
      layout_sidebar.png
      lightbulb.png
      lightbulb_add.png
      lightbulb_delete.png
      lightbulb_off.png
      lightning.png
      lightning_add.png
      lightning_delete.png
      lightning_go.png
      link.png
      link_add.png
      link_break.png
      link_delete.png
      link_edit.png
      link_error.png
      link_go.png
      lock.png
      lock_add.png
      lock_break.png
      lock_delete.png
      lock_edit.png
      lock_go.png
      lock_open.png
      newspaper.png
      newspaper_add.png
      newspaper_delete.png
      newspaper_go.png
      newspaper_link.png
      note.gif
      note.png
      note_add.png
      note_delete.gif
      note_delete.png
      note_edit.png
      note_error.png
      note_go.png
      note_new.gif
      overlays.png
      package.png
      package_add.png
      package_delete.png
      package_go.png
      package_green.png
      package_link.png
      page.gif
      page.png
      page_add.png
      page_attach.png
      page_code.png
      page_copy.png
      page_delete.png
      page_edit.png
      page_error.png
      page_excel.png
      page_find.png
      page_gear.png
      page_go.png
      page_green.png
      page_key.png
      page_lightning.png
      page_link.png
      page_paintbrush.png
      page_paste.png
      page_red.png
      page_refresh.png
      page_save.png
      page_white.png
      pencil.png
      pencil_add.png
      pencil_delete.png
      pencil_go.png
      photo.png
      photo_add.png
      photo_delete.png
      photo_link.png
      photos.png
      picture.png
      picture_add.png
      picture_delete.png
      picture_edit.png
      picture_empty.png
      picture_error.png
      picture_go.png
      picture_key.png
      picture_link.png
      picture_save.png
      pictures.png
      plugin.png
      plugin_add.png
      plugin_delete.png
      plugin_disabled.png
      plugin_edit.png
      plugin_error.png
      plugin_go.png
      plugin_link.png
      report.png
      report_add.png
      report_delete.png
      report_disk.png
      report_edit.png
      report_go.png
      report_key.png
      report_link.png
      report_magnify.png
      report_picture.png
      report_user.png
      report_word.png
      script.png
      script_add.png
      script_code.png
      script_code_red.png
      script_delete.png
      script_edit.png
      script_error.png
      script_gear.png
      script_go.png
      script_key.png
      script_lightning.png
      script_link.png
      script_palette.png
      script_save.png
      star.png
      star_rating.gif
      stop.png
      style.png
      text_align_center.png
      text_align_justify.png
      text_align_left.png
      text_align_right.png
      text_allcaps.png
      text_bold.png
      text_columns.png
      text_dropcaps.png
      text_heading_1.png
      text_heading_2.png
      text_heading_3.png
      text_heading_4.png
      text_heading_5.png
      text_heading_6.png
      text_horizontalrule.png
      text_indent.png
      text_indent_remove.png
      text_italic.png
      text_kerning.png
      text_letter_omega.png
      text_letterspacing.png
      text_linespacing.png
      text_list_bullets.png
      text_list_numbers.png
      text_lowercase.png
      text_padding_bottom.png
      text_padding_left.png
      text_padding_right.png
      text_padding_top.png
      text_replace.png
      text_signature.png
      text_smallcaps.png
      text_strikethrough.png
      text_subscript.png
      text_superscript.png
      text_underline.png
      text_uppercase.png
      textfield.png
      textfield_add.png
      textfield_delete.png
      textfield_key.png
      textfield_rename.png
      tux.png
      vert_star.gif
    ECP.xml
  Icon.php
  Location.php
  Module.php
  ModulesManager.php
  MusicTags.php
  Page.php
  XHTMLParser.php
  XMLForms.php
  ajax.php
  author.html
  cache.php
  config.php
  date.php
  db.php
  debug.php
  ecp-full.php
  ecp-mini.php
  engine.php
  events.php
  filesystem.php
  footer.html
  i18n.php
  mailer.php
  main.css
  mcrypt.php
  mime.php
  mod_rewrite.php
  perspective.php
  rc4.php
  reflection.php
  session_passport.php
  storage.php
  string.php
  template.php
  texy.php
  user.php
  user_cache.php
  wysiwyg_texy.php
  xhtml_form.php
  xtea.php