Sindbad~EG File Manager

Current Path : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt/panel/metabox/
Upload File :
Current File : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt/panel/metabox/settings.php

<?php
/*
 * Security 	: blocking direct access
 * Source		: http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");

/*
 * Metabox enqueue js and css
 *
*/
function mwp_metabox_enqueue() {	
	wp_register_style( 'mwp-metabox', get_template_directory_uri() . '/panel/css/metabox.css' );
	wp_enqueue_style( 'mwp-metabox' );
	wp_enqueue_script( 'mwp-metabox-tabs', get_template_directory_uri() . '/panel/js/metabox-tabs.js' , array( 'jquery' ) );
	wp_enqueue_script( 'mwp-metabox-upload', get_template_directory_uri() . '/panel/js/metabox-upload.js' , array( 'jquery' ) );
	wp_enqueue_script( 'mwp-amp-url', get_template_directory_uri() . '/panel/js/amp_url.js' );
	wp_enqueue_script( 'mwp-amp-url-helper', get_template_directory_uri() . '/panel/js/amp_url_converter.js' );
}
add_action( 'admin_print_styles-post-new.php', 'mwp_metabox_enqueue');
add_action( 'admin_print_styles-post.php', 'mwp_metabox_enqueue' );

add_filter('script_loader_tag', 'mwp_metabox_defer_attribute', 10, 2);
function mwp_metabox_defer_attribute($tag, $handle) {
   if (is_admin()) {
		if ( 'mwp-metabox-tabs' 	!== $handle )
		if ( 'mwp-metabox-upload'   !== $handle )
		if ( 'mwp-amp-url'        	!== $handle )	
		if ( 'mwp-amp-url-helper'   !== $handle )
			return $tag;
		return str_replace( ' src', ' defer="defer" src', $tag );
	} else {
		return $tag;
	}
}

/*
 * Get Options List
 *
*/
require_once( get_template_directory() . '/panel/metabox/options.php' );
/*
 * Metabox admin
 *
*/
function mwp_add_metabox() {
    global $metaboxes;
	
	$post_types = get_post_types();
	if(!empty($metaboxes)) {
        foreach($metaboxes as $id => $metabox) {
			foreach ( $post_types as $post_type ) {
				if ( 'page' == $post_type || 'attachment' == $post_type || 'nav_menu_item' == $post_type || 'customize_changeset' == $post_type || 'revision' == $post_type) {
					continue;
				}
				add_meta_box($id, $metabox['title'], 'mwp_display_metabox', $post_type, $metabox['context'], $metabox['priority']);
			}
		}
	}
}
add_action('admin_menu', 'mwp_add_metabox' );

