예제 #1
0
    function NewMediaObject($params)
    {
        global $USER, $DB;
        $blogId = IntVal(CBlogMetaWeblog::DecodeParams($params[0]["#"]["value"][0]["#"]));
        $user = CBlogMetaWeblog::DecodeParams($params[1]["#"]["value"][0]["#"]);
        $password = CBlogMetaWeblog::DecodeParams($params[2]["#"]["value"][0]["#"]);
        $arImage = $params[3]["#"]["value"][0]["#"]["struct"][0]["#"]["member"];
        foreach ($arImage as $val) {
            $arImageInfo[$val["#"]["name"][0]["#"]] = CBlogMetaWeblog::DecodeParams($val["#"]["value"][0]["#"]);
        }
        if (CBlogMetaWeblog::Authorize($user, $password)) {
            $result = '';
            $userId = $USER->GetID();
            if (IntVal($blogId) > 0) {
                $dbBlog = CBlog::GetList(array(), array("GROUP_SITE_ID" => SITE_ID, "ACTIVE" => "Y", "ID" => $blogId), false, false, array("ID", "URL", "NAME"));
                if ($arBlog = $dbBlog->GetNext()) {
                    $filename = trim(str_replace("\\", "/", trim($arImageInfo["name"])), "/");
                    $DIR_NAME = CTempFile::GetDirectoryName(12);
                    $FILE_NAME = rel2abs($DIR_NAME, "/" . $filename);
                    if (strlen($FILE_NAME) > 1 && $FILE_NAME === "/" . $filename) {
                        $ABS_FILE_NAME = $DIR_NAME . $FILE_NAME;
                    } else {
                        $ABS_FILE_NAME = "";
                    }
                    CheckDirPath($DIR_NAME);
                    if (strlen($ABS_FILE_NAME) > 0 && ($fp = fopen($ABS_FILE_NAME, "ab"))) {
                        $result = fwrite($fp, $arImageInfo["bits"]);
                        if ($result !== (function_exists("mb_strlen") ? mb_strlen($arImageInfo["bits"], 'latin1') : strlen($arImageInfo["bits"]))) {
                            return '<fault>
									<value>
										<struct>
											<member>
												<name>faultCode</name>
												<value><int>3</int></value>
												</member>
											<member>
												<name>faultString</name>
												<value><string>Error on saving media object</string></value>
												</member>
											</struct>
										</value>
									</fault>';
                        }
                        fclose($fp);
                    } else {
                        return '<fault>
								<value>
									<struct>
										<member>
											<name>faultCode</name>
											<value><int>3</int></value>
											</member>
										<member>
											<name>faultString</name>
											<value><string>Error on saving media object</string></value>
											</member>
										</struct>
									</value>
								</fault>';
                    }
                    $arFields = array("BLOG_ID" => $arBlog["ID"], "USER_ID" => $userId, "=TIMESTAMP_X" => $DB->GetNowFunction(), "FILE_ID" => array("name" => $arImageInfo["name"], "tmp_name" => $ABS_FILE_NAME, "MODULE_ID" => "blog", "type" => $arImageInfo["type"]));
                    $imageId = CBlogImage::Add($arFields);
                    $arImg = CBlogImage::GetByID($imageId);
                    $arFile = CFile::GetFileArray($arImg["FILE_ID"]);
                    $path = $arFile["SRC"];
                    $dbSite = CSite::GetByID(SITE_ID);
                    $arSite = $dbSite->Fetch();
                    $serverName = htmlspecialcharsEx($arSite["SERVER_NAME"]);
                    if (strlen($serverName) <= 0) {
                        if (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0) {
                            $serverName = SITE_SERVER_NAME;
                        } else {
                            $serverName = COption::GetOptionString("main", "server_name", "www.bitrixsoft.com");
                        }
                    }
                    if (strlen($path) > 0) {
                        return '<params>
							<param>
								<value>
									<struct>
									<member>
									<name>url</name>
									<value>
									<string>' . CHTTP::URN2URI($path, $serverName) . '</string>
									</value>
									</member>
									</struct>
								</value>
							</param>
						</params>';
                    }
                }
            }
            return '<fault>
				<value>
					<struct>
						<member>
							<name>faultCode</name>
							<value><int>3</int></value>
							</member>
						<member>
							<name>faultString</name>
							<value><string>Error on saving media object</string></value>
							</member>
						</struct>
					</value>
				</fault>';
        } else {
            return '<fault>
				<value>
					<struct>
						<member>
							<name>faultCode</name>
							<value><int>3</int></value>
							</member>
						<member>
							<name>faultString</name>
							<value><string>' . $arAuthResult["MESSAGE"] . '</string></value>
							</member>
						</struct>
					</value>
				</fault>';
        }
    }
