Example #1
1
 /**
  * Import all attachments for this post
  * @param disPost $post
  * @param array $prow
  * @return array
  */
 public function importAttachments(disPost $post, array $prow = array())
 {
     $ast = $this->pdo->query('
         SELECT
             *
         FROM ' . $this->getFullTableName('attachments') . '
         WHERE
             `ID_MSG` = ' . $prow['ID_MSG'] . '
     ');
     if (!$ast) {
         return array();
     }
     $aIdx = 0;
     while ($arow = $ast->fetch(PDO::FETCH_ASSOC)) {
         $this->log('Adding attachment: ' . $arow['filename']);
         /** @var disPostAttachment $attachment */
         $attachment = $this->modx->newObject('disPostAttachment');
         $attachment->fromArray(array('post' => $post->get('id'), 'board' => $post->get('board'), 'filename' => $arow['filename'], 'filesize' => $arow['size'], 'downloads' => $arow['downloads'], 'integrated_id' => $arow['ID_ATTACH'], 'integrated_data' => $this->modx->toJSON(array('filename' => $arow['filename'], 'file_hash' => $arow['file_hash'], 'width' => $arow['width'], 'height' => $arow['height'], 'attachmentType' => $arow['attachmentType'], 'ID_MEMBER' => $arow['ID_MEMBER'], 'ID_MESSAGE' => !empty($arow['ID_MESSAGE']) ? $arow['ID_MESSAGE'] : 0, 'ID_THUMB' => $arow['ID_THUMB']))));
         if ($this->config['live']) {
             $attachment->save();
         }
         $aIdx++;
     }
     $ast->closeCursor();
 }
 protected function install($packagesDir, $dir, $packagesBaseUrl, OutputInterface $output)
 {
     $configContent = $this->modx->fromJSON(file_get_contents($packagesDir . $dir . '/_build/config.json'));
     $this->config = new Config($this->modx, $dir);
     $this->config->parseConfig($configContent);
     $this->packageCorePath = $packagesDir . $dir . "/core/components/" . $this->config->getLowCaseName() . "/";
     $this->packageCorePath = str_replace('\\', '/', $this->packageCorePath);
     $this->packageAssetsPath = $packagesDir . $dir . "/assets/components/" . $this->config->getLowCaseName() . "/";
     $this->packageAssetsPath = str_replace('\\', '/', $this->packageAssetsPath);
     $this->packageAssetsUrl = $packagesBaseUrl . $dir . '/assets/components/' . $this->config->getLowCaseName() . '/';
     $this->createNamespace();
     $this->createMenusAndActions();
     $this->createSystemSettings($packagesDir, $packagesBaseUrl);
     $this->createTables();
     $this->clearCache();
     /** @var \GitPackage $packageObject */
     $packageObject = $this->modx->newObject('GitPackage');
     $packageObject->set('version', $this->config->getVersion());
     $packageObject->set('description', $this->config->getDescription());
     $packageObject->set('author', $this->config->getAuthor());
     $packageObject->set('name', $this->config->getName());
     $packageObject->set('dir_name', $dir);
     $packageObject->set('config', $this->modx->toJSON($configContent));
     $packageObject->save();
 }
Example #3
0
 /**
  * Converts PHP to JSON with JavaScript literals left in-tact.
  *
  * JSON does not allow JavaScript literals, but this function encodes certain identifiable
  * literals and decodes them back into literals after modX::toJSON() formats the data.
  *
  * @access public
  * @param mixed $data The PHP data to be converted.
  * @return string The extended JSON-encoded string.
  */
 public function toJSON($data)
 {
     if (is_array($data)) {
         array_walk_recursive($data, array(&$this, '_encodeLiterals'));
     }
     return $this->_decodeLiterals($this->modx->toJSON($data));
 }
Example #4
0
 /**
  * Loads javascript and styles for ajax pagination
  *
  */
 public function loadJsCss()
 {
     $assetsUrl = !empty($this->pdoTools->config['assetsUrl']) ? $this->pdoTools->config['assetsUrl'] : MODX_ASSETS_URL . 'components/pdotools/';
     if ($css = trim($this->pdoTools->config['frontend_css'])) {
         $this->modx->regClientCSS(str_replace('[[+assetsUrl]]', $assetsUrl, $css));
     }
     if ($js = trim($this->pdoTools->config['frontend_js'])) {
         $this->modx->regClientScript(str_replace('[[+assetsUrl]]', $assetsUrl, $js));
     }
     $ajaxHistory = $this->pdoTools->config['ajaxHistory'] === '' ? !in_array($this->pdoTools->config['ajaxMode'], array('scroll', 'button')) : !empty($this->pdoTools->config['ajaxHistory']);
     $limit = $this->pdoTools->config['limit'] > $this->pdoTools->config['maxLimit'] ? $this->pdoTools->config['maxLimit'] : $this->pdoTools->config['limit'];
     $moreChunk = $this->modx->getOption('ajaxTplMore', $this->pdoTools->config, '@INLINE <button class="btn btn-default btn-more">[[%pdopage_more]]</button>');
     $moreTpl = $this->pdoTools->getChunk($moreChunk, array('limit' => $limit));
     $hash = sha1($this->modx->toJSON($this->pdoTools->config));
     $_SESSION['pdoPage'][$hash] = $this->pdoTools->config;
     $config = $this->modx->toJSON(array('wrapper' => $this->modx->getOption('ajaxElemWrapper', $this->pdoTools->config, '#pdopage'), 'rows' => $this->modx->getOption('ajaxElemRows', $this->pdoTools->config, '#pdopage .rows'), 'pagination' => $this->modx->getOption('ajaxElemPagination', $this->pdoTools->config, '#pdopage .pagination'), 'link' => $this->modx->getOption('ajaxElemLink', $this->pdoTools->config, '#pdopage .pagination a'), 'more' => $this->modx->getOption('ajaxElemMore', $this->pdoTools->config, '#pdopage .btn-more'), 'moreTpl' => $moreTpl, 'mode' => $this->pdoTools->config['ajaxMode'], 'history' => (int) $ajaxHistory, 'pageVarKey' => $this->pdoTools->config['pageVarKey'], 'pageLimit' => $limit, 'assetsUrl' => $assetsUrl, 'connectorUrl' => rtrim($assetsUrl, '/') . '/connector.php', 'pageId' => $this->modx->resource->id, 'hash' => $hash));
     $this->modx->regClientStartupScript('<script type="text/javascript">pdoPage = {callbacks: {}, keys: {}, configs: {}};</script>', true);
     $this->modx->regClientScript('<script type="text/javascript">pdoPage.initialize(' . $config . ');</script>', true);
 }
        /**
         * Gets the challenge HTML (javascript and non-javascript version).
         * This is called from the browser, and the resulting reCAPTCHA HTML widget
         * is embedded within the HTML form it was called from.
         *
         * @param array $scriptProperties
         * @return string - The HTML to be embedded in the user's form.
         */
        public function render($scriptProperties = array())
        {
            if (empty($this->config[FormItReCaptcha::OPT_PUBLIC_KEY])) {
                return $this->error($this->modx->lexicon('recaptcha.no_api_key'));
            }
            /* use ssl or not */
            $server = !empty($this->config[FormItReCaptcha::OPT_USE_SSL]) ? FormItReCaptcha::API_SECURE_SERVER : FormItReCaptcha::API_SERVER;
            $opt = $this->getOptions($scriptProperties);
            $html = '<script type="text/javascript">var RecaptchaOptions = ' . $this->modx->toJSON($opt) . ';</script><script type="text/javascript" src="' . $server . 'challenge?k=' . $this->config[FormItReCaptcha::OPT_PUBLIC_KEY] . '"></script>
<noscript><div>
        <object data="' . $server . 'noscript?k=' . $this->config[FormItReCaptcha::OPT_PUBLIC_KEY] . '" height="' . $opt['height'] . '" width="' . $opt['width'] . '" style="width: ' . $opt['width'] . 'px; height: ' . $opt['height'] . 'px;"></object>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/></div>
</noscript>';
            $this->modx->setPlaceholder('formit.recaptcha_html', $html);
            $this->modx->setPlaceholder($scriptProperties['placeholderPrefix'] . 'recaptcha_html', $html);
            return $html;
        }
Example #6
0
 /**
  * Sets the fields to MODX placeholders
  * @return void
  */
 public function setFieldsAsPlaceholders()
 {
     $fields = $this->dictionary->toArray();
     /* better handling of checkbox values when input name is an array[] */
     $fs = array();
     /** @var mixed $v */
     foreach ($fields as $k => $v) {
         if (is_array($v) && !isset($_FILES[$k])) {
             foreach ($v as $sk => $sv) {
                 $fs[$k . '.' . $sk] = $this->convertMODXTags($sv);
             }
             $v = $this->modx->toJSON($v);
         }
         /* str_replace to prevent showing of placeholders */
         $fs[$k] = $this->convertMODXTags($v);
     }
     $this->modx->setPlaceholders($fs, $this->config['placeholderPrefix']);
 }
Example #7
0
 /**
  * @param modManagerController $controller
  * @param array                $opts
  */
 public function loadControllerFiles(modManagerController $controller, array $opts = array())
 {
     $config = $this->config;
     $config['connector_url'] = $this->config['connectorUrl'];
     $config['fields_grid_domain'] = $this->getDomainGridFields();
     if (!empty($opts['css'])) {
         $controller->addCss($this->config['cssUrl'] . 'mgr/main.css');
         $controller->addCss($this->config['cssUrl'] . 'mgr/bootstrap.buttons.css');
     }
     if (!empty($opts['config'])) {
         $controller->addHtml("<script type='text/javascript'>subdomainsfolder.config={$this->modx->toJSON($config)}</script>");
     }
     if (!empty($opts['tools'])) {
         $controller->addJavascript($this->config['jsUrl'] . 'mgr/subdomainsfolder.js');
         $controller->addJavascript($this->config['jsUrl'] . 'mgr/misc/tools.js');
         $controller->addJavascript($this->config['jsUrl'] . 'mgr/misc/combo.js');
     }
     if (!empty($opts['domain'])) {
         $controller->addLastJavascript($this->config['jsUrl'] . 'mgr/domain/domain.window.js');
         $controller->addLastJavascript($this->config['jsUrl'] . 'mgr/domain/domain.grid.js');
         $controller->addLastJavascript($this->config['jsUrl'] . 'mgr/domain/domain.panel.js');
     }
 }
 /** @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();
 }
Example #9
0
if (!defined('MODX_CORE_PATH')) {
    define('MODX_CORE_PATH', dirname(dirname(__FILE__)) . '/core/');
}
if (!(include_once MODX_CORE_PATH . 'model/modx/modx.class.php')) {
    die;
}
$modx = new modX('', array(xPDO::OPT_CONN_INIT => array(xPDO::OPT_CONN_MUTABLE => true)));
/* initialize the proper context */
$ctx = isset($_REQUEST['ctx']) && !empty($_REQUEST['ctx']) ? $_REQUEST['ctx'] : 'mgr';
$modx->initialize($ctx);
if (defined('MODX_REQP') && MODX_REQP === false) {
} else {
    if (!is_object($modx->context) || !$modx->context->checkPolicy('load')) {
        header("Content-Type: application/json; charset=UTF-8");
        header('HTTP/1.1 401 Not Authorized');
        echo $modx->toJSON(array('success' => false, 'code' => 401));
        @session_write_close();
        die;
    }
}
if ($ctx == 'mgr') {
    $ml = $modx->getOption('manager_language', null, 'en');
    if ($ml != 'en') {
        $modx->lexicon->load($ml . ':core:default');
        $modx->setOption('cultureKey', $ml);
    }
}
/* handle the request */
$connectorRequestClass = $modx->getOption('modConnectorRequest.class', null, 'modConnectorRequest');
$modx->config['modRequest.class'] = $connectorRequestClass;
$modx->getRequest();
Example #10
0
        SELECT
            *
        FROM ' . $discuss->import->getFullTableName('attachments') . '
        WHERE
            `ID_MSG` != 0
    ');
    if (!$ast) {
        return array();
    }
    $aIdx = 0;
    while ($arow = $ast->fetch(PDO::FETCH_ASSOC)) {
        $post = $modx->getObject('disPost', array('integrated_id' => $arow['ID_MSG']));
        if ($post) {
            $discuss->import->log('Adding attachment: ' . $arow['filename']);
            $attachment = $modx->newObject('disPostAttachment');
            $attachment->fromArray(array('post' => $post->get('id'), 'board' => $post->get('board'), 'filename' => $arow['filename'], 'filesize' => $arow['size'], 'downloads' => $arow['downloads'], 'integrated_id' => $arow['ID_ATTACH'], 'integrated_data' => $modx->toJSON(array('filename' => $arow['filename'], 'file_hash' => $arow['file_hash'], 'width' => $arow['width'], 'height' => $arow['height'], 'attachmentType' => $arow['attachmentType'], 'ID_MEMBER' => $arow['ID_MEMBER'], 'ID_MSG' => $arow['ID_MSG'], 'ID_THUMB' => $arow['ID_THUMB']))));
            $attachment->save();
            $aIdx++;
        }
    }
    $ast->closeCursor();
} else {
    $modx->log(xPDO::LOG_LEVEL_ERROR, 'Failed to load Import class.');
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
$modx->log(modX::LOG_LEVEL_INFO, "\nExecution time: {$totalTime}\n");
 /**
  * Get the properties on this source
  * @param boolean $parsed
  * @return array
  */
 public function getProperties($parsed = false)
 {
     $properties = $this->get('properties');
     $defaultProperties = $this->getDefaultProperties();
     if (!empty($properties) && is_array($properties)) {
         foreach ($properties as &$property) {
             $property['overridden'] = 0;
             if (array_key_exists($property['name'], $defaultProperties)) {
                 if ($defaultProperties[$property['name']]['value'] != $property['value']) {
                     $property['overridden'] = 1;
                 }
             } else {
                 $property['overridden'] = 2;
             }
         }
         $properties = array_merge($defaultProperties, $properties);
     } else {
         $properties = $defaultProperties;
     }
     /** @var array $results Allow manipulation of media source properties via event */
     $results = $this->xpdo->invokeEvent('OnMediaSourceGetProperties', array('properties' => $this->xpdo->toJSON($properties)));
     if (!empty($results)) {
         foreach ($results as $result) {
             $result = is_array($result) ? $result : $this->xpdo->fromJSON($result);
             $properties = array_merge($properties, $result);
         }
     }
     if ($parsed) {
         $properties = $this->parseProperties($properties);
     }
     return $this->prepareProperties($properties);
 }
Example #12
0
                 }
                 if (strpos($path, $core_path) === 0) {
                     $path = str_replace($core_path, '[[++core_path]]', $path);
                 } elseif (strpos($path, $assets_path) === 0) {
                     $path = str_replace($assets_path, '[[++assets_path]]', $path);
                 } elseif (strpos($path, $manager_path) === 0) {
                     $path = str_replace($manager_path, '[[++manager_path]]', $path);
                 } elseif (strpos($path, $base_path) === 0) {
                     $path = str_replace($base_path, '[[++base_path]]', $path);
                 }
                 $pkg['path'] = $path;
             }
         }
     }
     $modx->log(modX::LOG_LEVEL_INFO, "Setting extension packages to: " . print_r($extPackages, true));
     $object->set('value', $modx->toJSON($extPackages));
     $package->put($object, array_merge($attributes, array('resolve' => array(array('type' => 'php', 'source' => VAPOR_DIR . 'scripts/resolve.extension_packages.php')))));
 }
 /* loop through the classes and package the objects */
 foreach ($classes as $class) {
     if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $instances = 0;
     $classCriteria = null;
     $classAttributes = $attributes;
     switch ($class) {
         case 'modSession':
             /* skip sessions */
             continue 2;
         case 'modSystemSetting':
   /**
    * @param modManagerController $controller
    * @param modResource $resource
    */
   public function loadManagerFiles(modManagerController $controller, modResource $resource)
   {
       $modx23 = (int) $this->systemVersion();
       $cssUrl = $this->config['cssUrl'] . 'mgr/';
       $jsUrl = $this->config['jsUrl'] . 'mgr/';
       $properties = $resource->getProperties('ms2gallery');
       if (empty($properties['media_source'])) {
           if (!($source_id = $resource->getTVValue('ms2Gallery'))) {
               /** @var modContextSetting $setting */
               $setting = $this->modx->getObject('modContextSetting', array('key' => 'ms2gallery_source_default', 'context_key' => $resource->get('context_key')));
               $source_id = !empty($setting) ? $setting->get('value') : $this->modx->getOption('ms2gallery_source_default');
           }
           $resource->setProperties(array('media_source' => $source_id), 'ms2gallery');
           $resource->save();
       } else {
           $source_id = $properties['media_source'];
       }
       if (empty($source_id)) {
           $source_id = $this->modx->getOption('ms2gallery_source_default');
       }
       $resource->set('media_source', $source_id);
       $controller->addLexiconTopic('ms2gallery:default');
       $controller->addJavascript($jsUrl . 'ms2gallery.js');
       $controller->addLastJavascript($jsUrl . 'misc/ms2.combo.js');
       $controller->addLastJavascript($jsUrl . 'misc/ms2.utils.js');
       $controller->addLastJavascript($jsUrl . 'misc/plupload/plupload.full.js');
       $controller->addLastJavascript($jsUrl . 'misc/ext.ddview.js');
       $controller->addLastJavascript($jsUrl . 'gallery.view.js');
       $controller->addLastJavascript($jsUrl . 'gallery.window.js');
       $controller->addLastJavascript($jsUrl . 'gallery.toolbar.js');
       $controller->addLastJavascript($jsUrl . 'gallery.panel.js');
       $controller->addCss($cssUrl . 'main.css');
       if (!$modx23) {
           $controller->addCss($cssUrl . 'font-awesome.min.css');
       }
       $source_config = array();
       /** @var modMediaSource $source */
       if ($source = $this->modx->getObject('modMediaSource', $source_id)) {
           $tmp = $source->getProperties();
           foreach ($tmp as $v) {
               $source_config[$v['name']] = $v['value'];
           }
       }
       $controller->addHtml('
	<script type="text/javascript">
		MODx.modx23 = ' . $modx23 . ';
		ms2Gallery.config = ' . $this->modx->toJSON($this->config) . ';
		ms2Gallery.config.media_source = ' . $this->modx->toJSON($source_config) . ';
	</script>');
       if ($this->modx->getOption('ms2gallery_new_tab_mode', null, true)) {
           $controller->addLastJavascript($jsUrl . 'tab.js');
       } else {
           $insert = '
			tabs.add({
				xtype: "ms2gallery-page",
				id: "ms2gallery-page",
				title: _("ms2gallery"),
				record: {
					id: ' . $resource->get('id') . ',
					source: ' . $source_id . ',
				}
			});
		';
           if ($this->modx->getCount('modPlugin', array('name' => 'AjaxManager', 'disabled' => false))) {
               $controller->addHtml('
			<script type="text/javascript">
				Ext.onReady(function() {
					window.setTimeout(function() {
						var tabs = Ext.getCmp("modx-resource-tabs");
						if (tabs) {
							' . $insert . '
						}
					}, 10);
				});
			</script>');
           } else {
               $controller->addHtml('
			<script type="text/javascript">
				Ext.ComponentMgr.onAvailable("modx-resource-tabs", function() {
					var tabs = this;
					tabs.on("beforerender", function() {
						' . $insert . '
					});
				});
			</script>');
           }
       }
   }
Example #14
0
 /**
  * This method returns an success of the order
  *
  * @param string $message A lexicon key for success message
  * @param array $data.Additional data, for example cart status
  * @param array $placeholders Array with placeholders for lexicon entry
  *
  * @return array|string $response
  */
 public function success($message = '', $data = array(), $placeholders = array())
 {
     $response = array('success' => true, 'message' => $this->modx->lexicon($message, $placeholders), 'data' => $data);
     return $this->config['json_response'] ? $this->modx->toJSON($response) : $response;
 }
Example #15
0
 public function process()
 {
     //$startTime = microtime(true);
     try {
         $vaporOptions = array('excludeExtraTablePrefix' => array(), 'excludeExtraTables' => array(), 'excludeFiles' => array(MODX_BASE_PATH . 'vapor', MODX_BASE_PATH . 'phpmyadmin', MODX_BASE_PATH . 'assets', MODX_BASE_PATH . 'core'));
         if (is_readable(VAPOR_DIR . 'config.php')) {
             $vaporConfigOptions = @(include VAPOR_DIR . 'config.php');
             if (is_array($vaporConfigOptions)) {
                 $vaporOptions = array_merge($vaporOptions, $vaporConfigOptions);
             }
         }
         if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
             set_time_limit(0);
         }
         $options = array('log_level' => xPDO::LOG_LEVEL_INFO, 'log_target' => array('target' => 'FILE', 'options' => array('filename' => 'vapor-' . strftime('%Y%m%dT%H%M%S', $this->getProperty('startTime')) . '.log')), xPDO::OPT_CACHE_DB => false, xPDO::OPT_SETUP => true);
         $modx = new modX('', $options);
         $modx->setLogTarget($options['log_target']);
         $modx->setLogLevel($options['log_level']);
         $modx->setOption(xPDO::OPT_CACHE_DB, false);
         $modx->setOption(xPDO::OPT_SETUP, true);
         $modx->setDebug(-1);
         $modx->startTime = $this->getProperty('startTime');
         $modx->getVersionData();
         $modxVersion = $modx->version['full_version'];
         if (version_compare($modxVersion, '2.2.1-pl', '>=')) {
             $modx->initialize('mgr', $options);
         } else {
             $modx->initialize('mgr');
         }
         /*$modx->setLogTarget($options['log_target']);
           $modx->setLogLevel($options['log_level']);*/
         $modx->setOption(xPDO::OPT_CACHE_DB, false);
         $modx->setOption(xPDO::OPT_SETUP, true);
         $modx->setDebug(-1);
         $modxDatabase = $modx->getOption('dbname', $options, $modx->getOption('database', $options));
         $modxTablePrefix = $modx->getOption('table_prefix', $options, '');
         $core_path = realpath($modx->getOption('core_path', $options, MODX_CORE_PATH)) . '/';
         $assets_path = realpath($modx->getOption('assets_path', $options, MODX_ASSETS_PATH)) . '/';
         $manager_path = realpath($modx->getOption('manager_path', $options, MODX_MANAGER_PATH)) . '/';
         $base_path = realpath($modx->getOption('base_path', $options, MODX_BASE_PATH)) . '/';
         $modx->log(modX::LOG_LEVEL_INFO, "core_path=" . $core_path);
         $modx->log(modX::LOG_LEVEL_INFO, "assets_path=" . $assets_path);
         $modx->log(modX::LOG_LEVEL_INFO, "manager_path=" . $manager_path);
         $modx->log(modX::LOG_LEVEL_INFO, "base_path=" . $base_path);
         $modx->loadClass('transport.modPackageBuilder', '', false, true);
         $builder = new modPackageBuilder($modx);
         /** @var modWorkspace $workspace */
         $workspace = $modx->getObject('modWorkspace', 1);
         if (!$workspace) {
             $modx->log(modX::LOG_LEVEL_FATAL, "no workspace!");
         }
         $package = $builder->createPackage(PKG_NAME, PKG_VERSION, PKG_RELEASE);
         /* Defines the classes to extract (also used for truncation) */
         $classes = $this->getClassesList();
         $attributes = array('vehicle_class' => 'xPDOFileVehicle');
         /* get all files from the components directory */
         /*$modx->log(modX::LOG_LEVEL_INFO, "Packaging " . MODX_CORE_PATH . 'components');
           $package->put(
               array(
                   'source' => MODX_CORE_PATH . 'components',
                   'target' => 'return MODX_CORE_PATH;'
               ),
               array(
                   'vehicle_class' => 'xPDOFileVehicle'
               )
           );*/
         /* get all files from the assets directory */
         /*$modx->log(modX::LOG_LEVEL_INFO, "Packaging " . MODX_BASE_PATH . 'assets');
           $package->put(
               array(
                   'source' => MODX_BASE_PATH . 'assets',
                   'target' => 'return MODX_BASE_PATH;'
               ),
               array(
                   'vehicle_class' => 'xPDOFileVehicle'
               )
           );*/
         /* get all files from the manager/components directory */
         /*$modx->log(modX::LOG_LEVEL_INFO, "Packaging " . MODX_MANAGER_PATH . 'components');
           $package->put(
               array(
                   'source' => MODX_MANAGER_PATH . 'components',
                   'target' => 'return MODX_MANAGER_PATH;'
               ),
               array(
                   'vehicle_class' => 'xPDOFileVehicle'
               )
           );*/
         /* find other files/directories in the MODX_BASE_PATH */
         $excludes = array('_build', 'setup', 'assets', 'ht.access', 'index.php', 'config.core.php', dirname(MODX_CORE_PATH) . '/' === MODX_BASE_PATH ? basename(MODX_CORE_PATH) : 'core', dirname(MODX_CONNECTORS_PATH) . '/' === MODX_BASE_PATH ? basename(MODX_CONNECTORS_PATH) : 'connectors', dirname(MODX_MANAGER_PATH) . '/' === MODX_BASE_PATH ? basename(MODX_MANAGER_PATH) : 'manager');
         if (isset($vaporOptions['excludeFiles']) && is_array($vaporOptions['excludeFiles'])) {
             $excludes = array_unique($excludes + $vaporOptions['excludeFiles']);
         }
         /*if ($dh = opendir(MODX_BASE_PATH)) {
           $includes = array();
           while (($file = readdir($dh)) !== false) {
               /* ignore files/dirs starting with . or matching an exclude */
         /*if (strpos($file, '.') === 0 || in_array(strtolower($file), $excludes)) {
                       continue;
                   }
                   $includes[] = array(
                       'source' => MODX_BASE_PATH . $file,
                       'target' => 'return MODX_BASE_PATH;'
                   );
               }
               closedir($dh);
               foreach ($includes as $include) {
                   $modx->log(modX::LOG_LEVEL_INFO, "Packaging " . $include['source']);
                   $package->put(
                       $include,
                       array(
                           'vehicle_class' => 'xPDOFileVehicle'
                       )
                   );
               }
           }*/
         foreach ($this->getProperty('sources') as $source_id) {
             // Try to get mediaSource
             $loaded = $this->getSource($source_id);
             if ($loaded !== true) {
                 return $this->failure($loaded);
             }
             /* Why for??
                if (!$this->source->checkPolicy('delete')) {
                    return $this->failure($this->modx->lexicon('permission_denied'));
                }*/
             if ($properties = $this->source->getBases('') and $properties['pathIsRelative'] and $path = $properties['path']) {
                 if ($dh = opendir(MODX_BASE_PATH . $path)) {
                     $includes = array();
                     while (($file = readdir($dh)) !== false) {
                         /* ignore files/dirs starting with . or matching an exclude */
                         if (strpos($file, '.') === 0 || in_array(strtolower($file), $excludes)) {
                             continue;
                         }
                         $includes[] = array('source' => MODX_BASE_PATH . $path . $file, 'target' => "return MODX_BASE_PATH . '{$path}/';");
                     }
                     closedir($dh);
                     foreach ($includes as $include) {
                         $modx->log(modX::LOG_LEVEL_INFO, "Packaging " . $include['source']);
                         $package->put($include, array('vehicle_class' => 'xPDOFileVehicle'));
                     }
                 }
             }
         }
         if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
             set_time_limit(0);
         }
         /* package up the vapor model for use on install */
         $modx->log(modX::LOG_LEVEL_INFO, "Packaging vaporVehicle class");
         /*$package->put(
               array(
                   'source' => VAPOR_DIR . 'model/vapor',
                   'target' => "return MODX_CORE_PATH . 'components/vapor/model/';"
               ),
               array(
                   'vehicle_class' => 'xPDOFileVehicle',
                   'validate' => array(
                       array(
                           'type' => 'php',
                           'source' => VAPOR_DIR . 'scripts/validate.truncate_tables.php',
                           'classes' => $classes
                       ),
                   ),
                   'resolve' => array(
                       array(
                           'type' => 'php',
                           'source' => VAPOR_DIR . 'scripts/resolve.vapor_model.php'
                       )
                   )
               )
           );*/
         $attributes = array('preserve_keys' => true, 'update_object' => true);
         /* get the extension_packages and resolver */
         if ($this->getProperty('includeExtensionPackages')) {
             $object = $modx->getObject('modSystemSetting', array('key' => 'extension_packages'));
             if ($object) {
                 $extPackages = $object->get('value');
                 $extPackages = $modx->fromJSON($extPackages);
                 foreach ($extPackages as &$extPackage) {
                     if (!is_array($extPackage)) {
                         continue;
                     }
                     foreach ($extPackage as $pkgName => &$pkg) {
                         if (!empty($pkg['path']) && strpos($pkg['path'], '[[++') === false) {
                             if (substr($pkg['path'], 0, 1) !== '/' || strpos($pkg['path'], $base_path) !== 0 && strpos($pkg['path'], $core_path) !== 0) {
                                 $path = realpath($pkg['path']);
                                 if ($path === false) {
                                     $path = $pkg['path'];
                                 } else {
                                     $path = rtrim($path, '/') . '/';
                                 }
                             } else {
                                 $path = $pkg['path'];
                             }
                             if (strpos($path, $core_path) === 0) {
                                 $path = str_replace($core_path, '[[++core_path]]', $path);
                             } elseif (strpos($path, $assets_path) === 0) {
                                 $path = str_replace($assets_path, '[[++assets_path]]', $path);
                             } elseif (strpos($path, $manager_path) === 0) {
                                 $path = str_replace($manager_path, '[[++manager_path]]', $path);
                             } elseif (strpos($path, $base_path) === 0) {
                                 $path = str_replace($base_path, '[[++base_path]]', $path);
                             }
                             $pkg['path'] = $path;
                         }
                     }
                 }
                 $modx->log(modX::LOG_LEVEL_INFO, "Setting extension packages to: " . print_r($extPackages, true));
                 $object->set('value', $modx->toJSON($extPackages));
                 $package->put($object, array_merge($attributes, array('resolve' => array(array('type' => 'php', 'source' => VAPOR_DIR . 'scripts/resolve.extension_packages.php')))));
             }
         }
         /* loop through the classes and package the objects */
         foreach ($classes as $class) {
             if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
                 set_time_limit(0);
             }
             $instances = 0;
             $classCriteria = null;
             $classAttributes = $attributes;
             switch ($class) {
                 case 'modSession':
                     /* skip sessions */
                     continue 2;
                 case 'modSystemSetting':
                     $classCriteria = array('key:!=' => 'extension_packages');
                     break;
                 case 'modWorkspace':
                     /** @var modWorkspace $object */
                     foreach ($modx->getIterator('modWorkspace', $classCriteria) as $object) {
                         if (strpos($object->path, $core_path) === 0) {
                             $object->set('path', str_replace($core_path, '{core_path}', $object->path));
                         } elseif (strpos($object->path, $assets_path) === 0) {
                             $object->set('path', str_replace($assets_path, '{assets_path}', $object->path));
                         } elseif (strpos($object->path, $manager_path) === 0) {
                             $object->set('path', str_replace($manager_path, '{manager_path}', $object->path));
                         } elseif (strpos($object->path, $base_path) === 0) {
                             $object->set('path', str_replace($base_path, '{base_path}', $object->path));
                         }
                         if ($package->put($object, $classAttributes)) {
                             $instances++;
                         } else {
                             $modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey(), true));
                         }
                     }
                     $modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
                     continue 2;
                 case 'transport.modTransportPackage':
                     $modx->loadClass($class);
                     $response = $modx->call('modTransportPackage', 'listPackages', array(&$modx, $workspace->get('id')));
                     if (isset($response['collection'])) {
                         foreach ($response['collection'] as $object) {
                             $packagesDir = MODX_CORE_PATH . 'packages/';
                             if ($object->getOne('Workspace')) {
                                 $packagesDir = $object->Workspace->get('path') . 'packages/';
                             }
                             $pkgSource = $object->get('source');
                             $folderPos = strrpos($pkgSource, '/');
                             $sourceDir = $folderPos > 1 ? substr($pkgSource, 0, $folderPos + 1) : '';
                             $source = realpath($packagesDir . $pkgSource);
                             $target = 'MODX_CORE_PATH . "packages/' . $sourceDir . '"';
                             $classAttributes = array_merge($attributes, array('resolve' => array(array('type' => 'file', 'source' => $source, 'target' => "return {$target};"))));
                             if ($package->put($object, $classAttributes)) {
                                 $instances++;
                             } else {
                                 $modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey(), true));
                             }
                         }
                     }
                     $modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
                     continue 2;
                 case 'sources.modMediaSource':
                     foreach ($modx->getIterator('sources.modMediaSource') as $object) {
                         $classAttributes = $attributes;
                         /** @var modMediaSource $object */
                         if ($object->get('is_stream') && $object->initialize()) {
                             $sourceBases = $object->getBases('');
                             $source = $object->getBasePath();
                             if (!$sourceBases['pathIsRelative'] && strpos($source, '://') === false) {
                                 $sourceBasePath = $source;
                                 if (strpos($source, $base_path) === 0) {
                                     $sourceBasePath = str_replace($base_path, '', $sourceBasePath);
                                     $classAttributes['resolve'][] = array('type' => 'php', 'source' => VAPOR_DIR . 'scripts/resolve.media_source.php', 'target' => $sourceBasePath, 'targetRelative' => true);
                                 } else {
                                     /* when coming from Windows sources, remove "{volume}:" */
                                     if (strpos($source, ':\\') !== false || strpos($source, ':/') !== false) {
                                         $sourceBasePath = str_replace('\\', '/', substr($source, strpos($source, ':') + 1));
                                     }
                                     $target = 'dirname(MODX_BASE_PATH) . "/sources/' . ltrim(dirname($sourceBasePath), '/') . '/"';
                                     $classAttributes['resolve'][] = array('type' => 'file', 'source' => $source, 'target' => "return {$target};");
                                     $classAttributes['resolve'][] = array('type' => 'php', 'source' => VAPOR_DIR . 'scripts/resolve.media_source.php', 'target' => $sourceBasePath, 'targetRelative' => false, 'targetPrepend' => "return dirname(MODX_BASE_PATH) . '/sources/';");
                                 }
                             }
                         }
                         if ($package->put($object, $classAttributes)) {
                             $instances++;
                         } else {
                             $modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey(), true));
                         }
                     }
                     $modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
                     continue 2;
                 default:
                     break;
             }
             /** @var xPDOObject $object */
             foreach ($modx->getIterator($class, $classCriteria) as $object) {
                 if ($package->put($object, $classAttributes)) {
                     $instances++;
                 } else {
                     $modx->log(modX::LOG_LEVEL_WARN, "Could not package {$class} instance with pk: " . print_r($object->getPrimaryKey(), true));
                 }
             }
             $modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} of {$class}");
         }
         /* collect table names from classes and grab any additional tables/data not listed */
         $coreTables = array();
         $extraTables = array();
         foreach ($classes as $class) {
             $coreTables[$class] = $modx->quote($modx->literal($modx->getTableName($class)));
         }
         if ($coreTables) {
             $stmt = $modx->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '{$modxDatabase}' AND TABLE_NAME NOT IN (" . implode(',', $coreTables) . ")");
             $extraTables = $stmt->fetchAll(PDO::FETCH_COLUMN);
         }
         if (is_array($extraTables) && !empty($extraTables)) {
             //$modx->loadClass('vapor.vaporVehicle', VAPOR_DIR . 'model/', true, true);
             $modx->loadClass('vapor.vaporVehicle', VAPOR_DIR, true, true);
             $excludeExtraTablePrefix = isset($vaporOptions['excludeExtraTablePrefix']) && is_array($vaporOptions['excludeExtraTablePrefix']) ? $vaporOptions['excludeExtraTablePrefix'] : array();
             $excludeExtraTables = isset($vaporOptions['excludeExtraTables']) && is_array($vaporOptions['excludeExtraTables']) ? $vaporOptions['excludeExtraTables'] : array();
             foreach ($extraTables as $extraTable) {
                 if (in_array($extraTable, $excludeExtraTables)) {
                     continue;
                 }
                 if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
                     set_time_limit(0);
                 }
                 $instances = 0;
                 $object = array();
                 $attributes = array('vehicle_package' => 'vapor', 'vehicle_class' => 'vaporVehicle');
                 /* remove modx table_prefix if table starts with it */
                 $extraTableName = $extraTable;
                 if (!empty($modxTablePrefix) && strpos($extraTableName, $modxTablePrefix) === 0) {
                     $extraTableName = substr($extraTableName, strlen($modxTablePrefix));
                     $addTablePrefix = true;
                 } elseif (!empty($modxTablePrefix) || in_array($extraTableName, $excludeExtraTablePrefix)) {
                     $addTablePrefix = false;
                 } else {
                     $addTablePrefix = true;
                 }
                 $object['tableName'] = $extraTableName;
                 $modx->log(modX::LOG_LEVEL_INFO, "Extracting non-core table {$extraTableName}");
                 /* generate the CREATE TABLE statement */
                 $stmt = $modx->query("SHOW CREATE TABLE {$modx->escape($extraTable)}");
                 $resultSet = $stmt->fetch(PDO::FETCH_NUM);
                 $stmt->closeCursor();
                 if (isset($resultSet[1])) {
                     if ($addTablePrefix) {
                         $object['drop'] = "DROP TABLE IF EXISTS {$modx->escape('[[++table_prefix]]' . $extraTableName)}";
                         $object['table'] = str_replace("CREATE TABLE {$modx->escape($extraTable)}", "CREATE TABLE {$modx->escape('[[++table_prefix]]' . $extraTableName)}", $resultSet[1]);
                     } else {
                         $object['drop'] = "DROP TABLE IF EXISTS {$modx->escape($extraTableName)}";
                         $object['table'] = $resultSet[1];
                     }
                     /* collect the rows and generate INSERT statements */
                     $object['data'] = array();
                     $stmt = $modx->query("SELECT * FROM {$modx->escape($extraTable)}");
                     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                         if ($instances === 0) {
                             $fields = implode(', ', array_map(array($modx, 'escape'), array_keys($row)));
                         }
                         $values = array();
                         while (list($key, $value) = each($row)) {
                             switch (gettype($value)) {
                                 case 'string':
                                     $values[] = $modx->quote($value);
                                     break;
                                 case 'NULL':
                                 case 'array':
                                 case 'object':
                                 case 'resource':
                                 case 'unknown type':
                                     $values[] = 'NULL';
                                     break;
                                 default:
                                     $values[] = (string) $value;
                                     break;
                             }
                         }
                         $values = implode(', ', $values);
                         if ($addTablePrefix) {
                             $object['data'][] = "INSERT INTO {$modx->escape('[[++table_prefix]]' . $extraTableName)} ({$fields}) VALUES ({$values})";
                         } else {
                             $object['data'][] = "INSERT INTO {$modx->escape($extraTable)} ({$fields}) VALUES ({$values})";
                         }
                         $instances++;
                     }
                 }
                 if (!$package->put($object, $attributes)) {
                     $modx->log(modX::LOG_LEVEL_WARN, "Could not package rows for table {$extraTable}: " . print_r($object, true));
                 } else {
                     $modx->log(modX::LOG_LEVEL_INFO, "Packaged {$instances} rows for table {$extraTable}");
                 }
             }
         }
         if (!XPDO_CLI_MODE && !ini_get('safe_mode')) {
             set_time_limit(0);
         }
         if (!$package->pack()) {
             $message = "Error extracting package, could not pack transport: {$package->signature}";
             $modx->log(modX::LOG_LEVEL_ERROR, $message);
             //echo "{$message}\n";
         } else {
             $message = "Completed extracting package: {$package->signature}";
             $modx->log(modX::LOG_LEVEL_INFO, $message);
             //echo "{$message}\n";
         }
         $endTime = microtime(true);
         $msg = sprintf("Vapor execution completed without exception in %2.4fs", $endTime - $this->getProperty('startTime'));
         $modx->log(modX::LOG_LEVEL_INFO, $msg);
         return $this->success($msg, array('signature' => $package->signature));
     } catch (Exception $e) {
         if (empty($endTime)) {
             $endTime = microtime(true);
         }
         if (!empty($modx)) {
             $modx->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
             $msg = sprintf("Vapor execution completed with exception in %2.4fs", $endTime - $this->getProperty('startTime'));
             $modx->log(modX::LOG_LEVEL_INFO, $msg);
             return $this->failure($msg);
         } else {
             //echo $e->getMessage() . "\n";
         }
         $msg = sprintf("Vapor execution completed with exception in %2.4fs\n", $endTime - $this->getProperty('startTime'));
         $modx->log(modX::LOG_LEVEL_INFO, $msg);
         return $this->failure($msg);
     }
     return $modx->success(printf("Vapor execution completed without exception in %2.4fs\n", $endTime - $this->getProperty('startTime')));
 }
