· 9 years ago · Nov 15, 2016, 01:26 AM
1<?php
2/**
3 * Include Vafpress Framework
4 */
5require_once 'vafpress-framework/bootstrap.php';
6/**
7 * Include Custom Data Sources
8 */
9require_once 'admin/data_sources.php';
10/**
11 * Load options, metaboxes, and shortcode generator array templates.
12 */
13// options
14$tmpl_opt = get_template_directory() . '/admin/option-quantum.php';
15//$tmpl_opt = get_template_directory() . '/admin/option.php';
16// metaboxes
17$tmpl_mb1 = get_template_directory() . '/admin/metabox/sample_1.php';
18$mb1 = new VP_Metabox($tmpl_mb1);
19/**
20 * Create instance of Options
21 */
22$theme_options = new VP_Option(array(
23 'is_dev_mode' => false, // dev mode, default to false
24 'option_key' => 'vpt_option', // options key in db, required
25 'page_slug' => 'vpt_option', // options page slug, required
26 'template' => $tmpl_opt, // template file path or array, required
27 'menu_page' => 'themes.php', // parent menu slug or supply `array` (can contains 'icon_url' & 'position') for top level menu
28 'use_auto_group_naming' => true, // default to true
29 'use_util_menu' => true, // default to true, shows utility menu
30 'minimum_role' => 'edit_theme_options', // default to 'edit_theme_options'
31 'layout' => 'fixed', // fluid or fixed, default to fixed
32 'page_title' => __( 'Theme Options', 'vp_textdomain' ), // page title
33 'menu_label' => __( 'Theme Options', 'vp_textdomain' ), // menu label
34));
35
36// Include Auto Desc
37require_once 'lib/auto-desc.php';
38//require_once (TEMPLATEPATH . '/functions/auto-desc.php');
39// Remove query string from static files
40function remove_cssjs_ver( $src ) {
41 if( strpos( $src, '?ver=' ) )
42 $src = remove_query_arg( 'ver', $src );
43 return $src;
44}
45add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
46add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
47
48
49 function pbd_alp_init() {
50 global $wp_query;
51
52 // Add code to index pages.
53
54 // Queue JS and CSS
55 //wp_register_script('jquery', get_template_directory_uri() . '/js/jquery-1.12.0.min.js', false, '1.3.2', true);
56 wp_enqueue_script(
57 'pbd-alp-load-posts',
58 get_template_directory_uri() . '/js/load-posts.js',
59 array('jquery'),
60 '1.0',
61 true
62 );
63 // What page are we on? And what is the pages limit?
64 $max = $wp_query->max_num_pages;
65 $paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
66
67 // Add some parameters for the JS.
68 wp_localize_script(
69 'pbd-alp-load-posts',
70 'pbd_alp',
71 array(
72 'startPage' => $paged,
73 'maxPages' => $max,
74 'nextLink' => next_posts($max, false)
75 )
76 );
77
78 }
79add_action('template_redirect', 'pbd_alp_init');
80
81
82//////////////////////////////////////////////////////////////////
83// Theme set up
84//////////////////////////////////////////////////////////////////
85add_action( 'after_setup_theme', 'quantum_theme_setup' );
86
87if ( !function_exists('quantum_theme_setup') ) {
88
89 function quantum_theme_setup() {
90
91 // Register navigation menu
92 register_nav_menus(
93 array(
94 'main_menu' => __('Main','quantum'),
95 'foot_menu' => __('Footer Menu', 'quantum'),
96 )
97);
98
99 // Localization support
100 load_theme_textdomain('quantum', get_template_directory() . '/lang');
101
102 // Background
103 $sp_background = array(
104 'default-color' => 'f5f5f5'
105 );
106 add_theme_support( 'custom-background', $sp_background );
107
108 // Post formats
109 add_theme_support( 'post-formats', array( 'gallery', 'video', 'audio' ) );
110
111 // Feed Links
112 add_theme_support( 'automatic-feed-links' );
113
114 // Featured image
115 add_theme_support( 'post-thumbnails' );
116 //add_image_size( 'full-thumb', 1080, 0, true );
117 //add_image_size( 'misc-thumb', 500, 380, true );
118
119 }
120 /*
121 * Switch default core markup for search form, comment form, and comments
122 * to output valid HTML5.
123 */
124 add_theme_support( 'html5', array(
125 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
126 ) );
127
128 /*
129 * Enable support for Post Formats.
130 * See http://codex.wordpress.org/Post_Formats
131 */
132 add_theme_support( 'post-formats', array(
133 'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery',
134 ) );
135
136}
137
138class Themeslug_Page_Navigation_Walker extends Walker_Nav_Menu {
139 function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
140 $id_field = $this->db_fields['id'];
141 if ( !empty( $children_elements[ $element->$id_field ] ) ) {
142 $element->classes[] = 'sub-indicator';
143 }
144 Walker_Nav_Menu:: display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
145 }
146}
147
148/* $license_key = get_option('sample_license_key');
149 // API query parameters
150 $api_params = array(
151 'slm_action' => 'slm_check',
152 'secret_key' => '57ff368b1138f7.26031776',
153 'license_key' => $license_key
154 );
155 $response = wp_remote_get(add_query_arg($api_params, VIRALE_SERVER_URL), array('timeout' => 20, 'sslverify' => false));
156 $license_data = json_decode(wp_remote_retrieve_body($response));
157 //var_dump($license_data);//uncomment it to look at the data
158 if($license_data->status == 'active'){
159 add_action( 'wp_enqueue_scripts','quantum_load_scripts' );
160 }
161 else{
162 add_action( 'wp_head','expired_script' );
163 } */
164add_action( 'wp_enqueue_scripts','quantum_load_scripts' );
165function expired_script(){
166 $html .="<div style='padding-top:100px;position:absolute;top:0px;height:100%;width:100%;font-size:72px;background:#000;line-height:90px;text-align:center;color:#fff;'>";
167 $html .= "Your Theme License is INVALID or EXPIRED";
168 $html .="</div>";
169 echo $html;
170}
171function quantum_load_scripts() {
172 // Register scripts and styles
173 wp_register_style('quantum_style', get_stylesheet_directory_uri() . '/css/style.css');
174 wp_register_style('quantum_foundationmin', get_stylesheet_directory_uri() . '/css/foundation.min.css');
175 wp_register_style('googleFonts', 'http://fonts.googleapis.com/css?family=Oswald|Open+sans');
176 wp_register_style( 'quantum_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css');
177 // Enqueue scripts and styles
178 wp_enqueue_style( 'quantum_fontawesome');
179 wp_enqueue_style('quantum_foundationmin');
180 wp_enqueue_style('quantum_style');
181 wp_enqueue_style( 'googleFonts');
182}
183
184function quantum_admin_load_scripts(){
185 wp_enqueue_style( 'quantum_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css');
186 }
187add_action('admin_enqueue_scripts', 'quantum_admin_load_scripts', 200);
188
189//////////////////////////////////////////////////////////////////
190// Register widgets
191//////////////////////////////////////////////////////////////////
192if ( function_exists('register_sidebar') ) {
193 register_sidebar(array(
194 'name' => __('Main Sidebar', 'quantum'),
195 'id' => 'primary-sidebar',
196 'description' => __('Widgets in this area will be shown in the default sidebar.', 'quantum'),
197 'before_title' => '<h3 class="widgettitle">',
198 'after_title' => '</h3>',
199 'before_widget' => '<div class="widget col-4 %2$s">',
200 'after_widget' => '</div>'
201 ));
202 register_sidebar(array(
203 'name' => __('Footer (3 widgets columns)', 'quantum'),
204 'id' => 'main-footer',
205 'description' => __('Widgets in this area will be shown in the footer. Max 3 widgets.', 'quantum'),
206 'before_title' => '<h3 class="widgettitle">',
207 'after_title' => '</h3>',
208 'before_widget' => '<li class="widget col-4 %2$s">',
209 'after_widget' => '</li>'
210 ));
211}
212
213require_once (TEMPLATEPATH . '/widgets/social-profiles.php');
214require_once (TEMPLATEPATH . '/widgets/thumbnail-posts.php');
215require_once (TEMPLATEPATH . '/widgets/facebook-widget.php');
216require_once (TEMPLATEPATH . '/widgets/trends-widget.php');
217add_action('widgets_init', 'quantum_load_widgets');
218function quantum_load_widgets(){
219 register_widget('Quantum_Social_Profiles');
220 register_widget('Quantum_Thumbnail_Posts');
221 register_widget('Quantum_Facebook_Widget');
222 register_widget('Quantum_Google_Trends');
223}
224
225
226// Krise pagination
227function kriesi_pagination($pages = '', $range = 2){
228 $showitems = ($range * 3)+1;
229
230 global $paged;
231 if(empty($paged)) $paged = 1;
232
233 if($pages == ''){
234 global $wp_query;
235 $pages = $wp_query->max_num_pages;
236 if(!$pages) {
237 $pages = 1;
238 }
239 }
240
241 $output = '';
242
243 if(1 != $pages){
244 $output .= "<div class='pagination'><ul>";
245 if($paged > 2 && $paged > $range+1 && $showitems < $pages) $output .= "<li><a class='btn' href='".get_pagenum_link(1)."'>". __('First', 'quantum') ."</a></li> ";
246
247 for ($i=1; $i <= $pages; $i++){
248 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
249 $output .= ($paged == $i)? "<li class='active'><a class='btn' href='".get_pagenum_link($i)."'>".$i."</a></li> ":"<li><a class='btn' href='".get_pagenum_link($i)."'>".$i."</a></li> ";
250 }
251 }
252
253 if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) $output .= "<li><a class='btn' href='".get_pagenum_link($pages)."'>". __('Last', 'quantum') ."</a></li> ";
254 $output.= "</ul></div>";
255 }
256
257 return $output;
258 }
259
260//CUSTOM EXCERPT LENGTH
261function quantum_excerpt($len=20, $trim="..."){
262 $limit = $len+1;
263 $excerpt = explode(' ', get_the_excerpt(), $limit);
264 $num_words = count($excerpt);
265 if($num_words >= $len){
266 $last_item=array_pop($excerpt);
267 }
268 else{
269 $trim="";
270 }
271 $excerpt = implode(" ",$excerpt)."$trim";
272 echo $excerpt;
273}
274
275function quantum_breadcrumbs() {
276
277 $delimiter = ' » ';
278 echo '<div id="breadcrumbs">';
279 echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="';
280 echo home_url();
281 echo '" rel="nofollow">'.sprintf( __( "Home","quantum"));
282 echo '</a></span>'.$delimiter.'';
283 if (is_single()) {
284 $categories = get_the_category();
285 if ( $categories ) {
286 $level = 0;
287 $hierarchy_arr = array();
288 foreach ( $categories as $cat ) {
289 $anc = get_ancestors( $cat->term_id, 'category' );
290 $count_anc = count( $anc );
291 if ( 0 < $count_anc && $level < $count_anc ) {
292 $level = $count_anc;
293 $hierarchy_arr = array_reverse( $anc );
294 array_push( $hierarchy_arr, $cat->term_id );
295 }
296 }
297 if ( empty( $hierarchy_arr ) ) {
298 $category = $categories[0];
299 echo '<span typeof="v:Breadcrumb"><a href="'. esc_url( get_category_link( $category->term_id ) ).'" rel="v:url" property="v:title">'.esc_html( $category->name ).'</a></span>'.$delimiter.'';
300 } else {
301 foreach ( $hierarchy_arr as $cat_id ) {
302 $category = get_term_by( 'id', $cat_id, 'category' );
303 echo '<span typeof="v:Breadcrumb"><a href="'. esc_url( get_category_link( $category->term_id ) ).'" rel="v:url" property="v:title">'.esc_html( $category->name ).'</a></span>'.$delimiter.'';
304 }
305 }
306 }
307 echo "<span><span>";
308 the_title();
309 echo "</span></span>";
310 } elseif (is_page()) {
311 global $post;
312 if ( $post->post_parent ) {
313 $parent_id = $post->post_parent;
314 $breadcrumbs = array();
315 while ( $parent_id ) {
316 $page = get_page( $parent_id );
317 $breadcrumbs[] = '<span typeof="v:Breadcrumb"><a href="'.esc_url( get_permalink( $page->ID ) ).'" rel="v:url" property="v:title">'.esc_html( get_the_title($page->ID) ). '</a></span>'.$delimiter.'';
318 $parent_id = $page->post_parent;
319 }
320 $breadcrumbs = array_reverse( $breadcrumbs );
321 foreach ( $breadcrumbs as $crumb ) { echo $crumb; }
322 }
323 echo "<span><span>";
324 the_title();
325 echo "</span></span>";
326 } elseif (is_category()) {
327 global $wp_query;
328 $cat_obj = $wp_query->get_queried_object();
329 $this_cat_id = $cat_obj->term_id;
330 $hierarchy_arr = get_ancestors( $this_cat_id, 'category' );
331 if ( $hierarchy_arr ) {
332 $hierarchy_arr = array_reverse( $hierarchy_arr );
333 foreach ( $hierarchy_arr as $cat_id ) {
334 $category = get_term_by( 'id', $cat_id, 'category' );
335 echo '<span typeof="v:Breadcrumb"><a href="'.esc_url( get_category_link( $category->term_id ) ).'" rel="v:url" property="v:title">'.esc_html( $category->name ).'</a></span>'.$delimiter.'';
336 }
337 }
338 echo "<span><span>";
339 single_cat_title();
340 echo "</span></span>";
341 } elseif (is_author()) {
342 echo "<span><span>";
343 if(get_query_var('author_name')) :
344 $curauth = get_user_by('slug', get_query_var('author_name'));
345 else :
346 $curauth = get_userdata(get_query_var('author'));
347 endif;
348 echo esc_html( $curauth->nickname );
349 echo "</span></span>";
350 } elseif (is_search()) {
351 echo "<span><span>";
352 the_search_query();
353 echo "</span></span>";
354 } elseif (is_tag()) {
355 echo "<span><span>";
356 single_tag_title();
357 echo "</span></span>";
358 }
359 echo '</div>';
360}
361
362//////////////////////////////////////////////////////////////////
363// COMMENTS LAYOUT
364//////////////////////////////////////////////////////////////////
365
366 function quantum_comment($comment, $args, $depth) {
367 $GLOBALS['comment'] = $comment;
368
369 ?>
370 <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
371
372 <div class="thecomment">
373
374 <div class="author-img">
375 <?php echo get_avatar($comment,$args['avatar_size']); ?>
376 </div>
377
378 <div class="comment-text">
379 <span class="reply">
380 <?php comment_reply_link(array_merge( $args, array('reply_text' => __('Reply', 'quantum'), 'depth' => $depth, 'max_depth' => $args['max_depth'])), $comment->comment_ID); ?>
381 <?php edit_comment_link(__('Edit', 'quantum')); ?>
382 </span>
383 <span class="author"><?php echo get_comment_author_link(); ?></span>
384 <span class="date"><?php printf(__('%1$s at %2$s', 'quantum'), get_comment_date(), get_comment_time()) ?></span>
385 <?php if ($comment->comment_approved == '0') : ?>
386 <em><i class="icon-info-sign"></i> <?php _e('Comment awaiting approval', 'quantum'); ?></em>
387 <br />
388 <?php endif; ?>
389 <?php comment_text(); ?>
390 </div>
391
392 </div>
393
394
395 </li>
396
397 <?php
398 }
399
400// total share class function
401function facebook_like_share_count ($id) {
402 $url = get_permalink($id);
403 $response = wp_remote_get("https://api.facebook.com/method/links.getStats?format=json&urls=" . $url);
404 $body = $response["body"];
405 $body = json_decode($body);
406
407 if($body[0]->share_count)
408 {
409 return $facebook_count = $body[0]->share_count;
410 }
411 else
412 {
413 return $facebook_count = 0;
414 }
415 };
416
417function twitter_tweet_count ( $id ) {
418 $url = get_permalink($id);
419 $api = file_get_contents( 'https://cdn.api.twitter.com/1/urls/count.json?url=' . $url );
420
421 $count = json_decode( $api );
422
423 return $count->count;
424 };
425function pinterest_pins ( $id ) {
426 $url = get_permalink($id);
427 $api = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback%20&url=' . $url );
428
429 $body = preg_replace( '/^receiveCount\((.*)\)$/', '\\1', $api );
430
431 $count = json_decode( $body );
432 $pin_count = $count->count;
433 if ( !isset($pin_count ) ) {
434 return $pin_count = '0';
435 }
436 else {
437 return $pin_count;
438 }
439
440};
441function google_plusones( $id ) {
442 $url = get_permalink($id);
443 $curl = curl_init();
444 curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc" );
445 curl_setopt( $curl, CURLOPT_POST, 1 );
446 curl_setopt( $curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]' );
447 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
448 curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) );
449 $curl_results = curl_exec( $curl );
450 curl_close( $curl );
451 $json = json_decode( $curl_results, true );
452
453 $gplus_count = intval( $json[0]['result']['metadata']['globalCounts']['count'] );
454 if ( !isset($gplus_count ) ) {
455 return $gplus_count = '0';
456 }
457 else {
458 return $gplus_count;
459 }
460 };
461
462function twentyfourteen_the_attached_image() {
463 $post = get_post();
464 $attachment_url = wp_get_attachment_url();
465 $attachment_ids = get_posts( array(
466 'post_parent' => $post->post_parent,
467 'fields' => 'ids',
468 'numberposts' => -1,
469 'post_status' => 'inherit',
470 'post_type' => 'attachment',
471 'post_mime_type' => 'image',
472 'order' => 'ASC',
473 'orderby' => 'menu_order ID',
474 ) );
475
476 printf( '<a href="%1$s" rel="attachment">%2$s</a>',
477 esc_url( $attachment_url ),
478 wp_get_attachment_image( $post->ID,'full' )
479 );
480}
481
482//include Most Share
483require_once(TEMPLATEPATH. '/lib/most-share/most-shared-widget.php');
484
485
486add_action('wp_head', 'quantum_custom_color_css');
487 function quantum_custom_color_css(){
488 $custom_css_code = vp_option('vpt_option.custom_css');
489 $main_color = vp_option('vpt_option.main_color');
490 $bg_color = vp_option('vpt_option.bg_color');
491 $fix_img = vp_option('vpt_option.fix_img');
492 $custom_css='';
493
494 $custom_css .= 'a, #mc_embed_signup h2,.share-container,.widgettitle .fa,.single .total-count{color:'.$main_color.';}';
495 $custom_css .='#header,#mc_embed_signup .button,.search-form .search-submit,.cat-com .comments,.most-shared li::before,#pbd-alp-load-posts a:link, #pbd-alp-load-posts a:visited,.cat-title,.post-comments span.reply a,#respond #submit,.mobile-nav>div>ul{background:'.$main_color.';}';
496 $custom_css .='{border-color:'.$main_color.'}';
497 $custom_css .='body{background:'.$bg_color.';}';
498 if ($fix_img == 'value_1'){
499 $custom_css .='.home-thumb img{width:100%;height:auto}';
500 }
501 $custom_css .= $custom_css_code;
502 $css_output = "<!-- Custom CSS -->\n<style type=\"text/css\">\n" . $custom_css . "\n</style>";
503
504 if(!empty($custom_css)) {
505 echo $css_output;
506 }
507 }
508
509// Grab google trends
510function get_url($url){
511$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8';
512$ch = curl_init();
513curl_setopt($ch, CURLOPT_URL, $url);
514curl_setopt($ch, CURLOPT_HEADER, 0);
515curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
516curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
517curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
518curl_setopt($ch, CURLOPT_USERAGENT, $agent);
519$result = curl_exec($ch);
520return $result;
521}
522function autoset_featured() {
523 global $post;
524 $already_has_thumb = has_post_thumbnail($post->ID);
525 if (!$already_has_thumb) {
526 $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
527 if ($attached_image) {
528 foreach ($attached_image as $attachment_id => $attachment) {
529 set_post_thumbnail($post->ID, $attachment_id);
530 }
531 }
532 }
533 }
534add_action('the_post', 'autoset_featured');
535add_action('save_post', 'autoset_featured');
536add_action('draft_to_publish', 'autoset_featured');
537add_action('new_to_publish', 'autoset_featured');
538add_action('pending_to_publish', 'autoset_featured');
539add_action('future_to_publish', 'autoset_featured');
540
541function msp_is_post()
542{
543 if(is_single() && !is_attachment())
544 {
545 global $post;
546 $last_update = get_post_meta($post->ID, "msp_last_update", true);
547 if($last_update)
548 {
549 if(time() - 21600 > $last_update)
550 {
551 msp_update($post->ID);
552 }
553 }
554 else
555 {
556 msp_update($post->ID);
557 }
558 }
559}
560add_action("wp", "msp_is_post");
561function msp_update($id) {
562$url = get_permalink($id);
563$json = json_decode(file_get_contents("http://graph.facebook.com/?ids=".$url),true);
564$facebook_count = $json[$url]['share']['share_count'];
565
566 //twitter shares
567/* $response = file_get_contents("http://urls.api.twitter.com/1/urls/count.json?url=" . $url);
568 $body = $response["body"];
569 $body = json_decode($body);
570 if($body->count)
571 {
572 $twitter_count = $body->count;
573 }
574 else
575 {
576 $twitter_count = 0;
577 } */
578$twitter_count = 0;
579 // Pinterest Pin
580 $api_pin = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback%20&url=' . $url );
581 $body = preg_replace( '/^receiveCount\((.*)\)$/', '\\1', $api_pin );
582 $count = json_decode( $body );
583 $pin_count = $count->count;
584 if ( !isset($pin_count ) ) {
585 $pin_count = 0;
586 }
587 else {
588 $pin_count;
589 }
590 // Google Plus
591 $curl = curl_init();
592 curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc" );
593 curl_setopt( $curl, CURLOPT_POST, 1 );
594 curl_setopt( $curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]' );
595 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
596 curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) );
597 $curl_results = curl_exec( $curl );
598 curl_close( $curl );
599 $json = json_decode( $curl_results, true );
600 $gplus_count = intval( $json[0]['result']['metadata']['globalCounts']['count'] );
601 if ( !isset($gplus_count ) ) {
602 $gplus_count = '0';
603 }
604 else {
605 $gplus_count;
606 }
607 $total = $facebook_count + $twitter_count + $pin_count + $gplus_count;
608
609 update_post_meta($id, "msp_share_count", $total);
610 update_post_meta($id, "msp_last_update", time());
611}
612function fb_opengraph() {
613 global $post;
614
615 if(is_single()) {
616 if(has_post_thumbnail($post->ID)) {
617 $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
618 } else {
619 $img_src[] = get_stylesheet_directory_uri() . '/img/fb_share.jpg';
620 }
621 if($excerpt = $post->post_content) {
622 $excerpt = strip_tags($post->post_content);
623 $excerpt = str_replace("", "'", $excerpt);
624 $excerpt = substr($excerpt, 0, 299);
625 } else {
626 $excerpt = get_bloginfo('description');
627 }
628 ?>
629
630 <meta property="og:title" content="<?php echo the_title(); ?>"/>
631 <meta property="og:description" content="<?php echo $excerpt; ?>"/>
632 <meta property="og:type" content="article"/>
633 <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
634 <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
635 <meta property="og:image" content="<?php echo $img_src[0]; ?>"/>
636 <meta name="twitter:card" content="summary" />
637 <meta name="twitter:description" content="<?php echo $excerpt; ?>" />
638 <meta name="twitter:title" content="<?php the_title();?>" />
639 <meta name="twitter:image" content="<?php echo $img_src[0]; ?>" />
640
641<?php
642 } else {
643 return;
644 }
645}
646add_action('wp_head', 'fb_opengraph', 5);
647
648
649function fb_count($id) {
650 $url = get_permalink($id);
651 //facebook shares
652$json = json_decode(file_get_contents("http://graph.facebook.com/?ids=".$url),true);
653$facebook_count = $json[$url]['share']['share_count'];
654return $facebook_count;
655}
656
657add_filter('manage_edit-post_columns', 'my_extra_cake_columns');
658function my_extra_cake_columns($columns) {
659 $columns['share'] =__('Share','myplugindomain');
660 return $columns;
661}
662add_action( 'manage_posts_custom_column', 'my_cake_column_content', 10, 2 );
663function my_cake_column_content( $column_name, $post_id ) {
664 if ( 'share' != $column_name )
665 return;
666 //Get number of share from post meta
667 $share = get_post_meta($post_id, 'msp_share_count', true);
668 echo intval($share);
669}
670add_filter( 'manage_edit-post_sortable_columns', 'my_sortable_cake_column' );
671function my_sortable_cake_column( $columns ) {
672 $columns['share'] = 'share';
673
674 //To make a column 'un-sortable' remove it from the array
675 //unset($columns['date']);
676
677 return $columns;
678}
679add_action( 'pre_get_posts', 'my_slice_orderby' );
680function my_slice_orderby( $query ) {
681 if( ! is_admin() )
682 return;
683
684 $orderby = $query->get( 'orderby');
685
686 if( 'share' == $orderby ) {
687 $query->set('meta_key','msp_share_count');
688 $query->set('orderby','meta_value_num');
689 }
690}
691
692include('functions/auto-thumb-video.php');
693?>