/** * Update Vote for inline plugin * * @param array &$lines * @param integer $vote_id * @parram string $choice_id * @return array array($linenum, $updated_line, $updated_text, $updated_votes) */ function get_update_inline(&$lines, $vote_id, $choice_id) { $contents = implode('', $lines); global $vars, $defaultpage; $page = isset($vars['refer']) ? $vars['refer'] : $defaultpage; $ic = new InlineConverter(array('plugin')); $vote_count = 0; foreach ($lines as $linenum => $line) { if (strpos($line, ' ') === 0) { continue; } // skip pre $inlines = $ic->getObjects($line, $page); $pos = 0; foreach ($inlines as $inline) { if ($inline->name !== 'vote') { continue; } $pos = strpos($line, '&vote', $pos); if ($vote_id > $vote_count++) { $pos++; } else { $l_remain = substr($line, 0, $pos); $r_remain = substr($line, $pos + strlen($inline->text)); $arg = $inline->param; $body = $inline->body; $args = explode(',', $arg); list($votes, $options) = $this->parse_args_inline($args, $this->default_options); if ($options['readonly']) { return array(false, false, false, false); } foreach ($votes as $i => &$vote) { list($choice, $count) = $vote; if ($i == $choice_id) { ++$count; $vote = array($choice, $count); } } $new_args = $this->restore_args_inline($votes, $options, $this->default_options); $new_arg = implode(',', $new_args); $body = $body != '' ? '{' . $body . '};' : ';'; $newtext = '&vote(' . $new_arg . ')' . $body; $newline = $l_remain . $newtext . $r_remain; return array($linenum, $newline, $newtext, $votes); } } } return array(false, false, false, false); }