| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Document Embedder |
| 4 |
* Plugin URI: https://bplugins.com/document-embedder-demo/ |
| 5 |
* Description: Embed Any document easily in wordpress such as word, excel, powerpoint, pdf and more |
| 6 |
* Version: 1.1 |
| 7 |
* Author: Abu Hayat Polash |
| 8 |
* Author URI: http://abuhayatpolash.com |
| 9 |
* License: GPLv3 |
| 10 |
*/ |
| 11 |
|
| 12 |
/*Some Set-up*/ |
| 13 |
define('PPV_PLUGIN_DIR', WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/' ); |
| 14 |
|
| 15 |
//Remove post update massage and link |
| 16 |
function ppv_updated_messages( $messages ) { |
| 17 |
$messages['ppt_viewer'][1] = __('Updated '); |
| 18 |
return $messages; |
| 19 |
} |
| 20 |
add_filter('post_updated_messages','ppv_updated_messages'); |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
/*-------------------------------------------------------------------------------*/ |
| 25 |
/* Register Custom Post Types |
| 26 |
/*-------------------------------------------------------------------------------*/ |
| 27 |
add_action( 'init', 'ppv_create_post_type' ); |
| 28 |
function ppv_create_post_type() { |
| 29 |
register_post_type( 'ppt_viewer', |
| 30 |
array( |
| 31 |
'labels' => array( |
| 32 |
'name' => __( 'Document Embedder'), |
| 33 |
'singular_name' => __( 'Document Embedder' ), |
| 34 |
'add_new' => __( 'Add New Doc' ), |
| 35 |
'add_new_item' => __( 'Add New Doc' ), |
| 36 |
'edit_item' => __( 'Edit' ), |
| 37 |
'new_item' => __( 'New item' ), |
| 38 |
'view_item' => __( 'View item' ), |
| 39 |
'search_items' => __( 'Search'), |
| 40 |
'not_found' => __( 'Sorry, we couldn\'t find the power point file you are looking for.' ) |
| 41 |
), |
| 42 |
'public' => false, |
| 43 |
'show_ui' => true, |
| 44 |
'publicly_queryable' => true, |
| 45 |
'exclude_from_search' => true, |
| 46 |
'menu_position' => 14, |
| 47 |
'menu_icon' =>PPV_PLUGIN_DIR .'/img/doc.png', |
| 48 |
'has_archive' => false, |
| 49 |
'hierarchical' => false, |
| 50 |
'capability_type' => 'post', |
| 51 |
'rewrite' => array( 'slug' => 'ppt_viewer' ), |
| 52 |
'supports' => array( 'title' ) |
| 53 |
) |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
/*-------------------------------------------------------------------------------*/ |
| 58 |
/* Metabox |
| 59 |
/*-------------------------------------------------------------------------------*/ |
| 60 |
|
| 61 |
include_once('metabox/meta-box-class/my-meta-box-class.php'); |
| 62 |
include_once('metabox/class-usage-demo.php'); |
| 63 |
//include_once('tinymce/ewic-tinymce.php'); |
| 64 |
|
| 65 |
/*-------------------------------------------------------------------------------*/ |
| 66 |
/* Hide & Disabled View, Quick Edit and Preview Button |
| 67 |
/*-------------------------------------------------------------------------------*/ |
| 68 |
function ppv_remove_row_actions( $idtions ) { |
| 69 |
global $post; |
| 70 |
if( $post->post_type == 'ppt_viewer' ) { |
| 71 |
unset( $idtions['view'] ); |
| 72 |
unset( $idtions['inline hide-if-no-js'] ); |
| 73 |
} |
| 74 |
return $idtions; |
| 75 |
} |
| 76 |
|
| 77 |
if ( is_admin() ) { |
| 78 |
add_filter( 'post_row_actions','ppv_remove_row_actions', 10, 2 );} |
| 79 |
|
| 80 |
/*-------------------------------------------------------------------------------*/ |
| 81 |
/* HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button |
| 82 |
/*-------------------------------------------------------------------------------*/ |
| 83 |
|
| 84 |
function ppv_hide_publishing_actions(){ |
| 85 |
$my_post_type = 'ppt_viewer'; |
| 86 |
global $post; |
| 87 |
if($post->post_type == $my_post_type){ |
| 88 |
echo ' |
| 89 |
<style type="text/css"> |
| 90 |
#misc-publishing-actions, |
| 91 |
#minor-publishing-actions{ |
| 92 |
display:none; |
| 93 |
} |
| 94 |
</style> |
| 95 |
'; |
| 96 |
} |
| 97 |
} |
| 98 |
add_action('admin_head-post.php', 'ppv_hide_publishing_actions'); |
| 99 |
add_action('admin_head-post-new.php', 'ppv_hide_publishing_actions'); |
| 100 |
|
| 101 |
/*-------------------------------------------------------------------------------*/ |
| 102 |
/* Change publish button to save. |
| 103 |
/*-------------------------------------------------------------------------------*/ |
| 104 |
|
| 105 |
add_filter( 'gettext', 'ppv_change_publish_button', 10, 2 ); |
| 106 |
|
| 107 |
function ppv_change_publish_button( $translation, $text ) { |
| 108 |
if ( 'ppt_viewer' == get_post_type()) |
| 109 |
if ( $text == 'Publish' ) |
| 110 |
return 'Save'; |
| 111 |
|
| 112 |
return $translation; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
// ONLY MOVIE CUSTOM TYPE POSTS |
| 117 |
add_filter('manage_ppt_viewer_posts_columns', 'ST4_columns_head_only_ppt_viewer', 10); |
| 118 |
add_action('manage_ppt_viewer_posts_custom_column', 'ST4_columns_content_only_ppt_viewer', 10, 2); |
| 119 |
|
| 120 |
// CREATE TWO FUNCTIONS TO HANDLE THE COLUMN |
| 121 |
function ST4_columns_head_only_ppt_viewer($defaults) { |
| 122 |
$defaults['directors_name'] = 'ShortCode'; |
| 123 |
return $defaults; |
| 124 |
} |
| 125 |
function ST4_columns_content_only_ppt_viewer($column_name, $post_ID) { |
| 126 |
if ($column_name == 'directors_name') { |
| 127 |
// show content of 'directors_name' column |
| 128 |
echo '<input onClick="this.select();" value="[doc id='. $post_ID . ']" >'; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/*-------------------------------------------------------------------------------*/ |
| 133 |
// sub menu page |
| 134 |
/*-------------------------------------------------------------------------------*/ |
| 135 |
add_action('admin_menu', 'ppv_custom_submenu_page'); |
| 136 |
|
| 137 |
function ppv_custom_submenu_page() { |
| 138 |
add_submenu_page( 'edit.php?post_type=ppt_viewer', 'Developer', 'Developer', 'manage_options', 'ppv_submenu_page', 'ppv_submenu_page_callback' ); |
| 139 |
} |
| 140 |
|
| 141 |
function ppv_submenu_page_callback() { |
| 142 |
|
| 143 |
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>'; |
| 144 |
echo '<h2>Developer</h2> |
| 145 |
<h2>Md Abu hayat polash</h2> |
| 146 |
<h4>Professional Web Developer (Freelancer)</h4> |
| 147 |
<h5>Web : <a href="http://abuhayatpolash.com">www.abuhayatpolash.com</h5></a> |
| 148 |
<h5>Hire Me : <a href="http://fiverr.com/abuhayat">www.fiverr.com/abuhayat</h5></a> |
| 149 |
Email: <a href="mailto:abuhayat.du@gmail.com">abuhayat.du@gmail.com </a> |
| 150 |
<h5>Skype: ah_polash</h5> |
| 151 |
<br /> |
| 152 |
|
| 153 |
'; |
| 154 |
echo '</div>'; |
| 155 |
|
| 156 |
} |
| 157 |
//How to use |
| 158 |
add_action('admin_menu', 'svp_howto_page'); |
| 159 |
|
| 160 |
function svp_howto_page() { |
| 161 |
add_submenu_page( 'edit.php?post_type=ppt_viewer', 'How To Use', 'How To Use', 'manage_options', 'ppv_howto', 'ppv_howto_page_callback' ); |
| 162 |
} |
| 163 |
|
| 164 |
function ppv_howto_page_callback() { |
| 165 |
|
| 166 |
echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>'; |
| 167 |
echo '<h2>How to use </h2> |
| 168 |
<h2>Watch the video to learn how to use the plugin. </h2> |
| 169 |
<br/> |
| 170 |
Coming Soon... |
| 171 |
<br /> |
| 172 |
|
| 173 |
'; |
| 174 |
echo '</div>'; |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
/* |
| 179 |
<iframe width="789" height="375" src="https://www.youtube.com/embed/LJym2Pe1h2k" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> |
| 180 |
*/ |
| 181 |
|
| 182 |
|
| 183 |
/*-------------------------------------------------------------------------------*/ |
| 184 |
// Dashboard widget |
| 185 |
/*-------------------------------------------------------------------------------*/ |
| 186 |
|
| 187 |
|
| 188 |
function ppv_add_dashboard_widgets() { |
| 189 |
wp_add_dashboard_widget( 'ppv_example_dashboard_widget', 'Support Document Embedder', 'ppv_dashboard_widget_function' ); |
| 190 |
|
| 191 |
global $wp_meta_boxes; |
| 192 |
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; |
| 193 |
$example_widget_backup = array( 'ppv_example_dashboard_widget' => $normal_dashboard['ppv_example_dashboard_widget'] ); |
| 194 |
unset( $normal_dashboard['ppv_example_dashboard_widget'] ); |
| 195 |
$sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard ); |
| 196 |
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; |
| 197 |
} |
| 198 |
function ppv_dashboard_widget_function() { |
| 199 |
|
| 200 |
// Display whatever it is you want to show. |
| 201 |
echo ' |
| 202 |
<p>It is hard to continue development and support for this plugin without contributions from users like you. If you enjoy using the plugin and find it useful, please consider support by <b>DONATION</b> or <b>BUY THE PRO VERSION (Ad Less)</b> of the Plugin. Your support will help encourage and support the plugin’s continued development and better user support.</p> |
| 203 |
<center> |
| 204 |
<a target="_blank" href="https://gum.co/wpdonate"><div><img width="200" src="'.PPV_PLUGIN_DIR.'img/donation.png'.'" alt="Donate Now" /></div></a> |
| 205 |
</center> |
| 206 |
<br /> |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
';} |
| 211 |
add_action( 'wp_dashboard_setup', 'ppv_add_dashboard_widgets' ); |
| 212 |
|
| 213 |
|
| 214 |
// Adds a box to the main column on the Post and Page edit screens. |
| 215 |
|
| 216 |
function ppv_myplugin_add_meta_box() { |
| 217 |
add_meta_box( |
| 218 |
'donation', |
| 219 |
__( 'Support Document Embedder', 'myplugin_textdomain' ), |
| 220 |
'ppv_callback_donation', |
| 221 |
'ppt_viewer' |
| 222 |
); |
| 223 |
add_meta_box( |
| 224 |
'myplugin_sectionid', |
| 225 |
__( 'Try LightBox Addons', 'myplugin_textdomain' ), |
| 226 |
'ppv_addons_callback', |
| 227 |
'ppt_viewer', |
| 228 |
'side' |
| 229 |
); |
| 230 |
add_meta_box( |
| 231 |
'myplugin', |
| 232 |
__( 'Please show some love', 'myplugin_textdomain' ), |
| 233 |
'ppv_callback', |
| 234 |
'ppt_viewer', |
| 235 |
'side' |
| 236 |
); |
| 237 |
} |
| 238 |
add_action( 'add_meta_boxes', 'ppv_myplugin_add_meta_box' ); |
| 239 |
function ppv_callback_donation( ) {echo 'If you found this Plugin helpful and wish to support our opensource Project, Then You can <a target="_blank" href="https://gum.co/wpdonate">DONATE</a> us any amount you want. <a target="_blank" href="https://gum.co/wpdonate">Donate Now</a>';}; |
| 240 |
function ppv_addons_callback(){echo'<a target="_blank" href="http://bit.ly/2GiuI2G"><img style="width:100%" src="'.PPV_PLUGIN_DIR.'/img/upwork.png" ></a> |
| 241 |
<p>LightBox Addons enable you to open any doc in a Nice LightBox</p> |
| 242 |
<table> |
| 243 |
<tr> |
| 244 |
<td><a class="button button-primary button-large" href="http://bit.ly/2IHqXpc" target="_blank">See Demo </a></td> |
| 245 |
<td><a class="button button-primary button-large" href="http://bit.ly/327b8A9" target="_blank">Buy Now</a></td> |
| 246 |
</tr> |
| 247 |
</table> |
| 248 |
';}; |
| 249 |
|
| 250 |
function ppv_callback( ) {echo 'If you like <strong>Document Embedder </strong> Plugin, please leave us a <a href="https://wordpress.org/support/plugin/document-emberdder/reviews/?filter=5#new-post" target="_blank">★★★★★ rating.</a> Your Review is very important to us as it helps us to grow more. |
| 251 |
<p>Need some improvement ? <a href="mailto:abuhayat.du@gmail.com">Please let me know </a> how can i improve the Plugin.</p>';}; |
| 252 |
|
| 253 |
|
| 254 |
// Add shortcode area |
| 255 |
|
| 256 |
add_action('edit_form_after_title','ppv_shortcode_area'); |
| 257 |
function ppv_shortcode_area(){ |
| 258 |
global $post; |
| 259 |
if($post->post_type=='ppt_viewer'){ |
| 260 |
?> |
| 261 |
<div> |
| 262 |
<label style="cursor: pointer;font-size: 13px; font-style: italic;" for="h5vp_shortcode">Copy this shortcode and paste it into your post, page, or text widget content:</label> |
| 263 |
<span style="display: block; margin: 5px 0; background:#1e8cbe; "> |
| 264 |
<input type="text" id="h5vp_shortcode" style="font-size: 12px; border: none; box-shadow: none;padding: 4px 8px; width:100%; background:transparent; color:white;" onfocus="this.select();" readonly="readonly" value="[doc id=<?php echo $post->ID; ?>]" /> |
| 265 |
|
| 266 |
</span> |
| 267 |
</div> |
| 268 |
<?php |
| 269 |
}} |
| 270 |
|
| 271 |
|
| 272 |
// Add Sortcode |
| 273 |
function ppv_cpt_content_func($atts){ |
| 274 |
extract( shortcode_atts( array( |
| 275 |
|
| 276 |
'id' => null, |
| 277 |
|
| 278 |
), $atts ) ); |
| 279 |
|
| 280 |
$file_url=get_post_meta($id,'_groupped_ppv_file_url', true); |
| 281 |
$ext_url=get_post_meta($id,'_groupped_ppv_ext_url', true); |
| 282 |
if (is_array($file_url)){$url=$file_url['url'];}else{$url=$ext_url;} |
| 283 |
|
| 284 |
$width=get_post_meta($id,'ppt_ppv_width', true); |
| 285 |
$height= get_post_meta($id,'ppt_ppv_height', true); |
| 286 |
|
| 287 |
if ($width==''){$width='100%';} else{$width=$width.'px';} |
| 288 |
if ($height==''){$height='600px'; } else {$height=$height.'px';} |
| 289 |
$frame_style= 'width:'.$width.'; '. 'height:'. $height. ';'; |
| 290 |
$base_url = '//docs.google.com/gview?embedded=true&url='; |
| 291 |
?> |
| 292 |
<?php ob_start(); ?> |
| 293 |
<?php |
| 294 |
if($url==''){ echo '<h2>Ooops... You forgot to Select a document. Please select a file or paste a external document link to show here. </h2>';} else{ |
| 295 |
// show file name |
| 296 |
$file_name=get_post_meta($id,'ppt_ppv_file_name', true); |
| 297 |
if($file_name=='on'){$file_name=basename($url); echo '<p style="padding-left:10px;">File Name: '.$file_name.'</p>';} |
| 298 |
|
| 299 |
// Download button |
| 300 |
if(get_post_meta($id,'ppt_ppv_download',true)=='on'){ |
| 301 |
$down_btn_color= get_post_meta($id,'ppt_ppv_download_btn_color', true); |
| 302 |
echo '<p style="padding-left:10px;"><a class="s_pdf_download_link" href="'.$url.'" download><button style="margin-bottom:10px;'.'background-color:'.$down_btn_color.';" class="ppv_download_bttn">'.get_post_meta($id,'ppt_ppv_download_btn_text',true).'</button></a></p>';} |
| 303 |
|
| 304 |
|
| 305 |
echo '<iframe id="s_pdf_frame" src="' . $base_url . $url . '" style="float:left; padding:10px;' . $frame_style . '" frameborder="0"></iframe>'; |
| 306 |
} |
| 307 |
?> |
| 308 |
<?php $output = ob_get_clean();return $output;//print $output; // debug ?> |
| 309 |
|
| 310 |
<?php |
| 311 |
} |
| 312 |
add_shortcode('doc','ppv_cpt_content_func'); |