<?php
################################################################################
// Wordpress main Admin Theme
################################################################################
	
//Custome Footer ..
    function remove_footer_admin () {
    echo 'الموقع يستخدم احدى اعمال محجوز.كوم <br /> قالب الموقع الشخصى من محجوز.كوم
  <?php echo   comicpress_copyright(); ?>

';
    }
    
    add_filter('admin_footer_text', 'remove_footer_admin');
	
	
// custom admin login logo
    function custom_login_logo() {
    echo '
<style type="text/css">
	h1 a { background-image: url('.get_bloginfo('template_directory').'/img/mhgoz-general/no-img/logo.png) !important;height:232px !important ;width:459px !important;margin-right: -100px !important;}
	#login {padding: 25px 0 0 !important;}
	</style>
';  
    }
    add_action('login_head', 'custom_login_logo'); 
################################################################################
/*/ MAIN SETTING /*/
################################################################################
function pagination($pages = '', $range = 4)
{
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class=\"pagination\">";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }

         echo "</div>\n";
     }
}	
################################################################################
// Securty Rules .. 
################################################################################
// Remove Wordpress Num.Ver.
############################
    function mhgoz_remove_version() {
    return '';
    }
    add_filter('the_generator', 'mhgoz_remove_version');
	
// Remove Error Message ..
##########################
	add_filter('login_errors',create_function('$a', "return null;"));
	
################################################################################
// top adminbar Menu
################################################################################
//Add To Menu..	
	function my_admin_bar_menu() {
	global $wp_admin_bar;
	if ( !is_super_admin() || !is_admin_bar_showing() )
		return;
	$wp_admin_bar->add_menu( array(
	'id' => 'Mhgoz',
	'title' => __( 'محجوز.كوم'),
	'href' => FALSE ) );
	$wp_admin_bar->add_menu( array(
	'parent' => 'Mhgoz',
	'id' => 'Mhgoz sub',
	'title' => __( 'الدعم الفنى'),
	'href' => 'http://www.mhgoz.com/supportplans.php' ) );
	$wp_admin_bar->add_menu( array(
	'parent' => 'Mhgoz',
	'id' => 'Mhgoz sub2',
	'title' => __( 'خدمات محجوز'),
	'href' => 'http://www.mhgoz.com' ) );
}
add_action('admin_bar_menu', 'my_admin_bar_menu' , 30);

################################################################################
// Important Snippets
################################################################################
// Copyrights ...
###################
function comicpress_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "&copy; " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}

################################################################################
// Removing From Admin Panel ..
################################################################################
function remove_menu_items() {
  global $menu;
  $restricted = array(__('Links'), __('Media'), __('widgets'), __('Users'));
  end ($menu);
  while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
      unset($menu[key($menu)]);}
    }
  }

add_action('admin_menu', 'remove_menu_items');
function remove_editor_menu() {
  remove_action('admin_menu', '_add_themes_utility_last', 101);
}

add_action('_admin_menu', 'remove_editor_menu', 1);

function wps_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('wp-logo');
    $wp_admin_bar->remove_menu('about');
    $wp_admin_bar->remove_menu('wporg');
    $wp_admin_bar->remove_menu('documentation');
    $wp_admin_bar->remove_menu('support-forums');
    $wp_admin_bar->remove_menu('feedback');
    $wp_admin_bar->remove_menu('view-site');
}
add_action( 'wp_before_admin_bar_render', 'wps_admin_bar' );
################################################################################
// Editor .. 
################################################################################
function html5_audio($atts, $content = null) {
	extract(shortcode_atts(array(
		"src" => '',
		"autoplay" => '',
		"preload"=> 'true',
		"loop" => '',
		"controls"=> ''
	), $atts));
	return '
        <audio src="'.$src.'" autoplay="'.$autoplay.'" preload="'.$preload.'" loop controls="'.$controls.'" autobuffer />
';
}
add_shortcode('audio5', 'html5_audio');
///[audio5 src="http://your-site/videos/your-video.mp4" loop="true" autoplay="autoplay" preload="auto" loop="loop" controls=""]///

