function addMetaForSEO()
{
global $post;
$pageURL = "http";
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
$canonical = $pageURL;
if (is_home()) {
$title = get_bloginfo("name");
if (get_query_var("paged")) {
$paged = get_query_var("paged");
} else {
if (get_query_var("page")) {
$paged = get_query_var("page");
} else {
$paged = 1;
}
}
if (1 < $paged) {
$title .= " - صفحة " . $paged;
$posts_titles = array();
$current_posts = get_posts(array(
'posts_per_page' => 5,
'paged' => $paged,
'post_status' => 'publish'
));
if (!empty($current_posts)) {
foreach ($current_posts as $post_item) {
$posts_titles[] = $post_item->post_title;
}
$description = implode(" · ", $posts_titles);
} else {
$description = (get_option("SiteName") == "") ? get_bloginfo("description") : get_option("descSite");
$description = "صفحة " . $paged . " من " . $description;
}
$canonical = home_url('/');
if ($paged > 1) {
$canonical = home_url('/page/' . $paged . '/');
}
} else {
$description = (get_option("SiteName") == "") ? get_bloginfo("description") : get_option("descSite");
$canonical = home_url();
}
$sitename = get_option("SiteName") != "" ? get_option("SiteName") : get_bloginfo("name");
echo "
" . $title . "
";
}elseif(is_singular() && !is_page()) {
$post = get_queried_object();
$sitename = get_option("SiteName") == "" ? get_bloginfo("name") : get_option("SiteName");
$facebook = get_option("facebook");
$title = $post->post_title;
$image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
$ogimage = !isset(get_post_meta($post->ID, "ogimage", true)["url"]) && empty(get_post_meta($post->ID, "ogimage", true)["url"]) ? $image : get_post_meta($post->ID, "ogimage", true)["url"];
$content = $post->post_content;
$metadescription = get_post_meta($post->ID, "metadescription", true) == "" ? $content : get_post_meta($post->ID, "metadescription", true);
$metadescription = wp_trim_words($metadescription, 30, "");
$metatitle = get_post_meta($post->ID, "metatitle", true) == "" ? $title : get_post_meta($post->ID, "metatitle", true);
if (get_query_var("download")) {
$metatitle .= " - تحميل";
}
if ($post->post_type == "post") {
$cats = is_array(get_the_terms($post->ID, "category", "")) ? get_the_terms($post->ID, "category", "") : array();
} else {
if ($post->post_type == "news") {
$cats = is_array(get_the_terms($post->ID, "catnews", "")) ? get_the_terms($post->ID, "catnews", "") : array();
} else {
$cats = is_array(get_the_terms($post->ID, "progcategories", "")) ? get_the_terms($post->ID, "progcategories", "") : array();
}
}
$category = "";
foreach (array_slice($cats, 0, 1) as $term) {
$category = $term->name;
}
$publishedtime = date("c", strtotime($post->post_date));
$modifiedtime = date("c", strtotime($post->post_modified));
echo "
" . $metatitle . " | " . $sitename . "
";
}else{
if (is_category() || is_tag() || is_tax() || is_archive() && !is_page()) {
$obj = get_queried_object();
$sitename = get_option("SiteName") == "" ? get_bloginfo("name") : get_option("SiteName");
$secondname = get_bloginfo("name");
$title = $obj->name . " - " . $sitename;
if (get_query_var("paged")) {
$paged = get_query_var("paged");
} else {
if (get_query_var("page")) {
$paged = get_query_var("page");
} else {
$paged = 1;
}
}
if (1 < $paged) {
$title .= " - صفحة " . $paged;
$posts_titles = array();
$current_posts = get_posts(array(
'posts_per_page' => 5,
'paged' => $paged,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => $obj->taxonomy,
'field' => 'term_id',
'terms' => $obj->term_id
)
)
));
if (!empty($current_posts)) {
foreach ($current_posts as $post_item) {
$posts_titles[] = $post_item->post_title;
}
$description = implode(" · ", $posts_titles);
} else {
$description = $obj->description;
$description = "صفحة " . $paged . " من " . $obj->name . " - " . $description;
}
$canonical = get_term_link($obj);
if ($paged > 1) {
$canonical = add_query_arg('paged', $paged, $canonical);
}
} else {
if (empty($obj->description)) {
$posts_titles = array();
$current_posts = get_posts(array(
'posts_per_page' => 5,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => $obj->taxonomy,
'field' => 'term_id',
'terms' => $obj->term_id
)
)
));
if (!empty($current_posts)) {
foreach ($current_posts as $post_item) {
$posts_titles[] = $post_item->post_title;
}
$description = implode(" · ", $posts_titles);
} else {
$description = $obj->name . " - " . $sitename;
}
} else {
$description = $obj->description;
}
$canonical = get_term_link($obj);
}
echo "
" . $title . "
";
}else{
if (is_search() && !is_page()) {
if (get_query_var("paged")) {
$paged = get_query_var("paged");
} else {
if (get_query_var("page")) {
$paged = get_query_var("page");
} else {
$paged = 1;
}
}
if (1 < $paged) {
$title .= " - صفحة " . $paged;
}
$search_query = get_search_query();
$search_results = array();
$current_search = get_posts(array(
'posts_per_page' => 5,
'paged' => $paged,
'post_status' => 'publish',
's' => $search_query
));
if (!empty($current_search)) {
foreach ($current_search as $search_item) {
$search_results[] = $search_item->post_title;
}
$description = implode(" · ", $search_results);
} else {
$description = get_option("descSite") == "" ? get_bloginfo("descSite") : get_option("description");
}
$canonical = home_url('/?s=' . urlencode($search_query));
if ($paged > 1) {
$canonical = add_query_arg('paged', $paged, $canonical);
}
$sitename = get_option("SiteName") == "" ? get_bloginfo("name") : get_option("SiteName");
$title = "نتائج البحث عن " . $search_query . " | " . $sitename;
echo "
" . $title . "
";
} else if(is_page()) {
$post = get_queried_object();
$sitename = get_option("SiteName") == "" ? get_bloginfo("name") : get_option("SiteName");
$title = $post->post_title;
$image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
$ogimage = !isset(get_post_meta($post->ID, "ogimage", true)["url"]) && empty(get_post_meta($post->ID, "ogimage", true)["url"]) ? $image : get_post_meta($post->ID, "ogimage", true)["url"];
$content = $post->post_content;
$metadescription = get_post_meta($post->ID, "metadescription", true);
if (empty($metadescription)) {
$content_text = wp_strip_all_tags($content);
$metadescription = wp_trim_words($content_text, 30, "");
}
$metatitle = get_post_meta($post->ID, "metatitle", true) == "" ? $title : get_post_meta($post->ID, "metatitle", true);
$canonical = get_permalink();
echo "
" . $metatitle . " | " . $sitename . "
";
} else{
$canonical = get_permalink();
?>
» توب سينما - مشاهدة افلام ومسلسلات اون لاين
echo "
";
}
}
}
}
function addSchema($post)
{
global $post;
$seriesTax = "series";
if (wp_get_attachment_url(get_post_thumbnail_id($post->ID))) {
$thumb = get_the_post_thumbnail_url($post->ID, "TopSlider ");
} else {
$thumb = get_option("DefultBlock")["url"];
}
$Schema = "movie";
foreach (is_array(get_the_terms($post->ID, $seriesTax, "")) ? get_the_terms($post->ID, $seriesTax, "") : array() as $series) {
$Schema = "serie";
if (0 < $series->parent) {
$HasSeasons = true;
$SerieID = $series->parent;
$CurrentSeason = $series->term_id;
} else {
$CurrentSeries = $series->term_id;
}
}
foreach (is_array(get_the_terms($post->ID, "tvshow", "")) ? get_the_terms($post->ID, "tvshow", "") : array() as $tvshow) {
$Schema = "tvshow";
if (0 < $tvshow->parent) {
$HasSeasons = true;
$tvshowID = $tvshow->parent;
$CurrentSeTv = $tvshow->term_id;
} else {
if (isset($serie->parent) && $serie->parent == 0) {
$CurrentTvShow = $tvshow->term_id;
} else {
$CurrentTvShow = $tvshow->term_id;
}
}
}
if ($Schema == "movie") {
// استخدام JSON-LD بدلاً من microdata للفيلم
$movie_schema = [
"@context" => "https://schema.org",
"@type" => "Movie",
"name" => get_the_title($post->ID),
"description" => wp_trim_words(get_the_content(), 20, "..."),
"image" => wp_get_attachment_url(get_post_thumbnail_id($post->ID)),
"datePublished" => date("Y-m-d", strtotime($post->post_date)),
"director" => [],
"author" => [],
"actor" => []
];
// إضافة المخرجين
foreach (is_array(get_the_terms($post->ID, "director", "")) ? get_the_terms($post->ID, "director", "") : array() as $director) {
$movie_schema["director"][] = [
"@type" => "Person",
"name" => $director->name
];
}
// إضافة الكتّاب
foreach (is_array(get_the_terms($post->ID, "escritor", "")) ? get_the_terms($post->ID, "escritor", "") : array() as $writers) {
$movie_schema["author"][] = [
"@type" => "Person",
"name" => $writers->name
];
}
// إضافة الممثلين
foreach (is_array(get_the_terms($post->ID, "actor", "")) ? get_the_terms($post->ID, "actor", "") : array() as $actor) {
$movie_schema["actor"][] = [
"@type" => "Person",
"name" => $actor->name
];
}
// إضافة التقييم فقط إذا كان متاحًا
$rating_value = get_post_meta($post->ID, 'rating_value', true);
$rating_count = get_post_meta($post->ID, 'rating_count', true);
$review_count = get_post_meta($post->ID, 'review_count', true);
if ($rating_value || $rating_count || $review_count) {
$movie_schema["aggregateRating"] = [
"@type" => "AggregateRating",
"ratingValue" => $rating_value ? $rating_value : "8",
"bestRating" => "10",
"ratingCount" => $rating_count ? $rating_count : "200",
"reviewCount" => $review_count ? $review_count : "50"
];
}
echo '';
} else {
if ($Schema == "tvshow") {
if (get_the_terms($post->ID, "tvshow", "")) {
$tv_schema = [
"@context" => "https://schema.org",
"@type" => "TVSeries"
];
foreach (get_the_terms($post->ID, "tvshow", "") as $serie) {
if ($serie->parent == 0) {
$tv_schema["name"] = $serie->name;
$tv_schema["url"] = get_term_link($serie);
$tv_schema["containsSeason"] = [];
foreach (get_the_terms($post->ID, "tvshow", "") as $season) {
if (0 < $season->parent) {
$season_schema = [
"@type" => "TVSeason",
"name" => $season->name,
"url" => get_term_link($season),
"episode" => [
"@type" => "TVEpisode",
"name" => get_the_title($post->ID),
"url" => get_the_permalink($post->ID),
"position" => get_post_meta($post->ID, "number", true) ?: "1"
]
];
$tv_schema["containsSeason"][] = $season_schema;
}
}
echo '';
}
}
}
} else {
if ($Schema == "serie" || get_the_terms($post->ID, $seriesTax, "")) {
$serie_schema = [
"@context" => "https://schema.org",
"@type" => "TVSeries"
];
foreach (get_the_terms($post->ID, $seriesTax, "") as $serie) {
if ($serie->parent == 0) {
$serie_schema["name"] = $serie->name;
$serie_schema["url"] = get_term_link($serie);
$serie_schema["containsSeason"] = [];
foreach (get_the_terms($post->ID, $seriesTax, "") as $season) {
if (0 < $season->parent) {
$season_schema = [
"@type" => "TVSeason",
"name" => $season->name,
"url" => get_term_link($season),
"episode" => [
"@type" => "TVEpisode",
"name" => get_the_title($post->ID),
"url" => get_the_permalink($post->ID),
"position" => get_post_meta($post->ID, "number", true) ?: "1"
]
];
$serie_schema["containsSeason"][] = $season_schema;
}
}
echo '';
}
}
}
}
}
// إضافة بيانات الفيديو
$video_duration = get_post_meta($post->ID, 'video_duration', true) ?: "PT1H30M";
$video_schema = [
"@context" => "https://schema.org",
"@type" => "VideoObject",
"name" => get_the_title($post->ID),
"description" => wp_trim_words(get_the_content(), 20, "..."),
"thumbnailUrl" => wp_get_attachment_url(get_post_thumbnail_id($post->ID)),
"uploadDate" => date("c", strtotime($post->post_date)), // تنسيق ISO 8601
"embedUrl" => get_the_permalink($post->ID) . "?watch=1",
"duration" => $video_duration
];
echo '';
}
/**
* إضافة بيانات منظمة للصفحة الرئيسية
* تضيف هذه الدالة بيانات schema.org من نوع WebSite و Organization للصفحة الرئيسية
*/
function addHomePageSchema()
{
if (is_front_page() || is_home()) {
// إضافة بيانات WebSite
$website_schema = [
"@context" => "https://schema.org",
"@type" => "WebSite",
"name" => get_bloginfo('name'),
"url" => home_url(),
"description" => get_bloginfo('description'),
"potentialAction" => [
"@type" => "SearchAction",
"target" => home_url('?s={search_term_string}'),
"query-input" => "required name=search_term_string"
]
];
echo '';
// إضافة بيانات Organization
$organization_schema = [
"@context" => "https://schema.org",
"@type" => "Organization",
"name" => get_bloginfo('name'),
"url" => home_url(),
"logo" => [
"@type" => "ImageObject",
"url" => get_site_icon_url() ?: home_url('/wp-content/uploads/logo.png'),
"width" => "112",
"height" => "112"
]
];
echo '';
}
}
// إضافة الدالة إلى hook مناسب في WordPress
if (!function_exists('add_homepage_schema_to_wp')) {
function add_homepage_schema_to_wp() {
if (is_front_page() || is_home()) {
addHomePageSchema();
}
}
add_action('wp_head', 'add_homepage_schema_to_wp', 20);
}
/**
* دالة للتحقق من البيانات المنظمة في الموقع
* إضافة ?debug_schema=1 إلى نهاية رابط أي صفحة لعرض البيانات المنظمة (للمدراء فقط)
*/
function debug_schema_data() {
if (current_user_can('administrator') && isset($_GET['debug_schema'])) {
// جمع كل البيانات المنظمة من الصفحة
ob_start();
// استدعاء الدوال التي تضيف البيانات المنظمة
if (is_front_page() || is_home()) {
addHomePageSchema();
} else if (is_single()) {
global $post;
addSchema($post);
}
$schema_html = ob_get_clean();
// استخراج جميع وسوم JSON-LD
preg_match_all('/
} ?>