コード例 #1
0
ファイル: redirects.php プロジェクト: hungnv0789/vhtm
	public function GetListRow($row)
	{
		switch($row['redirectassoctype']) {
			case ISC_REDIRECTS::REDIRECT_TYPE_PRODUCT:
				$urlInfo = ISC_URLS::getProductUrl($row['redirectassocid'], true);
				if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
					$newUrl = '<a href="' . $urlInfo['url'] . '" target="_blank">' . GetLang('Product') . ': ' . $urlInfo['title'] . '</a>';
				}
				break;
			case ISC_REDIRECTS::REDIRECT_TYPE_CATEGORY:
				$urlInfo = ISC_URLS::getCategoryUrl($row['redirectassocid'], true);
				if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
					$newUrl = '<a href="' . $urlInfo['url'] . '" target="_blank">' . GetLang('Category') . ': ' .  $urlInfo['title'] . '</a>';
				}
				break;
			case ISC_REDIRECTS::REDIRECT_TYPE_BRAND:
				$urlInfo = ISC_URLS::getBrandUrl($row['redirectassocid'], true);
				if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
					$newUrl = '<a href="' . $urlInfo['url'] . '" target="_blank">' . GetLang('Brand') . ': ' . $urlInfo['title'] . '</a>';
				}
				break;
			case ISC_REDIRECTS::REDIRECT_TYPE_PAGE:
				$urlInfo = ISC_URLS::getPageUrl($row['redirectassocid'], true);
				if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
					$newUrl = '<a href="' . $urlInfo['url'] . '" target="_blank">' . GetLang('Page') . ': ' . $urlInfo['title'] . '</a>';
				}
				break;
			default:
				$newUrl = '<a href="' . $row['redirectmanual'] . '" target="_blank">' . $row['redirectmanual'] . '</a>';
		}


		$new_row['ID'] = $row['redirectid'];
		$new_row['Old URL'] = '<a href="' . GetConfig('ShopPath') . $row['redirectpath'] . '" target="_blank">' . $row['redirectpath'] . '</a>';
		$new_row['New URL'] = $newUrl;

		return $new_row;
	}
コード例 #2
0
	private function saveLinkById()
	{
		$redirectId = (int)$_POST['redirectid'];
		$newId = (int)$_POST['newid'];
		$dataType = $_POST['datatype'];

		if(!in_array($dataType, array('product', 'category', 'page', 'brand'))) {
			ISC_JSON::output(GetLang('LinkerInvalidDataType'));
		}

		GetLib('class.urls');
		GetLib('class.redirects');
		$assocType = ISC_REDIRECTS::REDIRECT_TYPE_MANUAL;

		switch($dataType) {
			case 'product':
				$assocType = ISC_REDIRECTS::REDIRECT_TYPE_PRODUCT;
				$urlInfo = ISC_URLS::getProductUrl($newId , true);
				$newUrl = $urlInfo['url'];
				$title = GetLang('Product') . ': ' . $urlInfo['title'];
				break;
			case 'category':
				$assocType = ISC_REDIRECTS::REDIRECT_TYPE_CATEGORY;
				$urlInfo = ISC_URLS::getCategoryUrl($newId , true);
				$newUrl = $urlInfo['url'];
				$title = GetLang('Category') . ': ' . $urlInfo['title'];
				break;
			case 'page':
				$assocType = ISC_REDIRECTS::REDIRECT_TYPE_PAGE;
				$urlInfo = ISC_URLS::getPageUrl($newId , true);
				$newUrl = $urlInfo['url'];
				$title = GetLang('Page') . ': ' . $urlInfo['title'];
				break;
			case 'brand':
				$assocType = ISC_REDIRECTS::REDIRECT_TYPE_BRAND;
				$urlInfo = ISC_URLS::getBrandUrl($newId , true);
				$newUrl = $urlInfo['url'];
				$title = GetLang('Brand') . ': ' . $urlInfo['title'];
				break;
		}

		$returnData = array(
			'title' => $title,
			'url' => $newUrl,
			'newid' =>  $newId,
			'redirectid' =>  $redirectId,
		);

		if($redirectId == 0 && substr($_POST['redirectid'], 0, 3) == 'tmp') {
			$redirectId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('redirects', array('redirectassoctype' => $assocType, 'redirectassocid'=> $newId,'redirectpath' => '', 'redirectmanual' => ''));

			if($redirectId) {
				$returnData['redirectid'] = $redirectId;
				$returnData['tmpredirectid'] = $_POST['redirectid'];
				ISC_JSON::output('', true, $returnData);
				return;
			}
		} else {
			if($GLOBALS['ISC_CLASS_DB']->UpdateQuery('redirects', array('redirectassoctype' => $assocType, 'redirectassocid'=> $newId ), 'redirectid=' . $redirectId)) {
				ISC_JSON::output('', true, $returnData);
				return;
			}
		}
		// return results
		ISC_JSON::output(GetLang('RedirectSaveErrorDatabase'));
	}