function html5_video($atts, $content = null) {
	extract(shortcode_atts(array(
		"src" => '',
		"width" => '',
		"height" => ''
	), $atts));
	return '
        <video src="'.$src.'" width="'.$width.'" height="'.$height.'" controls autobuffer>
';
}
add_shortcode('video5', 'html5_video');

/// [video5 src="http://your-site/videos/your-video.mp4" width="720" height="480"] ///

function youtube($atts) {
	extract(shortcode_atts(array(
		"value" => 'http://',
		"width" => '475',
		"height" => '350',
		"name"=> 'movie',
		"allowFullScreen" => 'true',
		"allowScriptAccess"=>'always',
	), $atts));
	return '
        <object style="height: '.$height.'px; width: '.$width.'px">
  <param name="'.$name.'" value="'.$value.'">
  <param name="allowFullScreen" value="'.$allowFullScreen.'">
  </param>
  <param name="allowScriptAccess" value="'.$allowScriptAccess.'">
  </param>
  <embed src="'.$value.'" type="application/x-shockwave-flash" allowfullscreen="'.$allowFullScreen.'" allowScriptAccess="'.$allowScriptAccess.'" width="'.$width.'" height="'.$height.'"></embed>
</object>
';
}
add_shortcode("youtube", "youtube");


/// [youtube value="http://www.youtube.com/watch?v=1aBSPn2P9bg"] ///

function wps_screenshot($atts, $content = null) {
        extract(shortcode_atts(array(
			"screenshot" => 'http://s.wordpress.com/mshots/v1/',
			"url" => 'http://',
			"alt" => 'screenshot',
			"width" => '400',
			"height" => '300'
        ), $atts));
		return $screen = '<img src="' . $screenshot . '' . urlencode($url) . '?w=' . $width . '&h=' . $height . '" alt="' . $alt . '"/>';
}
add_shortcode("screenshot", "wps_screenshot");

/// [screenshot url="http://wpsnipp.com" alt="wordpress code snippets for your blog" width="200" height="200"]
 ///
 
 function content_countdown($atts, $content = null){
  extract(shortcode_atts(array(
     'month' => '',
     'day'   => '',
     'year'  => ''
    ), $atts));
    $remain = ceil((mktime( 0,0,0,(int)$month,(int)$day,(int)$year) - time())/86400);
    if( $remain > 1 ){
        return $daysremain = "
        <div class=\"event\">Just <b>($remain)</b> days until content is available</div>
";
    }else if($remain == 1 ){
	return $daysremain = "
    <div class=\"event\">Just <b>($remain)</b> day until content is available</div>
";
    }else{
        return $content;
    }
}
add_shortcode('cdt', 'content_countdown');

/*/[cdt month="10" day="17" year="2011"]
This is content that will only be shown after a set number of days.
[/cdt] /*/

add_shortcode('iframe', array('iframe_shortcode', 'shortcode'));
class iframe_shortcode {
    function shortcode($atts, $content=null) {
          extract(shortcode_atts(array(
               'url'      => '',
               'scrolling'      => 'no',
               'width'      => '100%',
               'height'      => '500',
               'frameborder'      => '0',
               'marginheight'      => '0',
          ), $atts));
          if (empty($url)) return '<!-- Iframe: You did not enter a valid URL -->';
     return '
          <iframe src="'.$url.'" title="" width="'.$width.'" height="'.$height.'" scrolling="'.$scrolling.'" frameborder="'.$frameborder.'" marginheight="'.$marginheight.'"><a href="'.$url.'" target="_blank">'.$url.'</a></iframe>
';
    }
}
 /*/ [iframe url="http://wpsnipp.com" width="100" height="100" scrolling="yes" frameborder="1" marginheight="2"] /*/


