function GetShortUrl($url, $server = false) { $show = false; $rsData = CBXShortUri::GetList(array(), array()); while ($arRes = $rsData->Fetch()) { if ($arRes["URI"] == $url) { $str_SHORT_URI = $arRes["SHORT_URI"]; $show = true; } } if ($show) { return $server ? 'http://' . $_SERVER['SERVER_NAME'] . '/' . $str_SHORT_URI : $str_SHORT_URI; } else { $str_SHORT_URI = CBXShortUri::GenerateShortUri(); $arFields = array("URI" => $url, "SHORT_URI" => $str_SHORT_URI, "STATUS" => "301"); $ID = CBXShortUri::Add($arFields); return $server ? 'http://' . $_SERVER['SERVER_NAME'] . '/' . $str_SHORT_URI : $str_SHORT_URI; } }
/** * Returns short link * * @param string $fullLink * @return string */ public static function getShortLink($fullLink) { $prefix = 'http://' . SITE_SERVER_NAME . '/'; $rsShortLink = \CBXShortUri::GetList([], ['URI' => $fullLink]); if ($shortLink = $rsShortLink->Fetch()) { return $prefix . $shortLink['SHORT_URI']; } $shortLink = \CBXShortUri::GenerateShortUri(); $id = \CBXShortUri::Add(['URI' => $fullLink, 'SHORT_URI' => $shortLink, 'STATUS' => '301']); if ($id) { return $prefix . $shortLink; } }
else LocalRedirect("/freetrix/admin/short_uri_admin.php?lang=".LANG); } else { $message = implode("\n", CBXShortUri::GetErrors()); if(strlen($message) <= 0) $message = GetMessage("SU_EF_save_error"); $message = new CAdminMessage($message); $bVarsFromForm = true; } } ClearVars(); $str_SHORT_URI = CBXShortUri::GenerateShortUri(); if (isset($_REQUEST["public"])) { $str_URI = $_REQUEST["str_URI"]; $suri = CBXShortUri::GetList(array(), array("URI_EXACT" => $str_URI)); if ($a = $suri->Fetch()) $ID = $a["ID"]; $str_URI = htmlspecialcharsbx($str_URI); } if($ID>0) { $suri = CBXShortUri::GetList(array(), array("ID" => $ID)); if(!$suri->ExtractFields("str_")) $ID=0;