Exemplo n.º 1
0
	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;
	}
Exemplo n.º 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'));
	}
Exemplo n.º 3
0
	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);
	}
Exemplo n.º 4
0
	/**
	* Finds and returns a redirect for $urlPath which is typically the current REQUEST_URI (including app path for sub-dir installs)
	*
	* @param mixed $urlPath
	*/
	public function generateRedirectUrl($urlPath)
	{
		$urlPath = isc_substr($urlPath, strlen(GetConfig('AppPath')));
		$check = self::loadRedirectByURL($urlPath);

		if(!$check) {
			return false;
		}

		// if we made it here, we have redirect, we now need to find what item it's for and redirect
		if($check['redirectassoctype'] == self::REDIRECT_TYPE_MANUAL) {
			// it's a manual redirect, so the new URL has already been specified
			if(!is_null($check['redirectmanual'])) {
				$url = parse_url($check['redirectmanual']);
				if (isset($url['host'])) {
					return $check['redirectmanual'];
				} else {
					$url = GetConfig('AppPath') . $url['path'];
					if (!$url) {
						return '/';
					}
					return $url;
				}
			}
			return false;
		}

		GetLib("class.urls");

		$newUrl = null;
		$check['redirectassoctype'] = (int)$check['redirectassoctype'];
		switch ($check['redirectassoctype']) {
			case self::REDIRECT_TYPE_PRODUCT:
				$newUrl = ISC_URLS::getProductUrl($check['redirectassocid']);
				break;
			case self::REDIRECT_TYPE_CATEGORY:
				$newUrl = ISC_URLS::getCategoryUrl($check['redirectassocid']);
				break;
			case self::REDIRECT_TYPE_BRAND:
				$newUrl = ISC_URLS::getBrandUrl($check['redirectassocid']);
				break;
			case self::REDIRECT_TYPE_PAGE:
				$newUrl = ISC_URLS::getPageUrl($check['redirectassocid']);
				break;
			default:
				return false;
		}

		if(!$newUrl) {
			return false;
		}

		return $newUrl;
	}