Example #1
0
function appnet_is_repost($a, $uid, $body)
{
    $body = trim($body);
    // Skip if it isn't a pure repeated messages
    // Does it start with a share?
    if (strpos($body, "[share") > 0) {
        return false;
    }
    // Does it end with a share?
    if (strlen($body) > strrpos($body, "[/share]") + 8) {
        return false;
    }
    $attributes = preg_replace("/\\[share(.*?)\\]\\s?(.*?)\\s?\\[\\/share\\]\\s?/ism", "\$1", $body);
    // Skip if there is no shared message in there
    if ($body == $attributes) {
        return false;
    }
    $link = "";
    preg_match("/link='(.*?)'/ism", $attributes, $matches);
    if ($matches[1] != "") {
        $link = $matches[1];
    }
    preg_match('/link="(.*?)"/ism', $attributes, $matches);
    if ($matches[1] != "") {
        $link = $matches[1];
    }
    $id = preg_replace("=https?://alpha.app.net/(.*)/post/(.*)=ism", "\$2", $link);
    if ($id == $link) {
        return false;
    }
    logger('appnet_is_repost: Reposting id ' . $id . ' for user ' . $uid, LOGGER_DEBUG);
    require_once 'addon/appnet/AppDotNet.php';
    $token = get_pconfig($uid, 'appnet', 'token');
    $clientId = get_pconfig($uid, 'appnet', 'clientid');
    $clientSecret = get_pconfig($uid, 'appnet', 'clientsecret');
    $app = new AppDotNet($clientId, $clientSecret);
    $app->setAccessToken($token);
    try {
        $result = $app->repost($id);
        logger('appnet_is_repost: result ' . print_r($result, true), LOGGER_DEBUG);
        return true;
    } catch (AppDotNetException $e) {
        logger('appnet_is_repost: error doing repost ' . appnet_error($e->getMessage()), LOGGER_DEBUG);
        return false;
    }
}