reasonableframework/helper/socialhub.utl.php

71 lines
1.9 KiB
PHP
Raw Normal View History

2018-09-26 20:16:48 +00:00
<?php
/**
* @file socialhub.utl.php
* @date 2018-09-27
* @author Go Namhyeon <gnh1201@gmail.com>
* @brief SocialHub Utilities (refactoring from SocioRouter Utilities)
*/
if(!function_exists("socialhub_send_message")) {
function socialhub_send_message($provider, $adapter, $message, $options=array()) {
$response = false;
$status = array(
"message" => $message
);
2018-09-26 20:19:46 +00:00
2018-09-26 20:16:48 +00:00
switch($provider) {
case "facebook":
$status['link'] = get_value_in_array("link", $options, "");
$status['picture'] = get_value_in_array("picture", $options, "");
$response = $adapter->setUserStatus($status);
break;
2018-09-26 20:19:46 +00:00
2018-09-26 20:16:48 +00:00
case "linkedin":
$status['content'] => array(
"title" => get_value_in_array("title", $options, "");
"description" => get_value_in_array("description", $options, "");
"submitted-url" => get_value_in_array("link", $options, "");
"submitted-image-url" => get_value_in_array("picture", $options, "");
);
$status['visibility'] => array(
"code" => "anyone",
);
$response = $adapter->setUserStatus($status);
break;
case "twitter":
$status['link'] = get_value_in_array("link", $options, "");
$status['picture'] = get_value_in_array("picture", $options, "");
$response = $adapter->setUserStatus($status);
break;
2018-09-26 20:19:46 +00:00
2018-09-26 20:16:48 +00:00
default:
set_error("Unknown provider");
show_errors();
}
2018-09-26 20:20:11 +00:00
return $response;
2018-09-26 20:16:48 +00:00
}
}
2018-09-26 20:19:46 +00:00
if(!function_exists("socialhub_parse_object_id")) {
function socialhub_parse_object_id($provider, $response) {
$object_id = false;
switch($provider) {
case "facebook":
$decodedBody = get_property_value("decodedBody", $response, true);
$object_id = $decodedBody['id'];
break;
case "linkedin":
$object_id = get_property_value("updateKey", $response);
break;
case "twitter":
$object_id = get_property_value("id_str", $response);
break;
}
return $object_id;
}
}