/** * Checks validity of captcha against $value * * @param string $value * @return boolean */ public function isCaptchaValid($value) { $result = false; if (!isset($_SESSION['captcha'])) { return $result; } $saved_value = fix_chars($_SESSION['captcha']); $result = $saved_value == $value; return $result; }
/** * Remove illegal characters and tags from input strings to avoid XSS. * It also replaces few tags such as [b] [small] [big] [i] [u] [tt] into * <b> <small> <big> <i> <u> <tt> * * @param string $string Input string * @return string * @author MeanEYE */ function fix_chars($string, $strip_tags = true) { if (!is_array($string)) { $string = strip_tags($string); $string = str_replace("*", "*", $string); $string = str_replace(chr(92) . chr(34), """, $string); $string = str_replace("\r\n", "\n", $string); $string = str_replace("\\'", "'", $string); $string = str_replace("'", "'", $string); $string = str_replace(chr(34), """, $string); $string = str_replace("<", "<", $string); $string = str_replace(">", ">", $string); } else { foreach ($string as $key => $value) { $string[$key] = fix_chars($value); } } return $string; }
/** * Register new referral * * @return boolean */ private function createReferral() { $result = false; $manager = AffiliatesManager::getInstance(); $referrals_manager = AffiliateReferralsManager::getInstance(); // prepare data $uid = fix_chars($_REQUEST['affiliate']); $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $base_url = url_GetBaseURL(); $landing = url_MakeFromArray($_REQUEST); $landing = mb_substr($landing, 0, mb_strlen($base_url)); // get affiliate $affiliate = $manager->getSingleItem($manager->getFieldNames(), array('uid' => $uid)); // if affiliate code is not valid, assign to default affiliate if (!is_object($affiliate)) { $affiliate = $manager->getSingleItem($manager->getFieldNames(), array('default' => 1)); } // if affiliate exists, update if (is_object($affiliate) && !is_null($referer)) { $referral_data = array('url' => $referer, 'landing' => $landing, 'affiliate' => $affiliate->id, 'conversion' => 0); $referrals_manager->insertData($data); $id = $referrals_manager->getInsertedID(); $_SESSION['referral_id'] = $id; // increase referrals counter $manager->updateData(array('clicks' => '`clicks` + 1'), array('id' => $affiliate->id)); $result = true; } return result; }
/** * Set page description for current execution. * * @param array $tag_params * @param array $children */ private function setDescription($tag_params, $children) { global $language; // set from language constant if (isset($tag_params['constant'])) { $language_handler = MainLanguageHandler::getInstance(); $constant = fix_chars($tag_params['constant']); $this->page_description = $language_handler->getText($constant); // set from article } else { if (isset($tag_params['article']) && class_exists('articles')) { $manager = ArticleManager::getInstance(); $text_id = fix_chars($tag_params['article']); // get article from database $item = $manager->getSingleItem(array('content'), array('text_id' => $text_id)); if (is_object($item)) { $content = strip_tags(Markdown($item->content[$language])); $data = explode("\n", utf8_wordwrap($content, 150, "\n", true)); if (count($data) > 0) { $this->page_description = $data[0]; } } } } }
/** * Handle printing search results * * Modules need to return results in following format: * array( * array( * 'score' => 0..100 // score for this result * 'title' => '', // title to be shown in list * 'description' => '', // short description, if exists * 'id' => 0, // id of containing item * 'type' => '', // type of item * 'module' => '' // module name * ), * ... * ); * * Resulting array doesn't need to be sorted. * * @param array $tag_params * @param array $children */ public function tag_ResultList($tag_params, $children) { // get search query $query_string = null; $threshold = 25; $limit = 30; // get query if (isset($tag_params['query'])) { $query_string = mb_strtolower(fix_chars($tag_params['query'])); } if (isset($_REQUEST['query']) && is_null($query_string)) { $query_string = mb_strtolower(fix_chars($_REQUEST['query'])); } if (is_null($query_string)) { return; } // get threshold if (isset($tag_params['threshold'])) { $threshold = fix_chars($tag_params['threshold']); } if (isset($_REQUEST['threshold']) && is_null($threshold)) { $threshold = fix_chars($_REQUEST['threshold']); } // get limit if (isset($tag_params['limit'])) { $limit = fix_id($tag_params['limit']); } // get list of modules to search on $module_list = null; if (isset($tag_params['module_list'])) { $module_list = fix_chars(split(',', $tag_params['module_list'])); } if (isset($_REQUEST['module_list']) && is_null($module_list)) { $module_list = fix_chars(split(',', $_REQUEST['module_list'])); } if (is_null($module_list)) { $module_list = array_keys($this->modules); } // get intersection of available and specified modules $available_modules = array_keys($this->modules); $module_list = array_intersect($available_modules, $module_list); // get results from modules $results = array(); if (count($module_list) > 0) { foreach ($module_list as $name) { $module = $this->modules[$name]; $results = array_merge($results, $module->getSearchResults($query_string, $threshold)); } } // sort results usort($results, array($this, 'sortResults')); // apply limit if ($limit > 0) { $results = array_slice($results, 0, $limit); } // load template $template = $this->loadTemplate($tag_params, 'result.xml'); // parse results if (count($results) > 0) { foreach ($results as $params) { $template->setLocalParams($params); $template->restoreXML(); $template->parse(); } } }
$rowData = ""; $colCount = 0; foreach ($rows as $cell) { $rowData = $rowData . $cell->plaintext . ", "; array_push($columns, fix_chars($cell->plaintext)); $data[$colCount] = array(); $colCount++; } } else { $rows = $row->find("td"); $rowData = ""; $colCount = 0; $rowResult = array(); foreach ($rows as $cell) { $rowData = $rowData . $cell->plaintext . ", "; array_push($data[$colCount], fix_chars($cell->plaintext)); $colCount++; } } $rowCount++; } $colCount = 0; $rowCount = 0; $currentDate = date('Y-m-d'); foreach ($data[0] as $row) { $cols = array(); $colCount = 0; foreach ($columns as $col) { array_push($cols, "aa"); $colCount++; }
/** * Save new or changed item data */ private function saveItem() { $manager = ShopItemSizesManager::getInstance(); $id = isset($_REQUEST['id']) ? fix_id($_REQUEST['id']) : null; $name = fix_chars($_REQUEST['name']); if (is_null($id)) { $window = 'shop_item_size_add'; $manager->insertData(array('name' => $name)); } else { $window = 'shop_item_size_change'; $manager->updateData(array('name' => $name), array('id' => $id)); } // show message $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->_parent->getLanguageConstant('message_item_size_saved'), 'button' => $this->_parent->getLanguageConstant('close'), 'action' => window_Close($window) . ";" . window_ReloadContent('shop_item_sizes') . ';'); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Redirect user based on specified code */ private function redirect() { define('_OMIT_STATS', 1); $code = fix_chars($_REQUEST['code']); $manager = CodeManager::getInstance(); $url = $manager->getItemValue("url", array("code" => $code)); $_SESSION['request_code'] = $code; print url_SetRefresh($url, 0); }
/** * Tag handler for tip list * * @param array $tag_params * @param array $children */ public function tag_TipList($tag_params, $children) { $manager = TipManager::getInstance(); $conditions = array(); $limit = null; $order_by = array('id'); $order_asc = true; if (isset($tag_params['only_visible']) && $tag_params['only_visible'] == 1) { $conditions['visible'] = 1; } if (isset($tag_params['order_by'])) { $order_by = explode(',', fix_chars($tag_params['order_by'])); } if (isset($tag_params['order_asc'])) { $order_asc = $tag_params['order_asc'] == '1' || $tag_params['order_asc'] == 'yes'; } if (isset($tag_params['limit'])) { $limit = fix_id($tag_params['limit']); } $template = $this->loadTemplate($tag_params, 'list_item.xml'); $template->setMappedModule($this->name); // get items $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc, $limit); if (count($items) > 0) { foreach ($items as $item) { $params = array('id' => $item->id, 'content' => $item->content, 'visible' => $item->visible, 'item_change' => url_MakeHyperlink($this->getLanguageConstant('change'), window_Open('tips_change', 400, $this->getLanguageConstant('title_tips_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'tips_change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->getLanguageConstant('delete'), window_Open('tips_delete', 400, $this->getLanguageConstant('title_tips_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'tips_delete'), array('id', $item->id))))); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } } }
/** * Tag handler for category list * * @param array $tag_params * @param array $children */ public function tag_CategoryList($tag_params, $children) { global $language; $manager = ShopCategoryManager::getInstance(); $conditions = array(); $order_by = array(); $order_asc = true; $item_category_ids = array(); $item_id = isset($tag_params['item_id']) ? fix_id($tag_params['item_id']) : null; // create conditions if (isset($tag_params['parent_id'])) { // set parent from tag parameter $conditions['parent'] = fix_id($tag_params['parent_id']); } else { if (isset($tag_params['parent'])) { // get parent id from specified text id $text_id = fix_chars($tag_params['parent']); $parent = $manager->getSingleItem(array('id'), array('text_id' => $text_id)); if (is_object($parent)) { $conditions['parent'] = $parent->id; } else { $conditions['parent'] = -1; } } else { if (!isset($tag_params['show_all'])) { $conditions['parent'] = 0; } } } if (isset($tag_params['level'])) { $level = fix_id($tag_params['level']); } else { $level = 0; } if (isset($tag_params['exclude'])) { $list = fix_id(explode(',', $tag_params['exclude'])); $conditions['id'] = array('operator' => 'NOT IN', 'value' => $list); } if (!is_null($item_id)) { $membership_manager = ShopItemMembershipManager::getInstance(); $membership_items = $membership_manager->getItems(array('category'), array('item' => $item_id)); if (count($membership_items) > 0) { foreach ($membership_items as $membership) { $item_category_ids[] = $membership->category; } } } // get order list if (isset($tag_params['order_by'])) { $order_by = fix_chars(split(',', $tag_params['order_by'])); } else { $order_by = array('title_' . $language); } if (isset($tag_params['order_ascending'])) { $order_asc = $tag_params['order_asc'] == '1' or $tag_params['order_asc'] == 'yes'; } else { // get items from database $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc); } // create template handler $template = $this->_parent->loadTemplate($tag_params, 'category_list_item.xml'); $template->registerTagHandler('_children', $this, 'tag_CategoryList'); // initialize index $index = 0; // parse template if (count($items) > 0) { foreach ($items as $item) { $image_url = ''; $thumbnail_url = ''; if (class_exists('gallery')) { $gallery = gallery::getInstance(); $gallery_manager = GalleryManager::getInstance(); $image = $gallery_manager->getSingleItem(array('filename'), array('id' => $item->image)); if (!is_null($image)) { $image_url = $gallery->getImageURL($image); $thumbnail_url = $gallery->getThumbnailURL($image); } } $params = array('id' => $item->id, 'index' => $index++, 'item_id' => $item_id, 'parent' => $item->parent, 'image_id' => $item->image, 'image' => $image_url, 'thumbnail' => $thumbnail_url, 'text_id' => $item->text_id, 'title' => $item->title, 'description' => $item->description, 'level' => $level, 'in_category' => in_array($item->id, $item_category_ids) ? 1 : 0, 'selected' => isset($tag_params['selected']) ? fix_id($tag_params['selected']) : 0, 'item_change' => url_MakeHyperlink($this->_parent->getLanguageConstant('change'), window_Open('shop_category_change', 400, $this->_parent->getLanguageConstant('title_category_change'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'change'), array('id', $item->id)))), 'item_delete' => url_MakeHyperlink($this->_parent->getLanguageConstant('delete'), window_Open('shop_category_delete', 270, $this->_parent->getLanguageConstant('title_category_delete'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'delete'), array('id', $item->id)))), 'item_add' => url_MakeHyperlink($this->_parent->getLanguageConstant('add'), window_Open('shop_category_add', 400, $this->_parent->getLanguageConstant('title_category_add'), false, false, url_Make('transfer_control', 'backend_module', array('module', $this->name), array('backend_action', 'categories'), array('sub_action', 'add'), array('parent', $item->id))))); $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(); }
/** * Create JSON object containing group items */ private function json_GroupList() { define('_OMIT_STATS', 1); $groups = array(); $conditions = array(); $limit = isset($tag_params['limit']) ? fix_id($tag_params['limit']) : null; $order_by = isset($tag_params['order_by']) ? explode(',', fix_chars($tag_params['order_by'])) : array('id'); $order_asc = isset($tag_params['order_asc']) && $tag_params['order_asc'] == 'yes' ? true : false; $manager = LinkGroupsManager::getInstance(); $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc, $limit); $result = array('error' => false, 'error_message' => '', 'items' => array()); if (count($items) > 0) { foreach ($items as $item) { $result['items'][] = array('id' => $item->id, 'name' => $item->name); } } else { } print json_encode($result); }
/** * Save default currency */ private function saveDefault() { $currency = fix_chars($_REQUEST['currency']); $this->_parent->saveDefaultCurrency($currency); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->_parent->getLanguageConstant('message_default_currency_saved'), 'button' => $this->_parent->getLanguageConstant('close'), 'action' => window_Close('shop_currencies_set_default')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
function scrapeTable($inputGrid, $stationID) { $entries = $inputGrid->find("tr"); $rowCount = 0; foreach ($entries as $entry) { $trainDepartureTime = ""; $isDeviationInDeparture = ""; $trainDeviatingDepartureTime = ""; $trainName = ""; $trainLink = ""; $trainDestination = ""; $trainOperatorName = ""; $trainOperatorLink = ""; $trainCurrentState = ""; $trainCurrentStatePlace = ""; $trainDeviationInMinutes = ""; $trainDeviationType = ""; $trainType = ""; $trainTrack = ""; $cells = $entry->find("td"); $colCount = 0; if ($rowCount > 0) { foreach ($cells as $cell) { $divs = $cell->find("div"); $divCount = 0; $isDeviationInDeparture = false; foreach ($divs as $div) { $data = strip_tags_attributes($div, '<a>', 'href'); if ($colCount == 0) { if ($divCount == 0) { $trainDepartureTime = $data; # print("Ordinarie avgångstid: " . $trainDepartureTime); } if ($divCount == 1) { if ($data == "Avgick") { $isDeviationInDeparture = true; } else { $isDeviationInDeparture = false; } } if ($divCount == 2 && $isDeviationInDeparture == true) { $trainDeviatingDepartureTime = $data; # print("\nAvgick: ". $data); } } if ($colCount == 1) { // 1. Tåg nr + länk if ($divCount == 0) { $trainLink = get_href($data); $trainName = str_replace(" till", "", strip_tags(fix_chars($data))); $trainName = str_replace("Tåg nr ", "", $trainName); # print("Tåg nr: ". $trainName); } // 2. Destination if ($divCount == 1) { $trainDestination = fix_chars($data); # print(" Till: " . $trainDestination ); } // 3. Operatör + länk if ($divCount == 2) { $trainOperatorLink = get_href($data); $trainOperatorName = fix_chars(trim(strip_tags($data))); # print (" Operatör: " . $trainOperatorName . " (" . $trainOperatorLink . ")" ); } } if ($colCount == 2) { // Tåg som just passerat / ankommit if ($divCount == 0) { if (strpos($data, "Ankom")) { $trainCurrentState = "ARRIVED"; $trainCurrentStatePlace = str_replace("Ankom ", "", fix_chars($data)); } else { $trainCurrentState = "PASSED"; $trainCurrentStatePlace = str_replace("Passerade ", "", fix_chars($data)); } # print("--> " . $trainCurrentState . " " . $trainCurrentStatePlace ); } // Avvikelse i minuter if ($divCount == 1) { if (strpos($data, "tidig")) { $trainDeviationInMinutes = str_replace(" min tidig", "", fix_chars($data)); $trainDeviationType = "EARLY"; } else { $trainDeviationInMinutes = str_replace(" min försenad", "", fix_chars($data)); $trainDeviationType = "EARLY"; } # print(" (" . $trainDeviationInMinutes . " " . $trainDeviationType . ")"); } } if ($colCount == 3) { // Hämta tågtyp if ($divCount == 0) { $trainType = fix_chars($data); # print("Tågtyp: " . $trainType); } } if ($colCount == 4) { if ($divCount == 0) { $trainTrack = trim($data); # print("Spår: " . $data); } } $divCount++; } # print("\n"); $colCount++; } } // trainDepartureTime, isDeviationInDeparture, trainDeviatingDepartureTime // trainName, trainLink, trainDestination, trainOperatorName, trainOperatorLink, // trainCurrentState, trainCurrentStatePlace // trainDeviationInMinutes, trainDeviationType // trainType, trainTrack $dataset = array('StationID' => $stationID, 'Avgång' => $trainDepartureTime, 'Avvikelse' => $isDeviationInDeparture, 'AvvikelseAvgång' => $isDeviationInDeparture, 'TågNamn' => $trainName, 'TågLänk' => $trainLink, 'Destination' => $trainDestination, 'Operatör' => $trainOperatorName, 'OperatörLänk' => $trainOperatorLink, 'Aktuellt' => $trainCurrentState, 'AktuelltPlats' => $trainCurrentStatePlace, 'AvvikelseMinuter' => $trainDeviationInMinutes, 'AvvikelseTyp' => $trainDeviationType, 'TågTyp' => $trainType, 'Spår' => $trainTrack); if ($rowCount > 0) { scraperwiki::save(array('Avgång', 'TågNamn'), $dataset); #print("Tågnamn : " . $trainName); } #print( "\n" ); $rowCount++; } }
/** * 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(); } }
/** * Perform feed removal */ private function deleteFeed_Commit() { $id = fix_id(fix_chars($_REQUEST['id'])); $manager = NewsFeedManager::getInstance(); $manager->deleteData(array('id' => $id)); $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->getLanguageConstant("message_news_deleted"), 'button' => $this->getLanguageConstant("close"), 'action' => window_Close('news_feeds_delete') . ";" . window_ReloadContent('news')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Print JSON object containing all the comments * * @param boolean $only_visible */ private function printCommentData($only_visible = true) { $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; $result = array(); if (!is_null($module) || !is_null($comment_section)) { $result['error'] = 0; $result['error_message'] = ''; $starting_with = isset($_REQUEST['starting_with']) ? fix_id($_REQUEST['starting_with']) : null; $manager = CommentManager::getInstance(); $conditions = array('module' => $module, 'section' => $comment_section); if (!is_null($starting_with)) { $conditions['id'] = array('operator' => '>', 'value' => $starting_with); } if ($only_visible) { $conditions['visible'] = 1; } $items = $manager->getItems(array('id', 'user', 'message', 'timestamp'), $conditions); $result['last_id'] = 0; $result['comments'] = array(); if (count($items) > 0) { foreach ($items as $item) { $timestamp = strtotime($item->timestamp); $date = date($this->getLanguageConstant('format_date_short'), $timestamp); $time = date($this->getLanguageConstant('format_time_short'), $timestamp); $result['comments'][] = array('id' => $item->id, 'user' => empty($item->user) ? 'Anonymous' : $item->user, 'content' => $item->message, 'date' => $date, 'time' => $time); } $result['last_id'] = end($items)->id; } } else { // no comments_section and/or module specified $result['error'] = 1; $result['error_message'] = $this->getLanguageConstant('message_error_data'); } print json_encode($result); }
/** * Handle drawing a single form. * * @param array $tag_params * @param array $children */ public function tag_Form($tag_params, $children) { $conditions = array(); $manager = ContactForm_FormManager::getInstance(); $field_manager = ContactForm_FormFieldManager::getInstance(); // get parameters if (isset($tag_params['text_id'])) { $conditions['text_id'] = fix_chars($tag_params['text_id']); } if (isset($tag_params['id'])) { $conditions['id'] = fix_id($tag_params['id']); } // load template $template = $this->loadTemplate($tag_params, 'form.xml'); $template->registerTagHandler('cms:fields', $this, 'tag_FieldList'); // get form from the database $item = $manager->getSingleItem($manager->getFieldNames(), $conditions); if (is_object($item)) { $fields = $field_manager->getItems(array('id'), array('form' => $item->id, 'type' => 'file')); $params = array('id' => $item->id, 'text_id' => $item->text_id, 'name' => $item->name, 'action' => !empty($item->action) ? $item->action : url_Make('submit', $this->name), 'template' => $item->template, 'use_ajax' => $item->use_ajax, 'show_submit' => $item->show_submit, 'show_reset' => $item->show_reset, 'show_cancel' => $item->show_cancel, 'show_controls' => $item->show_submit || $item->show_reset || $item->show_cancel, 'has_files' => count($fields) > 0); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } }
/** * Store file in new location */ private function _saveUpload($field_name) { $result = array('error' => false, 'message' => ''); if (is_uploaded_file($_FILES[$field_name]['tmp_name'])) { // prepare data for recording $file_name = $this->_getFileName(fix_chars(basename($_FILES[$field_name]['name']))); if (move_uploaded_file($_FILES[$field_name]['tmp_name'], $this->path . 'files/' . $file_name)) { // file was moved properly, record new data $result['filename'] = $file_name; $result['message'] = $this->getLanguageConstant('message_file_uploaded'); } else { // error moving file to new location. folder permissions? $result['error'] = true; $result['message'] = $this->getLanguageConstant('message_file_save_error'); } } else { // there was an error during upload, notify user $result['error'] = true; $result['message'] = $this->getLanguageConstant('message_file_upload_error'); } return $result; }
/** * Get language constants for specified array */ private function json_GetTextArray() { // check if we were asked to get languages from specific module if (isset($_REQUEST['from_module']) && class_exists($_REQUEST['from_module'])) { $module = call_user_func(array(escape_chars($_REQUEST['from_module']), 'getInstance')); $language_handler = $module->language; } else { $language_handler = MainLanguageHandler::getInstance(); } // prepare variables $constants = fix_chars($_REQUEST['constants']); $result = array('text' => array()); // get constants if (count($constants) > 0) { foreach ($constants as $constant) { $result['text'][$constant] = $language_handler->getText($constant); } } print json_encode($result); }
/** * Generate JSON object list for specified parameters */ private function json_ArticleList() { global $language; $manager = ArticleManager::getInstance(); $group_manager = ArticleGroupManager::getInstance(); $admin_manager = UserManager::getInstance(); $conditions = array(); $order_by = array('id'); $order_asc = true; // give the ability to limit number of articles to display if (isset($_REQUEST['limit'])) { $limit = fix_id($_REQUEST['limit']); } else { $limit = null; } // get parameters if (isset($_REQUEST['id'])) { $conditions['id'] = fix_id($_REQUEST['id']); } if (isset($_REQUEST['text_id'])) { $conditions['text_id'] = explode(',', $_REQUEST['text_id']); } if (isset($_REQUEST['order_by'])) { $order_by = explode(',', fix_chars($_REQUEST['order_by'])); } if (isset($_REQUEST['random']) && $_REQUEST['random'] == 1) { $order_by = array('RAND()'); } if (isset($_REQUEST['order_asc'])) { $order_asc = $_REQUEST['order_asc'] == 1 ? true : false; } if (isset($_REQUEST['only_visible']) && $_REQUEST['only_visible'] == 1) { $conditions['visible'] = 1; } if (isset($_REQUEST['group'])) { $group_id_list = array(); $group_names = explode(',', $_REQUEST['group']); if (count($group_names) > 0 && is_numeric($group_names[0])) { // specified group is a number, treat it as group id $group_id_list = $group_names; } else { // get id's from specitifed text_id $groups = $group_manager->getItems($group_manager->getFieldNames(), array('text_id' => $group_names)); if (count($groups) > 0) { foreach ($groups as $group) { $group_id_list[] = $group->id; } } } if (count($group_id_list) > 0) { $conditions['group'] = $group_id_list; } else { $conditions['group'] = -1; } } $all_languages = isset($_REQUEST['all_languages']) && $_REQUEST['all_languages'] == 1; $rating_image_type = isset($_REQUEST['rating_image_type']) ? $_REQUEST['rating_image_type'] : ImageType::Stars; // get items from manager $items = $manager->getItems($manager->getFieldNames(), $conditions, $order_by, $order_asc, $limit); $result = array('error' => false, 'error_message' => '', 'items' => array()); if (count($items) > 0) { foreach ($items as $item) { $timestamp = strtotime($item->timestamp); $date = date($this->getLanguageConstant('format_date_short'), $timestamp); $time = date($this->getLanguageConstant('format_time_short'), $timestamp); $rating_image_url = url_Make('get_rating_image', $this->name, array('type', $rating_image_type), array('id', $item->id)); $result['items'][] = array('id' => $item->id, 'text_id' => $item->text_id, 'timestamp' => $item->timestamp, 'date' => $date, 'time' => $time, 'title' => $all_languages ? $item->title : $item->title[$language], 'author' => $admin_manager->getItemValue('fullname', array('id' => $item->author)), 'visible' => $item->visible, 'views' => $item->views, 'votes_up' => $item->votes_up, 'votes_down' => $item->votes_down, 'rating' => $this->getArticleRating($item, 10), 'rating_image' => $rating_image_url); } } else { // no articles were found for specified cirteria $result['error'] = true; $result['error_message'] = $this->getLanguageConstant('message_json_articles_not_found'); } print json_encode($result); }
/** * Verify user account using code specified in either tag_params or _REQUEST. * * @param array $tag_params * @param array $children */ public function verifyAccount($tag_params, $children) { $manager = UserManager::getInstance(); $verification_manager = UserVerificationManager::getInstance(); $result = false; $username = null; $code = null; $verification = null; // get username if (isset($tag_params['username'])) { $username = fix_chars($tag_params['username']); } if (isset($_REQUEST['username']) && is_null($username)) { $username = fix_chars($_REQUEST['username']); } // get verification code if (isset($tag_params['code'])) { $code = fix_chars($tag_params['code']); } if (isset($_REQUEST['code']) && is_null($code)) { $code = fix_chars($_REQUEST['code']); } if (is_null($username) || is_null($code)) { return; } // get user from database $user = $manager->getSingleItem($manager->getFieldNames(), array('username' => $username)); if (is_object($user)) { $verification = $verification_manager->getSingleItem($verification_manager->getFieldNames(), array('user' => $user->id, 'code' => $code)); } // data matches, mark account as verified if (is_object($verification)) { $manager->updateData(array('verified' => 1), array('id' => $user->id)); $verification_manager->deleteData(array('user' => $user->id)); // automatically log user in $_SESSION['uid'] = $user->id; $_SESSION['logged'] = true; $_SESSION['level'] = $user->level; $_SESSION['username'] = $user->username; $_SESSION['fullname'] = $user->fullname; } }
/** * Handle request for JSON object */ public function json_GetItem() { $uid = isset($_REQUEST['uid']) ? fix_chars($_REQUEST['uid']) : null; $manager = ShopItemManager::getInstance(); // prepare result $result = array('error' => false, 'error_message' => '', 'item' => array()); if (!is_null($uid)) { // create conditions $conditions = array('uid' => $uid, 'deleted' => 0, 'visible' => 1); $item = $manager->getSingleItem($manager->getFieldNames(), $conditions); if (is_object($item)) { // get item image url $thumbnail_url = null; if (class_exists('gallery')) { $gallery = gallery::getInstance(); $thumbnail_url = $gallery->getGroupThumbnailURL($item->gallery); } $rating = 0; $result['item'] = array('id' => $item->id, 'uid' => $item->uid, 'name' => $item->name, 'description' => $item->description, 'gallery' => $item->gallery, 'views' => $item->views, 'price' => $item->price, 'tax' => $item->tax, 'weight' => $item->weight, 'votes_up' => $item->votes_up, 'votes_down' => $item->votes_down, 'rating' => $rating, 'priority' => $item->priority, 'timestamp' => $item->timestamp, 'thumbnail' => $thumbnail_url); } else { // there was a problem with reading item from database $result['error'] = true; $result['error_message'] = $this->_parent->getLanguageConstant('message_error_getting_item'); } } else { // invalid ID was specified $result['error'] = true; $result['error_message'] = $this->_parent->getLanguageConstant('message_error_invalid_id'); } // create JSON object and print it define('_OMIT_STATS', 1); print json_encode($result); }
/** * Complete checkout and charge money. */ public function completeCheckout() { global $language; $shop = shop::getInstance(); $return_url = fix_chars($_REQUEST['return_url']); $recurring = isset($_REQUEST['type']) && $_REQUEST['type'] == 'recurring'; $transaction_uid = $_SESSION['transaction']['uid']; // get billing information $billing = array(); $fields = array('billing_full_name', 'billing_card_type', 'billing_credit_card', 'billing_expire_month', 'billing_expire_year', 'billing_cvv'); foreach ($fields as $field) { if (isset($_REQUEST[$field])) { $billing[$field] = fix_chars($_REQUEST[$field]); } } // create recurring profile if ($recurring) { $request_id = 0; $plan_name = $_SESSION['recurring_plan']; $manager = PayPal_PlansManager::getInstance(); $plan = $manager->getSingleItem($manager->getFieldNames(), array('text_id' => $plan_name)); $current_plan = $shop->getRecurringPlan(); // cancel existing recurring payment if exists if (!is_null($current_plan)) { $plans = $this->get_recurring_plans(); $current_group = null; // get plan data if (isset($plans[$current_plan->plan_name])) { $current_group = $plans[$current_plan->plan_name]['group']; } // cancel current plan if (!is_null($current_group) && $current_group == $plan->group_name) { $shop->cancelTransaction($current_plan->transaction); } } // generate params for description $plan_params = array('price' => $plan->price, 'period' => $plan->interval_count, 'unit' => $plan->interval, 'setup' => $plan->setup_price, 'trial_period' => $plan->trial_count, 'trial_unit' => $plan->trial); // charge one time setup fee // TODO: Charge one time setup fee. // create recurring payments profile $recurring_fields = $fields; // set buyer information $name = explode(' ', $billing['billing_full_name']); $recurring_fields['CREDITCARDTYPE'] = $this->card_type[$billing['billing_card_type']]; $recurring_fields['ACCT'] = $billing['billing_credit_card']; $recurring_fields['EXPDATE'] = $billing['billing_expire_month'] . $billing['billing_expire_year']; $recurring_fields['FIRSTNAME'] = $name[0]; $recurring_fields['LASTNAME'] = $name[1]; // set starting date of the profile $start_timestamp = strtotime($plan->start_time); if ($start_timestamp < time()) { $start_timestamp = time(); } $recurring_fields['PROFILESTARTDATE'] = strftime('%Y-%m-%dT%T%z', $start_timestamp); // set description $recurring_fields['DESC'] = $shop->formatRecurring($plan_params); // set currency $recurring_fields['AMT'] = $plan->price; $recurring_fields['CURRENCYCODE'] = $shop->getDefaultCurrency(); // billing period $recurring_fields['BILLINGPERIOD'] = $this->units[$plan->interval]; $recurring_fields['BILLINGFREQUENCY'] = $plan->interval_count; // trial period if ($plan->trial_count > 0) { $recurring_fields['TRIALBILLINGPERIOD'] = $this->units[$plan->trial]; $recurring_fields['TRIALBILLINGFREQUENCY'] = $plan->trial_count; $recurring_fields['TRIALTOTALBILLINGCYCLES'] = 1; } // make api call $response = PayPal_Helper::callAPI(PayPal_Helper::METHOD_CreateRecurringPaymentsProfile, $recurring_fields); if ($response['ACK'] == 'Success' || $response['ACK'] == 'SuccessWithWarning') { // update transaction token $shop->setTransactionToken($transaction_uid, fix_chars($response['PROFILEID'])); // update transaction status if ($response['PROFILESTATUS'] == 'ActiveProfile') { $shop->setTransactionStatus($transaction_uid, TransactionStatus::COMPLETED); } } else { // report error $error_code = urldecode($response['L_ERRORCODE0']); $error_long = urldecode($response['L_LONGMESSAGE0']); trigger_error("PayPal_Express: ({$error_code}) - {$error_long}", E_USER_ERROR); } // redirect user header('Location: ' . $return_url, true, 302); } }
/** * Charge specified amount with specified token and transaction. */ public function chargeToken() { $transaction_uid = fix_chars($_REQUEST['transaction_uid']); $stripe_token = fix_chars($_REQUEST['stripe_token']); $manager = ShopTransactionsManager::getInstance(); $currency_manager = ShopCurrenciesManager::getInstance(); $transaction = null; // make sure we are working on same transaction for current user if (isset($_SESSION['transaction']) && $_SESSION['transaction']['uid'] == $transaction_uid) { $transaction = $manager->getSingleItem($manager->getFieldNames(), array('uid' => $transaction_uid)); } if (is_object($transaction)) { $currency = $currency_manager->getSingleItem(array('currency'), array('id' => $transaction->currency)); try { // create charge Stripe::setApiKey($this->getPrivateKey()); $charge = Stripe_Charge::create(array('amount' => $transaction->total * 100, 'currency' => $currency->currency, 'card' => $stripe_token, 'description' => null)); } catch (Stripe_CardError $error) { } // update transaction status if (is_object($charge) && $charge->paid) { $shop = shop::getInstance(); $shop->setTransactionToken($transaction_uid, $charge->id); $shop->setTransactionStatus($transaction_uid, TransactionStatus::COMPLETED); } } }
/** * 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(); } } }
/** * Save new price for delivery method */ private function savePrice() { $id = isset($_REQUEST['id']) ? fix_id($_REQUEST['id']) : null; $manager = ShopDeliveryMethodPricesManager::getInstance(); $data = array('value' => fix_chars($_REQUEST['value'])); // method is optional when editing if (isset($_REQUEST['method'])) { $data['method'] = fix_id($_REQUEST['method']); } if (is_null($id)) { $manager->insertData($data); $window = 'shop_delivery_price_add'; } else { $manager->updateData($data, array('id' => $id)); $window = 'shop_delivery_price_change'; } // show message $template = new TemplateHandler('message.xml', $this->path . 'templates/'); $template->setMappedModule($this->name); $params = array('message' => $this->_parent->getLanguageConstant('message_delivery_price_saved'), 'button' => $this->_parent->getLanguageConstant('close'), 'action' => window_Close($window) . ";" . window_ReloadContent('shop_delivery_method_prices')); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); }
/** * Submit form reactor data to the server. */ private function json_FormReactor() { $result = false; $reactor_id = fix_chars($_REQUEST['reactor_id']); $visitor_sid = fix_chars($_REQUEST['visitor_sid']); $account_key = $this->settings['account_key']; $account_secret = $this->settings['account_secret']; // exit if we are missing data if (empty($account_key) || empty($account_secret)) { trigger_error('Account key and/or secret are not properly configured!', E_USER_ERROR); print json_encode($result); return; } // prepare content $params = array('phone_number', 'country_code', 'caller_name'); $data = array(); $strip_slashes = get_magic_quotes_gpc(); foreach ($params as $param) { $value = $_REQUEST[$param]; if ($strip_slashes) { $value = stripslashes($value); } $data[] = $param . '=' . urlencode($value); } // add visitor session id $data['visitor_sid'] = $visitor_sid; // make query string $content = implode('&', $data); // prepare headers $api_path = str_replace('{reactor_id}', $reactor_id, callbox::URL_FORM_REACTOR); $header = "POST " . $api_path . " HTTP/1.0\n"; $header .= "Content-Type: application/x-www-form-urlencoded\n"; $header .= "Content-Length: " . strlen($content) . "\n"; $header .= "Authorization: Basic " . base64_encode($account_key . ':' . $account_secret) . "\n"; $header .= "Connection: close\n\n"; // connect to server and send data $socket = fsockopen(callbox::URL_API, 443, $error_number, $error_string, 30); if ($socket) { fputs($socket, $header . $content); $response = fgets($socket); $result = strpos($response, '200 OK') != false; } fclose($socket); print json_encode($result); }
/** * Print a list of United States using specified template * * @param array $tag_params * @param array $children */ private function printStateList($tag_params, $children) { $manager = CountryStateManager::getInstance(); $conditions = array(); // get tag params $selected = isset($tag_params['selected']) ? fix_chars($tag_params['selected']) : null; if (isset($tag_params['country'])) { // country is defined as a part of XML tag $conditions['country'] = fix_chars($tag_params['country']); } else { if (isset($_REQUEST['country'])) { // country is defined in query $conditions['country'] = fix_chars($_REQUEST['country']); } } $template = $this->loadTemplate($tag_params, 'state_option.xml'); $state_list = $manager->getItems($manager->getFieldNames(), $conditions); foreach ($state_list as $state) { $params = array('selected' => $selected, 'name' => $state->name, 'short' => $state->short); $template->restoreXML(); $template->setLocalParams($params); $template->parse(); } }