/*
 * Metabox Display
 *
*/
function mwp_display_metabox($post, $args) {
    
	global $themename, $metaboxes, $post;
 
    $custom = get_post_custom($post->ID);
    $tabs = $metaboxes[$args['id']]['tabs'];
 
    /** Wrapper **/
 
    $output = "<div class='tabs'>";
 
    /** Nonce **/
    $output .= '<input type="hidden" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
 
    /** Menu **/
    $output .= '<ul class="tab_nav">';
 
    $i = 0;
    foreach($tabs as $id => $tab)
    {
        $output .= '<li><a href="#'.$id.'"';
        if($i == 0)
            $output .= ' class="current_tab"';
        $output .= '><i class="'.$id.'"></i><span>'.__($tab['title'], $themename).'</span></a></li>';
        $i++;
    }
 
    $output .= '</ul>';
 
    /** Content **/
    $output .= '';
 
    foreach($tabs as $id => $tab) {
       
		$fields = $tab['fields'];
 
        $output .= '<div class="tab_content" id="'.$id.'">';
 
        $iter = 0;
 
        foreach($fields as $id => $field) {
            
			$output .= '<div class="row">
                    <div class="label">
                        <label for="'.$id.'">'.$field['title'].'</label>';
                    $output .= '</div>
                    <div class="value">';
 
            switch($field['type']) {
                
				case "text":
					if ( ! isset( $field['std'] ))
						$custom[$id][0] = $field['std'];
					elseif ( ! isset( $custom[$id][0] ) )
						$custom[$id][0] = '';
                    $output .= '<input type="text" class="text" id="'.$id.'" name="'.$id.'" value="'.$custom[$id][0].'" size="'.$field['size'].'" />';
                break;
				
				case "textarea":
					if ( ! isset( $field['std'] ))
						$custom[$id][0] = $field['std'];
					elseif ( ! isset( $custom[$id][0] ) )
						$custom[$id][0] = '';
					$output .= '<textarea name="'.$id. '" id="'.$id.'" cols="40" rows="4">'.$custom[$id][0].'</textarea>';
				break;
 
                case "checkbox":
					if ( ! isset( $field['std'] ))
						$custom[$id][0] = $field['std'];
					elseif ( ! isset( $custom[$id][0] ) )
						$custom[$id][0] = 0;
					
                    $output .= '<input type="checkbox" id="'.$id.'" name="'.$id.'" size="'.$field['size'].'"';
                    if($custom[$id][0]) $output .= " checked='checked'";
                    $output .= '/>';
					
                break;
				
				case 'select':
					if ( ! isset( $field['std'] ))
						$custom[$id][0] = $field['std'];
					elseif ( ! isset( $custom[$id][0] ) )
						$custom[$id][0] = '';
						
					$output .= '<select name="'. $id. '" id="'. $id. '">';
						foreach ( $field['options'] as $key => $label ) {
							$selected = $custom[$id][0] == $key ? ' selected="selected"' : '';
							$output .= '<option value="' . esc_attr( $key ) . '" ' . $selected . '>' . esc_html( $label ) . '</option>';
						}
					$output .= '</select>';
				break;
				
 
                case "radio":
					
					if ( ! isset( $field['std'] ))
						$custom[$id][0] = $field['std'];
					elseif ( ! isset( $custom[$id][0] ) )
						$custom[$id][0] = '';
					
                    $val = $custom[$id][0];
                    $radio_id = $id;
 
                    foreach($field['options'] as $id => $label) :
                        if($val == $id) $checked = ' checked="checked"';
                        else $checked = "";
                        if (is_rtl()) {
							$output .= "<div class='grad'><input$checked type='radio' name='".$radio_id."' value='".$id."' id='".$id."_$iter' /><label for='".$id."_$iter'>".$label."</label></div>";
						} else {
							$output .= "<div class='grad'><label for='".$id."_$iter'>".$label."</label><input$checked type='radio' name='".$radio_id."' value='".$id."' id='".$id."_$iter' /></div>";
						}
                    
					endforeach;
                   
					
                break;
				
				case 'upload':
					if ( ! isset( $field['std'] ))
						$custom[$id][0] = $field['std'];
					elseif ( ! isset( $custom[$id][0] ) )
						$custom[$id][0] = '';
				    $output .= '<input type="text" name="'.$id.'" id="'.$id.'" class="upload-url" value="'.$custom[$id][0].'" /><input id="st_upload_button" class="button st_upload_button" type="button" name="upload_button" value="Upload" /><br>';
				break;
				
				case 'custom-button':
				
					$button_img = get_template_directory_uri(). '/panel/images/spinner.gif';
					$button_text = __( 'Fetch new scrape information', MWP_TEXT_DOMAIN);
					$button_link = 'https://www.facebook.com/sharer/sharer.php?u='. get_the_permalink( $post->ID );
					$button_link_text = __( 'Preview post on facebook', MWP_TEXT_DOMAIN);
					$output .= '<span class="scrap button button-primary">'.$button_text.'</span><img class="preload" src="'.$button_img.'"><a class="fb-share button" href="'.$button_link.'">'.$button_link_text.'</a><br><div class="fb-result"></div>';

				break;
				
				case 'generate-amp-cache':
					$button_text = __( 'Generate URL', MWP_TEXT_DOMAIN);
					$output .= '<input class="generate-amp-cache" type="url" value="'.get_permalink( $post->ID ).'/amp" name="input" id="input" style="display:none;">
					<span id="execute" class="button button-primary">'.$button_text.'</span>
					<span id="result" class="fb-result"></span>';

				break;

            }
 
            $output .= '</div>';
			
			if(!empty($field['description']))
				$output .= '<small>'.$field['description'].'</small>';
						
			$output .= '</div>';		
			
 
            $iter++;
        }
        $output .= '<div class="clear"></div></div>';
    }
 
    $output .= '</div>';
 
    echo $output;
	?>
	<script>
	jQuery.noConflict();
	jQuery(document).ready(function($) {
		pid = <?php echo $post->ID; ?>;
		
		$('body').on("click", "span.scrap", function(){
			$('.preload').show();
			$('.fb-result').empty();
			//$('.fb-share').hide();
			$.ajax({
				type: "GET",
				url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
				dataType: 'html',
				data: ({action:'mwp_fb_fetch_scrape', pid:pid}),
				success: function(data){
					$('.preload').hide();
					$(data).appendTo('.fb-result');
					$('.fb-result').show();
				}
			});
		});
		$('.fb-share').click(function(e) {
			e.preventDefault();
			window.open($(this).attr('href'), 'fbShareWindow', 'height=450, width=550, top=' + ($(window).height() / 2 - 275) + ', left=' + ($(window).width() / 2 - 225) + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
			return false;
		});
	});
	</script>
	<?php
}
/*
 * Save Metabox Fields
 *
*/
function mwp_save_metabox($post_id) {
	
	global $metaboxes;

	// verify nonce
	if ( !isset($_POST['custom_meta_box_nonce']) || !wp_verify_nonce( $_POST['custom_meta_box_nonce'], basename(__FILE__) ))
		return $post_id;
	
 
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;
 
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id))
            return $post_id;
    } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
	
    $post_types = get_post_types();

    // loop through fields and save the data
    foreach($metaboxes as $id => $metabox) {
       
		$tabs = $metaboxes[$id]['tabs'];
		
		foreach ( $post_types as $post_type ) {
			if ( 'page' == $post_type || 'attachment' == $post_type || 'nav_menu_item' == $post_type || 'customize_changeset' == $post_type || 'revision' == $post_type) {
				continue;
			}
			
			foreach($tabs as $id => $tab) {
				   
				$fields = $tab['fields'];
					
				foreach($fields as $id => $field) {
					$old = get_post_meta($post_id, $id, true);
					$new = ( isset ( $_POST[$id] ) === true ? $_POST[$id] : '' );
					if ($new && $new != $old) {
						update_post_meta($post_id, $id, $new);
					} elseif ('' == $new && $old || !isset($_POST[$id])) {
						delete_post_meta($post_id, $id, $old);
					}
				}	
			}
		}
	 
    }
}
add_action( 'save_post', 'mwp_save_metabox' );