예제 #2
0
 $arFields = array('TITLE' => $_POST['POST_TITLE'], 'DETAIL_TEXT' => $_POST['POST_MESSAGE'], 'DATE_PUBLISH' => $DATE_PUBLISH, 'PUBLISH_STATUS' => $_POST['PUBLISH_STATUS'], 'ENABLE_TRACKBACK' => $_POST['ENABLE_TRACKBACK'], 'CATEGORY_ID' => $CATEGORY_ID);
 if ($_POST['blog_perms'] == 1) {
     if ($_POST['perms_p'][1] > BLOG_PERMS_READ) {
         $_POST['perms_p'][1] = BLOG_PERMS_READ;
     }
     if ($_POST['perms_c'][1] > BLOG_PERMS_READ) {
         $_POST['perms_c'][1] = BLOG_PERMS_READ;
     }
     $arFields['PERMS_POST'] = $_POST['perms_p'];
     $arFields['PERMS_COMMENT'] = $_POST['perms_c'];
 } else {
     $arFields['PERMS_POST'] = array();
     $arFields['PERMS_COMMENT'] = array();
 }
 while (is_array($_POST['IMAGE_ID_title']) && (list($imgID, $imgTitle) = each($_POST['IMAGE_ID_title']))) {
     $aImg = CBlogImage::GetByID($imgID);
     if ($aImg['BLOG_ID'] == $BLOG_ID && $aImg['POST_ID'] == $ID) {
         if ($_POST['IMAGE_ID_del'][$imgID]) {
             CBlogImage::Delete($imgID);
             $arFields['DETAIL_TEXT'] = str_replace("[IMG ID={$imgID}]", "", $arFields['DETAIL_TEXT']);
         } else {
             CBlogImage::Update($imgID, array("TITLE" => $imgTitle));
         }
     }
 }
 if ($ID > 0) {
     // Проверяем: новая запись или изменение старой
     $newID = CBlogPost::Update($ID, $arFields);
 } else {
     $arFields['=DATE_CREATE'] = $DB->GetNowFunction();
     $arFields['AUTHOR_ID'] = $USER_ID;
예제 #3
0
 function convert_blog_image($p1 = "", $imageId = "", $p2 = "", $type = "html", $serverName = "")
 {
     $imageId = IntVal($imageId);
     if ($imageId <= 0) {
         return;
     }
     $res = "";
     if (IntVal($this->arImages[$imageId]) > 0) {
         if ($f = CBlogImage::GetByID($imageId)) {
             if ($db_img_arr = CFile::GetFileArray($this->arImages[$imageId])) {
                 $strImage = $db_img_arr["SRC"];
                 $strPar = "";
                 preg_match("/width\\=([0-9]+)/is" . BX_UTF_PCRE_MODIFIER, $p1, $width);
                 preg_match("/height\\=([0-9]+)/is" . BX_UTF_PCRE_MODIFIER, $p1, $height);
                 $width = intval($width[1]);
                 $height = intval($height[1]);
                 if ($width <= 0) {
                     preg_match("/width\\=([0-9]+)/is" . BX_UTF_PCRE_MODIFIER, $p2, $width);
                     $width = intval($width[1]);
                 }
                 if ($height <= 0) {
                     preg_match("/height\\=([0-9]+)/is" . BX_UTF_PCRE_MODIFIER, $p2, $height);
                     $height = intval($height[1]);
                 }
                 if (IntVal($width) <= 0) {
                     $width = $db_img_arr["WIDTH"];
                 }
                 if (IntVal($height) <= 0) {
                     $height = $db_img_arr["HEIGHT"];
                 }
                 if ($width > $this->imageWidth || $height > $this->imageHeight) {
                     $arFileTmp = CFile::ResizeImageGet($db_img_arr, array("width" => $this->imageWidth, "height" => $this->imageHeight), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                     if (substr($arFileTmp["src"], 0, 1) == "/") {
                         $strImage = $serverName . $arFileTmp["src"];
                     } else {
                         $strImage = $arFileTmp["src"];
                     }
                     $width = $arFileTmp["width"];
                     $height = $arFileTmp["height"];
                 }
                 $strPar = ' width="' . $width . '" height="' . $height . '"';
                 $res = '<img src="' . $strImage . '" title="' . $f["TITLE"] . '" border="0"' . $strPar . '/>';
             }
         }
     }
     return $res;
 }
예제 #4
0
 function Delete($ID)
 {
     global $DB;
     $ID = IntVal($ID);
     unset($GLOBALS["BLOG_IMAGE"]["BLOG_IMAGE_CACHE_" . $ID]);
     if ($res = CBlogImage::GetByID($ID)) {
         CFile::Delete($res['FILE_ID']);
         return $DB->Query("DELETE FROM b_blog_image WHERE ID = " . $ID, true);
     }
     return false;
 }
예제 #5
0
	function convert_blog_image($p1 = "", $imageId = "", $p2 = "", $type = "html", $serverName="")
	{
		$imageId = IntVal($imageId);
		if($imageId <= 0)
			return;

		$res = "";
		if(IntVal($this->arImages[$imageId]) > 0)
		{
			$this->showedImages[] = $imageId;
			if($f = CBlogImage::GetByID($imageId))
			{
				if(COption::GetOptionString("blog", "use_image_perm", "N") == "N")
				{
					if($db_img_arr = CFile::GetFileArray($this->arImages[$imageId]))
					{
						if(substr($db_img_arr["SRC"], 0, 1) == "/")
							$strImage = $this->serverName.$db_img_arr["SRC"];
						else
							$strImage = $db_img_arr["SRC"];
						$sourceImage = $strImage;

						$strPar = "";
						preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $width);
						preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $height);
						$width = intval($width[1]);
						$height = intval($height[1]);

						if($width <= 0)
						{
							preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $width);
							$width = intval($width[1]);
						}
						if($height <= 0)
						{
							preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $height);
							$height = intval($height[1]);
						}

						if(IntVal($width) <= 0)
							$width = $db_img_arr["WIDTH"];
						if(IntVal($height) <= 0)
							$height= $db_img_arr["HEIGHT"];

						if($width > $this->imageWidth || $height > $this->imageHeight)
						{
							$arFileTmp = CFile::ResizeImageGet(
								$db_img_arr,
								array("width" => $this->imageWidth, "height" => $this->imageHeight),
								BX_RESIZE_IMAGE_PROPORTIONAL,
								true
							);
							if(substr($arFileTmp["src"], 0, 1) == "/")
								$strImage = $this->serverName.$arFileTmp["src"];
							else
								$strImage = $arFileTmp["src"];
							$width = $arFileTmp["width"];
							$height = $arFileTmp["height"];
						}

						$strPar = ' width="'.$width.'" height="'.$height.'"';
						$strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
						$sourceImage = preg_replace("'(?<!:)/+'s", "/", $sourceImage);

						if(strlen($this->authorName) > 0)
							$strPar .= " data-bx-title=\"".$this->authorName."\"";

						if ($this->isSonetLog)
						{
							$strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
							$res = '[IMG]'.$strImage.'[/IMG]';
						}
						else
						{

							if($type == "mail")
								$res = htmlspecialcharsbx($f["TITLE"])." (IMAGE: ".$strImage." )";
							else
								$res = '<img src="'.$strImage.'" title="" alt="'.htmlspecialcharsbx($f["TITLE"]).'" border="0"'.$strPar.' data-bx-image="'.$sourceImage.'" />';
						}
					}
				}
				else
				{
					preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $width);
					preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $height);
					$width = intval($width[1]);
					$height = intval($height[1]);

					if($width <= 0)
					{
						preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $width);
						$width = intval($width[1]);
					}
					if($height <= 0)
					{
						preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $height);
						$height = intval($height[1]);
					}

					if(IntVal($width) <= 0)
						$width = $this->imageWidth;
					if(IntVal($height) <= 0)
						$height = $this->imageHeight;

					if($width > $this->imageWidth)
						$width = $this->imageWidth;
					if($height > $this->imageHeight)
						$height = $this->imageHeight;

					$strImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId."&width=".$width."&height=".$height;
					$sourceImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId;

					$db_img_arr = CFile::GetFileArray($this->arImages[$imageId]);

					CFile::ScaleImage($db_img_arr["WIDTH"], $db_img_arr["HEIGHT"], Array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);

					if ($this->isSonetLog)
					{
						$strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
						$res = '[IMG]'.$strImage.'[/IMG]';
					}
					else
					{
						if($type == "mail")
							$res = htmlspecialcharsbx($f["TITLE"])." (IMAGE: ".$strImage." )";
						else
						{
							$strPar = ' width="'.$arDestinationSize["width"].'" height="'.$arDestinationSize["height"].'"';
							if(strlen($this->authorName) > 0)
								$strPar .= " data-bx-title=\"".$this->authorName."\"";

							$res = '<img src="'.$strImage.'" title="" alt="'.htmlspecialcharsbx($f["TITLE"]).'" border="0" data-bx-image="'.$sourceImage.'"'.$strPar.' />';
							if(!empty($this->blogImageSizeEvents))
							{
								foreach($this->blogImageSizeEvents as $arEvent)
									ExecuteModuleEventEx($arEvent, Array(&$res, $strImage, $db_img_arr, $f, $arDestinationSize));
							}
						}
					}
				}
				return $res;
			}
		}
		return $res;
	}
