| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
class mbSocialNetworks |
| 6 |
{ |
| 7 |
protected $network = ""; |
| 8 |
protected $network_data = array(); |
| 9 |
protected $network_name = ''; |
| 10 |
|
| 11 |
protected $networks = array(); |
| 12 |
|
| 13 |
|
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
$this->setNetworkClasses(); |
| 17 |
|
| 18 |
//$this->setNetWorks(); |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
public function get($name = null) |
| 23 |
{ |
| 24 |
if (! is_null($name)) |
| 25 |
{ |
| 26 |
foreach($this->networks as $class => $network) |
| 27 |
{ |
| 28 |
if ($name == $class || $name == $network->get('network') ) |
| 29 |
return $network; |
| 30 |
} |
| 31 |
return false; // not found |
| 32 |
|
| 33 |
} |
| 34 |
else |
| 35 |
return $this->networks; |
| 36 |
} |
| 37 |
|
| 38 |
//public function |
| 39 |
|
| 40 |
/** Get all available subclasses of main mbNetwork class **/ |
| 41 |
protected function setNetworkClasses() |
| 42 |
{ |
| 43 |
foreach (get_declared_classes() as $class) { |
| 44 |
|
| 45 |
if (is_subclass_of($class, 'MBSocial\mbNetwork')) |
| 46 |
{ |
| 47 |
$this->networks[$class] = new $class; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
if (! Install::isPRO() ) |
| 52 |
{ |
| 53 |
foreach($this->networks as $index => $class) |
| 54 |
{ |
| 55 |
if ($class->get('limitedpro') === true) |
| 56 |
{ |
| 57 |
unset($this->networks[$index]); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
// replace this with subclasses |
| 65 |
/* Set the network variables to be using for this inquery */ |
| 66 |
/*public function setNetworks($network) |
| 67 |
{ |
| 68 |
//$networks = $this->getSupportedNetworks(); |
| 69 |
|
| 70 |
$network_data = array( |
| 71 |
"share_url" => '', // url to send share to (incl. var) |
| 72 |
"count_api" => '', // request url |
| 73 |
"count_function" => "jsonRequest", // which function to run. |
| 74 |
"json_return_var" => '', // which var is the count number? |
| 75 |
"count_check_time" => 4 * HOUR_IN_SECONDS, // how much time before checking again - in seconds |
| 76 |
"popup" => true, // button opens share popup |
| 77 |
"popup_dimensions" => array(400,300), // width - height of popup |
| 78 |
); |
| 79 |
|
| 80 |
|
| 81 |
switch($network) |
| 82 |
{ |
| 83 |
case "bloglovin": |
| 84 |
$network_data["popup"] = false; |
| 85 |
|
| 86 |
break; |
| 87 |
case "digg": |
| 88 |
$network_data["share_url"] = "http://digg.com/submit?url={url}&title={title}"; |
| 89 |
$network_data["count_api"] = ''; |
| 90 |
$network_data["popup_dimensions"] = array(600,400); |
| 91 |
break; |
| 92 |
case "email": |
| 93 |
$network_data["share_url"] = 'mailto:?subject={title}&body={url}'; |
| 94 |
$network_data["count_api"] = ''; |
| 95 |
$network_data["popup"] = false; |
| 96 |
break; |
| 97 |
case "facebook": |
| 98 |
$network_data["share_url"] = 'https://www.facebook.com/sharer.php?u={url}'; |
| 99 |
$network_data["count_api"] = "https://graph.facebook.com/{url}"; |
| 100 |
$network_data["json_return_var"] = "share|share_count"; |
| 101 |
break; |
| 102 |
case "google-plus": |
| 103 |
$network_data["share_url"] = 'https://plus.google.com/share?url={url}'; |
| 104 |
$network_data["count_api"] = "{url}"; |
| 105 |
$network_data["popup_dimensions"] = array(600,600); |
| 106 |
$network_data["count_function"] = "googlePlus"; |
| 107 |
|
| 108 |
break; |
| 109 |
case "linkedin": |
| 110 |
$network_data["share_url"] = "https://www.linkedin.com/shareArticle?mini=true&url={url}"; |
| 111 |
$network_data["count_api"] = "https://www.linkedin.com/countserv/count/share?url={url}&format=json"; |
| 112 |
$network_data["json_return_var"] = "count"; |
| 113 |
$network_data["popup_dimensions"] = array(700,500); |
| 114 |
break; |
| 115 |
case "pinterest": |
| 116 |
$network_data["share_url"] = "https://www.pinterest.com/pin/create/bookmarklet/?media={img}&url={url}&is_video=false&description={title}"; |
| 117 |
$network_data["count_api"] = "https://api.pinterest.com/v1/urls/count.json?url={url}"; |
| 118 |
$network_data["json_return_var"] = "count"; |
| 119 |
$network_data["count_function"] = "pinterestCount"; |
| 120 |
$network_data["popup_dimensions"] = array(750, 500); |
| 121 |
break; |
| 122 |
case "print": |
| 123 |
$network_data["share_url"] = 'javascript:window.print()'; |
| 124 |
$network_data["count_api"] = ''; |
| 125 |
$network_data["popup"] = false; |
| 126 |
break; |
| 127 |
case "stumbleupon": |
| 128 |
$network_data["share_url"] = "https://www.stumbleupon.com/submit?url={url}&title={title}"; |
| 129 |
$network_data["count_api"] = "https://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}"; |
| 130 |
$network_data["json_return_var"] = "result|views"; |
| 131 |
|
| 132 |
break; |
| 133 |
case "reddit": |
| 134 |
$network_data["share_url"] = "https://reddit.com/submit?url={url}&title={title}"; |
| 135 |
$network_data["count_api"] = "https://buttons.reddit.com/button_info.json?url={url}"; |
| 136 |
$network_data["json_return_var"] = "data|children|0|data|score"; |
| 137 |
$network_data["popup_dimensions"] = array(800, 500); |
| 138 |
|
| 139 |
break; |
| 140 |
case "twitter": |
| 141 |
$network_data["share_url"] = 'https://twitter.com/intent/tweet?url={url}'; |
| 142 |
$network_data["count_api"] = ""; |
| 143 |
$network_data["json_return_var"] = ""; |
| 144 |
$network_data["popup_dimensions"] = array(550, 420); |
| 145 |
break; |
| 146 |
case "twitter-follow": |
| 147 |
$network_data["share_url"] = 'https://twitter.com/{user}'; |
| 148 |
$network_data['count_api'] = ''; |
| 149 |
$network_data['json_return_var'] = 'count'; |
| 150 |
|
| 151 |
|
| 152 |
break; |
| 153 |
case "vkontakte": |
| 154 |
$network_data["share_url"] = "https://vkontakte.ru/share.php?url={url}"; |
| 155 |
$network_data["count_api"] = "https://vk.com/share.php?act=count&url={url}"; |
| 156 |
$network_data["count_function"] = "vKontakteCount"; |
| 157 |
break; |
| 158 |
case "whatsapp": |
| 159 |
$network_data["share_url"] = "whatsapp://send?text={url} {title}"; |
| 160 |
$network_data["count_api"] = ''; |
| 161 |
break; |
| 162 |
default: |
| 163 |
$network_data['popup'] = false; // no network no popup. |
| 164 |
break; |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
$network_data = apply_filters("mb-collection-network-data", $network_data); |
| 169 |
$network_data = apply_filters("mb-collection-network-data-" . $network, $network_data); |
| 170 |
|
| 171 |
$this->network_data = $network_data; |
| 172 |
} */ |
| 173 |
|
| 174 |
|
| 175 |
public function checkPopup() |
| 176 |
{ |
| 177 |
if (isset($this->network_data["popup"]) && $this->network_data["popup"] ) |
| 178 |
return true; |
| 179 |
else |
| 180 |
return false; |
| 181 |
} |
| 182 |
|
| 183 |
public function getPopupDimensions() |
| 184 |
{ |
| 185 |
if (isset($this->network_data["popup_dimensions"])) |
| 186 |
return $this->network_data["popup_dimensions"]; |
| 187 |
else |
| 188 |
return array(); |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
public static function getSupportedNetworks() |
| 193 |
{ |
| 194 |
// alphabetic |
| 195 |
exit('supported networks?'); |
| 196 |
$supported_networks = array( |
| 197 |
"none" => __("Select a network","maxbuttons"), |
| 198 |
"bloglovin" => __("Bloglovin","maxbuttons"), |
| 199 |
"digg" => __("Digg","maxbuttons"), |
| 200 |
"email" => __("Email","maxbuttons"), |
| 201 |
"facebook" => __("Facebook","maxbuttons"), |
| 202 |
"google-plus" => __("Google +","maxbuttons"), |
| 203 |
"linkedin" => __("LinkedIn","maxbuttons"), |
| 204 |
"pinterest" => __("Pinterest","maxbuttons"), |
| 205 |
"print" => __("Print this page","maxbuttons"), |
| 206 |
"reddit" => __("Reddit", "maxbuttons"), |
| 207 |
"stumbleupon" => __("StumbleUpon","maxbuttons"), |
| 208 |
"twitter" => __("Twitter","maxbuttons"), |
| 209 |
"vkontakte" => __("Vkontakte","maxbuttons"), |
| 210 |
"whatsapp" => __("Whatsapp", "maxbuttons"), |
| 211 |
); |
| 212 |
$supported_networks = apply_filters("mb-collection-supported-networks", $supported_networks); |
| 213 |
return $supported_networks; |
| 214 |
} |
| 215 |
|
| 216 |
} |
| 217 |
|