function plugin_urlbookmark_action() { global $script, $vars, $post, $now; if (auth::check_role('readonly')) { die_message('PKWK_READONLY prohibits editing'); } $post['msg'] = preg_replace("/\n/", '', $post['msg']); $url = $post['url']; if ($url == '') { return array('msg' => '', 'body' => ''); } $head = ''; if (preg_match('/^(-{1,2})(.*)/', $post['msg'], $match)) { $head = $match[1]; $post['msg'] = $match[2]; } $title = $post['title']; if ($title == '') { // try to get the title from the site $title = plugin_urlbookmark_get_title($url); } if ($title == '') { $_name = str_replace('$name', $url, URLBOOKMARK_NAME_FORMAT); } else { $patterns = array("/:/", "/\\[/", "/\\]/"); $replace = array(" ", "(", ")"); $title = preg_replace($patterns, $replace, $title); $_name = str_replace('$name', '[[' . $title . ":" . $url . ']]', URLBOOKMARK_NAME_FORMAT); } $_msg = str_replace('$msg', $post['msg'], URLBOOKMARK_MSG_FORMAT); $_now = $post['nodate'] == '1' ? '' : str_replace('$now', $now, URLBOOKMARK_NOW_FORMAT); $urlbookmark = str_replace("MSG", $_msg, URLBOOKMARK_FORMAT); $urlbookmark = str_replace("NAME", $_name, $urlbookmark); $urlbookmark = str_replace("NOW", $_now, $urlbookmark); $urlbookmark = $head . $urlbookmark; $postdata = ''; $postdata_old = get_source($post['refer']); $urlbookmark_no = 0; $urlbookmark_ins = $post['above'] == '1'; foreach ($postdata_old as $line) { if (!$urlbookmark_ins) { $postdata .= $line; } if (preg_match('/^#urlbookmark/', $line) and $urlbookmark_no++ == $post['urlbookmark_no']) { $postdata = rtrim($postdata) . "\n-{$urlbookmark}\n"; if ($urlbookmark_ins) { $postdata .= "\n"; } } if ($urlbookmark_ins) { $postdata .= $line; } } $title = _(" \$1 was updated"); $body = ''; if (md5(@join('', get_source($post['refer']))) != $post['digest']) { $title = _("On updating \$1, a collision has occurred."); $body = _("It seems that someone has already updated this page while you were editing it.<br />") . _("It is likely to be inserted in a different position though it bookmarked.<br />") . make_pagelink($post['refer']); } page_write($post['refer'], $postdata); $retvars['msg'] = $title; $retvars['body'] = $body; $post['page'] = $vars['page'] = $post['refer']; return $retvars; }
function plugin_urlbookmark_action() { global $vars, $post, $now, $_string; if (Auth::check_role('readonly')) { die_message(sprintf($_string['error_prohibit'], 'PKWK_READONLY')); } $post['msg'] = preg_replace("/\n/", '', $post['msg']); $url = $post['url']; if ($url == '') { return array('msg' => '', 'body' => ''); } $head = ''; if (preg_match('/^(-{1,2})(.*)/', $post['msg'], $match)) { $head = $match[1]; $post['msg'] = $match[2]; } $title = $post['title']; if ($title == '') { // try to get the title from the site $title = plugin_urlbookmark_get_title($url); } if ($title == '') { $_name = str_replace('$name', $url, URLBOOKMARK_NAME_FORMAT); } else { $patterns = array("/:/", "/\\[/", "/\\]/"); $replace = array(" ", "(", ")"); $title = preg_replace($patterns, $replace, $title); $_name = str_replace('$name', '[[' . $title . ":" . $url . ']]', URLBOOKMARK_NAME_FORMAT); } $_msg = str_replace('$msg', $post['msg'], URLBOOKMARK_MSG_FORMAT); $_now = $post['nodate'] == '1' ? '' : str_replace('$now', $now, URLBOOKMARK_NOW_FORMAT); $urlbookmark = str_replace("MSG", $_msg, URLBOOKMARK_FORMAT); $urlbookmark = str_replace("NAME", $_name, $urlbookmark); $urlbookmark = str_replace("NOW", $_now, $urlbookmark); $urlbookmark = $head . $urlbookmark; $postdata = array(); $wiki = Factory::Wiki($post['refer']); $urlbookmark_no = 0; $urlbookmark_ins = $post['above'] == '1'; foreach ($wiki->get() as $line) { if (!$urlbookmark_ins) { $postdata[] = $line; } if (preg_match('/^#urlbookmark/', $line) and $urlbookmark_no++ == $post['urlbookmark_no']) { $postdata[] = rtrim($postdata); $postdata[] = '-' . $urlbookmark; if ($urlbookmark_ins) { $postdata[] = ''; } } if ($urlbookmark_ins) { $postdata[] = $line; } } $title = T_(" \$1 was updated"); $body = ''; if ($wiki->digest() != $post['digest']) { $title = $_string['title_collided']; $body = $_string['msg_collided'] . make_pagelink($post['refer']); } $wiki->set($postdata); $retvars['msg'] = $title; $retvars['body'] = $body; $post['page'] = $vars['page'] = $post['refer']; return $retvars; }