Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * Get an option for the MODX hashing service.
  *
  * Searches for local options and then prefixes keys with encrypt_ to look for
  * MODX System Settings.
  *
  * @param string $key The option key to get a value for.
  * @param array|null $options An optional array of options to look in first.
  * @param mixed $default An optional default value to return if no value is set.
  * @return mixed The option value or the specified default if not found.
  */
 public function getOption($key, $options = null, $default = null) {
     if (is_array($options) && array_key_exists($key, $options)) {
         $option = $options[$key];
     } elseif (array_key_exists($key, $this->options)) {
         $option = $this->options[$key];
     } else {
         $option = $this->modx->getOption('hashing_' . $key, $this->options, $default);
     }
     return $option;
 }
 /**
  * @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;
 }
Ejemplo n.º 5
0
 /**
  * Send an email to the user
  *
  * @param string $message The body of the email
  * @param array $options An array of options
  * @return boolean True if successful
  */
 public function sendEmail($message, array $options = array())
 {
     if (!$this->xpdo instanceof modX) {
         return false;
     }
     $profile = $this->getOne('Profile');
     if (empty($profile)) {
         return false;
     }
     $this->xpdo->getService('mail', 'mail.modPHPMailer');
     if (!$this->xpdo->mail) {
         return false;
     }
     $this->xpdo->mail->set(modMail::MAIL_BODY, $message);
     $this->xpdo->mail->set(modMail::MAIL_FROM, $this->xpdo->getOption('from', $options, $this->xpdo->getOption('emailsender')));
     $this->xpdo->mail->set(modMail::MAIL_FROM_NAME, $this->xpdo->getOption('fromName', $options, $this->xpdo->getOption('site_name')));
     $this->xpdo->mail->set(modMail::MAIL_SENDER, $this->xpdo->getOption('sender', $options, $this->xpdo->getOption('emailsender')));
     $this->xpdo->mail->set(modMail::MAIL_SUBJECT, $this->xpdo->getOption('subject', $options, $this->xpdo->getOption('emailsubject')));
     $this->xpdo->mail->address('to', $profile->get('email'), $profile->get('fullname'));
     $this->xpdo->mail->address('reply-to', $this->xpdo->getOption('sender', $options, $this->xpdo->getOption('emailsender')));
     $this->xpdo->mail->setHTML($this->xpdo->getOption('html', $options, true));
     if ($this->xpdo->mail->send() == false) {
         return false;
     }
     $this->xpdo->mail->reset();
     return true;
 }
 protected function args(array $args = array())
 {
     if (!is_array($this->xpdo->version)) {
         $this->xpdo->getVersionData();
     }
     $baseArgs = array('api_key' => $this->get('api_key'), 'username' => $this->get('username'), 'uuid' => $this->xpdo->uuid, 'database' => $this->xpdo->config['dbtype'], 'revolution_version' => $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version'], 'supports' => $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version'], 'http_host' => $this->xpdo->getOption('http_host'), 'php_version' => XPDO_PHP_VERSION, 'language' => $this->xpdo->getOption('manager_language'));
     return array_merge($baseArgs, $args);
 }
Ejemplo n.º 7
0
 /**
  * Get an option value for this instance.
  *
  * @param string $key The option key to retrieve a value for.
  * @param array|null $options An optional array to search for a value in first.
  * @param mixed $default A default value to return if no value is found; null is the default.
  * @return mixed The value of the option or the provided default if it is not set.
  */
 public function getOption($key, $options = null, $default = null) {
     if (is_array($options) && array_key_exists($key, $options)) {
         $value= $options[$key];
     } elseif (array_key_exists($key, $this->_options)) {
         $value= $this->_options[$key];
     } else {
         $value= $this->xpdo->getOption($key, null, $default);
     }
     return $value;
 }
