Beispiel #1
0
 /**
  * Sets up the JavsScript cart
  *
  * Searches all $themesPages elements for the first occurrence of the
  * "shopJsCart" template block.
  * Generates the structure of the Javascript cart, puts it in the template,
  * and registers all required JS code.
  * Note that this is only ever called when the JS cart is enabled in the
  * extended settings!
  * @access  public
  * @global  array   $_ARRAYLANG   Language array
  * @global  array   $themesPages  Theme template array
  * @return  void
  * @static
  */
 static function setJsCart()
 {
     global $_ARRAYLANG, $themesPages;
     if (!\Cx\Core\Setting\Controller\Setting::getValue('use_js_cart', 'Shop')) {
         return;
     }
     $objTemplate = new \Cx\Core\Html\Sigma('.');
     $objTemplate->setErrorHandling(PEAR_ERROR_DIE);
     $match = null;
     $div_cart = $div_product = '';
     foreach ($themesPages as $index => $content) {
         //\DBG::log("Shop::setJsCart(): Section $index");
         $objTemplate->setTemplate($content, false, false);
         if (!$objTemplate->blockExists('shopJsCart')) {
             continue;
         }
         //\DBG::log("Shop::setJsCart(): In themespage $index: {$themesPages[$index]}");
         $objTemplate->setCurrentBlock('shopJsCart');
         // Set all language entries and replace formats
         $objTemplate->setGlobalVariable($_ARRAYLANG);
         if ($objTemplate->blockExists('shopJsCartProducts')) {
             $objTemplate->parse('shopJsCartProducts');
             $div_product = $objTemplate->get('shopJsCartProducts');
             //\DBG::log("Shop::setJsCart(): Got Product: $div_product");
             $objTemplate->replaceBlock('shopJsCartProducts', '[[SHOP_JS_CART_PRODUCTS]]');
         }
         $objTemplate->touchBlock('shopJsCart');
         $objTemplate->parse('shopJsCart');
         $div_cart = $objTemplate->get('shopJsCart');
         //\DBG::log("Shop::setJsCart(): Got Cart: $div_cart");
         if (preg_match('#^([\\n\\r]?[^<]*<.*id=["\']shopJsCart["\'][^>]*>)(([\\n\\r].*)*)(</[^>]*>[^<]*[\\n\\r]?)$#', $div_cart, $match)) {
             //\DBG::log("Shop::setJsCart(): Matched DIV {$match[1]}, content: {$match[2]}");
             $themesPages[$index] = preg_replace('@(<!--\\s*BEGIN\\s+(shopJsCart)\\s*-->.*?<!--\\s*END\\s+\\2\\s*-->)@s', $match[1] . $_ARRAYLANG['TXT_SHOP_CART_IS_LOADING'] . $match[4], $content);
             /*
             // Template use won't work, because it kills the remaining <!-- blocks -->!
                             $objTemplate->setTemplate($content, false, false);
                             $objTemplate->replaceBlock('shopJsCart',
                                 $match[1].
                                 $_ARRAYLANG['TXT_SHOP_CART_IS_LOADING'].
                                 $match[4]);
                             $themesPages[$index] = $objTemplate->get();
             */
             //\DBG::log("Shop::setJsCart(): Out themespage $index: {$themesPages[$index]}");
         }
         // One instance only (mind that there's a unique id attribute)
         self::$use_js_cart = true;
         break;
     }
     if (!self::$use_js_cart) {
         return;
     }
     self::registerJavascriptCode();
     \ContrexxJavascript::getInstance()->setVariable('TXT_SHOP_CART_IS_LOADING', $_ARRAYLANG['TXT_SHOP_CART_IS_LOADING'], 'shop/cart');
     \ContrexxJavascript::getInstance()->setVariable('TXT_SHOP_COULD_NOT_LOAD_CART', $_ARRAYLANG['TXT_SHOP_COULD_NOT_LOAD_CART'], 'shop/cart');
     \ContrexxJavascript::getInstance()->setVariable('TXT_EMPTY_SHOPPING_CART', $_ARRAYLANG['TXT_EMPTY_SHOPPING_CART'], 'shop/cart');
     \ContrexxJavascript::getInstance()->setVariable("url", (string) \Cx\Core\Routing\URL::fromModuleAndCMd('Shop' . MODULE_INDEX, 'cart', FRONTEND_LANG_ID, array('remoteJs' => 'addProduct')), 'shop/cart');
     \JS::registerJS(substr(\Cx\Core\Core\Controller\Cx::instanciate()->getModuleFolderName() . '/Shop/View/Script/cart.js', 1));
     \JS::registerCode("cartTpl = '" . preg_replace(array('/\'/', '/[\\n\\r]/', '/\\//'), array('\\\'', '\\n', '\\/'), $div_cart) . "';\n" . "cartProductsTpl = '" . preg_replace(array('/\'/', '/[\\n\\r]/', '/\\//'), array('\\\'', '\\n', '\\/'), $div_product) . "';\n");
 }
 function getCategoriesLevels($intType, $intEntryId = null, $cmdName = null)
 {
     if ($intType == 1) {
         //categories
         $objEntryCategoriesLevels = $this->getCategories($intEntryId);
         $paramName = 'cid';
     } else {
         //levels
         $objEntryCategoriesLevels = $this->getLevels($intEntryId);
         $paramName = 'lid';
     }
     $pageRepo = \Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page');
     $page = $pageRepo->findOneByModuleCmdLang($this->moduleName, $cmdName, FRONTEND_LANG_ID);
     if ($objEntryCategoriesLevels !== false) {
         $list = '<ul>';
         while (!$objEntryCategoriesLevels->EOF) {
             $paramValue = intval($objEntryCategoriesLevels->fields['elm_id']);
             $url = $page ? \Cx\Core\Routing\URL::fromPage($page, array($paramName => $paramValue)) : '';
             $name = htmlspecialchars($objEntryCategoriesLevels->fields['elm_name'], ENT_QUOTES, CONTREXX_CHARSET);
             $list .= '<li>';
             $list .= !empty($url) ? '<a href="' . $url . '">' . $name . '</a>' : $name;
             $list .= '</li>';
             $objEntryCategoriesLevels->MoveNext();
         }
         $list .= '</ul>';
     }
     return $list;
 }
 private function parseContentTree($nodeTree, $userGroupType, $arrDynamicPermissionIdsOfGroup, $cssRowClassNr = 1, $level = 0)
 {
     global $_ARRAYLANG;
     foreach ($nodeTree as $nodeData) {
         $pages = $nodeData['data'];
         // remove non-existent pages
         foreach ($pages as $idx => $pageData) {
             if (!$pageData['attr']['id']) {
                 unset($pages[$idx]);
             }
         }
         $numberOfPages = count($pages);
         foreach ($pages as $idx => $pageData) {
             // TODO: handle broken pages differently
             if ($pageData['attr']['id'] == 'broken') {
                 //continue;
             }
             $rowCssClass = array();
             if ($idx == 0) {
                 $rowCssClass[] = 'rowFirst';
             }
             if ($idx + 1 == $numberOfPages) {
                 $rowCssClass[] = 'rowLast';
             }
             $protected = $userGroupType == 'backend' && $pageData['attr']['locked'] || $userGroupType == 'frontend' && $pageData['attr']['protected'];
             if ($protected) {
                 $rowCssClass[] = 'active';
             }
             $published = $nodeData['metadata'][$pageData['attr']['id']]['publishing'] == 'published';
             $this->_objTpl->setVariable(array('ACCESS_PAGE_ID' => $pageData['attr']['id'], 'ACCESS_NODE_ID' => $nodeData['attr']['rel_id'], 'ACCESS_NODE_LANG' => $pageData['language'], 'ACCESS_WEBPAGE_CSS_CLASS' => join(' ', $rowCssClass), 'ACCESS_PAGE_SELECTION_DISPLAY' => $protected ? '' : 'none', 'ACCESS_PAGE_PUBLISHING' => $published ? 'published' : 'unpublished', 'ACCESS_PAGE_PROTECTED' => $protected ? 'locked' : '', 'ACCESS_PAGE_PROTECT_BACKEND' => $userGroupType == 'backend' ? 1 : 0, 'ACCESS_WEBPAGE_TEXT_INDENT' => $level * 20, 'ACCESS_WEBPAGE_NAME' => contrexx_raw2xhtml($pageData['title']) . ' [' . $pageData['language'] . ']', 'ACCESS_PAGE_CHECKED' => $protected && in_array($pageData['attr'][$userGroupType . '_access_id'], $arrDynamicPermissionIdsOfGroup) ? 'checked="checked"' : '', 'ACCESS_CLICK_TO_CHANGE_PROTECTION_TXT' => $userGroupType == 'backend' ? $protected ? $_ARRAYLANG['TXT_ACCESS_CLICK_UNLOCK_PAGE_MODIF'] : $_ARRAYLANG['TXT_ACCESS_CLICK_LOCK_PAGE_MODIFY'] : ($protected ? $_ARRAYLANG['TXT_ACCESS_CLICK_UNLOCK_PAGE_ACCESS'] : $_ARRAYLANG['TXT_ACCESS_CLICK_LOCK_PAGE_ACCESS'])));
             if ($published) {
                 $this->_objTpl->setVariable('ACCESS_WEBPAGE_LINK', \Cx\Core\Routing\URL::fromPageId($pageData['attr']['id']));
                 $this->_objTpl->parse('access_permission_webpage_preview');
             } else {
                 $this->_objTpl->hideBlock('access_permission_webpage_preview');
             }
             $this->_objTpl->parse('access_permission_website');
         }
         if (isset($nodeData['children'])) {
             $this->parseContentTree($nodeData['children'], $userGroupType, $arrDynamicPermissionIdsOfGroup, $cssRowClassNr, $level + 1);
         }
     }
 }