/** * Get the default MODX dashboard * @static * @param xPDO $xpdo A reference to an xPDO instance * @return An|null|object */ public static function getDefaultDashboard(xPDO &$xpdo) { /** @var modDashboard $defaultDashboard */ $defaultDashboard = $xpdo->getObject('modDashboard', array('id' => 1)); if (empty($defaultDashboard)) { $defaultDashboard = $xpdo->getObject('modDashboard', array('name' => 'Default')); } return $defaultDashboard; }
/** * Sends notification email to moderators telling them the comment is awaiting approval. * * @return boolean True if successful */ public function notifyModerators() { if (!$this->_loadLexicon()) { return false; } $this->xpdo->lexicon->load('quip:emails'); /** @var quipThread $thread */ $thread = $this->getOne('Thread'); if (!$thread) { return false; } $properties = $this->toArray(); $properties['url'] = $this->makeUrl('', array(), array('scheme' => 'full')); /** * Get the Quip mgr action * @var modAction $action */ $action = $this->xpdo->getObject('modAction', array('controller' => 'index', 'namespace' => 'quip')); if ($action) { $managerUrl = MODX_URL_SCHEME . MODX_HTTP_HOST . MODX_MANAGER_URL; $properties['approveUrl'] = $managerUrl . '?a=' . $action->get('id') . '&quip_unapproved=1&quip_approve=' . $this->get('id'); $properties['rejectUrl'] = $managerUrl . '?a=' . $action->get('id') . '&quip_unapproved=1&quip_reject=' . $this->get('id'); $properties['unapprovedUrl'] = $managerUrl . '?a=' . $action->get('id') . '&quip_unapproved=1'; } $body = $this->xpdo->lexicon('quip.email_moderate', $properties); $subject = $this->xpdo->lexicon('quip.email_moderate_subject'); $success = true; $moderators = $thread->getModeratorEmails(); if (!empty($moderators)) { $success = $this->sendEmail($subject, $body, $moderators); } return $success; }
/** * Gets an object related to this instance by a foreign key relationship. * * Use this for 1:? (one:zero-or-one) or 1:1 relationships, which you can * distinguish by setting the nullability of the field representing the * foreign key. * * For all 1:* relationships for this instance, see {@link getMany()}. * * @see xPDOObject::getMany() * @see xPDOObject::addOne() * @see xPDOObject::addMany() * * @param string $alias Alias of the foreign class representing the related * object. * @param object $criteria xPDOCriteria object to get the related objects * @param boolean|integer $cacheFlag Indicates if the object should be * cached and optionally, by specifying an integer value, for how many * seconds. * @return xPDOObject|null The related object or null if no instance exists. */ public function &getOne($alias, $criteria = null, $cacheFlag = true) { $object = null; if ($fkdef = $this->getFKDefinition($alias)) { $k = $fkdef['local']; $fk = $fkdef['foreign']; if (isset($this->_relatedObjects[$alias])) { if (is_object($this->_relatedObjects[$alias])) { $object =& $this->_relatedObjects[$alias]; return $object; } } if ($criteria === null) { $criteria = array($fk => $this->get($k)); if (isset($fkdef['criteria']) && isset($fkdef['criteria']['foreign'])) { $criteria = array($fkdef['criteria']['foreign'], $criteria); } } if ($object = $this->xpdo->getObject($fkdef['class'], $criteria, $cacheFlag)) { $this->_relatedObjects[$alias] = $object; } } else { $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Could not getOne: foreign key definition for alias {$alias} not found."); } return $object; }
public function find(array $search = array(), array $args = array()) { $results = array(); $where = array_merge(array('query' => false, 'tag' => false, 'sorter' => false, 'start' => 0, 'limit' => 10, 'dateFormat' => '%b %d, %Y', 'supportsSeparator' => ', '), $search); $where['page'] = !empty($where['start']) ? round($where['start'] / $where['limit']) : 0; /** @var modRestResponse $response */ $response = $this->request('package', 'GET', $where); if ($response->isError()) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $response->getError(), '', __METHOD__, __FILE__, __LINE__); return $results; } $xml = $response->toXml(); /** @var SimpleXMLElement $package */ foreach ($xml as $package) { $installed = $this->xpdo->getObject('transport.modTransportPackage', (string) $package->signature); $versionCompiled = rtrim((string) $package->version . '-' . (string) $package->release, '-'); $releasedon = strftime($this->arg('dateFormat', $where), strtotime((string) $package->releasedon)); $supports = ''; foreach ($package->supports as $support) { $supports .= (string) $support . $this->arg('supportsSeparator', $where); } $results[] = array('id' => (string) $package->id, 'version' => (string) $package->version, 'release' => (string) $package->release, 'signature' => (string) $package->signature, 'author' => (string) $package->author, 'description' => (string) $package->description, 'instructions' => (string) $package->instructions, 'changelog' => (string) $package->changelog, 'createdon' => (string) $package->createdon, 'editedon' => (string) $package->editedon, 'name' => (string) $package->name, 'downloads' => number_format((int) $package->downloads, 0), 'releasedon' => $releasedon, 'screenshot' => (string) $package->screenshot, 'thumbnail' => !empty($package->thumbnail) ? (string) $package->thumbnail : (string) $package->screenshot, 'license' => (string) $package->license, 'minimum_supports' => (string) $package->minimum_supports, 'breaks_at' => (int) $package->breaks_at != 10000000 ? (string) $package->breaks_at : '', 'supports_db' => (string) $package->supports_db, 'location' => (string) $package->location, 'version-compiled' => $versionCompiled, 'downloaded' => !empty($installed) ? true : false, 'featured' => (bool) $package->featured, 'audited' => (bool) $package->audited, 'dlaction-icon' => $installed ? 'package-installed' : 'package-download', 'dlaction-text' => $installed ? $this->xpdo->lexicon('downloaded') : $this->xpdo->lexicon('download')); } return array((int) $xml['total'], $results); }
/** * @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; }
/** * Removes the User from the specified User Group. * * @access public * @param mixed $groupId Either the name or ID of the User Group to join. * @return boolean True if successful. */ public function leaveGroup($groupId) { $left = false; $c = $this->xpdo->newQuery('modUserGroupMember'); $c->innerJoin('modUserGroup', 'UserGroup'); $c->where(array('member' => $this->get('id'))); $fk = is_string($groupId) ? 'name' : 'id'; $c->where(array('member' => $this->get('id'), 'UserGroup.' . $fk => $groupId)); /** @var modUserGroupMember $member */ $member = $this->xpdo->getObject('modUserGroupMember', $c); if (empty($member)) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'User could not leave group with key "' . $groupId . '" because the User was not a part of that group.'); } else { $left = $member->remove(); if (!$left) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'An unknown error occurred preventing removing the User from the User Group.'); } else { unset($_SESSION["modx.user.{$this->get('id')}.userGroupNames"], $_SESSION["modx.user.{$this->get('id')}.userGroups"]); } } return $left; }
public function checkDownloadedDependencies(array $dependencies) { $satisfied = array(); foreach ($dependencies as $package => $constraint) { if (strtolower($package) === strtolower($this->identifier)) { continue; } /* get latest installed package version */ $latestQuery = $this->xpdo->newQuery('modTransportPackage', array(array("UCASE({$this->xpdo->escape('package_name')}) LIKE UCASE({$this->xpdo->quote($package)})"), 'installed:IS' => null)); $latestQuery->sortby('installed', 'DESC'); /** @var modTransportPackage $latest */ $latest = $this->xpdo->getObject('modTransportPackage', $latestQuery); if ($latest) { $latest->parseSignature(); if (xPDOTransport::satisfies($latest->version, $constraint)) { $satisfied[strtolower($package)] = $latest->signature; continue; } } } return $satisfied; }
/** * Fetch a board by ID * * @static * @param xPDO $modx * @param int $id * @param bool $integrated * @return disBoard */ public static function fetch(xPDO &$modx, $id, $integrated = false) { $c = $modx->newQuery('disBoard'); $c->leftJoin('disBoardUserGroup', 'UserGroups'); $c->where(array($integrated ? 'integrated_id' : 'id' => trim($id, '.'))); $groups = $modx->discuss->user->getUserGroups(); $where = array(); /* restrict boards by user group if applicable */ if (!$modx->discuss->user->isAdmin()) { if (!empty($groups)) { /* restrict boards by user group if applicable */ $g = array('UserGroups.usergroup:IN' => $groups); $g['OR:UserGroups.usergroup:IS'] = null; $where[] = $g; $c->andCondition($where, null, 2); } else { $c->where(array('UserGroups.usergroup:IS' => null)); } } $c->andCondition($where, null, 2); return $modx->getObject('disBoard', $c); }
} if (isset($template)) { $gc->setTemplate($template); } if (isset($defaultView)) { $gc->set('view', $view); } if (isset($formatForICal)) { $gc->set('formatForICal', $formatForICal); } if (isset($lang)) { $gc->set('lang', $lang); } if (isset($count)) { $gc->set('count', $count); } if (isset($offset)) { $gc->set('offset', $offset); } if (isset($filter)) { $gc->set('filter', $filter); } if (isset($snippetUrl)) { $gc->set('snippetUrl', $snippetUrl); } if ($debug) { $gc->setDebug(); } // Load calendar $gc->setCalendar($xpdo->getObject('Gregorian', $gc->get('calId'))); return $gc->handle();
public function getValue($criteria) { /** @var msProductOption $value */ $value = $this->xpdo->getObject('msProductOption', $criteria); return $value ? $value->get('value') : null; }
/** * Get the default MODX filesystem source * @static * @param xPDO|modX $xpdo A reference to an xPDO instance * @param int $defaultSourceId * @param boolean $fallbackToDefault * @return modMediaSource|null */ public static function getDefaultSource(xPDO &$xpdo, $defaultSourceId = null, $fallbackToDefault = true) { if (empty($defaultSourceId)) { $defaultSourceId = $xpdo->getOption('default_media_source', null, 1); } /** @var modMediaSource $defaultSource */ $defaultSource = $xpdo->getObject('sources.modMediaSource', array('id' => $defaultSourceId)); if (empty($defaultSource) && $fallbackToDefault) { $c = $xpdo->newQuery('sources.modMediaSource'); $c->sortby('id', 'ASC'); $defaultSource = $xpdo->getObject('sources.modMediaSource', $c); } return $defaultSource; }
$snippetUrl = $modx->config['base_url'] . 'assets/snippets/Gregorian/'; $snippetDir = $_SERVER['DOCUMENT_ROOT'] . $snippetUrl; // Load xPDO $xpdo = new xPDO(XPDO_DSN, XPDO_DB_USER, XPDO_DB_PASS, XPDO_TABLE_PREFIX, array(PDO_ATTR_ERRMODE => PDO_ERRMODE_WARNING, PDO_ATTR_PERSISTENT => false, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY => true)); $xpdo->setPackage('Gregorian', $snippetDir . 'model/'); // $xpdo->setDebug(); // $xpdo->setLoglevel(XPDO_LOG_LEVEL_INFO); $moduleUrl = "{$_SERVER['SCRIPT_NAME']}?a={$_REQUEST['a']}&id={$_REQUEST['id']}"; $output = ''; $output .= "<a href='{$moduleUrl}&action=createContent'>Create random content</a><br />"; $output .= "<a href='{$moduleUrl}&action=createTables'>Create database tables</a><br />"; if (array_key_exists('action', $_REQUEST)) { switch ($_REQUEST['action']) { case 'createContent': // Generate 10 random events in the future $calendar = $xpdo->getObject('Gregorian', 1); for ($i = 0; $i < 10; $i++) { $start = time() + rand(1, 10) * 3600 * 24; $fields = array('summary' => "Test event number {$i}", 'dtstart' => date('Y-m-d H:i', $start)); if (rand(0, 10) > 5) { $fields['dtend'] = date('Y-m-d H:i', $start + rand(1, 48) * 3600); } $fields['allday'] = rand(0, 10) > 5; if (rand(0, 10) > 5) { $fields['description'] = "An event with a description!"; } if (rand(0, 10) > 5) { $fields['location'] = "Somewhere, over the rainbow"; } var_dump($calendar->createEvent($fields)); echo "Event '{$fields['summary']}' on '{$fields['dtstart']}' created<br />\n";
/** * Fetch a thread, but check permissions first * * @static * @param xPDO $modx A reference to the modX instance * @param $id The ID of the thread * @param string $type The type of thread: post/message * @param boolean $integrated Grab by the integrated_id instead of the id * @return disThread/null The returned, grabbed thread; or false/null if not found/accessible */ public static function fetch(xPDO &$modx, $id, $type = disThread::TYPE_POST, $integrated = false) { $c = $modx->newQuery('disThread'); $c->innerJoin('disPost', 'FirstPost'); $c->leftJoin('disBoard', 'Board'); $c->select($modx->getSelectColumns('disThread', 'disThread')); $c->select(array('FirstPost.title', 'Board.rtl')); if ($integrated) { $c->where(array('disThread.integrated_id' => trim($id, '.'))); } else { $c->where(array('disThread.id' => $id)); } if ($type == disThread::TYPE_POST) { $c->where(array('Board.status:!=' => disBoard::STATUS_INACTIVE)); $c->leftJoin('disBoardUserGroup', 'UserGroups', 'Board.id = UserGroups.board'); $groups = $modx->discuss->user->getUserGroups(); if (!$modx->discuss->user->isAdmin()) { if (!empty($groups)) { /* restrict boards by user group if applicable */ $g = array('UserGroups.usergroup:IN' => $groups); $g['OR:UserGroups.usergroup:IS'] = null; $where[] = $g; $c->andCondition($where, null, 2); } else { $c->where(array('UserGroups.usergroup:IS' => null)); } } } if ($type == disThread::TYPE_MESSAGE) { $c->innerJoin('disThreadUser', 'Users'); $c->leftJoin('disUser', 'ThreadUser', 'Users.user = ThreadUser.id'); $c->where(array('Users.user' => $modx->discuss->user->get('id'))); $c->select(array('(SELECT GROUP_CONCAT(sqThreadUser.username) FROM ' . $modx->getTableName('disThreadUser') . ' AS sqThreadUsers INNER JOIN ' . $modx->getTableName('disUser') . ' AS sqThreadUser ON sqThreadUser.id = sqThreadUsers.user WHERE sqThreadUsers.thread = disThread.id ) AS participants_usernames')); } else { $c->select(array('(SELECT GROUP_CONCAT(sqPostAuthor.username) FROM ' . $modx->getTableName('disPost') . ' AS sqPosts INNER JOIN ' . $modx->getTableName('disUser') . ' AS sqPostAuthor ON sqPostAuthor.id = sqPosts.author WHERE sqPosts.thread = disThread.id ) AS participants_usernames')); } /** @var disThread $thread */ $thread = $modx->getObject('disThread', $c); if ($thread) { $participants = $thread->get('participants_usernames'); if (!empty($participants)) { $pu = array_unique(explode(',', $participants)); asort($pu); foreach ($pu as &$username) { $username = '******' . $modx->discuss->request->makeUrl('user', array('type' => 'username', 'user' => $username)) . '">' . $username . '</a>'; } $pu = implode(', ', $pu); $thread->set('participants_usernames', trim($pu)); } } return $thread; }