コード例 #1
0
ファイル: class.php プロジェクト: ASDAFF/1C_Bitrix_info_site
 protected function doPostAction($isEdit, $action)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     if ($isEdit) {
         $APPLICATION->RestartBuffer();
         header('Content-Type: application/json', true);
         echo CSecurityJsonHelper::encode($this->arResult);
         die;
     } else {
         switch ($action) {
             case 'download':
                 $APPLICATION->restartBuffer();
                 header('Content-Type: text/plain', true);
                 header('Content-Disposition: attachment; filename="recovery_codes.txt"');
                 header('Content-Transfer-Encoding: binary');
                 header(sprintf('Content-Length: %d', CUtil::BinStrlen($this->arResult['PLAIN_RESPONSE'])));
                 echo $this->arResult['PLAIN_RESPONSE'];
                 exit;
                 break;
             case 'print':
                 $APPLICATION->restartBuffer();
                 $this->includeComponentTemplate(static::PRINT_PAGE);
                 exit;
                 break;
             case 'view':
             default:
                 $this->includeComponentTemplate(static::VIEW_PAGE);
                 break;
         }
     }
 }
コード例 #2
0
ファイル: asn.php プロジェクト: DarneoStudio/bitrix
 protected static function ToInt($bin)
 {
     $result = 0;
     $len = CUtil::BinStrlen($bin);
     for ($i = 0; $i < $len; $i++) {
         $byte = self::ReadByte($bin);
         $result += $byte << ($len - $i - 1) * 8;
     }
     return $result;
 }
コード例 #3
0
ファイル: google_push.php プロジェクト: rasuldev/torino
 /**
  * Returns batch of the message
  * @return string
  */
 public function getBatch()
 {
     $data = array("data" => array('contentTitle' => $this->title, "contentText" => $this->text, "messageParams" => $this->customProperties), "time_to_live" => $this->expiryValue, "registration_ids" => $this->deviceTokens);
     $data = CPushManager::_MakeJson($data, "", true);
     $batch = "Content-type: application/json\r\n";
     $batch .= "Content-length: " . CUtil::BinStrlen($data) . "\r\n";
     $batch .= "\r\n";
     $batch .= $data;
     return base64_encode($batch);
 }
コード例 #4
0
function CRCCryptData($data, $pwdString, $type)
{
    $type = strtoupper($type);
    if ($type != "D") {
        $type = "E";
    }
    $res_data = "";
    if ($type == 'D') {
        $data = urldecode($data);
    }
    $key[] = "";
    $box[] = "";
    $temp_swap = "";
    $pwdLength = CUtil::BinStrlen($pwdString);
    for ($i = 0; $i <= 255; $i++) {
        $key[$i] = ord(CUtil::BinSubstr($pwdString, $i % $pwdLength, 1));
        $box[$i] = $i;
    }
    $x = 0;
    for ($i = 0; $i <= 255; $i++) {
        $x = ($x + $box[$i] + $key[$i]) % 256;
        $temp_swap = $box[$i];
        $box[$i] = $box[$x];
        $box[$x] = $temp_swap;
    }
    $temp = "";
    $k = "";
    $cipherby = "";
    $cipher = "";
    $a = 0;
    $j = 0;
    for ($i = 0, $n = CUtil::BinStrlen($data); $i < $n; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $temp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $temp;
        $k = $box[($box[$a] + $box[$j]) % 256];
        $cipherby = ord(CUtil::BinSubstr($data, $i, 1)) ^ $k;
        $cipher .= chr($cipherby);
    }
    if ($type == 'D') {
        $res_data = urldecode(urlencode($cipher));
    } else {
        $res_data = urlencode($cipher);
    }
    return $res_data;
}
コード例 #5
0
ファイル: apple_push.php プロジェクト: Satariall/izurit
 public function getBatch()
 {
     $arTokens = $this->getRecipients();
     $sPayload = $this->getPayload();
     $nPayloadLength = CUtil::BinStrlen($sPayload);
     $totalBatch = "";
     for ($i = 0; $i < count($arTokens); $i++) {
         $sDeviceToken = $arTokens[$i];
         $nTokenLength = strlen($sDeviceToken);
         $sRet = pack('CNNnH*', 1, $this->getCustomIdentifier(), $this->getExpiry() > 0 ? time() + $this->getExpiry() : 0, 32, $sDeviceToken);
         $sRet .= pack('n', $nPayloadLength);
         $sRet .= $sPayload;
         if (strlen($totalBatch) > 0) {
             $totalBatch .= ";";
         }
         $totalBatch .= base64_encode($sRet);
     }
     return $totalBatch;
 }
コード例 #6
0
ファイル: mail.php プロジェクト: Satariall/izurit
 function AddAttachment($arFields)
 {
     global $DB;
     $strSql = "SELECT ATTACHMENTS FROM b_mail_message WHERE ID=" . IntVal($arFields["MESSAGE_ID"]);
     $dbr = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!($dbr_arr = $dbr->Fetch())) {
         return false;
     }
     $n = IntVal($dbr_arr["ATTACHMENTS"]) + 1;
     if (strlen($arFields["FILE_NAME"]) <= 0) {
         $arFields["FILE_NAME"] = $n . ".";
         if (strpos($arFields["CONTENT_TYPE"], "message/") === 0) {
             $arFields["FILE_NAME"] .= "msg";
         } else {
             $arFields["FILE_NAME"] .= "tmp";
         }
     }
     if (is_set($arFields, "CONTENT_TYPE")) {
         $arFields["CONTENT_TYPE"] = strtolower($arFields["CONTENT_TYPE"]);
     }
     if (strpos($arFields["CONTENT_TYPE"], "image/") === 0 && (!is_set($arFields, "IMAGE_WIDTH") || !is_set($arFields, "IMAGE_HEIGHT")) && is_set($arFields, "FILE_DATA")) {
         $filename = CTempFile::GetFileName(md5(uniqid("")) . '.tmp');
         CheckDirPath($filename);
         if (file_put_contents($filename, $arFields["FILE_DATA"]) !== false) {
             $img_arr = CFile::GetImageSize($filename);
             $arFields["IMAGE_WIDTH"] = $img_arr ? $img_arr[0] : 0;
             $arFields["IMAGE_HEIGHT"] = $img_arr ? $img_arr[1] : 0;
         }
     }
     if (is_set($arFields, "FILE_DATA") && !is_set($arFields, "FILE_SIZE")) {
         $arFields["FILE_SIZE"] = CUtil::BinStrlen($arFields["FILE_DATA"]);
     }
     $file = array('name' => md5($arFields['FILE_NAME']), 'size' => $arFields['FILE_SIZE'], 'type' => $arFields['CONTENT_TYPE'], 'content' => $arFields['FILE_DATA'], 'MODULE_ID' => 'mail');
     if (!($file_id = CFile::saveFile($file, 'mail/attachment'))) {
         return false;
     }
     unset($arFields['FILE_DATA']);
     $arFields['FILE_ID'] = $file_id;
     $ID = $DB->add('b_mail_msg_attachment', $arFields);
     if ($ID > 0) {
         $strSql = 'UPDATE b_mail_message SET ATTACHMENTS = ' . $n . ' WHERE ID = ' . intval($arFields['MESSAGE_ID']);
         $DB->query($strSql, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__);
     }
     return $ID;
 }
