Пример #1
0
 /**
  * @param modX $modx
  * @param array $config
  */
 public function __construct(modX &$modx, $config = array())
 {
     $this->modx =& $modx;
     $config = array_merge(array('firstClass' => 'first', 'lastClass' => 'last', 'hereClass' => 'active', 'parentClass' => '', 'rowClass' => '', 'outerClass' => '', 'innerClass' => '', 'levelClass' => '', 'selfClass' => '', 'webLinkClass' => '', 'limit' => 0, 'hereId' => 0), $config, array('return' => 'data'));
     if (empty($config['tplInner']) && !empty($config['tplOuter'])) {
         $config['tplInner'] = $config['tplOuter'];
     }
     if (empty($config['hereId']) && !empty($modx->resource)) {
         $config['hereId'] = $modx->resource->id;
     }
     $fqn = $modx->getOption('pdoFetch.class', null, 'pdotools.pdofetch', true);
     if ($pdoClass = $modx->loadClass($fqn, '', false, true)) {
         $this->pdoTools = new $pdoClass($modx, $config);
     } elseif ($pdoClass = $modx->loadClass($fqn, MODX_CORE_PATH . 'components/pdotools/model/', false, true)) {
         $this->pdoTools = new $pdoClass($modx, $config);
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not load pdoFetch from "MODX_CORE_PATH/components/pdotools/model/".');
         return false;
     }
     if ($config['hereId'] && ($currentResource = $this->pdoTools->getObject('modResource', $config['hereId']))) {
         $tmp = $modx->getParentIds($currentResource['id'], 100, array('context' => $currentResource['context_key']));
         $tmp[] = $config['hereId'];
         $this->parentTree = array_flip($tmp);
     }
     $modx->lexicon->load('pdotools:pdomenu');
     return true;
 }
Пример #2
0
 /**
  * Load all class files and init defaults.
  *
  * @access public
  * @return boolean success state of initialization
  */
 public function initialize()
 {
     if (!$this->modx->getService('smarty', 'smarty.modSmarty')) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[AjaxUpload] Could not load modSmarty service.');
         $this->debug[] = 'Could not load modSmarty service.';
         return FALSE;
     }
     if (!$this->modx->loadClass('modPhpThumb', $this->modx->getOption('core_path') . 'model/phpthumb/', TRUE, TRUE)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[AjaxUpload] Could not load modPhpThumb class.');
         $this->debug[] = 'Could not load modPhpThumb class.';
         return FALSE;
     }
     if (!class_exists('qqFileUploader')) {
         include_once $this->config['modelPath'] . 'fileuploader/fileuploader.class.php';
         //include_once $this->config['modelPath'] . 'filecopier/filecopier.class.php';
     }
     $language = empty($this->config['language']) ? '' : $this->config['language'] . ':';
     $this->modx->lexicon->load($language . 'ajaxupload:default');
     if (!isset($_SESSION['ajaxupload'][$this->config['uid']])) {
         $_SESSION['ajaxupload'][$this->config['uid']] = array();
     }
     $_SESSION['ajaxupload'][$this->config['uid'] . 'config'] = $this->config;
     if (!@is_dir($this->config['cachePath'])) {
         @mkdir($this->config['cachePath'], 0755);
     }
     $this->clearCache();
     return TRUE;
 }
