本文整理汇总了PHP中modX::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::escape方法的具体用法?PHP modX::escape怎么用?PHP modX::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::escape方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThread
/**
* Gets the current thread
*
* @static
* @param modX $modx
* @param quipThread $thread
* @param int $parent
* @param string $ids
* @param string $sortBy
* @param string $sortByAlias
* @param string $sortDir
* @return array
*/
public static function getThread(modX $modx, quipThread $thread, $parent = 0, $ids = '', $sortBy = 'rank', $sortByAlias = 'quipComment', $sortDir = 'ASC')
{
$c = $modx->newQuery('quipComment');
$c->innerJoin('quipThread', 'Thread');
$c->leftJoin('quipCommentClosure', 'Descendants');
$c->leftJoin('quipCommentClosure', 'RootDescendant', 'RootDescendant.descendant = quipComment.id AND RootDescendant.ancestor = 0');
$c->leftJoin('quipCommentClosure', 'Ancestors');
$c->leftJoin('modUser', 'Author');
$c->leftJoin('modResource', 'Resource');
$c->where(array('quipComment.thread' => $thread->get('name'), 'quipComment.deleted' => false));
if (!$thread->checkPolicy('moderate')) {
$c->andCondition(array('quipComment.approved' => true), null, 2);
}
if (!empty($parent)) {
$c->where(array('Descendants.ancestor' => $parent));
}
$total = $modx->getCount('quipComment', $c);
if (!empty($ids)) {
$c->where(array('Descendants.ancestor:IN' => $ids));
}
$c->select($modx->getSelectColumns('quipComment', 'quipComment'));
$c->select(array('Thread.resource', 'Thread.idprefix', 'Thread.existing_params', 'RootDescendant.depth', 'Author.username', 'Resource.pagetitle', 'Resource.context_key'));
$c->sortby($modx->escape($sortByAlias) . '.' . $modx->escape($sortBy), $sortDir);
$comments = $modx->getCollection('quipComment', $c);
return array('results' => $comments, 'total' => $total);
}
示例2: getPostCount
/**
* Get total post count
* @param string $class
* @param int $id
* return int
*/
public function getPostCount($className = 'disBoard', $id = 0)
{
$c = $this->modx->newQuery($className);
if ($className == 'disBoard') {
if (!$id) {
$c->select(array('post_count' => "SUM({$this->modx->escape('disBoard')}.{$this->modx->escape('total_posts')})"));
} else {
$c->select(array($this->modx->getSelectColumns('disBoard', 'disBoard', '', array('post_count'))));
$c->where(array('id' => $id));
}
} else {
if ($className == 'disThread') {
$c->select(array($this->modx->getSelectColumns('disThread', 'disThread', '', array('replies'))));
$c->where(array('id' => $id));
}
}
if ($stmt = $c->prepare()) {
if ($stmt->execute()) {
if ($results = $stmt->fetchAll(PDO::FETCH_COLUMN)) {
$count = reset($results);
$count = intval($count);
}
}
}
return !$results ? 0 : $className == 'disBoard' ? $count : $count + 1;
// +1 for original thread start post
}
示例3: move
/**
* Move a thread to a new board
*
* @param int $boardId
* @return boolean True if successful
*/
public function move($boardId)
{
$oldBoard = $this->getOne('Board');
$newBoard = is_object($boardId) && $boardId instanceof disBoard ? $boardId : $this->xpdo->getObject('disBoard', $boardId);
if (!$oldBoard || !$newBoard) {
return false;
}
$this->addOne($newBoard);
if ($this->save()) {
/* readjust all posts */
$posts = $this->getMany('Posts');
foreach ($posts as $post) {
$post->set('board', $newBoard->get('id'));
$post->save();
}
/* adjust old board topics/reply counts */
$oldBoard->set('num_topics', $oldBoard->get('num_topics') - 1);
$replies = $oldBoard->get('num_replies') - $this->get('replies');
$oldBoard->set('num_replies', $replies);
$total_posts = $oldBoard->get('total_posts') - $this->get('replies') - 1;
$oldBoard->set('total_posts', $total_posts);
/* recalculate latest post */
$oldBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $oldBoard->get('last_post')));
if ($oldBoardLastPost && $oldBoardLastPost->get('id') == $this->get('post_last')) {
$newLastPost = $oldBoard->get2ndLatestPost();
if ($newLastPost) {
$oldBoard->set('last_post', $newLastPost->get('id'));
$oldBoard->addOne($newLastPost, 'LastPost');
}
}
$oldBoard->save();
/* adjust new board topics/reply counts */
$newBoard->set('num_topics', $oldBoard->get('num_topics') - 1);
$replies = $newBoard->get('num_replies') + $this->get('replies');
$newBoard->set('num_replies', $replies);
$total_posts = $newBoard->get('total_posts') + $this->get('replies') + 1;
$newBoard->set('total_posts', $total_posts);
/* recalculate latest post */
$newBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $newBoard->get('last_post')));
$thisThreadPost = $this->getOne('LastPost');
if ($newBoardLastPost && $thisThreadPost && $newBoardLastPost->get('createdon') < $thisThreadPost->get('createdon')) {
$newBoard->set('last_post', $thisThreadPost->get('id'));
$newBoard->addOne($thisThreadPost, 'LastPost');
}
$newBoard->save();
/* Update ThreadRead board field */
$this->xpdo->exec('UPDATE ' . $this->xpdo->getTableName('disThreadRead') . '
SET ' . $this->xpdo->escape('board') . ' = ' . $newBoard->get('id') . '
WHERE ' . $this->xpdo->escape('thread') . ' = ' . $this->get('id') . '
');
/* clear caches */
if (!defined('DISCUSS_IMPORT_MODE')) {
$this->xpdo->getCacheManager();
$this->xpdo->cacheManager->delete('discuss/thread/' . $this->get('id'));
$this->xpdo->cacheManager->delete('discuss/board/' . $newBoard->get('id'));
$this->xpdo->cacheManager->delete('discuss/board/' . $oldBoard->get('id'));
}
}
return true;
}
示例4: updateChildrenURIs
/**
* Update all Articles URIs to reflect the new blog alias
*
* @param string $newAlias
* @param string $oldAlias
* @return bool
*/
public function updateChildrenURIs($newAlias, $oldAlias)
{
$useMultiByte = $this->getOption('use_multibyte', null, false) && function_exists('mb_strlen');
$encoding = $this->getOption('modx_charset', null, 'UTF-8');
$oldAliasLength = ($useMultiByte ? mb_strlen($oldAlias, $encoding) : strlen($oldAlias)) + 1;
$uriField = $this->xpdo->escape('uri');
$sql = 'UPDATE ' . $this->xpdo->getTableName('Article') . '
SET ' . $uriField . ' = CONCAT("' . $newAlias . '",SUBSTRING(' . $uriField . ',' . $oldAliasLength . '))
WHERE
' . $this->xpdo->escape('parent') . ' = ' . $this->get('id') . '
AND SUBSTRING(' . $uriField . ',1,' . $oldAliasLength . ') = "' . $oldAlias . '/"';
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $sql);
$this->xpdo->exec($sql);
return true;
}
示例5: checkForFormCustomizationRules
/**
* Check for any Form Customization rules for this TV
* @param string $value
* @param modResource $resource
* @return mixed
*/
public function checkForFormCustomizationRules($value, &$resource)
{
if ($this->xpdo->request && $this->xpdo->user instanceof modUser) {
if (empty($resource)) {
$resource =& $this->xpdo->resource;
}
if ($this->xpdo->getOption('form_customization_use_all_groups', null, false)) {
$userGroups = $this->xpdo->user->getUserGroups();
} else {
$primaryGroup = $this->xpdo->user->getPrimaryGroup();
if ($primaryGroup) {
$userGroups = array($primaryGroup->get('id'));
}
}
$c = $this->xpdo->newQuery('modActionDom');
$c->innerJoin('modFormCustomizationSet', 'FCSet');
$c->innerJoin('modFormCustomizationProfile', 'Profile', 'FCSet.profile = Profile.id');
$c->leftJoin('modFormCustomizationProfileUserGroup', 'ProfileUserGroup', 'Profile.id = ProfileUserGroup.profile');
$c->leftJoin('modFormCustomizationProfile', 'UGProfile', 'UGProfile.id = ProfileUserGroup.profile');
$ruleFieldName = $this->xpdo->escape('rule');
$c->where(array(array("(modActionDom.{$ruleFieldName} = 'tvDefault'\n OR modActionDom.{$ruleFieldName} = 'tvVisible'\n OR modActionDom.{$ruleFieldName} = 'tvTitle')"), "'tv{$this->get('id')}' IN ({$this->xpdo->escape('modActionDom')}.{$this->xpdo->escape('name')})", 'FCSet.active' => true, 'Profile.active' => true));
if (!empty($userGroups)) {
$c->where(array(array('ProfileUserGroup.usergroup:IN' => $userGroups, array('OR:ProfileUserGroup.usergroup:IS' => null, 'AND:UGProfile.active:=' => true)), 'OR:ProfileUserGroup.usergroup:=' => null), xPDOQuery::SQL_AND, null, 2);
}
if (!empty($this->xpdo->request) && !empty($this->xpdo->request->action)) {
$c->where(array('modActionDom.action' => $this->xpdo->request->action));
}
$c->select($this->xpdo->getSelectColumns('modActionDom', 'modActionDom'));
$c->select(array('FCSet.constraint_class', 'FCSet.constraint_field', 'FCSet.' . $this->xpdo->escape('constraint'), 'FCSet.template'));
$c->sortby('FCSet.template', 'ASC');
$c->sortby('modActionDom.rank', 'ASC');
$domRules = $this->xpdo->getCollection('modActionDom', $c);
/** @var modActionDom $rule */
foreach ($domRules as $rule) {
if (!empty($resource)) {
$template = $rule->get('template');
if (!empty($template) && $template != $resource->get('template')) {
continue;
}
$constraintClass = $rule->get('constraint_class');
if (!empty($constraintClass)) {
if (!$resource instanceof $constraintClass) {
continue;
}
$constraintField = $rule->get('constraint_field');
$constraint = $rule->get('constraint');
if ($resource->get($constraintField) != $constraint) {
continue;
}
}
}
switch ($rule->get('rule')) {
case 'tvVisible':
if ($rule->get('value') == 0) {
$this->set('type', 'hidden');
}
break;
case 'tvDefault':
$v = $rule->get('value');
if (empty($resourceId)) {
$value = $v;
$this->set('value', $v);
}
$this->set('default_text', $v);
break;
case 'tvTitle':
$v = $rule->get('value');
$this->set('caption', $v);
break;
}
}
unset($domRules, $rule, $userGroups, $v, $c);
}
return $value;
}
示例6: clearCache
/**
* Clear the caches of all sources
* @param array $options
* @return void
*/
public function clearCache(array $options = array())
{
/** @var modCacheManager $cacheManager */
$cacheManager = $this->xpdo->getCacheManager();
if (empty($cacheManager)) {
return;
}
$c = $this->xpdo->newQuery('modContext');
$c->select($this->xpdo->escape('key'));
$options[xPDO::OPT_CACHE_KEY] = $this->getOption('cache_media_sources_key', $options, 'media_sources');
$options[xPDO::OPT_CACHE_HANDLER] = $this->getOption('cache_media_sources_handler', $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options));
$options[xPDO::OPT_CACHE_FORMAT] = (int) $this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP));
$options[xPDO::OPT_CACHE_ATTEMPTS] = (int) $this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10));
$options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (int) $this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000));
if ($c->prepare() && $c->stmt->execute()) {
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row && !empty($row['key'])) {
$cacheManager->delete($row['key'] . '/source', $options);
}
}
}
}
示例7: getResource
/**
* Gets a requested resource and all required data.
*
* @param string $method The method, 'id', or 'alias', by which to perform
* the resource lookup.
* @param string|integer $identifier The identifier with which to search.
* @param array $options An array of options for the resource fetching
* @return modResource The requested modResource instance or request
* is forwarded to the error page, or unauthorized page.
*/
public function getResource($method, $identifier, array $options = array())
{
$resource = null;
if ($method == 'alias') {
$resourceId = $this->modx->aliasMap[$identifier];
} else {
$resourceId = $identifier;
}
if (!is_numeric($resourceId)) {
$this->modx->sendErrorPage();
}
$isForward = array_key_exists('forward', $options) && !empty($options['forward']);
$fromCache = false;
$cacheKey = $this->modx->context->get('key') . "/resources/{$resourceId}";
$cachedResource = $this->modx->cacheManager->get($cacheKey, array(xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_resource_key', null, 'resource'), xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_resource_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $this->modx->getOption('cache_resource_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))));
if (is_array($cachedResource) && array_key_exists('resource', $cachedResource) && is_array($cachedResource['resource'])) {
/** @var modResource $resource */
$resource = $this->modx->newObject($cachedResource['resourceClass']);
if ($resource) {
$resource->fromArray($cachedResource['resource'], '', true, true, true);
$resource->_content = $cachedResource['resource']['_content'];
$resource->_isForward = isset($cachedResource['resource']['_isForward']) && !empty($cachedResource['resource']['_isForward']);
if (isset($cachedResource['contentType'])) {
$contentType = $this->modx->newObject('modContentType');
$contentType->fromArray($cachedResource['contentType'], '', true, true, true);
$resource->addOne($contentType, 'ContentType');
}
if (isset($cachedResource['resourceGroups'])) {
$rGroups = array();
foreach ($cachedResource['resourceGroups'] as $rGroupKey => $rGroup) {
$rGroups[$rGroupKey] = $this->modx->newObject('modResourceGroupResource', $rGroup);
}
$resource->addMany($rGroups);
}
if (isset($cachedResource['policyCache'])) {
$resource->setPolicies(array($this->modx->context->get('key') => $cachedResource['policyCache']));
}
if (isset($cachedResource['elementCache'])) {
$this->modx->elementCache = $cachedResource['elementCache'];
}
if (isset($cachedResource['sourceCache'])) {
$this->modx->sourceCache = $cachedResource['sourceCache'];
}
if ($resource->get('_jscripts')) {
$this->modx->jscripts = $this->modx->jscripts + $resource->get('_jscripts');
}
if ($resource->get('_sjscripts')) {
$this->modx->sjscripts = $this->modx->sjscripts + $resource->get('_sjscripts');
}
if ($resource->get('_loadedjscripts')) {
$this->modx->loadedjscripts = array_merge($this->modx->loadedjscripts, $resource->get('_loadedjscripts'));
}
$isForward = $resource->_isForward;
$resource->setProcessed(true);
$fromCache = true;
}
}
if (!$fromCache || !is_object($resource)) {
$criteria = $this->modx->newQuery('modResource');
$criteria->select(array($this->modx->escape('modResource') . '.*'));
$criteria->where(array('id' => $resourceId, 'deleted' => '0'));
if (!$this->modx->hasPermission('view_unpublished') || $this->modx->getSessionState() !== modX::SESSION_STATE_INITIALIZED) {
$criteria->where(array('published' => 1));
}
if ($resource = $this->modx->getObject('modResource', $criteria)) {
if ($resource instanceof modResource) {
if ($resource->get('context_key') !== $this->modx->context->get('key')) {
if (!$isForward || $isForward && !$this->modx->getOption('allow_forward_across_contexts', $options, false)) {
if (!$this->modx->getCount('modContextResource', array($this->modx->context->get('key'), $resourceId))) {
return null;
}
}
}
$resource->_isForward = $isForward;
if (!$resource->checkPolicy('view')) {
$this->modx->sendUnauthorizedPage();
}
if ($tvs = $resource->getMany('TemplateVars', 'all')) {
/** @var modTemplateVar $tv */
foreach ($tvs as $tv) {
$resource->set($tv->get('name'), array($tv->get('name'), $tv->getValue($resource->get('id')), $tv->get('display'), $tv->get('display_params'), $tv->get('type')));
}
}
$this->modx->resourceGenerated = true;
}
}
} elseif ($fromCache && $resource instanceof modResource && !$resource->get('deleted')) {
if ($resource->checkPolicy('load') && ($resource->get('published') || $this->modx->getSessionState() === modX::SESSION_STATE_INITIALIZED && $this->modx->hasPermission('view_unpublished'))) {
if ($resource->get('context_key') !== $this->modx->context->get('key')) {
if (!$isForward || $isForward && !$this->modx->getOption('allow_forward_across_contexts', $options, false)) {
//.........这里部分代码省略.........
示例8: array
$object = array();
$attributes = array('vehicle_package' => 'vapor', 'vehicle_class' => 'vaporVehicle');
/* remove modx table_prefix if table starts with it */
$extraTableName = $extraTable;
if (!empty($modxTablePrefix) && strpos($extraTableName, $modxTablePrefix) === 0) {
$extraTableName = substr($extraTableName, strlen($modxTablePrefix));
$addTablePrefix = true;
} elseif (!empty($modxTablePrefix) || in_array($extraTableName, $excludeExtraTablePrefix)) {
$addTablePrefix = false;
} else {
$addTablePrefix = true;
}
$object['tableName'] = $extraTableName;
$modx->log(modX::LOG_LEVEL_INFO, "Extracting non-core table {$extraTableName}");
/* generate the CREATE TABLE statement */
$stmt = $modx->query("SHOW CREATE TABLE {$modx->escape($extraTable)}");
$resultSet = $stmt->fetch(PDO::FETCH_NUM);
$stmt->closeCursor();
if (isset($resultSet[1])) {
if ($addTablePrefix) {
$object['drop'] = "DROP TABLE IF EXISTS {$modx->escape('[[++table_prefix]]' . $extraTableName)}";
$object['table'] = str_replace("CREATE TABLE {$modx->escape($extraTable)}", "CREATE TABLE {$modx->escape('[[++table_prefix]]' . $extraTableName)}", $resultSet[1]);
} else {
$object['drop'] = "DROP TABLE IF EXISTS {$modx->escape($extraTableName)}";
$object['table'] = $resultSet[1];
}
/* collect the rows and generate INSERT statements */
$object['data'] = array();
$stmt = $modx->query("SELECT * FROM {$modx->escape($extraTable)}");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($instances === 0) {
示例9: getAliasPath
/**
* Get the Resource's full alias path.
*
* @param string $alias Optional. The alias to check. If not set, will
* then build it from the pagetitle if automatic_alias is set to true.
* @param array $fields Optional. An array of field values to use instead of
* using the current modResource fields.
* @return string
*/
public function getAliasPath($alias = '', array $fields = array())
{
if (empty($fields)) {
$fields = $this->toArray();
}
$workingContext = $this->xpdo->getContext($fields['context_key']);
if (empty($fields['uri_override']) || empty($fields['uri'])) {
/* auto assign alias if using automatic_alias */
if (empty($alias) && $workingContext->getOption('automatic_alias', false)) {
$alias = $this->cleanAlias($fields['pagetitle']);
} elseif (empty($alias) && isset($fields['id']) && !empty($fields['id'])) {
$alias = $this->cleanAlias($fields['id']);
} else {
$alias = $this->cleanAlias($alias);
}
$fullAlias = $alias;
$isHtml = true;
$extension = '';
$containerSuffix = $workingContext->getOption('container_suffix', '');
/* @var modContentType $contentType process content type */
if (!empty($fields['content_type']) && ($contentType = $this->xpdo->getObject('modContentType', $fields['content_type']))) {
$extension = $contentType->getExtension();
$isHtml = strpos($contentType->get('mime_type'), 'html') !== false;
}
/* set extension to container suffix if Resource is a folder, HTML content type, and the container suffix is set */
if (!empty($fields['isfolder']) && $isHtml && !empty($containerSuffix)) {
$extension = $containerSuffix;
}
$aliasPath = '';
/* if using full alias paths, calculate here */
if ($workingContext->getOption('use_alias_path', false)) {
$pathParentId = $fields['parent'];
$parentResources = array();
$query = $this->xpdo->newQuery('modResource');
$query->select($this->xpdo->getSelectColumns('modResource', '', '', array('parent', 'alias')));
$query->where("{$this->xpdo->escape('id')} = ?");
$query->prepare();
$query->stmt->execute(array($pathParentId));
$currResource = $query->stmt->fetch(PDO::FETCH_ASSOC);
while ($currResource) {
$parentAlias = $currResource['alias'];
if (empty($parentAlias)) {
$parentAlias = "{$pathParentId}";
}
$parentResources[] = "{$parentAlias}";
$pathParentId = $currResource['parent'];
$query->stmt->execute(array($pathParentId));
$currResource = $query->stmt->fetch(PDO::FETCH_ASSOC);
}
$aliasPath = !empty($parentResources) ? implode('/', array_reverse($parentResources)) : '';
if (strlen($aliasPath) > 0 && $aliasPath[strlen($aliasPath) - 1] !== '/') {
$aliasPath .= '/';
}
}
$fullAlias = $aliasPath . $fullAlias . $extension;
} else {
$fullAlias = $fields['uri'];
}
return $fullAlias;
}
示例10: countUnansweredQuestions
/**
* Get the number of unanswered questions.
* @return int
*/
public function countUnansweredQuestions()
{
$response = $this->xpdo->call('disThread', 'fetchUnansweredQuestions', array(&$this->xpdo, "{$this->xpdo->escape('disThread')}.{$this->xpdo->escape('post_last_on')}", 'DESC', 10, 0, false, true));
return number_format($response['total']);
}
示例11: previousVersionInstalled
/**
* Indicates if a previous version of the package is installed.
*
* @return boolean True if a previous version of the package is installed.
*/
public function previousVersionInstalled()
{
$this->parseSignature();
$count = $this->xpdo->getCount('transport.modTransportPackage', array(array("UCASE({$this->xpdo->escape('package_name')}) LIKE UCASE({$this->xpdo->quote($this->identifier)})"), 'installed:IS NOT' => null, 'signature:!=' => $this->get('signature')));
return $count > 0;
}
示例12: modX
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
//get resourse context_key
$context_key = 'web';
$query = $modx->newQuery('modResource', array('id' => $resource_id, 'published' => true, 'deleted' => false));
$query->select($modx->getSelectColumns('modResource', '', '', array('context_key')));
$stmt = $query->prepare();
if ($stmt) {
if ($value = $modx->getValue($stmt)) {
$context_key = $value;
}
}
$modx->initialize($context_key);
//get resource
$criteria = $modx->newQuery('modResource');
$criteria->select(array($modx->escape('modResource') . '.*'));
$criteria->where(array('id' => $resource_id, 'deleted' => false, 'published' => true));
$modx->resource = $modx->getObject('modResource', $criteria);
if (!is_object($modx->resource) || !$modx->resource->checkPolicy('view')) {
echo json_encode($output);
exit;
}
$modx->resourceIdentifier = $modx->resource->get('id');
$modx->getService('error', 'error.modError');
$modx->getRequest();
$modx->getParser();
$modx->resourceMethod = 'id';
$modx->resource->_contextKey = $modx->context->get('key');
$modx->invokeEvent('OnLoadWebDocument');
require_once MODX_CORE_PATH . "components/tag_manager2/model/tm_base.class.php";
$tag_manager = new tagManagerBase($modx);
示例13: process
//.........这里部分代码省略.........
}
if ($coreTables) {
$stmt = $modx->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '{$modxDatabase}' AND TABLE_NAME NOT IN (" . implode(',', $coreTables) . ")");
$extraTables = $stmt->fetchAll(PDO::FETCH_COLUMN);
}
if (is_array($extraTables) && !empty($extraTables)) {
//$modx->loadClass('vapor.vaporVehicle', VAPOR_DIR . 'model/', true, true);
$modx->loadClass('vapor.vaporVehicle', VAPOR_DIR, true, true);
$excludeExtraTablePrefix = isset($vaporOptions['excludeExtraTablePrefix']) && is_array($vaporOptions['excludeExtraTablePrefix']) ? $vaporOptions['excludeExtraTablePrefix'] : array();
$excludeExtraTables = isset($vaporOptions['excludeExtraTables']) && is_array($vaporOptions['excludeExtraTables']) ? $vaporOptions['excludeExtraTables'] : array();
foreach ($extraTables as $extraTable) {
if (in_array($extraTable, $excludeExtraTables)) {
continue;
}
if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
set_time_limit(0);
}
$instances = 0;
$object = array();
$attributes = array('vehicle_package' => 'vapor', 'vehicle_class' => 'vaporVehicle');
/* remove modx table_prefix if table starts with it */
$extraTableName = $extraTable;
if (!empty($modxTablePrefix) && strpos($extraTableName, $modxTablePrefix) === 0) {
$extraTableName = substr($extraTableName, strlen($modxTablePrefix));
$addTablePrefix = true;
} elseif (!empty($modxTablePrefix) || in_array($extraTableName, $excludeExtraTablePrefix)) {
$addTablePrefix = false;
} else {
$addTablePrefix = true;
}
$object['tableName'] = $extraTableName;
$modx->log(modX::LOG_LEVEL_INFO, "Extracting non-core table {$extraTableName}");
/* generate the CREATE TABLE statement */
$stmt = $modx->query("SHOW CREATE TABLE {$modx->escape($extraTable)}");
$resultSet = $stmt->fetch(PDO::FETCH_NUM);
$stmt->closeCursor();
if (isset($resultSet[1])) {
if ($addTablePrefix) {
$object['drop'] = "DROP TABLE IF EXISTS {$modx->escape('[[++table_prefix]]' . $extraTableName)}";
$object['table'] = str_replace("CREATE TABLE {$modx->escape($extraTable)}", "CREATE TABLE {$modx->escape('[[++table_prefix]]' . $extraTableName)}", $resultSet[1]);
} else {
$object['drop'] = "DROP TABLE IF EXISTS {$modx->escape($extraTableName)}";
$object['table'] = $resultSet[1];
}
/* collect the rows and generate INSERT statements */
$object['data'] = array();
$stmt = $modx->query("SELECT * FROM {$modx->escape($extraTable)}");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($instances === 0) {
$fields = implode(', ', array_map(array($modx, 'escape'), array_keys($row)));
}
$values = array();
while (list($key, $value) = each($row)) {
switch (gettype($value)) {
case 'string':
$values[] = $modx->quote($value);
break;
case 'NULL':
case 'array':
case 'object':
case 'resource':
case 'unknown type':
$values[] = 'NULL';
break;
default:
$values[] = (string) $value;