02-04-26, 09:31 AM
تعديل المشاركة رقم 13 :
ملاحظة:
----------------------
حل بديل
ملاحظة:
PHP كود :
<?php
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
function GetCacheID()
{
global $db;
$SQL = "INSERT INTO " . TABLE_PREFIX . "y2ksw_imgcache2 (ID) VALUES (0)";
$result = $db->query_write($SQL);
if(!$result) return null;
return $db->insert_id();
}
function AddWatermark($filepath, $extension)
{
$ext = strtolower(ltrim($extension, '.'));
switch($ext) {
case 'jpg':
case 'jpeg':
$image = @imagecreatefromjpeg($filepath);
break;
case 'png':
$image = @imagecreatefrompng($filepath);
break;
case 'gif':
$image = @imagecreatefromgif($filepath);
break;
default:
return;
}
if(!$image) return;
$img_w = imagesx($image);
$img_h = imagesy($image);
$watermark_text = 'alsh3er.com';
$font = 5;
$text_w = imagefontwidth($font) * strlen($watermark_text);
$text_h = imagefontheight($font);
$margin = 10;
$color = imagecolorallocatealpha($image, 255, 255, 255, 60);
imagestring(
$image,
$font,
$img_w - $text_w - $margin,
$img_h - $text_h - $margin,
$watermark_text,
$color
);
switch($ext) {
case 'jpg':
case 'jpeg':
imagejpeg($image, $filepath, 90);
break;
case 'png':
imagepng($image, $filepath);
break;
case 'gif':
imagegif($image, $filepath);
break;
}
imagedestroy($image);
}
function CacheImages($message_body, $old_message, $forum_home)
{
global $context;
// التحقق من وجود المجلد وإنشاؤه إذا غير موجود
if(!is_dir('imgcache/2/'))
{
mkdir('imgcache/2/', 0755, true);
}
// التحقق من صلاحيات الكتابة
if(!is_writable('imgcache/2/'))
{
error_log('imgcache/2/ غير قابل للكتابة');
return $old_message;
}
$n = 0;
$pos_end = -1;
for(;;)
{
$pos_start = strpos(strtolower($message_body), '', $pos_start + 1);
if($pos_end === FALSE) break;
$pos_start += 5;
$pos_end--;
$files[$n]['url'] = substr($message_body, $pos_start, $pos_end - $pos_start + 1);
$n++;
}
if(!$n) return $old_message;
// تجاهل الصور المحفوظة مسبقاً والمواقع المحظورة
for($i = 0; $i < $n; $i++)
{
if(strpos($files[$i]['url'], $forum_home . 'imgcache/2/') !== FALSE)
$files[$i]['url'] = '';
$matar = strtolower($files[$i]['url']);
if(strpos($matar, 'alshafeen.site') !== false || strpos($matar, 'alsh3er.com') !== false)
$files[$i]['url'] = '';
}
// إزالة المكرر
for($i = 0; $i < $n; $i++)
{
$a = $files[$i]['url'];
if($a)
{
for($j = $i + 1; $j < $n; $j++)
{
if($files[$j]['url'] == $a)
$files[$j]['url'] = '';
}
}
}
// تحميل الصور مع SSL context
for($i = 0; $i < $n; $i++)
{
if(empty($files[$i]['url'])) continue;
// getimagesize مع context لدعم HTTPS
if(@getimagesize($files[$i]['url'], $info, $context))
{
$files[$i]['content'] = @file_get_contents($files[$i]['url'], false, $context);
$files[$i]['ext'] = strrchr($files[$i]['url'], '.');
if(empty($files[$i]['content']))
{
error_log('فشل تحميل الصورة: ' . $files[$i]['url']);
}
}
}
// حفظ الصور وإضافة الختم
for($i = 0; $i < $n; $i++)
{
$k = strlen($files[$i]['content']);
if(!$k) continue;
// التحقق من ID قاعدة البيانات
$id = GetCacheID();
if(!$id) continue;
$ext = $files[$i]['ext'];
$f = 'imgcache/2/' . sprintf('%d', $id) . 'alsh3er' . $ext;
$hFile = @fopen($f, 'wb');
if($hFile)
{
$m = @fwrite($hFile, $files[$i]['content'], $k);
fclose($hFile);
$files[$i]['content'] = '';
if($m == $k)
{
// إضافة الختم
AddWatermark($f, $ext);
$old_url = $files[$i]['url'];
$new_url = $forum_home . $f;
$old_message = str_replace($old_url, $new_url, $old_message);
}
else
{
// حذف الملف لو الكتابة فشلت
@unlink($f);
error_log('فشلت الكتابة للملف: ' . $f);
}
}
}
return $old_message;
}
?>حل بديل
PHP كود :
<?php
/******************************************************************************
* Image Cache Plugin with Arabic Watermark - الكامل الجاهز *
* (C) Copyright Y2K Software s.a.s., Italy 2006 - Modified 2024 *
* ---------------------------------------------------------------------------- *
* ينقل الصور ويضيف ختم مائي عربي تلقائياً *
*******************************************************************************/
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
// =====================================================
// دالة الختم المائي العربي المتقدمة
// =====================================================
function addArabicWatermark($sourceImage, $outputPath) {
$imageInfo = getimagesize($sourceImage);
if (!$imageInfo) return false;
$mime = $imageInfo['mime'];
// تحميل الصورة حسب نوعها
switch($mime) {
case 'image/jpeg':
$image = imagecreatefromjpeg($sourceImage);
break;
case 'image/png':
$image = imagecreatefrompng($sourceImage);
break;
case 'image/gif':
$image = imagecreatefromgif($sourceImage);
break;
default:
return false;
}
$width = imagesx($image);
$height = imagesy($image);
// إنشاء ألوان الختم
$white = imagecolorallocatealpha($image, 255, 255, 255, 0);
$black_shadow = imagecolorallocatealpha($image, 0, 0, 0, 30);
// نصوص الختم (يمكنك تغييرها)
$mainText = "القناة الشعرية";
$subText = "www.alsh3er.com";
$fontSizeMain = min(36, $height * 0.08); // حجم ديناميكي
$fontSizeSub = min(20, $height * 0.04);
$fontPath = __DIR__ . '/fonts/Amiri-Regular.ttf';
if (!file_exists($fontPath)) {
// خط احتياطي إذا لم يوجد الخط
$mainText = "ALSH3ER.COM";
$subText = "Watermark";
}
// حساب أبعاد النصوص
$bboxMain = imagettfbbox($fontSizeMain, 0, $fontPath, $mainText);
$bboxSub = imagettfbbox($fontSizeSub, 0, $fontPath, $subText);
$textWidthMain = $bboxMain[4] - $bboxMain[6];
$textHeightMain = $bboxMain[5] - $bboxMain[1];
$textWidthSub = $bboxSub[4] - $bboxSub[6];
$textHeightSub = $bboxSub[5] - $bboxSub[1];
// موضع النص في المنتصف مع مسافة
$xMain = ($width - $textWidthMain) / 2;
$yMain = ($height + $textHeightMain) / 2;
$xSub = ($width - $textWidthSub) / 2;
$ySub = $yMain + $textHeightSub + 10;
// الظل الأسود
imagettftext($image, $fontSizeMain, 0, $xMain+2, $yMain+2, $black_shadow, $fontPath, $mainText);
imagettftext($image, $fontSizeSub, 0, $xSub+1, $ySub+1, $black_shadow, $fontPath, $subText);
// النص الأبيض الرئيسي
imagettftext($image, $fontSizeMain, 0, $xMain, $yMain, $white, $fontPath, $mainText);
imagettftext($image, $fontSizeSub, 0, $xSub, $ySub, $white, $fontPath, $subText);
// حفظ الصورة
$result = false;
switch($mime) {
case 'image/jpeg':
$result = imagejpeg($image, $outputPath, 92);
break;
case 'image/png':
$result = imagepng($image, $outputPath, 8);
break;
case 'image/gif':
$result = imagegif($image, $outputPath);
break;
}
imagedestroy($image);
return $result;
}
// =====================================================
// الحصول على ID فريد للصورة
// =====================================================
function GetCacheID()
{
global $db;
$SQL = "INSERT INTO " . TABLE_PREFIX . "y2ksw_imgcache2 (ID) VALUES (0)";
$db->query_write($SQL);
return $db->insert_id();
}
// =====================================================
// الدالة الرئيسية لنقل الصور مع الختم
// =====================================================
function CacheImages($message_body, $old_message, $forum_home)
{
// البحث عن جميع العلامات [img]...[/img]
$n = 0;
$pos_end = -1;
for(;;)
{
$pos_start = strpos(strtolower($message_body), '[img]', $pos_end + 1);
if($pos_start === FALSE) break;
$pos_end = strpos(strtolower($message_body), '[/img]', $pos_start + 1);
if($pos_end === FALSE) break;
$pos_start += 5;
$pos_end--;
$files[$n]['url'] = substr($message_body, $pos_start, $pos_end - $pos_start + 1);
$n++;
}
if(!$n) return $old_message;
// استبعاد الصور المحفوظة مسبقاً
for($i = 0; $i < $n; $i++)
{
if(strpos($files[$i]['url'], $forum_home . 'imgcache/2/') !== FALSE)
{
$files[$i]['url'] = '';
continue;
}
$matar = strtolower($files[$i]['url']);
if (stripos($matar, "alshafeen.site") !== false || stripos($matar, "alsh3er.com") !== false) {
$files[$i]['url'] = '';
}
}
// إزالة التكرارات
for($i = 0; $i < $n; $i++)
{
$a = $files[$i]['url'];
if($a)
{
for($j = $i + 1; $j < $n; $j++)
{
if($files[$j]['url'] == $a) $files[$j]['url'] = '';
}
}
}
// تحميل محتويات الصور
for($i = 0; $i < $n; $i++)
{
if(@getimagesize($files[$i]['url']))
{
$files[$i]['content'] = @file_get_contents($files[$i]['url'], false, $context);
}
}
// حفظ الصور مع الختم المائي
for($i = 0; $i < $n; $i++)
{
$k = strlen($files[$i]['content']);
if($k)
{
$id = GetCacheID();
$tempFile = 'imgcache/2/temp_' . $id . '.tmp';
$finalFile = 'imgcache/2/' . $id . '_watermarked.jpg';
// حفظ الملف المؤقت
$hTempFile = @fopen($tempFile, 'wb');
if($hTempFile)
{
$m = @fwrite($hTempFile, $files[$i]['content'], $k);
fclose($hTempFile);
if($m == $k)
{
// إضافة الختم واستبدال الرابط
if(addArabicWatermark($tempFile, $forum_home . $finalFile))
{
@unlink($tempFile); // حذف المؤقت
$old_url = $files[$i]['url'];
$new_url = $forum_home . $finalFile;
$old_message = str_replace($old_url, $new_url, $old_message);
}
}
}
}
}
return $old_message;
}
// نهاية الكود =====================================================
?>

![[صورة مرفقة: 177461173141861.gif]](https://up6.cc/2026/03/177461173141861.gif)