Пример #3
0
    /**
     * Get the connection class for the client. Defaults to cURL, then
     * fsockopen. If neither exists, returns false.
     *
     * @access public
     * @return boolean True if a connection can be made.
     */
    public function getConnection() {
        if (function_exists('curl_init')) {
            $className = $this->modx->loadClass('rest.modRestCurlClient','',false,true);
        } else if (function_exists('fsockopen')) {
            $className = $this->modx->loadClass('rest.modRestSockClient','',false,true);
        }

        if ($className) {
            $this->conn = new $className($this->modx,$this->config);
        }
        return is_object($this->conn);
    }
 /**
  * @param \modX $modx
  * @param array $config
  */
 public function __construct(modX &$modx, array $config = array())
 {
     $this->modx =& $modx;
     $basePath = $this->modx->getOption('scheduler.core_path', $config, $this->modx->getOption('core_path') . 'components/scheduler/');
     $assetsUrl = $this->modx->getOption('scheduler.assets_url', $config, $this->modx->getOption('assets_url') . 'components/scheduler/');
     $assetsPath = $this->modx->getOption('scheduler.assets_path', $config, $this->modx->getOption('assets_path') . 'components/scheduler/');
     $managerUrl = $this->modx->getOption('manager_url', $config, $this->modx->getOption('base_url') . 'manager/');
     $this->config = array_merge(array('basePath' => $basePath, 'corePath' => $basePath, 'modelPath' => $basePath . 'model/', 'processorsPath' => $basePath . 'processors/', 'elementsPath' => $basePath . 'elements/', 'templatesPath' => $basePath . 'templates/', 'assetsPath' => $assetsPath, 'assetsUrl' => $assetsUrl, 'jsUrl' => $assetsUrl . 'js/', 'cssUrl' => $assetsUrl . 'css/', 'connectorUrl' => $assetsUrl . 'connector.php', 'managerUrl' => $managerUrl, 'hideLogo' => $this->modx->getOption('scheduler.hideLogo', null, false)), $config);
     $this->modx->addPackage('scheduler', $this->config['modelPath']);
     $this->modx->loadClass('sTask', $this->config['modelPath'] . 'scheduler/');
     $this->modx->loadClass('sTaskRun', $this->config['modelPath'] . 'scheduler/');
 }
