diff --git a/scripts/settag.php b/scripts/settag.php new file mode 100644 index 0000000000..1d7b60b902 --- /dev/null +++ b/scripts/settag.php @@ -0,0 +1,84 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'd'; +$longoptions = array('delete'); + +$helptext = << +Set the tag for site . + +With -d, delete the tag. + +END_OF_SETTAG_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (count($args) != 2) { + show_help(); + exit(1); +} + +$nickname = $args[0]; +$tag = strtolower($args[1]); + +$sn = Status_network::memGet('nickname', $nickname); + +if (empty($sn)) { + print "No such site.\n"; + exit(-1); +} + +$tags = $sn->getTags(); + +$i = array_search($tags, $tag); + +if ($i !== false) { + if (have_option('d', 'delete')) { // Delete + unset($tags[$i]); + + $orig = clone($sn); + $sn->tags = implode('|', $tags); + $result = $sn->update($orig); + if (!$result) { + print "Couldn't update.\n"; + exit(-1); + } + } else { + print "Already set.\n"; + exit(-1); + } +} else { + if (have_option('d', 'delete')) { // Delete + print "No such tag.\n"; + exit(-1); + } else { + $tags[] = $tag; + $orig = clone($sn); + $sn->tags = implode('|', $tags); + $result = $sn->update($orig); + if (!$result) { + print "Couldn't update.\n"; + exit(-1); + } + } +}