· 9 years ago · Jan 22, 2017, 12:26 PM
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 }
164function expired_script(){
165 $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;'>";
166 $html .= "Your Theme License is INVALID or EXPIRED";
167 $html .="</div>";
168 echo $html;
169}
170function quantum_load_scripts() {
171 // Register scripts and styles
172 wp_register_style('quantum_style', get_stylesheet_directory_uri() . '/css/style.css');
173 wp_register_style('quantum_foundationmin', get_stylesheet_directory_uri() . '/css/foundation.min.css');
174 wp_register_style('googleFonts', 'http://fonts.googleapis.com/css?family=Oswald|Open+sans');
175 wp_register_style( 'quantum_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css');
176 // Enqueue scripts and styles
177 wp_enqueue_style( 'quantum_fontawesome');
178 wp_enqueue_style('quantum_foundationmin');
179 wp_enqueue_style('quantum_style');
180 wp_enqueue_style( 'googleFonts');
181}
182
183function quantum_admin_load_scripts(){
184 wp_enqueue_style( 'quantum_fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css');
185 }
186add_action('admin_enqueue_scripts', 'quantum_admin_load_scripts', 200);
187
188//////////////////////////////////////////////////////////////////
189// Register widgets
190//////////////////////////////////////////////////////////////////
191if ( function_exists('register_sidebar') ) {
192 register_sidebar(array(
193 'name' => __('Main Sidebar', 'quantum'),
194 'id' => 'primary-sidebar',
195 'description' => __('Widgets in this area will be shown in the default sidebar.', 'quantum'),
196 'before_title' => '<h3 class="widgettitle">',
197 'after_title' => '</h3>',
198 'before_widget' => '<div class="widget col-4 %2$s">',
199 'after_widget' => '</div>'
200 ));
201 register_sidebar(array(
202 'name' => __('Footer (3 widgets columns)', 'quantum'),
203 'id' => 'main-footer',
204 'description' => __('Widgets in this area will be shown in the footer. Max 3 widgets.', 'quantum'),
205 'before_title' => '<h3 class="widgettitle">',
206 'after_title' => '</h3>',
207 'before_widget' => '<li class="widget col-4 %2$s">',
208 'after_widget' => '</li>'
209 ));
210}
211
212require_once (TEMPLATEPATH . '/widgets/social-profiles.php');
213require_once (TEMPLATEPATH . '/widgets/thumbnail-posts.php');
214require_once (TEMPLATEPATH . '/widgets/facebook-widget.php');
215require_once (TEMPLATEPATH . '/widgets/trends-widget.php');
216add_action('widgets_init', 'quantum_load_widgets');
217function quantum_load_widgets(){
218 register_widget('Quantum_Social_Profiles');
219 register_widget('Quantum_Thumbnail_Posts');
220 register_widget('Quantum_Facebook_Widget');
221 register_widget('Quantum_Google_Trends');
222}
223
224
225// Krise pagination
226function kriesi_pagination($pages = '', $range = 2){
227 $showitems = ($range * 3)+1;
228
229 global $paged;
230 if(empty($paged)) $paged = 1;
231
232 if($pages == ''){
233 global $wp_query;
234 $pages = $wp_query->max_num_pages;
235 if(!$pages) {
236 $pages = 1;
237 }
238 }
239
240 $output = '';
241
242 if(1 != $pages){
243 $output .= "<div class='pagination'><ul>";
244 if($paged > 2 && $paged > $range+1 && $showitems < $pages) $output .= "<li><a class='btn' href='".get_pagenum_link(1)."'>". __('First', 'quantum') ."</a></li> ";
245
246 for ($i=1; $i <= $pages; $i++){
247 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
248 $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> ";
249 }
250 }
251
252 if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) $output .= "<li><a class='btn' href='".get_pagenum_link($pages)."'>". __('Last', 'quantum') ."</a></li> ";
253 $output.= "</ul></div>";
254 }
255
256 return $output;
257 }
258
259//CUSTOM EXCERPT LENGTH
260function quantum_excerpt($len=20, $trim="..."){
261 $limit = $len+1;
262 $excerpt = explode(' ', get_the_excerpt(), $limit);
263 $num_words = count($excerpt);
264 if($num_words >= $len){
265 $last_item=array_pop($excerpt);
266 }
267 else{
268 $trim="";
269 }
270 $excerpt = implode(" ",$excerpt)."$trim";
271 echo $excerpt;
272}
273
274function quantum_breadcrumbs() {
275
276 $delimiter = ' » ';
277 echo '<div id="breadcrumbs">';
278 echo '<span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="';
279 echo home_url();
280 echo '" rel="nofollow">'.sprintf( __( "Home","quantum"));
281 echo '</a></span>'.$delimiter.'';
282 if (is_single()) {
283 $categories = get_the_category();
284 if ( $categories ) {
285 $level = 0;
286 $hierarchy_arr = array();
287 foreach ( $categories as $cat ) {
288 $anc = get_ancestors( $cat->term_id, 'category' );
289 $count_anc = count( $anc );
290 if ( 0 < $count_anc && $level < $count_anc ) {
291 $level = $count_anc;
292 $hierarchy_arr = array_reverse( $anc );
293 array_push( $hierarchy_arr, $cat->term_id );
294 }
295 }
296 if ( empty( $hierarchy_arr ) ) {
297 $category = $categories[0];
298 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.'';
299 } else {
300 foreach ( $hierarchy_arr as $cat_id ) {
301 $category = get_term_by( 'id', $cat_id, 'category' );
302 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.'';
303 }
304 }
305 }
306 echo "<span><span>";
307 the_title();
308 echo "</span></span>";
309 } elseif (is_page()) {
310 global $post;
311 if ( $post->post_parent ) {
312 $parent_id = $post->post_parent;
313 $breadcrumbs = array();
314 while ( $parent_id ) {
315 $page = get_page( $parent_id );
316 $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.'';
317 $parent_id = $page->post_parent;
318 }
319 $breadcrumbs = array_reverse( $breadcrumbs );
320 foreach ( $breadcrumbs as $crumb ) { echo $crumb; }
321 }
322 echo "<span><span>";
323 the_title();
324 echo "</span></span>";
325 } elseif (is_category()) {
326 global $wp_query;
327 $cat_obj = $wp_query->get_queried_object();
328 $this_cat_id = $cat_obj->term_id;
329 $hierarchy_arr = get_ancestors( $this_cat_id, 'category' );
330 if ( $hierarchy_arr ) {
331 $hierarchy_arr = array_reverse( $hierarchy_arr );
332 foreach ( $hierarchy_arr as $cat_id ) {
333 $category = get_term_by( 'id', $cat_id, 'category' );
334 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.'';
335 }
336 }
337 echo "<span><span>";
338 single_cat_title();
339 echo "</span></span>";
340 } elseif (is_author()) {
341 echo "<span><span>";
342 if(get_query_var('author_name')) :
343 $curauth = get_user_by('slug', get_query_var('author_name'));
344 else :
345 $curauth = get_userdata(get_query_var('author'));
346 endif;
347 echo esc_html( $curauth->nickname );
348 echo "</span></span>";
349 } elseif (is_search()) {
350 echo "<span><span>";
351 the_search_query();
352 echo "</span></span>";
353 } elseif (is_tag()) {
354 echo "<span><span>";
355 single_tag_title();
356 echo "</span></span>";
357 }
358 echo '</div>';
359}
360
361//////////////////////////////////////////////////////////////////
362// COMMENTS LAYOUT
363//////////////////////////////////////////////////////////////////
364
365 function quantum_comment($comment, $args, $depth) {
366 $GLOBALS['comment'] = $comment;
367
368 ?>
369 <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
370
371 <div class="thecomment">
372
373 <div class="author-img">
374 <?php echo get_avatar($comment,$args['avatar_size']); ?>
375 </div>
376
377 <div class="comment-text">
378 <span class="reply">
379 <?php comment_reply_link(array_merge( $args, array('reply_text' => __('Reply', 'quantum'), 'depth' => $depth, 'max_depth' => $args['max_depth'])), $comment->comment_ID); ?>
380 <?php edit_comment_link(__('Edit', 'quantum')); ?>
381 </span>
382 <span class="author"><?php echo get_comment_author_link(); ?></span>
383 <span class="date"><?php printf(__('%1$s at %2$s', 'quantum'), get_comment_date(), get_comment_time()) ?></span>
384 <?php if ($comment->comment_approved == '0') : ?>
385 <em><i class="icon-info-sign"></i> <?php _e('Comment awaiting approval', 'quantum'); ?></em>
386 <br />
387 <?php endif; ?>
388 <?php comment_text(); ?>
389 </div>
390
391 </div>
392
393
394 </li>
395
396 <?php
397 }
398
399// total share class function
400function facebook_like_share_count ($id) {
401 $url = get_permalink($id);
402 $response = wp_remote_get("https://api.facebook.com/method/links.getStats?format=json&urls=" . $url);
403 $body = $response["body"];
404 $body = json_decode($body);
405
406 if($body[0]->share_count)
407 {
408 return $facebook_count = $body[0]->share_count;
409 }
410 else
411 {
412 return $facebook_count = 0;
413 }
414 };
415
416function twitter_tweet_count ( $id ) {
417 $url = get_permalink($id);
418 $api = file_get_contents( 'https://cdn.api.twitter.com/1/urls/count.json?url=' . $url );
419
420 $count = json_decode( $api );
421
422 return $count->count;
423 };
424function pinterest_pins ( $id ) {
425 $url = get_permalink($id);
426 $api = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback%20&url=' . $url );
427
428 $body = preg_replace( '/^receiveCount\((.*)\)$/', '\\1', $api );
429
430 $count = json_decode( $body );
431 $pin_count = $count->count;
432 if ( !isset($pin_count ) ) {
433 return $pin_count = '0';
434 }
435 else {
436 return $pin_count;
437 }
438
439};
440function google_plusones( $id ) {
441 $url = get_permalink($id);
442 $curl = curl_init();
443 curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc" );
444 curl_setopt( $curl, CURLOPT_POST, 1 );
445 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"}]' );
446 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
447 curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) );
448 $curl_results = curl_exec( $curl );
449 curl_close( $curl );
450 $json = json_decode( $curl_results, true );
451
452 $gplus_count = intval( $json[0]['result']['metadata']['globalCounts']['count'] );
453 if ( !isset($gplus_count ) ) {
454 return $gplus_count = '0';
455 }
456 else {
457 return $gplus_count;
458 }
459 };
460
461function twentyfourteen_the_attached_image() {
462 $post = get_post();
463 $attachment_url = wp_get_attachment_url();
464 $attachment_ids = get_posts( array(
465 'post_parent' => $post->post_parent,
466 'fields' => 'ids',
467 'numberposts' => -1,
468 'post_status' => 'inherit',
469 'post_type' => 'attachment',
470 'post_mime_type' => 'image',
471 'order' => 'ASC',
472 'orderby' => 'menu_order ID',
473 ) );
474
475 printf( '<a href="%1$s" rel="attachment">%2$s</a>',
476 esc_url( $attachment_url ),
477 wp_get_attachment_image( $post->ID,'full' )
478 );
479}
480
481//include Most Share
482require_once(TEMPLATEPATH. '/lib/most-share/most-shared-widget.php');
483
484
485add_action('wp_head', 'quantum_custom_color_css');
486 function quantum_custom_color_css(){
487 $custom_css_code = vp_option('vpt_option.custom_css');
488 $main_color = vp_option('vpt_option.main_color');
489 $bg_color = vp_option('vpt_option.bg_color');
490 $fix_img = vp_option('vpt_option.fix_img');
491 $custom_css='';
492
493 $custom_css .= 'a, #mc_embed_signup h2,.share-container,.widgettitle .fa,.single .total-count{color:'.$main_color.';}';
494 $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.';}';
495 $custom_css .='{border-color:'.$main_color.'}';
496 $custom_css .='body{background:'.$bg_color.';}';
497 if ($fix_img == 'value_1'){
498 $custom_css .='.home-thumb img{width:100%;height:auto}';
499 }
500 $custom_css .= $custom_css_code;
501 $css_output = "<!-- Custom CSS -->\n<style type=\"text/css\">\n" . $custom_css . "\n</style>";
502
503 if(!empty($custom_css)) {
504 echo $css_output;
505 }
506 }
507
508// Grab google trends
509function get_url($url){
510$agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8';
511$ch = curl_init();
512curl_setopt($ch, CURLOPT_URL, $url);
513curl_setopt($ch, CURLOPT_HEADER, 0);
514curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
515curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
516curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
517curl_setopt($ch, CURLOPT_USERAGENT, $agent);
518$result = curl_exec($ch);
519return $result;
520}
521function autoset_featured() {
522 global $post;
523 $already_has_thumb = has_post_thumbnail($post->ID);
524 if (!$already_has_thumb) {
525 $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
526 if ($attached_image) {
527 foreach ($attached_image as $attachment_id => $attachment) {
528 set_post_thumbnail($post->ID, $attachment_id);
529 }
530 }
531 }
532 }
533add_action('the_post', 'autoset_featured');
534add_action('save_post', 'autoset_featured');
535add_action('draft_to_publish', 'autoset_featured');
536add_action('new_to_publish', 'autoset_featured');
537add_action('pending_to_publish', 'autoset_featured');
538add_action('future_to_publish', 'autoset_featured');
539
540function msp_is_post()
541{
542 if(is_single() && !is_attachment())
543 {
544 global $post;
545 $last_update = get_post_meta($post->ID, "msp_last_update", true);
546 if($last_update)
547 {
548 if(time() - 21600 > $last_update)
549 {
550 msp_update($post->ID);
551 }
552 }
553 else
554 {
555 msp_update($post->ID);
556 }
557 }
558}
559add_action("wp", "msp_is_post");
560function msp_update($id) {
561$url = get_permalink($id);
562$json = json_decode(file_get_contents("http://graph.facebook.com/?ids=".$url),true);
563$facebook_count = $json[$url]['share']['share_count'];
564
565 //twitter shares
566/* $response = file_get_contents("http://urls.api.twitter.com/1/urls/count.json?url=" . $url);
567 $body = $response["body"];
568 $body = json_decode($body);
569 if($body->count)
570 {
571 $twitter_count = $body->count;
572 }
573 else
574 {
575 $twitter_count = 0;
576 } */
577$twitter_count = 0;
578 // Pinterest Pin
579 $api_pin = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback%20&url=' . $url );
580 $body = preg_replace( '/^receiveCount\((.*)\)$/', '\\1', $api_pin );
581 $count = json_decode( $body );
582 $pin_count = $count->count;
583 if ( !isset($pin_count ) ) {
584 $pin_count = 0;
585 }
586 else {
587 $pin_count;
588 }
589 // Google Plus
590 $curl = curl_init();
591 curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc" );
592 curl_setopt( $curl, CURLOPT_POST, 1 );
593 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"}]' );
594 curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
595 curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) );
596 $curl_results = curl_exec( $curl );
597 curl_close( $curl );
598 $json = json_decode( $curl_results, true );
599 $gplus_count = intval( $json[0]['result']['metadata']['globalCounts']['count'] );
600 if ( !isset($gplus_count ) ) {
601 $gplus_count = '0';
602 }
603 else {
604 $gplus_count;
605 }
606 $total = $facebook_count + $twitter_count + $pin_count + $gplus_count;
607
608 update_post_meta($id, "msp_share_count", $total);
609 update_post_meta($id, "msp_last_update", time());
610}
611function fb_opengraph() {
612 global $post;
613
614 if(is_single()) {
615 if(has_post_thumbnail($post->ID)) {
616 $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
617 } else {
618 $img_src[] = get_stylesheet_directory_uri() . '/img/fb_share.jpg';
619 }
620 if($excerpt = $post->post_content) {
621 $excerpt = strip_tags($post->post_content);
622 $excerpt = str_replace("", "'", $excerpt);
623 $excerpt = substr($excerpt, 0, 299);
624 } else {
625 $excerpt = get_bloginfo('description');
626 }
627 ?>
628
629 <meta property="og:title" content="<?php echo the_title(); ?>"/>
630 <meta property="og:description" content="<?php echo $excerpt; ?>"/>
631 <meta property="og:type" content="article"/>
632 <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
633 <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
634 <meta property="og:image" content="<?php echo $img_src[0]; ?>"/>
635 <meta name="twitter:card" content="summary" />
636 <meta name="twitter:description" content="<?php echo $excerpt; ?>" />
637 <meta name="twitter:title" content="<?php the_title();?>" />
638 <meta name="twitter:image" content="<?php echo $img_src[0]; ?>" />
639
640<?php
641 } else {
642 return;
643 }
644}
645add_action('wp_head', 'fb_opengraph', 5);
646
647
648function fb_count($id) {
649 $url = get_permalink($id);
650 //facebook shares
651$json = json_decode(file_get_contents("http://graph.facebook.com/?ids=".$url),true);
652$facebook_count = $json[$url]['share']['share_count'];
653return $facebook_count;
654}
655
656add_filter('manage_edit-post_columns', 'my_extra_cake_columns');
657function my_extra_cake_columns($columns) {
658 $columns['share'] =__('Share','myplugindomain');
659 return $columns;
660}
661add_action( 'manage_posts_custom_column', 'my_cake_column_content', 10, 2 );
662function my_cake_column_content( $column_name, $post_id ) {
663 if ( 'share' != $column_name )
664 return;
665 //Get number of share from post meta
666 $share = get_post_meta($post_id, 'msp_share_count', true);
667 echo intval($share);
668}
669add_filter( 'manage_edit-post_sortable_columns', 'my_sortable_cake_column' );
670function my_sortable_cake_column( $columns ) {
671 $columns['share'] = 'share';
672
673 //To make a column 'un-sortable' remove it from the array
674 //unset($columns['date']);
675
676 return $columns;
677}
678add_action( 'pre_get_posts', 'my_slice_orderby' );
679function my_slice_orderby( $query ) {
680 if( ! is_admin() )
681 return;
682
683 $orderby = $query->get( 'orderby');
684
685 if( 'share' == $orderby ) {
686 $query->set('meta_key','msp_share_count');
687 $query->set('orderby','meta_value_num');
688 }
689}
690
691include('functions/auto-thumb-video.php');
692?>