Example #1
0
 function setParam($page, $name, $body, $type = '', $alias = '')
 {
     static $converter = NULL;
     $this->page = $page;
     $this->name = $name;
     $this->body = $body;
     $this->type = $type;
     if (!PKWK_DISABLE_INLINE_IMAGE_FROM_URI && is_url($alias) && preg_match('/\\.(gif|png|jpe?g)$/i', $alias)) {
         $alias = '<img src="' . htmlspecialchars($alias) . '" alt="' . $name . '" />';
     } else {
         if ($alias != '') {
             if ($converter === NULL) {
                 $converter = new InlineConverter(array('plugin'));
             }
             $alias = make_line_rules($converter->convert($alias, $page));
             // BugTrack/669: A hack removing anchor tags added by AutoLink
             $alias = preg_replace('#</?a[^>]*>#i', '', $alias);
         }
     }
     $this->alias = $alias;
     return TRUE;
 }
Example #2
0
 /**
  * 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);
 }
Example #3
0
function plugin_vote2_action_inline($vote_no)
{
    global $get, $vars, $script, $cols, $rows, $_vote2_messages;
    //	global $_title_collided,$_msg_collided,$_title_updated;
    global $_vote_plugin_choice, $_vote_plugin_votes;
    $_title_collided = _("On updating \$1, a collision has occurred.");
    $_title_updated = _("\$1 was updated");
    $_msg_collided = _("It seems that someone has already updated this page while you were editing it.<br />") . _(" + is placed at the beginning of a line that was newly added.<br />") . _(" ! is placed at the beginning of a line that has possibly been updated.<br />") . _(" Edit those lines, and submit again.");
    //$_vote_plugin_choice = _("Selection");
    //$_vote_plugin_votes  = _("Vote");
    $str_notimestamp = $_vote2_messages['arg_notimestamp'];
    $str_nonumber = $_vote2_messages['arg_nonumber'];
    $str_nolabel = $_vote2_messages['arg_nolabel'];
    $str_notitle = $_vote2_messages['arg_notitle'];
    $str_plugin = 'vote2';
    $len_plugin = strlen($str_plugin) + 1;
    $title = $body = $postdata = '';
    $vote_ct = $skipflag = 0;
    $page = $vars['page'];
    $postdata_old = get_source($vars['refer']);
    $ic = new InlineConverter(array('plugin'));
    $notimestamp = $update_flag = FALSE;
    foreach ($postdata_old as $line) {
        if ($skipflag || substr($line, 0, 1) == ' ' || substr($line, 0, 2) == '//') {
            $postdata .= $line;
            continue;
        }
        $pos = 0;
        $arr = $ic->get_objects($line, $page);
        while (count($arr)) {
            $obj = array_shift($arr);
            if ($obj->name != $str_plugin) {
                continue;
            }
            $pos = strpos($line, '&' . $str_plugin, $pos);
            if ($vote_ct++ < $vote_no) {
                $pos += $len_plugin;
                continue;
            }
            $l_line = substr($line, 0, $pos);
            $r_line = substr($line, $pos + strlen($obj->text));
            $options = explode(',', $obj->param);
            $cnt = 0;
            $name = '';
            $vote = array();
            foreach ($options as $opt) {
                $arg = trim($opt);
                if ($arg == '') {
                    continue;
                }
                if ($arg == $str_notimestamp) {
                    $notimestamp = TRUE;
                    $vote[] = $arg;
                    continue;
                }
                if ($arg == $str_nonumber || $arg == $str_nolabel || $arg == $str_notitle) {
                    $vote[] = $arg;
                    continue;
                }
                if (preg_match("/^.+(?==)=[+-]?\\d+[bir]?\$/", $arg, $match)) {
                    $vote[] = $arg;
                    continue;
                }
                if ($name == '' and preg_match("/^(.*)\\[(\\d+)\\]\$/", $arg, $match)) {
                    $name = $match[1];
                    $cnt = $match[2];
                    continue;
                } else {
                    if ($name == '') {
                        $name = $arg;
                        continue;
                    }
                }
                $vote[] = $arg;
            }
            array_unshift($vote, $name . '[' . ($cnt + 1) . ']');
            $vote_str = "&{$str_plugin}(" . join(',', $vote) . ');';
            $pline = $l_line . $vote_str . $r_line;
            if ($pline !== $line) {
                $update_flag = TRUE;
            }
            $postdata_input = $line = $pline;
            $skipflag = 1;
            break;
        }
        $postdata .= $line;
    }
    // if ( md5(@join('',get_source($vars['refer']))) != $vars['digest'])
    if (md5(@join('', $postdata_old)) != $vars['digest']) {
        $title = $_title_collided;
        $body = $_vote2_messages['msg_collided'] . make_pagelink($vars['refer']) . "<hr />\n {$postdata_input}";
    } else {
        if ($update_flag == TRUE) {
            page_write($vars['refer'], $postdata, $notimestamp);
            $title = $_title_updated;
            //$body = convert_html($postdata . "\n----\n"). $postdata_input . "/" . $vote_str . "/" . $vote . "/" . $name;
            //$title = "debug for vote2";
        } else {
            $title = $_vote2_messages['update_failed'];
        }
    }
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    $get['page'] = $vars['refer'];
    $vars['page'] = $vars['refer'];
    unset($postdata_old, $postdata);
    return $retvars;
}
 function make_inline($string, $page = '')
 {
     global $vars;
     static $converter;
     if (!isset($converter)) {
         $converter = new InlineConverter(array('plugin'));
     }
     $clone = $converter->get_clone($converter);
     return $clone->convert($string, $page != '' ? $page : $vars['page']);
 }
Example #5
0
	function setParam($page,$name,$type='',$alias='')
	{
		static $converter = NULL;
		
		$this->page = $page;
		$this->name = $name;
		$this->type = $type;
		if ($type != 'InterWikiName' and preg_match('/\.(gif|png|jpe?g)$/i',$alias))
		{
			$alias = htmlspecialchars($alias);
			$alias = "<img src=\"$alias\" alt=\"$name\" />";
		}
		else if ($alias != '')
		{
			if ($converter === NULL)
			{
				$converter = new InlineConverter(array('plugin'));
			}
			$alias = make_line_rules($converter->convert($alias,$page));
		}
		$this->alias = $alias;
		
		return TRUE;
	}