Пример #1
0
 /**
  * Returns current base url for pagination
  *
  * @return string $url
  */
 public function getBaseUrl()
 {
     if ($this->modx->getOption('friendly_urls')) {
         $q_var = $this->modx->getOption('request_param_alias', null, 'q');
         $q_val = isset($_REQUEST[$q_var]) ? $_REQUEST[$q_var] : '';
         $this->req_var = $q_var;
         $host = '';
         switch ($this->pdoTools->config['scheme']) {
             case 'full':
                 $host = $this->modx->getOption('site_url');
                 break;
             case 'abs':
             case 'absolute':
                 $host = $this->modx->getOption('base_url');
                 break;
             case 'https':
             case 'http':
                 $host = $this->pdoTools->config['scheme'] . '://' . $this->modx->getOption('http_host') . $this->modx->getOption('base_url');
                 break;
         }
         $url = $host . $q_val;
     } else {
         $id_var = $this->modx->getOption('request_param_id', null, 'id');
         $id_val = isset($_GET[$id_var]) ? $_GET[$id_var] : $this->modx->getOption('site_start');
         $this->req_var = $id_var;
         $url = $this->modx->makeUrl($id_val, '', '', $this->pdoTools->config['scheme']);
     }
     return $url;
 }
Пример #2
0
 /**
  * @param int $resource
  *
  * @return string
  */
 public function formatResourceUrl($resource = 0)
 {
     $url = '';
     $args = array();
     if (!empty($resource)) {
         $url = $this->modx->makeUrl($resource, '', $args, 'full', array('xhtml_urls' => false));
     }
     return $url;
 }
Пример #3
0
 /**
  * Show the remembered list
  *
  * @param array $options Template options
  * @return string
  */
 public function showList($options)
 {
     $output = array();
     // Generate the list
     $list = array();
     foreach ($_SESSION['rememberThis'] as $element) {
         $list[] = $element['element']['identifier'];
     }
     $output['list'] = $list;
     // Generate the result
     if (!count($_SESSION['rememberThis'])) {
         if (!$this->getOption('notRememberRedirect')) {
             $output['result'] = $this->modx->getChunk($options['outerTpl'], array('wrapper' => $this->modx->getChunk($options['noResultsTpl']), 'count' => $this->getOption('showZeroCount') ? '0' : ''));
         } else {
             $this->modx->sendRedirect($this->modx->makeUrl($this->getOption('notRememberRedirect')));
         }
     } else {
         $output['result'] = $this->modx->getChunk($options['outerTpl'], array('wrapper' => $this->showElements($options['rowTpl']), 'count' => (string) count($_SESSION['rememberThis'])));
     }
     // Generate count
     $output['count'] = count($_SESSION['rememberThis']);
     // Generate debug informations
     if ($this->getOption('debug')) {
         $output['debug'] = '<pre>DEBUG: $_SESSION["rememberThis"] = ' . print_r($_SESSION['rememberThis'], TRUE) . '</pre>';
     }
     return $output;
 }
Пример #4
0
 /**
  * @param $id
  * @param array $options
  * @param array $args
  *
  * @return mixed|string
  */
 public function makeUrl($id, $options = array(), $args = array())
 {
     $scheme = !empty($options['scheme']) ? $options['scheme'] : $this->config['scheme'];
     if (strtolower($scheme) == 'uri' && !empty($options['uri'])) {
         $url = $options['uri'];
         if (!empty($args)) {
             if (is_array($args)) {
                 $args = rtrim(modX::toQueryString($args), '?&');
             }
             $url .= strpos($url, '?') !== false ? '&' : '?';
             $url .= ltrim(trim($args), '?&');
         }
     } else {
         if (!empty($options['context_key'])) {
             $context = $options['context_key'];
         } elseif (!empty($options['context'])) {
             $context = $options['context'];
         } else {
             $context = '';
         }
         if (strtolower($scheme) == 'uri') {
             $scheme = -1;
         }
         $url = $this->modx->makeUrl($id, $context, $args, $scheme, $options);
     }
     return $url;
 }