コード例 #7
0
ファイル: site_checker.php プロジェクト: ASDAFF/entask.ru
			strFinalStatus = "'.CUtil::JSEscape($strFinalStatus).'";
			strGroupName = "'.CUtil::JSEscape($oTest->group_name).'";
			strGroupDesc = "'.CUtil::JSEscape($oTest->group_desc).'";
			test_result = '.($oTest->result === true ? 1 : ($oTest->result === false ? -1 : 0)).'; // 0 = note
		';
	}
	else
		echo '<h1>Permission denied: BITRIX SESSID ERROR</h1>';
	exit;
}
elseif ($_REQUEST['read_log']) // after prolog to send correct charset
{
	$oTest = new CSiteCheckerTest();
	$str = htmlspecialcharsEx(file_get_contents($_SERVER['DOCUMENT_ROOT'].$oTest->LogFile));

	if (($s = CUtil::BinStrlen($str)) > ini_get('pcre.backtrack_limit'))
		@ini_set('pcre.backtrack_limit', $s);

	?><!DOCTYPE HTML><html><body style="color:#666"><h1 style="color:#000"><?php 
echo GetMessage("MAIN_SC_SYSTEST_LOG");
?>
</h1><?
	$str = preg_replace('#^[0-9]{4}-...-[0-9]{2} .*\):#m','<span style="color:#000">$0</span>', $str);
	if (preg_match('#[a-z_0-9]+#', $a = $_REQUEST['anchor']))
		$str = preg_replace('#^.+\('.$a.'\)#m','<a name="'.$a.'" style="background-color:#EE3">$0</a>', $str);

	$str = preg_replace('#Ok$#m', '<span style="color:#408218">$0</span>', $str);
	$str = preg_replace('#Warning$#m', '<span style="color:#663300">$0</span>', $str);
	$str = preg_replace('#Fail$#m', '<span style="color:#DD0000">$0</span>', $str);
	echo '<pre>'.$str.'</pre>';
	exit;
コード例 #8
0
ファイル: site_checker.php プロジェクト: nycmic/bittest
	function check_compression()
	{
		$strRequest = "GET "."/bitrix/admin/site_checker.php?test_type=compression&unique_id=".checker_get_unique_id()." HTTP/1.1\r\n";
		$strRequest.= "Host: ".$this->host."\r\n";
		$strRequest.= "Accept-Encoding: gzip, deflate\r\n";
		$strRequest.= "\r\n";

		$retVal = false;

		if (!$res = $this->ConnectToHost())
			return false;

		$compression = IsModuleInstalled('compression');
		$strRes = GetHttpResponse($res, $strRequest, $strHeaders);

		if (preg_match('#gzip|deflate#mi', $strHeaders) && CUtil::BinStrlen($strRes) < 64 * 1024) // comression not supported by server
			return $compression ? $this->Result(false, GetMessage("MAIN_SC_ENABLED")) : $this->Result(true, GetMessage("MAIN_SC_ENABLED_MOD"));
		else
			return $compression ? $this->Result(false, GetMessage("MAIN_SC_COMP_DISABLED")) : $this->Result(false, GetMessage("MAIN_SC_COMP_DISABLED_MOD"));
	}
コード例 #9
0
 function Analyze(&$content)
 {
     static $arLocalCache = array();
     $content_len = CUtil::BinStrlen($content) * 2;
     CUtil::AdjustPcreBacktrackLimit($content_len);
     $this->stylewithiframe = preg_match("/<style.*>\\s*iframe/", $content);
     $arData = preg_split("/(<script.*?>.*?<\\/script.*?>|<iframe.*?>.*?<\\/iframe.*?>)/is", $content, -1, PREG_SPLIT_DELIM_CAPTURE);
     $cData = count($arData);
     if ($cData < 2) {
         return;
     }
     $bDataChanged = false;
     for ($iData = 1; $iData < $cData; $iData += 2) {
         $this->data = $arData[$iData];
         //полный код блока, включая ограничивающие теги
         //                <       1         2  >  3        4
         if (!preg_match('/^<(script|iframe)(.*?)>(.*?)(<\\/\\1.*?>)$/is', $this->data, $ret)) {
             continue;
         }
         if ($iData > 1) {
             $this->prev = $arData[$iData - 2] . $arData[$iData - 1];
         } else {
             $this->prev = $arData[$iData - 1];
         }
         if ($iData < $cData - 2) {
             $this->next = $arData[$iData + 1] . $arData[$iData + 2];
         } else {
             $this->next = $arData[$iData + 1];
         }
         $this->resultrules = array();
         $this->bodylines = false;
         $this->atributes = $ret[2];
         if (strtolower($ret[1]) == 'script') {
             $this->body = $this->returnscriptbody($this->data);
             $this->type = 'script';
         } else {
             $this->body = '';
             $this->type = 'iframe';
         }
         $this->whitelist_id = $this->isinwhitelist();
         if (!$this->whitelist_id) {
             $cache_id = md5($this->data);
             if (!isset($arLocalCache[$cache_id])) {
                 $arLocalCache[$cache_id] = $this->returnblockrating();
             }
             if ($arLocalCache[$cache_id] >= $this->maxrating) {
                 $this->dolog();
                 $arData[$iData] = $this->end_blkblock();
                 if ($this->replace) {
                     $bDataChanged = true;
                 }
             }
         }
         $this->cnt++;
     }
     if ($bDataChanged) {
         $content = implode('', $arData);
     }
 }
コード例 #10
0
ファイル: site_checker.php プロジェクト: ASDAFF/open_bx
function PrintHTTP($strRequest, $strHeaders, $strRes)
{
	echo 
	"== Request ==\n".
	$strRequest.
	"== Response ==\n".
	$strHeaders.
	"== Body ==\n".
	(($l = CUtil::BinStrlen($strRes)) > 1000 ? CUtil::BinSubstr($strRes, 0, 1000).' ... ('.$l.' bytes)' : $strRes).
	"==========\n";
}
コード例 #11
0
ファイル: mail.php プロジェクト: mrdeadmouse/u136006
 function AddAttachment($arFields)
 {
     global $DB;
     $strSql = "SELECT ATTACHMENTS FROM b_mail_message WHERE ID=" . IntVal($arFields["MESSAGE_ID"]);
     $dbr = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!($dbr_arr = $dbr->Fetch())) {
         return false;
     }
     $n = IntVal($dbr_arr["ATTACHMENTS"]) + 1;
     if (strlen($arFields["FILE_NAME"]) <= 0) {
         $arFields["FILE_NAME"] = $n . ".";
         if (strpos($arFields["CONTENT_TYPE"], "message/") === 0) {
             $arFields["FILE_NAME"] .= "msg";
         } else {
             $arFields["FILE_NAME"] .= "tmp";
         }
     }
     if (is_set($arFields, "CONTENT_TYPE")) {
         $arFields["CONTENT_TYPE"] = strtolower($arFields["CONTENT_TYPE"]);
     }
     if (strpos($arFields["CONTENT_TYPE"], "image/") === 0 && (!is_set($arFields, "IMAGE_WIDTH") || !is_set($arFields, "IMAGE_HEIGHT")) && is_set($arFields, "FILE_DATA")) {
         $filename = CTempFile::GetFileName(md5(uniqid("")) . '.tmp');
         CheckDirPath($filename);
         if (file_put_contents($filename, $arFields["FILE_DATA"]) !== false) {
             $img_arr = CFile::GetImageSize($filename);
             $arFields["IMAGE_WIDTH"] = $img_arr ? $img_arr[0] : 0;
             $arFields["IMAGE_HEIGHT"] = $img_arr ? $img_arr[1] : 0;
         }
     }
     if (is_set($arFields, "FILE_DATA") && !is_set($arFields, "FILE_SIZE")) {
         $arFields["FILE_SIZE"] = CUtil::BinStrlen($arFields["FILE_DATA"]);
     }
     if (!CMailUtil::IsSizeAllowed(strlen($DB->ForSQL($arFields["FILE_DATA"])) + 100)) {
         return false;
     }
     $ID = $DB->Add("b_mail_msg_attachment", $arFields, array("FILE_DATA"));
     if ($ID > 0) {
         $strSql = "UPDATE b_mail_message SET ATTACHMENTS=" . $n . " WHERE ID=" . IntVal($arFields["MESSAGE_ID"]);
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     return $ID;
     /*
     $arFile = Array(
     		"name"=>$filename,
     		"size"=>strlen($part["BODY"]),
     		"type"=>$part["CONTENT-TYPE"],
     		"content"=>$part["BODY"],
     		"MODULE_ID"=>"mail"
     	);
     $file_id = CFile::SaveFile($arFile, "mail");
     */
 }
コード例 #12
0
 public function SaveFile($arBucket, $filePath, $arFile)
 {
     global $APPLICATION;
     if ($arBucket["PREFIX"]) {
         if (substr($filePath, 0, strlen($arBucket["PREFIX"]) + 2) != "/" . $arBucket["PREFIX"] . "/") {
             $filePath = "/" . $arBucket["PREFIX"] . "/" . ltrim($filePath, "/");
         }
     }
     $filePath = CCloudUtil::URLEncode($filePath, "UTF-8");
     $additional_headers = array();
     if ($this->_public) {
         $additional_headers["x-amz-acl"] = "public-read";
     }
     $additional_headers["Content-Type"] = $arFile["type"];
     $additional_headers["Content-Length"] = array_key_exists("content", $arFile) ? CUtil::BinStrlen($arFile["content"]) : filesize($arFile["tmp_name"]);
     $this->SetLocation($arBucket["LOCATION"]);
     $response = $this->SendRequest($arBucket["SETTINGS"], 'PUT', $arBucket["BUCKET"], $filePath, '', array_key_exists("content", $arFile) ? $arFile["content"] : fopen($arFile["tmp_name"], "rb"), $additional_headers);
     if ($this->status == 200) {
         return true;
     } elseif ($this->status == 403) {
         return false;
     } else {
         $APPLICATION->ResetException();
         return false;
     }
 }
コード例 #13
0
ファイル: user.php プロジェクト: ASDAFF/bxApiDocs
	/**
	 * @param $pSecret
	 * @param $pCount
	 * @param int $pDigits
	 * @return bool|int
	 */
	protected static function HOTP($pSecret, $pCount, $pDigits = 6)
	{
		if(CUtil::BinStrlen($pSecret) <= 25)
			$sha_hash = self::hmacsha1(pack("NN", 0, $pCount), $pSecret);
		else
			$sha_hash = self::hmacsha256(pack("NN", 0, $pCount), $pSecret);

		if($sha_hash !== false)
		{
			$dwOffset = hexdec(substr($sha_hash, -1, 1));
			$dbc1 = hexdec(substr($sha_hash, $dwOffset * 2, 8 ));
			$dbc2 = $dbc1 & 0x7fffffff;
			$hotp = $dbc2 % pow(10, $pDigits);
			return str_pad($hotp, $pDigits, "0", STR_PAD_LEFT);
		}
		else
		{
			return false;
		}
	}
コード例 #14
0
ファイル: filter.php プロジェクト: k-kalashnikov/geekcon_new
 /**
  * @param $pString
  * @return bool
  */
 protected static function AdjustPcreBacktrackLimit($pString)
 {
     if (!is_string($pString)) {
         return false;
     }
     $strlen = CUtil::BinStrlen($pString) * 2;
     CUtil::AdjustPcreBacktrackLimit($strlen);
     return true;
 }
コード例 #15
0
 function HOTP($secret, $cnt, $digits = 6)
 {
     if (CUtil::BinStrlen($secret) <= 25) {
         $sha_hash = CSecurityUser::hmacsha1(pack("NN", 0, $cnt), $secret);
     } else {
         $sha_hash = CSecurityUser::hmacsha256(pack("NN", 0, $cnt), $secret);
     }
     if ($sha_hash !== false) {
         $dwOffset = hexdec(substr($sha_hash, -1, 1));
         $dbc1 = hexdec(substr($sha_hash, $dwOffset * 2, 8));
         $dbc2 = $dbc1 & 0x7fffffff;
         $hotp = $dbc2 % pow(10, $digits);
         return $hotp;
     } else {
         return false;
     }
 }
コード例 #16
0
ファイル: search.php プロジェクト: nycmic/bittest
	function PrepareSearchResult($str)
	{
		//$words - contains what we will highlight
		$words = array();
		foreach ($this->Query->m_words as $v)
		{
			$v = ToUpper($v);
			$words[$v] = "KAV";
			if(strpos($v, "\"")!==false)
				$words[str_replace("\"", "&QUOT;", $v)] = "KAV";
		}

		foreach ($this->Query->m_stemmed_words as $v)
			$words[ToUpper($v)]="STEM";

		//Prepare upper case version of the string
		if ($this->Query->bStemming)
		{
			//And add missing stemming words
			$arStemInfo = stemming_init($this->Query->m_lang);
			$a = stemming($this->Query->m_query, $this->Query->m_lang, true);
			foreach ($a as $stem => $cnt)
			{
				if (!preg_match("/cut[56]/i", $stem))
					$words[$stem] = "STEM";
			}
			$pcreLettersClass = "[".$arStemInfo["pcre_letters"]."]";
			$strUpp = stemming_upper($str, $this->Query->m_lang);
		}
		else
		{
			$strUpp = ToUpper($str);
			$pcreLettersClass = "";
		}

		$wordsCount = count($words);

		//We'll use regexp to find positions of the words in the text
		$pregMask = "";
		foreach ($words as $search => $type)
		{
			if ($type == "STEM")
				$pregMask = "(?<!".$pcreLettersClass.")".preg_quote($search, "/").$pcreLettersClass."*|".$pregMask;
			else
				$pregMask = $pregMask."|".preg_quote($search, "/");
		}
		$pregMask = trim($pregMask, "|");

		$arPos = array(); //This will contain positions of the first occurrence
		$arPosW = array(); //This is "running" words array
		$arPosP = array(); //and their positions
		$arPosLast = false; //Best found combination of the positions
		$matches = array();
		if (preg_match_all("/(".$pregMask.")/i".BX_UTF_PCRE_MODIFIER, $strUpp, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE))
		{
			foreach ($matches as $oneCase)
			{
				$search = null;
				if (isset($words[$oneCase[0][0]]))
				{
					$search = $oneCase[0][0];
				}
				else
				{
					$a = stemming($oneCase[0][0], $this->Query->m_lang, true);
					foreach ($a as $stem => $cnt)
					{
						if (isset($words[$stem]))
						{
							$search = $stem;
							break;
						}
					}
				}

				if (isset($search))
				{
					$p = $oneCase[0][1];
					if (!isset($arPos[$search]))
						$arPos[$search] = $p;
					//Add to the tail of the running window
					$arPosP[] = $p;
					$arPosW[] = $search;
					$cc = count($arPosW);
					if ($cc >= $wordsCount)
					{
						//This cuts the tail of the running window
						while ($cc > $wordsCount)
						{
							array_shift($arPosW);
							array_shift($arPosP);
							$cc--;
						}
						//Check if all the words present in the current window
						if (count(array_unique($arPosW)) == $wordsCount)
						{
							//And check if positions is the best
							if (
								!$arPosLast
								|| (
									(max($arPosP) - min($arPosP)) < (max($arPosLast) - min($arPosLast))
								))
								$arPosLast = $arPosP;
						}
					}
				}
			}
		}

		if ($arPosLast)
			$arPos = $arPosLast;

		//Nothing found just cut some text
		if (empty($arPos))
		{
			$str_len = strlen($str);
			$pos_end = 500;
			while (($pos_end < $str_len) && (strpos(" ,.\n\r", substr($str, $pos_end, 1)) === false))
				$pos_end++;
			return substr($str, 0, $pos_end).($pos_end < $str_len? "...": "");
		}

		sort($arPos);

		$str_len = CUtil::BinStrlen($str);
		$delta = 250/count($arPos);
		$arOtr = array();
		//Have to do it two times because Positions eat each other
		for ($i = 0; $i < 2; $i++)
		{
			$arOtr = array();
			$last_pos = -1;
			foreach ($arPos as $pos_mid)
			{
				//Find where sentence begins
				$pos_beg = $pos_mid - $delta;
				if($pos_beg <= 0)
					$pos_beg = 0;
				while(($pos_beg > 0) && (strpos(" ,.!?\n\r", CUtil::BinSubstr($str, $pos_beg, 1)) === false))
					$pos_beg--;

				//Find where sentence ends
				$pos_end = $pos_mid + $delta;
				if($pos_end > $str_len)
					$pos_end = $str_len;
				while(($pos_end < $str_len) && (strpos(" ,.!?\n\r", CUtil::BinSubstr($str, $pos_end, 1)) === false))
					$pos_end++;

				if($pos_beg <= $last_pos)
					$arOtr[count($arOtr)-1][1] = $pos_end;
				else
					$arOtr[] = array($pos_beg, $pos_end);

				$last_pos = $pos_end;
			}
			//Adjust length of the text
			$delta = 250/count($arOtr);
		}

		$str_result = "";
		foreach ($arOtr as $borders)
		{
			$str_result .= ($borders[0]<=0? "": " ...")
				.CUtil::BinSubstr($str, $borders[0], $borders[1] - $borders[0] + 1)
				.($borders[1] >= $str_len? "": "... ")
			;
		}

		foreach ($words as $search => $type)
			$str_result = $this->repl($search, $type, $str_result);

		$str_result = str_replace("%/^%", "</b>", str_replace("%^%","<b>", $str_result));

		return $str_result;
	}
コード例 #17
0
ファイル: file.php プロジェクト: nycmic/bittest
 function SaveFile($arFile, $strSavePath, $bForceMD5 = false, $bSkipExt = false)
 {
     $strFileName = GetFileName($arFile["name"]);
     /* filename.gif */
     if (isset($arFile["del"]) && $arFile["del"] != '') {
         CFile::DoDelete($arFile["old_file"]);
         if ($strFileName == '') {
             return "NULL";
         }
     }
     if ($arFile["name"] == '') {
         if (isset($arFile["description"]) && intval($arFile["old_file"]) > 0) {
             CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
         }
         return false;
     }
     if (isset($arFile["content"])) {
         if (!isset($arFile["size"])) {
             $arFile["size"] = CUtil::BinStrlen($arFile["content"]);
         }
     } else {
         try {
             $file = new IO\File($arFile["tmp_name"]);
             $arFile["size"] = $file->getSize();
         } catch (IO\IoException $e) {
             $arFile["size"] = 0;
         }
     }
     $arFile["ORIGINAL_NAME"] = $strFileName;
     //translit, replace unsafe chars, etc.
     $strFileName = self::transformName($strFileName, $bForceMD5, $bSkipExt);
     //transformed name must be valid, check disk quota, etc.
     if (self::validateFile($strFileName, $arFile) !== "") {
         return false;
     }
     if ($arFile["type"] == "image/pjpeg" || $arFile["type"] == "image/jpg") {
         $arFile["type"] = "image/jpeg";
     }
     $bExternalStorage = false;
     foreach (GetModuleEvents("main", "OnFileSave", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt))) {
             $bExternalStorage = true;
             break;
         }
     }
     if (!$bExternalStorage) {
         $upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
         $io = CBXVirtualIo::GetInstance();
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             $dir_add = '';
             $i = 0;
             while (true) {
                 $dir_add = substr(md5(uniqid("", true)), 0, 3);
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
                     break;
                 }
                 if ($i >= 25) {
                     $j = 0;
                     while (true) {
                         $dir_add = substr(md5(mt_rand()), 0, 3) . "/" . substr(md5(mt_rand()), 0, 3);
                         if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
                             break;
                         }
                         if ($j >= 25) {
                             $dir_add = substr(md5(mt_rand()), 0, 3) . "/" . md5(mt_rand());
                             break;
                         }
                         $j++;
                     }
                     break;
                 }
                 $i++;
             }
             if (substr($strSavePath, -1, 1) != "/") {
                 $strSavePath .= "/" . $dir_add;
             } else {
                 $strSavePath .= $dir_add . "/";
             }
         } else {
             $strFileExt = $bSkipExt == true || ($ext = GetFileExtension($strFileName)) == '' ? '' : "." . $ext;
             while (true) {
                 if (substr($strSavePath, -1, 1) != "/") {
                     $strSavePath .= "/" . substr($strFileName, 0, 3);
                 } else {
                     $strSavePath .= substr($strFileName, 0, 3) . "/";
                 }
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $strFileName)) {
                     break;
                 }
                 //try the new name
                 $strFileName = md5(uniqid("", true)) . $strFileExt;
             }
         }
         $arFile["SUBDIR"] = $strSavePath;
         $arFile["FILE_NAME"] = $strFileName;
         $strDirName = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/";
         $strDbFileNameX = $strDirName . $strFileName;
         $strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);
         CheckDirPath($strDirName);
         if (is_set($arFile, "content")) {
             $f = fopen($strPhysicalFileNameX, "ab");
             if (!$f) {
                 return false;
             }
             if (fwrite($f, $arFile["content"]) === false) {
                 return false;
             }
             fclose($f);
         } elseif (!copy($arFile["tmp_name"], $strPhysicalFileNameX) && !move_uploaded_file($arFile["tmp_name"], $strPhysicalFileNameX)) {
             CFile::DoDelete($arFile["old_file"]);
             return false;
         }
         if (isset($arFile["old_file"])) {
             CFile::DoDelete($arFile["old_file"]);
         }
         @chmod($strPhysicalFileNameX, BX_FILE_PERMISSIONS);
         //flash is not an image
         $flashEnabled = !CFile::IsImage($arFile["ORIGINAL_NAME"], $arFile["type"]);
         $imgArray = CFile::GetImageSize($strDbFileNameX, false, $flashEnabled);
         if (is_array($imgArray)) {
             $arFile["WIDTH"] = $imgArray[0];
             $arFile["HEIGHT"] = $imgArray[1];
             if ($imgArray[2] == IMAGETYPE_JPEG) {
                 $exifData = CFile::ExtractImageExif($io->GetPhysicalName($strDbFileNameX));
                 if ($exifData && isset($exifData['Orientation'])) {
                     //swap width and height
                     if ($exifData['Orientation'] >= 5 && $exifData['Orientation'] <= 8) {
                         $arFile["WIDTH"] = $imgArray[1];
                         $arFile["HEIGHT"] = $imgArray[0];
                     }
                     $properlyOriented = CFile::ImageHandleOrientation($exifData['Orientation'], $io->GetPhysicalName($strDbFileNameX));
                     if ($properlyOriented) {
                         $jpgQuality = intval(COption::GetOptionString('main', 'image_resize_quality', '95'));
                         if ($jpgQuality <= 0 || $jpgQuality > 100) {
                             $jpgQuality = 95;
                         }
                         imagejpeg($properlyOriented, $io->GetPhysicalName($strDbFileNameX), $jpgQuality);
                     }
                 }
             }
         } else {
             $arFile["WIDTH"] = 0;
             $arFile["HEIGHT"] = 0;
         }
     }
     if ($arFile["WIDTH"] == 0 || $arFile["HEIGHT"] == 0) {
         //mock image because we got false from CFile::GetImageSize()
         if (strpos($arFile["type"], "image/") === 0) {
             $arFile["type"] = "application/octet-stream";
         }
     }
     if ($arFile["type"] == '' || !is_string($arFile["type"])) {
         $arFile["type"] = "application/octet-stream";
     }
     /****************************** QUOTA ******************************/
     if (COption::GetOptionInt("main", "disk_space") > 0) {
         CDiskQuota::updateDiskQuota("file", $arFile["size"], "insert");
     }
     /****************************** QUOTA ******************************/
     $NEW_IMAGE_ID = CFile::DoInsert(array("HEIGHT" => $arFile["HEIGHT"], "WIDTH" => $arFile["WIDTH"], "FILE_SIZE" => $arFile["size"], "CONTENT_TYPE" => $arFile["type"], "SUBDIR" => $arFile["SUBDIR"], "FILE_NAME" => $arFile["FILE_NAME"], "MODULE_ID" => $arFile["MODULE_ID"], "ORIGINAL_NAME" => $arFile["ORIGINAL_NAME"], "DESCRIPTION" => isset($arFile["description"]) ? $arFile["description"] : '', "HANDLER_ID" => isset($arFile["HANDLER_ID"]) ? $arFile["HANDLER_ID"] : '', "EXTERNAL_ID" => isset($arFile["external_id"]) ? $arFile["external_id"] : md5(mt_rand())));
     CFile::CleanCache($NEW_IMAGE_ID);
     return $NEW_IMAGE_ID;
 }