Ejemplo n.º 8
0
 /**
  * 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}";
 }
 /**
  * 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 static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('phptemplates.core_path', null, $modx->getOption('core_path') . 'components/phptemplates/') . 'controllers/phptemplateresource/';
 }
 /**
  * Custom collection loader that forces access policy checking.
  *
  * {@inheritdoc}
  */
 public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
     $objCollection= array ();
     $fromCache = false;
     if (!$className= $xpdo->loadClass($className)) return $objCollection;
     $rows= false;
     $fromCache= false;
     $collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
     if (!is_object($criteria)) {
         $criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag);
     }
     if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
         $rows= $xpdo->fromCache($criteria);
         $fromCache = (is_array($rows) && !empty($rows));
     }
     if (!$fromCache && is_object($criteria)) {
         $rows= xPDOObject :: _loadRows($xpdo, $className, $criteria);
     }
     if (is_array ($rows)) {
         foreach ($rows as $row) {
             modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
         }
     } elseif (is_object($rows)) {
         $cacheRows = array();
         while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
             modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
             if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $cacheRows[] = $row;
         }
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $rows =& $cacheRows;
     }
     if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($rows)) {
         $xpdo->toCache($criteria, $rows, $cacheFlag);
     }
     return $objCollection;
 }
Ejemplo n.º 12
0
 /**
  * Remove the persistent instance of an object permanently.
  *
  * Deletes the persistent object instance stored in the database when
  * called, including any dependent objects defined by composite foreign key
  * relationships.
  *
  * @todo Implement some way to reassign ownership of related composite
  * objects when remove is called, perhaps by passing another object
  * instance as an optional parameter, or creating a separate method.
  *
  * @param array $ancestors Keeps track of classes which have already been
  * removed to prevent loop with circular references.
  * @return boolean Returns true on success, false on failure.
  */
 public function remove(array $ancestors = array())
 {
     $result = false;
     $pk = $this->getPrimaryKey();
     if ($pk && $this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
         if (!empty($this->_composites)) {
             $current = array($this->_class, $this->_alias);
             foreach ($this->_composites as $compositeAlias => $composite) {
                 if (in_array($compositeAlias, $ancestors) || in_array($composite['class'], $ancestors)) {
                     continue;
                 }
                 if ($composite['cardinality'] === 'many') {
                     if ($many = $this->getMany($compositeAlias)) {
                         /** @var xPDOObject $one */
                         foreach ($many as $one) {
                             $ancestors[] = $compositeAlias;
                             $newAncestors = $ancestors + $current;
                             if (!$one->remove($newAncestors)) {
                                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing dependent object: " . print_r($one->toArray('', true), true));
                             }
                         }
                         unset($many);
                     }
                 } elseif ($one = $this->getOne($compositeAlias)) {
                     $ancestors[] = $compositeAlias;
                     $newAncestors = $ancestors + $current;
                     if (!$one->remove($newAncestors)) {
                         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing dependent object: " . print_r($one->toArray('', true), true));
                     }
                     unset($one);
                 }
             }
         }
         $delete = $this->xpdo->newQuery($this->_class);
         $delete->command('DELETE');
         $delete->where($pk);
         // $delete->limit(1);
         $stmt = $delete->prepare();
         if (is_object($stmt)) {
             $tstart = microtime(true);
             if (!($result = $stmt->execute())) {
                 $this->xpdo->queryTime += microtime(true) - $tstart;
                 $this->xpdo->executedQueries++;
                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not delete from ' . $this->_table . '; primary key specified was ' . print_r($pk, true) . "\n" . print_r($stmt->errorInfo(), true));
             } else {
                 $this->xpdo->queryTime += microtime(true) - $tstart;
                 $this->xpdo->executedQueries++;
                 $callback = $this->getOption(xPDO::OPT_CALLBACK_ON_REMOVE);
                 if ($callback && is_callable($callback)) {
                     call_user_func($callback, array('className' => $this->_class, 'criteria' => $delete, 'object' => $this));
                 }
                 if ($this->xpdo->_cacheEnabled && $this->xpdo->getOption('cache_db', null, false)) {
                     /** @var xPDOCache $dbCache */
                     $dbCache = $this->xpdo->getCacheManager()->getCacheProvider($this->getOption('cache_db_key', null, 'db'), array(xPDO::OPT_CACHE_KEY => $this->getOption('cache_db_key', null, 'db'), xPDO::OPT_CACHE_HANDLER => $this->getOption(xPDO::OPT_CACHE_DB_HANDLER, null, $this->getOption(xPDO::OPT_CACHE_HANDLER, null, 'cache.xPDOFileCache')), xPDO::OPT_CACHE_FORMAT => (int) $this->getOption('cache_db_format', null, $this->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)), xPDO::OPT_CACHE_EXPIRES => (int) $this->getOption(xPDO::OPT_CACHE_DB_EXPIRES, null, $this->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0)), xPDO::OPT_CACHE_PREFIX => $this->getOption('cache_db_prefix', null, xPDOCacheManager::CACHE_DIR)));
                     if (!$dbCache->delete($this->_class, array('multiple_object_delete' => true))) {
                         $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Could not remove cache entries for {$this->_class}", '', __METHOD__, __FILE__, __LINE__);
                     }
                 }
                 $this->xpdo->log(xPDO::LOG_LEVEL_INFO, "Removed {$this->_class} instance with primary key " . print_r($pk, true));
             }
         } else {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not build criteria to delete from ' . $this->_table . '; primary key specified was ' . print_r($pk, true));
         }
     }
     return $result;
 }
