Skip to content

Commit

Permalink
Rename TagInfo functions: split_index->unpack, split_tlist->split_unp…
Browse files Browse the repository at this point in the history
…ack.
  • Loading branch information
kohler committed Jan 22, 2017
1 parent e0e24ab commit aa3afa7
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 47 deletions.
49 changes: 16 additions & 33 deletions lib/tagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,28 @@ function emoji_regex() {
static function make(Conf $conf) {
$map = new TagMap($conf);
$ct = $conf->setting_data("tag_chair", "");
foreach (TagInfo::split_tlist($ct) as $ti)
foreach (TagInfo::split_unpack($ct) as $ti)
$map->add($ti[0])->chair = true;
foreach ($conf->track_tags() as $tn) {
$t = $map->add(TagInfo::base($tn));
$t->chair = $t->track = true;
}
$ct = $conf->setting_data("tag_sitewide", "");
foreach (TagInfo::split_tlist($ct) as $ti)
foreach (TagInfo::split_unpack($ct) as $ti)
$map->add($ti[0])->sitewide = $map->has_sitewide = true;
$vt = $conf->setting_data("tag_vote", "");
foreach (TagInfo::split_tlist($vt) as $ti) {
foreach (TagInfo::split_unpack($vt) as $ti) {
$t = $map->add($ti[0]);
$t->vote = ($ti[1] ? : 1);
$t->votish = $map->has_vote = $map->has_votish = true;
}
$vt = $conf->setting_data("tag_approval", "");
foreach (TagInfo::split_tlist($vt) as $ti) {
foreach (TagInfo::split_unpack($vt) as $ti) {
$t = $map->add($ti[0]);
$t->approval = $t->votish = $map->has_approval = $map->has_votish = true;
}
$rt = $conf->setting_data("tag_rank", "");
foreach (TagInfo::split_tlist($rt) as $ti)
foreach (TagInfo::split_unpack($rt) as $ti)
$map->add($ti[0])->rank = $map->has_rank = true;
$ct = $conf->setting_data("tag_color", "");
if ($ct !== "")
Expand Down Expand Up @@ -408,49 +408,31 @@ static function base($tag) {
return $tag;
}

static function index($tag) {
if ($tag && (($pos = strpos($tag, "#")) > 0
|| ($pos = strpos($tag, "=")) > 0))
return (float) substr($tag, $pos + 1);
else
return false;
}

static function split_index($tag) {
static function unpack($tag) {
if (!$tag)
return array(false, false);
return [false, false];
else if (!($pos = strpos($tag, "#")) && !($pos = strpos($tag, "=")))
return array($tag, false);
return [$tag, false];
else if ($pos == strlen($tag) - 1)
return array(substr($tag, 0, $pos), false);
return [substr($tag, 0, $pos), false];
else
return array(substr($tag, 0, $pos), (float) substr($tag, $pos + 1));
return [substr($tag, 0, $pos), (float) substr($tag, $pos + 1)];
}

static function split($taglist) {
preg_match_all(',\S+,', $taglist, $m);
return $m[0];
}

static function split_unpack($taglist) {
return array_map("TagInfo::unpack", self::split($taglist));
}

static function basic_check($tag) {
return $tag !== "" && strlen($tag) <= TAG_MAXLEN
&& preg_match('{\A' . TAG_REGEX . '\z}', $tag);
}

static function in_list($tag, $taglist) {
if (is_string($taglist))
$taglist = explode(" ", $taglist);
list($base, $index) = self::split_index($tag);
if (is_associative_array($taglist))
return isset($taglist[$base]);
else
return in_array($base, $taglist);
}

static function split_tlist($tl) {
return array_map("TagInfo::split_index", self::split($tl));
}

static function unparse_anno_json($anno) {
global $Conf;
$j = (object) ["annoid" => $anno->annoId === null ? null : +$anno->annoId];
Expand Down Expand Up @@ -651,7 +633,8 @@ function unparse_decoration_html($tags) {
foreach ($ts as $t) {
if (($link = $this->link_base($t)))
$links[] = "#" . $link;
$count = max($count, (float) TagInfo::index($t));
list($base, $value) = TagInfo::unpack($t);
$count = max($count, (float) $value);
}
$b = self::unparse_emoji_html($e, $count);
if (!empty($links))
Expand Down
2 changes: 1 addition & 1 deletion src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ function pc_members() {
}
if ($row->contactTags)
foreach (explode(" ", $row->contactTags) as $t) {
list($tag, $value) = TagInfo::split_index($t);
list($tag, $value) = TagInfo::unpack($t);
if ($tag)
$this->_pc_tags_cache[strtolower($tag)] = $tag;
}
Expand Down
2 changes: 1 addition & 1 deletion src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ function save_json($cj, $actor, $send) {
if (isset($cj->tags)) {
$tags = array();
foreach ($cj->tags as $t) {
list($tag, $value) = TagInfo::split_index($t);
list($tag, $value) = TagInfo::unpack($t);
if (strcasecmp($tag, "pc") != 0)
$tags[$tag] = $tag . "#" . ($value ? : 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/formulagraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function _paper_style(PaperInfo $prow) {

private function _add_tag_data(&$data, $d, PaperInfo $prow) {
assert($this->fx_type === self::X_TAG);
$tags = TagInfo::split_tlist($prow->viewable_tags($this->user));
$tags = TagInfo::split_unpack($prow->viewable_tags($this->user));
foreach ($tags as $ti) {
if (!isset($this->tags[$ti[0]]))
$this->tags[$ti[0]] = count($this->tags);
Expand Down
9 changes: 4 additions & 5 deletions src/papersearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,11 +1203,10 @@ function evaluate($user, $tags) {
$res[] = preg_quote($value);
$this->_re = '/\A(?:' . join("|", $res) . ')\z/i';
}
foreach (TagInfo::split($tags) as $ti) {
list($tag, $index) = TagInfo::split_index($ti);
if (preg_match($this->_re, $tag)
&& (!$this->index1 || $this->index1->test($index))
&& (!$this->index2 || $this->index2->test($index)))
foreach (TagInfo::split_unpack($tags) as $ti) {
if (preg_match($this->_re, $ti[0])
&& (!$this->index1 || $this->index1->test($ti[1]))
&& (!$this->index2 || $this->index2->test($ti[1])))
return true;
}
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/settings/s_decisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ function crosscheck(SettingValues $sv) {
&& $sv->newv("au_seerev") == Conf::AUSEEREV_TAGS
&& $sv->newv("tag_au_seerev")
&& !$sv->has_error_at("tag_au_seerev")) {
$ct = [];
foreach (TagInfo::split_unpack($sv->newv("tag_chair")) as $ti)
$ct[$ti[0]] = true;
foreach (explode(" ", $sv->newv("tag_au_seerev")) as $t)
if ($t !== "" && !TagInfo::in_list($t, $sv->newv("tag_chair"))) {
if ($t !== "" && !isset($ct[$t])) {
$sv->warning_at("tag_au_seerev", "PC members can change the tag “" . htmlspecialchars($t) . "”, which affects whether authors can see reviews. Such tags should usually be <a href=\"" . hoturl("settings", "group=tags") . "\">chair-only</a>.");
$sv->warning_at("tag_chair");
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings/s_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private function parse_list(SettingValues $sv, Si $si, $checkf, $min_idx) {
$ts = array();
foreach (preg_split('/\s+/', $sv->req[$si->name]) as $t)
if ($t !== "" && ($tx = $this->tagger->check($t, $checkf))) {
list($tag, $idx) = TagInfo::split_index($tx);
list($tag, $idx) = TagInfo::unpack($tx);
if ($min_idx)
$tx = $tag . "#" . max($min_idx, (float) $idx);
$ts[$tag] = $tx;
Expand Down
6 changes: 3 additions & 3 deletions src/userstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,17 @@ private function normalize($cj, $old_user) {
$old_tags = array();
foreach ($cj->tags as $t)
if ($t !== "") {
list($tag, $index) = TagInfo::split_index($t);
list($tag, $index) = TagInfo::unpack($t);
$old_tags[$tag] = $index;
}
// process removals, then additions
foreach ($this->make_tags_array(get($cj, "remove_tags"), "remove_tags") as $t) {
list($tag, $index) = TagInfo::split_index($t);
list($tag, $index) = TagInfo::unpack($t);
if ($index === false || get($old_tags, $tag) == $index)
unset($old_tags[$tag]);
}
foreach ($this->make_tags_array(get($cj, "add_tags"), "add_tags") as $t) {
list($tag, $index) = TagInfo::split_index($t);
list($tag, $index) = TagInfo::unpack($t);
$old_tags[$tag] = $index;
}
// collect results
Expand Down
2 changes: 1 addition & 1 deletion users.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function do_tags() {
$likes = array();
$removes = array();
foreach ($t1 as $t) {
list($tag, $index) = TagInfo::split_index($t);
list($tag, $index) = TagInfo::unpack($t);
$removes[] = $t;
$likes[] = "contactTags like " . Dbl::utf8ci("'% " . sqlq_for_like($tag) . "#%'");
}
Expand Down

0 comments on commit aa3afa7

Please sign in to comment.