/** * Embed flash player with specified parameters * * @param string $url * @param string $target_id * @param integer $width * @param integer $height * @param array $flash_vars * @param array $params */ public function embedSWF($url, $target_id, $width, $height, $flash_vars = array(), $params = array()) { $template = new TemplateHandler('embed.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $p_flashvars = json_encode($flash_vars); $p_params = json_encode($params); $script = "swfobject.embedSWF('{$url}', '{$target_id}', '{$width}', '{$height}', '{$this->flash_version}', null, {$p_flashvars}, {$p_params});"; $params = array('params' => $p_params, 'flash_vars' => $p_flashvars, 'url' => $url, 'id' => $target_id, 'width' => $width, 'height' => $height, 'version' => $this->flash_version, 'script' => $script); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Show content of feedback form in backend. */ private function showFeedback() { $template = new TemplateHandler('list.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $template->registerTagHandler('cms:list', $this, 'tag_FeedbackList'); $params = array(); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Save settings. */ private function saveSettings() { // grab parameters $account_id = fix_chars($_REQUEST['account_id']); $account_key = fix_chars($_REQUEST['account_key']); $account_secret = fix_chars($_REQUEST['account_secret']); $include_code = isset($_REQUEST['include_code']) && ($_REQUEST['include_code'] == 'on' || $_REQUEST['include_code'] == '1') ? 1 : 0; $this->saveSetting('account_id', $account_id); $this->saveSetting('account_key', $account_key); $this->saveSetting('account_secret', $account_secret); $this->saveSetting('include_code', $include_code); // show message $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_saved'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('callbox_settings')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Parse loaded template * * @param integer $level Current level of parsing * @param array $tags Leave blank, used for recursion * @param boolean $parent_block If parent tag is block element */ public function parse($tags = array()) { global $section, $action, $language, $template_path, $system_template_path; if (!$this->active && empty($tags)) { return; } // get language handler for later $language_handler = MainLanguageHandler::getInstance(); // take the tag list for parsing $tag_array = empty($tags) ? $this->engine->document->tagChildren : $tags; // start parsing tags $count = count($tag_array); for ($i = 0; $i < $count; $i++) { $tag = $tag_array[$i]; // if tag has eval set if (isset($tag->tagAttrs['cms:eval']) || isset($tag->tagAttrs['eval'])) { // get evaluation values if (isset($tag->tagAttrs['eval'])) { $value = $tag->tagAttrs['eval']; } else { $value = $tag->tagAttrs['cms:eval']; } $eval_params = explode(',', $value); foreach ($eval_params as $param) { // prepare module includes for evaluation $settings = array(); if (!is_null($this->module)) { $settings = $this->module->settings; } $params = $this->params; $to_eval = $tag->tagAttrs[$param]; $tag->tagAttrs[$param] = eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';'); } // unset param unset($tag->tagAttrs['cms:eval']); } if (isset($tag->tagAttrs['cms:optional'])) { // get evaluation values $optional_params = explode(',', $tag->tagAttrs['cms:optional']); foreach ($optional_params as $param) { // prepare module includes for evaluation $settings = array(); if (!is_null($this->module)) { $settings = $this->module->settings; } $params = $this->params; $to_eval = $tag->tagAttrs[$param]; $value = eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';'); if ($value == false) { unset($tag->tagAttrs[$param]); } else { $tag->tagAttrs[$param] = $value; } } // unset param unset($tag->tagAttrs['cms:optional']); } // implement tooltip if (isset($tag->tagAttrs['cms:tooltip'])) { if (!is_null($this->module)) { $value = $this->module->getLanguageConstant($tag->tagAttrs['cms:tooltip']); } else { $value = $language_handler->getText($tag->tagAttrs['cms:tooltip']); } $tag->tagAttrs['data-tooltip'] = $value; unset($tag->tagAttrs['cms:tooltip']); } // implement constants if (isset($tag->tagAttrs['cms:constant'])) { $params = explode(',', $tag->tagAttrs['cms:constant']); if (count($params) > 0) { foreach ($params as $param) { if (!is_null($this->module)) { $tag->tagAttrs[$param] = $this->module->getLanguageConstant($tag->tagAttrs[$param]); } else { $tag->tagAttrs[$param] = $language_handler->getText($tag->tagAttrs[$param]); } } } unset($tag->tagAttrs['cms:constant']); } // check if specified tag shouldn't be cached $skip_cache = false; if (isset($tag->tagAttrs['skip_cache'])) { // unset param unset($tag->tagAttrs['skip_cache']); // get cache handler $cache = CacheHandler::getInstance(); // only if current URL is being cached, we start dirty area if ($cache->isCaching()) { $cache->startDirtyArea(); $skip_cache = true; // reconstruct template for cache, // ugly but we are not doing it a lot $data = $this->getDataForCache($tag); $cache->setCacheForDirtyArea($data); } } // now parse the tag switch ($tag->tagName) { // handle tag used for setting session variable case '_session': case 'cms:session': $name = $tag->tagAttrs['name']; // allow setting referral only once per seesion if (isset($tag->tagAttrs['once'])) { $only_once = in_array($tag->tagAttrs['once'], array(1, 'yes')); } else { $only_once = false; } $should_set = $only_once && !isset($_SESSION[$name]) || !$only_once; // store value if (!in_array($name, $this->protected_variables) && $should_set) { $_SESSION[$name] = $tag->tagAttrs['value']; } break; // transfer control to module // transfer control to module case '_module': case 'cms:module': if (class_exists($tag->tagAttrs['name'])) { $module = call_user_func(array($tag->tagAttrs['name'], 'getInstance')); $module->transferControl($tag->tagAttrs, $tag->tagChildren); } break; // load other template // load other template case '_template': case 'cms:template': $file = $tag->tagAttrs['file']; $path = key_exists('path', $tag->tagAttrs) ? $tag->tagAttrs['path'] : ''; if (!is_null($this->module)) { $path = preg_replace('/^%module%/i', $this->module->path, $path); $path = preg_replace('/^%templates%/i', $template_path, $path); } $new = new TemplateHandler($file, $path); $new->setLocalParams($this->params); $new->parse(); break; // raw text copy // raw text copy case '_raw': case 'cms:raw': if (key_exists('file', $tag->tagAttrs)) { // if file attribute is specified $file = $tag->tagAttrs['file']; $path = key_exists('path', $tag->tagAttrs) ? $tag->tagAttrs['path'] : $template_path; $text = file_get_contents($path . $file); } elseif (key_exists('text', $tag->tagAttrs)) { // if text attribute is specified $text = $tag->tagAttrs['text']; } else { // in any other case we display data inside tag $text = $tag->tagData; } echo $text; break; // multi language constants // multi language constants case '_text': case 'cms:text': $constant = $tag->tagAttrs['constant']; $language = key_exists('language', $tag->tagAttrs) ? $tag->tagAttrs['language'] : $language; $text = ""; // check if constant is module based if (key_exists('module', $tag->tagAttrs)) { if (class_exists($tag->tagAttrs['module'])) { $module = call_user_func(array($tag->tagAttrs['module'], 'getInstance')); $text = $module->getLanguageConstant($constant, $language); } } else { // use default language handler $text = MainLanguageHandler::getInstance()->getText($constant, $language); } echo $text; break; // support for markdown // support for markdown case 'cms:markdown': $char_count = isset($tag->tagAttrs['chars']) ? fix_id($tag->tagAttrs['chars']) : null; $end_with = isset($tag->tagAttrs['end_with']) ? fix_id($tag->tagAttrs['end_with']) : null; $name = isset($tag->tagAttrs['param']) ? $tag->tagAttrs['param'] : null; $multilanguage = isset($tag->tagAttrs['multilanguage']) ? $tag->tagAttrs['multilanguage'] == 'yes' : false; // get content for parsing if (is_null($name)) { $content = $tag->tagData; } $content = $multilanguage ? $this->params[$name][$language] : $this->params[$name]; // convert to HTML $content = Markdown($content); // limit words if specified if (!is_null($char_count)) { if (is_null($end_with)) { $content = limit_words($content, $char_count); } else { $content = limit_words($content, $char_count, $end_with); } } echo $content; break; // call section specific data // call section specific data case '_section_data': case 'cms:section_data': if (!is_null($this->module)) { $file = $this->module->getSectionFile($section, $action, $language); $new = new TemplateHandler(basename($file), dirname($file) . '/'); $new->setLocalParams($this->params); $new->setMappedModule($this->module); $new->parse(); } else { // log error trigger_error('Mapped module is not loaded! File: ' . $this->file, E_USER_WARNING); } break; // print multilanguage data // print multilanguage data case '_language_data': case 'cms:language_data': $name = isset($tag->tagAttrs['param']) ? $tag->tagAttrs['param'] : null; if (!isset($this->params[$name]) || !is_array($this->params[$name]) || is_null($name)) { break; } $template = new TemplateHandler('language_data.xml', $system_template_path); $template->setMappedModule($this->module); foreach ($this->params[$name] as $lang => $data) { $params = array('param' => $name, 'language' => $lang, 'data' => $data); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } break; // replace tag data string with matching params // replace tag data string with matching params case '_replace': case 'cms:replace': $pool = isset($tag->tagAttrs['param']) ? $this->params[$tag->tagAttrs['param']] : $this->params; $keys = array_keys($pool); $values = array_values($pool); foreach ($keys as $i => $key) { $keys[$i] = "%{$key}%"; } // we can't replact string with array, only matching data types foreach ($values as $i => $value) { if (is_array($value)) { unset($keys[$i]); unset($values[$i]); } } echo str_replace($keys, $values, $tag->tagData); break; // conditional tag // conditional tag case '_if': case 'cms:if': $settings = !is_null($this->module) ? $this->module->settings : array(); $params = $this->params; $condition = true; // check if section is specified and matches if (isset($tag->tagAttrs['section'])) { $condition &= $tag->tagAttrs['section'] == $section; } // check if action is specified and matches if (isset($tag->tagAttrs['action'])) { $condition &= $tag->tagAttrs['action'] == $action; } // check custom condition if (isset($tag->tagAttrs['condition'])) { $to_eval = $tag->tagAttrs['condition']; $eval_result = eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';') == true; $condition &= $eval_result; } // parse children if ($condition) { $this->parse($tag->tagChildren); } break; // conditional tag parsed for desktop version // conditional tag parsed for desktop version case 'cms:desktop': if (_DESKTOP_VERSION) { $this->parse($tag->tagChildren); } break; // conditional tag parsed for mobile version // conditional tag parsed for mobile version case 'cms:mobile': if (_MOBILE_VERSION) { $this->parse($tag->tagChildren); } break; // conditional tag parsed for users that are logged in // conditional tag parsed for users that are logged in case 'cms:user': if ($_SESSION['logged']) { $this->parse($tag->tagChildren); } break; // conditional tag parsed for guests // conditional tag parsed for guests case 'cms:guest': if (!$_SESSION['logged']) { $this->parse($tag->tagChildren); } break; // variable // variable case '_var': case 'cms:var': $settings = array(); if (!is_null($this->module)) { $settings = $this->module->settings; } $params = $this->params; $to_eval = $tag->tagAttrs['name']; echo eval('global $section, $action, $language, $language_rtl, $language_handler; return ' . $to_eval . ';'); break; // support for script tag // support for script tag case 'cms:script': if (class_exists('head_tag')) { $head_tag = head_tag::getInstance(); $head_tag->addTag('script', $tag->tagAttrs); } break; // support for collection module // support for collection module case 'cms:collection': if (array_key_exists('include', $tag->tagAttrs) && class_exists('collection')) { $scripts = fix_chars(explode(',', $tag->tagAttrs['include'])); $collection = collection::getInstance(); $collection->includeScript($scripts); } break; // support for link tag // support for link tag case 'cms:link': if (class_exists('head_tag')) { $head_tag = head_tag::getInstance(); $head_tag->addTag('link', $tag->tagAttrs); } break; // support for parameter based choice // support for parameter based choice case 'cms:choice': $param_value = null; if (array_key_exists('param', $tag->tagAttrs)) { // grap param value from GET or POST parameters $param_name = fix_chars($tag->tagAttrs['param']); $param_value = isset($_REQUEST[$param_name]) ? fix_chars($_REQUEST[$param_name]) : null; } else { if (array_key_exists('value', $tag->tagAttrs)) { // use param value specified $param_value = fix_chars($tag->tagAttrs['value']); } } // parse only option foreach ($tag->tagChildren as $option) { if (!$option->tagName == 'option') { continue; } $option_value = isset($option->tagAttrs['value']) ? $option->tagAttrs['value'] : null; $option_default = isset($option->tagAttrs['default']) ? $option->tagAttrs['default'] == 1 : false; // values match or option is default, parse its content if ($option_value == $param_value || $option_default) { $this->parse($option->tagChildren); break; } } break; // default action for parser, draw tag // default action for parser, draw tag default: if (in_array($tag->tagName, array_keys($this->handlers))) { // custom tag handler is set... $handle = $this->handlers[$tag->tagName]; $obj = $handle['object']; $function = $handle['function']; $obj->{$function}($tag->tagAttrs, $tag->tagChildren); } else { // default tag handler echo '<' . $tag->tagName . $this->getTagParams($tag->tagAttrs) . '>'; if (count($tag->tagChildren) > 0) { $this->parse($tag->tagChildren); } if (count($tag->tagData) > 0) { echo $tag->tagData; } $close_tag = $this->close_all_tags ? true : !in_array($tag->tagName, $this->tags_without_end); if ($close_tag) { echo '</' . $tag->tagName . '>'; } } break; } // end cache dirty area if initialized if ($skip_cache) { $cache->endDirtyArea(); } } }
/** * Perform item removal from specified page */ private function pageItems_Delete_Commit() { $id = fix_id($_REQUEST['id']); $manager = UserPageItemsManager::getInstance(); // remove item from database $manager->deleteData(array('id' => $id)); // show message $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_page_item_deleted'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('user_pages_items_delete') . ';' . window_ReloadContent('user_pages_items')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Print level option */ public function tag_Level($tag_params, $children) { $max_level = 10; if ($_SESSION['level'] < 10) { $max_level = $_SESSION['level'] - 1; } $selected = -1; if (isset($tag_params['selected'])) { $selected = $tag_params['selected']; } // create template if (isset($tag_params['template'])) { if (isset($tag_params['local']) && $tag_params['local'] == 1) { $template = new TemplateHandler($tag_params['template'], $this->parent->path . 'templates/'); } else { $template = new TemplateHandler($tag_params['template']); } } else { $template = new TemplateHandler('users_level.xml', $this->parent->path . 'templates/'); } $template->setMappedModule($this->parent->name); for ($i = 0; $i <= $max_level; $i++) { $params = array('level' => $i, 'selected' => $selected); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } }
/** * Tag handler for printing code lists * * @param array $params * @param array $children */ public function tag_CodeList($params, $children) { $manager = CodeManager::getInstance(); $conditions = array(); $items = $manager->getItems($manager->getFieldNames(), $conditions, array('id')); $template = new TemplateHandler('list_item.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); if (count($items) > 0) { foreach ($items as $item) { $params = array('id' => $item->id, 'code' => $item->code, 'url' => $item->url, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('codes_change', 400, $this->getLanguageConstant('title_codes_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'codes_change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('codes_delete', 400, $this->getLanguageConstant('title_codes_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'codes_delete'), array('id', $item->id)))), 'item_open' => url_MakeHyperlink($this->getLanguageConstant('open'), $item->url, '', '', '_blank')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }
/** * Tag handler for feed list * * @param array $params * @param array $children */ public function tag_FeedList($params, $children) { $manager = NewsFeedManager::getInstance(); $group_manager = NewsGroupManager::getInstance(); $items = $manager->getItems($manager->getFieldNames(), array()); // create template parser $template = new TemplateHandler('feed_list_item.xml', $this->path . 'templates/'); if (count($items) > 0) { foreach ($items as $item) { $group = $group_manager->getSingleItem(array('title'), array('id' => $item->group)); $params = array('id' => $item->id, 'group' => $item->group, 'news_count' => $item->news_count, 'title' => $item->title, 'group_title' => $group->title, 'description' => $item->description, 'active' => $item->active, 'active_char' => $item->active ? CHAR_CHECKED : CHAR_UNCHECKED, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('news_feeds_change', 390, $this->getLanguageConstant('title_news_feed_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'feed_change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('news_feeds_delete', 390, $this->getLanguageConstant('title_news_feed_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'feed_delete'), array('id', $item->id))))); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }
/** * Handle displaying list of ISO defined currencies * * @param array $tag_params * @param array $children */ public function tag_IsoCurrencyList($tag_params, $children) { // whether to to print only unique currencies $only_unique = isset($tag_params['unique']) && $tag_params['unique'] == '1'; if (isset($tag_params['template'])) { if (isset($tag_params['local']) && $tag_params['local'] == 1) { $template = new TemplateHandler($tag_params['template'], $this->path . 'templates/'); } else { $template = new TemplateHandler($tag_params['template']); } } else { $template = new TemplateHandler('iso_currency.xml', $this->path . 'templates/'); } // update cache $this->__update_cache(); $displayed = array(); foreach ($this->_cache as $currency_data) { if ($only_unique && in_array($currency_data['numeric_code'], $displayed)) { continue; } // store displayed currency $displayed[] = $currency_data['numeric_code']; // parse template $template->restoreXML(); $template->setLocalParams($currency_data); $template->parse(); } }
/** * Tag handler for printing link groups * * @param array $tag_params * @param array $children */ public function tag_GroupList($tag_params, $children) { $manager = LinkGroupsManager::getInstance(); $link_manager = LinksManager::getInstance(); $membership_manager = LinkMembershipManager::getInstance(); // save some CPU time by getting this early if (class_exists('gallery')) { $use_images = true; $gallery = gallery::getInstance(); $gallery_manager = GalleryManager::getInstance(); } else { $use_images = false; } $conditions = array(); if (isset($tag_params['sponsored']) && $tag_params['sponsored'] == '1') { $conditions['sponsored'] = 1; } $items = $manager->getItems($manager->getFieldNames(), $conditions, array('id')); if (isset($tag_params['template'])) { if (isset($tag_params['local']) && $tag_params['local'] == 1) { $template = new TemplateHandler($tag_params['template'], $this->path . 'templates/'); } else { $template = new TemplateHandler($tag_params['template']); } } else { $template = new TemplateHandler('groups_item.xml', $this->path . 'templates/'); } $template->setMappedModule($this->name); $template->registerTagHandler('_link', $this, 'tag_Link'); $template->registerTagHandler('_link_list', $this, 'tag_LinkList'); if (count($items) > 0) { foreach ($items as $item) { $thumbnail = ''; if ($use_images) { $first_link_id = $membership_manager->getItemValue('link', array('group' => $item->id)); // we have some links assigned to the group, get thumbnail if (!empty($first_link_id)) { $image_id = $link_manager->getItemValue('image', array('id' => $first_link_id)); if (!empty($image_id)) { $image = $gallery_manager->getSingleItem($gallery_manager->getFieldNames(), array('id' => $image_id)); $thumbnail = $gallery->getThumbnailURL($image); } } } $params = array('id' => $item->id, 'name' => $item->name, 'text_id' => $item->text_id, 'thumbnail' => $thumbnail, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('groups_change', 400, $this->getLanguageConstant('title_groups_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'groups_change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('groups_delete', 400, $this->getLanguageConstant('title_groups_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'groups_delete'), array('id', $item->id)))), 'item_links' => url_MakeHyperlink($this->getLanguageConstant('links'), window_Open('groups_links', 400, $this->getLanguageConstant('title_groups_links'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'groups_links'), array('id', $item->id))))); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }
/** * Show details for specified transaction */ private function showTransactionDetails() { $manager = ShopTransactionsManager::getInstance(); $buyer_manager = ShopBuyersManager::getInstance(); $address_manager = ShopDeliveryAddressManager::getInstance(); $id = fix_id($_REQUEST['id']); $transaction = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id)); $buyer = $buyer_manager->getSingleItem($buyer_manager->getFieldNames(), array('id' => $transaction->buyer)); $address = $address_manager->getSingleItem($address_manager->getFieldNames(), array('id' => $transaction->address)); $full_address = "{$address->name}\n\n{$address->street}\n"; $full_address .= "{$address->zip} {$address->city}\n"; if (empty($address->state)) { $full_address .= $address->country; } else { $full_address .= "{$address->state}, {$address->country}"; } $params = array('id' => $transaction->id, 'uid' => $transaction->uid, 'type' => $transaction->type, 'type_string' => '', 'status' => $transaction->status, 'currency' => $transaction->currency, 'handling' => $transaction->handling, 'shipping' => $transaction->shipping, 'timestamp' => $transaction->timestamp, 'delivery_method' => $transaction->delivery_method, 'remark' => $transaction->remark, 'total' => $transaction->total, 'first_name' => $buyer->first_name, 'last_name' => $buyer->last_name, 'email' => $buyer->email, 'address_name' => $address->name, 'address_street' => $address->street, 'address_city' => $address->city, 'address_zip' => $address->zip, 'address_state' => $address->state, 'address_country' => $address->country, 'full_address' => $full_address); $template = new TemplateHandler('transaction_details.xml', $this->path . 'templates/'); // register tag handler $template->registerTagHandler('_item_list', $this, 'tag_TransactionItemList'); $template->registerTagHandler('_transaction_status', $this, 'tag_TransactionStatus'); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Save new or changed API key. */ private function saveApiKey() { $api_key = fix_chars($_REQUEST['api_key']); $this->saveSetting('api_key', $api_key); // prepare and parse result message $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_api_key_saved'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('page_speed_set_api_key')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Handle drawing checkout form * * @param array $tag_params * @param array $children */ public function tag_CheckoutForm($tag_params, $children) { $account_information = array(); $shipping_information = array(); $billing_information = array(); $payment_method = null; $stage = isset($_REQUEST['stage']) ? fix_chars($_REQUEST['stage']) : null; $recurring = isset($_SESSION['recurring_plan']) && !empty($_SESSION['recurring_plan']); // decide whether to include shipping and account information if (isset($tag_params['include_shipping'])) { $include_shipping = fix_id($tag_params['include_shipping']) == 1; } else { $include_shipping = true; } $bad_fields = array(); $info_available = false; // grab user information if (!is_null($stage)) { // get payment method $payment_method = $this->getPaymentMethod($tag_params); if (is_null($payment_method)) { throw new PaymentMethodError('No payment method selected!'); } // get billing information $billing_information = $this->getBillingInformation($payment_method); $billing_required = array('billing_full_name', 'billing_card_type', 'billing_credit_card', 'billing_expire_month', 'billing_expire_year', 'billing_cvv'); $bad_fields = $this->checkFields($billing_information, $billing_required, $bad_fields); // get shipping information if ($include_shipping && $stage == 'set_info') { $shipping_information = $this->getShippingInformation(); $shipping_required = array('name', 'email', 'street', 'city', 'zip', 'country'); $bad_fields = $this->checkFields($shipping_information, $shipping_required, $bad_fields); } } $info_available = count($bad_fields) == 0 && !is_null($payment_method); if ($info_available) { $address_manager = ShopDeliveryAddressManager::getInstance(); $currency_manager = ShopCurrenciesManager::getInstance(); // get fields for payment method $return_url = url_Make('checkout_completed', 'shop', array('payment_method', $payment_method->get_name())); $cancel_url = url_Make('checkout_canceled', 'shop', array('payment_method', $payment_method->get_name())); // get currency info $currency = $this->settings['default_currency']; $currency_item = $currency_manager->getSingleItem(array('id'), array('currency' => $currency)); if (is_object($currency_item)) { $transaction_data['currency'] = $currency_item->id; } // get buyer $buyer = $this->getUserAccount(); if ($include_shipping) { $address = $this->getAddress($buyer, $shipping_information); } else { $address = null; } // update transaction $transaction_type = $recurring ? TransactionType::SUBSCRIPTION : TransactionType::SHOPPING_CART; $summary = $this->updateTransaction($transaction_type, $payment_method, '', $buyer, $address); // emit signal and return if handled if ($stage == 'set_info') { Events::trigger('shop', 'before-checkout', $payment_method->get_name(), $return_url, $cancel_url); foreach ($result_list as $result) { if ($result) { $this->showCheckoutRedirect(); return; } } } // create new payment if ($recurring) { // recurring payment $checkout_fields = $payment_method->new_recurring_payment($_SESSION['recurring_plan'], $billing_information, $return_url, $cancel_url); } else { // regular payment $checkout_fields = $payment_method->new_payment($transaction_data, $billing_information, $summary['items_for_checkout'], $return_url, $cancel_url); } // load template $template = $this->loadTemplate($tag_params, 'checkout_form.xml'); $template->registerTagHandler('cms:checkout_items', $this, 'tag_CheckoutItems'); $template->registerTagHandler('cms:delivery_methods', $this, 'tag_DeliveryMethodsList'); // parse template $params = array('checkout_url' => $payment_method->get_url(), 'checkout_fields' => $checkout_fields, 'checkout_name' => $payment_method->get_title(), 'currency' => $this->getDefaultCurrency(), 'recurring' => $recurring, 'include_shipping' => $include_shipping); // for recurring plans add additional params if ($recurring) { $plans = $payment_method->get_recurring_plans(); $plan_name = $_SESSION['recurring_plan']; $plan = $plans[$plan_name]; $params['plan_name'] = $plan['name']; $params['plan_description'] = $this->formatRecurring(array('price' => $plan['price'], 'period' => $plan['interval_count'], 'period' => $plan['interval_count'], 'unit' => $plan['interval'], 'setup' => $plan['setup_price'], 'trial_period' => $plan['trial_count'], 'trial_unit' => $plan['trial'])); } else { $params['sub-total'] = number_format($summary['total'], 2); $params['shipping'] = number_format($summary['shipping'], 2); $params['handling'] = number_format($summary['handling'], 2); $params['total_weight'] = number_format($summary['weight'], 2); $params['total'] = number_format($summary['total'] + $summary['shipping'] + $summary['handling'], 2); } $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } else { // no information available, show form $template = new TemplateHandler('buyer_information.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $template->registerTagHandler('cms:card_type', $this, 'tag_CardType'); // get fixed country if set $fixed_country = ''; if (isset($this->settings['fixed_country'])) { $fixed_country = $this->settings['fixed_country']; } $params = array('include_shipping' => $include_shipping, 'fixed_country' => $fixed_country, 'bad_fields' => $bad_fields, 'recurring' => $recurring); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } }
/** * Save settings */ private function saveSettings() { $secret_key = fix_chars($_REQUEST['secret_key']); $public_key = fix_chars($_REQUEST['public_key']); $this->saveSetting('secret_key', $secret_key); $this->saveSetting('public_key', $public_key); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_settings_saved'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('stripe')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Perform price removal */ private function deletePrice_Commit() { $manager = ShopDeliveryMethodPricesManager::getInstance(); $relations_manager = ShopDeliveryItemRelationsManager::getInstance(); $id = fix_id($_REQUEST['id']); $manager->deleteData(array('id' => $id)); $relations_manager->deleteData(array('price' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->_parent->name); $params = array('message' => $this->_parent->getLanguageConstant("message_delivery_price_deleted"), 'button' => $this->_parent->getLanguageConstant("close"), 'action' => window_Close('shop_delivery_price_delete') . ";" . window_ReloadContent('shop_delivery_method_prices')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Perform category removal */ private function deleteCategory_Commit() { $id = fix_id($_REQUEST['id']); $manager = ShopCategoryManager::getInstance(); $manager->deleteData(array('id' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->_parent->getLanguageConstant('message_category_deleted'), 'button' => $this->_parent->getLanguageConstant('close'), 'action' => window_Close('shop_category_delete') . ";" . window_ReloadContent('shop_categories')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Show affiliate information. */ private function showAffiliateInformation() { global $url_rewrite; $manager = AffiliatesManager::getInstance(); $user_id = $_SESSION['uid']; $affiliate = $manager->getSingleItem($manager->getFieldNames(), array('user' => $user_id)); if (is_object($affiliate)) { $template = new TemplateHandler('information.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); if ($affiliate->clicks > 0) { $rate = round(100 * $affiliate->conversions / $affiliate->clicks, 2); } else { $rate = 0; } $params = array('uid' => $affiliate->uid, 'name' => $affiliate->name, 'clicks' => $affiliate->clicks, 'conversions' => $affiliate->conversions, 'rate' => $rate, 'url_rewrite' => $url_rewrite ? 'true' : 'false', 'cancel_action' => window_Close('affiliate_information')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } }
/** * Save settings. */ private function saveSettings() { $key = fix_chars($_REQUEST['key']); $password = fix_chars($_REQUEST['password']); $account = fix_chars($_REQUEST['account']); $meter = fix_chars($_REQUEST['meter']); $this->saveSetting('fedex_key', $key); $this->saveSetting('fedex_password', $password); $this->saveSetting('fedex_account', $account); $this->saveSetting('fedex_meter', $meter); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_settings_saved'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('fedex')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Perfrom field removal. */ private function deleteField_Commit() { $id = fix_id($_REQUEST['id']); $manager = ContactForm_FormFieldManager::getInstance(); $form = $manager->getItemValue('form', array('id' => $id)); $manager->deleteData(array('id' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_field_deleted'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('contact_form_fields_delete') . ';' . window_ReloadContent('contact_form_fields_' . $form)); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Save comment data and send response as JSON Object */ private function saveCommentData() { if ($this->_canPostComment()) { $module = isset($_REQUEST['module']) && !empty($_REQUEST['module']) ? fix_chars($_REQUEST['module']) : null; $comment_section = isset($_REQUEST['comment_section']) && !empty($_REQUEST['comment_section']) ? fix_chars($_REQUEST['comment_section']) : null; $user = fix_chars($_REQUEST['user']); $email = fix_chars($_REQUEST['email']); $message = fix_chars($_REQUEST['comment']); if (strlen($message) > $this->settings['size_limit']) { $tmp = str_split($message, $this->settings['size_limit']); $message = $tmp[0]; } if (!is_null($module) || !is_null($comment_section)) { $data = array('module' => $module, 'section' => $comment_section, 'user' => $user, 'email' => $email, 'address' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'], 'message' => $message, 'visible' => $this->settings['default_visibility']); $manager = CommentManager::getInstance(); $manager->insertData($data); $response_message = $this->getLanguageConstant('message_saved'); } else { // invalide module and/or comment section $response_message = $this->getLanguageConstant('message_error'); } } else { $response_message = str_replace('%t', $this->settings['repost_time'], $this->getLanguageConstant('message_error_repost_time')); } $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $reponse_message, 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('comments_settings')); $params = array_merge($params, $this->settings); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Perform tip removal */ private function deleteTip_Commit() { $id = fix_id(fix_chars($_REQUEST['id'])); $manager = TipManager::getInstance(); $manager->deleteData(array('id' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant("message_tip_deleted"), 'button' => $this->getLanguageConstant("close"), 'action' => window_Close('tips_delete') . ";" . window_ReloadContent('tips')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Perform interval removal. */ private function delete_interval_commit() { $id = fix_id($_REQUEST['id']); $manager = IntervalManager::getInstance(); $time_manager = IntervalTimeManager::getInstance(); $manager->deleteData(array('id' => $id)); $time_manager->deleteData(array('interval' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_interval_deleted'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('delivery_intervals_delete') . ';' . window_ReloadContent('delivery_intervals')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Perform manufacturer removal */ private function deleteManufacturer_Commit() { $id = fix_id($_REQUEST['id']); $manager = ShopManufacturerManager::getInstance(); $item_manager = ShopItemManager::getInstance(); $manager->deleteData(array('id' => $id)); $item_manager->updateData(array('manufacturer' => 0), array('manufacturer' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->_parent->getLanguageConstant("message_manufacturer_deleted"), 'button' => $this->_parent->getLanguageConstant("close"), 'action' => window_Close('shop_manufacturer_delete') . ";" . window_ReloadContent('shop_manufacturers')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Handle _downloads_list tag * * @param array $tag_params * @param array $children */ public function tag_DownloadsList($tag_params, $children) { $manager = DownloadsManager::getInstance(); $conditions = array(); if (!isset($tag_params['show_invisible'])) { $conditions['visible'] = 1; } // get items from database $items = $manager->getItems($manager->getFieldNames(), $conditions); if (isset($tag_params['template'])) { if (isset($tag_params['local']) && $tag_params['local'] == 1) { $template = new TemplateHandler($tag_params['template'], $this->path . 'templates/'); } else { $template = new TemplateHandler($tag_params['template']); } } else { $template = new TemplateHandler('list_item.xml', $this->path . 'templates/'); } $template->setMappedModule($this->name); $template->registerTagHandler('_download', $this, 'tag_Download'); if (count($items) > 0) { foreach ($items as $item) { $params = array('id' => $item->id, 'name' => $item->name, 'description' => $item->description, 'filename' => $item->filename, 'size' => $item->size, 'count' => $item->count, 'visible' => $item->visible, 'timestamp' => $item->timestamp, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('downloads_change', 400, $this->getLanguageConstant('title_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('downloads_delete', 400, $this->getLanguageConstant('title_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'delete'), array('id', $item->id))))); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }
/** * Show mailing lists window. */ private function showLists() { // update list $this->updateLists(); // create template $template = new TemplateHandler('lists.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); // create menu links // create template params $params = array(); // register tag handlers $template->registerTagHandler('cms:items', $this, 'tag_ListItems'); // show template $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Tag handler for printing article list * * @param array $tag_params * @param array $children */ public function tag_ArticleRatingImage($tag_params, $children) { if (isset($tag_params['id'])) { // print image tag with specified URL $id = fix_id($tag_params['id']); $type = isset($tag_params['type']) ? $tag_params['type'] : ImageType::Stars; $manager = ArticleManager::getInstance(); $item = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id)); $template = new TemplateHandler('rating_image.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); if (is_object($item)) { $url = url_Make('get_rating_image', $this->name, array('type', $type), array('id', $id)); $params = array('url' => $url, 'rating' => round($this->getArticleRating($item, 5), 2)); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } else { if (isset($_REQUEST['id'])) { // print image itself $id = fix_id($_REQUEST['id']); $type = isset($_REQUEST['type']) ? fix_id($_REQUEST['type']) : ImageType::Stars; $manager = ArticleManager::getInstance(); $item = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id)); switch ($type) { case ImageType::Stars: $background_image = 'stars_bg.png'; $foreground_image = 'stars.png'; break; case ImageType::Circles: $background_image = 'circles_bg.png'; $foreground_image = 'circles.png'; break; default: $background_image = 'stars_bg.png'; $foreground_image = 'stars.png'; break; } $img_bg = imagecreatefrompng($this->path . 'images/' . $background_image); $img_fg = imagecreatefrompng($this->path . 'images/' . $foreground_image); // get rating based on image width if (is_object($item)) { $rating = $this->getArticleRating($item, imagesx($img_bg)); } else { $rating = 0; } $img = imagecreatetruecolor(imagesx($img_bg), imagesy($img_bg)); imagesavealpha($img, true); // make image transparent $transparent_color = imagecolorallocatealpha($img, 0, 0, 0, 127); imagefill($img, 0, 0, $transparent_color); // draw background image imagecopy($img, $img_bg, 0, 0, 0, 0, imagesx($img_bg), imagesy($img_bg)); // draw foreground images imagecopy($img, $img_fg, 0, 0, 0, 0, $rating, imagesy($img_bg)); header('Content-type: image/png'); imagepng($img); imagedestroy($img); } } }
/** * Save settings */ private function saveSettings() { $description = fix_chars($_REQUEST['description']); $analytics = fix_chars($_REQUEST['analytics']); $analytics_domain = fix_chars($_REQUEST['analytics_domain']); $analytics_version = fix_chars($_REQUEST['analytics_version']); $wm_tools = fix_chars($_REQUEST['wm_tools']); $bing_wm_tools = fix_chars($_REQUEST['bing_wm_tools']); $optimizer = fix_chars($_REQUEST['optimizer']); $optimizer_key = fix_chars($_REQUEST['optimizer_key']); $this->saveSetting('description', $description); $this->saveSetting('analytics', $analytics); $this->saveSetting('analytics_domain', $analytics_domain); $this->saveSetting('analytics_version', $analytics_version); $this->saveSetting('wm_tools', $wm_tools); $this->saveSetting('bing_wm_tools', $bing_wm_tools); $this->saveSetting('optimizer', $optimizer); $this->saveSetting('optimizer_key', $optimizer_key); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant('message_saved'), 'button' => $this->getLanguageConstant('close'), 'action' => window_Close('page_settings')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Show search results for various backend tools */ private function showSearchResults() { $query = fix_chars($_REQUEST['query']); $template = new TemplateHandler('search_results.xml', $this->path . 'templates/'); $params = array('query' => $query); // register tag handler $template->registerTagHandler('_item_list', $this, 'tag_ItemList'); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Show page for printing all attached cards with selected text. */ private function print_card() { $id = fix_id($_REQUEST['transaction']); $manager = ShopTransactionsManager::getInstance(); $item_manager = ShopItemManager::getInstance(); $transaction_item_manager = ShopTransactionItemsManager::getInstance(); // get transaction with specified id $transaction = $manager->getSingleItem(array('id'), array('id' => $id)); // ensure transaction is a valid one if (!is_object($transaction)) { return; } // get items associated with transaction $transaction_items = $transaction_item_manager->getItems(array('item', 'description'), array('transaction' => $transaction->id)); if (count($transaction_items) == 0) { return; } $id_list = array(); $description_list = array(); foreach ($transaction_items as $item) { $id_list[] = $item->item; $description_list[$item->item] = $item->description; } // get unique id and gallery $shop_items = $item_manager->getItems(array('id', 'uid', 'gallery'), array('id' => $id_list)); if (count($shop_items) == 0) { return; } // prepare final list and only include items that are actually known cards $items = array(); foreach ($shop_items as $item) { if (!array_key_exists($item->uid, $this->text_position)) { continue; } $position = $this->text_position[$item->uid]; $description = unserialize($description_list[$item->id]); $data = array('text' => $description['text'], 'top' => $position[0] . '%', 'left' => $position[1] . '%', 'bottom' => $position[2] . '%', 'right' => $position[3] . '%', 'image' => gallery::getGroupImageById($item->gallery)); $items[] = $data; } // prepare template $template = new TemplateHandler('print_card.xml', $this->path . 'templates/'); if (count($items) > 0) { foreach ($items as $item) { $template->setLocalParams($item); $template->restoreXML(); $template->parse(); } } }
/** * Perform logout procedure */ private function logout_commit() { // change session type to default Session::change_type(); // kill session variables unset($_SESSION['uid']); unset($_SESSION['logged']); unset($_SESSION['level']); unset($_SESSION['username']); unset($_SESSION['fullname']); // get message $message = $this->parent->getLanguageConstant('message_logout_ok'); // get url $url = url_SetRefresh(url_Make('', $this->parent->name), 2); // load template and show the message $template = new TemplateHandler('session_message.xml', $this->parent->path . 'templates/'); $template->setMappedModule($this->parent->name); $params = array('message' => $message, 'redirect_url' => $url); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }