Code Search for Developers
 
 
  

Module.php from ECP (EliteCore Project) at Krugle


Show Module.php syntax highlighted

<?php

/**
 * Module object is loaded using ModulesManager.
 *
 * Module can be a widget,a component or just a set of classes with templates.
 *
 * @package ModulesManager
 * @author Luke Satin <cyberluk@seznam.cz>
 * @version 0.9.6
 */
class Module {
	public $object = null;
	public $default_pos = 0;
	public $admin_pos = 0;
	public $display_admin = false;
	private $accessRights = array ();
	private $locales = true;
	private $printed = false;
	private $xml = false;

	private $i18n_xml = false;
	private $templateVars = array ();

	const MODE_NORMAL = 1;
	const MODE_SEARCH = 2;
	protected $_resources;

	function __get($var) {
		if (strpos($var, 'i18n_') === 0) {
			$array = explode("i18n_", $var);
			if (!$this->i18n_xml) {
				exit ('ERROR: LOCALES NOT LOADED! MODULE:' . $this->getInstance());
			}
			return i18n :: Translate($array[1], $this->i18n_xml);
		} else {
			$array = explode("__", $var);
			if (sizeof($array) == 2) {
				return $this->localeString($array[0], $array[1]);
			}

		}
	}
	function __construct($dbModule = false) {
		if ($dbModule) {
			$this->ECPMODULE($dbModule);
		}
	}
	function getLanguageXML() {
		return $this->i18n_xml;
	}
	function DrawSettings() {
		$url = Location :: Rewrite('index.php?op=Settings');
		return '<a class="settingsButton" onclick="ajaxify(this)" href="' . $url . '">' . Icon :: Insert('settings', 'icon') . ' Settings</a>';
	}
	function onSettings() {
		try {
			$XHTML = $this->InsertForm('settings.xml',$this->getSettings());
			$code = 'var XHTML="' . String :: Escape($XHTML) . '";';
			$code .= 'net.elitemedia.Settings.setWindow(net.elitemedia.Windows.Create({width:430,content:XHTML}));';
			Ajax :: Action(TabEval :: getBehavior($code));
			Renderer :: FlushAjax();
		} catch (NoAjaxException $e) {
		}
	}
	function onSaveSettings() {
		$DataArray = Ajax :: getPostData();
		UserCache :: Set('M' . $this->getID() . '_Settings', $DataArray);
		try {
			Ajax :: Action(TabCallFunction :: getBehavior('net.elitemedia.Settings.closeWindow'));
			Renderer :: FlushAjax();
		} catch (NoAjaxException $e) {
		}
	}
	function getSettings() {
		try {
			$settings = UserCache :: Get('M' . $this->getID() . '_Settings');
			return new ArrayToObject($settings);
		} catch (Exception $e) {
			return new ArrayToObject;
		}
	}
	function InsertForm($XMLSource,$DefaultValues=false) {
		$form = $this->getPath() . 'forms/' . $XMLSource;
		if (@ file_exists($form)) {
			$XHTML = XMLForms :: getXHTML($form,$DefaultValues);
			return $XHTML;
		} else {
			return false;
		}
	}
	function addAccess($Rights) {
		$this->accessRights = $Rights;
	}
	function ECPMODULE($dbModule) {
		global $ECP;

		$this->addDBInfo($dbModule);

		// Current site theme can rewrite module's template
		if (Engine :: file_exists("styles/" . $ECP->getDefaultTheme() . "/modules/" . $this->getName() . "/" . $this->getTemplatePath())) {
			$this->theme_path = "styles/" . $ECP->getDefaultTheme() . "/modules/" . $this->getName() . "/";
		} else
			if (Engine :: file_exists($this->path . $this->getTemplatePath())) {
				$this->theme_path = $this->path;
			} else
				if (Engine :: file_exists("styles/" . $ECP->getDefaultTheme(2) . "/modules/" . $this->getName() . "/" . $this->getTemplatePath())) {
					$this->theme_path = "styles/" . $ECP->getDefaultTheme(2) . "/modules/" . $this->getName() . "/";
				} else
					if (Engine :: file_exists("styles/" . $ECP->getDefaultTheme(1) . "/modules/" . $this->getName() . "/" . $this->getTemplatePath())) {
						$this->theme_path = "styles/" . $ECP->getDefaultTheme(1) . "/modules/" . $this->getName() . "/";
					} else {
						// FATAL ERROR - TEMPLATE NOT FOUND
						$this->theme_path = $this->path;
					}
		$this->CSS = $this->theme_path . $this->getTemplatePath() . "main.css";
		//if (!Engine::file_exists($this->CSS) && Engine::file_exists($this->theme_path.$this->getTemplatePath()."main.css.php"))
		//	$this->CSS = $this->theme_path.$this->getTemplatePath()."main.css.php?template=".$this->getTemplate();
		$this->loadLocaleFile();
		$this->loadXML();
	}

