Exemplo n.º 1
0
 /**
  * Creates a Javascript based dynamic state list, depending of the selected
  * country of a country drop-down list (specified by $country_list_name)
  *
  * @param string $country_list_name The name of the country select list element
  * @param string $state_list_name The name for this states drop-down list
  * @param string $selected_country_code The 3-digit country code that is pre-selected
  * @param string $selected_state_code The state code of a pre-selected state
  * @return string HTML code containing the dynamic state list
  */
 function dynamic_state_lists($country_list_name, $state_list_name, $selected_country_code = "", $selected_state_code = "")
 {
     global $vendor_country_3_code, $VM_LANG, $vm_mainframe, $mm_action_url, $page;
     $db = new ps_DB();
     if (empty($selected_country_code)) {
         $selected_country_code = $vendor_country_3_code;
     }
     if (empty($selected_state_code)) {
         $selected_state_code = "originalPos";
     } else {
         $selected_state_code = "'" . $selected_state_code . "'";
     }
     $db->query("SELECT c.country_id, c.country_3_code, s.state_name, s.state_2_code\n\t\t\t\t\t\tFROM #__{vm}_country c\n\t\t\t\t\t\tLEFT JOIN #__{vm}_state s \n\t\t\t\t\t\tON c.country_id=s.country_id OR s.country_id IS NULL\n\t\t\t\t\t\tORDER BY c.country_id, s.state_name");
     if ($db->num_rows() > 0) {
         if (!vmIsAdminMode()) {
             $vm_mainframe->addScript($mm_action_url . 'includes/js/mambojavascript.js');
             $vm_mainframe->addScript($mm_action_url . 'includes/js/joomla.javascript.js');
         }
         // Build the State lists for each Country
         $script = "<script language=\"javascript\" type=\"text/javascript\">//<![CDATA[\n";
         $script .= "<!--\n";
         $script .= "var originalOrder = '1';\n";
         $script .= "var originalPos = '{$selected_country_code}';\n";
         $script .= "var states = new Array();\t// array in the format [key,value,text]\n";
         $i = 0;
         $prev_country = '';
         while ($db->next_record()) {
             $country_3_code = $db->f("country_3_code");
             if ($db->f('state_name')) {
                 // Add 'none' to the list of countries that have states:
                 if ($prev_country != $country_3_code && $page == 'tax.tax_form') {
                     $script .= "states[" . $i++ . "] = new Array( '" . $country_3_code . "',' - ','" . $VM_LANG->_('PHPSHOP_NONE') . "' );\n";
                 } elseif ($prev_country != $country_3_code) {
                     $script .= "states[" . $i++ . "] = new Array( '" . $country_3_code . "','',' -= " . $VM_LANG->_('PHPSHOP_SELECT') . " =-' );\n";
                 }
                 $prev_country = $country_3_code;
                 // array in the format [key,value,text]
                 $script .= "states[" . $i++ . "] = new Array( '" . $country_3_code . "','" . $db->f("state_2_code") . "','" . addslashes($db->f("state_name")) . "' );\n";
             } else {
                 $script .= "states[" . $i++ . "] = new Array( '" . $country_3_code . "',' - ','" . $VM_LANG->_('PHPSHOP_NONE') . "' );\n";
             }
         }
         $script .= "\n\t\t\tfunction changeStateList() { \n\t\t\t  var selected_country = null;\n\t\t\t  for (var i=0; i<document.adminForm." . $country_list_name . ".length; i++)\n\t\t\t\t if (document.adminForm." . $country_list_name . "[i].selected)\n\t\t\t\t\tselected_country = document.adminForm." . $country_list_name . "[i].value;\n\t\t\t  changeDynaList('" . $state_list_name . "',states,selected_country, originalPos, originalOrder);\n\t\t\t  \n\t\t\t}\n\t\t\twriteDynaList( 'class=\"inputbox\" name=\"" . $state_list_name . "\" size=\"1\" id=\"state\"', states, originalPos, originalPos, {$selected_state_code} );\n\t\t\t//-->\n\t\t\t//]]></script>";
         return $script;
     }
 }