コード例 #18
0
ファイル: post_filter.php プロジェクト: rasuldev/torino
 /**
  * @param string $string
  * @return string
  */
 protected function filter($string)
 {
     $stringLen = CUtil::BinStrlen($string) * 2;
     CUtil::AdjustPcreBacktrackLimit($stringLen);
     return preg_replace_callback("/(<script[^>]*>)(.*?)(<\\/script[^>]*>)/is", array($this, "getFilteredScript"), $string);
 }
コード例 #19
0
ファイル: posting.php プロジェクト: k-kalashnikov/geekcon_new
 function EncodeHeaderFrom($text, $charset)
 {
     $i = CUtil::BinStrlen($text);
     while ($i > 0) {
         if (ord(CUtil::BinSubstr($text, $i - 1, 1)) >> 7) {
             break;
         }
         $i--;
     }
     if ($i == 0) {
         return $text;
     } else {
         return "=?" . $charset . "?B?" . base64_encode(CUtil::BinSubstr($text, 0, $i)) . "?=" . CUtil::BinSubstr($text, $i);
     }
 }
コード例 #20
0
ファイル: cml2.php プロジェクト: nycmic/bittest
 function __unserialize_callback($match)
 {
     return 's:' . CUtil::BinStrlen($match[2]) . ':"' . $match[2] . '";';
 }