Пример #5
0
 /**
  * Cleans the resource identifier from the request params.
  *
  * @param string $identifier The raw identifier.
  * @return string|integer The cleansed identifier.
  */
 public function _cleanResourceIdentifier($identifier)
 {
     if (empty($identifier)) {
         $identifier = $this->modx->getOption('site_start', null, 1);
         $this->modx->resourceMethod = 'id';
     } elseif ($this->modx->getOption('friendly_urls', null, false) && ($this->modx->resourceMethod = 'alias')) {
         $containerSuffix = trim($this->modx->getOption('container_suffix', null, ''));
         if (!isset($this->modx->aliasMap[$identifier])) {
             if (!empty($containerSuffix)) {
                 $suffixPos = strpos($identifier, $containerSuffix);
                 $suffixLen = strlen($containerSuffix);
                 $identifierLen = strlen($identifier);
                 if (substr($identifier, $identifierLen - $suffixLen) === $containerSuffix) {
                     $identifier = substr($identifier, 0, $identifierLen - $suffixLen);
                 } elseif (isset($this->modx->aliasMap["{$identifier}{$containerSuffix}"])) {
                     $identifier = "{$identifier}{$containerSuffix}";
                 }
                 if (isset($this->modx->aliasMap[$identifier])) {
                     $url = $this->modx->makeUrl($this->modx->aliasMap[$identifier], '', '', 'full');
                     $this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
                 }
                 $this->modx->resourceMethod = 'alias';
             }
         } elseif ($this->modx->getOption('site_start', null, 1) == $this->modx->aliasMap[$identifier]) {
             $this->modx->sendRedirect($this->modx->getOption('site_url', null, MODX_SITE_URL), array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
         } else {
             $this->modx->resourceMethod = 'alias';
         }
     } else {
         $this->modx->resourceMethod = 'id';
     }
     return $identifier;
 }
Пример #6
0
 /**
  * @param $id
  * @param string $context
  * @param string $args
  * @param int $scheme
  * @param array $options
  *
  * @return string
  */
 public function makeUrl($id, $context = '', $args = '', $scheme = -1, array $options = array())
 {
     $this->debugParser('makeUrl', $id, $args);
     $result = $this->modx->makeUrl($id, $context, $args, $scheme, $options);
     $this->debugParser('makeUrl', $id, $args);
     return $result;
 }
Пример #7
0
 /**
  * Redirect to a specified URL.
  *
  * Properties needed:
  * - redirectTo - the ID of the Resource to redirect to.
  *
  * @param array $fields An array of cleaned POST fields
  * @return boolean False if unsuccessful.
  */
 public function redirect(array $fields = array())
 {
     if (empty($this->formit->config['redirectTo'])) {
         return false;
     }
     $redirectParams = !empty($this->formit->config['redirectParams']) ? $this->formit->config['redirectParams'] : '';
     if (!empty($redirectParams)) {
         $prefix = $this->modx->getOption('placeholderPrefix', $this->formit->config, 'fi.');
         $this->modx->setPlaceholders($fields, $prefix);
         $this->modx->parser->processElementTags('', $redirectParams, true, true);
         $redirectParams = $this->modx->fromJSON($redirectParams);
         if (empty($redirectParams)) {
             $redirectParams = '';
         }
     }
     $contextKey = $this->modx->context->get('key');
     $resource = $this->modx->getObject('modResource', $this->formit->config['redirectTo']);
     if ($resource) {
         $contextKey = $resource->get('context_key');
     }
     if (!is_numeric($this->formit->config['redirectTo']) && isset($fields[$this->formit->config['redirectTo']]) && is_numeric($fields[$this->formit->config['redirectTo']])) {
         $url = $this->modx->makeUrl($fields[$this->formit->config['redirectTo']], $contextKey, $redirectParams, 'full');
     } elseif (!is_numeric($this->formit->config['redirectTo']) && substr($this->formit->config['redirectTo'], 0, 4) === "http") {
         $url = $this->formit->config['redirectTo'];
     } else {
         $url = $this->modx->makeUrl($this->formit->config['redirectTo'], $contextKey, $redirectParams, 'full');
     }
     $this->setRedirectUrl($url);
     return true;
 }
 /**
  * Redirect to a specified URL.
  *
  * Properties needed:
  * - redirectTo - the ID of the Resource to redirect to.
  *
  * @param array $fields An array of cleaned POST fields
  * @return boolean False if unsuccessful.
  */
 public function redirect(array $fields = array())
 {
     if (empty($this->login->config['redirectTo'])) {
         return false;
     }
     $url = $this->modx->makeUrl($this->login->config['redirectTo'], '', '', 'abs');
     return $this->modx->sendRedirect($url);
 }
Пример #9
0
 /**
  * Cleans the resource identifier from the request params.
  *
  * @param string $identifier The raw identifier.
  * @return string|integer The cleansed identifier.
  */
 public function _cleanResourceIdentifier($identifier)
 {
     if (empty($identifier)) {
         if ($this->modx->getOption('base_url', null, MODX_BASE_URL) !== strtok($_SERVER["REQUEST_URI"], '?')) {
             $this->modx->sendRedirect($this->modx->getOption('site_url', null, MODX_SITE_URL), array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
         }
         $identifier = $this->modx->getOption('site_start', null, 1);
         $this->modx->resourceMethod = 'id';
     } elseif ($this->modx->getOption('friendly_urls', null, false) && $this->modx->resourceMethod == 'alias') {
         $containerSuffix = trim($this->modx->getOption('container_suffix', null, ''));
         $found = $this->modx->findResource($identifier);
         if ($found === false && !empty($containerSuffix)) {
             $suffixLen = strlen($containerSuffix);
             $identifierLen = strlen($identifier);
             if (substr($identifier, $identifierLen - $suffixLen) === $containerSuffix) {
                 $identifier = substr($identifier, 0, $identifierLen - $suffixLen);
                 $found = $this->modx->findResource($identifier);
             } else {
                 $identifier = "{$identifier}{$containerSuffix}";
                 $found = $this->modx->findResource("{$identifier}{$containerSuffix}");
             }
             if ($found) {
                 $parameters = $this->getParameters();
                 unset($parameters[$this->modx->getOption('request_param_alias')]);
                 $url = $this->modx->makeUrl($found, $this->modx->context->get('key'), $parameters, 'full');
                 $this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
             }
             $this->modx->resourceMethod = 'alias';
         } elseif ((int) $this->modx->getOption('site_start', null, 1) === $found) {
             $parameters = $this->getParameters();
             unset($parameters[$this->modx->getOption('request_param_alias')]);
             $url = $this->modx->makeUrl($this->modx->getOption('site_start', null, 1), $this->modx->context->get('key'), $parameters, 'full');
             $this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
         } else {
             if ($this->modx->getOption('friendly_urls_strict', null, false)) {
                 $requestUri = $_SERVER['REQUEST_URI'];
                 $qsPos = strpos($requestUri, '?');
                 if ($qsPos !== false) {
                     $requestUri = substr($requestUri, 0, $qsPos);
                 }
                 $fullId = $this->modx->getOption('base_url', null, MODX_BASE_URL) . $identifier;
                 $requestUri = urldecode($requestUri);
                 if ($fullId !== $requestUri && strpos($requestUri, $fullId) !== 0) {
                     $parameters = $this->getParameters();
                     unset($parameters[$this->modx->getOption('request_param_alias')]);
                     $url = $this->modx->makeUrl($found, $this->modx->context->get('key'), $parameters, 'full');
                     $this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
                 }
             }
             $this->modx->resourceMethod = 'alias';
         }
     } else {
         $this->modx->resourceMethod = 'id';
     }
     return $identifier;
 }
Пример #10
0
 /**
  * Recursive template of branch of menu
  *
  * @param array $row
  *
  * @return mixed|string
  */
 public function templateBranch($row = array())
 {
     $children = '';
     $row['level'] = $this->level;
     if (!empty($row['children']) && ($this->isHere($row['id']) || empty($this->pdoTools->config['hideSubMenus'])) && $this->checkResource($row['id'])) {
         $idx = 1;
         $this->level++;
         $count = count($row['children']);
         foreach ($row['children'] as $v) {
             $v['idx'] = $idx++;
             $v['last'] = (int) $v['idx'] == $count;
             $children .= $this->templateBranch($v);
         }
         $this->level--;
         $row['children'] = $count;
     } else {
         $row['children'] = isset($row['children']) ? count($row['children']) : 0;
     }
     if (!empty($this->pdoTools->config['countChildren'])) {
         if ($ids = $this->modx->getChildIds($row['id'])) {
             $tstart = microtime(true);
             $count = $this->modx->getCount('modResource', array('id:IN' => $ids, 'published' => true, 'deleted' => false));
             $this->modx->queryTime += microtime(true) - $tstart;
             $this->modx->executedQueries++;
             $this->pdoTools->addTime('Got the number of active children for resource "' . $row['id'] . '": ' . $count);
         } else {
             $count = 0;
         }
         $row['children'] = $count;
     }
     if (!empty($children)) {
         $pls = $this->addWayFinderPlaceholders(array('wrapper' => $children, 'classes' => ' class="' . $this->pdoTools->config['innerClass'] . '"', 'classNames' => $this->pdoTools->config['innerClass'], 'classnames' => $this->pdoTools->config['innerClass'], 'level' => $this->level));
         $row['wrapper'] = $this->pdoTools->parseChunk($this->pdoTools->config['tplInner'], $pls);
     } else {
         $row['wrapper'] = '';
     }
     if (empty($row['menutitle']) && !empty($row['pagetitle'])) {
         $row['menutitle'] = $row['pagetitle'];
     }
     $classes = $this->getClasses($row);
     if (!empty($classes)) {
         $row['classNames'] = $row['classnames'] = $classes;
         $row['classes'] = ' class="' . $classes . '"';
     } else {
         $row['classNames'] = $row['classnames'] = $row['classes'] = '';
     }
     if (!empty($this->pdoTools->config['useWeblinkUrl']) && $row['class_key'] == 'modWebLink') {
         $row['link'] = is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), '', '', $this->pdoTools->config['scheme']) : $row['content'];
     } else {
         $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->pdoTools->config['scheme']);
     }
     $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : '';
     $tpl = $this->getTpl($row);
     $row = $this->addWayFinderPlaceholders($row);
     return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']);
 }
