public static function GetShortUri($uri) { $uriCrc32 = self::Crc32($uri); $dbResult = CBXShortUri::GetList(array(), array("URI_CRC" => $uriCrc32)); while ($arResult = $dbResult->Fetch()) { if ($arResult["URI"] == $uri) { return "/" . $arResult["SHORT_URI"]; } } $arFields = array("URI" => $uri, "SHORT_URI" => self::GenerateShortUri(), "STATUS" => 301); $id = CBXShortUri::Add($arFields); if ($id) { return "/" . $arFields["SHORT_URI"]; } return ""; }
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; } }
$bVarsFromForm = false; if($REQUEST_METHOD == "POST" && ($save!="" || $apply!="") && $isAdmin && check_freetrix_sessid()) { $arFields = Array( "URI" => $URI, "SHORT_URI" => $SHORT_URI, "STATUS" => $STATUS, ); if($ID>0) { $res = CBXShortUri::Update($ID, $arFields); } else { $ID = CBXShortUri::Add($arFields); $res = ($ID>0); } if($res) { if($apply!="") LocalRedirect("/freetrix/admin/short_uri_edit.php?ID=".$ID."&mess=ok&lang=".LANG."&".$tabControl->ActiveTabParam()); 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");