Example #16
0
 /**
  * @param $config
  */
 public function getBreadCrumbs($config)
 {
     $mode = $this->modx->getOption('mode', $config);
     $resource = $this->modx->getOption('resource', $config);
     if ($mode === modSystemEvent::MODE_NEW || !$resource) {
         if (!isset($_GET['parent'])) {
             return;
         }
         $resource = $this->modx->getObject('modResource', $_GET['parent']);
         if (!$resource) {
             return;
         }
     }
     $context = $resource->get('context_key');
     if ($context != 'web') {
         $this->modx->reloadContext($context);
     }
     /** @TODO Prepare as System Setting */
     $limit = 3;
     $resources = $this->modx->getParentIds($resource->get('id'), $limit, array('context' => $context));
     if ($mode === modSystemEvent::MODE_NEW) {
         array_unshift($resources, $_GET['parent']);
     }
     $crumbs = array();
     $root = $this->modx->toJSON(array('text' => $context, 'className' => 'first', 'root' => true, 'url' => '?'));
     $controllerConfig = $this->modx->controller->config;
     $action = $controllerConfig['controller'];
     if ($action == 'resource/create') {
         $action = 'resource/update';
     }
     if (isset($controllerConfig['id'])) {
         if ($controllerConfig['controller'] == 'resource/create') {
             $actionObj = $this->modx->getObject('modAction', array('controller' => 'resource/update'));
             $action = $actionObj->get('id');
         } else {
             $action = $controllerConfig['id'];
         }
     }
     $isAll = false;
     for ($i = count($resources) - 1; $i >= 0; $i--) {
         $resId = $resources[$i];
         if ($resId == 0) {
             continue;
         }
         $parent = $this->modx->getObject('modResource', $resId);
         if (!$parent) {
             break;
         }
         if ($parent->get('parent') == 0) {
             $isAll = true;
         }
         $crumbs[] = array('text' => $parent->get('pagetitle'), 'url' => '?a=' . $action . '&id=' . $parent->get('id'));
     }
     if (count($resources) == $limit && !$isAll) {
         array_unshift($crumbs, array('text' => '...'));
     }
     // Add pagetitle of current page
     if ($mode === modSystemEvent::MODE_NEW) {
         $pagetitle = $this->modx->lexicon('new_document');
     } else {
         $pagetitle = $resource->get('pagetitle');
     }
     $crumbs[] = array('text' => $pagetitle);
     $crumbs = $this->modx->toJSON($crumbs);
     $this->modx->controller->addJavascript($this->config['jsUrl'] . 'mgr/moddevtools.js');
     $this->modx->controller->addJavascript($this->config['jsUrl'] . 'mgr/widgets/breadcrumbs.panel.js');
     $this->modx->controller->addHtml("<script>\n            Ext.onReady(function() {\n                var header = Ext.getCmp('modx-resource-header').ownerCt;\n                header.insert(1, {\n                    xtype: 'moddevtools-breadcrumbs-panel'\n                    ,id: 'resource-breadcrumbs'\n                    ,desc: ''\n                    ,root : {$root}\n                });\n                header.doLayout();\n\n                var crumbCmp = Ext.getCmp('resource-breadcrumbs');\n                var bd = { trail : {$crumbs}};\n\t\t        crumbCmp.updateDetail(bd);\n\n\t\t        Ext.getCmp('modx-resource-pagetitle').on('keyup', function(){\n                    bd.trail[bd.trail.length-1] = {text: crumbCmp.getPagetitle()};\n                    crumbCmp._updatePanel(bd);\n                });\n            });\n            </script>");
 }
    /**
     * Get the getPage and getArchives call to display listings of posts on the container.
     *
     * @param string $placeholderPrefix
     * @return string
     */
    public function getPostListingCall($placeholderPrefix = '')
    {
        $settings = $this->getContainerSettings();
        $where = array('class_key' => 'Article');
        if (!empty($_REQUEST['arc_user'])) {
            $userPk = $this->xpdo->sanitizeString($_REQUEST['arc_user']);
            if (intval($userPk) == 0) {
                /** @var modUser $user */
                $user = $this->xpdo->getObject('modUser', array('username' => $userPk));
                if ($user) {
                    $userPk = $user->get('id');
                } else {
                    $userPk = false;
                }
            }
            if ($userPk !== false) {
                $where['createdby:='] = $userPk;
                $this->set('cacheable', false);
            }
        }
        $output = '[[!getPage?
          &elementClass=`modSnippet`
          &element=`getArchives`
          &makeArchive=`0`
          &cache=`1`
          &parents=`' . $this->get('id') . '`
          &where=`' . $this->xpdo->toJSON($where) . '`
          &showHidden=`1`
          &includeContent=`1`
          &includeTVs=`' . $this->xpdo->getOption('archivesIncludeTVs', $settings, 0) . '`
          &includeTVsList=`' . $this->xpdo->getOption('includeTVsList', $settings, '') . '`
          &processTVs=`' . $this->xpdo->getOption('archivesProcessTVs', $settings, 0) . '`
          &processTVsList=`' . $this->xpdo->getOption('processTVsList', $settings, '') . '`
          &tagKey=`articlestags`
          &tagSearchType=`contains`
          &sortby=`' . $this->xpdo->getOption('sortBy', $settings, 'publishedon') . '`
          &sortdir=`' . $this->xpdo->getOption('sortDir', $settings, 'DESC') . '`
          &tpl=`' . $this->xpdo->getOption('tplArticleRow', $settings, 'sample.ArticleRowTpl') . '`

          &limit=`' . $this->xpdo->getOption('articlesPerPage', $settings, 10) . '`
          &pageLimit=`' . $this->xpdo->getOption('pageLimit', $settings, 5) . '`
          &pageVarKey=`' . $this->xpdo->getOption('pageVarKey', $settings, 'page') . '`
          &pageNavVar=`' . $this->xpdo->getOption('pageNavVar', $settings, 'page.nav') . '`
          &totalVar=`' . $this->xpdo->getOption('pageTotalVar', $settings, 'total') . '`
          &offset=`' . $this->xpdo->getOption('pageOffset', $settings, 0) . '`

          &pageNavTpl=`' . $this->xpdo->getOption('pageNavTpl', $settings, '<li[[+classes]]><a[[+classes]][[+title]] href="[[+href]]">[[+pageNo]]</a></li>') . '`
          &pageActiveTpl=`' . $this->xpdo->getOption('pageActiveTpl', $settings, '<li[[+activeClasses]]><a[[+activeClasses:default=` class="active"`]][[+title]] href="[[+href]]">[[+pageNo]]</a></li>') . '`
          &pageFirstTpl=`' . $this->xpdo->getOption('pageFirstTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">First</a></li>') . '`
          &pageLastTpl=`' . $this->xpdo->getOption('pageLastTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">Last</a></li>') . '`
          &pagePrevTpl=`' . $this->xpdo->getOption('pagePrevTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">&lt;&lt;</a></li>') . '`
          &pageNextTpl=`' . $this->xpdo->getOption('pageNextTpl', $settings, '<li class="control"><a[[+classes]][[+title]] href="[[+href]]">&gt;&gt;</a></li>') . '`

          ' . $this->xpdo->getOption('otherGetArchives', $settings, '') . '
        ]]';
        $this->xpdo->setPlaceholder($placeholderPrefix . 'articles', $output);
        $this->xpdo->setPlaceholder($placeholderPrefix . 'paging', '[[!+page.nav:notempty=`
<div class="paging">
<ul class="pageList">
  [[!+page.nav]]
</ul>
</div>
`]]');
        return $output;
    }