	protected function _createResource($resource) {
		$this->_resources[(string) $resource] = array ();
	}
	protected function _addResource($resource, $name, $href, $image_src = false, $search_data = false, $info = false) {
		$object = new module_class_resource;
		$object->name = $name;
		$object->href = $href;
		$object->image_src = $image_src;
		$object->info = $info;
		if (is_array($search_data) === false && $search_data !== false)
			exit ("search_data must be an array! in " . $name);
		$object->search_data = $search_data;
		$this->_resources[(string) $resource][] = $object;
	}
	protected function _returnResources() {
		return $this->_resources;
	}

	public function _getResources($mode = MODE_NORMAL) {
		return false;
	}
	public function _getSEO($source, $name) {
		return false;
	}
	function getThemePath() {
		return $this->theme_path;
	}

	/**
	 * This method sets some of module's properties to it's initial values. You can pass an object which has these basic properties defined to set them in current module.
	 *
	 * @param object $module
	 */
	private function addDBInfo($dbModule) {
		$this->height = $dbModule->height;
		$this->language = $dbModule->language;
		$this->template_name = $dbModule->template;
		$this->template = "templates/" . $dbModule->template . "/";
		$this->block = $dbModule->block;
		$this->accessRights = $dbModule->accessRights;
		$this->base = $dbModule->base;
		$this->height = $dbModule->height;
		$this->status = $dbModule->status;
		$this->id = $dbModule->id;
		if (isset ($dbModule->object))
			$this->object = $dbModule->object;
		$this->instance_name = $dbModule->instance_name;
		$this->nick = $dbModule->name;
		if ($_GET['module'] == $this->getInstance() && User :: inAdmin()) {
			$this->display_admin = true;
		}
		if ((User :: inAdmin() && !$this->display_admin) || ($this->default_pos == -1 && User :: inAdmin() && $this->display_admin)) {
			$this->default_pos = $dbModule->admin_position;
		} else {
			$this->default_pos = $dbModule->position;
		}
		$this->admin_pos = $dbModule->admin_position;
		$this->resource = $dbModule->resource;
		$this->path = "modules/" . $this->base . "/";
		if ($this->display_admin)
			$this->default_pos = 2;
	}

