PluginProbe
Shariff Wrapper / trunk
Shariff Wrapper vtrunk
4.6.22 4.6.21 4.6.20 4.6.19 trunk 1.0.0 1.9.0 1.9.9 2.4.3 3.4.2 4.0.8 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.3.0 4.4.2 4.4.3 4.4.4 4.5.0 4.5.1 4.5.2 4.5.3 4.6.0 All 42 releases
shariff / services / shariff-reddit.php

shariff-reddit.php in Shariff Wrapper trunk, at services/shariff-reddit.php

77 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Will be included in the shariff.php only, when Reddit is requested as a service.
4 *
5 * @package Shariff Wrapper
6 */
7
8 // Prevent direct calls.
9 if ( ! class_exists( 'WP' ) ) { die(); }
10 // and again the same because the WP Plugin Check does not understand what the line above does ;-)
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 // Check if we need the frontend or the backend part.
14 if ( isset( $frontend ) && 1 === $frontend ) {
15 // Service URL.
16 $service_url = esc_url( 'https://www.reddit.com/submit' );
17
18 // Build button URL.
19 $button_url = $service_url . '?url=' . $share_url;
20
21 // Colors.
22 $main_color = '#ff4500';
23 $secondary_color = '#ff5700';
24 $wcag_color = '#A32D00';
25
26 // SVG icon.
27 $svg_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="' . $main_color . '" d="M440.3 203.5c-15 0-28.2 6.2-37.9 15.9-35.7-24.7-83.8-40.6-137.1-42.3L293 52.3l88.2 19.8c0 21.6 17.6 39.2 39.2 39.2 22 0 39.7-18.1 39.7-39.7s-17.6-39.7-39.7-39.7c-15.4 0-28.7 9.3-35.3 22l-97.4-21.6c-4.9-1.3-9.7 2.2-11 7.1L246.3 177c-52.9 2.2-100.5 18.1-136.3 42.8-9.7-10.1-23.4-16.3-38.4-16.3-55.6 0-73.8 74.6-22.9 100.1-1.8 7.9-2.6 16.3-2.6 24.7 0 83.8 94.4 151.7 210.3 151.7 116.4 0 210.8-67.9 210.8-151.7 0-8.4-.9-17.2-3.1-25.1 49.9-25.6 31.5-99.7-23.8-99.7zM129.4 308.9c0-22 17.6-39.7 39.7-39.7 21.6 0 39.2 17.6 39.2 39.7 0 21.6-17.6 39.2-39.2 39.2-22 .1-39.7-17.6-39.7-39.2zm214.3 93.5c-36.4 36.4-139.1 36.4-175.5 0-4-3.5-4-9.7 0-13.7 3.5-3.5 9.7-3.5 13.2 0 27.8 28.5 120 29 149 0 3.5-3.5 9.7-3.5 13.2 0 4.1 4 4.1 10.2.1 13.7zm-.8-54.2c-21.6 0-39.2-17.6-39.2-39.2 0-22 17.6-39.7 39.2-39.7 22 0 39.7 17.6 39.7 39.7-.1 21.5-17.7 39.2-39.7 39.2z"/></svg>';
28
29 // Backend available?
30 $backend_available = 1;
31
32 // Button alt label.
33 $button_title_array = array(
34 'bg' => 'Сподели в Reddit',
35 'cs' => 'Sdílet na Redditu',
36 'da' => 'Del på Reddit',
37 'de' => 'Bei Reddit teilen',
38 'en' => 'Share on Reddit',
39 'es' => 'Compartir en Reddit',
40 'fi' => 'Jaa Redditissä',
41 'fr' => 'Envoyer par Reddit',
42 'hr' => 'Podijelite na Reddit',
43 'hu' => 'Megosztás Redditen',
44 'it' => 'Condividi su Reddit',
45 'ja' => 'Reddit上で�
46 �有',
47 'ko' => 'Reddit에서 공유하기',
48 'nl' => 'Delen op Reddit',
49 'no' => 'Del på Reddit',
50 'pl' => 'Udostępnij przez Reddit',
51 'pt' => 'Compartilhar no Reddit',
52 'ro' => 'Partajează pe Reddit',
53 'ru' => 'Поделиться на Reddit',
54 'sk' => 'Zdieľať na Reddit',
55 'sl' => 'Deli na Reddit',
56 'sr' => 'Podeli na Reddit-u',
57 'sv' => 'Dela på Reddit',
58 'tr' => 'Reddit\'ta paylaş',
59 'zh' => '分享至Reddit',
60 );
61 } elseif ( isset( $backend ) && 1 === $backend ) {
62 // Fetch counts.
63 $reddit = sanitize_text_field( wp_remote_retrieve_body( wp_remote_get( 'https://www.reddit.com/api/info.json?url=' . $post_url ) ) );
64 $reddit_json = json_decode( $reddit, true );
65
66 // Store results, if we have some and record errors, if enabled (e.g. request from the status tab).
67 if ( isset( $reddit_json['data']['children'] ) ) {
68 $count = 0;
69 foreach ( $reddit_json['data']['children'] as $child ) {
70 $count += intval( $child['data']['score'] );
71 }
72 $share_counts['reddit'] = $count;
73 } elseif ( isset( $record_errors ) && 1 === $record_errors ) {
74 $service_errors['reddit'] = $reddit;
75 }
76 }
77