コード例 #21
0
	public function SaveFile($arBucket, $filePath, $arFile)
	{
		global $APPLICATION;

		if($arBucket["PREFIX"])
		{
			if(substr($filePath, 0, strlen($arBucket["PREFIX"])+2) != "/".$arBucket["PREFIX"]."/")
				$filePath = "/".$arBucket["PREFIX"]."/".ltrim($filePath, "/");
		}
		$filePath = CCloudUtil::URLEncode($filePath, "UTF-8");

		if (array_key_exists("content", $arFile))
		{
			$obRequest = $this->SendRequest(
				$arBucket["SETTINGS"],
				"PUT",
				$arBucket["BUCKET"],
				$filePath,
				"",
				$arFile["content"],
				array(
					"Content-Type" => $arFile["type"],
					"Content-Length" => CUtil::BinStrlen($arFile["content"]),
				)
			);
		}
		else
		{
			$obRequest = $this->SendRequest(
				$arBucket["SETTINGS"],
				"PUT",
				$arBucket["BUCKET"],
				$filePath,
				"",
				fopen($arFile["tmp_name"], "rb"),
				array(
					"Content-Type" => $arFile["type"],
					"Content-Length" => filesize($arFile["tmp_name"]),
				)
			);
		}

		if($obRequest->status == 201)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
コード例 #22
0
ファイル: tools.php プロジェクト: nProfessor/Mytb
	function Query($method, $host, $port, $path, $postdata = false, $proto = '', $post_content_type = 'N')
	{
		$this->status = 0;
		$this->result = '';
		$this->headers = array();
		$this->cookies = array();
		$fp = fsockopen($proto.$host, $port, $this->errno, $this->errstr, $this->http_timeout);
		if ($fp)
		{
			$strRequest = "$method $path HTTP/1.0\r\n";
			$strRequest .= "Connection: close\r\n";
			$strRequest .= "User-Agent: {$this->user_agent}\r\n";
			$strRequest .= "Accept: */*\r\n";
			$strRequest .= "Host: $host\r\n";
			$strRequest .= "Accept-Language: en\r\n";

			foreach ($this->additional_headers as $key => $value)
				$strRequest .= $key.": ".$value."\r\n";

			if ($method == 'POST' || $method == 'PUT')
			{
				if ('N' !== $post_content_type)
					$strRequest .= $post_content_type == '' ? '' : "Content-type: ".$post_content_type."\r\n";
				else
					$strRequest.= "Content-type: application/x-www-form-urlencoded\r\n";

				if(!array_key_exists("Content-Length", $this->additional_headers))
					$strRequest.= "Content-Length: ".CUtil::BinStrlen($postdata) . "\r\n";
			}
			$strRequest .= "\r\n";
			fwrite($fp, $strRequest);

			if ($method == 'POST' || $method == 'PUT')
			{
				if(is_resource($postdata))
				{
					while(!feof($postdata))
						fwrite($fp, fread($postdata, 1024*1024));
				}
				else
				{
					fwrite($fp, $postdata);
				}
				fwrite($fp, "\r\n");
			}

			$headers = "";
			while(!feof($fp))
			{
				$line = fgets($fp, 4096);
				if($line == "\r\n")
				{
					//$line = fgets($fp, 4096);
					break;
				}
				$headers .= $line;
			}
			$this->ParseHeaders($headers);

			if(is_resource($this->fp))
			{
				while(!feof($fp))
					fwrite($this->fp, fread($fp, 4096));
			}
			else
			{
				$this->result = "";
				while(!feof($fp))
					$this->result .= fread($fp, 4096);
			}

			fclose($fp);

			return true;
		}

		$GLOBALS['APPLICATION']->ThrowException(
					GetMessage('HTTP_CLIENT_ERROR_CONNECT',
					array(
						'%ERRSTR%' => $this->errstr,
						'%ERRNO%' => $this->errno,
						'%HOST%' => $host,
						'%PORT%' => $port,
					)
				)
			);
		return false;
	}
コード例 #23
0
ファイル: file.php プロジェクト: nProfessor/Mytb
	function SaveFile($arFile, $strSavePath, $bForceMD5=false, $bSkipExt=false)
	{
		$strFileName = GetFileName($arFile["name"]);	/* filename.gif */

		if(isset($arFile["del"]) && $arFile["del"] <> '')
		{
			CFile::DoDelete($arFile["old_file"]);
			if($strFileName == '')
				return "NULL";
		}

		if($arFile["name"] == '')
		{
			if(is_set($arFile, "description") && intval($arFile["old_file"])>0)
				CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
			return false;
		}

		if(is_set($arFile, "content") && !is_set($arFile, "size"))
			$arFile["size"] = CUtil::BinStrlen($arFile["content"]);
		else
			$arFile["size"] = filesize($arFile["tmp_name"]);

		/****************************** QUOTA ******************************/
		if (COption::GetOptionInt("main", "disk_space") > 0)
		{
			$quota = new CDiskQuota();
			if (!$quota->checkDiskQuota($arFile))
				return false;
		}
		/****************************** QUOTA ******************************/

		$arFile["ORIGINAL_NAME"] = $strFileName;

		$io = CBXVirtualIo::GetInstance();
		if($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y")
		{
			if(COption::GetOptionString("main", "translit_original_file_name", "N") == "Y")
				$strFileName = CUtil::translit($strFileName, LANGUAGE_ID, array("max_len"=>1024, "safe_chars"=>"."));

			if(COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y")
				$strFileName = $io->RandomizeInvalidFilename($strFileName);
		}

		if(!$io->ValidateFilenameString($strFileName))
			return false;

		//check for double extension vulnerability
		$strFileName = RemoveScriptExtension($strFileName);
		if($strFileName == '')
			return false;

		if(strlen($strFileName) > 255)
			return false;

		//check .htaccess etc.
		if(IsFileUnsafe($strFileName))
			return false;

		//nginx returns octet-stream for .jpg
		if(GetFileNameWithoutExtension($strFileName) == '')
			return false;

		$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");

		if($arFile["type"]=="image/pjpeg" || $arFile["type"]=="image/jpg")
			$arFile["type"]="image/jpeg";

		//.jpe is not image type on many systems
		if(strtolower(GetFileExtension($strFileName)) == "jpe")
			$strFileName = substr($strFileName, 0, -4).".jpg";

		$bExternalStorage = false;
		foreach(GetModuleEvents("main", "OnFileSave", true) as $arEvent)
		{
			if(ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt)))
			{
				$bExternalStorage = true;
				break;
			}
		}

		if(!$bExternalStorage)
		{
			$newName = '';
			if($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N")=="Y")
			{
				$dir_add = '';
				$i=0;
				while(true)
				{
					$dir_add = substr(md5(uniqid(mt_rand(), true)), 0, 3);
					if(!$io->FileExists($_SERVER["DOCUMENT_ROOT"]."/".$upload_dir."/".$strSavePath."/".$dir_add."/".$strFileName))
						break;
					if($i>=25)
					{
						$j=0;
						while(true)
						{
							$dir_add = substr(md5(mt_rand()), 0, 3)."/".substr(md5(mt_rand()), 0, 3);
							if(!$io->FileExists($_SERVER["DOCUMENT_ROOT"]."/".$upload_dir."/".$strSavePath."/".$dir_add."/".$strFileName))
								break;
							if($j>=25)
							{
								$dir_add = substr(md5(mt_rand()), 0, 3)."/".md5(mt_rand());
								break;
							}
							$j++;
						}
						break;
					}
					$i++;
				}
				if(substr($strSavePath, -1, 1) <> "/")
					$strSavePath .= "/".$dir_add;
				else
					$strSavePath .= $dir_add."/";

				$newName = $strFileName;
			}
			else
			{
				$strFileExt = ($bSkipExt == true? '' : strrchr($strFileName, "."));
				while(true)
				{
					$newName = md5(uniqid(mt_rand(), true)).$strFileExt;
					if(substr($strSavePath, -1, 1) <> "/")
						$strSavePath .= "/".substr($newName, 0, 3);
					else
						$strSavePath .= substr($newName, 0, 3)."/";

					if(!$io->FileExists($_SERVER["DOCUMENT_ROOT"]."/".$upload_dir."/".$strSavePath."/".$newName))
						break;
				}
			}

			$arFile["SUBDIR"] = $strSavePath;
			$arFile["FILE_NAME"] = $newName;
			$strDirName = $_SERVER["DOCUMENT_ROOT"]."/".$upload_dir."/".$strSavePath."/";
			$strDbFileNameX = $strDirName.$newName;
			$strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);

			CheckDirPath($strDirName);

			if(is_set($arFile, "content"))
			{
				$f = fopen($strPhysicalFileNameX, "ab");
				if(!$f)
					return false;
				if(!fwrite($f, $arFile["content"]))
					return false;
				fclose($f);
			}
			elseif(
				!copy($arFile["tmp_name"], $strPhysicalFileNameX)
				&& !move_uploaded_file($arFile["tmp_name"], $strPhysicalFileNameX)
			)
			{
				CFile::DoDelete($arFile["old_file"]);
				return false;
			}

			if(isset($arFile["old_file"]))
				CFile::DoDelete($arFile["old_file"]);

			@chmod($strPhysicalFileNameX, BX_FILE_PERMISSIONS);

			$imgArray = CFile::GetImageSize($strDbFileNameX);

			if(is_array($imgArray))
			{
				$arFile["WIDTH"] = $imgArray[0];
				$arFile["HEIGHT"] = $imgArray[1];
			}
			else
			{
				$arFile["WIDTH"] = 0;
				$arFile["HEIGHT"] = 0;
			}
		} //if(!$bExternalStorage)


		/****************************** QUOTA ******************************/
		if (COption::GetOptionInt("main", "disk_space") > 0)
		{
			CDiskQuota::updateDiskQuota("file", $arFile["size"], "insert");
		}
		/****************************** QUOTA ******************************/

		$NEW_IMAGE_ID = CFile::DoInsert(array(
			"HEIGHT" => $arFile["HEIGHT"],
			"WIDTH" => $arFile["WIDTH"],
			"FILE_SIZE" => $arFile["size"],
			"CONTENT_TYPE" => $arFile["type"],
			"SUBDIR" => $arFile["SUBDIR"],
			"FILE_NAME" => $arFile["FILE_NAME"],
			"MODULE_ID" => $arFile["MODULE_ID"],
			"ORIGINAL_NAME" => $arFile["ORIGINAL_NAME"],
			"DESCRIPTION" => isset($arFile["description"])? $arFile["description"]: '',
			"HANDLER_ID" => isset($arFile["HANDLER_ID"])? $arFile["HANDLER_ID"]: '',
		));

		CFile::CleanCache($NEW_IMAGE_ID);
		return $NEW_IMAGE_ID;
	}
コード例 #24
0
ファイル: file.php プロジェクト: k-kalashnikov/geekcon_new
 function SaveFile($arFile, $strSavePath, $bForceMD5 = false, $bSkipExt = false)
 {
     $strFileName = GetFileName($arFile["name"]);
     /* filename.gif */
     if (isset($arFile["del"]) && $arFile["del"] != '') {
         CFile::DoDelete($arFile["old_file"]);
         if ($strFileName == '') {
             return "NULL";
         }
     }
     if ($arFile["name"] == '') {
         if (isset($arFile["description"]) && intval($arFile["old_file"]) > 0) {
             CFile::UpdateDesc($arFile["old_file"], $arFile["description"]);
         }
         return false;
     }
     if (array_key_exists("content", $arFile)) {
         if (!array_key_exists("size", $arFile)) {
             $arFile["size"] = CUtil::BinStrlen($arFile["content"]);
         }
     } else {
         $arFile["size"] = filesize($arFile["tmp_name"]);
     }
     $arFile["ORIGINAL_NAME"] = $strFileName;
     $io = CBXVirtualIo::GetInstance();
     if (self::validateFile($strFileName, $arFile, $bForceMD5) !== "") {
         return false;
     }
     $upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
     if ($arFile["type"] == "image/pjpeg" || $arFile["type"] == "image/jpg") {
         $arFile["type"] = "image/jpeg";
     }
     //.jpe is not image type on many systems
     if (strtolower(GetFileExtension($strFileName)) == "jpe") {
         $strFileName = substr($strFileName, 0, -4) . ".jpg";
     }
     $bExternalStorage = false;
     foreach (GetModuleEvents("main", "OnFileSave", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFile, $strFileName, $strSavePath, $bForceMD5, $bSkipExt))) {
             $bExternalStorage = true;
             break;
         }
     }
     if (!$bExternalStorage) {
         $newName = '';
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             $dir_add = '';
             $i = 0;
             while (true) {
                 $dir_add = substr(md5(uniqid(mt_rand(), true)), 0, 3);
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
                     break;
                 }
                 if ($i >= 25) {
                     $j = 0;
                     while (true) {
                         $dir_add = substr(md5(mt_rand()), 0, 3) . "/" . substr(md5(mt_rand()), 0, 3);
                         if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $dir_add . "/" . $strFileName)) {
                             break;
                         }
                         if ($j >= 25) {
                             $dir_add = substr(md5(mt_rand()), 0, 3) . "/" . md5(mt_rand());
                             break;
                         }
                         $j++;
                     }
                     break;
                 }
                 $i++;
             }
             if (substr($strSavePath, -1, 1) != "/") {
                 $strSavePath .= "/" . $dir_add;
             } else {
                 $strSavePath .= $dir_add . "/";
             }
             $newName = $strFileName;
         } else {
             $strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, ".");
             while (true) {
                 $newName = md5(uniqid(mt_rand(), true)) . $strFileExt;
                 if (substr($strSavePath, -1, 1) != "/") {
                     $strSavePath .= "/" . substr($newName, 0, 3);
                 } else {
                     $strSavePath .= substr($newName, 0, 3) . "/";
                 }
                 if (!$io->FileExists($_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/" . $newName)) {
                     break;
                 }
             }
         }
         $arFile["SUBDIR"] = $strSavePath;
         $arFile["FILE_NAME"] = $newName;
         $strDirName = $_SERVER["DOCUMENT_ROOT"] . "/" . $upload_dir . "/" . $strSavePath . "/";
         $strDbFileNameX = $strDirName . $newName;
         $strPhysicalFileNameX = $io->GetPhysicalName($strDbFileNameX);
         CheckDirPath($strDirName);
         if (is_set($arFile, "content")) {
             $f = fopen($strPhysicalFileNameX, "ab");
             if (!$f) {
                 return false;
             }
             if (!fwrite($f, $arFile["content"])) {
                 return false;
             }
             fclose($f);
         } elseif (!copy($arFile["tmp_name"], $strPhysicalFileNameX) && !move_uploaded_file($arFile["tmp_name"], $strPhysicalFileNameX)) {
             CFile::DoDelete($arFile["old_file"]);
             return false;
         }
         if (isset($arFile["old_file"])) {
             CFile::DoDelete($arFile["old_file"]);
         }
         @chmod($strPhysicalFileNameX, BX_FILE_PERMISSIONS);
         $imgArray = CFile::GetImageSize($strDbFileNameX);
         if (is_array($imgArray)) {
             $arFile["WIDTH"] = $imgArray[0];
             $arFile["HEIGHT"] = $imgArray[1];
         } else {
             $arFile["WIDTH"] = 0;
             $arFile["HEIGHT"] = 0;
         }
     }
     /****************************** QUOTA ******************************/
     if (COption::GetOptionInt("main", "disk_space") > 0) {
         CDiskQuota::updateDiskQuota("file", $arFile["size"], "insert");
     }
     /****************************** QUOTA ******************************/
     $NEW_IMAGE_ID = CFile::DoInsert(array("HEIGHT" => $arFile["HEIGHT"], "WIDTH" => $arFile["WIDTH"], "FILE_SIZE" => $arFile["size"], "CONTENT_TYPE" => $arFile["type"], "SUBDIR" => $arFile["SUBDIR"], "FILE_NAME" => $arFile["FILE_NAME"], "MODULE_ID" => $arFile["MODULE_ID"], "ORIGINAL_NAME" => $arFile["ORIGINAL_NAME"], "DESCRIPTION" => isset($arFile["description"]) ? $arFile["description"] : '', "HANDLER_ID" => isset($arFile["HANDLER_ID"]) ? $arFile["HANDLER_ID"] : ''));
     CFile::CleanCache($NEW_IMAGE_ID);
     return $NEW_IMAGE_ID;
 }
