/** * Abstract method for routing GET requests without a primary key passed. Must be defined in your derivative * controller. Handles fetching of collections of objects. * * @abstract * @return array */ public function getList() { $this->getProperties(); $c = $this->modx->newQuery($this->classKey); $c = $this->addSearchQuery($c); $c = $this->prepareListQueryBeforeCount($c); $total = $this->modx->getCount($this->classKey, $c); $alias = !empty($this->classAlias) ? $this->classAlias : $this->classKey; $c->select($this->modx->getSelectColumns($this->classKey, $alias)); $c = $this->prepareListQueryAfterCount($c); $c->sortby($this->getProperty($this->getOption('propertySort', 'sort'), $this->defaultSortField), $this->getProperty($this->getOption('propertySortDir', 'dir'), $this->defaultSortDirection)); $limit = $this->getProperty($this->getOption('propertyLimit', 'limit'), $this->defaultLimit); if (empty($limit)) { $limit = $this->defaultLimit; } $c->limit($limit, $this->getProperty($this->getOption('propertyOffset', 'start'), $this->defaultOffset)); $objects = $this->modx->getCollection($this->classKey, $c); if (empty($objects)) { $objects = array(); } $list = array(); /** @var xPDOObject $object */ foreach ($objects as $object) { $list[] = $this->prepareListObject($object); } return $this->collection($list, $total); }
function getStats() { $output = ''; $q_status = $this->modx->newQuery('msOrderStatus', array('active' => 1)); $q_status->select('id,name,color'); if ($q_status->prepare() && $q_status->stmt->execute()) { while ($row = $q_status->stmt->fetch(PDO::FETCH_ASSOC)) { //$output[$row['id']] = $row; $output['total_counts'][$row['id']] = array('name' => $row['name'], 'color' => $row['color'], 'count_orders' => $this->modx->getCount('msOrder', array('status' => $row['id']))); } } $q_stats_month = $this->modx->newQuery('msOrder'); $q_stats_month->select('status,`createdon`, month(`createdon`) AS `order_month`, count(*) AS `order_count`, SUM(cart_cost) AS order_cost'); $q_stats_month->groupby('month(`createdon`), status'); $q_stats_month->sortby('createdon', ASC); if ($q_stats_month->prepare() && $q_stats_month->stmt->execute()) { $output['cart_cost'] = 0; $output['cart_count'] = 0; while ($row = $q_stats_month->stmt->fetch(PDO::FETCH_ASSOC)) { $date = date_parse($row['createdon']); $output['stats_month'][$date['year'] . '-' . $date['month']][$row['status']] = array('total_cost' => $row['order_cost'], 'count_orders' => $row['order_count'], 'status' => $row['status']); $output['cart_cost'] += $row['order_cost']; $output['cart_count'] += $row['order_count']; } $output['cart_cost'] = number_format($output['cart_cost'], 2, ',', ' '); $output['users_count'] = $this->modx->getCount('modUser', array('active' => 1, 'primary_group' => 0)); } return $output; }
/** * 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); }
/** * Get the statistics for the bottom area of the forums * @return void */ protected function getStatistics() { $this->setPlaceholder('totalPosts', number_format((int) $this->getPostCount())); $this->setPlaceholder('totalTopics', number_format((int) $this->getThreadCount())); $this->setPlaceholder('totalMembers', number_format((int) $this->modx->getCount('disUser'))); /* active in last 40 */ if ($this->modx->getOption('discuss.show_whos_online', null, true)) { $this->setPlaceholder('activeUsers', $this->discuss->hooks->load('user/active_in_last')); } else { $this->setPlaceholder('activeUsers', ''); } /* total active */ $this->setPlaceholder('totalMembersActive', number_format((int) $this->modx->getCount('disSession', array('user:!=' => 0)))); $this->setPlaceholder('totalVisitorsActive', number_format((int) $this->modx->getCount('disSession', array('user' => 0)))); /** * forum activity * @var disForumActivity $activity */ $activity = $this->modx->getObject('disForumActivity', array('day' => date('Y-m-d'))); if (!$activity) { $activity = $this->modx->newObject('disForumActivity'); $activity->set('day', date('Y-m-d')); $activity->save(); } $this->setPlaceholders($activity->toArray('activity.')); }
/** * Grab settings (from cache if possible) as key => value pairs. * @return array|mixed */ public function getSettings() { /* Attempt to get from cache */ $cacheOptions = array(xPDO::OPT_CACHE_KEY => 'system_settings'); $settings = $this->modx->getCacheManager()->get('clientconfig', $cacheOptions); if (empty($settings) && $this->modx->getCount('cgSetting') > 0) { $collection = $this->modx->getCollection('cgSetting'); $settings = array(); /* @var cgSetting $setting */ foreach ($collection as $setting) { $settings[$setting->get('key')] = $setting->get('value'); } /* Write to cache again */ $this->modx->cacheManager->set('clientconfig', $settings, 0, $cacheOptions); } return is_array($settings) ? $settings : array(); }
/** * Recursive template of branch of menu * * @param array $row * * @return mixed|string */ public function templateBranch($row = array()) { $children = ''; $row['level'] = $this->level; if (!empty($row['children']) && ($this->isHere($row['id']) || empty($this->pdoTools->config['hideSubMenus'])) && $this->checkResource($row['id'])) { $idx = 1; $this->level++; $count = count($row['children']); foreach ($row['children'] as $v) { $v['idx'] = $idx++; $v['last'] = (int) $v['idx'] == $count; $children .= $this->templateBranch($v); } $this->level--; $row['children'] = $count; } else { $row['children'] = isset($row['children']) ? count($row['children']) : 0; } if (!empty($this->pdoTools->config['countChildren'])) { if ($ids = $this->modx->getChildIds($row['id'])) { $tstart = microtime(true); $count = $this->modx->getCount('modResource', array('id:IN' => $ids, 'published' => true, 'deleted' => false)); $this->modx->queryTime += microtime(true) - $tstart; $this->modx->executedQueries++; $this->pdoTools->addTime('Got the number of active children for resource "' . $row['id'] . '": ' . $count); } else { $count = 0; } $row['children'] = $count; } if (!empty($children)) { $pls = $this->addWayFinderPlaceholders(array('wrapper' => $children, 'classes' => ' class="' . $this->pdoTools->config['innerClass'] . '"', 'classNames' => $this->pdoTools->config['innerClass'], 'classnames' => $this->pdoTools->config['innerClass'], 'level' => $this->level)); $row['wrapper'] = $this->pdoTools->parseChunk($this->pdoTools->config['tplInner'], $pls); } else { $row['wrapper'] = ''; } if (empty($row['menutitle']) && !empty($row['pagetitle'])) { $row['menutitle'] = $row['pagetitle']; } $classes = $this->getClasses($row); if (!empty($classes)) { $row['classNames'] = $row['classnames'] = $classes; $row['classes'] = ' class="' . $classes . '"'; } else { $row['classNames'] = $row['classnames'] = $row['classes'] = ''; } if (!empty($this->pdoTools->config['useWeblinkUrl']) && $row['class_key'] == 'modWebLink') { $row['link'] = is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), '', '', $this->pdoTools->config['scheme']) : $row['content']; } else { $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->pdoTools->config['scheme']); } $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : ''; $tpl = $this->getTpl($row); $row = $this->addWayFinderPlaceholders($row); return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']); }
/** * Check if a user (by id) has a subscription to this thread * * @param int $userId ID of disUser * @return bool True if has a subscription */ public function hasSubscription($userId = 0) { if (!isset($this->hasSubscription)) { if (empty($userId)) { $userId = $this->xpdo->discuss->user->get('id'); } $this->hasSubscription = $this->xpdo->getCount('disUserNotification', array('user' => $userId, 'thread' => $this->get('id'))) > 0; } return $this->hasSubscription; }
/** * Gets a count of {@link modUserMessage} objects ascribed to the user. * * @access public * @param mixed $read * @return integer The number of messages. */ public function countMessages($read = '') { if ($read == 'read') { $read = 1; } elseif ($read == 'unread') { $read = 0; } $criteria = array('recipient' => $this->get('id')); if ($read) { $criteria['messageread'] = $read; } return $this->xpdo->getCount('modUserMessage', $criteria); }
/** * @param sTaskRun $run * @return mixed */ public function _run(&$run) { $snippet = $this->get('content'); $scriptProperties = (array) $run->get('data'); $scriptProperties['task'] =& $this; $scriptProperties['run'] =& $run; // Check if the snippet exists before running it. // This may fail with OnElementNotFound snippets in 2.3 $key = !empty($snippet) && is_numeric($snippet) ? 'id' : 'name'; if ($this->xpdo->getCount('modSnippet', array($key => $snippet)) < 1) { $run->addError('snippet_not_found', array('snippet' => $snippet)); return false; } /** @var modSnippet $snippet */ $snippet = $this->xpdo->getObject('modSnippet', array($key => $snippet)); if (empty($snippet) || !is_object($snippet)) { $run->addError('snippet_not_found', array('snippet' => $snippet)); return false; } $snippet->setCacheable(false); $out = $snippet->process($scriptProperties); unset($scriptProperties, $snippet); return $out; }
public function checkDependencies() { $failed = array(); foreach ($this->dependencies as $dependency) { $found = $this->modx->getCount('transport.modTransportPackage', array('package_name' => $dependency['name'])); $foundInGPM = $this->modx->getCount('GitPackage', array('name' => $dependency['name'], 'OR:dir_name:=' => $dependency['name'])); if ($found == 0 && $foundInGPM == 0) { $failed[] = $dependency['name']; } } if (count($failed) == 0) { return true; } return $failed; }
/** * Check resource have conversations * * @param integer $id Resource ID * * @access private * @return boolean True if resource have a conversation */ private function _hasConversations($id) { if (!intval($id)) { return false; } /** * Checking through the map so the cache */ if ($map = $this->conversationsMap()) { /** * If the resource contains at least one topic return true */ if (array_key_exists($id, $map)) { return true; } return false; } elseif ($this->modx->getCount('modxTalksConversation', array('rid' => $id))) { /** * If the conversationsMap () returned false (with the cache enabled), on-base */ return true; } return false; }
public static function listPackageVersions(modX &$modx, $criteria, $limit = 0, $offset = 0) { $result = array('collection' => array(), 'total' => 0); $c = $modx->newQuery('transport.modTransportPackage'); $c->select($modx->getSelectColumns('transport.modTransportPackage','modTransportPackage')); $c->select(array('Provider.name AS provider_name')); $c->leftJoin('transport.modTransportProvider','Provider'); $c->where($criteria); $result['total'] = $modx->getCount('modTransportPackage',$c); $c->sortby('modTransportPackage.version_major', 'DESC'); $c->sortby('modTransportPackage.version_minor', 'DESC'); $c->sortby('modTransportPackage.version_patch', 'DESC'); $c->sortby('IF(modTransportPackage.release = "" OR modTransportPackage.release = "ga" OR modTransportPackage.release = "pl","z",modTransportPackage.release) DESC',''); $c->sortby('modTransportPackage.release_index', 'DESC'); if((int)$limit > 0) { $c->limit((int)$limit, (int)$offset); } $result['collection'] = $modx->getCollection('transport.modTransportPackage',$c); return $result; }
public function alreadyExists($name) { return $this->modx->getCount('modUser', array('username' => $name, 'id:!=' => $this->user->get('id'))) > 0; }
public static function getList(modX &$modx, array $scriptProperties = array()) { $sort = $modx->getOption('sort', $scriptProperties, 'rank'); $cacheKey = 'gallery/item/list/' . md5(serialize($scriptProperties)); if ($modx->getCacheManager() && ($cache = $modx->cacheManager->get($cacheKey))) { $items = array(); foreach ($cache['items'] as $data) { /** @var galItem $item */ $item = $modx->newObject('galItem'); $item->fromArray($data, '', true, true); $items[] = $item; } if (in_array(strtolower($sort), array('random', 'rand()', 'rand'))) { shuffle($items); } $data = array('items' => $items, 'total' => $cache['total'], 'album' => $cache['album']); } else { $album = $modx->getOption('album', $scriptProperties, false); $tag = $modx->getOption('tag', $scriptProperties, ''); $limit = $modx->getOption('limit', $scriptProperties, 0); $start = $modx->getOption('start', $scriptProperties, 0); /* Fix to make it work with getPage which uses "offset" instead of "start" */ $offset = $modx->getOption('offset', $scriptProperties, 0); if ($offset > 0) { $start = $offset; } $sortAlias = $modx->getOption('sortAlias', $scriptProperties, 'galItem'); if ($sort == 'rank') { $sortAlias = 'AlbumItems'; } $dir = $modx->getOption('dir', $scriptProperties, 'ASC'); $showInactive = $modx->getOption('showInactive', $scriptProperties, false); $activeAlbum = array('id' => '', 'name' => '', 'description' => ''); $tagc = $modx->newQuery('galTag'); $tagc->setClassAlias('TagsJoin'); $tagc->select('GROUP_CONCAT(' . $modx->getSelectColumns('galTag', 'TagsJoin', '', array('tag')) . ')'); $tagc->where($modx->getSelectColumns('galTag', 'TagsJoin', '', array('item')) . ' = ' . $modx->getSelectColumns('galItem', 'galItem', '', array('id'))); $tagc->prepare(); $tagSql = $tagc->toSql(); $c = $modx->newQuery('galItem'); $c->innerJoin('galAlbumItem', 'AlbumItems'); $c->innerJoin('galAlbum', 'Album', $modx->getSelectColumns('galAlbumItem', 'AlbumItems', '', array('album')) . ' = ' . $modx->getSelectColumns('galAlbum', 'Album', '', array('id'))); /* pull by album */ if (!empty($album)) { $albumField = is_numeric($album) ? 'id' : 'name'; $albumWhere = $albumField == 'name' ? array('name' => $album) : $album; /** @var galAlbum $album */ $album = $modx->getObject('galAlbum', $albumWhere); if (empty($album)) { return ''; } $c->where(array('Album.' . $albumField => $album->get($albumField))); $activeAlbum['id'] = $album->get('id'); $activeAlbum['name'] = $album->get('name'); $activeAlbum['description'] = $album->get('description'); $activeAlbum['year'] = $album->get('year'); unset($albumWhere, $albumField); } if (!empty($tag)) { /* pull by tag */ $c->innerJoin('galTag', 'Tags'); $c->where(array('Tags.tag' => $tag)); if (empty($album)) { $activeAlbum['id'] = 0; $activeAlbum['name'] = $tag; $activeAlbum['description'] = ''; } } $c->where(array('galItem.mediatype' => $modx->getOption('mediatype', $scriptProperties, 'image'))); if (!$showInactive) { $c->where(array('galItem.active' => true)); } $count = $modx->getCount('galItem', $c); $c->select($modx->getSelectColumns('galItem', 'galItem')); $c->select(array('(' . $tagSql . ') AS tags')); if (in_array(strtolower($sort), array('random', 'rand()', 'rand'))) { $c->sortby('RAND()', $dir); } else { $c->sortby($sortAlias . '.' . $sort, $dir); } if (!empty($limit)) { $c->limit($limit, $start); } $items = $modx->getCollection('galItem', $c); $data = array('items' => $items, 'total' => $count, 'album' => $activeAlbum); $cache = array('items' => array(), 'total' => $count, 'album' => $activeAlbum); /** @var galItem $item */ foreach ($items as $item) { $cache['items'][] = $item->toArray('', true); } $modx->cacheManager->set($cacheKey, $cache); } return $data; }
/** * 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)) { if (!$this->modx->getCount('modContextResource', array($this->modx->context->get('key'), $resourceId))) { return null; } } } if (!$resource->checkPolicy('view')) { $this->modx->sendUnauthorizedPage(); } } else { return null; } $this->modx->invokeEvent('OnLoadWebPageCache'); } return $resource; }
$modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); /* load Discuss */ $discuss = $modx->getService('discuss', 'Discuss', $modx->getOption('discuss.core_path', null, $modx->getOption('core_path') . 'components/discuss/') . 'model/discuss/'); if (!$discuss instanceof Discuss) { return ''; } /* setup mem limits */ ini_set('memory_limit', '1024M'); set_time_limit(0); @ob_end_clean(); echo '<pre>'; /* load and run importer */ if ($discuss->loadImporter('disSmfImport')) { $c = $modx->newQuery('disPost'); $total = $modx->getCount('disPost', $c); $c->sortby('thread', 'DESC'); $posts = $modx->getIterator('disPost', $c); $discuss->import->log('Found ' . $total . ' threads: ' . $total); /** @var disThread $thread */ $thread = null; /** @var disPost $post */ foreach ($posts as $post) { if (!$thread || $post->get('thread') != $thread->get('id')) { $thread = $post->getOne('Thread'); } if ($thread) { $thread->addParticipant($post->get('author')); $discuss->import->log('Fixing participants for: ' . $thread->get('title')); } }
/** * @param modManagerController $controller * @param modResource $resource */ public function loadManagerFiles(modManagerController $controller, modResource $resource) { $modx23 = (int) $this->systemVersion(); $cssUrl = $this->config['cssUrl'] . 'mgr/'; $jsUrl = $this->config['jsUrl'] . 'mgr/'; $properties = $resource->getProperties('ms2gallery'); if (empty($properties['media_source'])) { if (!($source_id = $resource->getTVValue('ms2Gallery'))) { /** @var modContextSetting $setting */ $setting = $this->modx->getObject('modContextSetting', array('key' => 'ms2gallery_source_default', 'context_key' => $resource->get('context_key'))); $source_id = !empty($setting) ? $setting->get('value') : $this->modx->getOption('ms2gallery_source_default'); } $resource->setProperties(array('media_source' => $source_id), 'ms2gallery'); $resource->save(); } else { $source_id = $properties['media_source']; } if (empty($source_id)) { $source_id = $this->modx->getOption('ms2gallery_source_default'); } $resource->set('media_source', $source_id); $controller->addLexiconTopic('ms2gallery:default'); $controller->addJavascript($jsUrl . 'ms2gallery.js'); $controller->addLastJavascript($jsUrl . 'misc/ms2.combo.js'); $controller->addLastJavascript($jsUrl . 'misc/ms2.utils.js'); $controller->addLastJavascript($jsUrl . 'misc/plupload/plupload.full.js'); $controller->addLastJavascript($jsUrl . 'misc/ext.ddview.js'); $controller->addLastJavascript($jsUrl . 'gallery.view.js'); $controller->addLastJavascript($jsUrl . 'gallery.window.js'); $controller->addLastJavascript($jsUrl . 'gallery.toolbar.js'); $controller->addLastJavascript($jsUrl . 'gallery.panel.js'); $controller->addCss($cssUrl . 'main.css'); if (!$modx23) { $controller->addCss($cssUrl . 'font-awesome.min.css'); } $source_config = array(); /** @var modMediaSource $source */ if ($source = $this->modx->getObject('modMediaSource', $source_id)) { $tmp = $source->getProperties(); foreach ($tmp as $v) { $source_config[$v['name']] = $v['value']; } } $controller->addHtml(' <script type="text/javascript"> MODx.modx23 = ' . $modx23 . '; ms2Gallery.config = ' . $this->modx->toJSON($this->config) . '; ms2Gallery.config.media_source = ' . $this->modx->toJSON($source_config) . '; </script>'); if ($this->modx->getOption('ms2gallery_new_tab_mode', null, true)) { $controller->addLastJavascript($jsUrl . 'tab.js'); } else { $insert = ' tabs.add({ xtype: "ms2gallery-page", id: "ms2gallery-page", title: _("ms2gallery"), record: { id: ' . $resource->get('id') . ', source: ' . $source_id . ', } }); '; if ($this->modx->getCount('modPlugin', array('name' => 'AjaxManager', 'disabled' => false))) { $controller->addHtml(' <script type="text/javascript"> Ext.onReady(function() { window.setTimeout(function() { var tabs = Ext.getCmp("modx-resource-tabs"); if (tabs) { ' . $insert . ' } }, 10); }); </script>'); } else { $controller->addHtml(' <script type="text/javascript"> Ext.ComponentMgr.onAvailable("modx-resource-tabs", function() { var tabs = this; tabs.on("beforerender", function() { ' . $insert . ' }); }); </script>'); } } }
/** * Checks accordance of payment and delivery * * @param $delivery * @param $payment * * @return bool */ public function hasPayment($delivery, $payment) { $q = $this->modx->newQuery('msPayment', array('id' => $payment, 'active' => 1)); $q->innerJoin('msDeliveryMember', 'Member', 'Member.payment_id = msPayment.id AND Member.delivery_id = ' . $delivery); return $this->modx->getCount('msPayment', $q) ? true : false; }
/** * Duplicate the Resource. * * @param array $options An array of options. * @return mixed Returns either an error message, or the newly created modResource object. */ public function duplicate(array $options = array()) { if (!$this->xpdo instanceof modX) { return false; } /* duplicate resource */ $prefixDuplicate = !empty($options['prefixDuplicate']) ? true : false; $newName = !empty($options['newName']) ? $options['newName'] : ($prefixDuplicate ? $this->xpdo->lexicon('duplicate_of', array('name' => $this->get('pagetitle'))) : $this->get('pagetitle')); /** @var modResource $newResource */ $newResource = $this->xpdo->newObject($this->get('class_key')); $newResource->fromArray($this->toArray('', true), '', false, true); $newResource->set('pagetitle', $newName); /* do published status preserving */ $publishedMode = $this->getOption('publishedMode', $options, 'preserve'); switch ($publishedMode) { case 'unpublish': $newResource->set('published', false); $newResource->set('publishedon', 0); $newResource->set('publishedby', 0); break; case 'publish': $newResource->set('published', true); $newResource->set('publishedon', time()); $newResource->set('publishedby', $this->xpdo->user->get('id')); break; case 'preserve': default: $newResource->set('published', $this->get('published')); $newResource->set('publishedon', $this->get('publishedon')); $newResource->set('publishedby', $this->get('publishedby')); break; } /* allow overrides for every item */ if (!empty($options['overrides']) && is_array($options['overrides'])) { $newResource->fromArray($options['overrides']); } $newResource->set('id', 0); /* make sure children get assigned to new parent */ $newResource->set('parent', isset($options['parent']) ? $options['parent'] : $this->get('parent')); $newResource->set('createdby', $this->xpdo->user->get('id')); $newResource->set('createdon', time()); $newResource->set('editedby', 0); $newResource->set('editedon', 0); /* get new alias */ $preserve_alias = $this->xpdo->getOption('preserve_alias', $options, false); $alias = $newResource->cleanAlias($newName); if ($this->xpdo->getOption('friendly_urls', $options, false)) { if (!$preserve_alias) { /* auto assign alias */ $aliasPath = $newResource->getAliasPath($newName); $dupeContext = $this->xpdo->getOption('global_duplicate_uri_check', $options, false) ? '' : $newResource->get('context_key'); if ($newResource->isDuplicateAlias($aliasPath, $dupeContext)) { $alias = ''; if ($newResource->get('uri_override')) { $newResource->set('uri_override', false); } } $newResource->set('alias', $alias); } } $preserve_menuindex = $this->xpdo->getOption('preserve_menuindex', $options, false); /* set new menuindex */ if (!$preserve_menuindex) { $menuindex = $this->xpdo->getCount('modResource', array('parent' => $this->get('parent'))); $newResource->set('menuindex', $menuindex); } /* save resource */ if (!$newResource->save()) { return $this->xpdo->lexicon('resource_err_duplicate'); } $tvds = $this->getMany('TemplateVarResources'); /** @var modTemplateVarResource $oldTemplateVarResource */ foreach ($tvds as $oldTemplateVarResource) { /** @var modTemplateVarResource $newTemplateVarResource */ $newTemplateVarResource = $this->xpdo->newObject('modTemplateVarResource'); $newTemplateVarResource->set('contentid', $newResource->get('id')); $newTemplateVarResource->set('tmplvarid', $oldTemplateVarResource->get('tmplvarid')); $newTemplateVarResource->set('value', $oldTemplateVarResource->get('value')); $newTemplateVarResource->save(); } $groups = $this->getMany('ResourceGroupResources'); /** @var modResourceGroupResource $oldResourceGroupResource */ foreach ($groups as $oldResourceGroupResource) { /** @var modResourceGroupResource $newResourceGroupResource */ $newResourceGroupResource = $this->xpdo->newObject('modResourceGroupResource'); $newResourceGroupResource->set('document_group', $oldResourceGroupResource->get('document_group')); $newResourceGroupResource->set('document', $newResource->get('id')); $newResourceGroupResource->save(); } /* duplicate resource, recursively */ $duplicateChildren = isset($options['duplicateChildren']) ? $options['duplicateChildren'] : true; if ($duplicateChildren) { if (!$this->checkPolicy('add_children')) { return $newResource; } $children = $this->getMany('Children'); if (is_array($children) && count($children) > 0) { /** @var modResource $child */ foreach ($children as $child) { $child->duplicate(array('duplicateChildren' => true, 'parent' => $newResource->get('id'), 'prefixDuplicate' => $prefixDuplicate, 'overrides' => !empty($options['overrides']) ? $options['overrides'] : false, 'publishedMode' => $publishedMode, 'preserve_alias' => $preserve_alias, 'preserve_menuindex' => $preserve_menuindex)); } } } return $newResource; }
/** * @param string $tpl * * @return bool */ public function templateExists($tpl) { $c = is_numeric($tpl) && $tpl > 0 ? $tpl : array('name' => $tpl); return (bool) $this->modx->getCount('modChunk', $c); }
/** * 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; }
/** * CustomRequest constructor * * @param modX $modx A reference to the modX instance. * @param array $options An array of options. Optional. */ function __construct(modX &$modx, array $options = array()) { $this->modx =& $modx; $this->modx->lexicon->load('customrequest:default'); $corePath = $this->getOption('core_path', $options, $this->modx->getOption('core_path') . 'components/customrequest/'); $assetsPath = $this->getOption('assets_path', $options, $this->modx->getOption('assets_path') . 'components/customrequest/'); $assetsUrl = $this->getOption('assets_url', $options, $this->modx->getOption('assets_url') . 'components/customrequest/'); // Load some default paths for easier management $this->options = array_merge(array('namespace' => $this->namespace, 'assetsPath' => $assetsPath, 'assetsUrl' => $assetsUrl, 'cssUrl' => $assetsUrl . 'css/', 'jsUrl' => $assetsUrl . 'js/', 'imagesUrl' => $assetsUrl . 'images/', 'corePath' => $corePath, 'modelPath' => $corePath . 'model/', 'chunksPath' => $corePath . 'elements/chunks/', 'pagesPath' => $corePath . 'elements/pages/', 'snippetsPath' => $corePath . 'elements/snippets/', 'pluginsPath' => $corePath . 'elements/plugins/', 'processorsPath' => $corePath . 'processors/', 'templatesPath' => $corePath . 'templates/', 'configsPath' => $this->getOption('configsPath', null, $corePath . 'configs/', true), 'cachePath' => $this->modx->getOption('core_path') . 'cache/', 'connectorUrl' => $assetsUrl . 'connector.php'), $options); // Load (system) properties $this->options = array_merge($this->options, array('debug' => $this->getOption('debug', null, false))); $this->modx->addPackage('customrequest', $this->getOption('modelPath')); if (isset($this->options['aliases'])) { $this->requests = $this->modx->fromJson($this->options['aliases'], true); } if (!$this->requests) { $this->requests = array(); } // Import old config files if no configuration is set if (!$this->modx->getCount('CustomrequestConfigs')) { $i = 0; $configFiles = glob($this->getOption('configsPath') . '*.config.inc.php'); // Import old config files foreach ($configFiles as $configFile) { // $settings will be defined in each config file $settings = array(); include $configFile; foreach ($settings as $key => $setting) { // fill urlParams if defined $urlParams = isset($setting['urlParams']) && is_array($setting['urlParams']) ? $setting['urlParams'] : array(); $regEx = isset($setting['regEx']) ? $setting['regEx'] : ''; if (isset($setting['alias'])) { // if alias is defined, calculate the other values if (isset($setting['resourceId'])) { $resourceId = $setting['resourceId']; } elseif ($res = $this->modx->getObject('modResource', array('uri' => $setting['alias']))) { $resourceId = $res->get('id'); } else { // if resourceId could not be calculated, don't use that setting if ($this->getOption('debug')) { $this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the resourceId for the given alias'); } break; } $alias = $setting['alias']; } elseif (isset($setting['resourceId'])) { $resourceId = $setting['resourceId']; if (isset($setting['alias'])) { $alias = $setting['alias']; } else { $alias = ''; } } $config = $this->modx->newObject('CustomrequestConfigs'); $config->fromArray(array('name' => ucfirst($key), 'menuindex' => $i, 'alias' => $alias, 'resourceid' => $resourceId, 'urlparams' => json_encode($urlParams), 'regex' => $regEx)); $config->save(); $i++; } } return; } }
require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('web'); $modx->invokeEvent("OnLoadWebDocument"); define('SHOPKEEPER_PATH', MODX_BASE_PATH . "core/components/shopkeeper3/"); define('SHOPKEEPER_URL', MODX_BASE_URL . "core/components/shopkeeper3/"); $manager_language = $modx->config['manager_language']; $charset = $modx->config['modx_charset']; header("Content-Type: text/html; charset={$charset}"); require_once SHOPKEEPER_PATH . "model/shopkeeper.class.php"; //Определяем параметры сниппета Shopkeeper $sys_property_sets = $modx->getOption('shk3.property_sets', null, 'default'); $sys_property_sets = explode(',', $sys_property_sets); $sys_property_sets = array_map('trim', $sys_property_sets); $propertySerNum = isset($_POST['psn']) && is_numeric($_POST['psn']) ? intval($_POST['psn']) : 1; $propertySetName = isset($sys_property_sets[$propertySerNum - 1]) ? $sys_property_sets[$propertySerNum - 1] : $sys_property_sets[0]; $snippet = $modx->getObject('modSnippet', array('name' => 'Shopkeeper3')); $properties = $snippet->getProperties(); if ($propertySetName != 'default' && $modx->getCount('modPropertySet', array('name' => $propertySetName)) > 0) { $propSet = $modx->getObject('modPropertySet', array('name' => $propertySetName)); $propSetProperties = $propSet->getProperties(); if (is_array($propSetProperties)) { $properties = array_merge($properties, $propSetProperties); } } $shopCart = new Shopkeeper($modx, $properties); $shopCart->config['charset'] = $charset; $cart_html = $shopCart->getCartContent(); $cart_html = $shopCart->stripModxTags($cart_html); $output = array('price_total' => Shopkeeper::$price_total, 'items_total' => Shopkeeper::$items_total, 'items_unique_total' => Shopkeeper::$items_unique_total, 'delivery_price' => !empty($shopCart->delivery['price']) ? $shopCart->delivery['price'] : 0, 'delivery_name' => !empty($shopCart->delivery['label']) ? $shopCart->delivery['label'] : '', 'ids' => $shopCart->getProdIds(), 'html' => $cart_html); echo json_encode($output);
/** * See if a user is a moderator of a board * @param int $boardId * @return bool */ public function isModerator($boardId) { if (!array_key_exists($boardId, $this->moderatorships)) { if ($this->xpdo->discuss->user->isGlobalModerator() || $this->xpdo->discuss->user->isAdmin()) { $isModerator = true; } else { $moderator = $this->xpdo->getCount('disModerator', array('user' => $this->get('id'), 'board' => $boardId)); $isModerator = $moderator > 0; } $this->moderatorships[$boardId] = $isModerator; $this->xpdo->setPlaceholder('discuss.user.isModerator', $isModerator); } return $this->moderatorships[$boardId]; }
/** * @param string $tpl * * @return bool */ public function templateExists($tpl) { return (bool) $this->modx->getCount('modTemplate', array('templatename' => $tpl)); }