Пример #11
0
 /** @inheritdoc} */
 public function formatUrlReferrer($id = 0)
 {
     $clientKey = $this->MlmSystem->getOption('client_key', null, 'rclient');
     $referrerKey = $this->MlmSystem->getOption('referrer_key', null, 'rhash');
     $contextKey = $this->MlmSystem->getOption('ctx', null, $this->MlmSystem->getOption('referrer_context'), true);
     $referrerPage = $this->MlmSystem->getOption('referrer_page', null, $this->modx->getOption('site_start'));
     if (empty($referrerPage)) {
         $referrerPage = $this->modx->getOption('site_start');
     }
     $params = array($clientKey => $id, $referrerKey => $this->formatHashReferrer($id));
     $url = $this->modx->makeUrl($referrerPage, $contextKey, $params, 'full');
     return $url;
 }
Пример #12
0
 /**
  * Load all config files and prepare the values.
  *
  * @access public
  * @return void
  */
 public function initialize()
 {
     // TODO: Caching of these calculated values.
     $configFiles = glob($this->config['configsPath'] . '*.config.inc.php');
     // import config files
     foreach ($configFiles as $configFile) {
         // $settings will be defined in each config file
         $settings = array();
         include $configFile;
         foreach ($settings as $setting) {
             // fill urlParams if defined
             $urlParams = isset($setting['urlParams']) && is_array($setting['urlParams']) ? $setting['urlParams'] : array();
             $regEx = isset($setting['regEx']) && is_array($setting['regEx']) ? $setting['regEx'] : FALSE;
             if (isset($setting['alias'])) {
                 // if alias is defined, calculate the other values
                 if (isset($setting['resourceId'])) {
                     $resourceId = $setting['resourceId'];
                 } elseif ($res = $this->modx->getObject('modResource', array('uri' => $setting['alias']))) {
                     $resourceId = $res->get('id');
                 } else {
                     // if resourceId could not be calculated, don't use that setting
                     if ($this->config['debug']) {
                         $modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the resourceId for the given alias');
                     }
                     break;
                 }
                 $alias = $setting['alias'];
             } elseif (isset($setting['resourceId'])) {
                 // else if resourceId is defined, calculate the other values
                 $resourceId = $setting['resourceId'];
                 if (isset($setting['alias'])) {
                     $alias = $setting['alias'];
                 } elseif ($url = $this->modx->makeUrl($setting['resourceId'])) {
                     $alias = $url;
                 } else {
                     // if alias could not be calculated, don't use that setting
                     if ($this->config['debug']) {
                         $modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the alias for the given resourceId');
                     }
                     break;
                 }
             }
             $this->requests[$alias] = array('resourceId' => $resourceId, 'alias' => $alias, 'urlParams' => $urlParams, 'regEx' => $regEx);
         }
     }
     return;
 }