コード例 #25
0
ファイル: discount.php プロジェクト: rasuldev/torino
 public function CheckFields($ACTION, &$arFields, $ID = 0)
 {
     global $APPLICATION, $DB, $USER;
     $boolResult = true;
     $arMsg = array();
     $ACTION = strtoupper($ACTION);
     if ($ACTION != 'UPDATE' && $ACTION != 'ADD') {
         return false;
     }
     if (!is_array($arFields)) {
         return false;
     }
     $boolValueType = false;
     $boolValue = false;
     $arCurrent = array('VALUE' => 0, 'VALUE_TYPE' => '');
     $clearFields = array('ID', '~ID', 'UNPACK', '~UNPACK', '~CONDITIONS', 'USE_COUPONS', '~USE_COUPONS', 'HANDLERS', '~HANDLERS', '~TYPE', '~VERSION', 'TIMESTAMP_X', 'DATE_CREATE', '~DATE_CREATE', '~MODIFIED_BY', '~CREATED_BY');
     if ($ACTION == 'UPDATE') {
         $clearFields[] = 'CREATED_BY';
     }
     $arFields = array_filter($arFields, 'CCatalogDiscount::clearFields');
     foreach ($clearFields as &$fieldName) {
         if (isset($arFields[$fieldName])) {
             unset($arFields[$fieldName]);
         }
     }
     unset($fieldName, $clearFields);
     $arFields['TYPE'] = self::ENTITY_ID;
     $arFields['VERSION'] = self::CURRENT_FORMAT;
     if ($ACTION == 'ADD') {
         $boolValueType = true;
         $boolValue = true;
         $defaultValues = array('ACTIVE' => 'Y', 'RENEWAL' => 'N', 'MAX_USES' => 0, 'COUNT_USES' => 0, 'SORT' => 100, 'MAX_DISCOUNT' => 0, 'VALUE_TYPE' => self::TYPE_PERCENT, 'MIN_ORDER_SUM' => 0, 'PRIORITY' => 1, 'LAST_DISCOUNT' => 'Y');
         $arFields = array_merge($defaultValues, $arFields);
         unset($defaultValues);
         if (!isset($arFields['SITE_ID'])) {
             $boolResult = false;
             $arMsg[] = array('id' => 'SITE_ID', 'text' => Loc::getMessage("KGD_EMPTY_SITE"));
         }
         if (!isset($arFields['CURRENCY'])) {
             $boolResult = false;
             $arMsg[] = array('id' => 'CURRENCY', 'text' => Loc::getMessage('KGD_EMPTY_CURRENCY'));
         }
         if (!isset($arFields['NAME'])) {
             $boolResult = false;
             $arMsg[] = array('id' => 'NAME', 'text' => Loc::getMessage('KGD_EMPTY_NAME'));
         }
         if (!isset($arFields['VALUE'])) {
             $boolResult = false;
             $arMsg[] = array('id' => 'VALUE', 'text' => Loc::getMessage('BT_MOD_CATALOG_DISC_ERR_BAD_VALUE'));
         }
         if (!isset($arFields['CONDITIONS'])) {
             $boolResult = false;
             $arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_CATALOG_DISC_ERR_EMPTY_CONDITIONS'));
         }
         $arFields['USE_COUPONS'] = 'N';
     }
     if ($ACTION == 'UPDATE') {
         $ID = (int) $ID;
         if ($ID <= 0) {
             $boolResult = false;
             $arMsg[] = array('id' => 'ID', 'text' => Loc::getMessage('BT_MOD_CATALOG_DISC_ERR_BAD_ID', array('#ID#', $ID)));
         } else {
             $boolValueType = isset($arFields['VALUE_TYPE']);
             $boolValue = isset($arFields['VALUE']);
             if ($boolValueType != $boolValue) {
                 $rsDiscounts = CCatalogDiscount::GetList(array(), array('ID' => $ID), false, false, array('ID', 'VALUE_TYPE', 'VALUE'));
                 if ($arCurrent = $rsDiscounts->Fetch()) {
                     $arCurrent['VALUE'] = doubleval($arCurrent['VALUE']);
                 } else {
                     $boolResult = false;
                     $arMsg[] = array('id' => 'ID', 'text' => Loc::getMessage('BT_MOD_CATALOG_DISC_ERR_BAD_ID', array('#ID#', $ID)));
                 }
             }
         }
     }
     if ($boolResult) {
         if (isset($arFields['SITE_ID'])) {
             if (empty($arFields['SITE_ID'])) {
                 $boolResult = false;
                 $arMsg[] = array('id' => 'SITE_ID', 'text' => Loc::getMessage('KGD_EMPTY_SITE'));
             }
         }
         if (isset($arFields['CURRENCY'])) {
             if (empty($arFields['CURRENCY'])) {
                 $boolResult = false;
                 $arMsg[] = array('id' => 'CURRENCY', 'text' => Loc::getMessage('KGD_EMPTY_CURRENCY'));
             }
         }
         if (isset($arFields['NAME'])) {
             $arFields['NAME'] = trim($arFields['NAME']);
             if ($arFields['NAME'] === '') {
                 $boolResult = false;
                 $arMsg[] = array('id' => 'NAME', 'text' => Loc::getMessage('KGD_EMPTY_NAME'));
             }
         }
         if (isset($arFields['ACTIVE'])) {
             $arFields['ACTIVE'] = $arFields['ACTIVE'] != 'N' ? 'Y' : 'N';
         }
         if (isset($arFields['ACTIVE_FROM'])) {
             if (!$DB->IsDate($arFields['ACTIVE_FROM'], false, LANGUAGE_ID, 'FULL')) {
                 $arFields['ACTIVE_FROM'] = false;
             }
         }
         if (isset($arFields['ACTIVE_TO'])) {
             if (!$DB->IsDate($arFields['ACTIVE_TO'], false, LANGUAGE_ID, 'FULL')) {
                 $arFields['ACTIVE_TO'] = false;
             }
         }
         if (isset($arFields['RENEWAL'])) {
             $arFields['RENEWAL'] = $arFields['RENEWAL'] == 'Y' ? 'Y' : 'N';
         }
         if (isset($arFields['MAX_USES'])) {
             $arFields['MAX_USES'] = (int) $arFields['MAX_USES'];
             if ($arFields['MAX_USES'] < 0) {
                 $arFields['MAX_USES'] = 0;
             }
         }
         if (isset($arFields['COUNT_USES'])) {
             $arFields['COUNT_USES'] = (int) $arFields['COUNT_USES'];
             if ($arFields['COUNT_USES'] < 0) {
                 $arFields['COUNT_USES'] = 0;
             }
         }
         if (isset($arFields['CATALOG_COUPONS'])) {
             if (empty($arFields['CATALOG_COUPONS']) && !is_array($arFields['CATALOG_COUPONS'])) {
                 unset($arFields['CATALOG_COUPONS']);
             }
         }
         if (isset($arFields['SORT'])) {
             $arFields['SORT'] = (int) $arFields['SORT'];
             if ($arFields['SORT'] <= 0) {
                 $arFields['SORT'] = 100;
             }
         }
         if (isset($arFields['MAX_DISCOUNT'])) {
             $arFields['MAX_DISCOUNT'] = str_replace(',', '.', $arFields['MAX_DISCOUNT']);
             $arFields['MAX_DISCOUNT'] = doubleval($arFields['MAX_DISCOUNT']);
             if ($arFields['MAX_DISCOUNT'] < 0) {
                 $arFields['MAX_DISCOUNT'] = 0;
             }
         }
         if ($boolValueType) {
             if (!in_array($arFields['VALUE_TYPE'], CCatalogDiscount::GetDiscountTypes())) {
                 $arFields['VALUE_TYPE'] = self::TYPE_PERCENT;
             }
         }
         if ($boolValue) {
             $arFields['VALUE'] = str_replace(',', '.', $arFields['VALUE']);
             $arFields['VALUE'] = doubleval($arFields['VALUE']);
             if ($arFields['VALUE'] <= 0) {
                 $boolResult = false;
                 $arMsg[] = array('id' => 'VALUE', 'text' => Loc::getMessage('BT_MOD_CATALOG_DISC_ERR_BAD_VALUE'));
             }
         }
         if ($ACTION == 'UPDATE') {
             if ($boolValue != $boolValueType) {
                 if (!$boolValue) {
                     $arFields['VALUE'] = $arCurrent['VALUE'];
                     $boolValue = true;
                 }
                 if (!$boolValueType) {
                     $arFields['VALUE_TYPE'] = $arCurrent['VALUE_TYPE'];
                     $boolValueType = true;
                 }
             }
         }
         if ($boolValue && $boolValueType) {
             if ($arFields['VALUE_TYPE'] == self::TYPE_PERCENT && $arFields['VALUE'] > 100) {
                 $boolResult = false;
                 $arMsg[] = array('id' => 'VALUE', 'text' => Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_BAD_VALUE"));
             }
         }
         if (isset($arFields['MIN_ORDER_SUM'])) {
             $arFields['MIN_ORDER_SUM'] = str_replace(',', '.', $arFields['MIN_ORDER_SUM']);
             $arFields['MIN_ORDER_SUM'] = doubleval($arFields['MIN_ORDER_SUM']);
         }
         if (isset($arFields['PRIORITY'])) {
             $arFields['PRIORITY'] = (int) $arFields['PRIORITY'];
             if (0 >= $arFields['PRIORITY']) {
                 $arFields['PRIORITY'] = 1;
             }
         }
         if (isset($arFields['LAST_DISCOUNT'])) {
             $arFields['LAST_DISCOUNT'] = $arFields['LAST_DISCOUNT'] != 'N' ? 'Y' : 'N';
         }
     }
     if ($boolResult) {
         if (isset($arFields['CONDITIONS'])) {
             if (empty($arFields['CONDITIONS'])) {
                 $boolResult = false;
                 $arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_EMPTY_CONDITIONS"));
             } else {
                 $usedHandlers = array();
                 $boolCond = true;
                 $strEval = '';
                 if (!is_array($arFields['CONDITIONS'])) {
                     if (!CheckSerializedData($arFields['CONDITIONS'])) {
                         $boolCond = false;
                         $boolResult = false;
                         $arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_BAD_CONDITIONS"));
                     } else {
                         $arFields['CONDITIONS'] = unserialize($arFields['CONDITIONS']);
                         if (empty($arFields['CONDITIONS']) || !is_array($arFields['CONDITIONS'])) {
                             $boolCond = false;
                             $boolResult = false;
                             $arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_BAD_CONDITIONS"));
                         }
                     }
                 }
                 if ($boolCond) {
                     $obCond = new CCatalogCondTree();
                     $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_CATALOG, array());
                     if (!$boolCond) {
                         return false;
                     }
                     $strEval = $obCond->Generate($arFields['CONDITIONS'], array('FIELD' => '$arProduct'));
                     if (empty($strEval) || 'false' == $strEval) {
                         $boolCond = false;
                         $boolResult = false;
                         $arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage("BT_MOD_CATALOG_DISC_ERR_BAD_CONDITIONS"));
                     } else {
                         $usedHandlers = $obCond->GetConditionHandlers();
                     }
                 }
                 if ($boolCond) {
                     $arFields['UNPACK'] = $strEval;
                     $arFields['CONDITIONS'] = serialize($arFields['CONDITIONS']);
                     if (!empty($usedHandlers)) {
                         $arFields['HANDLERS'] = $usedHandlers;
                     }
                     if (strtolower($DB->type) == 'mysql') {
                         if (64000 < CUtil::BinStrlen($arFields['UNPACK']) || 64000 < CUtil::BinStrlen($arFields['CONDITIONS'])) {
                             $boolResult = false;
                             $arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_CATALOG_DISC_ERR_CONDITIONS_TOO_LONG'));
                             unset($arFields['UNPACK']);
                             $arFields['CONDITIONS'] = unserialize($arFields['CONDITIONS']);
                         }
                     }
                 }
             }
         }
     }
     $intUserID = 0;
     $boolUserExist = CCatalog::IsUserExists();
     if ($boolUserExist) {
         $intUserID = (int) $USER->GetID();
     }
     $strDateFunction = $DB->GetNowFunction();
     $arFields['~TIMESTAMP_X'] = $strDateFunction;
     if ($boolUserExist) {
         if (!isset($arFields['MODIFIED_BY']) || (int) $arFields["MODIFIED_BY"] <= 0) {
             $arFields["MODIFIED_BY"] = $intUserID;
         }
     }
     if ($ACTION == 'ADD') {
         $arFields['~DATE_CREATE'] = $strDateFunction;
         if ($boolUserExist) {
             if (!isset($arFields['CREATED_BY']) || (int) $arFields["CREATED_BY"] <= 0) {
                 $arFields["CREATED_BY"] = $intUserID;
             }
         }
     }
     if (!$boolResult) {
         $obError = new CAdminException($arMsg);
         $APPLICATION->ResetException();
         $APPLICATION->ThrowException($obError);
     }
     return $boolResult;
 }