Ejemplo n.º 13
0
 /**
  * Load a collection of xPDOObject instances and a graph of related objects.
  *
  * @static
  * @param xPDO &$xpdo A valid xPDO instance.
  * @param string $className Name of the class.
  * @param string|array $graph A related object graph in array or JSON
  * format, e.g. array('relationAlias'=>array('subRelationAlias'=>array()))
  * or {"relationAlias":{"subRelationAlias":{}}}.  Note that the empty arrays
  * are necessary in order for the relation to be recognized.
  * @param mixed $criteria A valid primary key, criteria array, or xPDOCriteria instance.
  * @param boolean|integer $cacheFlag Indicates if the objects should be
  * cached and optionally, by specifying an integer value, for how many
  * seconds.
  * @return array An array of xPDOObject instances or an empty array if no instances are loaded.
  */
 public static function loadCollectionGraph(xPDO &$xpdo, $className, $graph, $criteria, $cacheFlag)
 {
     $objCollection = array();
     if ($query = $xpdo->newQuery($className, $criteria, $cacheFlag)) {
         $query->bindGraph($graph);
         $fromCache = false;
         $collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
         if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
             $rows = $xpdo->fromCache($criteria);
             $fromCache = !empty($rows);
         }
         if (!$fromCache && ($stmt = $query->prepare())) {
             if ($stmt->execute()) {
                 $objCollection = $query->hydrateGraph($stmt, $cacheFlag);
             }
         } else {
             $objCollection = $query->hydrateGraph($rows, $cacheFlag);
         }
     }
     return $objCollection;
 }
Ejemplo n.º 14
0
 /**
  * Find all policies for this object
  * 
  * @param string $context
  * @return array
  */
 public function findPolicy($context = '')
 {
     $policy = array();
     $enabled = true;
     $context = 'mgr';
     if ($context === $this->xpdo->context->get('key')) {
         $enabled = (bool) $this->xpdo->getOption('access_media_source_enabled', null, true);
     } elseif ($this->xpdo->getContext($context)) {
         $enabled = (bool) $this->xpdo->contexts[$context]->getOption('access_media_source_enabled', true);
     }
     if ($enabled) {
         if (empty($this->_policies) || !isset($this->_policies[$context])) {
             $accessTable = $this->xpdo->getTableName('sources.modAccessMediaSource');
             $sourceTable = $this->xpdo->getTableName('sources.modMediaSource');
             $policyTable = $this->xpdo->getTableName('modAccessPolicy');
             $sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " . "LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " . "JOIN {$sourceTable} Source ON Acl.principal_class = 'modUserGroup' " . "AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " . "AND Source.id = Acl.target " . "WHERE Acl.target = :source " . "GROUP BY Acl.target, Acl.principal, Acl.authority, Acl.policy";
             $bindings = array(':source' => $this->get('id'), ':context' => $context);
             $query = new xPDOCriteria($this->xpdo, $sql, $bindings);
             if ($query->stmt && $query->stmt->execute()) {
                 while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
                     $policy['sources.modAccessMediaSource'][$row['target']][] = array('principal' => $row['principal'], 'authority' => $row['authority'], 'policy' => $row['data'] ? $this->xpdo->fromJSON($row['data'], true) : array());
                 }
             }
             $this->_policies[$context] = $policy;
         } else {
             $policy = $this->_policies[$context];
         }
     }
     return $policy;
 }
 /**
  * @param string $tpl
  * @param array $placeholders
  * @return string
  */
 public function getFileChunk($tpl, array $placeholders = array())
 {
     $output = '';
     $file = $tpl;
     if (!file_exists($file)) {
         $file = $this->modx->getOption('manager_path') . 'templates/' . $this->modx->getOption('manager_theme', null, 'default') . '/' . $tpl;
     }
     if (!file_exists($file)) {
         $file = $this->modx->getOption('manager_path') . 'templates/default/' . $tpl;
     }
     if (file_exists($file)) {
         /** @var modChunk $chunk */
         $chunk = $this->modx->newObject('modChunk');
         $chunk->setCacheable(false);
         $tplContent = file_get_contents($file);
         $chunk->setContent($tplContent);
         $output = $chunk->process($placeholders);
     }
     return $output;
 }