	/**
	 * @return boolean Returns current status - if the module is active.
	 */
	function getStatus() {
		if ($_GET['module'] == $this->getInstance() && Location :: currentScript() == "openWindow.php")
			return 1;
		return $this->status;
	}
	/**
	 *
	 *
	 * @return string This method returns a path to images folder under current template in module.
	 */
	function getImagesPath($image = false) {
		global $XCS;
		if ($image === false) {
			return $this->theme_path . $this->template . "images/";
		} else {
			if (Engine :: file_exists("styles/" . $XCS->getDefaultTheme() . "/modules/" . $this->getName() . "/" . $this->getTemplatePath() . "images/" . $image)) {
				$returnPath = "styles/" . $XCS->getDefaultTheme() . "/modules/" . $this->getName() . "/" . $this->getTemplatePath() . "images/";
			} else
				if (Engine :: file_exists("modules/" . $this->getName() . "/" . $this->getTemplatePath() . "images/" . $image)) {
					$returnPath = "modules/" . $this->getName() . "/" . $this->getTemplatePath() . "images/";
				} else {
					$returnPath = "modules/articles/templates/default/images/";
				}
			return $returnPath . $image;
		}
	}
	function getTemplatesDir() {
		return "modules/" . $this->getName() . "/" . $this->getTemplatePath();
	}
	/**
	 * @return int Returns ID stored in database for current module or -1 if it
	 * doesn't exist (this module was created manualy).
	 */
	function getID() {
		return $this->id;
	}

	/**
	 * @return int This method returns module's height (=place number in
	 * current content position)
	 */
	function getHeight() {
		return $this->height;
	}

	/**
	 *
	 *
	 * @return string Returns the name of current module. (=name of module,
	 * directory) - This information is stored in base column in xcs_modules
	 * table.
	 */
	function getBase() {
		return $this->base;
	}
	function getName() {
		return $this->getBase();
	}

	/**
	 *
	 *
	 * @return string Returns the root name of table from database,where this
	 * module stores it's informations. ($prefix."_module_"."$name)
	 */
	function getInstance() {
		if ($this->instance_name != "none") {
			$retval = $this->instance_name;
		} else {
			$retval = $this->base;
		}

		return $retval;
	}

	/**
	 *
	 *
	 * @return string Returns the localized name(=nick) of current module (user
	 * can specify this name in administration - it's stored in name column in
	 * modules table)
	 */
	function getNick() {
		return $this->nick;
	}

	/**
	*
	*
	* @return string Returns module's position
	*/
	function getPosition() {
		return $this->default_pos;
	}
	/**
	 * @return string Returns module's own language
	 */
	function getLanguage() {
		return $this->language;
	}
	/**
	*
	*
	* @return string Returns module's position in administration
	*/
	function getAdminPosition() {
		return $this->admin_pos;
	}

	/**
	 *
	 *
	 * @return string Returns the block of current module or "none" value.
	 */
	function getBlock() {
		return $this->block;
	}

	/**
	 *
	 *
	 * @return string Returns template of current module.
	 */
	function getTemplate() {
		return $this->template_name;
	}

	/**
	 *
	 *
	 * @return string Returns template path of current module.
	 */
	function getTemplatePath() {
		return "templates/" . $this->template_name . "/";
	}

	/**
	 *
	 *
	 * @return string Returns path to module's main directory (including module's name).
	 */
	function getPath() {
		return $this->path;
	}

	/**
	 *
	 *
	 * @param int $group
	 * @return object|false Returns object which have rights for given group as properties or FALSE if this module has no rights setted in DB.
	 */
	function getRights($group) {
		global $DB;
		$retval = false;
		if (!sizeof($this->accessRights)) {
			$TA = new TA();
			$TA->addQuery(TA :: SELECT, "xcs_modules_access");
			$TA->WHERE("module='" . $this->getInstance() . "'");
			$TA->Execute();
			while ($access = $TA->Result()->FetchObject()) {
				$this->accessRights[] = $access;
			}
			$TA->End();
		}
		foreach ($this->accessRights as $rights) {
			if ($rights->group == $group)
				$retval = $rights;
		}
		if ($retval == false && $group != 0) {
			foreach ($this->accessRights as $rights) {
				if ($rights->group == 0)
					$retval = $rights;
			}
		}
		return $retval;
	}