コード例 #3
0
ファイル: class.redirects.php プロジェクト: hungnv0789/vhtm
	public function getRedirectsTable()
	{
		GetLib('class.redirects');
		GetLib('class.urls');

		$perPage = 20;
		$page    = max((int)@$_GET['page'], 1);
		$start   = ($page * $perPage) - $perPage;
		$NumResults = 0;
		$GLOBALS['RedirectsGrid']  = "";
		$GLOBALS['RedirectPaging'] = "";

		$sortOrder = 'desc';

		if (isset($_GET['sortOrder']) && $_GET['sortOrder'] == 'asc') {
			$sortOrder = 'asc';
		}

		$sortLinks = array(
			"OldUrl" => "r.redirectpath",
			"NewUrl" => "r.redirectassoctype",
			"RedirectId" => "r.redirectid",
		);

		if (isset($_GET['sortField']) && in_array($_GET['sortField'], $sortLinks)) {
			$sortField = $_GET['sortField'];
		}
		else {
			$sortField = "r.redirectid";
		}

		$sortURL = '&sortField=' . $sortField . '&sortOrder=' . $sortOrder;
		$GLOBALS['SortURL'] = $sortURL;

		// Get the results for the query
		$redirectResult = $this->getRedirectRows($start, $sortField, $sortOrder, $perPage, $NumResults);
		$numPages = ceil($NumResults / $perPage);

		if(($start+1) > $NumResults && $start > 1) {
			$_GET['page'] = 1;
			return $this->getRedirectsTable();
		}

		// Add the "(Page x of n)" label
		if($NumResults > $perPage) {
			$GLOBALS['RedirectPaging'] = sprintf("(%s %d of %d) &nbsp;&nbsp;&nbsp;", GetLang('Page'), $page, $numPages);
			$GLOBALS['RedirectPaging'] .= BuildPagination($NumResults, $perPage, $page, 'remote.php?remoteSection=redirects&w=getRedirectsTable' . $sortURL);
		}

		$GLOBALS['RedirectPaging'] = rtrim($GLOBALS['RedirectPaging'], ' |');
		$GLOBALS['SortField'] = $sortField;
		$GLOBALS['SortOrder'] = $sortOrder;

		BuildAdminSortingLinks($sortLinks, "remote.php?remoteSection=redirects&amp;w=getRedirectsTable&amp;page=".$page, $sortField, $sortOrder);

		if($NumResults > 0) {
			// Display the redirects
			while ($row = $GLOBALS["ISC_CLASS_DB"]->Fetch($redirectResult))
			{
				$GLOBALS['RedirectId'] = $row['redirectid'];
				$GLOBALS['OldURL'] = $row['redirectpath'];
				$redirectManual = $row['redirectmanual'];
				if ($redirectManual == '') {
					$redirectManual = GetLang('ClickHereToEnterAURL');
				}
				$GLOBALS['NewURL'] = $redirectManual;
				$GLOBALS['RedirectTypeAutoSelected'] = "selected='selected'";
				$GLOBALS['RedirectTypeManualSelected'] = '';
				$GLOBALS['RedirectTypeManualDisplay'] = "display: none;";
				$GLOBALS['RedirectTypeAutoDisplay'] = "";
				$GLOBALS['NewURLTitle'] = '';
				$GLOBALS['LinkerTitle'] = GetLang('ChangeLink');
				$GLOBALS['RedirectTestLink'] = GetConfig('ShopPath') . $row['redirectpath'];

				$row['redirectassoctype'] = (int)$row['redirectassoctype'];

				switch($row['redirectassoctype']) {
					case ISC_REDIRECTS::REDIRECT_TYPE_NOREDIRECT:
					case ISC_REDIRECTS::REDIRECT_TYPE_MANUAL:
						$GLOBALS['RedirectTypeManualSelected'] = "selected='selected'";
						$GLOBALS['RedirectTypeAutoSelected'] = "";
						$GLOBALS['RedirectTypeManualDisplay'] = "";
						$GLOBALS['RedirectTypeAutoDisplay'] = "display: none;";
						$GLOBALS['LinkerTitle'] = GetLang('BrowseForLink');
						break;
					case ISC_REDIRECTS::REDIRECT_TYPE_PRODUCT:
						$urlInfo = ISC_URLS::getProductUrl($row['redirectassocid'], true);
						if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
							$GLOBALS['NewURL'] = $urlInfo['url'];
							$GLOBALS['NewURLTitle'] = GetLang('Product') . ': ' . $urlInfo['title'];
						}
						break;
					case ISC_REDIRECTS::REDIRECT_TYPE_CATEGORY:
						$urlInfo = ISC_URLS::getCategoryUrl($row['redirectassocid'], true);
						if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
							$GLOBALS['NewURL'] = $urlInfo['url'];
							$GLOBALS['NewURLTitle'] = GetLang('Category') . ': ' .  $urlInfo['title'];
						}
						break;
					case ISC_REDIRECTS::REDIRECT_TYPE_BRAND:
						$urlInfo = ISC_URLS::getBrandUrl($row['redirectassocid'], true);
						if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
							$GLOBALS['NewURL'] = $urlInfo['url'];
							$GLOBALS['NewURLTitle'] = GetLang('Brand') . ': ' . $urlInfo['title'];
						}
						break;
					case ISC_REDIRECTS::REDIRECT_TYPE_PAGE:
						$urlInfo = ISC_URLS::getPageUrl($row['redirectassocid'], true);
						if(is_array($urlInfo)  && !empty($urlInfo['title'])) {
							$GLOBALS['NewURL'] = $urlInfo['url'];
							$GLOBALS['NewURLTitle'] = GetLang('Page') . ': ' . $urlInfo['title'];
						}
						break;
				}

				$GLOBALS['RedirectsGrid'] .= $this->template->render('redirects.row.tpl');
			}
		}

		return array($this->template->render('redirects.grid.tpl'), $NumResults);
	}
