Changeset 2118377
- Timestamp:
- 07/05/2019 09:10:19 PM (7 years ago)
- Location:
- sharing-plus/trunk
- Files:
-
- 2 deleted
- 3 edited
-
Gruntfile.js (deleted)
-
inc/utils.php (modified) (3 diffs)
-
package.json (deleted)
-
readme.txt (modified) (2 diffs)
-
sharing-plus.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sharing-plus/trunk/inc/utils.php
r2023619 r2118377 1 1 <?php 2 3 /** 4 * Crul to fetch stats. 5 * 6 * @since 1.0.1 7 */ 8 function sharing_plus_fetch_shares_via_curl_multi( $data, $options = array() ) { 9 10 // array of curl handles 11 $curly = array(); 12 // data to be returned 13 $result = array(); 14 15 // multi handle 16 $mh = curl_multi_init(); 17 18 // loop through $data and create curl handles 19 // then add them to the multi-handle 20 if ( is_array( $data ) ) : 21 foreach ( $data as $id => $d ) : 22 23 if ( $d !== 0 || $id == 'googleplus' ) : 24 25 $curly[ $id ] = curl_init(); 26 27 if ( $id == 'googleplus' ) : 28 29 curl_setopt( $curly[ $id ], CURLOPT_URL, 'https://clients6.google.com/rpc' ); 30 curl_setopt( $curly[ $id ], CURLOPT_POST, true ); 31 curl_setopt( $curly[ $id ], CURLOPT_SSL_VERIFYPEER, false ); 32 curl_setopt( $curly[ $id ], CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . rawurldecode( $d ) . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]' ); 33 curl_setopt( $curly[ $id ], CURLOPT_RETURNTRANSFER, true ); 34 curl_setopt( $curly[ $id ], CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) ); 35 36 else : 37 38 $url = (is_array( $d ) && ! empty( $d['url'] )) ? $d['url'] : $d; 39 curl_setopt( $curly[ $id ], CURLOPT_URL, $url ); 40 curl_setopt( $curly[ $id ], CURLOPT_HEADER, 0 ); 41 curl_setopt( $curly[ $id ], CURLOPT_RETURNTRANSFER, 1 ); 42 curl_setopt( $curly[ $id ], CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ); 43 curl_setopt( $curly[ $id ], CURLOPT_FAILONERROR, 0 ); 44 curl_setopt( $curly[ $id ], CURLOPT_FOLLOWLOCATION, 0 ); 45 curl_setopt( $curly[ $id ], CURLOPT_RETURNTRANSFER,1 ); 46 curl_setopt( $curly[ $id ], CURLOPT_SSL_VERIFYPEER, false ); 47 curl_setopt( $curly[ $id ], CURLOPT_SSL_VERIFYHOST, false ); 48 curl_setopt( $curly[ $id ], CURLOPT_TIMEOUT, 5 ); 49 curl_setopt( $curly[ $id ], CURLOPT_CONNECTTIMEOUT, 5 ); 50 curl_setopt( $curly[ $id ], CURLOPT_NOSIGNAL, 1 ); 51 curl_setopt( $curly[ $id ], CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 52 // curl_setopt($curly[$id], CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3); 53 endif; 54 55 // extra options? 56 if ( ! empty( $options ) ) { 57 curl_setopt_array( $curly[ $id ], $options ); 58 } 59 60 curl_multi_add_handle( $mh, $curly[ $id ] ); 61 62 endif; 63 endforeach; 64 endif; 65 66 // execute the handles 67 $running = null; 68 do { 69 curl_multi_exec( $mh, $running ); 70 } while ( $running > 0 ); 71 72 // get content and remove handles 73 foreach ( $curly as $id => $c ) { 74 $result[ $id ] = curl_multi_getcontent( $c ); 75 curl_multi_remove_handle( $mh, $c ); 76 } 77 78 // all done 79 curl_multi_close( $mh ); 80 81 return $result; 82 } 83 84 2 85 /** 3 86 * Return false if to fetch the new counts. … … 47 130 } 48 131 132 /** 133 * Fetch fresh counts and cached them. 134 * 135 * @param Array $stats 136 * @param String $post_id 137 * @return Array Simple array with counts. 138 * @since 1.0.1 139 */ 140 function sharing_plus_fetch_fresh_counts( $stats, $post_id ,$alt_share_link) { 141 142 $stats_result = array(); 143 $total = 0; 144 145 // special case if post id not exist for example short code run on widget out side the loop in archive page 146 if( 0 !== $post_id ){ 147 $networks = get_post_meta( $post_id, 'sharing_plus_old_counts', true ); 148 }else{ 149 $networks = get_option( 'sharing_plus_not_exist_post_old_counts' ); 150 } 151 152 if( ! $networks ){ 153 $_result = sharing_plus_fetch_shares_via_curl_multi( array_filter( $alt_share_link ) ); 154 sharing_plus_fetch_http_or_https_counts( $_result, $post_id ); 155 // special case if post id not exist for example short code run on widget out side the loop in archive page 156 if( 0 !== $post_id ){ 157 $networks = get_post_meta( $post_id, 'sharing_plus_old_counts', true ); 158 }else{ 159 $networks = get_option( 'sharing_plus_not_exist_post_old_counts' ); 160 161 } 162 163 } 164 165 foreach ( $stats as $social_name => $counts ) { 166 if ( 'totalshare' == $social_name || 'viber' == $social_name || 'fblike' == $social_name || 'whatsapp' == $social_name || 'print' == $social_name || 'email' == $social_name || 'messenger' == $social_name ) 167 { continue; } 168 $stats_counts = call_user_func( 'sharing_plus_format_' . $social_name . '_response', $counts ); 169 $new_counts = $stats_counts + $networks[ $social_name]; 170 171 $old_counts = get_post_meta( $post_id, 'sharing_plus_' . $social_name . '_counts', true ); 172 173 // this will solve if new plugin install. 174 $old_counts = $old_counts ? $old_counts : 0; 175 // if old counts less than new. Return old. 176 if ( $new_counts > $old_counts ) { 177 $stats_result[ $social_name ] = $new_counts; 178 } else { 179 $stats_result[ $social_name ] = $old_counts; 180 } 181 182 // special case if post id not exist for example short code run on widget out side the loop in archive page 183 if( 0 !== $post_id ) { 184 if ( $new_counts > $old_counts ) { 185 update_post_meta( $post_id, 'sharing_plus_' . $social_name . '_counts', $new_counts ); 186 } else { 187 // set new counts = old counts for total calculation. 188 $new_counts = $old_counts; 189 } 190 } else { 191 update_option( 'sharing_plus_not_exist_post_'. $social_name .'_counts', $new_counts ); 192 } 193 194 $total += $new_counts; 195 } 196 197 $stats_result['total'] = $total; 198 // special case if post id not exist for example short code run on widget out side the loop in archive page 199 if( 0 !== $post_id ){ 200 update_post_meta( $post_id, 'sharing_plus_total_counts', $total ); 201 }else{ 202 update_option( 'sharing_plus_not_exist_post_total_counts', $total ); 203 } 204 205 return $stats_result; 206 } 49 207 50 208 /** … … 95 253 return $result; 96 254 } 255 256 /** 257 * Detect if mobile. 258 * 259 * @since 1.0.4 260 */ 261 function is_mobile() { 262 263 $useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'none'; 264 265 if ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr( $useragent, 0, 4 ) ) ) { 266 return true; 267 } else { 268 return false; 269 } 270 } 271 272 273 /** 274 * Generate Whats app shara link. 275 * 276 * @param String $url 277 * @return Srtring Final url after detection is it mobile or desktop. 278 * @since 1.0.1 279 */ 280 function sharing_plus_whats_app_share_link( $url ){ 281 $whats_share_link = ''; 282 if( wp_is_mobile() ){ 283 $whats_share_link = 'https://api.whatsapp.com/send?text=' . $url; 284 } else { 285 $whats_share_link = 'https://web.whatsapp.com/send?text=' . $url; 286 } 287 288 return $whats_share_link; 289 } 290 291 292 -
sharing-plus/trunk/readme.txt
r2023619 r2118377 4 4 Tags: Social share, Social buttons, Whatsapp, Viber, LinkedIn, facebook, google, twitter, pinterest etc. 5 5 Requires at least: 4.0 6 Tested up to: 5.0.3 7 Stable tag: 1.0.0 6 Tested up to: 5.2.2 7 Version: 1.0.1 8 Stable tag: trunk 8 9 License: GPLv2 or later 9 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 79 80 == Changelog == 80 81 81 = 1.0.0 - 2019-02-02 = 82 = 1.0.3 - 2019-02-01 = 83 * Fixed - escaping issue fixed 84 * Removed - custom debug log path removed 85 86 = 1.0.2 - 2019-01-31 = 87 * Fixed - sanitization, escaping and validation issue fixed 88 89 = 1.0.1 - 2018-12-14 = 90 * Fixed - Curl Issue Fixed 91 92 = 1.0.0 - 2018-10-02 = 82 93 * Initial Release 83 94 -
sharing-plus/trunk/sharing-plus.php
r2023619 r2118377 10 10 * Plugin URI: https://wordpress.org/plugins/sharing-plus/ 11 11 * Description: Sharing Plus adds an advanced set of social media sharing buttons to your WordPress sites, such as: Google +1, Facebook, WhatsApp, Viber, Twitter, Reddit, LinkedIn and Pinterest. This makes it the most Flexible Social Sharing Plugin ever for Everyone. 12 * Version: 1.0. 012 * Version: 1.0.1 13 13 * Author: ThemeCentury 14 14 * Author URI: https://themecentury.com … … 652 652 // if false fetch the new share counts. 653 653 if ( ( isset( $this->settings['cache'] ) && $this->settings['cache'] == 'off' ) || ( true == $http_solve ) ){ 654 echo '<h1>Hello WOrld</h1>';655 654 $_share_links = array(); 656 655 foreach ( $arrButtons as $social_name => $priority ){
Note: See TracChangeset
for help on using the changeset viewer.