Ejemplo n.º 16
0
 public static function getFilesUrl(xPDO &$modx)
 {
     $path = $modx->getOption('gallery.files_url', null, $modx->getOption('base_url', null, MODX_BASE_URL) . 'assets/gallery/');
     $path = str_replace(array('[[++assets_url]]', '{assets_url}', '[[++base_url]]', '{base_url}'), array($modx->getOption('assets_url', null, MODX_BASE_URL . 'assets/'), $modx->getOption('assets_url', null, MODX_BASE_URL . 'assets/'), $modx->getOption('base_url', null, MODX_BASE_URL), $modx->getOption('base_url', null, MODX_BASE_URL)), $path);
     return $path;
 }
 /**
  * Determine the controller path for this Resource class
  * @static
  * @param xPDO $modx A reference to the modX object
  * @return string The absolute path to the controller for this Resource class
  */
 public static function getControllerPath(xPDO &$modx)
 {
     $theme = $modx->getOption('manager_theme', null, 'default');
     $controllersPath = $modx->getOption('manager_path', null, MODX_MANAGER_PATH) . 'controllers/' . $theme . '/';
     return $controllersPath . 'resource/';
 }
Ejemplo n.º 18
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('modxtalks.core_path', null, $modx->getOption('core_path') . 'components/modxtalks/') . 'controllers/comments/';
 }
 /**
  * Transfers the package from one directory to another.
  *
  * @access public
  * @param string $sourceFile The file to transfer.
  * @param string $targetDir The directory to transfer into.
  * @return boolean True if successful.
  */
 public function transferPackage($sourceFile, $targetDir)
 {
     $transferred = false;
     $content = '';
     if (is_dir($targetDir) && is_writable($targetDir)) {
         if (!is_array($this->xpdo->version)) {
             $this->xpdo->getVersionData();
         }
         $productVersion = $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version'];
         $source = $this->get('service_url') . $sourceFile . (strpos($sourceFile, '?') !== false ? '&' : '?') . 'revolution_version=' . $productVersion;
         /* see if user has allow_url_fopen on and is not behind a proxy */
         $proxyHost = $this->xpdo->getOption('proxy_host', null, '');
         if (ini_get('allow_url_fopen') && empty($proxyHost)) {
             if ($handle = @fopen($source, 'rb')) {
                 $filesize = @filesize($source);
                 $memory_limit = @ini_get('memory_limit');
                 if (!$memory_limit) {
                     $memory_limit = '8M';
                 }
                 $byte_limit = $this->_bytes($memory_limit) * 0.5;
                 if (strpos($source, '://') !== false || $filesize > $byte_limit) {
                     $content = @file_get_contents($source);
                 } else {
                     $content = @fread($handle, $filesize);
                 }
                 @fclose($handle);
             } else {
                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_file_read', array('source' => $source)));
             }
             /* if not, try curl */
         } else {
             if (function_exists('curl_init')) {
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $source);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_TIMEOUT, 180);
                 $safeMode = @ini_get('safe_mode');
                 $openBasedir = @ini_get('open_basedir');
                 if (empty($safeMode) && empty($openBasedir)) {
                     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                 }
                 $proxyHost = $this->xpdo->getOption('proxy_host', null, '');
                 if (!empty($proxyHost)) {
                     $proxyPort = $this->xpdo->getOption('proxy_port', null, '');
                     curl_setopt($ch, CURLOPT_PROXY, $proxyHost);
                     curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort);
                     $proxyUsername = $this->xpdo->getOption('proxy_username', null, '');
                     if (!empty($proxyUsername)) {
                         $proxyAuth = $this->xpdo->getOption('proxy_auth_type', null, 'BASIC');
                         $proxyAuth = $proxyAuth == 'NTLM' ? CURLAUTH_NTLM : CURLAUTH_BASIC;
                         curl_setopt($ch, CURLOPT_PROXYAUTH, $proxyAuth);
                         $proxyPassword = $this->xpdo->getOption('proxy_password', null, '');
                         $up = $proxyUsername . (!empty($proxyPassword) ? ':' . $proxyPassword : '');
                         curl_setopt($ch, CURLOPT_PROXYUSERPWD, $up);
                     }
                 }
                 $content = curl_exec($ch);
                 curl_close($ch);
                 /* and as last-ditch resort, try fsockopen */
             } else {
                 $content = $this->_getByFsockopen($source);
             }
         }
         if ($content) {
             if ($cacheManager = $this->xpdo->getCacheManager()) {
                 $filename = $this->signature . '.transport.zip';
                 $target = $targetDir . $filename;
                 $transferred = $cacheManager->writeFile($target, $content);
             }
         } else {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'MODX could not download the file. You must enable allow_url_fopen, cURL or fsockopen to use remote transport packaging.');
         }
     } else {
         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_target_write', array('targetDir' => $targetDir)));
     }
     return $transferred;
 }