/****** Add Thumbnails in Manage Posts/Pages List ******/
if ( !function_exists('AddThumbColumn') && function_exists('add_theme_support') ) {
    // for post and page
    add_theme_support('post-thumbnails', array( 'post', 'page' ) );
    function AddThumbColumn($cols) {
        $cols['thumbnail'] = __('Thumbnail');
        return $cols;
    }
    function AddThumbValue($column_name, $post_id) {
            $width = (int) 60;
            $height = (int) 60;
            if ( 'thumbnail' == $column_name ) {
                // thumbnail of WP 2.9
                $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
                // image from gallery
                $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
                if ($thumbnail_id)
                    $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
                elseif ($attachments) {
                    foreach ( $attachments as $attachment_id => $attachment ) {
                        $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
                    }
                }
                    if ( isset($thumb) && $thumb ) {
                        echo $thumb;
                    } else {
                        echo __('None');
                    }
            }
    }
    // for posts
    add_filter( 'manage_posts_columns', 'AddThumbColumn' );
    add_action( 'manage_posts_custom_column', 'AddThumbValue', 10, 2 );
    // for pages
    add_filter( 'manage_pages_columns', 'AddThumbColumn' );
    add_action( 'manage_pages_custom_column', 'AddThumbValue', 10, 2 );
}

/*/ 



add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');

function optionsframework_custom_scripts() { ?> 
<script type="text/javascript">
jQuery(document).ready(function() {

	jQuery('#example_showhidden').click(function() {
  		jQuery('#section-example_text_hidden').fadeToggle(400);
	});
	
	if (jQuery('#example_showhidden:checked').val() !== undefined) {
		jQuery('#section-example_text_hidden').show();
	}
	
});
</script>
<?php
}

/* 
 * Turns off the default options panel from Twenty Eleven
 */
 
add_action('after_setup_theme','remove_twentyeleven_options', 100);

function remove_twentyeleven_options() {
	remove_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );
}

/////////////////////////////////////////////////////////////////////////////////

function show_posts_nav() {
   global $wp_query;
   return ($wp_query->max_num_pages > 1);
}

################################################################################
// Add theme support
################################################################################

add_theme_support( 'automatic-feed-links' );
add_theme_support( 'nav-menus' );

register_nav_menus( array(
	'primary' => __( 'القائمه الرئيسيه' ),
) );

################################################################################
// Actions + Filters/*/
################################################################################

// Remove links to the extra feeds (e.g. category feeds)
remove_action( 'wp_head', 'feed_links_extra', 3 );
// Remove links to the general feeds (e.g. posts and comments)
remove_action( 'wp_head', 'feed_links', 2 );
// Remove link to the RSD service endpoint, EditURI link
remove_action( 'wp_head', 'rsd_link' );
// Remove link to the Windows Live Writer manifest file
remove_action( 'wp_head', 'wlwmanifest_link' );
// Remove index link
remove_action( 'wp_head', 'index_rel_link' );
// Remove prev link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
// Remove start link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
// Display relational links for adjacent posts
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
// Remove XHTML generator showing WP version
remove_action( 'wp_head', 'wp_generator' );

/*/Text post introduction /*/
//function custom_excerpt_length( $length ) {
//	return 10;
//}
//add_filter( 'excerpt_length', 'custom_excerpt_length', 5 );

// Allow HTML in descriptions
$filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
foreach ( $filters as $filter ) {
	remove_filter($filter, 'wp_filter_kses');
}
// Allow Reigistering With Arabic Laters .. 
add_filter('sanitize_user', 'lenient_username', 1, 3);

function lenient_username($username, $raw_username, $strict) {
	$username = $raw_username;
	$username = wp_strip_all_tags( $username );
	$username = remove_accents( $username );
	$username = preg_replace('|[^a-z0-9 _.\-@ضصثقفغعهخحجدذشسيبلاتنمك طئءؤـرلاىةوزظًٌَُّلإإألأٍِ~ْلآآ]|i', '', $username); 
	$username = preg_replace( '/&.+?;/', '', $username );
	$username = preg_replace( '|\s+|', ' ', $username );
	return $username;
}
// Limit Post Title
function shortened_title() {
$original_title = get_the_title();
$title = html_entity_decode($original_title, ENT_QUOTES, "UTF-8");
// Set Limit
$limit = "50";
// Set End Text
$ending="...";
if(strlen($title) >= ($limit+3)) {
$title = substr($title, 0, $limit) . $ending; }
echo $title;
}