コード例 #26
0
 function UploadPart($arBucket, &$NS, $data)
 {
     global $APPLICATION;
     $filePath = '/' . trim($NS["filePath"], '/');
     if ($arBucket["PREFIX"]) {
         if (substr($filePath, 0, strlen($arBucket["PREFIX"]) + 2) != "/" . $arBucket["PREFIX"] . "/") {
             $filePath = "/" . $arBucket["PREFIX"] . $filePath;
         }
     }
     $filePathU = CCloudUtil::URLEncode($filePath, "UTF-8");
     $response = $this->SendRequest($arBucket["SETTINGS"]["ACCESS_KEY"], $arBucket["SETTINGS"]["SECRET_KEY"], 'PUT', $arBucket["BUCKET"], $filePathU . '?upload_id=' . urlencode($NS["upload_id"]), '', '', array("Content-Range" => "bytes */" . $NS["fileSize"]));
     $data_len = CUtil::BinStrlen($data);
     $response = $this->SendRequest($arBucket["SETTINGS"]["ACCESS_KEY"], $arBucket["SETTINGS"]["SECRET_KEY"], 'PUT', $arBucket["BUCKET"], $filePathU . '?upload_id=' . urlencode($NS["upload_id"]), '', $data, array("Content-Range" => "bytes " . $NS["filePos"] . "-" . ($NS["filePos"] + $data_len - 1) . "/" . $NS["fileSize"]));
     if ($this->status == 308 && is_array($this->headers) && preg_match("/^bytes=(\\d+)-(\\d+)\$/", $this->headers["Range"], $match)) {
         $APPLICATION->ResetException();
         $NS["filePos"] = $match[2] + 1;
         return true;
     } elseif ($this->status == 200) {
         return true;
     } else {
         return false;
     }
 }