Ejemplo n.º 20
0
 /**
  * Fetch a full list of boards for the forum with restrictions based on current user
  * 
  * @static
  * @param xPDO $modx
  * @param bool $ignoreBoards
  * @return array
  */
 public static function fetchList(xPDO &$modx, $ignoreBoards = true)
 {
     $c = array('ignore_boards' => $ignoreBoards);
     $cacheKey = 'discuss/board/user/' . $modx->discuss->user->get('id') . '/select-options-' . md5(serialize($c));
     $boards = $modx->cacheManager->get($cacheKey);
     if (empty($boards)) {
         $c = $modx->newQuery('disBoard');
         $c->innerJoin('disBoardClosure', 'Descendants');
         $c->leftJoin('disBoardUserGroup', 'UserGroups');
         $c->innerJoin('disCategory', 'Category');
         $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 ($modx->discuss->user->isLoggedIn && $ignoreBoards) {
             $ignoreBoards = $modx->discuss->user->get('ignore_boards');
             if (!empty($ignoreBoards)) {
                 $c->where(array('id:NOT IN' => explode(',', $ignoreBoards)));
             }
         }
         $c->select($modx->getSelectColumns('disBoard', 'disBoard'));
         $c->select(array('Descendants.depth AS depth', 'Category.name AS category_name'));
         $c->where(array('Descendants.ancestor' => 0));
         $c->sortby('Category.rank', 'ASC');
         $c->sortby('disBoard.map', 'ASC');
         $c->groupby('disBoard.id');
         $boardObjects = $modx->getCollection('disBoard', $c);
         /** @var disBoard $board */
         foreach ($boardObjects as $board) {
             $boards[] = $board->toArray('', false, true);
         }
         if (!empty($boards)) {
             $modx->cacheManager->set($cacheKey, $boards, $modx->getOption('discuss.cache_time', null, 3600));
         }
     }
     return $boards;
 }
Ejemplo n.º 21
0
 /**
  * Get the controller path for our Articles type.
  * 
  * {@inheritDoc}
  * @static
  * @param xPDO $modx
  * @return string
  */
 public static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('articles.core_path', null, $modx->getOption('core_path') . 'components/articles/') . 'controllers/container/';
 }
Ejemplo n.º 22
0
 /**
  * @param xPDO $modx
  *
  * @return string
  */
 public static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('tickets.core_path', null, $modx->getOption('core_path') . 'components/tickets/') . 'controllers/ticket/';
 }
Ejemplo n.º 23
0
 public static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('gridclasskey.core_path', null, $modx->getOption('core_path') . 'components/gridclasskey/') . 'controllers/classkey/container/';
 }
Ejemplo n.º 24
0
 public static function translatePath(xPDO &$xpdo, $path)
 {
     return str_replace(array('{core_path}', '{base_path}', '{assets_path}'), array($xpdo->getOption('core_path', null, MODX_CORE_PATH), $xpdo->getOption('base_path', null, MODX_BASE_PATH), $xpdo->getOption('assets_path', null, MODX_ASSETS_PATH)), $path);
 }
 public static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('core_path') . 'components/translations/controllers/mgr/';
 }
