/** * Verifies the authenticity of the provider * * @return boolean True if verified, xml if failed */ public function verify() { $response = $this->request('verify', 'GET'); if ($response->isError()) { $message = $response->getError(); if ($this->xpdo->lexicon && $this->xpdo->lexicon->exists('provider_err_' . $message)) { $message = $this->xpdo->lexicon('provider_err_' . $message); } return $message; } $status = $response->toXml(); return (bool) $status->verified; }
public static function loadOptions(xPDO &$xpdo, $product) { $c = $xpdo->newQuery('msProductOption'); $c->rightJoin('msOption', 'msOption', 'msProductOption.key=msOption.key'); $c->leftJoin('modCategory', 'Category', 'Category.id=msOption.category'); $c->where(array('msProductOption.product_id' => $product)); $c->select($xpdo->getSelectColumns('msOption', 'msOption')); $c->select($xpdo->getSelectColumns('msProductOption', 'msProductOption', '', array('key'), true)); $c->select('`Category`.`category` AS `category_name`'); $data = array(); $tstart = microtime(true); if ($c->prepare() && $c->stmt->execute()) { $xpdo->queryTime += microtime(true) - $tstart; $xpdo->executedQueries++; while ($option = $c->stmt->fetch(PDO::FETCH_ASSOC)) { if (isset($data[$option['key']])) { // если опция повторяется, ее значение будет массивом if (!is_array($data[$option['key']])) { $data[$option['key']] = array($data[$option['key']]); } $data[$option['key']][] = $option['value']; } else { // одиночная опция останется строкой $data[$option['key']] = $option['value']; } foreach ($option as $key => $value) { $data[$option['key'] . '.' . $key] = $value; } } } return $data; }
public static function listEvents(xPDO &$xpdo, $plugin, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { $c = $xpdo->newQuery('modEvent'); $count = $xpdo->getCount('modEvent',$c); $c->select(array( 'modEvent.*', 'IF(ISNULL(modPluginEvent.pluginid),0,1) AS enabled', 'modPluginEvent.priority AS priority', 'modPluginEvent.propertyset AS propertyset', )); $c->leftJoin('modPluginEvent','modPluginEvent',' modPluginEvent.event = modEvent.name AND modPluginEvent.pluginid = '.$plugin.' '); $c->where($criteria); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modEvent','modEvent','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array( 'count'=> $count, 'collection'=> $xpdo->getCollection('modEvent',$c) ); }
public static function _getControllerPath(xPDO &$modx, $path) { if (!($_path = $modx->getOption('shopmodx.core_path', null))) { $_path = $modx->getOption('core_path') . 'components/shopmodx/'; } $_path .= "controllers/default/{$path}/"; return $_path; }
/** * 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; }
public static function getControllerPath(xPDO &$modx) { $path = $modx->getOption('modsociety.controller_path', null); if (empty($path)) { $path = $modx->getOption('modsociety.core_path', null, $modx->getOption('core_path', null) . 'components/modsociety/') . 'controllers/mgr/'; } $path .= "societytopic/"; return $path; }
public static function listSettings(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { /* build query */ $c = $xpdo->newQuery('modSystemSetting'); $c->select(array( $xpdo->getSelectColumns('modSystemSetting','modSystemSetting'), )); $c->select(array( 'name_trans' => 'Entry.value', 'description_trans' => 'Description.value', )); $c->leftJoin('modLexiconEntry','Entry',"CONCAT('setting_',modSystemSetting.{$xpdo->escape('key')}) = Entry.name"); $c->leftJoin('modLexiconEntry','Description',"CONCAT('setting_',modSystemSetting.{$xpdo->escape('key')},'_desc') = Description.name"); $c->where($criteria); $count = $xpdo->getCount('modSystemSetting',$c); $c->sortby($xpdo->getSelectColumns('modSystemSetting','modSystemSetting','',array('area')),'ASC'); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modSystemSetting','modSystemSetting','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } $c->prepare(); return array( 'count'=> $count, 'collection'=> $xpdo->getCollection('modSystemSetting',$c) ); }
public function removeSourceContainer($dsnArray = null, $username = null, $password = null) { $removed = false; if ($dsnArray === null) { $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn')); } if ($username === null) { $username = $this->xpdo->getOption('username', null, ''); } if ($password === null) { $password = $this->xpdo->getOption('password', null, ''); } if (is_array($dsnArray) && is_string($username) && is_string($password)) { $sql = 'DROP DATABASE ' . $this->xpdo->escape($dsnArray['dbname']); try { $pdo = new PDO("mysql:host={$dsnArray['host']}", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $result = $pdo->exec($sql); if ($result !== false) { $removed = true; } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container:\n{$sql}\nresult = " . var_export($result, true)); } } catch (PDOException $pe) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not connect to database server: " . $pe->getMessage()); } catch (Exception $e) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container: " . $e->getMessage()); } } return $removed; }
public function removeSourceContainer($dsnArray = null, $username = null, $password = null) { $removed = false; if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) { if ($dsnArray === null) { $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn')); } if ($username === null) { $username = $this->xpdo->getOption('username', null, ''); } if ($password === null) { $password = $this->xpdo->getOption('password', null, ''); } if (is_array($dsnArray) && is_string($username) && is_string($password)) { $sql = 'DROP DATABASE ' . $this->xpdo->escape($dsnArray['dbname']); try { $pdo = new PDO("sqlsrv:server={$dsnArray['server']}", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $pdo->exec("ALTER DATABASE {$this->xpdo->escape($dsnArray['dbname'])} SET single_user WITH ROLLBACK IMMEDIATE"); $result = $pdo->exec($sql); if ($result !== false) { $removed = true; } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container:\n{$sql}\nresult = " . var_export($result, true)); } } catch (PDOException $pe) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not connect to database server: " . $pe->getMessage()); } catch (Exception $e) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container: " . $e->getMessage()); } } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__); } return $removed; }
public function initialize() { $this->setDefaultProperties(array('classKey' => 'modSnippet', 'pk' => false)); $tagParts = xPDO::escSplit('?', $this->getProperty('tag'), '`', 2); $tagNameParts = xPDO::escSplit('@', $tagParts[0]); $propertySet = isset($tagNameParts[1]) ? trim($tagNameParts[1]) : null; if (isset($propertySet) && strpos($propertySet, ':') != false) { $propSetParts = xPDO::escSplit(':', $propertySet); $propertySet = trim($propSetParts[0]); } if (isset($propertySet) && ($ps = $this->modx->getObject('modPropertySet', array('name' => $propertySet)))) { $this->setProperty('propertySet', $ps->id); } if (isset($tagParts[1])) { $tagPropString = ltrim(trim($tagParts[1]), '&'); $this->tagProperties = $this->modx->getParser()->parseProperties($tagPropString); } //$this->modx->log(1,print_r($this->tagProperties,1)); //$this->modx->log(modX::LOG_LEVEL_ERROR, $this->getProperty('tag')); $this->element = $this->modx->getObject($this->getProperty('classKey'), $this->getProperty('pk')); if (empty($this->element)) { return $this->modx->lexicon('element_err_nf'); } return true; }
public function removeSourceContainer($dsnArray = null, $username = null, $password = null) { $removed = false; if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) { if ($dsnArray === null) { $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn')); } if (is_array($dsnArray)) { try { $dbfile = $dsnArray['dbname']; if (file_exists($dbfile)) { $removed = unlink($dbfile); if (!$removed) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container"); } } else { $removed = true; } } catch (Exception $e) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container: " . $e->getMessage()); } } } return $removed; }
/** * Custom collection loader that forces access policy checking. * * {@inheritdoc} */ public static function loadCollection(xPDO &$xpdo, $className, $criteria = null, $cacheFlag = true) { $objCollection = array(); if (!($className = $xpdo->loadClass($className))) { return $objCollection; } $rows = false; $fromCache = false; $collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1); if (!is_object($criteria)) { $criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag); } if (is_object($criteria)) { if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) { $rows = $xpdo->fromCache($criteria, $className); $fromCache = is_array($rows) && !empty($rows); } if (!$fromCache) { $rows = xPDOObject::_loadRows($xpdo, $className, $criteria); } $cacheRows = array(); if (is_array($rows)) { foreach ($rows as $row) { if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) { if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) { $cacheRows[] = $row; } } } } elseif (is_object($rows)) { while ($row = $rows->fetch(PDO::FETCH_ASSOC)) { if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) { if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) { $cacheRows[] = $row; } } } } if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($cacheRows)) { $xpdo->toCache($criteria, $cacheRows, $cacheFlag); } } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'modAccessibleObject::loadCollection() - No valid statement could be found in or generated from the given criteria.'); } return $objCollection; }
public function processTag($tag, $processUncacheable = true) { // We need only # placeholders if ($tag[1][0] !== '#' && strpos($tag[1], '!#') === false) { return parent::processTag($tag, $processUncacheable); } $this->_processingTag = true; $element = null; $elementOutput = null; $outerTag = $tag[0]; $innerTag = $tag[1]; /* collect any nested element tags in the innerTag and process them */ $this->processElementTags($outerTag, $innerTag, $processUncacheable); $this->_processingTag = true; $outerTag = '[[' . $innerTag . ']]'; $tagParts = xPDO::escSplit('?', $innerTag, '`', 2); $tagName = trim($tagParts[0]); $tagPropString = null; if (isset($tagParts[1])) { $tagPropString = trim($tagParts[1]); } $token = substr($tagName, 0, 1); $tokenOffset = 0; $cacheable = true; if ($token === '!') { if (!$processUncacheable) { $this->_processingTag = false; return $outerTag; } $cacheable = false; $tokenOffset++; $token = substr($tagName, $tokenOffset, 1); } if ($cacheable && $token !== '+') { $elementOutput = $this->loadFromCache($outerTag); } if ($elementOutput === null) { switch ($token) { case '#': include_once $this->modx->getOption('core_path') . 'components/fastfield/model/fastfield/fastfield.php'; $tagName = substr($tagName, 1 + $tokenOffset); $element = new modResourceFieldTag($this->modx); $element->set('name', $tagName); $element->setTag($outerTag); $element->setCacheable($cacheable); $elementOutput = $element->process($tagPropString); break; } } if (($elementOutput === null || $elementOutput === false) && $outerTag !== $tag[0]) { $elementOutput = $outerTag; } if ($this->modx->getDebug() === true) { $this->modx->log(xPDO::LOG_LEVEL_DEBUG, "Processing {$outerTag} as {$innerTag} using tagname {$tagName}:\n" . print_r($elementOutput, 1) . "\n\n"); } $this->_processingTag = false; return $elementOutput; }
public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { /* query for profiles */ $c = $xpdo->newQuery('modFormCustomizationProfile'); $c->select(array( 'modFormCustomizationProfile.*', )); $c->select(' (SELECT GROUP_CONCAT(UserGroup.name) FROM '.$xpdo->getTableName('modUserGroup').' AS UserGroup INNER JOIN '.$xpdo->getTableName('modFormCustomizationProfileUserGroup').' AS fcpug ON fcpug.usergroup = UserGroup.id WHERE fcpug.profile = modFormCustomizationProfile.id ) AS usergroups '); $c->where($criteria,null,2);// also log issue in remine to look at this usage of where() $count = $xpdo->getCount('modFormCustomizationProfile',$c); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array( 'count'=> $count, 'collection'=> $xpdo->getCollection('modFormCustomizationProfile',$c) ); }
/** * Creates the database connection for the installation process. * * @access private * @return xPDO The xPDO instance to be used by the installation. */ public function _connect($dsn, $user = '', $password = '', $prefix = '', array $options = array()) { if (include_once MODX_CORE_PATH . 'xpdo/xpdo.class.php') { $this->xpdo = new xPDO($dsn, $user, $password, array_merge(array(xPDO::OPT_CACHE_PATH => MODX_CORE_PATH . 'cache/', xPDO::OPT_TABLE_PREFIX => $prefix, xPDO::OPT_SETUP => true), $options), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); $this->xpdo->setLogTarget(array('target' => 'FILE', 'options' => array('filename' => 'install.' . MODX_CONFIG_KEY . '.' . strftime('%Y%m%dT%H%M%S') . '.log'))); $this->xpdo->setLogLevel(xPDO::LOG_LEVEL_ERROR); return $this->xpdo; } else { return $this->lexicon('xpdo_err_nf', array('path' => MODX_CORE_PATH . 'xpdo/xpdo.class.php')); } }
/** * Retrieve the profile photo, if any * * @param int $width The desired photo width * @param int $height The desired photo height * * @return string The photo URL */ public function getProfilePhoto($width = 128, $height = 128) { if (empty($this->Profile->photo)) { return ''; } $this->xpdo->loadClass('sources.modMediaSource'); /** @var modMediaSource $source */ $source = modMediaSource::getDefaultSource($this->xpdo, $this->xpdo->getOption('photo_profile_source')); $source->initialize(); $path = $source->getBasePath($this->Profile->photo) . $this->Profile->photo; return $this->xpdo->getOption('connectors_url', MODX_CONNECTORS_URL) . "system/phpthumb.php?zc=1&h={$height}&w={$width}&src={$path}"; }
public static function listProfiles(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { $objCollection= array (); /* query for profiles */ $c = $xpdo->newQuery('modFormCustomizationProfile'); $c->select(array( $xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile'), )); $c->where($criteria,null,2);// also log issue in remine to look at this usage of where() $count = $xpdo->getCount('modFormCustomizationProfile',$c); foreach($sort as $field=> $dir) { $c->sortby($xpdo->getSelectColumns('modFormCustomizationProfile','modFormCustomizationProfile','',array($field)),$dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } $rows= xPDOObject :: _loadRows($xpdo, 'modFormCustomizationProfile', $c); $rowsArray = $rows->fetchAll(PDO::FETCH_ASSOC); $rows->closeCursor(); foreach($rowsArray as $row) { $objCollection[] = $xpdo->call('modFormCustomizationProfile', '_loadInstance', array(&$xpdo, 'modFormCustomizationProfile', $c, $row)); } unset($row, $rowsArray); return array( 'count'=> $count, 'collection'=> $objCollection ); }
public function testInitialize() { $xpdo = $this->getXPDOObject(); if ($xpdo && $xpdo->connect()) { $response = $xpdo->getManager()->removeSourceContainer(xPDO::parseDSN($this->properties[$this->properties['xpdo_driver'] . '_string_dsn_test'])); if ($response) { $xpdo = null; } } else { $xpdo = null; } $this->assertTrue($xpdo == null, "Test container exists and could not be removed for initialization"); }
/** * @static * @param xPDO|modX $modx * @return array|mixed */ public static function loadCache(xPDO &$modx) { if (!$modx->getCacheManager()) { return array(); } $cacheKey = 'extension-packages'; $cache = $modx->cacheManager->get($cacheKey, array(xPDO::OPT_CACHE_KEY => $modx->getOption('cache_extension_packages_key', null, 'namespaces'), xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_extension_packages_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $modx->getOption('cache_extension_packages_format', null, $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)))); if (empty($cache)) { $cache = $modx->cacheManager->generateExtensionPackagesCache($cacheKey); } return $cache; }
/** * Load preserved objects from the previous install(). * * @return array An array of preserved objects, or an empty array. */ public function loadPreserved() { $preserved = array(); $fileName = $this->path . $this->signature . '/preserved.php'; if (file_exists($fileName)) { $content = (include $fileName); if (is_array($content)) { $preserved = $content; } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error loading preserved objects from ' . $fileName); } } return $preserved; }
/** * @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; }
/** * Verify drop database works. */ public function testRemoveSourceContainer() { if (!empty(xPDOTestHarness::$debug)) { print "\n" . __METHOD__ . " = "; } $xpdo = xPDOTestHarness::getInstance(true); $success = false; if ($xpdo) { $driver = xPDOTestHarness::$properties['xpdo_driver']; $dsn = xPDOTestHarness::$properties[$driver . '_string_dsn_test']; $dsn = xPDO::parseDSN($dsn); $success = $xpdo->getManager()->removeSourceContainer($dsn); } $this->assertTrue($success, "Test container exists and could not be removed for initialization via xPDOManager->removeSourceContainer()"); }
/** * Get the dashboard for this user * * @return modDashboard */ public function getDashboard() { $this->xpdo->loadClass('modDashboard'); /** @var modUserGroup $userGroup */ $userGroup = $this->getPrimaryGroup(); if ($userGroup) { /** @var modDashboard $dashboard */ $dashboard = $userGroup->getOne('Dashboard'); if (empty($dashboard)) { $dashboard = modDashboard::getDefaultDashboard($this->xpdo); } } else { $dashboard = modDashboard::getDefaultDashboard($this->xpdo); } return $dashboard; }
public function testInitialize() { if (!empty(xPDOTestHarness::$debug)) { print "\n" . __METHOD__ . " = "; } $xpdo = xPDOTestHarness::getInstance(true); if (is_object($xpdo)) { $response = $xpdo->getManager()->removeSourceContainer(xPDO::parseDSN(xPDOTestHarness::$properties[xPDOTestHarness::$properties['xpdo_driver'] . '_string_dsn_test'])); if ($response) { $xpdo = null; } } else { $xpdo = null; } $this->assertTrue($xpdo == null, "Test container exists and could not be removed for initialization"); }
/** * Get a hash implementation instance. * * The implementation is made available as a member variable of the modHashing service. * * @param string $key A key string identifying the instance; must be a valid PHP variable name. * @param string $class A valid fully-qualified modHash derivative class name * @param array $options * @return array|null */ public function getHash($key, $class, array $options = array()) { $className = $this->modx->loadClass($class, '', false, true); if ($className) { if (empty($key)) $key = strtolower(str_replace('mod', '', $className)); if (!array_key_exists($key, $this->_hashes)) { $hash = new $className($this); if ($hash instanceof $className) { $this->_hashes[$key] = $hash; $this->$key =& $this->_hashes[$key]; } } if (array_key_exists($key, $this->_hashes)) { return $this->_hashes[$key]; } } return null; }
public static function listSettings(xPDO &$xpdo, array $criteria = array(), array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) { $c = $xpdo->newQuery('modUserGroupSetting'); $c->select(array($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting'), 'Entry.value AS name_trans', 'Description.value AS description_trans')); $c->leftJoin('modLexiconEntry', 'Entry', "'setting_' + modUserGroupSetting.[key] = Entry.name"); $c->leftJoin('modLexiconEntry', 'Description', "'setting_' + modUserGroupSetting.[key] + '_desc' = Description.name"); $c->where($criteria); $count = $xpdo->getCount('modUserGroupSetting', $c); $c->sortby($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting', '', array('area')), 'ASC'); foreach ($sort as $field => $dir) { $c->sortby($xpdo->getSelectColumns('modUserGroupSetting', 'modUserGroupSetting', '', array($field)), $dir); } if ((int) $limit > 0) { $c->limit((int) $limit, (int) $offset); } return array('count' => $count, 'collection' => $xpdo->getCollection('modUserGroupSetting', $c)); }
/** * Grab a persistent instance of the xPDO class to share sample model data * across multiple tests and test suites. * * @param boolean $new Indicate if a new singleton should be created * @return xPDO An xPDO object instance. */ public static function &getInstance($new = false) { if ($new || !is_object(xPDOTestHarness::$xpdo)) { $driver = xPDOTestHarness::$properties['xpdo_driver']; $xpdo = xPDO::getInstance(null, xPDOTestHarness::$properties["{$driver}_array_options"]); if (is_object($xpdo)) { $logLevel = array_key_exists('logLevel', xPDOTestHarness::$properties) ? xPDOTestHarness::$properties['logLevel'] : xPDO::LOG_LEVEL_WARN; $logTarget = array_key_exists('logTarget', xPDOTestHarness::$properties) ? xPDOTestHarness::$properties['logTarget'] : (XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $xpdo->setLogLevel($logLevel); $xpdo->setLogTarget($logTarget); if (!empty(xPDOTestHarness::$debug)) { $xpdo->setDebug(xPDOTestHarness::$properties['debug']); } $xpdo->setPackage('sample', xPDOTestHarness::$properties['xpdo_test_path'] . 'model/'); xPDOTestHarness::$xpdo = $xpdo; } } return xPDOTestHarness::$xpdo; }
/** * {@inheritDoc} * @return boolean */ public function initialize() { $this->objectType = $this->getProperty('elementType'); $this->classKey = 'mod' . ucfirst($this->objectType); $this->permission = 'view_' . $this->objectType; $tag = $this->getProperty('tag'); $tagParts = xPDO::escSplit('?', $tag, '`', 2); $tagName = trim($tagParts[0]); $parser = $this->modx->getParser(); $elementName = $this->elementName = $parser->realname($tagName); if (empty($elementName)) { return $this->modx->lexicon($this->objectType . '_err_ns'); } $query = $this->modx->newQuery($this->classKey, array('name' => $elementName)); $query->select('id'); $id = $this->modx->getValue($query->prepare()); if (!$id) { return $this->modx->lexicon($this->objectType . '_err_nf'); } $this->setProperty('id', $id); return parent::initialize(); }
/** * Creates the physical data container represented by a data source * * @todo Refactor this to work on an xPDO instance rather than as a static call. */ public function createSourceContainer($dsn, $username = '', $password = '', $containerOptions = null) { $created = false; if ($dsnArray = xPDO::parseDSN($dsn)) { switch ($dsnArray['dbtype']) { case 'mysql': include_once strtr(realpath(dirname(__FILE__)), '\\', '/') . '/mysql/xpdomanager.class.php'; $created = xPDOManager_mysql::createSourceContainer($dsnArray, $username, $password, $containerOptions); break; case 'sqlite': include_once strtr(realpath(dirname(__FILE__)), '\\', '/') . '/sqlite/xpdomanager.class.php'; $created = xPDOManager_sqlite::createSourceContainer($dsnArray, $username, $password, $containerOptions); break; case 'pgsql': include_once strtr(realpath(dirname(__FILE__)), '\\', '/') . '/pgsql/xpdomanager.class.php'; $created = xPDOManager_pgsql::createSourceContainer($dsnArray, $username, $password, $containerOptions); break; default: break; } } return $created; }
public static function getControllerPath(xPDO &$modx) { $x = $modx->getOption('moxycart.core_path', null, $modx->getOption('core_path')) . 'components/moxycart/controllers/taxonomy/'; return $x; }