Пример #5
0
 /**
  * Initializes mSearch2 into different contexts.
  *
  * @access public
  * @param string $ctx The context to load. Defaults to web.
  *
  * @return boolean
  */
 public function initialize($ctx = 'web', $scriptProperties = array())
 {
     switch ($ctx) {
         case 'mgr':
             if (!$this->modx->loadClass('msearch2.request.mSearch2ControllerRequest', $this->config['modelPath'], true, true)) {
                 return 'Could not load controller request handler.';
             }
             $this->request = new mSearch2ControllerRequest($this);
             return $this->request->handleRequest();
             break;
         default:
             $this->config = array_merge($this->config, $scriptProperties);
             $this->config['ctx'] = $ctx;
             if (!empty($this->initialized[$ctx])) {
                 return true;
             }
             if (!defined('MODX_API_MODE') || !MODX_API_MODE) {
                 $config = $this->makePlaceholders($this->config);
                 if ($css = $this->modx->getOption('mse2_frontend_css')) {
                     $this->modx->regClientCSS(str_replace($config['pl'], $config['vl'], $css));
                 }
                 if ($js = trim($this->modx->getOption('mse2_frontend_js'))) {
                     $this->modx->regClientStartupScript(str_replace('					', '', '
			<script type="text/javascript">
			mSearch2Config = {
				cssUrl: "' . $this->config['cssUrl'] . 'web/"
				,jsUrl: "' . $this->config['jsUrl'] . 'web/"
				,actionUrl: "' . $this->config['actionUrl'] . '"
				,pageId: ' . $this->modx->resource->id . '
				,filter_delimeter: "' . $this->config['filter_delimeter'] . '"
				,method_delimeter: "' . $this->config['method_delimeter'] . '"
				,values_delimeter: "' . $this->config['values_delimeter'] . '"
			};
			</script>
		'), true);
                     if (!empty($js) && preg_match('/\\.js$/i', $js)) {
                         $this->modx->regClientScript(str_replace('							', '', '
				<script type="text/javascript">
				if(typeof jQuery == "undefined") {
					document.write("<script src=\\"' . $this->config['jsUrl'] . 'web/lib/jquery.min.js\\" type=\\"text/javascript\\"><\\/script>");
				}
				</script>
				'), true);
                         $this->modx->regClientScript(str_replace($config['pl'], $config['vl'], $js));
                     }
                 }
             }
             $this->initialized[$ctx] = true;
     }
     return true;
 }
Пример #6
0
 /**
  * @param modX $modx
  * @param array $config
  */
 public function __construct(modX &$modx, $config = array())
 {
     $this->modx =& $modx;
     $fqn = $modx->getOption('pdoTools.class', null, 'pdotools.pdotools', true);
     if ($pdoClass = $modx->loadClass($fqn, '', false, true)) {
         $this->pdoTools = new $pdoClass($modx, $config);
     } elseif ($pdoClass = $modx->loadClass($fqn, MODX_CORE_PATH . 'components/pdotools/model/', false, true)) {
         $this->pdoTools = new $pdoClass($modx, $config);
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not load pdoTools from "MODX_CORE_PATH/components/pdotools/model/".');
         return false;
     }
     $modx->lexicon->load('pdotools:pdopage');
     return true;
 }
Пример #7
0
 public function put($artifact, $attributes = array())
 {
     $added = false;
     if (!empty($artifact)) {
         $vehiclePackage = isset($attributes['vehicle_package']) ? $attributes['vehicle_package'] : 'transport';
         $vehiclePackagePath = isset($attributes['vehicle_package_path']) ? $attributes['vehicle_package_path'] : '';
         $vehicleClass = isset($attributes['vehicle_class']) ? $attributes['vehicle_class'] : '';
         $vehicleParentClass = isset($attributes['vehicle_parent_class']) ? $attributes['vehicle_parent_class'] : '';
         if (!empty($vehicleParentClass)) {
             $this->xpdo->loadClass('transport.' . $vehicleParentClass, '', true, true);
         }
         if (empty($vehicleClass)) {
             $vehicleClass = $options['vehicle_class'] = 'xPDOObjectVehicle';
         }
         if (!empty($vehiclePackage)) {
             $vehicleClass = "{$vehiclePackage}.{$vehicleClass}";
             $className = $this->xpdo->loadClass($vehicleClass, $vehiclePackagePath, true, true);
         } else {
             $className = $vehicleClass;
         }
         if ($className) {
             /** @var \xPDOVehicle $vehicle */
             $vehicle = new $className();
             $vehicle->put($this, $artifact, $attributes);
             if ($added = $vehicle->store($this)) {
                 $this->registerVehicle($vehicle);
             }
         } else {
             $this->xpdo->log(\xPDO::LOG_LEVEL_ERROR, "The specified xPDOVehicle class ({$vehiclePackage}.{$vehicleClass}) could not be loaded.");
         }
     }
     return $added;
 }
 /**
  * Prepare the output in this method to allow processing of this without depending on the actual render of the output
  * @param string $value
  * @param integer $resourceId The id of the resource; 0 defaults to the
  * current resource.
  * @return string
  */
 public function prepareOutput($value, $resourceId = 0)
 {
     /* Allow custom source types to manipulate the output URL for image/file tvs */
     $mTypes = $this->xpdo->getOption('manipulatable_url_tv_output_types', null, 'image,file');
     $mTypes = explode(',', $mTypes);
     if (!empty($value) && in_array($this->get('type'), $mTypes)) {
         $context = !empty($resourceId) ? $this->xpdo->getObject('modResource', $resourceId)->get('context_key') : $this->xpdo->context->get('key');
         $sourceCache = $this->getSourceCache($context);
         if (!empty($sourceCache) && !empty($sourceCache['class_key'])) {
             $coreSourceClasses = $this->xpdo->getOption('core_media_sources', null, 'modFileMediaSource,modS3MediaSource');
             $coreSourceClasses = explode(',', $coreSourceClasses);
             $classKey = in_array($sourceCache['class_key'], $coreSourceClasses) ? 'sources.' . $sourceCache['class_key'] : $sourceCache['class_key'];
             if ($this->xpdo->loadClass($classKey)) {
                 /** @var modMediaSource $source */
                 $source = $this->xpdo->newObject($classKey);
                 if ($source) {
                     $source->fromArray($sourceCache, '', true, true);
                     $source->initialize();
                     $isAbsolute = strpos($value, 'http://') === 0 || strpos($value, 'https://') === 0 || strpos($value, 'ftp://') === 0;
                     if (!$isAbsolute) {
                         $value = $source->prepareOutputUrl($value);
                     }
                 }
             }
         }
     }
     return $value;
 }
Пример #9
0
 /**
  * Initialize a register within the registry.
  *
  * @access protected
  * @param string $key The key of the registry
  * @param string $class The class of the modRegister implementation to
  * initialize.
  * @param array $options An optional array of register options.
  * @return modRegister The register instance.
  */
 protected function _initRegister($key, $class, array $options = array()) {
     $register = null;
     if ($className = $this->modx->loadClass($class, '', false, true)) {
         $register = new $className($this->modx, $key, $options);
     }
     return $register;
 }
Пример #10
0
 /**
  * Initializes mSearch2 into different contexts.
  *
  * @param string $ctx The context to load. Defaults to web.
  * @param array $scriptProperties
  *
  * @return boolean
  */
 public function initialize($ctx = 'web', $scriptProperties = array())
 {
     switch ($ctx) {
         case 'mgr':
             if (!$this->modx->loadClass('msearch2.request.mSearch2ControllerRequest', $this->config['modelPath'], true, true)) {
                 return 'Could not load controller request handler.';
             }
             $this->request = new mSearch2ControllerRequest($this);
             return $this->request->handleRequest();
             break;
         default:
             $this->config = array_merge($this->config, $scriptProperties);
             $this->config['ctx'] = $ctx;
             if (!defined('MODX_API_MODE') || !MODX_API_MODE) {
                 $config = $this->makePlaceholders($this->config);
                 if ($css = trim($this->modx->getOption('mse2_frontend_css'))) {
                     $this->modx->regClientCSS(str_replace($config['pl'], $config['vl'], $css));
                 }
                 if ($js = trim($this->modx->getOption('mse2_frontend_js'))) {
                     $this->modx->regClientScript(str_replace($config['pl'], $config['vl'], $js));
                 }
             }
     }
     return true;
 }
Пример #11
0
 /**
  * @param modX $modx
  * @param array $config
  */
 public function __construct(modX &$modx, $config = array())
 {
     $this->modx =& $modx;
     $config = array_merge(array('firstClass' => 'first', 'lastClass' => 'last', 'hereClass' => 'active', 'parentClass' => '', 'rowClass' => '', 'outerClass' => '', 'innerClass' => '', 'levelClass' => '', 'selfClass' => '', 'webLinkClass' => '', 'limit' => 0, 'hereId' => 0), $config, array('return' => 'data'));
     if (empty($config['tplInner']) && !empty($config['tplOuter'])) {
         $config['tplInner'] = $config['tplOuter'];
     }
     if (empty($config['hereId']) && !empty($modx->resource)) {
         $config['hereId'] = $modx->resource->id;
     }
     $fqn = $modx->getOption('pdoFetch.class', null, 'pdotools.pdofetch', true);
     $path = $modx->getOption('pdofetch_class_path', null, MODX_CORE_PATH . 'components/pdotools/model/', true);
     if ($pdoClass = $modx->loadClass($fqn, $path, false, true)) {
         $this->pdoTools = new $pdoClass($modx, $config);
     } else {
         return;
     }
     if ($config['hereId']) {
         $here = $this->pdoTools->getObject('modResource', $config['hereId'], array('select' => 'id, context_key'));
         if ($here) {
             $tmp = $modx->getParentIds($here['id'], 100, array('context' => $here['context_key']));
             $tmp[] = $config['hereId'];
             $this->parentTree = array_flip($tmp);
         }
     }
     $modx->lexicon->load('pdotools:pdomenu');
 }
Пример #12
0
 /**
  * Loads the error handling class for the request.
  *
  * @param string $class The class to use as the error handler.
  */
 public function loadErrorHandler($class = 'modError')
 {
     if ($className = $this->modx->loadClass('error.' . $class, '', false, true)) {
         $this->modx->error = new $className($this->modx);
     } else {
         $this->modx->log(modX::LOG_LEVEL_FATAL, 'Error handling class could not be loaded: ' . $class);
     }
 }
Пример #13
0
 /**
  * Load the dictionary storage mechanism
  * @return null|fiDictionary
  */
 public function loadDictionary()
 {
     if ($this->modx->loadClass('formit.fiDictionary', $this->formit->config['modelPath'], true, true)) {
         $this->dictionary = new fiDictionary($this->formit, $this->config);
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormIt] Could not load Dictionary class.');
     }
     return $this->dictionary;
 }
 /**
  * Loads the Hooks class.
  *
  * @access public
  * @param string $type The name of the Hooks service to load
  * @param array $config array An array of configuration parameters for the
  * hooks class
  * @return LoginHooks An instance of the fiHooks class.
  */
 public function loadHooks($type, $config = array())
 {
     if (!$this->modx->loadClass('login.LoginHooks', $this->config['modelPath'], true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[Login] Could not load Hooks class.');
         return false;
     }
     $this->{$type} = new LoginHooks($this->login, $this, $config);
     return $this->{$type};
 }
Пример #15
0
 /**
  * Initialize the modPDF class
  *
  * @param array $options
  */
 public function initPDF($options)
 {
     // Autoload composer classes
     require $this->getOption('corePath') . 'vendor/autoload.php';
     if (!$this->modx->loadClass('modpdf.modpdf', $this->options['modelPath'], true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not load modPDF class.');
         return;
     }
     $this->pdf = new modPDF($this->modx, array('mode' => $this->getOption('mode', $options), 'format' => $this->getOption('format', $options), 'defaultFontSize' => $this->getOption('defaultFontSize', $options), 'defaultFont' => $this->getOption('defaultFont', $options), 'mgl' => $this->getOption('mgl', $options), 'mgr' => $this->getOption('mgr', $options), 'mgt' => $this->getOption('mgt', $options), 'mgb' => $this->getOption('mgb', $options), 'mgh' => $this->getOption('mgh', $options), 'mgf' => $this->getOption('mgf', $options), 'orientation' => $this->getOption('orientation', $options), 'customFonts' => $this->getOption('customFonts', $options)));
 }
Пример #16
0
 /**
  * Loads the Hooks class.
  *
  * @access public
  * @param $type string The type of hook to load.
  * @param $config array An array of configuration parameters for the
  * hooks class
  * @return fiHooks An instance of the fiHooks class.
  */
 public function loadHooks($type = 'post', $config = array())
 {
     if (!$this->modx->loadClass('formit.fiHooks', $this->config['modelPath'], true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormIt] Could not load Hooks class.');
         return false;
     }
     $typeVar = $type . 'Hooks';
     $this->{$typeVar} = new fiHooks($this, $config, $type);
     return $this->{$typeVar};
 }
Пример #17
0
 /**
  * Loads the Hooks class.
  *
  * @access public
  * @param string $type The type of hook to load.
  * @param array $config An array of configuration parameters for the
  * hooks class
  * @return siHooks An instance of the fiHooks class.
  */
 public function loadHooks($type = 'post', $config = array())
 {
     if (!$this->modx->loadClass('simplesearch.siHooks', $this->config['modelPath'], true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[SimpleSearch] Could not load Hooks class.');
         return false;
     }
     $type = $type . 'Hooks';
     $this->{$type} = new siHooks($this, $config);
     return $this->{$type};
 }
Пример #18
0
 public static function loadModxInstance()
 {
     require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
     $modx = new modX();
     $modx->initialize('mgr');
     echo XPDO_CLI_MODE ? '' : '<pre>';
     $modx->setLogLevel(modX::LOG_LEVEL_INFO);
     $modx->setLogTarget('ECHO');
     $modx->loadClass('transport.modPackageBuilder', '', false, true);
     return $modx;
 }
Пример #19
0
 /**
  * @param modX $modx
  * @param array $config
  */
 public function __construct(modX &$modx, $config = array())
 {
     $this->modx =& $modx;
     $fqn = $modx->getOption('pdoTools.class', null, 'pdotools.pdotools', true);
     $path = $modx->getOption('pdotools_class_path', null, MODX_CORE_PATH . 'components/pdotools/model/', true);
     if ($pdoClass = $modx->loadClass($fqn, $path, false, true)) {
         $this->pdoTools = new $pdoClass($modx, $config);
     } else {
         return false;
     }
     $modx->lexicon->load('pdotools:pdopage');
 }
Пример #20
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}";
 }
Пример #21
0
 /**
  * Load all class files and init defaults.
  *
  * @param array $properties properties to override the default config (if set)
  * @access public
  * @return boolean success state of initialization
  */
 public function initialize($properties = array())
 {
     if (!$this->modx->getService('smarty', 'smarty.modSmarty')) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not load modSmarty service.', '', 'AjaxUpload');
         $this->debug[] = 'Could not load modSmarty service.';
         return false;
     }
     if (!$this->modx->loadClass('modPhpThumb', $this->modx->getOption('core_path') . 'model/phpthumb/', true, true)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not load modPhpThumb class.', '', 'AjaxUpload');
         $this->debug[] = 'Could not load modPhpThumb class.';
         return false;
     }
     if (!class_exists('qqFileUploader')) {
         include_once $this->config['modelPath'] . 'fileuploader/fileuploader.class.php';
         //include_once $this->config['modelPath'] . 'filecopier/filecopier.class.php';
     }
     $language = empty($this->config['language']) ? '' : $this->config['language'] . ':';
     $this->modx->lexicon->load($language . 'ajaxupload:default');
     if (!isset($_SESSION['ajaxupload'][$this->config['uid']])) {
         $_SESSION['ajaxupload'][$this->config['uid']] = array();
     }
     if (!isset($_SESSION['ajaxupload'][$this->config['uid'] . 'delete'])) {
         $_SESSION['ajaxupload'][$this->config['uid'] . 'delete'] = array();
     }
     if (count($properties)) {
         $allowedExtensions = $this->modx->getOption('allowedExtensions', $properties, 'jpg,jpeg,png,gif');
         $allowedExtensions = !is_array($allowedExtensions) ? explode(',', $allowedExtensions) : $allowedExtensions;
         $config = array('allowedExtensions' => $allowedExtensions, 'allowedExtensionsString' => !empty($allowedExtensions) ? "'" . implode("','", $allowedExtensions) . "'" : '', 'sizeLimit' => $this->modx->getOption('sizeLimit', $properties, $this->modx->getOption('maxFilesizeMb', $properties, 8) * 1024 * 1024), 'maxFiles' => (int) $this->modx->getOption('maxFiles', $properties, 3), 'thumbX' => (int) $this->modx->getOption('thumbX', $properties, 100), 'thumbY' => (int) $this->modx->getOption('thumbY', $properties, 100), 'addJquery' => (bool) $this->modx->getOption('addJquery', $properties, false), 'addJscript' => $this->modx->getOption('addJscript', $properties, true), 'addCss' => $this->modx->getOption('addCss', $properties, true), 'debug' => (bool) $this->modx->getOption('debug', $properties, $this->modx->getOption('ajaxupload.debug', null, false)));
         $this->config = array_merge($this->config, $config);
         $_SESSION['ajaxupload'][$this->config['uid'] . 'config'] = $this->config;
     }
     if (!@is_dir($this->config['cachePath'])) {
         if (!@mkdir($this->config['cachePath'], 0755)) {
             $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not create the cache path.', '', 'AjaxUpload');
         }
     }
     $this->clearCache();
     return true;
 }
Пример #22
0
 /**
  * Return the appropriate Resource controller class based on the class_key request parameter
  *
  * @static
  * @param modX $modx A reference to the modX instance
  * @param string $className The controller class name that is attempting to be loaded
  * @param array $config An array of configuration options for the action
  * @return modManagerController The proper controller class
  */
 public static function getInstance(modX &$modx, $className, array $config = array())
 {
     $resourceClass = 'modDocument';
     $isDerivative = false;
     if (!empty($_REQUEST['class_key'])) {
         $isDerivative = true;
         $resourceClass = in_array($_REQUEST['class_key'], array('modDocument', 'modResource')) ? 'modDocument' : $_REQUEST['class_key'];
         if ($resourceClass == 'modResource') {
             $resourceClass = 'modDocument';
         }
     } else {
         if (!empty($_REQUEST['id']) && $_REQUEST['id'] != 'undefined' && strlen($_REQUEST['id']) === strlen((int) $_REQUEST['id'])) {
             /** @var modResource $resource */
             $resource = $modx->getObject('modResource', array('id' => $_REQUEST['id']));
             if ($resource && !in_array($resource->get('class_key'), array('modDocument', 'modResource'))) {
                 $isDerivative = true;
                 $resourceClass = $resource->get('class_key');
             } else {
                 if ($resource && $resource->get('class_key') == 'modResource') {
                     /* fix improper class key */
                     $resource->set('class_key', 'modDocument');
                     $resource->save();
                 }
             }
         }
     }
     if ($isDerivative) {
         $resourceClass = str_replace(array('../', '..', '/', '\\'), '', $resourceClass);
         if (!class_exists($resourceClass) && !$modx->loadClass($resourceClass)) {
             $resourceClass = 'modDocument';
         }
         $delegateView = $modx->call($resourceClass, 'getControllerPath', array(&$modx));
         $action = strtolower(str_replace(array('Resource', 'ManagerController'), '', $className));
         $className = str_replace('mod', '', $resourceClass) . ucfirst($action) . 'ManagerController';
         $controllerFile = $delegateView . $action . '.class.php';
         if (!file_exists($controllerFile)) {
             // We more than likely are using a custom manager theme without overridden controller, let's try with the default theme
             $theme = $modx->getOption('manager_theme', null, 'default');
             $modx->setOption('manager_theme', 'default');
             $delegateView = $modx->call($resourceClass, 'getControllerPath', array(&$modx));
             $controllerFile = $delegateView . $action . '.class.php';
             // Restore custom theme (so we don't process/use default theme assets)
             $modx->setOption('manager_theme', $theme);
         }
         require_once $controllerFile;
     }
     $controller = new $className($modx, $config);
     $controller->resourceClass = $resourceClass;
     return $controller;
 }
 protected function createTables()
 {
     if ($this->config->getDatabase() != null) {
         $modelPath = $this->packageCorePath . 'model/';
         $this->modx->addPackage($this->config->getLowCaseName(), $modelPath, $this->config->getDatabase()->getPrefix());
         foreach ($this->config->getDatabase()->getSimpleObjects() as $simpleObject) {
             $this->modx->loadClass($simpleObject);
         }
         $manager = $this->modx->getManager();
         foreach ($this->config->getDatabase()->getTables() as $table) {
             $manager->createObjectContainer($table);
         }
     }
 }
Пример #24
0
 /**
  * Handle the request.
  * @return bool|string
  */
 public function handle()
 {
     if (!is_array($this->action) or count($this->action) < 1) {
         return false;
     }
     $actionName = $this->action['hma'];
     $actionPath = $actionName;
     if (strlen($actionPath) < 1) {
         return 'Oops, hma failure.';
     }
     $actionName = 'hmc' . str_replace(array('/', '.'), '', $actionName);
     if (count($this->action['options']) > 0) {
         $actionOptions = $this->action['options'];
     }
     $actionOptions['get'] = array_merge($_GET, $_POST);
     foreach ($actionOptions['get'] as $k => $v) {
         $actionOptions['get'][$k] = htmlentities($v, ENT_QUOTES, 'UTF-8');
     }
     if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
         array_walk_recursive($actionOptions['get'], create_function('&$val', '$val = stripslashes($val);'));
     }
     $this->action['gpc'] = $actionOptions['get'];
     $output = '';
     $this->modx->loadClass('hmController', $this->hm->config['controllersPath'], true, true);
     $included = (include_once $this->hm->config['controllersPath'] . $actionPath . '.class.php');
     if (!$included) {
         $this->modx->loadClass('empty', $this->hm->config['controllersPath'], true, true);
         $actionName = 'hmcEmpty';
     }
     $this->action['actionName'] = $actionName;
     $this->action['actionPath'] = $actionPath;
     $this->controller = new $actionName($this->hm, $this->action);
     /* attempt to initialize (setup) the page */
     $initialized = $this->controller->initialize();
     /* assuming all went well, process and render the page */
     if ($initialized === true) {
         if ($this->controller->meta) {
             $this->action['meta'] = $this->controller->meta;
         } else {
             $this->action['meta'] = array('title' => 'HandyMan');
         }
         $output = $this->controller->render($actionOptions);
     } else {
         /* simulate a page for the error by wrapping with header/footer */
         $output = $this->controller->wrap($initialized);
     }
     $output = $this->stripMODXTags($output);
     return $output;
 }
 /**
  * Loads an instance of Tools
  *
  * @return boolean
  */
 public function loadTools()
 {
     if (!is_object($this->Tools) or !$this->Tools instanceof SubdomainsFolderToolsInterface) {
         $toolsClass = $this->modx->loadClass('tools.Tools', $this->config['handlersPath'], true, true);
         if ($derivedClass = $this->getOption('class_tools_handler', null, '')) {
             if ($derivedClass = $this->modx->loadClass('tools.' . $derivedClass, $this->config['handlersPath'], false, true)) {
                 $toolsClass = $derivedClass;
             }
         }
         if ($toolsClass) {
             $this->Tools = new $toolsClass($this->modx, $this->config);
         }
     }
     return !empty($this->Tools) and $this->Tools instanceof SubdomainsFolderToolsInterface;
 }
Пример #26
0
 /**
  * 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;
 }
Пример #27
0
 /**
  * Return the appropriate Resource controller class based on the class_key request parameter
  * 
  * @static
  * @param modX $modx A reference to the modX instance
  * @param string $className The controller class name that is attempting to be loaded
  * @param array $config An array of configuration options for the action
  * @return modManagerController The proper controller class
  */
 public static function getInstance(modX &$modx, $className, array $config = array())
 {
     $resourceClass = 'modDocument';
     $isDerivative = false;
     if (!empty($_REQUEST['class_key'])) {
         $isDerivative = true;
         $resourceClass = in_array($_REQUEST['class_key'], array('modDocument', 'modResource')) ? 'modDocument' : $_REQUEST['class_key'];
         if ($resourceClass == 'modResource') {
             $resourceClass = 'modDocument';
         }
     } else {
         if (!empty($_REQUEST['id']) && $_REQUEST['id'] != 'undefined') {
             /** @var modResource $resource */
             $resource = $modx->getObject('modResource', $_REQUEST['id']);
             if ($resource && !in_array($resource->get('class_key'), array('modDocument', 'modResource'))) {
                 $isDerivative = true;
                 $resourceClass = $resource->get('class_key');
             } else {
                 if ($resource && $resource->get('class_key') == 'modResource') {
                     /* fix improper class key */
                     $resource->set('class_key', 'modDocument');
                     $resource->save();
                 }
             }
         }
     }
     if ($isDerivative) {
         $resourceClass = str_replace(array('../', '..', '/', '\\'), '', $resourceClass);
         if (!class_exists($resourceClass) && !$modx->loadClass($resourceClass)) {
             $resourceClass = 'modDocument';
         }
         $delegateView = $modx->call($resourceClass, 'getControllerPath', array(&$modx));
         $action = strtolower(str_replace(array('Resource', 'ManagerController'), '', $className));
         $className = str_replace('mod', '', $resourceClass) . ucfirst($action) . 'ManagerController';
         $controllerFile = $delegateView . $action . '.class.php';
         if (!file_exists($controllerFile)) {
             $modx->setOption('manager_theme', 'default');
             $delegateView = $modx->call($resourceClass, 'getControllerPath', array(&$modx));
             $controllerFile = $delegateView . $action . '.class.php';
         }
         require_once $controllerFile;
     }
     $controller = new $className($modx, $config);
     $controller->resourceClass = $resourceClass;
     return $controller;
 }
 /**
  * Ensure the a field passes a spam filter.
  *
  * Properties:
  * - spamEmailFields - The email fields to check. A comma-delimited list.
  *
  * @access public
  * @param array $fields An array of cleaned POST fields
  * @return boolean True if email was successfully sent.
  */
 public function spam(array $fields = array())
 {
     $passed = true;
     $spamEmailFields = $this->modx->getOption('spamEmailFields', $this->login->config, 'email');
     $emails = explode(',', $spamEmailFields);
     if ($this->modx->loadClass('stopforumspam.StopForumSpam', $this->login->config['modelPath'], true, true)) {
         $sfspam = new StopForumSpam($this->modx);
         foreach ($emails as $email) {
             $spamResult = $sfspam->check($_SERVER['REMOTE_ADDR'], $fields[$email]);
             if (!empty($spamResult)) {
                 $spamFields = implode($this->modx->lexicon('register.spam_marked') . "\n<br />", $spamResult);
                 $this->errors[$email] = $this->modx->lexicon('register.spam_blocked', array('fields' => $spamFields));
                 $passed = false;
             }
         }
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[Register] Couldnt load StopForumSpam class.');
     }
     return $passed;
 }
Пример #29
0
 /**
  * @param string $type
  * @return mixed
  */
 public function loadOptionType($type)
 {
     $this->modx->loadClass('msOption', $this->config['modelPath'] . 'minishop2/');
     $typePath = $this->config['corePath'] . 'processors/mgr/settings/option/types/' . $type . '.class.php';
     if (array_key_exists($typePath, $this->optionTypes)) {
         $className = $this->optionTypes[$typePath];
     } else {
         $className = (include_once $typePath);
         /* handle already included classes */
         if ($className == 1) {
             $o = array();
             $s = explode(' ', str_replace(array('_', '-'), ' ', $type));
             foreach ($s as $k) {
                 $o[] = ucfirst($k);
             }
             $className = 'ms' . implode('', $o) . 'Type';
         }
         $this->optionTypes[$typePath] = $className;
     }
     return $className;
 }
Пример #30
0
 /**
  * Load the appropriate controller
  * @param string $controller
  * @return null|FormSaveController
  */
 public function loadController($controller)
 {
     if ($this->modx->loadClass('FormSaveController', $this->config['modelPath'] . 'formsave/request/', true, true)) {
         $classPath = $this->config['controllersPath'] . 'web/' . $controller . '.php';
         $className = 'FormSave' . $controller . 'Controller';
         if (file_exists($classPath)) {
             if (!class_exists($className)) {
                 $className = (require_once $classPath);
             }
             if (class_exists($className)) {
                 $this->controller = new $className($this, $this->config);
             } else {
                 $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormSave] Could not load controller: ' . $className . ' at ' . $classPath);
             }
         } else {
             $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormSave] Could not load controller file: ' . $classPath);
         }
     } else {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormSave] Could not load formsaveController class.');
     }
     return $this->controller;
 }