Ejemplo n.º 26
0
 /**
  * Fetch all new replies in threads that the active user is a participant in
  *
  * @static
  *
  * @param xPDO $modx A reference to the modX instance
  * @param string $sortBy The column to sort by
  * @param string $sortDir The direction to sort
  * @param int $limit The # of threads to limit
  * @param int $start The index to start by
  * @param boolean $sinceLastLogin
  * @param bool $countOnly Set to true to only return count, not run the actual query
  *
  * @return array An array in results/total format
  */
 public static function fetchNewReplies(xPDO &$modx, $sortBy = 'post_last_on', $sortDir = 'DESC', $limit = 20, $start = 0, $sinceLastLogin = false, $countOnly = false)
 {
     $response = array();
     $c = $modx->newQuery('disThread');
     $c->innerJoin('disBoard', 'Board');
     $c->innerJoin('disUser', 'LastAuthor');
     $c->innerJoin('disThreadParticipant', 'Participants', array("{$modx->escape('Participants')}.{$modx->escape('user')} = {$modx->discuss->user->get('id')}", "{$modx->escape('Participants')}.{$modx->escape('thread')} = {$modx->escape('disThread')}.{$modx->escape('id')}"));
     $groups = $modx->discuss->user->getUserGroups();
     /* usergroup protection */
     if ($modx->discuss->user->isLoggedIn) {
         if ($sinceLastLogin) {
             $lastLogin = $modx->discuss->user->get('last_login');
             if (!empty($lastLogin)) {
                 $c->where(array('disThread.post_last_on:>=' => is_int($lastLogin) ? $lastLogin : strtotime($lastLogin)));
             }
         }
         $ignoreBoards = $modx->discuss->user->get('ignore_boards');
         if (!empty($ignoreBoards)) {
             $c->where(array('Board.id:NOT IN' => explode(',', $ignoreBoards)));
         }
     }
     $cRead = $modx->newQuery('disThreadRead');
     $cRead->select(array($modx->getSelectColumns('disThreadRead', 'disThreadRead', '', array('thread'))));
     $cRead->where(array('user' => $modx->discuss->user->get('id'), "{$modx->escape('disThreadRead')}.{$modx->escape('thread')} = {$modx->escape('disThread')}.{$modx->escape('id')}"));
     $cRead->prepare();
     $c->WHERE(array("{$modx->escape('disThread')}.{$modx->escape('id')} NOT IN ({$cRead->toSQL()})"));
     if (!$modx->discuss->user->isAdmin()) {
         $c->leftJoin('disBoardUserGroup', 'UserGroups', 'Board.id = UserGroups.board');
         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));
         }
     }
     $daysAgo = time() - $modx->getOption('discuss.new_replies_threshold', null, 14) * 24 * 60 * 60;
     $c->where(array('Board.status:>' => disBoard::STATUS_INACTIVE, 'author_last:!=' => $modx->discuss->user->get('id')));
     /* ignore spam/recycle bin boards */
     $spamBoard = $modx->getOption('discuss.spam_bucket_board', null, false);
     if (!empty($spamBoard)) {
         $c->where(array('Board.id:!=' => $spamBoard));
     }
     $trashBoard = $modx->getOption('discuss.recycle_bin_board', null, false);
     if (!empty($trashBoard)) {
         $c->where(array('Board.id:!=' => $trashBoard));
     }
     $response['total'] = $modx->getCount('disThread', $c);
     $c->select($modx->getSelectColumns('disThread', 'disThread'));
     $c->select(array('board_name' => "{$modx->escape('Board')}.{$modx->escape('name')}", 'thread' => "{$modx->escape('disThread')}.{$modx->escape('id')}", 'author_username' => 'LastAuthor.username', 'post_id' => "{$modx->escape('disThread')}.{$modx->escape('post_last')}", "FROM_UNIXTIME({$modx->escape('disThread')}.{$modx->escape('post_last_on')}) AS {$modx->escape('createdon')}", 'author' => "{$modx->escape('disThread')}.{$modx->escape('author_last')}", 'last_post_replies' => "{$modx->escape('disThread')}.{$modx->escape('replies')}"));
     $c->sortby($sortBy, $sortDir);
     $c->limit($limit, $start);
     if (!$countOnly) {
         $response['results'] = $modx->getCollection('disThread', $c);
     }
     return $response;
 }
Ejemplo n.º 27
0
 public static function getControllerPath(xPDO &$modx)
 {
     $x = $modx->getOption('moxycart.core_path', null, $modx->getOption('core_path')) . 'components/moxycart/controllers/taxonomy/';
     return $x;
 }
Ejemplo n.º 28
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public static function getControllerPath(xPDO &$modx)
 {
     return $modx->getOption('minishop2.core_path', null, $modx->getOption('core_path') . 'components/minishop2/') . 'controllers/category/';
 }