Пример #13
0
 /**
  * Recursive template of branch of menu
  *
  * @param array $row
  *
  * @return mixed|string
  */
 public function templateBranch($row = array())
 {
     $children = '';
     $row['level'] = $this->level;
     if (!empty($row['children']) && ($this->isHere($row['id']) || empty($this->pdoTools->config['hideSubMenus'])) && $this->checkResource($row['id'])) {
         $idx = 1;
         $this->level++;
         $count = count($row['children']);
         foreach ($row['children'] as $v) {
             $v['idx'] = $idx++;
             $v['last'] = (int) $v['idx'] == $count;
             $children .= $this->templateBranch($v);
         }
         $this->level--;
         $row['children'] = $count;
     } else {
         $row['children'] = 0;
     }
     if (!empty($children)) {
         $pls = $this->addWayFinderPlaceholders(array('wrapper' => $children, 'classes' => ' class="' . $this->pdoTools->config['innerClass'] . '"', 'classNames' => $this->pdoTools->config['innerClass'], 'classnames' => $this->pdoTools->config['innerClass']));
         $row['wrapper'] = $this->pdoTools->parseChunk($this->pdoTools->config['tplInner'], $pls);
     } else {
         $row['wrapper'] = '';
     }
     if (empty($row['menutitle']) && !empty($row['pagetitle'])) {
         $row['menutitle'] = $row['pagetitle'];
     }
     $classes = $this->getClasses($row);
     if (!empty($classes)) {
         $row['classNames'] = $row['classnames'] = $classes;
         $row['classes'] = ' class="' . $classes . '"';
     } else {
         $row['classNames'] = $row['classnames'] = $row['classes'] = '';
     }
     if (!empty($this->pdoTools->config['useWeblinkUrl']) && $row['class_key'] == 'modWebLink') {
         $row['link'] = is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), $row['context_key'], '', $this->pdoTools->config['scheme']) : $row['content'];
     } else {
         $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->pdoTools->config['scheme']);
     }
     $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : '';
     $tpl = $this->getTpl($row);
     $row = $this->addWayFinderPlaceholders($row);
     return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']);
 }
Пример #14
0
 /**
  * Redirect to a specified URL.
  *
  * Properties needed:
  * - redirectTo - the ID of the Resource to redirect to.
  *
  * @param array $fields An array of cleaned POST fields
  * @return boolean False if unsuccessful.
  */
 public function redirect(array $fields = array())
 {
     if (empty($this->quip->config['redirectTo'])) {
         return false;
     }
     $redirectParams = !empty($this->quip->config['redirectParams']) ? $this->quip->config['redirectParams'] : '';
     if (!empty($redirectParams)) {
         $prefix = $this->modx->getOption('placeholderPrefix', $this->quip->config, 'fi.');
         $this->modx->setPlaceholders($fields, $prefix);
         $this->modx->parser->processElementTags('', $redirectParams, true, true);
         $redirectParams = $this->modx->fromJSON($redirectParams);
         if (empty($redirectParams)) {
             $redirectParams = '';
         }
     }
     $url = $this->modx->makeUrl($this->quip->config['redirectTo'], '', $redirectParams, 'abs');
     $this->setRedirectUrl($url);
     return true;
 }
Пример #15
0
 /**
  * @param $method
  * @param array $params
  *
  * @return string
  */
 public function fenomFunction($method, array $params)
 {
     if (empty($params[0])) {
         return '';
     }
     $result = '';
     switch ($method) {
         case 'lexicon':
             $key = array_shift($params);
             if (!empty($params[0]) && is_array($params[0])) {
                 $properties = $params[0];
                 $topic = !empty($properties['topic']) ? $properties['topic'] : 'default';
                 $namespace = !empty($properties['namespace']) ? $properties['namespace'] : 'core';
                 $language = !empty($properties['language']) ? $properties['language'] : $this->modx->getOption('cultureKey', null, 'en');
                 $this->modx->lexicon->load($language . ':' . $namespace . ':' . $topic);
             }
             $placeholders = !empty($params[1]) && is_array($params[1]) ? $params[1] : array();
             $result = $this->modx->lexicon($key, $placeholders);
             break;
         case 'url':
             $id = trim(array_shift($params), '[]~');
             if (is_numeric($id)) {
                 $context = $this->modx->context->get('key');
                 $scheme = $this->modx->getOption('link_tag_scheme', null, -1);
                 $options = array();
                 if (!empty($params[0]) && is_array($params[0])) {
                     $options = $params[0];
                     if (isset($options['context'])) {
                         $context = $options['context'];
                         unset($options['context']);
                     }
                     if (isset($options['scheme'])) {
                         $scheme = $options['scheme'];
                         unset($options['scheme']);
                     }
                 }
                 $args = !empty($params[1]) && is_array($params[1]) ? $params[1] : array();
                 $result = $this->modx->makeUrl($id, $context, $args, $scheme, $options);
             }
             break;
     }
     return $result;
 }
