<?php
/*
=====================================================
Social Share Plugin for DLE
-----------------------------------------------------
File: engine/modules/social_share_functions.php
-----------------------------------------------------
Author: elegance07 (düzeltilmiş)
Updated: 2025-08-27
=====================================================
*/
if (!defined('DATALIFEENGINE')) {
die("Hacking attempt!");
}
// Global değişkenleri kontrol et
global $config, $row, $is_logged, $member_id, $tpl, $full_link, $category_id;
// URL'yi oluştur - DLE'nin yapısına göre
if (isset($row['id']) && !empty($row['id'])) {
// Makale ID'si varsa makale linkini oluştur
if (isset($row['full_link']) && !empty($row['full_link'])) {
$currentUrl = $config['http_home_url'] . $row['full_link'];
} else {
// Fallback: manuel link oluştur
$currentUrl = $config['http_home_url'] . $row['id'] . '-' . $row['alt_name'] . '.html';
}
} else {
// Makale sayfası değilse mevcut URL
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? "https" : "http";
$currentUrl = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
// Başlık ve açıklamayı belirle
$shareTitle = '';
$shareDescription = '';
$shareImage = '';
// Eğer makale sayfasındaysak ve row verisi varsa
if (isset($row) && is_array($row) && !empty($row)) {
// Başlık
$shareTitle = !empty($row['title']) ? $row['title'] : $config['home_title'];
// Açıklama - önce short_story, sonra full_story'den al
if (!empty($row['short_story'])) {
$shareDescription = strip_tags($row['short_story']);
} elseif (!empty($row['full_story'])) {
$shareDescription = strip_tags($row['full_story']);
} else {
$shareDescription = $shareTitle;
}
// Açıklamayı temizle ve kısalt
$shareDescription = preg_replace('/\s+/', ' ', trim($shareDescription));
if (mb_strlen($shareDescription) > 160) {
$shareDescription = mb_substr($shareDescription, 0, 160) . '...';
}
// Resim ara - daha kapsamlı arama
// 1. Xfields'dan farklı resim alanlarını kontrol et
if (!empty($row['xfields'])) {
// Standart resim alanları
if (preg_match('/image\|([^|]+)/', $row['xfields'], $matches)) {
$shareImage = trim($matches[1]);
}
// Photo alanı
elseif (preg_match('/photo\|([^|]+)/', $row['xfields'], $matches)) {
$shareImage = trim($matches[1]);
}
// Picture alanı
elseif (preg_match('/picture\|([^|]+)/', $row['xfields'], $matches)) {
$shareImage = trim($matches[1]);
}
// Resim alanı (Türkçe)
elseif (preg_match('/resim\|([^|]+)/', $row['xfields'], $matches)) {
$shareImage = trim($matches[1]);
}
}
// 2. short_story'den resim ara (anasayfada bu kullanılır)
if (empty($shareImage) && !empty($row['short_story'])) {
// HTML img etiketleri
if (preg_match('/<img[^>]+src=["\']([^"\']+)["\'][^>]*>/i', $row['short_story'], $matches)) {
$shareImage = trim($matches[1]);
}
// BB code [img] etiketleri
elseif (preg_match('/\[img[^\]]*\]([^\[]+)\[\/img\]/i', $row['short_story'], $matches)) {
$shareImage = trim($matches[1]);
}
}
// 3. full_story'den resim ara (tam makale sayfasında)
if (empty($shareImage) && !empty($row['full_story'])) {
if (preg_match('/<img[^>]+src=["\']([^"\']+)["\'][^>]*>/i', $row['full_story'], $matches)) {
$shareImage = trim($matches[1]);
}
elseif (preg_match('/\[img[^\]]*\]([^\[]+)\[\/img\]/i', $row['full_story'], $matches)) {
$shareImage = trim($matches[1]);
}
}
// Resim URL'sini düzelt
if (!empty($shareImage)) {
// Boşlukları temizle
$shareImage = trim($shareImage);
// uploads/ ile başlıyorsa
if (strpos($shareImage, 'uploads/') === 0) {
$shareImage = $config['http_home_url'] . $shareImage;
}
// ./uploads/ ile başlıyorsa
elseif (strpos($shareImage, './uploads/') === 0) {
$shareImage = $config['http_home_url'] . ltrim($shareImage, './');
}
// / ile başlıyorsa
elseif (substr($shareImage, 0, 1) === '/') {
$shareImage = $config['http_home_url'] . ltrim($shareImage, '/');
}
// http ile başlamıyorsa
elseif (!preg_match('/^https?:\/\//', $shareImage)) {
$shareImage = $config['http_home_url'] . $shareImage;
}
// Son temizlik
$shareImage = str_replace('//', '/', $shareImage);
$shareImage = str_replace('http:/', 'http://', $shareImage);
$shareImage = str_replace('https:/', 'https://', $shareImage);
}
} else {
// Anasayfa veya diğer sayfalar için
$shareTitle = $config['home_title'];
$shareDescription = isset($config['description']) ? $config['description'] : $shareTitle;
}
// URL encode işlemleri
$encoded_url = urlencode($currentUrl);
$encoded_title = urlencode($shareTitle);
$encoded_desc = urlencode($shareDescription);
?>
<!-- CSS ve JS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
.social-share-buttons {
display: flex;
gap: 10px;
margin: 15px 0;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.share-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: 50%;
color: #fff;
transition: all 0.3s ease;
text-decoration: none;
}
.share-button:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
text-decoration: none;
color: #fff;
}
.share-button.facebook { background: #3b5998; }
.share-button.facebook:hover { background: #2d4373; }
.share-button.twitter { background: #1da1f2; }
.share-button.twitter:hover { background: #0c85d0; }
.share-button.linkedin { background: #0077b5; }
.share-button.linkedin:hover { background: #005582; }
.share-button.pinterest { background: #bd081c; }
.share-button.pinterest:hover { background: #8c0615; }
.share-button.whatsapp { background: #25d366; }
.share-button.whatsapp:hover { background: #1da851; }
.share-button.telegram { background: #0088cc; }
.share-button.telegram:hover { background: #006699; }
.share-button i { font-size: 18px; }
/* Responsive */
@media (max-width: 600px) {
.social-share-buttons {
justify-content: center;
}
.share-button {
width: 35px;
height: 35px;
}
.share-button i {
font-size: 16px;
}
}
</style>
<script>
function openSharePopup(url) {
var width = 600;
var height = 400;
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
window.open(url, 'shareWindow',
'width=' + width + ',height=' + height +
',left=' + left + ',top=' + top +
',scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,status=no');
return false;
}
</script>
<!-- Paylaşım Butonları -->
<div class="social-share-buttons">
<!-- Facebook -->
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $encoded_url; ?>"
class="share-button facebook"
onclick="openSharePopup(this.href); return false;"
title="Facebook'ta Paylaş">
<i class="fab fa-facebook-f"></i>
</a>
<!-- Twitter/X -->
<a href="https://twitter.com/intent/tweet?url=<?php echo $encoded_url; ?>&text=<?php echo $encoded_title; ?>"
class="share-button twitter"
onclick="openSharePopup(this.href); return false;"
title="Twitter'da Paylaş">
<i class="fab fa-twitter"></i>
</a>
<!-- WhatsApp -->
<a href="https://api.whatsapp.com/send?text=<?php echo $encoded_title; ?>%20<?php echo $encoded_url; ?>"
class="share-button whatsapp"
onclick="openSharePopup(this.href); return false;"
title="WhatsApp'ta Paylaş">
<i class="fab fa-whatsapp"></i>
</a>
<!-- Telegram -->
<a href="https://t.me/share/url?url=<?php echo $encoded_url; ?>&text=<?php echo $encoded_title; ?>"
class="share-button telegram"
onclick="openSharePopup(this.href); return false;"
title="Telegram'da Paylaş">
<i class="fab fa-telegram-plane"></i>
</a>
<!-- LinkedIn -->
<a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo $encoded_url; ?>&title=<?php echo $encoded_title; ?>"
class="share-button linkedin"
onclick="openSharePopup(this.href); return false;"
title="LinkedIn'de Paylaş">
<i class="fab fa-linkedin-in"></i>
</a>
<!-- Pinterest -->
<a href="https://pinterest.com/pin/create/button/?url=<?php echo $encoded_url; ?>&description=<?php echo $encoded_desc; ?><?php if (!empty($shareImage)) echo '&media=' . urlencode($shareImage); ?>"
class="share-button pinterest"
onclick="openSharePopup(this.href); return false;"
title="Pinterest'te Paylaş">
<i class="fab fa-pinterest-p"></i>
</a>
</div>
<?php
// Debug için - Anasayfada F12 > Console'da görmek için
if (isset($_GET['debug']) && $_GET['debug'] == '1') {
echo "<div style='background: #fff3cd; padding: 8px; margin: 5px 0; font-size: 11px; border: 1px solid #ffeaa7; border-radius: 4px;'>";
echo "<strong>🔍 Debug (ID: " . ($row['id'] ?? 'N/A') . "):</strong><br>";
echo "📰 Başlık: " . htmlspecialchars(mb_substr($shareTitle, 0, 50)) . (mb_strlen($shareTitle) > 50 ? '...' : '') . "<br>";
echo "🔗 URL: " . htmlspecialchars($currentUrl) . "<br>";
echo "🖼️ Resim: " . ($shareImage ? htmlspecialchars($shareImage) : 'YOK') . "<br>";
if (isset($row['alt_name'])) echo "🏷️ Alt name: " . htmlspecialchars($row['alt_name']) . "<br>";
echo "</div>";
}
?>
Kullanım
Eklenti, sayfanın herhangi bir yerine sosyal paylaşım butonlarını eklemek için kullanılabilir. Bu butonlar, kullanıcıların içeriği sosyal medya platformlarında hızlıca paylaşmalarını sağlar.
Ekstra Özellikler
- Responsive Tasarım: Mobil cihazlar için buton boyutları küçültülür, böylece her cihazda düzgün görünür.
- Esneklik: İhtiyaca göre yeni sosyal medya platformları eklemek mümkün.
1. Dosya Yerleştirme
Eklenti dosyasını uygun bir yere yerleştirmeniz gerekecek.
social_share.php
dosyasını engine/modules/
klasörüne yerleştirin.
- Bu dosya, sosyal paylaşım butonlarının işlevlerini sağlar.
2. Sosyal Paylaşım Butonlarının Sayfada Görüntülenmesi
Paylaşım butonlarının sayfanın belirli bir bölümünde görünmesini sağlamak için şablon dosyanıza ekleme yapmalısınız.
3. CSS ve İkonların Yüklenmesi
Eklenti, CSS ve Font Awesome ikonları için dış bir kaynak kullanmaktadır. Bu kaynakların doğru şekilde sayfanıza dahil edilmesi gerekmektedir.
Eklenti kodu zaten outputStyles
metodu içinde CSS'yi ve Font Awesome ikonlarını dahil etmeyi sağlıyor. Ancak, eğer özel bir stil dosyanız varsa, outputStyles
fonksiyonunu çağırarak bu stillerin sayfada yüklendiğinden emin olmanız gerekir.
Şablon dosyanızda, sosyal paylaşım butonlarının görüneceği yeri belirledikten sonra, aynı sayfada (örneğin, fullstory.tpl
veya shortstory.tpl
dosyasında) CSS'yi de dahil etmeniz gerekebilir. Ancak outputStyles
fonksiyonu doğru şekilde çalışıyorsa, bunu manuel olarak eklemeniz gerekmez.
4. Sosyal Paylaşım Butonlarını Konfigüre Etme
Bu eklenti, şablonda otomatik olarak mevcut sayfanın başlığını, açıklamasını ve URL’sini kullanır. Eğer şablonunuzda özelleştirilmiş bir içerik varsa, paylaşılan bilgilerin doğru olmasını sağlamak için bu bilgileri özelleştirmeniz gerekebilir.
5. Eklentinin Test Edilmesi
Eklentiyi kurduktan sonra aşağıdaki adımları takip ederek test edin:
- Sayfanızı açın ve sosyal paylaşım butonlarının görünür olup olmadığını kontrol edin.
- Butonlara tıklayarak her bir sosyal medya platformunda içeriğin doğru şekilde paylaşıldığından emin olun.
- Mobil cihazlarda da test yaparak butonların düzgün bir şekilde çalıştığından emin olun.
Eklenti düzgün çalışıyorsa, sosyal medya paylaşım butonları sayfada görüntülenecek ve kullanıcılar bu butonlar aracılığıyla içeriklerini kolayca paylaşabilecektir.
Eklenti Kodu:
Yorumlar (3)
Yorum Ekle