/** * 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']); }
/** * Gets tree of resources and template it * * @param array $tree * * @return mixed */ public function templateTree($tree = array()) { $this->tree = $tree; $count = count($tree); $output = ''; $idx = 1; $this->pdoTools->addTime('Start template tree'); foreach ($tree as $row) { if (empty($row['id'])) { continue; } $this->level = 1; $row['idx'] = $idx++; $row['last'] = (int) $row['idx'] == $count; $output .= $this->templateBranch($row); } $this->pdoTools->addTime('End template tree'); if (!empty($output)) { $pls = $this->addWayFinderPlaceholders(array('wrapper' => $output, 'classes' => ' class="' . $this->pdoTools->config['outerClass'] . '"', 'classNames' => $this->pdoTools->config['outerClass'], 'classnames' => $this->pdoTools->config['outerClass'])); $output = $this->pdoTools->parseChunk($this->pdoTools->config['tplOuter'], $pls); } return $output; }
$outer['cart_count'] = 0; $outer['cost'] = $miniShop2->formatPrice($outer['cost']); $outer['cart_cost'] = $miniShop2->formatPrice($outer['cart_cost']); $outer['delivery_cost'] = $miniShop2->formatPrice($outer['delivery_cost']); $outer['weight'] = $miniShop2->formatWeight($outer['weight']); // Include Thumbnails $thumbsLeftJoin = ''; $thumbsSelect = array(); if (!empty($includeThumbs)) { $thumbs = array_map('trim', explode(',', $includeThumbs)); if (!empty($thumbs[0])) { foreach ($thumbs as $thumb) { $thumbsLeftJoin .= ',{"class":"msProductFile","alias":"' . $thumb . '","on":"' . $thumb . '.product_id = msProduct.id AND ' . $thumb . '.parent != 0 AND ' . $thumb . '.path LIKE \'%/' . $thumb . '/\'"}'; $thumbsSelect[] = ' "' . $thumb . '":"' . $thumb . '.url as ' . $thumb . '" '; } $pdoFetch->addTime('Included list of thumbnails: <b>' . implode(', ', $thumbs) . '</b>.'); } } // End of including Thumbnails // Fields to select $resourceColumns = !empty($includeContent) ? $modx->getSelectColumns('msProduct', 'msProduct') : $modx->getSelectColumns('msProduct', 'msProduct', '', array('content'), true); $dataColumns = $modx->getSelectColumns('msProductData', 'Data', '', array('id'), true) . ',`Data`.`price` as `original_price`'; $vendorColumns = $modx->getSelectColumns('msVendor', 'Vendor', 'vendor.', array('id'), true); $orderProductColumns = $modx->getSelectColumns('msOrderProduct', 'msOrderProduct', '', array('id'), true); // Tables for joining $leftJoin = '{"class":"msProduct","alias":"msProduct","on":"msProduct.id=msOrderProduct.product_id"},{"class":"msProductData","alias":"Data","on":"msProduct.id=Data.id"},{"class":"msVendor","alias":"Vendor","on":"Data.vendor=Vendor.id"}'; if (!empty($thumbsLeftJoin)) { $leftJoin .= $thumbsLeftJoin; } $select = '"msProduct":"' . $resourceColumns . '","Data":"' . $dataColumns . '","OrderProduct":"' . $orderProductColumns . '","Vendor":"' . $vendorColumns . '"'; if (!empty($thumbsSelect)) {
if (!empty($_GET['msorder'])) { return ''; } elseif (empty($status['total_count'])) { return !empty($tplEmpty) ? $pdoFetch->getChunk($tplEmpty) : ''; } // Include Thumbnails $thumbsLeftJoin = ''; $thumbsSelect = array(); if (!empty($includeThumbs)) { $thumbs = array_map('trim', explode(',', $includeThumbs)); if (!empty($thumbs[0])) { foreach ($thumbs as $thumb) { $thumbsLeftJoin .= ',{"class":"msProductFile","alias":"' . $thumb . '","on":"' . $thumb . '.product_id = msProduct.id AND ' . $thumb . '.parent != 0 AND ' . $thumb . '.path LIKE \'%/' . $thumb . '/\'"}'; $thumbsSelect[] = ' "' . $thumb . '":"' . $thumb . '.url as ' . $thumb . '" '; } $pdoFetch->addTime('Included list of thumbnails: <b>' . implode(', ', $thumbs) . '</b>.'); } } // End of including Thumbnails // Fields to select $resourceColumns = !empty($includeContent) ? $modx->getSelectColumns('msProduct', 'msProduct') : $modx->getSelectColumns('msProduct', 'msProduct', '', array('content'), true); $dataColumns = $modx->getSelectColumns('msProductData', 'Data', '', array('id'), true); $vendorColumns = $modx->getSelectColumns('msVendor', 'Vendor', 'vendor.', array('id'), true); // Tables for joining $leftJoin = '{"class":"msProductData","alias":"Data","on":"msProduct.id=Data.id"},{"class":"msVendor","alias":"Vendor","on":"Data.vendor=Vendor.id"}'; if (!empty($thumbsLeftJoin)) { $leftJoin .= $thumbsLeftJoin; } $select = '"msProduct":"' . $resourceColumns . '","Data":"' . $dataColumns . '","Vendor":"' . $vendorColumns . '"'; if (!empty($thumbsSelect)) { $select .= ',' . implode(',', $thumbsSelect);
$row[$v] = $row['thumbnail']; } } if (!empty($getTags)) { $q = $modx->newQuery('msResourceFileTag', array('file_id' => $row['id'])); $q->select('tag'); $tstart = microtime(true); if ($q->prepare() && $q->stmt->execute()) { $modx->queryTime += microtime(true) - $tstart; $modx->executedQueries++; $row['tags'] = implode($tagsSeparator, $q->stmt->fetchAll(PDO::FETCH_COLUMN)); } } $images[] = $row; } $pdoFetch->addTime(!empty($getTags) ? 'Thumbnails and tags was retrieved' : 'Thumbnails was retrieved'); // Processing chunks $output = array(); foreach ($images as $row) { $tpl = $pdoFetch->defineChunk($row); $output[] = empty($tpl) ? '<pre>' . $pdoFetch->getChunk('', $row) . '</pre>' : $pdoFetch->getChunk($tpl, $row, $pdoFetch->config['fastMode']); } $pdoFetch->addTime('Rows was templated'); // Return output $log = ''; if ($modx->user->hasSessionContext('mgr') && !empty($showLog)) { $log .= '<pre class="ms2GalleryLog">' . print_r($pdoFetch->getTime(), 1) . '</pre>'; } if (!empty($toSeparatePlaceholders)) { $output['log'] = $log; $modx->setPlaceholders($output, $toSeparatePlaceholders);
<?php /* @var array $scriptProperties */ /* @var miniShop2 $miniShop2 */ $miniShop2 = $modx->getService('minishop2'); $miniShop2->initialize($modx->context->key); /* @var pdoFetch $pdoFetch */ if (!$modx->loadClass('pdofetch', MODX_CORE_PATH . 'components/pdotools/model/pdotools/', false, true)) { return false; } $pdoFetch = new pdoFetch($modx, $scriptProperties); $pdoFetch->addTime('pdoTools loaded.'); if (!empty($_GET['msorder'])) { if ($order = $modx->getObject('msOrder', $_GET['msorder'])) { if (!empty($_SESSION['minishop2']['orders']) && in_array($_GET['msorder'], $_SESSION['minishop2']['orders']) || $order->get('user_id') == $modx->user->id || $modx->context->key == 'mgr') { if (empty($tplSuccess)) { $tplSuccess = 'tpl.msOrder.success'; } return $pdoFetch->getChunk($tplSuccess, array('id' => $_GET['msorder'])); } } } $cart = $miniShop2->cart->get(); $status = $miniShop2->cart->status(); $order = $miniShop2->order->get(); if (empty($status['total_count'])) { return !empty($tplEmpty) ? $pdoFetch->getChunk($tplEmpty) : ''; } $deliveryColumns = $modx->getSelectColumns('msDelivery', 'msDelivery', 'delivery_'); $paymentColumns = $modx->getSelectColumns('msPayment', 'msPayment', 'payment_'); // Default parameters
$pdoFetch->setConfig(array_merge($default, $scriptProperties)); $rows = $pdoFetch->run(); if (!empty($returnIds)) { return $rows; } // Processing rows $output = array(); if (!empty($rows) && is_array($rows)) { $q = $modx->newQuery('modPluginEvent', array('event:IN' => array('msOnGetProductPrice', 'msOnGetProductWeight'))); $q->innerJoin('modPlugin', 'modPlugin', 'modPlugin.id = modPluginEvent.pluginid'); $q->where('modPlugin.disabled = 0'); if ($modificators = $modx->getOption('ms2_price_snippet', null, false, true) || $modx->getOption('ms2_weight_snippet', null, false, true) || $modx->getCount('modPluginEvent', $q)) { /* @var msProductData $product */ $product = $modx->newObject('msProductData'); } $pdoFetch->addTime('Checked the active modifiers'); $opt_time = 0; foreach ($rows as $k => $row) { if ($modificators) { $product->fromArray($row, '', true, true); $tmp = $row['price']; $row['price'] = $product->getPrice($row); $row['weight'] = $product->getWeight($row); if ($row['price'] != $tmp) { $row['old_price'] = $tmp; } } $row['price'] = $miniShop2->formatPrice($row['price']); $row['old_price'] = $miniShop2->formatPrice($row['old_price']); $row['weight'] = $miniShop2->formatWeight($row['weight']); $row['idx'] = $pdoFetch->idx++;
<?php /** @var array $scriptProperties */ /** @var mSearch2 $mSearch2 */ if (!$modx->loadClass('msearch2', MODX_CORE_PATH . 'components/msearch2/model/msearch2/', false, true)) { return false; } $mSearch2 = new mSearch2($modx, $scriptProperties); /** @var pdoFetch $pdoFetch */ if (!$modx->loadClass('pdofetch', MODX_CORE_PATH . 'components/pdotools/model/pdotools/', false, true)) { return false; } $pdoFetch = new pdoFetch($modx, $scriptProperties); $pdoFetch->addTime('pdoTools loaded.'); if (empty($queryVar)) { $queryVar = 'query'; } if (empty($parentsVar)) { $parentsVar = 'parents'; } if (empty($minQuery)) { $minQuery = $modx->getOption('index_min_words_length', null, 3, true); } if ($depth == '') { $depth = 10; } if (empty($htagOpen)) { $htagOpen = '<b>'; } if (empty($htagClose)) { $htagClose = '</b>';
$tmp = $modx->fromJSON($scriptProperties['where']); if (is_array($tmp) && !empty($tmp)) { $where = array_merge($where, $tmp); } } unset($scriptProperties['where']); // Default parameters $default = array('class' => 'msProductFile', 'where' => $modx->toJSON($where), 'select' => '{"msProductFile":"all"}', 'limit' => $limit, 'sortby' => 'rank', 'sortdir' => 'ASC', 'fastMode' => false, 'return' => 'data', 'nestedChunkPrefix' => 'minishop2_'); // Merge all properties and run! $scriptProperties['tpl'] = !empty($tplRow) ? $tplRow : ''; $pdoFetch->setConfig(array_merge($default, $scriptProperties)); $rows = $pdoFetch->run(); // Processing rows $output = null; $images = array(); $pdoFetch->addTime('Fetching thumbnails'); foreach ($rows as $k => $row) { $row['idx'] = $pdoFetch->idx++; $images[$row['id']] = $row; if (isset($row['type']) && $row['type'] == 'image') { $q = $modx->newQuery('msProductFile', array('parent' => $row['id'])); $q->select('url'); if ($q->prepare() && $q->stmt->execute()) { while ($url = $q->stmt->fetch(PDO::FETCH_COLUMN)) { $tmp = parse_url($url); if (preg_match('/((?:\\d{1,4}|)x(?:\\d{1,4}|))/', $tmp['path'], $size)) { $images[$row['id']][$size[0]] = $url; } } } } elseif (isset($row['type'])) {
$pdoFetch->setConfig(array_merge($default, $scriptProperties)); $rows = $pdoFetch->run(); if (!empty($returnIds)) { return $rows; } // Processing rows $output = array(); if (!empty($rows) && is_array($rows)) { $q = $modx->newQuery('modPluginEvent', array('event:IN' => array('msOnGetProductPrice', 'msOnGetProductWeight'))); $q->innerJoin('modPlugin', 'modPlugin', 'modPlugin.id = modPluginEvent.pluginid'); $q->where('modPlugin.disabled = 0'); if ($modificators = $modx->getOption('ms2_price_snippet', null, false, true) || $modx->getOption('ms2_weight_snippet', null, false, true) || $modx->getCount('modPluginEvent', $q)) { /* @var msProductData $product */ $product = $modx->newObject('msProductData'); } $pdoFetch->addTime('Checked the active modifiers'); foreach ($rows as $k => $row) { if ($modificators) { $product->fromArray($row, '', true, true); $tmp = $row['price']; $row['price'] = $product->getPrice($row); $row['weight'] = $product->getWeight($row); if ($row['price'] != $tmp) { $row['old_price'] = $tmp; } } $row['price'] = $miniShop2->formatPrice($row['price']); $row['old_price'] = $miniShop2->formatPrice($row['old_price']); $row['weight'] = $miniShop2->formatWeight($row['weight']); $row['idx'] = $pdoFetch->idx++; $tpl = $pdoFetch->defineChunk($row);
<?php /** @var array $scriptProperties */ /* @var pdoFetch $pdoFetch */ if (!$modx->getService('pdoFetch')) { return 'You need to install pdoTools to use this snippet!'; } $pdoFetch = new pdoFetch($modx, $scriptProperties); $pdoFetch->addTime('pdoTools loaded'); $modx->lexicon->load('bannery:default'); $modx->addPackage('bannery', MODX_CORE_PATH . 'components/bannery/model/'); if (!empty($tplOuter)) { $tplWrapper = $tplOuter; } if (empty($outputSeparator)) { $outputSeparator = "\n"; } $class = 'byAd'; // Adding extra parameters into special place so we can put them in results /** @var modSnippet $snippet */ $additionalPlaceholders = array(); if ($snippet = $modx->getObject('modSnippet', array('name' => 'BannerY'))) { $properties = unserialize($snippet->properties); foreach ($scriptProperties as $k => $v) { if (!isset($properties[$k])) { $additionalPlaceholders[$k] = $v; } } } // --- $date = date('Y-m-d H:i:s');
$output = ""; //working only with auth users if ($modx->user->isAuthenticated($modx->context->key)) { if ($modx->user->active || !$modx->user->Profile->blocked) { $ePochta = $modx->getService('epochta', 'ePochta', $modx->getOption('epochta_core_path', null, $modx->getOption('core_path') . 'components/epochta/') . 'model/epochta/', $scriptProperties); $ePochta->initialize($modx->context->key, $scriptProperties); if (!$ePochta instanceof ePochta) { return ''; } /* @var pdoFetch $pdoFetch */ if (!$modx->loadClass('pdofetch', MODX_CORE_PATH . 'components/pdotools/model/pdotools/', false, true)) { return false; } $pdoFetch = new pdoFetch($modx, $scriptProperties); $pdoFetch->addTime('pdoTools loaded.'); /* prepare settings */ if (!isset($tplCheck)) { $tplCheck = 'tpl.epPhone.check'; } if (!isset($tplExists)) { $tplExists = 'tpl.epPhone.exists'; } /* If user already have phone nothing to do */ $profile = $modx->user->getOne('Profile'); $userPhone = $profile->get('mobilephone'); if (!empty($userPhone)) { $output = $pdoFetch->getChunk($tplExists, array('mobilephone' => $userPhone)); } else { $output = $pdoFetch->getChunk($tplCheck); }
<?php /** @var array $scriptProperties */ /** @var mSearch2 $mSearch2 */ if (!$modx->loadClass('msearch2', MODX_CORE_PATH . 'components/msearch2/model/msearch2/', false, true)) { return false; } $mSearch2 = new mSearch2($modx, $scriptProperties); $mSearch2->initialize($modx->context->key); /** @var pdoFetch $pdoFetch */ if (!$modx->loadClass('pdofetch', MODX_CORE_PATH . 'components/pdotools/model/pdotools/', false, true)) { return false; } $pdoFetch = new pdoFetch($modx, $scriptProperties); $pdoFetch->addTime('pdoTools loaded.'); $_SESSION['mFilter2'][$modx->resource->id] = array(); if (empty($queryVar)) { $queryVar = 'query'; } if (empty($parentsVar)) { $parentsVar = 'parents'; } if (empty($minQuery)) { $minQuery = $modx->getOption('index_min_words_length', null, 3, true); } if ($depth == '') { $depth = 10; } if (empty($classActive)) { $classActive = 'active'; }