コード例 #4
0
ファイル: class.redirects.php プロジェクト: hungnv0789/vhtm
	/**
	* Adds or removes www. to the ShopPath depending on the RedirectWWW config setting.
	* This is so the store doesn't unnecessarily keep redirecting if the RedirectWWW setting doesn't match with the ShopPath.
	*
	* @param string $shopPath The ShopPath to normalize
	* @param REDIRECT_NO_PREFERENCE|REDIRECT_TO_WWW|REDIRECT_TO_NO_WWW $redirectWWW The chosen redirect www preference
	* @return string The normalized shop path
	*/
	public static function normalizeShopPath($shopPath, $redirectWWW)
	{
		if ($redirectWWW == REDIRECT_NO_PREFERENCE) {
			return $shopPath;
		}

		$info = @parse_url($shopPath);
		if ($info === false || empty($info['host'])) {
			return $shopPath;
		}

		$host = $info['host'];

		// set to redirect to www and their shop path doesn't contain www.
		if ($redirectWWW == REDIRECT_TO_WWW && isc_substr($host, 0, 4) != 'www.') {
			// add www. to host
			$newHost = 'www.' . $host;
		}
		// set to redirect to no-www but their shop path contains www?
		elseif ($redirectWWW == REDIRECT_TO_NO_WWW  && isc_substr($host, 0, 4) == 'www.') {
			// remove the www. from host
			$newHost = isc_substr($host, 4);
		}
		else {
			return $shopPath;
		}

		// reconstruct shop path
		$info['host'] = $newHost;

		GetLib('class.urls');
		$newShopPath = ISC_URLS::unparseUrl($info);

		return $newShopPath;
	}