// https://stackoverflow.com/a/19870632
// https://stackoverflow.com/a/18322405
// https://stackoverflow.com/a/12101700 access token need for object update
function mwp_fb_fetch_scrape() {
	
	$postid 	= $_GET['pid'];
	$token		= mwp_option('facebook-access-token');
	// Flush W3 Total Cache
	if (function_exists('w3tc_pgcache_flush_post')) : 
		w3tc_pgcache_flush_post($postid);
	endif;
	
	// Flush WP Super Cache
	if (function_exists('wp_cache_post_change')) :
		wp_cache_post_change($postid);
	endif;
	
	// Facebook scrape
	$url = 'https://graph.facebook.com';
	$param = array(
		'id' 			=> urlencode(get_permalink( $postid )),
		'scrape' 		=> 'true',
		'method' 		=> 'post',
		'access_token' 	=> $token
	);
	
	//wp_remote_get(add_query_arg( $param, $url ));
	
	$response = wp_remote_post(add_query_arg( $param, $url ));
	
	$response = json_decode( wp_remote_retrieve_body( $response )) ;

	if ( is_wp_error( $response ) ) {
			return false;
	}
	
	if ($response && isset($response->error)) {
		
		// An access token is required to request this resource.
		// Error validating access token: The session was invalidated explicitly using an API call.
		// An access token is required to request this resource.
		foreach ($response->error as $index => $value) {
			if ($index == 'message') {
				echo  '<div class="fb-message">'.$value.'</div>';
			}
		}
		
	} else {
		
	}
	//print_r($response);
	die();
}
add_action('wp_ajax_mwp_fb_fetch_scrape', 'mwp_fb_fetch_scrape');

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists