loadlib("cli"); loadlib("flickr_backups"); loadlib("flickr_push"); loadlib("flickr_push_subscriptions"); $features = array("backups", "flickr_push", "flickr_push_backups"); if (!features_is_enabled($features)) { echo "backups are currently disabled\n"; exit; } $spec = array("url" => array("flag" => "u", "required" => 1, "help" => "the *root* URL of your copy of parallel-ogram (the need to specify this here is not a feature...)")); $opts = cli_getopts($spec); $topic = $opts['topic']; # This sucks to have to do but I am uncertain what the # better alternative is right now... (20120601/straup) $root = rtrim($opts['url'], '/') . "/"; $GLOBALS['cfg']['abs_root_url'] = $root; log_info("set 'abs_root_url' to '{$GLOBALS['cfg']['abs_root_url']}'"); $topic_map = flickr_push_topic_map("string keys"); $topics = array("my_photos", "my_faves"); foreach (flickr_backups_users() as $user) { foreach ($topics as $topic) { $sub = array('user_id' => $user['id'], 'topic_id' => $topic_map[$topic]); $rsp = flickr_push_subscriptions_register_subscription($sub); log_info("[{$user['username']}] {$topic}: {$rsp['ok']}"); if (!$rsp['ok']) { log_info("[{$user['username']}] {$topic}: {$rsp['error']}"); } } } log_info("- done -"); exit;
function flickr_backups_toggle_push_subscription(&$backup, $enable) { $push_features = array("flickr_push", "flickr_push_backups"); if (!features_is_enabled($push_features)) { return null; } # First, figure out if this backup type is a valid push # backup topic - this duplicates most/all of the code in # flickr_backups_is_push_backups but since we'll need the # stub subscription (and the topic map) in order to create # new subscriptions we're just not going to worry about it # too much (20120608/straup) $type_id = $backup['type_id']; $map = flickr_backups_push_topics_map(); if (!isset($map[$type_id])) { return null; } # Stub subscription data $user = users_get_by_id($backup['user_id']); $topic_id = $map[$type_id]; $sub = array('user_id' => $user['id'], 'topic_id' => $topic_id); if (!flickr_backups_is_registered_push_subscription($sub)) { return null; } if ($enable) { $push_rsp = flickr_push_subscriptions_register_subscription($sub); } else { # Okay, now fetch the actual subscription in order to unsubscribe $sub = flickr_push_subscriptions_get_by_user_and_topic($user, $topic_id); # Keeping in mind that it may not actually exist... if (!$sub) { return okay(); } $push_rsp = flickr_push_subscriptions_remove_subscription($sub, 1); } return $push_rsp; }