<?php require_once MODX_CORE_PATH.'model/modx/moduser.class.php'; class myUser extends modUser { function test(){ return "Some text"; } } ?>
$user = $modx->getObject('modUser', $id); print $user->test();
public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) { $instance= null; $fromCache= false; if ($className= $xpdo->loadClass($className)) { if (!is_object($criteria)) { $criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag); } if (is_object($criteria)) { $row= null; if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) { $row= $xpdo->fromCache($criteria, $className); } if ($row === null || !is_array($row)) { if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) { $row= $rows->fetch(PDO::FETCH_ASSOC); $rows->closeCursor(); } } else { $fromCache= true; } if (!is_array($row)) { if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true)); } else { $instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row); if (is_object($instance)) { if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) { $xpdo->toCache($criteria, $instance, $cacheFlag); if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) { $pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag); $xpdo->toCache($pkCriteria, $instance, $cacheFlag); } } if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true)); } } } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.'); } } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className); } return $instance; }
public static function _loadInstance(& $xpdo, $className, $criteria, $row) { $rowPrefix= ''; if (is_object($criteria) && $criteria instanceof xPDOQuery) { $alias = $criteria->getAlias(); $actualClass = $criteria->getClass(); } elseif (is_string($criteria) && !empty($criteria)) { $alias = $criteria; $actualClass = $className; } else { $alias = $className; $actualClass= $className; } if (isset ($row["{$alias}_class_key"])) { $actualClass= $row["{$alias}_class_key"]; $rowPrefix= $alias . '_'; } elseif (isset($row["{$className}_class_key"])) { $actualClass= $row["{$className}_class_key"]; $rowPrefix= $className . '_'; } elseif (isset ($row['class_key'])) { $actualClass= $row['class_key']; } $instance= $xpdo->newObject($actualClass); if (is_object($instance) && $instance instanceof xPDOObject) { $pk = $xpdo->getPK($actualClass); if ($pk) { if (is_array($pk)) $pk = reset($pk); if (isset($row["{$alias}_{$pk}"])) { $rowPrefix= $alias . '_'; } elseif ($actualClass !== $className && $actualClass !== $alias && isset($row["{$actualClass}_{$pk}"])) { $rowPrefix= $actualClass . '_'; } elseif ($className !== $alias && isset($row["{$className}_{$pk}"])) { $rowPrefix= $className . '_'; } } elseif (strpos(strtolower(key($row)), strtolower($alias . '_')) === 0) { $rowPrefix= $alias . '_'; } elseif (strpos(strtolower(key($row)), strtolower($className . '_')) === 0) { $rowPrefix= $className . '_'; } $parentClass = $className; $isSubPackage = strpos($className,'.'); if ($isSubPackage !== false) { $parentClass = substr($className,$isSubPackage+1); } if (!$instance instanceof $parentClass) { $xpdo->log(xPDO::LOG_LEVEL_ERROR, "Instantiated a derived class {$actualClass} that is not a subclass of the requested class {$className}"); } $instance->_lazy= $actualClass !== $className ? array_keys($xpdo->getFieldMeta($actualClass)) : array_keys($instance->_fieldMeta); $instance->fromArray($row, $rowPrefix, true, true); $instance->_dirty= array (); $instance->_new= false; } return $instance; }
if (isset ($row["{$alias}_class_key"])) { $actualClass= $row["{$alias}_class_key"]; $rowPrefix= $alias . '_'; } elseif (isset($row["{$className}_class_key"])) { $actualClass= $row["{$className}_class_key"]; $rowPrefix= $className . '_'; } elseif (isset ($row['class_key'])) { $actualClass= $row['class_key']; } $instance= $xpdo->newObject($actualClass);
public function getAuthenticatedUser($contextKey= '') { $user= null; if ($contextKey == '') { if ($this->context !== null) { $contextKey= $this->context->get('key'); } } if ($contextKey && isset ($_SESSION['modx.user.contextTokens'][$contextKey])) { $user= $this->getObject('modUser', intval($_SESSION['modx.user.contextTokens'][$contextKey]), true); if ($user) { $user->getSessionContexts(); } } return $user; }
class SocietyUser extends modUser { static function load(xPDO &$xpdo, $className, $criteria, $cacheFlag = true) { $instance= null; $fromCache= false; if ($className= $xpdo->loadClass($className)) { if (!is_object($criteria)) { $criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag); } if (is_object($criteria)) { $row= null; if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) { $row= $xpdo->fromCache($criteria, $className); } if ($row === null || !is_array($row)) { if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) { $row= $rows->fetch(PDO::FETCH_ASSOC); $rows->closeCursor(); } } else { $fromCache= true; } if (!is_array($row)) { if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true)); } else { // Перегружаем значение класса $row['SocietyUser_class_key'] = 'SocietyTestUser'; $instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row); if (is_object($instance)) { if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) { $xpdo->toCache($criteria, $instance, $cacheFlag); if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) { $pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag); $xpdo->toCache($pkCriteria, $instance, $cacheFlag); } } if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true)); } } } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.'); } } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className); } return $instance; } function test(){ return "11Sdfsdfsd"; } }
Error adding index user to disUserFriend: Array ( [0] => 42S02 [1] => 1146 [2] => Table 'discuss_v01.modx_discuss_user_friends' doesn't exist ) Error adding index friend to disUserFriend: Array ( [0] => 42S02 [1] => 1146 [2] => Table 'discuss_v01.modx_discuss_user_friends' doesn't exist ) Error adding field disBoard->ltr: No metadata defined Error adding index ltr to disBoard: No metadata defined Error adding field disThread->post_last_on: Array ( [0] => 42S02 [1] => 1146 [2] => Table 'discuss_v01.modx_discuss_threads' doesn't exist ) Error adding index post_last_on to disThread: Array ( [0] => 42S02 [1] => 1146 [2] => Table 'discuss_v01.modx_discuss_threads' doesn't exist ) Error adding field disThread->participants: Array ( [0] => 42S02 [1] => 1146 [2] => Table 'discuss_v01.modx_discuss_threads' doesn't exist ) Could not load class: disBanGroup from mysql.disbangroup. Could not load class: disBanItem from mysql.disbanitem.
Error adding index user to disUserFriend: Array ( [0] => 42000 [1] => 1061 [2] => Duplicate key name 'user' ) Error adding index friend to disUserFriend: Array ( [0] => 42000 [1] => 1061 [2] => Duplicate key name 'friend' ) Error adding field disBoard->ltr: No metadata defined Error adding index ltr to disBoard: No metadata defined Error adding field disThread->post_last_on: Array ( [0] => 42S21 [1] => 1060 [2] => Duplicate column name 'post_last_on' ) Error adding index post_last_on to disThread: Array ( [0] => 42000 [1] => 1061 [2] => Duplicate key name 'post_last_on' ) Error adding field disThread->participants: Array ( [0] => 42S21 [1] => 1060 [2] => Duplicate column name 'participants' ) Could not load class: disBanGroup from mysql.disbangroup. Could not load class: disBanItem from mysql.disbanitem.
$manifest = array( 'preview' => 'preview.png', 'global' => array( 'js' => array( 'inline' => 'var DIS = {config: {}}; DIS.url = "'.$this->discuss->request->makeUrl().'";DIS.shJsUrl = "'.$this->discuss->config['jsUrl'].'sh/";DIS.config.connector = "'.$this->discuss->config['connectorUrl'].'"; DIS.config.forum_url = "'.$this->discuss->request->makeUrl().'"', ), 'options' => array( 'registerJsToScriptTags' => false, 'showBreadcrumbs' => true, 'showTitleInBreadcrumbs' => true, 'showReaders' => true, 'showModerators' => true, 'showPaginationIfOnePage' => false, 'showPrintOption' => false, ) ), 'print' => array( 'css' => array( 'header' => array( 'print.css', ), ), ),
<?php if($modx->context->key == 'mgr'){return;} if(isset($modx->resource) && is_object($modx->resource)){return;} $base_url = $modx->getOption('base_url', null); $url = $_SERVER['REQUEST_URI']; $forums_resource_id = $modx->getOption('discuss.forums_resource_id', null, $modx->getOption('site_start', null)); $forum_url_prefix = $modx->makeUrl($forums_resource_id, '', '', 'abs'); if(!$forum_url_prefix) $forum_url_prefix = $modx->getOption('base_url', null); // Check for forums path if(strpos($url, $forum_url_prefix) !== 0){return;} $preg = str_replace('/', '\/', $forum_url_prefix); $url = preg_replace("/^{$preg}/", $base_url, $url); $_SERVER['REQUEST_URI'] = $url; // cleare from params $url = preg_replace('/\?.*/','', $url); if(!$url){return;} $params = array(); if(preg_match('/^\/(board|thread|category)\/([0-9]+)\/(.*)$/', $url, $match)){ $params['action'] = $match[1]; $params[$match[1]] = $match[2]; } else if(preg_match('/^\/u\/(.*)$/', $url, $match)){ $params['action'] = 'user'; $params['user'] = $match[1]; } else{ $params['action'] = $url; } foreach($params as $k => $v){ $_GET[$k] = $v; $_REQUEST[$k] = $v; } $modx->sendForward($forums_resource_id);