Exemplo n.º 2
0
     } else {
         $page = $_SESSION['last_page'];
     }
 }
 $my_page = explode('.', $page);
 $modulename = $my_page[0];
 $pagename = $my_page[1];
 // For there's no errorpage to display the error,
 // we must echo it before the page is loaded
 if (!empty($error) && $page != ERRORPAGE) {
     echo '<span class="shop_error">' . $error . '</span>';
 }
 /*****************************
  ** FRONTEND ADMIN - MOD
  **/
 if (vmIsAdminMode() && $perm->check("admin,storeadmin") && (!stristr($my->usertype, "admin") ^ PSHOP_ALLOW_FRONTENDADMIN_FOR_NOBACKENDERS == '' || stristr($my->usertype, "admin")) && !stristr($page, "shop.")) {
     define('_FRONTEND_ADMIN_LOADED', '1');
     if (vmIsJoomla(1.5)) {
         $editor =& JFactory::getEditor();
         echo $editor->initialise();
     } else {
         $mainframe->loadEditor = 1;
         require_once $mosConfig_absolute_path . "/editor/editor.php";
         initEditor();
     }
     $editor1_array = array('product.product_form' => 'product_desc', 'product.product_category_form' => 'category_description', 'store.store_form' => 'vendor_store_desc', 'vendor.vendor_form' => 'vendor_store_desc');
     $editor2_array = array('store.store_form' => 'vendor_terms_of_service', 'vendor.vendor_form' => 'vendor_terms_of_service');
     editorScript(isset($editor1_array[$page]) ? $editor1_array[$page] : '', isset($editor2_array[$page]) ? $editor2_array[$page] : '');
     $vm_mainframe->addStyleSheet(VM_THEMEURL . 'admin.css');
     $vm_mainframe->addStyleSheet(VM_THEMEURL . 'admin.styles.css');
     $vm_mainframe->addScript("{$mosConfig_live_site}/components/{$option}/js/functions.js");
Exemplo n.º 3
0
 /**
  * Shows the Number of Products in category $category_id
  *
  * @param int $category_id
  * @return string The number in brackets
  */
 function products_in_category($category_id)
 {
     if (PSHOP_SHOW_PRODUCTS_IN_CATEGORY == '1' || vmIsAdminMode()) {
         $num = ps_product_category::product_count($category_id);
         if (empty($num) && ps_product_category::has_childs($category_id)) {
             $db = new ps_DB();
             $q = "SELECT category_child_id FROM #__{vm}_category_xref ";
             $q .= "WHERE category_parent_id='{$category_id}' ";
             $db->query($q);
             while ($db->next_record()) {
                 $num += ps_product_category::product_count($db->f("category_child_id"));
             }
         }
         return " ({$num}) ";
     } else {
         return "";
     }
 }
Exemplo n.º 4
0
  ************************************************/
 if (empty($page)) {
     // default page
     if (defined('_VM_IS_BACKEND')) {
         $page = "store.index";
     } else {
         $page = HOMEPAGE;
     }
 }
 // Let's check if the user is allowed to view the page
 // if not, $page is set to ERROR_PAGE
 $pagePermissionsOK = $ps_module->checkModulePermissions($page);
 $ok = true;
 if (!empty($funcParams["method"]) && vmGet($_REQUEST, 'task') != 'cancel') {
     // Protection against Cross-Site Request Forgery
     if (vmIsAdminMode() && !vmSpoofCheck(null, $sess->getSessionId())) {
         return;
     }
     // Get the function parameters: function name and class name
     $q = "SELECT #__{vm}_module.module_name,#__{vm}_function.function_class";
     $q .= " FROM #__{vm}_module,#__{vm}_function WHERE ";
     $q .= "#__{vm}_module.module_id=#__{vm}_function.module_id AND ";
     $q .= "#__{vm}_function.function_method='" . $funcParams["method"] . "' AND ";
     $q .= "#__{vm}_function.function_class='" . $funcParams["class"] . "'";
     $db->query($q);
     $db->next_record();
     $class = $db->f('function_class');
     if (file_exists(CLASSPATH . "{$class}.php")) {
         if ($ajax_request) {
             require_once CLASSPATH . 'connectionTools.class.php';
             vmConnector::sendHeaderAndContent(200);
Exemplo n.º 5
0
    /**
     * This allows us to print the user fields on
     * the various sections of the shop
     *
     * @param array $rowFields An array returned from ps_database::loadObjectlist
     * @param array $skipFields A one-dimensional array holding the names of fields that should NOT be displayed
     * @param ps_DB $db A ps_DB object holding ovalues for the fields
     * @param boolean $startform If true, print the starting <form...> tag
     */
    function listUserFields($rowFields, $skipFields = array(), $db = null, $startForm = true)
    {
        global $mm_action_url, $ps_html, $VM_LANG, $my, $default, $mainframe, $vm_mainframe, $vendor_country_3_code, $mosConfig_live_site, $mosConfig_absolute_path, $page;
        $dbf = new ps_DB();
        if ($db === null) {
            $db = new ps_DB();
        }
        $default['country'] = $vendor_country_3_code;
        $missing = vmGet($_REQUEST, 'missing', '');
        // collect all required fields
        $required_fields = array();
        foreach ($rowFields as $field) {
            if ($field->required == 1) {
                $required_fields[$field->name] = $field->type;
            }
            $allfields[$field->name] = $field->name;
        }
        foreach ($skipFields as $skip) {
            unset($required_fields[$skip]);
        }
        // Form validation function
        if (!vmIsAdminMode()) {
            ps_userfield::printJS_formvalidation($required_fields, $rowFields);
        } else {
            echo vmCommonHTML::scriptTag('', 'function submitregistration() { return true }');
        }
        if (file_exists($mosConfig_absolute_path . '/includes/js/mambojavascript.js')) {
            $vm_mainframe->addScript('includes/js/mambojavascript.js');
        }
        if ($startForm) {
            echo '<form action="' . $mm_action_url . basename($_SERVER['PHP_SELF']) . '" method="post" name="adminForm">';
        }
        echo '
		<div style="width:90%;">';
        if (!empty($required_fields)) {
            echo '<div style="padding:5px;text-align:center;"><strong>(* = ' . $VM_LANG->_('CMN_REQUIRED') . ')</strong></div>';
        }
        $delimiter = 0;
        foreach ($rowFields as $field) {
            if (!isset($default[$field->name])) {
                $default[$field->name] = $field->default;
            }
            $readonly = $field->readonly ? ' readonly="readonly"' : '';
            if (in_array($field->name, $skipFields)) {
                continue;
            }
            // Title handling.
            $key = $field->title;
            if ($key[0] == '_') {
                $key = substr($key, 1, strlen($key) - 1);
            }
            if ($VM_LANG->exists($key)) {
                $field->title = $VM_LANG->_($key);
            }
            if ($field->name == 'agreed') {
                $field->title = '<script type="text/javascript">//<![CDATA[
				document.write(\'<label for="agreed_field">' . str_replace("'", "\\'", $VM_LANG->_('PHPSHOP_I_AGREE_TO_TOS')) . '</label><a href="javascript:void window.open(\\\'' . $mosConfig_live_site . '/index2.php?option=com_virtuemart&page=shop.tos&pop=1\\\', \\\'win2\\\', \\\'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no\\\');">\');
				document.write(\' (' . $VM_LANG->_('PHPSHOP_STORE_FORM_TOS') . ')</a>\');
				//]]></script>
				<noscript>
					<label for="agreed_field">' . $VM_LANG->_('PHPSHOP_I_AGREE_TO_TOS') . '</label>
					<a target="_blank" href="' . $mosConfig_live_site . '/index.php?option=com_virtuemart&amp;page=shop.tos" title="' . $VM_LANG->_('PHPSHOP_I_AGREE_TO_TOS') . '">
					 (' . $VM_LANG->_('PHPSHOP_STORE_FORM_TOS') . ')
					</a></noscript>';
            }
            if ($field->name == 'username' && VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') {
                echo '<div class="formLabel">
						<input type="checkbox" id="register_account" name="register_account" value="1" class="inputbox" onchange="showFields( this.checked, new Array(\'username\', \'password\', \'password2\') );if( this.checked ) { document.adminForm.remember.value=\'yes\'; } else { document.adminForm.remember.value=\'yes\'; }" checked="checked" />
					</div>
					<div class="formField">
						<label for="register_account">' . $VM_LANG->_('VM_REGISTER_ACCOUNT') . '</label>
					</div>
					';
            } elseif ($field->name == 'username') {
                echo '<input type="hidden" id="register_account" name="register_account" value="1" />';
            }
            // a delimiter marks the beginning of a new fieldset and
            // the end of a previous fieldset
            if ($field->type == 'delimiter') {
                if ($delimiter > 0) {
                    echo "</fieldset>\n";
                }
                if (VM_REGISTRATION_TYPE == 'SILENT_REGISTRATION' && $field->title == $VM_LANG->_('PHPSHOP_ORDER_PRINT_CUST_INFO_LBL') && $page == 'checkout.index') {
                    continue;
                }
                echo '<fieldset>
				     <legend class="sectiontableheader">' . $field->title . '</legend>
';
                $delimiter++;
                continue;
            }
            echo '<div id="' . $field->name . '_div" class="formLabel ';
            if (stristr($missing, $field->name)) {
                echo 'missing';
            }
            echo '">';
            echo '<label for="' . $field->name . '_field">' . $field->title . '</label>';
            if (isset($required_fields[$field->name])) {
                echo '<strong>* </strong>';
            }
            echo ' </div>
	      <div class="formField" id="' . $field->name . '_input">' . "\n";
            /**
             * This is the most important part of this file
             * Here we print the field & its contents!
             */
            switch ($field->name) {
                case 'title':
                    $ps_html->list_user_title($db->sf('title'), "id=\"title_field\"");
                    break;
                case 'country':
                    if (in_array('state', $allfields)) {
                        $onchange = "onchange=\"changeStateList();\"";
                    } else {
                        $onchange = "";
                    }
                    $ps_html->list_country("country", $db->sf('country'), "id=\"country_field\" {$onchange}");
                    break;
                case 'state':
                    echo $ps_html->dynamic_state_lists("country", "state", $db->sf('country'), $db->sf('state'));
                    echo "<noscript>\n";
                    $ps_html->list_states("state", $db->sf('state'), "", "id=\"state_field\"");
                    echo "</noscript>\n";
                    break;
                case 'agreed':
                    echo '<input type="checkbox" id="agreed_field" name="agreed" value="1" class="inputbox" />';
                    break;
                case 'password':
                case 'password2':
                    echo '<input type="password" id="' . $field->name . '_field" name="' . $field->name . '" size="30" class="inputbox" />' . "\n";
                    break;
                default:
                    switch ($field->type) {
                        case 'date':
                            echo vmCommonHTML::scriptTag($mosConfig_live_site . '/includes/js/calendar/calendar.js');
                            if (vmIsJoomla('1.5', '>=')) {
                                // in Joomla 1.5, the name of calendar lang file is changed...
                                echo vmCommonHTML::scriptTag($mosConfig_live_site . '/includes/js/calendar/lang/calendar-en-GB.js');
                            } else {
                                echo vmCommonHTML::scriptTag($mosConfig_live_site . '/includes/js/calendar/lang/calendar-en.js');
                            }
                            echo vmCommonHTML::linkTag($mosConfig_live_site . '/includes/js/calendar/calendar-mos.css');
                            $maxlength = $field->maxlength ? 'maxlength="' . $field->maxlength . '"' : '';
                            echo '<input type="text" id="' . $field->name . '_field" name="' . $field->name . '" size="' . $field->size . '" value="' . ($db->sf($field->name) ? $db->sf($field->name) : '') . '" class="inputbox" ' . $maxlength . $readonly . ' />' . "\n";
                            echo '<input name="reset" type="reset" class="button" onclick="return showCalendar(\'' . $field->name . '_field\', \'y-mm-dd\');" value="..." />';
                            break;
                        case 'text':
                        case 'emailaddress':
                        case 'webaddress':
                        case 'euvatid':
                            $maxlength = $field->maxlength ? 'maxlength="' . $field->maxlength . '"' : '';
                            echo '<input type="text" id="' . $field->name . '_field" name="' . $field->name . '" size="' . $field->size . '" value="' . ($db->sf($field->name) ? $db->sf($field->name) : '') . '" class="inputbox" ' . $maxlength . $readonly . ' />' . "\n";
                            break;
                        case 'textarea':
                            echo '<textarea name="' . $field->name . '" id="' . $field->name . '_field" cols="' . $field->cols . '" rows="' . $field->rows . '" ' . $readonly . '>' . $db->sf($field->name) . '</textarea>';
                            break;
                        case 'editorta':
                            editorArea($field->name, $db->sf($field->name), $field->name, '300', '150', $field->cols, $field->rows);
                            break;
                        case 'checkbox':
                            echo '<input type="checkbox" name="' . $field->name . '" id="' . $field->name . '_field" value="1" ' . ($db->sf($field->name) ? 'checked="checked"' : '') . '/>';
                            break;
                        case 'age_verification':
                            $year = vmRequest::getInt('birthday_selector_year', date('Y'));
                            if ($db->f($field->name)) {
                                $birthday = $db->f($field->name);
                                $date_array = explode('-', $birthday);
                                $year = $date_array[0];
                                $month = $date_array[1];
                                $day = $date_array[2];
                            }
                            ps_html::list_days('birthday_selector_day', vmRequest::getInt('birthday_selector_day', @$day));
                            ps_html::list_month('birthday_selector_month', vmRequest::getInt('birthday_selector_month', @$month));
                            ps_html::list_year('birthday_selector_year', $year, $year - 100, $year);
                            break;
                        case 'captcha':
                            if (file_exists($mosConfig_absolute_path . '/administrator/components/com_securityimages/client.php')) {
                                include $mosConfig_absolute_path . '/administrator/components/com_securityimages/client.php';
                                // Note that this package name must be used on the validation side too! If both are not equal, validation will fail
                                $packageName = 'securityVMRegistrationCheck';
                                echo insertSecurityImage($packageName);
                                echo getSecurityImageText($packageName);
                            } else {
                                if (file_exists($mosConfig_absolute_path . '/plugins/system/securityimages.php')) {
                                    echo "<script type=\"text/javascript\" src=\"" . JURI::root() . "/components/com_securityimages/js/securityImages.js\"></script>";
                                    echo "<img id='captchaSecurityImages' name='captchaSecurityImages' src=\"" . JURI::root() . "/index.php?option=com_securityimages&task=displayCaptcha\" />";
                                    echo "<a href=\"javascript:askNewSecurityImages('captchaSecurityImages');\">";
                                    echo "<img src=\"" . JURI::root() . "/components/com_securityimages/buttons/reload.gif\" id=\"securityImagesContactCaptchaReload\" name=\"securityImagesContactCaptchaReload\" border=\"0\">";
                                    echo "</a>";
                                    echo "<input type=\"text\" name=\"securityVMRegistrationCheck_try\" />";
                                }
                            }
                            break;
                            // Begin of a fallthrough
                        // Begin of a fallthrough
                        case 'multicheckbox':
                        case 'select':
                        case 'multiselect':
                        case 'radio':
                            $k = $db->f($field->name);
                            $dbf->setQuery("SELECT fieldtitle,fieldvalue FROM #__{vm}_userfield_values" . "\n WHERE fieldid = " . $field->fieldid . "\n ORDER BY ordering");
                            $Values = $dbf->loadObjectList();
                            $multi = "";
                            $rowFieldValues['lst_' . $field->name] = '';
                            if ($field->type == 'multiselect') {
                                $multi = "multiple='multiple'";
                            }
                            if (count($Values) > 0) {
                                if ($field->type == 'radio') {
                                    $rowFieldValues['lst_' . $field->name] = vmCommonHTML::radioListTable($Values, $field->name, 'class="inputbox" size="1" ', 'fieldvalue', 'fieldtitle', $k, $field->cols, $field->rows, $field->size, $field->required);
                                } else {
                                    $ks = explode("|*|", $k);
                                    $k = array();
                                    foreach ($ks as $kv) {
                                        $k[]->fieldvalue = $kv;
                                    }
                                    if ($field->type == 'multicheckbox') {
                                        $rowFieldValues['lst_' . $field->name] = vmCommonHTML::checkboxListTable($Values, $field->name . "[]", 'class="inputbox" size="' . $field->size . '" ' . $multi, 'fieldvalue', 'fieldtitle', $k, $field->cols, $field->rows, $field->size, $field->required);
                                    } else {
                                        $rowFieldValues['lst_' . $field->name] = vmCommonHTML::selectList($Values, $field->name . "[]", 'class="inputbox" size="' . $field->size . '" ' . $multi, 'fieldvalue', 'fieldtitle', $k);
                                    }
                                }
                            }
                            // no break! still a fallthrough
                            echo $rowFieldValues['lst_' . $field->name];
                            break;
                    }
                    break;
            }
            if ($field->description != '') {
                echo vmToolTip($field->description);
            }
            echo '<br /></div>
				      <br style="clear:both;" />';
        }
        if ($delimiter > 0) {
            echo "</fieldset>\n";
        }
        echo '</div>';
        if (VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION') {
            echo '<script type="text/javascript">
		   function showFields( show, fields ) {
		   	if( fields ) {
		   		for (i=0; i<fields.length;i++) {
		   			if( show ) {
		   				document.getElementById( fields[i] + \'_div\' ).style.display = \'\';
		   				document.getElementById( fields[i] + \'_input\' ).style.display = \'\';
		   			} else {
		   				document.getElementById( fields[i] + \'_div\' ).style.display = \'none\';
		   				document.getElementById( fields[i] + \'_input\' ).style.display = \'none\';
		   			}
		   		}
		   	}
		   }
		   try {
		   	showFields( document.getElementById( \'register_account\').checked, new Array(\'username\', \'password\', \'password2\') );
		   } catch(e){}
		   </script>';
        }
    }
Exemplo n.º 6
0
 /**
  * This reformats an URL, appends "option=com_virtuemart" and "Itemid=XX"
  * where XX is the Id of an entry in the table mos_menu with "link: option=com_virtuemart"
  * It also calls sefRelToAbs to apply SEF formatting
  * 
  * @param string $text THE URL
  * @param boolean False: Create a URI like /joomla/index.php?....; True: Create a URI like http://www.domain.com/index.php?....
  * @return string The reformatted URL
  */
 function url($text, $createAbsoluteURI = false, $encodeAmpersands = true, $ignoreSEF = false)
 {
     global $mm_action_url, $page, $mainframe;
     if (!defined('_VM_IS_BACKEND')) {
         $Itemid = "&Itemid=" . $this->getShopItemid();
     } else {
         $Itemid = '';
     }
     switch ($text) {
         case SECUREURL:
             $text = SECUREURL . basename($_SERVER['SCRIPT_NAME']) . "?" . $this->component_name . $Itemid;
             break;
         case URL:
             $text = URL . basename($_SERVER['SCRIPT_NAME']) . "?" . $this->component_name . $Itemid;
             break;
         default:
             $limiter = strpos($text, '?');
             if (!stristr($text, $_SERVER['SCRIPT_NAME']) && $limiter === false) {
                 $text = '?' . $text;
             }
             $appendix = "";
             // now append "&option=com_virtuemart&Itemid=XX"
             if (!strstr($text, "option=")) {
                 $appendix .= "&" . $this->component_name;
             }
             $appendix .= $Itemid;
             $script = basename(substr($text, 0, $limiter));
             if ($script == '') {
                 $script = basename($_SERVER['SCRIPT_NAME']);
             }
             if (!defined('_VM_IS_BACKEND')) {
                 if ($script == 'index3.php') {
                     $script = 'index2.php';
                     // index3.php is not available in the frontend!
                 }
                 $appendix = $script . substr($text, $limiter, strlen($text)) . $appendix;
                 if (class_exists('JRoute') && !$ignoreSEF && $mainframe->getCfg('sef')) {
                     $appendix = JRoute::_(str_replace($script . '&', $script . '?', $appendix));
                 } else {
                     if (function_exists('sefRelToAbs') && !$ignoreSEF && !defined('_JLEGACY')) {
                         $appendix = sefRelToAbs(str_replace($script . '&', $script . '?', $appendix));
                     }
                 }
                 if ($createAbsoluteURI && substr($appendix, 0, 4) != 'http' && ($ignoreSEF || !$mainframe->getCfg('sef'))) {
                     $appendix = URL . $appendix;
                 }
             } elseif ($_SERVER['SERVER_PORT'] == 443) {
                 //$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
                 $appendix = SECUREURL . "administrator/{$script}" . substr($text, $limiter, strlen($text) - 1) . $appendix;
             } else {
                 //$script = strstr($_SERVER['PHP_SELF'], 'index2.php') ? 'index2.php' : 'index3.php';
                 $appendix = URL . "administrator/{$script}" . substr($text, $limiter, strlen($text) - 1) . $appendix;
             }
             if (vmIsAdminMode() && strstr($text, 'func') !== false) {
                 $appendix .= '&vmtoken=' . vmSpoofValue($this->getSessionId());
             }
             if (stristr($text, SECUREURL)) {
                 $appendix = str_replace(URL, SECUREURL, $appendix);
             } elseif (stristr($text, URL) && $createAbsoluteURI) {
                 $appendix = str_replace(SECUREURL, URL, $appendix);
             }
             $text = $appendix;
             break;
     }
     if ($encodeAmpersands) {
         $text = vmAmpReplace($text);
     } else {
         $text = str_replace('&amp;', '&', $text);
     }
     return $text;
 }
Exemplo n.º 7
0
 /**
  * This reformats an URL, appends "option=com_virtuemart" and "Itemid=XX"
  * where XX is the Id of an entry in the table mos_menu with "link: option=com_virtuemart"
  * It also calls sefRelToAbs to apply SEF formatting
  * 
  * @param string $text THE URL
  * @param boolean False: Create a URI like /joomla/index.php?....; True: Create a URI like http://www.domain.com/index.php?....
  * @return string The reformatted URL
  */
 function url($text, $createAbsoluteURI = false, $encodeAmpersands = true, $ignoreSEF = false)
 {
     global $mm_action_url, $page, $mainframe;
     if (!defined('_VM_IS_BACKEND')) {
         // Strip the parameters from the $text variable and parse to a temporary array
         $tmp_text = str_replace('amp;', '', substr($text, strpos($text, '?')));
         if (substr($tmp_text, 0, 1) == '?') {
             $tmp_text = substr($tmp_text, 1);
         }
         parse_str($tmp_text, $ii_arr);
         // Init the temp. Itemid
         $tmp_Itemid = '';
         $db = new ps_DB();
         // Check if there is a menuitem for a product_id (highest priority)
         if (!empty($ii_arr['product_id'])) {
             if ($ii_product_id = intval($ii_arr['product_id'])) {
                 $db->query("SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%product_id={$ii_product_id}%' AND published=1");
                 if ($db->next_record()) {
                     $tmp_Itemid = $db->f("id");
                 }
             }
         }
         // Check if there is a menuitem for a category_id
         // This only checks for the exact category ID, it might be good to check for parents also. But at the moment, this would produce a lot of queries
         if (!empty($ii_arr['category_id'])) {
             $ii_cat_id = intval($ii_arr['category_id']);
             if ($ii_cat_id && $tmp_Itemid == '') {
                 $db->query("SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%category_id={$ii_cat_id}%' AND published=1");
                 if ($db->next_record()) {
                     $tmp_Itemid = $db->f("id");
                 }
             }
         }
         // Check if there is a menuitem for a flypage
         if (!empty($ii_arr['flypage'])) {
             $ii_flypage = $db->getEscaped(vmget($ii_arr, 'flypage'));
             if ($ii_flypage && $tmp_Itemid == '') {
                 $db->query("SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%flypage={$ii_flypage}%' AND published=1");
                 if ($db->next_record()) {
                     $tmp_Itemid = $db->f("id");
                 }
             }
         }
         // Check if there is a menuitem for a page
         if (!empty($ii_arr['page'])) {
             $ii_page = $db->getEscaped(vmget($ii_arr, 'page'));
             if ($ii_page && $tmp_Itemid == '') {
                 $db->query("SELECT id FROM #__menu WHERE link='index.php?option=com_virtuemart' AND params like '%page={$ii_page}%' AND published=1");
                 if ($db->next_record()) {
                     $tmp_Itemid = $db->f("id");
                 }
             }
         }
         // If we haven't found an Itemid, use the standard VM-Itemid
         $Itemid = "&Itemid=" . ($tmp_Itemid ? $tmp_Itemid : $this->getShopItemid());
     } else {
         $Itemid = NULL;
     }
     // split url into base ? path
     $limiter = strpos($text, '?');
     if ($limiter === false) {
         if (!strstr($text, "=")) {
             // $text recognized to be parameter-list (bug?)
             $base = NULL;
             $params = $text;
         } else {
             // text recognized to be url without parameters
             $base = $mm_action_url;
             $params = $text;
         }
     } else {
         // base?params
         $base = substr($text, 0, $limiter);
         $params = substr($text, $limiter + 1);
     }
     // normalize base (cut off multislashes)
     $base = str_replace("//", "/", $base);
     $base = str_replace(":/", "://", $base);
     // add script name to naked base url
     // TODO: Improve
     if ($base == URL || $base == SECUREURL) {
         $base .= basename($_SERVER['SCRIPT_NAME']);
     }
     if (!basename($base)) {
         $base .= basename($_SERVER['SCRIPT_NAME']);
     }
     // append "&option=com_virtuemart&Itemid=XX"
     $params .= !strstr($params, $this->component_name) ? ($params ? "&" : NULL) . $this->component_name : NULL;
     $params .= $Itemid;
     if (vmIsAdminMode() && strstr($text, 'func') !== false) {
         $params .= ($params ? "&" : NULL) . 'vmtoken=' . vmSpoofValue($this->getSessionId());
     }
     if (!defined('_VM_IS_BACKEND')) {
         // index3.php is not available in the frontend!
         $base = str_replace("index3.php", "index2.php", $base);
         $url = basename($base) . "?" . $params;
         // make url absolute
         if ($createAbsoluteURI && !substr($url, 0, 4) != "http") {
             $url = (stristr($text, SECUREURL) ? SECUREURL : URL) . substr($url, $url[0] == '/' ? 1 : 0);
         }
         if (class_exists('JRoute') && !$ignoreSEF && $mainframe->getCfg('sef')) {
             $url = JRoute::_($url);
         } else {
             if (function_exists('sefRelToAbs') && !$ignoreSEF && !defined('_JLEGACY')) {
                 $url = sefRelToAbs($url);
             }
         }
     } else {
         // backend
         $url = ($_SERVER['SERVER_PORT'] == 443 ? SECUREURL : URL) . "administrator/" . basename($base) . "?" . $params;
     }
     $url = $encodeAmpersands ? vmAmpReplace($url) : str_replace('&amp;', '&', $url);
     return $url;
 }