Пример #16
0
 /**
  * Make the URL of the Quip thread for easy reference
  *
  * @param int $resource The ID of the resource to make from
  * @param array $params Any params to add to the URL
  * @param array $options An array of options for URL building
  * @return string The created URL
  */
 public function makeUrl($resource = 0, $params = array(), array $options = array())
 {
     if (empty($resource)) {
         $resource = $this->get('resource');
     }
     if (empty($params)) {
         $params = $this->get('existing_params');
     }
     if (empty($params)) {
         $params = array();
     }
     if (empty($options['context_key'])) {
         $options['context_key'] = $this->get('context_key');
         if (empty($options['context_key'])) {
             $options['context_key'] = $this->xpdo->context->get('key');
         }
     }
     $scheme = $this->xpdo->context->getOption('scheme', '', $options);
     return $this->xpdo->makeUrl($resource, $options['context_key'], $params, $scheme);
 }
 /**
  * Load all config files and prepare the values.
  *
  * @access public
  * @return void
  */
 public function initialize()
 {
     $configs = $this->modx->getCollection('CustomrequestConfigs');
     // TODO: Caching of the calculated values.
     // import config files
     foreach ($configs as $config) {
         // fill urlParams if defined
         $urlParams = ($tmp = json_decode($config->get('urlparams'))) ? $tmp : array();
         $regEx = $config->get('regex');
         if ($alias = $config->get('alias')) {
             // if alias is defined, calculate the other values
             if ($config->get('resourceid')) {
                 $resourceId = $config->get('resourceid');
             } elseif ($res = $this->modx->getObject('modResource', array('uri' => $config->get('alias')))) {
                 $resourceId = $res->get('id');
             } else {
                 // if resourceId could not be calculated or is not set, don't use that setting
                 if ($this->getOption('debug')) {
                     $this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the resourceId for the given alias "' . $alias . '"');
                 }
                 break;
             }
         } elseif ($resourceId = $config->get('resourceid')) {
             // else if resourceId is defined, calculate the other values
             if ($config->get('alias')) {
                 $alias = $config->get('alias');
             } elseif ($resourceId && ($alias = $this->modx->makeUrl($resourceId))) {
                 // cutoff trailing .html or /
                 $alias = trim(str_replace('.html', '', $alias), '/');
             } else {
                 // if alias could not be calculated, don't use that setting
                 if ($this->getOption('debug')) {
                     $this->modx->log(modX::LOG_LEVEL_INFO, 'CustomRequest Plugin: Could not calculate the alias for the given resourceId "' . $resourceId . '"');
                 }
                 break;
             }
         }
         $this->requests[$alias] = array('resourceId' => $resourceId, 'alias' => $alias, 'urlParams' => $urlParams, 'regEx' => $regEx);
     }
     return;
 }
