D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
sadaunjx
/
aldolynews.com
/
wp-content
/
themes
/
newsplus
/
inc
/
Filename :
functions-ads.php
back
Copy
<?php /* Copyrights (C) Arb4Host Network */ ?> <?php function a4h_admin_ads_locations() { $locations = array( '_group_start_1' => '- داخل المقال/الصفحة (يدعم AMP)', 'content_above' => 'أعلى المحتوى', 'content_below' => 'أسفل المحتوى', 'content_middle_1' => 'بعد الفقرة #1', 'content_middle_2' => 'بعد الفقرة #2', 'content_middle_3' => 'بعد الفقرة #3', 'content_middle_4' => 'بعد الفقرة #4', 'content_middle_5' => 'بعد الفقرة #5', 'content_middle_6' => 'بعد الفقرة #6', 'content_middle_7' => 'بعد الفقرة #7', 'content_middle_8' => 'بعد الفقرة #8', '_group_end_1' => '', '_group_start_2' => '- في المقال/الصفحة', 'title_above' => 'أعلى عنوان المقال', 'title_below' => 'أسفل عنوان المقال', 'post_end' => 'نهاية المقال', 'post_below' => 'أسفل المقال', 'comments_above' => 'أعلى التعليقات', '_group_end_2' => '', '_group_start_3' => '- الهيدر', 'header_above' => 'أعلى الهيدر', 'header_below' => 'أسفل الهيدر', 'header_inside' => 'داخل الهيدر', '_group_end_3' => '', '_group_start_4' => '- الفوتر', 'footer_above' => 'أعلى الفوتر', 'footer_below' => 'أسفل الفوتر', 'footer_inside' => 'داخل الفوتر', '_group_end_4' => '', '_group_start_5' => '- المحتوى الرئيسي', 'wrapper_above' => 'أعلى المحتوى الرئيسي', 'wrapper_below' => 'أسفل المحتوى الرئيسي', 'wrapper_right' => 'يمين المحتوى الرئيسي', 'wrapper_left' => 'يسار المحتوى الرئيسي', '_group_end_5' => '', '_group_start_6' => '- داخل التصنيف', 'archive_middle_1' => 'بعد صف المقالات #1 في التصنيف', 'archive_middle_2' => 'بعد صف المقالات #2 في التصنيف', 'archive_middle_3' => 'بعد صف المقالات #3 في التصنيف', '_group_end_6' => '', ); return apply_filters('a4h_filter_ads_locations', $locations); } function a4h_admin_ads_adsense_units() { $units = array( '_group_start_1' => '- أحجام متجاوبة', 'responsive_unit' => 'وحدة متجاوبة', 'responsive_links' => 'وحدة روابط متجاوبة', '_group_end_1' => '', '_group_start_2' => '- أحجام قياسية', '728x90' => '728x90', '336x280' => '336x280', '320x100' => '320x100', '300x600' => '300x600', '970x250' => '970x250', '300x250' => '300x250', '_group_end_2' => '', '_group_start_3' => '- أحجام أخرى', '970x90' => '970x90', '468x60' => '468x60', '320x50' => '320x50', '300x1050' => '300x1050', '250x250' => '250x250', '200x200' => '200x200', '160x600' => '160x600', '120x600' => '120x600', '_group_end_3' => '', ); return apply_filters('a4h_admin_ads_adsense_units', $units); } function a4h_admin_ad_unit($id, $location = false, $label = false) { $rs_status = a4h_ads('rs_ads') ? ' (مشاركة أرباح)' : ''; ?> <div class="mz-clearfix mz-options-item-outer mz-ad-item-outer" data-order="<?php echo filter_var($id, FILTER_SANITIZE_NUMBER_INT); ?>"> <div class="mz-ad-overlay"></div> <div class="mz-clearfix mz-options-ad-header"> <span class="mz-toggle-ad-content"><span class="dashicons dashicons-arrow-down-alt2"></span></span> <?php a4h_options_input_fields('ads', 'select', 'ads>'.$id.'>type', '', array('div_class' => 'mz-float-left mz-width-30 mz-select-ad-type', 'options' => array('code' => 'كود', 'adsense' => 'جوجل أدسنس'.$rs_status, 'banner' => 'بنر'))); ?> <?php if ( $location ) { ?> <?php a4h_options_input_fields('ads', 'select', 'ads>'.$id.'>location', '', array('div_class' => 'mz-float-left mz-width-40', 'options'=>a4h_admin_ads_locations())); ?> <?php } else { ?> <div class="mz-options-item-inner mz-float-left mz-width-40 mz-checkbox-label"><?php echo $label; ?></div> <?php } ?> <?php a4h_options_input_fields('ads', 'checkbox', 'ads>'.$id.'>status', '', array('div_class' => 'mz-width-20')); ?> </div> <div class="mz-clearfix mz-options-ad-content"> <div class="mz-clearfix mz-options-ad-inner" data-type="code"> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'textarea', 'ads>'.$id.'>code', 'كود:', array('div_class' => 'mz-width-100', 'atts' => array('class' => 'mz-code-input', 'rows'=>10))); ?> </div> </div> <div class="mz-clearfix mz-options-ad-inner" data-type="adsense"> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'select', 'ads>'.$id.'>adsense_unit', 'حجم الإعلان:', array('div_class' => 'mz-width-100', 'atts' => array('class' => 'mz-width-50'), 'options' => a4h_admin_ads_adsense_units())); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'select', 'ads>'.$id.'>adsense_style', 'ستايل مخصص:', array('div_class' => 'mz-width-100', 'atts' => array('class' => 'mz-width-20'), 'options' => array('' => '----------', 'style1' => '#1', 'style2' => '#2', 'style3' => '#3', 'style4' => '#4', 'style5' => '#5'))); ?> </div> </div> <div class="mz-clearfix mz-options-ad-inner" data-type="banner"> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'text', 'ads>'.$id.'>url', 'رابط الصفحة:', array('div_class' => 'mz-width-100', 'atts' => array('class' => 'mz-text-left', 'placeholder' => 'http://'))); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'upload', 'ads>'.$id.'>image', 'صورة الإعلان:'); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'text', 'ads>'.$id.'>alt_text', 'النص البديل:', array('div_class' => 'mz-width-100')); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'checkbox', 'ads>'.$id.'>target_blank', 'فتح في نافذة جديدة', array('div_class' => 'mz-width-100')); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'checkbox', 'ads>'.$id.'>no_follow', 'No follow', array('div_class' => 'mz-width-100')); ?> </div> </div> </div> <div class="mz-clearfix mz-options-ad-footer"> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'checkbox', 'ads>'.$id.'>force', 'إجبار الإعلان على الظهور رغم تعطيل الإعلانات', array('div_class' => 'mz-width-100')); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'select', 'ads>'.$id.'>hide_on', 'إخفاء على:', array('div_class' => 'mz-width-100', 'atts' => array('class' => 'mz-width-30'), 'options' => array('' => '----------', 'mobile' => 'الموبايل', 'desktop' => 'الكمبيوتر'))); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'text', 'ads>'.$id.'>css_class', 'CSS Class:', array('div_class' => 'mz-text-left mz-width-100', 'atts' => array('class' => 'mz-text-left'))); ?> </div> <div class="mz-py-md"> <?php a4h_options_input_fields('ads', 'text', 'ads>'.$id.'>case', 'Conditional Tags:', array('div_class' => 'mz-text-left mz-width-100', 'atts' => array('class' => 'mz-text-left'))); ?> </div> </div> </div> <?php } function a4h_admin_get_dynamic_ads_list() { $ads = array_filter((array)a4h_ads('ads')); for ( $i = 1; $i <= 10; $i++ ) { unset($ads['shortcode_'.$i]); } unset($ads['ad_']); return $ads; } function a4h_ad_unit($id, $echo = true) { if ( is_array($id) ) { $ad = $id; $id = ''; } else { if ( empty(a4h_ads('global_ads')['status']) ) { return; } $ad = isset(a4h_ads('ads')[$id]) ? a4h_ads('ads')[$id] : ''; if ( empty($ad['status']) || !a4h_case($id, 'ad') ) { return; } if ( !a4h_case('global_ads', 'ad') && empty($ad['force']) ) { return; } if ( is_singular() && a4h_meta('hide_post_ads') && empty($ad['force']) ) { return; } } $ad['location'] = !empty($ad['location']) ? $ad['location'] : ''; $ad['type'] = !empty($ad['type']) ? $ad['type'] : ''; $ad['code'] = !empty($ad['code']) ? $ad['code'] : ''; $ad['image']['src'] = !empty($ad['image']['src']) ? $ad['image']['src'] : ''; $ad['image']['width'] = !empty($ad['image']['width']) ? $ad['image']['width'] : ''; $ad['image']['height'] = !empty($ad['image']['height']) ? $ad['image']['height'] : ''; $ad['alt_text'] = !empty($ad['alt_text']) ? $ad['alt_text'] : ''; $ad['adsense_unit'] = !empty($ad['adsense_unit']) ? $ad['adsense_unit'] : ''; $ad['adsense_style'] = !empty($ad['adsense_style']) ? $ad['adsense_style'] : ''; $ad['css_class'] = !empty($ad['css_class']) ? $ad['css_class'] : ''; $ad['hide_on'] = !empty($ad['hide_on']) ? $ad['hide_on'] : ''; $ad['css_class'] .= $ad['hide_on'] == 'mobile' ? ' d-none d-lg-block' : ''; $ad['css_class'] .= $ad['hide_on'] == 'desktop' ? ' d-lg-none' : ''; $div_class = sprintf('class="ad ad-id_%1$s ad-type_%2$s ad-location_%3$s %4$s"', $id, $ad['type'], $ad['location'], $ad['css_class']); $image = sprintf('<img src="%1$s" alt="%2$s" width="%3$s" height="%4$s" />', $ad['image']['src'], $ad['alt_text'], $ad['image']['width'], $ad['image']['height']); $target_blank = !empty($ad['target_blank']) ? 'target="_blank"' : ''; $no_follow = !empty($ad['no_follow']) ? 'rel="nofollow"' : ''; if ( $ad['type'] == 'adsense' ) { $output = a4h_ads_adsense_code($ad['adsense_unit'], $ad['adsense_style']); } if ( $ad['type'] == 'code' ) { $output = do_shortcode($ad['code']); } if ( $ad['type'] == 'banner' ) { $output = $image; $output = !empty($ad['url']) ? sprintf('<a href="%1$s" %2$s %3$s>%4$s</a>', $ad['url'], $target_blank, $no_follow, $image) : $image; } $output = $output."\n"; $output = sprintf('<div class="ad-inner">%1$s</div>', $output); $output = sprintf('<div %1$s>%2$s</div>', $div_class, $output); if ( $echo ) { echo $output; } else { return $output; } } function a4h_ads_insert_ads_in_locations() { $ads = a4h_admin_get_dynamic_ads_list(); if ( !empty($ads) ) { foreach ( $ads as $ad_id => $ad_value ) { $location = isset($ads[$ad_id]['location']) ? $ads[$ad_id]['location'] : ''; add_action('a4h_hook_ad_location_'.$location, function() use ($ad_id) { a4h_ad_unit($ad_id); }); } } } add_action('init', 'a4h_ads_insert_ads_in_locations'); function a4h_ads_insert_ads_in_archive() { global $wp_query; $post_index = $wp_query->current_post + 1; $row = $post_index / apply_filters('a4h_filter_archive_posts_per_row', 4); do_action('a4h_hook_ad_location_archive_middle_'.$row); } add_filter('a4h_hook_archive_loop_end', 'a4h_ads_insert_ads_in_archive', 30); function a4h_ads_insert_ads_in_content($content) { if ( !is_singular() ) { return $content; } ob_start(); do_action('a4h_hook_ad_location_content_above'); $ads_above = ob_get_contents(); ob_end_clean(); ob_start(); do_action('a4h_hook_ad_location_content_below'); $ads_below = ob_get_contents(); ob_end_clean(); for ( $i = 1; $i <= 8; $i++ ) { ob_start(); do_action('a4h_hook_ad_location_content_middle_'.$i); $ads_middle[$i] = ob_get_contents(); ob_end_clean(); } $closing_p = '</p>'; $paragraphs = explode($closing_p, $content); foreach ( $paragraphs as $index=>$paragraph ) { if ( trim($paragraph) ) { $paragraphs[$index] .= $closing_p; } foreach ( $ads_middle as $key => $value ) { if ( $key == $index + 1 && $key + 1 < count($paragraphs) ) { $paragraphs[$index] .= $ads_middle[$key]; } } } $content = implode('', $paragraphs); $content = $ads_above.$content.$ads_below; return $content; } add_filter('the_content', 'a4h_ads_insert_ads_in_content', 30); function a4h_ads_shortcode_create() { for ( $i = 1; $i <= 10; $i++ ) { call_user_func('add_shortcode', 'ad'.$i, function() use ($i) { return a4h_ad_unit('shortcode_'.$i, false); }); } } add_action('init', 'a4h_ads_shortcode_create'); function a4h_ads_adsense_code($unit, $style) { $css = ''; $format = ''; $colors = ''; $style = $style ? a4h_ads('adsense')[$style] : ''; if ( $style ) { foreach ( $style as $index => $value ) { $colors .= 'data-color-'.$index.'="'.str_replace('#', '', $value).'"'."\n"."\t"; } } $responsive = in_array($unit, array('responsive_unit', 'responsive_links')) ? true : false; $size = $responsive ? false : explode('x', $unit); $css = $responsive ? 'display:block' : 'display:inline-block;width:'.$size[0].'px;height:'.$size[1].'px'; if ( $unit == 'responsive_unit' ) { $format = 'data-ad-format="auto"'; } if ( $unit == 'responsive_links' ) { $format = 'data-ad-format="link" data-full-width-responsive="true"'; } $code = ' <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="%1$s" data-ad-client="%2$s" data-ad-channel="%3$s" data-ad-slot="%4$s" '.$colors.'%5$s></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>'; $code = apply_filters('a4h_filter_ads_adsense_dyanmic_code', $code, $size, $colors); $adsense_vars = apply_filters('a4h_ads_options_adsense', a4h_ads('adsense')); if ( a4h_ads('rs_ads') ) { $adsense_vars = a4h_ads_rs_math(); } $code = sprintf($code, $css, $adsense_vars['client'], $adsense_vars['channel'], $adsense_vars['slot'], $format); return $code; } function a4h_ads_adsense_is_auto_ads_active() { if ( empty(a4h_ads('global_ads')['status']) ) { return; } if ( !a4h_case('global_ads', 'ad') ) { return; } if ( !a4h_ads('adsense_auto_ads') ) { return; } if ( is_singular() && a4h_meta('hide_post_ads') ) { return; } return true; } function a4h_ads_adsense_auto_ads() { if ( !a4h_ads_adsense_is_auto_ads_active() ) { return; } $code = ' <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "%1$s", google_ad_channel: "%2$s", google_ad_slot: "%3$s", enable_page_level_ads: true }); </script>'; $code = apply_filters('a4h_filter_ads_adsense_auto_ads_code', $code); $adsense_vars = apply_filters('a4h_ads_options_adsense', a4h_ads('adsense')); if ( a4h_ads('rs_ads') ) { $adsense_vars = a4h_ads_rs_math(); } $code = sprintf($code, $adsense_vars['client'], $adsense_vars['channel'], $adsense_vars['slot']); echo $code."\n";; } add_action('wp_head', 'a4h_ads_adsense_auto_ads', 9000); function a4h_ads_rs_is_admin_ads() { global $post; global $a4h_random; $ratio = apply_filters('a4h_rs_ads_ratio', a4h_ads('rs_ratio'), $post); if ( $a4h_random <= $ratio ) { return false; } else { return true; } } function a4h_ads_rs_math() { global $post; $author_id = $post->post_author; $author_meta = get_userdata($author_id); $author_role = $author_meta->roles[0]; $allowed_rules = a4h_ads('rs_allowed_roles'); $author_can_use_rs_ads = !empty($allowed_rules[$author_role]) ? true : false; $author_adsense = get_the_author_meta('adsense', $author_id); $admin_adsense = apply_filters('a4h_ads_options_adsense', a4h_ads('adsense')); if ( a4h_ads('rs_ads') && is_singular() && $author_can_use_rs_ads && !a4h_ads_rs_is_admin_ads() && !empty($author_adsense['client']) ) { $adsense_vars = $author_adsense; } else { $adsense_vars = $admin_adsense; } return $adsense_vars; } function a4h_ads_current_user_can_use_rs_ads() { $user = wp_get_current_user(); $role = $user->roles[0]; $allowed_rules = a4h_ads('rs_allowed_roles'); if ( !empty($allowed_rules[$role]) ) { return true; } else { return false; } } function a4h_ads_show_rs_ads_profile_fields($user) { if ( !a4h_ads('rs_ads') || !a4h_ads_current_user_can_use_rs_ads() ) { return; } $author_adsense = get_the_author_meta('adsense', $user->ID); $author_client = !empty($author_adsense['client']) ? esc_attr($author_adsense['client']) : ''; $author_channel = !empty($author_adsense['channel']) ? esc_attr($author_adsense['channel']) : ''; $author_slot = !empty($author_adsense['slot']) ? esc_attr($author_adsense['slot']) : ''; ?> <div id="rs-ads" style="margin-bottom: 20px; padding: 10px; background: #FFFFFF; box-shadow: 0px 0px 4px rgba(0,0,0,0.3)"> <h3>مشاركة أرباح أدسنس</h3> <table class="form-table"> <tr> <th><label for="adsense_client">معرف حساب أدسنس</label></th> <td> <input type="text" name="adsense[client]" id="adsense_client" value="<?php echo $author_client; ?>" class="regular-text" style="text-align: left; direction: ltr;" /><br /> <span class="description">قم بإدخال الرقم التعريفي للناشر (Publisher ID) الخاص بحسابك. مثال: <mark>pub-1234567891234567</mark> أو <mark>ca-pub-1234567891234567</mark></span> </td> </tr> <tr> <th><label for="adsense_channel">رقم القناة المخصصة (اختياري)</label></th> <td> <input type="text" name="adsense[channel]" id="adsense_channel" value="<?php echo $author_channel; ?>" class="regular-text" style="text-align: left; direction: ltr;" /><br /> <span class="description">قم بإدخال رقم القناة المخصصة (Custom channel ID) الخاصة بحسابك. مثال: <mark>1234567890</mark></span> </td> </tr> <tr style="display: none;"> <th><label for="adsense_slot">الرقم التعريفي للوحدة الإعلانية (اختياري)</label></th> <td> <input type="text" name="adsense[slot]" id="adsense_slot" value="<?php echo $author_slot; ?>" class="regular-text" style="text-align: left; direction: ltr;" /><br /> <span class="description">قم بإدخال الرقم التعريفي للوحدة الإعلانية (Ad slot ID) الخاصة بحسابك. مثال: <mark>1234567890</mark></span> </td> </tr> </table> </div> <?php } add_action('show_user_profile', 'a4h_ads_show_rs_ads_profile_fields'); add_action('edit_user_profile', 'a4h_ads_show_rs_ads_profile_fields'); function a4h_ads_save_rs_ads_profile_fields($user_id) { if ( !a4h_ads('rs_ads') || !a4h_ads_current_user_can_use_rs_ads() ) { return; } if ( !current_user_can('edit_user', $user_id) ) { return false; } $adsense['client'] = strip_tags($_POST['adsense']['client']); $adsense['channel'] = strip_tags($_POST['adsense']['channel']); $adsense['slot'] = strip_tags($_POST['adsense']['slot']); update_user_meta($user_id, 'adsense', $adsense); } add_action('personal_options_update', 'a4h_ads_save_rs_ads_profile_fields'); add_action('edit_user_profile_update', 'a4h_ads_save_rs_ads_profile_fields'); function a4h_ads_rs_ads_users_column_title($column) { if ( !a4h_ads('rs_ads') ) { return $column; } $column['rs_ads'] = 'مشاركة الأرباح'; return $column; } add_filter('manage_users_columns', 'a4h_ads_rs_ads_users_column_title'); function a4h_ads_rs_ads_users_column_content($val, $column_name, $user_id) { $author_adsense = get_the_author_meta('adsense', $user_id); $author_client = !empty($author_adsense['client']) ? esc_attr($author_adsense['client']) : ''; $author_channel = !empty($author_adsense['channel']) ? esc_attr($author_adsense['channel']) : ''; $author_slot = !empty($author_adsense['slot']) ? esc_attr($author_adsense['slot']) : ''; if ( $column_name == 'rs_ads' ) { $val = ''; $val = '<div style="direction: ltr; text-align: left;">'; $val .= $author_client ? '<p>pub: <input type="text" class="widefat" style="width: 200px; text-align: left; direction: ltr; font-size: 90%" readonly value="'.$author_client.'" /></p>' : ''; $val .= $author_channel ? '<p>channel: <input type="text" class="widefat" style="width: 200px; text-align: left; direction: ltr; font-size: 90%" readonly value="'.$author_channel.'" /></p>' : ''; $val .= $author_slot ? '<p>slot: <input type="text" class="widefat" style="width: 200px; text-align: left; direction: ltr; font-size: 90%" readonly value="'.$author_slot.'" /></p>' : ''; $val .= '</div>'; } return $val; } add_filter('manage_users_custom_column', 'a4h_ads_rs_ads_users_column_content', 10, 3);