PluginProbe
Document Embedder – let visitors read files without downloading / 1.2
Document Embedder – let visitors read files without downloading v1.2
2.3.1 2.3.0 2.2.1 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.3 1.7.4 1.7.6 1.7.9 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 2.0.0 2.0.1 2.0.2 All 30 releases
document-emberdder / document-embedder.php

document-embedder.php in Document Embedder – let visitors read files without downloading 1.2, at document-embedder.php

394 lines 15.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.2
7 * Author: bPlugins
8 * Author URI: http://abuhayatpolash.com
9 * License: GPLv3
10 * Text Domain: document-emberdder
11 * Domain Path: /languages
12 */
13
14 function svp_load_textdomain() {
15 load_plugin_textdomain( 'document-emberdder', false, dirname( __FILE__ ) . "/languages" );
16 }
17
18 add_action( "plugins_loaded", 'svp_load_textdomain' );
19
20 /*Some Set-up*/
21 define('PPV_PLUGIN_DIR', WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/' );
22
23 // Guten Block
24
25 include_once('gutenblock/index.php');
26
27 //Remove post update massage and link
28 function ppv_updated_messages( $messages ) {
29 $messages['ppt_viewer'][1] = __('Updated ');
30 return $messages;
31 }
32 add_filter('post_updated_messages','ppv_updated_messages');
33
34
35
36 /*-------------------------------------------------------------------------------*/
37 /* Register Custom Post Types
38 /*-------------------------------------------------------------------------------*/
39 add_action( 'init', 'ppv_create_post_type' );
40 function ppv_create_post_type() {
41 register_post_type( 'ppt_viewer',
42 array(
43 'labels' => array(
44 'name' => __( 'Document Embedder'),
45 'singular_name' => __( 'Document Embedder' ),
46 'add_new' => __( 'Add New Doc' ),
47 'add_new_item' => __( 'Add New Doc' ),
48 'edit_item' => __( 'Edit' ),
49 'new_item' => __( 'New item' ),
50 'view_item' => __( 'View item' ),
51 'search_items' => __( 'Search'),
52 'not_found' => __( 'Sorry, we couldn\'t find the power point file you are looking for.' )
53 ),
54 'public' => false,
55 'show_ui' => true,
56 'publicly_queryable' => true,
57 'exclude_from_search' => true,
58 'menu_position' => 14,
59 'show_in_rest' => true,
60 'menu_icon' =>PPV_PLUGIN_DIR .'/img/doc.png',
61 'has_archive' => false,
62 'hierarchical' => false,
63 'capability_type' => 'post',
64 'rewrite' => array( 'slug' => 'ppt_viewer' ),
65 'supports' => array( 'title' )
66 )
67 );
68 }
69
70 /*-------------------------------------------------------------------------------*/
71 /* Metabox
72 /*-------------------------------------------------------------------------------*/
73
74 include_once('metabox/meta-box-class/my-meta-box-class.php');
75 include_once('metabox/class-usage-demo.php');
76 //include_once('tinymce/ewic-tinymce.php');
77
78 /*-------------------------------------------------------------------------------*/
79 /* Hide & Disabled View, Quick Edit and Preview Button
80 /*-------------------------------------------------------------------------------*/
81 function ppv_remove_row_actions( $idtions ) {
82 global $post;
83 if( $post->post_type == 'ppt_viewer' ) {
84 unset( $idtions['view'] );
85 unset( $idtions['inline hide-if-no-js'] );
86 }
87 return $idtions;
88 }
89
90 if ( is_admin() ) {
91 add_filter( 'post_row_actions','ppv_remove_row_actions', 10, 2 );}
92
93 /*-------------------------------------------------------------------------------*/
94 /* HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
95 /*-------------------------------------------------------------------------------*/
96
97 function ppv_hide_publishing_actions(){
98 $my_post_type = 'ppt_viewer';
99 global $post;
100 if($post->post_type == $my_post_type){
101 echo '
102 <style type="text/css">
103 #misc-publishing-actions,
104 #minor-publishing-actions{
105 display:none;
106 }
107 </style>
108 ';
109 }
110 }
111 add_action('admin_head-post.php', 'ppv_hide_publishing_actions');
112 add_action('admin_head-post-new.php', 'ppv_hide_publishing_actions');
113
114 /*-------------------------------------------------------------------------------*/
115 /* Change publish button to save.
116 /*-------------------------------------------------------------------------------*/
117
118 add_filter( 'gettext', 'ppv_change_publish_button', 10, 2 );
119
120 function ppv_change_publish_button( $translation, $text ) {
121 if ( 'ppt_viewer' == get_post_type())
122 if ( $text == 'Publish' )
123 return 'Save';
124
125 return $translation;
126 }
127
128
129 // ONLY MOVIE CUSTOM TYPE POSTS
130 add_filter('manage_ppt_viewer_posts_columns', 'ST4_columns_head_only_ppt_viewer', 10);
131 add_action('manage_ppt_viewer_posts_custom_column', 'ST4_columns_content_only_ppt_viewer', 10, 2);
132
133 // CREATE TWO FUNCTIONS TO HANDLE THE COLUMN
134 function ST4_columns_head_only_ppt_viewer($defaults) {
135 $defaults['directors_name'] = 'ShortCode';
136 return $defaults;
137 }
138 function ST4_columns_content_only_ppt_viewer($column_name, $post_ID) {
139 if ($column_name == 'directors_name') {
140 // show content of 'directors_name' column
141 echo '<input onClick="this.select();" value="[doc id='. $post_ID . ']" >';
142 }
143 }
144
145 /*-------------------------------------------------------------------------------*/
146 // sub menu page
147 /*-------------------------------------------------------------------------------*/
148 add_action('admin_menu', 'ppv_custom_submenu_page');
149
150 function ppv_custom_submenu_page() {
151 add_submenu_page( 'edit.php?post_type=ppt_viewer', 'Developer', 'Developer', 'manage_options', 'ppv_submenu_page', 'ppv_submenu_page_callback' );
152 }
153
154 function ppv_submenu_page_callback() {
155
156 echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>';
157 echo '<h2>Developer</h2>
158 <h2>Md Abu hayat polash</h2>
159 <h4>Professional Web Developer (Freelancer)</h4>
160 <h5>Web : <a href="http://abuhayatpolash.com">www.abuhayatpolash.com</h5></a>
161 <h5>Hire Me : <a target="_blank" href="https://www.upwork.com/freelancers/~01c73e1e24504a195e">On Upwork.com</h5>
162 Email: <a href="mailto:abuhayat.du@gmail.com">abuhayat.du@gmail.com </a>
163 <h5>Skype: ah_polash</h5>
164 <br />
165
166 ';
167 echo '</div>';
168
169 }
170 //How to use
171 add_action('admin_menu', 'svp_howto_page');
172
173 function svp_howto_page() {
174 add_submenu_page( 'edit.php?post_type=ppt_viewer', 'How To Use', 'How To Use', 'manage_options', 'ppv_howto', 'ppv_howto_page_callback' );
175 }
176
177 function ppv_howto_page_callback() {
178
179 echo "<div class='wrap'><div id='icon-tools' class='icon32'></div>";
180 echo "<h2>How to use ? </h2>
181 <h2>We made a movie for you ! Watch it and learn. </h2>
182 <br/>
183 <style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 85%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://www.youtube.com/embed//mUlMpuPMP5Q' frameborder='0' allowfullscreen></iframe></div>
184 <br />
185 ";
186 echo '</div>';
187 }
188
189 /*
190 <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>
191 */
192
193
194 /*-------------------------------------------------------------------------------*/
195 // Dashboard widget
196 /*-------------------------------------------------------------------------------*/
197
198
199 function ppv_add_dashboard_widgets() {
200 wp_add_dashboard_widget( 'ppv_example_dashboard_widget', 'Get The PRO For Free', 'ppv_dashboard_widget_function' );
201
202 global $wp_meta_boxes;
203 $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
204 $example_widget_backup = array( 'ppv_example_dashboard_widget' => $normal_dashboard['ppv_example_dashboard_widget'] );
205 unset( $normal_dashboard['ppv_example_dashboard_widget'] );
206 $sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard );
207 $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
208 }
209 function ppv_dashboard_widget_function() {echo'
210
211
212 <ul style="list-style-type: square;padding-left:10px;">
213 <li><a href="https://wordpress.org/support/plugin/document-emberdder/reviews/?filter=5#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733; Rate </a> <strong>Document Embedder</strong> Plugin</li>
214 <li>Take a screenshot along with your name and the comment. </li>
215 <li><a href="mailto:pluginsfeedback@gmail.com">Email us</a> ( pluginsfeedback@gmail.com ) the screenshot.</li>
216 <li>You will receive a promo Code of 100% Off.</li>
217 </ul>
218 Your Review is very important to us as it helps us to grow more.</p>
219
220 <p>Not happy, Sorry for that. You can request for improvement. </p>
221
222 <table>
223 <tr>
224 <td><a class="button button-primary button-large" href="https://wordpress.org/support/plugin/html5-video-player/reviews/?filter=5#new-post" target="_blank">Write Review</a></td>
225 <td><a class="button button-primary button-large" href="mailto:abuhayat.du@gmail.com" target="_blank">Request Improvement</a></td>
226 </tr>
227 </table>
228
229 '; }
230 add_action( 'wp_dashboard_setup', 'ppv_add_dashboard_widgets' );
231
232
233 // Adds a box to the main column on the Post and Page edit screens.
234
235 function ppv_myplugin_add_meta_box() {
236 add_meta_box(
237 'donation',
238 __( 'Upgrade to Pro', 'myplugin_textdomain' ),
239 'ppv_callback_donation',
240 'ppt_viewer'
241 );
242 add_meta_box(
243 'myplugin_sectionid',
244 __( 'Try LightBox Addons', 'myplugin_textdomain' ),
245 'ppv_addons_callback',
246 'ppt_viewer',
247 'side'
248 );
249 add_meta_box(
250 'ppv_sectionid',
251 __( 'Get The Pro For Free', 'myplugin_textdomain' ),
252 'ppv_follow_me_callback',
253 'ppt_viewer',
254 'side'
255 );
256 }
257 add_action( 'add_meta_boxes', 'ppv_myplugin_add_meta_box' );
258 function ppv_callback_donation( ) {echo '
259 <script src="https://gumroad.com/js/gumroad-embed.js"></script>
260 <div class="gumroad-product-embed" data-gumroad-product-id="depro" data-outbound-embed="true"><a target="_blank" href="https://gumroad.com/l/depro">Loading...</a></div>
261 ';};
262 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>
263 <p>LightBox Addons enable you to open any doc in a Nice LightBox</p>
264 <table>
265 <tr>
266 <td><a class="button button-primary button-large" href="http://bit.ly/2IHqXpc" target="_blank">See Demo </a></td>
267 <td><a class="button button-primary button-large" href="http://bit.ly/327b8A9" target="_blank">Buy Now</a></td>
268 </tr>
269 </table>
270 ';};
271
272
273 function ppv_follow_me_callback( ) {echo'
274
275
276 <ul style="list-style-type: square;padding-left:10px;">
277 <li><a href="https://wordpress.org/support/plugin/document-emberdder/reviews/?filter=5#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733; Rate </a> <strong>Document Embedder</strong> Plugin</li>
278 <li>Take a screenshot along with your name and the comment. </li>
279 <li><a href="mailto:pluginsfeedback@gmail.com">Email us</a> ( pluginsfeedback@gmail.com ) the screenshot.</li>
280 <li>You will receive a promo Code of 100% Off.</li>
281 </ul>
282 Your Review is very important to us as it helps us to grow more.</p>
283
284 <p>Not happy, Sorry for that. You can request for improvement. </p>
285
286 <table>
287 <tr>
288 <td><a class="button button-primary button-large" href="https://wordpress.org/support/plugin/html5-audio-player/reviews/?filter=5#new-post" target="_blank">Write Review</a></td>
289 <td><a class="button button-primary button-large" href="mailto:abuhayat.du@gmail.com" target="_blank">Request Improvement</a></td>
290 </tr>
291 </table>
292
293 '; };
294
295
296 /* 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">&#9733;&#9733;&#9733;&#9733;&#9733; rating.</a> Your Review is very important to us as it helps us to grow more.
297 <p>Need some improvement ? <a href="mailto:abuhayat.du@gmail.com">Please let me know </a> how can i improve the Plugin.</p>';}; */
298
299
300 // Add shortcode area
301
302 add_action('edit_form_after_title','ppv_shortcode_area');
303 function ppv_shortcode_area(){
304 global $post;
305 if($post->post_type=='ppt_viewer'){
306 ?>
307 <div>
308 <label style="cursor: pointer;font-size: 13px; font-style: italic;" for="ppv_shortcode">Copy this shortcode and paste it into your post, page, or text widget content:</label>
309 <span style="display: block; margin: 5px 0; background:#1e8cbe; ">
310 <input type="text" id="ppv_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; ?>]" />
311
312 </span>
313 </div>
314 <?php
315 }}
316
317
318 // Add Sortcode
319 function ppv_cpt_content_func($atts){
320 extract( shortcode_atts( array(
321
322 'id' => null,
323
324 ), $atts ) );
325
326 $file_url=get_post_meta($id,'_groupped_ppv_file_url', true);
327 $ext_url=get_post_meta($id,'_groupped_ppv_ext_url', true);
328 if (is_array($file_url)){$url=$file_url['url'];}else{$url=$ext_url;}
329
330 $width=get_post_meta($id,'ppt_ppv_width', true);
331 $height= get_post_meta($id,'ppt_ppv_height', true);
332
333 if ($width==''){$width='100%';} else{$width=$width.'px';}
334 if ($height==''){$height='600px'; } else {$height=$height.'px';}
335 $frame_style= 'width:'.$width.'; '. 'height:'. $height. ';';
336 $base_url = '//docs.google.com/gview?embedded=true&url=';
337 ?>
338 <?php ob_start(); ?>
339 <?php
340 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{
341 // show file name
342 $file_name=get_post_meta($id,'ppt_ppv_file_name', true);
343 if($file_name=='on'){$file_name=basename($url); echo '<p style="padding-left:10px;">File Name: '.$file_name.'</p>';}
344
345 // Download button
346 if(get_post_meta($id,'ppt_ppv_download',true)=='on'){
347 $down_btn_color= get_post_meta($id,'ppt_ppv_download_btn_color', true);
348 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>';}
349
350
351 echo '<iframe id="s_pdf_frame" src="' . $base_url . $url . '" style="float:left; padding:10px;' . $frame_style . '" frameborder="0"></iframe>';
352 }
353 ?>
354 <?php $output = ob_get_clean();return $output;//print $output; // debug ?>
355
356 <?php
357 }
358 add_shortcode('doc','ppv_cpt_content_func');
359
360 //Demo Sub menu
361
362 add_action('admin_menu', 'ppv_add_custom_link_into_cpt_menu');
363 function ppv_add_custom_link_into_cpt_menu() {
364 global $submenu;
365 $link = 'https://bplugins.page.link/doc-embedder';
366 $submenu['edit.php?post_type=ppt_viewer'][] = array( 'PRO Version Demo', 'manage_options', $link, 'meta'=>'target="_blank"' );
367 }
368
369 function ppv_my_custom_script() {
370 ?>
371 <script type="text/javascript">
372 jQuery(document).ready( function($) {
373 $( "ul#adminmenu a[href$='https://bplugins.page.link/doc-embedder']" ).attr( 'target', '_blank' );
374 });
375 </script>
376 <?php
377 }
378 add_action( 'admin_head', 'ppv_my_custom_script' );
379
380 // After activation redirect
381
382 register_activation_hook(__FILE__, 'ppv_plugin_activate');
383 add_action('admin_init', 'ppv_plugin_redirect');
384
385 function ppv_plugin_activate() {
386 add_option('ppv_plugin_do_activation_redirect', true);
387 }
388
389 function ppv_plugin_redirect() {
390 if (get_option('ppv_plugin_do_activation_redirect', false)) {
391 delete_option('ppv_plugin_do_activation_redirect');
392 wp_redirect('edit.php?post_type=ppt_viewer&page=ppv_howto');
393 }
394 }