Пример #18
0
 /**
  * Prepare the comment for rendering
  * 
  * @param array $properties
  * @param int $idx
  * @return array
  */
 public function prepare(array $properties = array(), $idx)
 {
     $alt = $idx % 2;
     $commentArray = $this->toArray();
     $commentArray['children'] = '';
     $commentArray['alt'] = $alt ? $this->getOption('altRowCss', $properties) : '';
     $commentArray['createdon'] = strftime($this->getOption('dateFormat', $properties), strtotime($this->get('createdon')));
     $commentArray['url'] = $this->makeUrl();
     $commentArray['idx'] = $idx;
     $commentArray['threaded'] = $this->getOption('threaded', $properties, true);
     $commentArray['depth'] = $this->get('depth');
     $commentArray['depth_margin'] = $this->getOption('useMargins', $properties, false) ? (int) ($this->getOption('threadedPostMargin', $properties, '15') * $this->get('depth')) + 7 : '';
     $commentArray['cls'] = $this->getOption('rowCss', $properties, '') . ($this->get('approved') ? '' : ' ' . $this->getOption('unapprovedCls', $properties, 'quip-unapproved'));
     $commentArray['olCls'] = $this->getOption('olCss', $properties, '');
     if ($this->getOption('useGravatar', $properties, true)) {
         $commentArray['md5email'] = md5($this->get('email'));
         $commentArray['gravatarIcon'] = $this->getOption('gravatarIcon', $properties, 'mm');
         $commentArray['gravatarSize'] = $this->getOption('gravatarSize', $properties, 60);
         $urlsep = $this->xpdo->context->getOption('xhtml_urls', true) ? '&amp;' : '&';
         $commentArray['gravatarUrl'] = $this->getOption('gravatarUrl', $properties) . $commentArray['md5email'] . '?s=' . $commentArray['gravatarSize'] . $urlsep . 'd=' . $commentArray['gravatarIcon'];
     } else {
         $commentArray['gravatarUrl'] = '';
     }
     /* check for auth */
     if ($this->hasAuth) {
         /* allow removing of comment if moderator or own comment */
         $commentArray['allowRemove'] = $this->getOption('allowRemove', $properties, true);
         if ($commentArray['allowRemove']) {
             if ($this->isModerator) {
                 /* Always allow remove for moderators */
                 $commentArray['allowRemove'] = true;
             } else {
                 if ($this->get('author') == $this->xpdo->user->get('id')) {
                     /* if not moderator but author of post, check for remove
                      * threshold, which prevents removing comments after X minutes
                      */
                     $removeThreshold = $this->getOption('removeThreshold', $properties, 3);
                     if (!empty($removeThreshold)) {
                         $diff = time() - strtotime($this->get('createdon'));
                         if ($diff > $removeThreshold * 60) {
                             $commentArray['allowRemove'] = false;
                         }
                     }
                 }
             }
         }
         $commentArray['reported'] = !empty($_GET['reported']) && $_GET['reported'] == $this->get('id') ? 1 : '';
         if ($this->get('author') == $this->xpdo->user->get('id') || $this->isModerator) {
             $params = $this->xpdo->request->getParameters();
             $params['quip_comment'] = $this->get('id');
             $params[$this->getOption('removeAction', $properties, 'quip-remove')] = true;
             $commentArray['removeUrl'] = $this->makeUrl('', $params, null, false);
             $commentArray['options'] = $this->xpdo->quip->getChunk($this->getOption('tplCommentOptions', $properties), $commentArray);
         } else {
             $commentArray['options'] = '';
         }
         if ($this->getOption('allowReportAsSpam', $properties, true)) {
             $params = $this->xpdo->request->getParameters();
             $params['quip_comment'] = $this->get('id');
             $params[$this->getOption('reportAction', $properties, 'quip-report')] = true;
             $commentArray['reportUrl'] = $this->makeUrl('', $params, null, false);
             $commentArray['report'] = $this->xpdo->quip->getChunk($this->getOption('tplReport', $properties), $commentArray);
         }
     } else {
         $commentArray['report'] = '';
     }
     /* get author display name */
     $authorTpl = $this->getOption('authorTpl', $properties, 'quipAuthorTpl');
     $nameField = $this->getOption('nameField', $properties, 'username');
     $commentArray['authorName'] = '';
     if (empty($commentArray[$nameField])) {
         $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $this->getOption('showAnonymousName', false) ? $this->getOption('anonymousName', $this->xpdo->lexicon('quip.anonymous')) : $commentArray['name'], 'url' => ''));
     } else {
         $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $commentArray[$nameField], 'url' => ''));
     }
     if ($this->getOption('showWebsite', $properties, true) && !empty($commentArray['website'])) {
         $commentArray['authorName'] = $this->xpdo->quip->getChunk($authorTpl, array('name' => $commentArray[$nameField], 'url' => $commentArray['website']));
     }
     if ($this->getOption('threaded', $properties, true) && $this->getOption('stillOpen', $properties, true) && $this->get('depth') < $this->getOption('maxDepth', $properties, 10) && $this->get('approved') && !$this->getOption('closed', $properties, false)) {
         if (!$this->getOption('requireAuth', $properties, false) || $this->hasAuth) {
             $params = $this->xpdo->request->getParameters();
             $params['quip_thread'] = $this->get('thread');
             $params['quip_parent'] = $this->get('id');
             $commentArray['replyUrl'] = $this->xpdo->makeUrl($this->getOption('replyResourceId', $properties, 1), '', $params);
         }
     } else {
         $commentArray['replyUrl'] = '';
     }
     return $commentArray;
 }
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php';
require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$snippet = $modx->getObject('modSnippet', array('name' => 'YandexMoney'));
$config = $snippet->getProperties();
$config['payStatusOut'] = $modx->getOption('yandexmoney.payStatusOut', null, 5);
if (!defined('YANDEXMONEY_PATH')) {
    define('YANDEXMONEY_PATH', MODX_CORE_PATH . "components/yandexmoney/");
}
if ($_GET['fail'] == 1) {
    if ($res = $modx->getObject('modResource', $config['fail_page_id'])) {
        $modx->sendRedirect($modx->makeUrl($config['fail_page_id'], '', '', 'full'));
    }
    exit;
} elseif ($_GET['success'] == 1) {
    if ($res = $modx->getObject('modResource', $config['success_page_id'])) {
        $modx->sendRedirect($modx->makeUrl($config['success_page_id'], '', '', 'full'));
    }
    exit;
}
require_once YANDEXMONEY_PATH . 'model/yandexmoney.class.php';
$ym = new Yandexmoney($modx, $config);
$order_id = $ym->ProcessResult();
if ($order_id) {
    $modx->addPackage('shopkeeper3', MODX_CORE_PATH . "components/shopkeeper3/model/");
    $order = $modx->getObject('shk_order', array('id' => $order_id));
    $order->set('status', $config['payStatusOut']);
    $order->save();
}
Пример #20
0
 /** @inheritdoc} */
 public function submit($data = array())
 {
     $response = $this->ms2->invokeEvent('msOnSubmitOrder', array('data' => $data, 'order' => $this));
     if (!$response['success']) {
         return $this->error($response['message']);
     }
     if (!empty($response['data']['data'])) {
         $this->set($response['data']['data']);
     }
     $response = $this->getDeliveryRequiresFields();
     if ($this->ms2->config['json_response']) {
         $response = $this->modx->fromJSON($response);
     }
     $requires = $response['data']['requires'];
     $errors = array();
     foreach ($requires as $v) {
         if (!empty($v) && empty($this->order[$v])) {
             $errors[] = $v;
         }
     }
     if (!empty($errors)) {
         return $this->error('ms2_order_err_requires', $errors);
     }
     $user_id = $this->ms2->getCustomerId();
     $cart_status = $this->ms2->cart->status();
     $delivery_cost = $this->getCost(false, true);
     $createdon = date('Y-m-d H:i:s');
     /* @var msOrder $order */
     $order = $this->modx->newObject('msOrder');
     $order->fromArray(array('user_id' => $user_id, 'createdon' => $createdon, 'num' => $this->getnum(), 'delivery' => $this->order['delivery'], 'payment' => $this->order['payment'], 'cart_cost' => $cart_status['total_cost'], 'weight' => $cart_status['total_weight'], 'delivery_cost' => $delivery_cost, 'cost' => $cart_status['total_cost'] + $delivery_cost, 'status' => 0, 'context' => $this->ms2->config['ctx']));
     // Adding address
     /* @var msOrderAddress $address */
     $address = $this->modx->newObject('msOrderAddress');
     $address->fromArray(array_merge($this->order, array('user_id' => $user_id, 'createdon' => $createdon)));
     $order->addOne($address);
     // Adding products
     $cart = $this->ms2->cart->get();
     $products = array();
     foreach ($cart as $v) {
         /* @var msOrderProduct $product */
         $product = $this->modx->newObject('msOrderProduct');
         $product->fromArray(array_merge($v, array('product_id' => $v['id'], 'cost' => $v['price'] * $v['count'])));
         $products[] = $product;
     }
     $order->addMany($products);
     $response = $this->ms2->invokeEvent('msOnBeforeCreateOrder', array('msOrder' => $order, 'order' => $this));
     if (!$response['success']) {
         return $this->error($response['message']);
     }
     if ($order->save()) {
         $response = $this->ms2->invokeEvent('msOnCreateOrder', array('msOrder' => $order, 'order' => $this));
         if (!$response['success']) {
             return $this->error($response['message']);
         }
         $this->ms2->cart->clean();
         $this->clean();
         if (empty($_SESSION['minishop2']['orders'])) {
             $_SESSION['minishop2']['orders'] = array();
         }
         $_SESSION['minishop2']['orders'][] = $order->get('id');
         // Trying to set status "new"
         $response = $this->ms2->changeOrderStatus($order->get('id'), 1);
         if ($response !== true) {
             return $this->error($response, array('msorder' => $order->get('id')));
         } elseif ($payment = $this->modx->getObject('msPayment', array('id' => $order->get('payment'), 'active' => 1))) {
             $response = $payment->send($order);
             if ($this->config['json_response']) {
                 @session_write_close();
                 exit(is_array($response) ? $this->modx->toJSON($response) : $response);
             } else {
                 if (!empty($response['data']['redirect'])) {
                     $this->modx->sendRedirect($response['data']['redirect']);
                     exit;
                 } elseif (!empty($response['data']['msorder'])) {
                     $this->modx->sendRedirect($this->modx->makeUrl($this->modx->resource->id), array('msorder' => $response['data']['msorder']));
                     exit;
                 } else {
                     $this->modx->sendRedirect($this->modx->makeUrl($this->modx->resource->id));
                     exit;
                 }
             }
         } else {
             if ($this->ms2->config['json_response']) {
                 return $this->success('', array('msorder' => $order->get('id')));
             } else {
                 $this->modx->sendRedirect($this->modx->makeUrl($this->modx->resource->id), array('msorder' => $response['data']['msorder']));
                 exit;
             }
         }
     }
     return $this->error();
 }
 /**
  * Run the Google SiteMap XML generation, recursively
  *
  * @param int $currentParent The current parent resource the iteration
  * is on
  * @param int $selfId If specified, will exclude this ID
  * @param int $depth
  * @return string The generated XML
  */
 public function run($currentParent, $selfId = -1, $depth = 0)
 {
     if (!empty($this->config['maxDepth']) && $depth >= $this->config['maxDepth']) {
         return '';
     }
     $output = '';
     /* get children */
     $c = $this->getQuery($currentParent);
     $children = $this->modx->getCollection('modResource', $c);
     /** @var modResource $child */
     foreach ($children as $child) {
         $id = $child->get('id');
         if ($selfId == $id) {
             continue;
         }
         $canParse = true;
         if ($this->config['searchable']) {
             $canParse = $canParse && $child->get('searchable');
         }
         if ($this->config['published']) {
             $canParse = $canParse && $child->get('published');
         }
         if ($this->config['hideDeleted']) {
             $canParse = $canParse && !$child->get('deleted');
         }
         if (empty($this->config['showHidden'])) {
             $canParse = $canParse && (!$child->get('hidemenu') || $child->get('class_key') == 'Article');
         }
         if ($canParse) {
             $url = $this->modx->makeUrl($id, '', '', 'full');
             $date = $child->get('editedon') ? $child->get('editedon') : $child->get('createdon');
             $date = date("Y-m-d", strtotime($date));
             /* Get the date difference */
             $datediff = datediff("d", $date, date("Y-m-d"));
             if ($datediff <= 1) {
                 $priority = '1.0';
                 $update = 'daily';
             } elseif ($datediff > 1 && $datediff <= 7) {
                 $priority = '0.75';
                 $update = 'weekly';
             } elseif ($datediff > 7 && $datediff <= 30) {
                 $priority = '0.50';
                 $update = 'weekly';
             } else {
                 $priority = '0.25';
                 $update = 'monthly';
             }
             if (!empty($this->config['priorityTV'])) {
                 $priorityTV = $child->getTVValue($this->config['priorityTV']);
                 if (!empty($priorityTV)) {
                     $priority = $priorityTV;
                 }
             }
             /* add item to output */
             $output .= $this->getChunk($this->config['itemTpl'], array('url' => $url, 'date' => $date, 'update' => $update, 'priority' => $priority)) . $this->config['itemSeparator'];
         }
         /* if children, recurse */
         if ($child->get('children') > 0) {
             $output .= $this->run($child->get('id'), $selfId, $depth + 1);
         }
     }
     return $output;
 }
Пример #22
0
            $user->set('active', 1);
            $user->set('password', $password);
            $profile->set('email', $email);
            $profile->set('internalKey', 0);
            $user->addOne($profile, 'Profile');
            // save user
            if (!$user->save()) {
                print 'ERROR: Could not save user.';
            }
        }
        // Add User to a User Group
        $Member = $modx->newObject('modUserGroupMember');
        $Member->set('user_group', $usergroup->get('id'));
        $Member->set('member', $user->get('id'));
        // Grant the user a role within that group
        $Member->set('role', 1);
        $Member->set('rank', 0);
        if (!$Member->save()) {
            print 'ERROR: Could not add User to User Group';
            exit;
        }
    }
}
// Flush Permissions ??
// Clear Cache
$modx->query("TRUNCATE TABLE " . $modx->getTableName("modSession"));
$modx->cacheManager->refresh();
$login_id = $page1->get('id');
$url = $modx->makeUrl($login_id, '', '', 'full');
print 'SUCCESS.  You can log in at <a href="' . $url . '">Login Page</a>';
/*EOF*/
Пример #23
0
 /**
  * @param $id
  * @param string $context
  * @param string $args
  * @param int $scheme
  * @param array $options
  *
  * @return string
  */
 public function makeUrl($id, $context = '', $args = '', $scheme = -1, array $options = array())
 {
     return $this->modx->makeUrl($id, $context, $args, $scheme, $options);
 }
Пример #24
0
    print message("Debug SQL query.", 'HELP');
    $c->prepare();
    print $c->toSQL();
    print "\n";
    exit;
}
// see http://www.webhostingtalk.com/showthread.php?t=1043707
// http://www.webdeveloper.com/forum/showthread.php?208676-Remote-site-loading-time
print "STARTING " . date('Y-m-d H:i:s') . "\n";
$mtime = explode(" ", microtime());
$tstart = $mtime[1] + $mtime[0];
$pg_cnt = 0;
$e_cnt = 0;
$collection = $modx->getIterator('modResource', $c);
foreach ($collection as $obj) {
    $url = $modx->makeUrl($obj->get('id'), '', '', 'full');
    if (!$url) {
        print 'ERROR empty URL for page ' . $obj->get('id') . "\n";
        continue;
    }
    if (!($loadtime = request_url($url))) {
        print 'ERROR requesting ' . $url . "\n";
        $e_cnt++;
    } else {
        print $url . ' Load Time: ' . $loadtime . "s\n";
        $pg_cnt++;
    }
    wait($params['sleep']);
}
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
Пример #25
0
 /**
  * Generates the pagination links
  *
  * @param string $searchString The string of the search
  * @param integer $perPage The number of items per page
  * @param string $separator The separator to use between pagination links
  * @param bool|int $total The total of records. Will default to the main count if not passed
  * @return string Pagination links.
  */
 public function getPagination($searchString = '', $perPage = 10, $separator = ' | ', $total = false)
 {
     if ($total === false) {
         $total = $this->response['total'];
     }
     $pagination = '';
     /* setup default properties */
     $searchIndex = $this->modx->getOption('searchIndex', $this->config, 'search');
     $searchOffset = $this->modx->getOption('offsetIndex', $this->config, 'sisea_offset');
     $pageTpl = $this->modx->getOption('pageTpl', $this->config, 'PageLink');
     $currentPageTpl = $this->modx->getOption('currentPageTpl', $this->config, 'CurrentPageLink');
     $urlScheme = $this->modx->getOption('urlScheme', $this->config, -1);
     /* get search string */
     if (empty($searchString)) {
         $searchString = $this->searchString;
     } else {
         $searchString = isset($_REQUEST[$searchIndex]) ? $_REQUEST[$searchIndex] : '';
     }
     $pageLinkCount = ceil($total / $perPage);
     $pageArray = array();
     $id = $this->modx->resource->get('id');
     $pageLimit = $this->modx->getOption('pageLimit', $this->config, 0);
     $pageFirstTpl = $this->modx->getOption('pageFirstTpl', $this->config, $pageTpl);
     $pageLastTpl = $this->modx->getOption('pageLastTpl', $this->config, $pageTpl);
     $pagePrevTpl = $this->modx->getOption('pagePrevTpl', $this->config, $pageTpl);
     $pageNextTpl = $this->modx->getOption('pageNextTpl', $this->config, $pageTpl);
     for ($i = 0; $i < $pageLinkCount; ++$i) {
         $pageArray['separator'] = $separator;
         $pageArray['offset'] = $i * $perPage;
         $currentOffset = $this->modx->getOption($searchOffset, $_GET, 0);
         if ($pageLimit > 0 && $i + 1 == 1 && $pageArray['offset'] != $currentOffset && !empty($pageFirstTpl)) {
             $parameters = $this->modx->request->getParameters();
             $parameters = array_merge($parameters, array($searchOffset => $pageArray['offset'], $searchIndex => $searchString));
             $pageArray['text'] = 'First';
             $pageArray['link'] = $this->modx->makeUrl($id, '', $parameters, $urlScheme);
             $pagination .= $this->getChunk($pageFirstTpl, $pageArray);
             if (!empty($pagePrevTpl) && $currentOffset - $perPage >= $perPage) {
                 $parameters = $this->modx->request->getParameters();
                 $parameters = array_merge($parameters, array($searchOffset => $currentOffset - $perPage, $searchIndex => $searchString));
                 $pageArray['text'] = '&lt;&lt;';
                 $pageArray['link'] = $this->modx->makeUrl($id, '', $parameters, $urlScheme);
                 $pagination .= $this->getChunk($pagePrevTpl, $pageArray);
             }
         }
         if (empty($pageLimit) || $pageArray['offset'] >= $currentOffset - $pageLimit * $perPage && $pageArray['offset'] <= $currentOffset + $pageLimit * $perPage) {
             if ($currentOffset == $pageArray['offset']) {
                 $pageArray['text'] = $i + 1;
                 $pageArray['link'] = $i + 1;
                 $pagination .= $this->getChunk($currentPageTpl, $pageArray);
             } else {
                 $parameters = $this->modx->request->getParameters();
                 $parameters = array_merge($parameters, array($searchOffset => $pageArray['offset'], $searchIndex => $searchString));
                 $pageArray['text'] = $i + 1;
                 $pageArray['link'] = $this->modx->makeUrl($id, '', $parameters, $urlScheme);
                 $pagination .= $this->getChunk($pageTpl, $pageArray);
             }
         }
         if ($pageLimit > 0 && $i + 1 == $pageLinkCount && $pageArray['offset'] != $currentOffset && !empty($pageLastTpl)) {
             if (!empty($pageNextTpl) && $currentOffset + $perPage <= $total) {
                 $parameters = $this->modx->request->getParameters();
                 $parameters = array_merge($parameters, array($searchOffset => $currentOffset + $perPage, $searchIndex => $searchString));
                 $pageArray['text'] = '&gt;&gt;';
                 $pageArray['link'] = $this->modx->makeUrl($id, '', $parameters, $urlScheme);
                 $pagination .= $this->getChunk($pageNextTpl, $pageArray);
             }
             $parameters = $this->modx->request->getParameters();
             $parameters = array_merge($parameters, array($searchOffset => $pageArray['offset'], $searchIndex => $searchString));
             $pageArray['text'] = 'Last';
             $pageArray['link'] = $this->modx->makeUrl($id, '', $parameters, $urlScheme);
             $pagination .= $this->getChunk($pageLastTpl, $pageArray);
         }
         if ($i < $pageLinkCount) {
             $pagination .= $separator;
         }
     }
     return trim($pagination, $separator);
 }