Поддержать Проект

Обратная связь

[MODX] Guru
  • Информация
  • Разработчикам
    • Теги
    • API
    • DBAPI
    • System Variables
    • MMrules
  • Дополнения
  • Виджеты
  • Уроки
  • Разработчики
  • Готовые примеры
  • Блог
  • Конфиги
  • HTML коды
© [MODX] Guru
  • API

getDocumentObject API MODX Evo ✈ Evolution CMS

  • Разработчикам
  • API
  • getDocumentObject
Menu
  • addEventListener
  • changeWebUserPassword
  • clearCache
  • getActiveChildren
  • getAllChildren
  • getCachePath
  • getChildIds
  • getChunk
  • getConfig
  • getDocument
  • getDocumentChildren
  • getDocumentChildrenTVarOutput
  • getDocumentChildrenTVars
  • getDocumentObject
  • getDocuments
  • getFullTableName
  • getKeywords
  • getLoginUserID
  • getLoginUserName
  • getLoginUserType
  • getManagerPath
  • getMETATags
  • getPageInfo
  • getParent
  • getParentIds
  • getPlaceholder
  • getSnippetId
  • getSnippetName
  • getTemplateVar
  • getTemplateVarOutput
  • getTemplateVars
  • getUserData
  • getUserDocGroups
  • getUserInfo
  • getVersionData
  • getWebUserInfo
  • hasPermission
  • insideManager
  • invokeEvent
  • isBackend
  • isFrontend
  • isMemberOfWebGroup
  • logEvent
  • makeList
  • makeUrl
  • mapPath
  • parseChunk
  • parseText
  • parseProperties
  • putChunk
  • regClientCSS
  • regClientHTMLBlock
  • regClientScript
  • regClientStartupHTMLBlock
  • regClientStartupScript
  • removeAllEventListener
  • removeEventListener
  • runSnippet
  • sendAlert
  • setPlaceholder
  • stripTags
  • toPlaceholder
  • toPlaceholders
  • userLoggedIn
  • webAlert
  • sendmail
4200

getDocumentObject API MODX Evo ✈ Evolution CMS

Получает документ из базы данных

Права доступа к документу проверяются. Документ возвращается в виде массива на успех. Если документ не существует, анализатор вызывает sendErrorPage и выходы. Если документ существует, но пользователь не авторизован, анализатор вызывает sendUnauthorizedPage и выходы.

array getDocumentObject(string $method, mixed $identifier);

  • $method should be either 'id' or 'alias'
  • $identifier will be type string or int depending on $method.

Примеры

// Get the home page title
$homeDoc = $modx->getDocumentObject('id',1);
$title = $homeDoc['pagetitle'];
echo "

{$title}

"; echo htmlspecialchars(print_r($homeDoc,true));

Источник Функции

Файл: manager/includes/document.parser.class.inc.php

Строка: 901

/**
 * name: getDocumentObject  - used by parser
 * desc: returns a document object - $method: alias, id
 */
function getDocumentObject($method, $identifier) {
	$tblsc= $this->getFullTableName("site_content");
	$tbldg= $this->getFullTableName("document_groups");
 
	// get document groups for current user
	if ($docgrp= $this->getUserDocGroups())
		$docgrp= implode(",", $docgrp);
	// get document
	$access= ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") .
	 (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
	$sql= "SELECT sc.*
		  FROM $tblsc sc
		  LEFT JOIN $tbldg dg ON dg.document = sc.id
		  WHERE sc." . $method . " = '" . $identifier . "'
		  AND ($access) LIMIT 1;";
	$result= $this->db->query($sql);
	$rowCount= $this->recordCount($result);
	if ($rowCount < 1) {
		if ($this->config['unauthorized_page']) {
			// Fix for FS #375 - netnoise 2006/08/14
			if ($method != 'id')
				$identifier= $this->cleanDocumentIdentifier($identifier);
			if (!is_numeric($identifier) && array_key_exists($identifier, $this->documentListing)) {
				$identifier= $this->documentListing[$identifier];
				$method= 'id';
			}
 
			// check if file is not public
			$secrs= $this->dbQuery("SELECT id FROM $tbldg WHERE document = '" . $identifier . "' LIMIT 1;");
			if ($secrs)
				$seclimit= mysql_num_rows($secrs);
		}
		if ($seclimit > 0) {
			// match found but not publicly accessible, send the visitor to the unauthorized_page
			$this->sendUnauthorizedPage();
			exit; // stop here
		} else {
			$this->sendErrorPage();
			exit;
		}
	}
 
	# this is now the document :) #
	$documentObject= $this->fetchRow($result);
 
	// load TVs and merge with document - Orig by Apodigm - Docvars
	$sql= "SELECT tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value ";
	$sql .= "FROM " . $this->getFullTableName("site_tmplvars") . " tv ";
	$sql .= "INNER JOIN " . $this->getFullTableName("site_tmplvar_templates")." tvtpl ON tvtpl.tmplvarid = tv.id ";
	$sql .= "LEFT JOIN " . $this->getFullTableName("site_tmplvar_contentvalues")." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '" . $this->documentIdentifier . "' ";
	$sql .= "WHERE tvtpl.templateid = '" . $documentObject['template'] . "'";
	$rs= $this->dbQuery($sql);
	$rowCount= $this->recordCount($rs);
	if ($rowCount > 0) {
		for ($i= 0; $i < $rowCount; $i++) {
			$row= $this->fetchRow($rs);
			$tmplvars[$row['name']]= array (
				$row['name'],
				$row['value'],
				$row['display'],
				$row['display_params'],
				$row['type']
			);
		}
		$documentObject= array_merge($documentObject, $tmplvars);
	}
	return $documentObject;
}