	/**
	 * This method does the same as the {@link Engine} equivalent object with one difference: it checks if current module has rights to publish anything (=safe).
	 */
	function registerVariable($value, $variable, $type = false) {
		global $XCS;
		$rights = $this->getRights(User :: $profile->group);
		if ($rights->read && $this->getStatus() == 1 || User :: inAdmin()) {
			if ($type == 'array' && $value == false)
				$value = array ();
			$file = $this->content_file;
			$this->templateVars[$variable] = $value;
			$XCS->registerVariable($value, $variable, $file);
		}
	}
	/**
	 * This method does the same as the {@link Engine} equivalent with one difference: it checks if current module has rights to publish anything (=safe).
	 */
	function addContent($text, $customPosition = false, $plain_text = false, $noscroll = false) {
		global $ECP;

		$rights = $this->getRights(User :: $profile->group);
		if ($rights->read && ($this->default_pos != -1 || $customPosition !== false) && $this->getStatus() == 1 || User :: inAdmin()) {
			if ($plain_text === true) {
				$ECP->addContent($text, $customPosition);
				return;
			}

			if ($customPosition === false)
				$customPosition = $this->default_pos;

			$theme_path_exists = Engine :: file_exists($this->theme_path . $this->template . $text);
			$path_exists = Engine :: file_exists($this->path . $this->template . $text);
			$default_exists = Engine :: file_exists($this->path . "templates/default/" . $text);

			if ($theme_path_exists || $path_exists || $default_exists) {
				if ($theme_path_exists) {
					$text = $this->theme_path . $this->template . $text;
				} else
					if ($path_exists) {
						$text = $this->path . $this->template . $text;
					} else
						if ($default_exists) {
							$text = $this->path . "templates/default/" . $text;
						}
				$this->content_file = $text;
				$ECP->addContent($this->content_file, (int)$customPosition);
				$ECP->registerVariable($this, "language", $this->content_file); // variable $language is automatically accessible in every template file
				$ECP->registerVariable($this, "currentModule", $this->content_file);
				$ECP->registerVariable("_" . $this->getTemplate(), "cssid", $this->content_file);
			} else {
				$ECP->addContent($text, (int)$customPosition);
			}
		}
	}
	function getContent() {
		if (empty ($this->content_file))
			return false;

		/*ModulesManager :: disableAll();
		ModulesManager :: enableModule($this);

		$content2 = ob_get_contents();
		ob_end_clean();
		ob_start();

		$ECP = Engine :: getInstance();
		$ECP->printContent($this->default_pos, $this);

		$content = ob_get_contents();
		ob_end_clean();
		ob_start();
		echo $content2;
		return $content;*/


		$currentModule=Engine::getFlag('currentModule');
		$parentModule=Engine::getFlag('parentModule');
		$ECP = Engine :: getInstance();
		foreach ($this->templateVars as $name => $value) {
			${ $name } = $value;
		}
		$content2 = ob_get_contents();
		ob_end_clean();
		ob_start();
		require ($this->content_file);
		$content = ob_get_contents();
		ob_end_clean();
		ob_start();
		echo $content2;
		return $content;
	}
	/**
	 * Loads XML configuration file.
	 */
	function loadXML() {
		$this->xml = Engine :: loadXML("modules/" . $this->getName() . "/config.xml");
	}
	/**
	 * Returns XML object of XML configuration file.
	 */
	function getXML() {
		return $this->xml;
	}

	/**
	 * This method does the same as the {@link Engine} equivalent.
	 */
	private function loadLocaleFile() {
		global $ECP;
		if (User :: isAuthor()) {
			$this->language = User :: $profile->language;
		}
		$this->locales = i18n :: loadLocaleFile($this->language, $this->path);
		$this->i18n_xml = Engine :: loadXML($this->path . "language/" . $this->language . ".xml");
	}

	/**
	 * This method does the same as the {@link Engine} equivalent.
	 */
	function localeString() {
		global $ECP;
		$args = func_get_args();
		return i18n :: TranslateDEPRECATED($args, $this->locales);
	}