예제 #6
0
}
$arParams["WIDTH"] = isset($_REQUEST['width']) && intval($_REQUEST['width']) > 0 ? intval($_REQUEST['width']) : 0;
$arParams["HEIGHT"] = isset($_REQUEST['height']) && intval($_REQUEST['height']) > 0 ? intval($_REQUEST['height']) : 0;
$arParams["FILE_ID"] = IntVal($_REQUEST["fid"]);
$arParams["BP_FILE_ID"] = IntVal($_REQUEST["bp_fid"]);
$arParams["PERMISSION"] = false;
$arParams["QUALITY"] = isset($_REQUEST['mobile']) && $_REQUEST["mobile"] == "y" ? "50" : false;
$arResult = array();
$arResult["MESSAGE"] = array();
$arResult["FILE"] = array();
$arResult["POST"] = array();
$arResult["FILE_INFO"] = array();
$user_id = IntVal($USER->GetID());
$arError = array();
if (intVal($arParams["FILE_ID"]) > 0) {
    if ($res = CBlogImage::GetByID($arParams["FILE_ID"])) {
        $arResult["FILE_INFO"] = $res;
        $arResult["FILE"] = CFile::GetFileArray($arResult["FILE_INFO"]["FILE_ID"]);
    }
} elseif (intVal($arParams["BP_FILE_ID"]) > 0) {
    $arResult["FILE"] = CFile::GetFileArray(intVal($arParams['BP_FILE_ID']));
    if (!empty($arResult["FILE"])) {
        $dbPost = CBlogPost::GetList(array(), array('UF_BLOG_POST_DOC' => intVal($arParams['BP_FILE_ID'])));
        if ($dbPost && ($arPost = $dbPost->Fetch())) {
            $arResult["FILE_INFO"] = array('POST_ID' => $arPost['ID'], 'BLOG_ID' => $arPost['BLOG_ID']);
        } else {
            $dbPost = CBlogComment::GetList(array(), array('UF_BLOG_COMMENT_DOC' => intVal($arParams['BP_FILE_ID'])));
            if ($dbPost && ($arPost = $dbPost->Fetch())) {
                $arResult["FILE_INFO"] = array('POST_ID' => $arPost['POST_ID'], 'BLOG_ID' => $arPost['BLOG_ID']);
            }
        }