コード例 #27
0
 public function getPayload()
 {
     $sJSONPayload = str_replace('"' . self::APPLE_RESERVED_NAMESPACE . '":[]', '"' . self::APPLE_RESERVED_NAMESPACE . '":{}', $this->_MakeJson($this->_getPayload(), "", false));
     $nJSONPayloadLen = CUtil::BinStrlen($sJSONPayload);
     if ($nJSONPayloadLen > self::PAYLOAD_MAXIMUM_SIZE) {
         if ($this->_bAutoAdjustLongPayload) {
             $nMaxTextLen = $nTextLen = CUtil::BinStrlen($this->_sText) - ($nJSONPayloadLen - self::PAYLOAD_MAXIMUM_SIZE);
             if ($nMaxTextLen > 0) {
                 while (CUtil::BinStrlen($this->_sText = CUtil::BinSubstr($this->_sText, 0, --$nTextLen)) > $nMaxTextLen) {
                 }
                 return $this->getPayload();
             } else {
                 throw new Exception("JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " . self::PAYLOAD_MAXIMUM_SIZE . " bytes. The message text can not be auto-adjusted.");
             }
         } else {
             throw new Exception("JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " . self::PAYLOAD_MAXIMUM_SIZE . " bytes");
         }
     }
     return $sJSONPayload;
 }