	/**
	 * This method outputs an href link(anchor) which (after you click on it) will open new window(popup) and display given content.
	 *
	 * @param string $link_name Text which will be displayed as a hypertext link.
	 * @param string $file File in current module directory which will be used for displaying the content in new window.
	 * @param string $params You can pass your own $_GET parameters here.
	 * @param int $width Window's width
	 * @param int $height Window's height
	 * @param bool $closeTag Add </a> tag?
	 * @return string Returns HTML code which you should insert if you want something to happen :-)
	 */
	function newWindow($link_name, $file, $params = false, $width = 500, $height = 400, $closeTag = true) {
		if ($params)
			$params = "&amp;" . $params;

		if ($closeTag)
			$retval = "<a href=\"openWindow.php?module=" . $this->getInstance() . "$params\" onClick=\"openWindow(this.href,'$file','$width','$height');\" target=\"$file\">$link_name</a>";
		else
			$retval = "<a href=\"openWindow.php?module=" . $this->getInstance() . "$params\" onClick=\"openWindow(this.href,'$file','$width','$height');\" target=\"$file\">$link_name";

		return $retval;
	}

	/**
	 * This method outputs a button which (after you click on it) will open new window(popup) and display given content.
	 *
	 * @param string $link_name Text which will be displayed as a hypertext link.
	 * @param string $file File in current module directory which will be used for displaying the content in new window.
	 * @param string $params You can pass your own $_GET parameters here.
	 * @param int $width Window's width
	 * @param int $height Window's height
	 * @return string Returns HTML code which you should insert if you want something to happen :-)
	 */
	function newWindowButton($link_name, $file, $params = false, $width = 500, $height = 400) {
		if ($params)
			$params = "&amp;" . $params;

		$retval = "<input type=\"button\" onClick=\"openWindow('openWindow.php?module=" . $this->getInstance() . "&amp;file=$file$params','$file','$width','$height');\" value=\"$link_name\" />";

		return $retval;
	}
	/**
	 * @return string Returns current module's resource (if any)
	 */
	function getResource() {
		return $this->resource;
	}
	/**
	 * @return array Returns module's public resources
	 */
	function getResources($mode = module_class :: MODE_NORMAL) {
		if (isset ($this->object) && $this->object instanceof module_class) {
			$retval = $this->object->_getResources($mode);
		} else {
			$retval = false;
		}

		return $retval;
	}
	/**
	 * Activate current resource for current module.
	 */
	function activateResource() {
		if (!empty ($this->resource) && $this->getStatus() == 1 && !User :: inAdmin() && $_GET['module'] != $this->getInstance()) {
			$link = explode("?", $this->resource);
			if ($this->default_pos != -1 && $link[0] == "index.php" && ($_GET['module'] == $this->getInstance() && $_GET['block'] == "" && $this->getBlock() == "none" || $_GET['module'] == $this->getInstance() && $this->getBlock() == $_GET['block'] || empty ($_GET['module']) && $this->hide == 0)) {
				$this->oldGET = $_GET;
				$gets = explode("&", $link[1]);
				foreach ($gets as $get) {
					$value = explode("=", $get);
					$_GET[(string) $value[0]] = $value[1];
				}
			}
		}
	}
	/**
	 * Unset GET variables defined by current resource for current module.
	 */
	function unsetResource() {
		if (!empty ($this->resource) && $this->getStatus() == 1 && !User :: inAdmin() && $_GET['module'] != $this->getInstance()) {
			$link = explode("?", $this->resource);
			if ($this->default_pos != -1 && $link[0] == "index.php" && ($_GET['module'] == $this->getInstance() && $_GET['block'] == "" && $this->getBlock() == "none" || $_GET['module'] == $this->getInstance() && $this->getBlock() == $_GET['block'] || empty ($_GET['module']) && $this->hide == 0)) {
				$_GET = $this->oldGET;
			}
		}
	}
	function formAction($url) {
		// ? (check Survey module)
		$url = Engine :: Rewrite('index.php?op=vote');
		$url .= '" onsubmit="return net.elitemedia.events.onSubmit();';
		return $url;
	}
}
?>



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