if ($input['guid']) { $markdown_wiki = get_entity($input['guid']); if (!$markdown_wiki) { register_error(elgg_echo('markdown_wiki:error:no_entity')); forward(REFERER); } if (!$markdown_wiki->canEdit($user_guid)) { register_error(elgg_echo('markdown_wiki:error:no_access')); forward(REFERER); } $new_markdown_wiki = false; $old_markdown_wiki_annotations = $markdown_wiki->getAnnotations('markdown_wiki', 1, 0, 'desc'); $value = unserialize($old_markdown_wiki_annotations[0]->value); $old_description = $value['text']; } else { if ($page = search_markdown_wiki_by_title($input['title'], $input['container_guid'])) { register_error(elgg_echo('markdown_wiki:error:already_exist')); forward(elgg_get_site_url() . "wiki/group/{$input['container_guid']}/page/{$page}/{$input['title']}"); } $markdown_wiki = new ElggObject(); $markdown_wiki->subtype = 'markdown_wiki'; $markdown_wiki->access_id = 2; $new_markdown_wiki = true; $old_description = ''; } unset($input['guid']); // don't want to override guid cause if it's new page if (sizeof($input) > 0) { foreach ($input as $name => $value) { $markdown_wiki->{$name} = $value; }
function _parse_link_callback($matches) { // link $array_match = explode('#', $matches[2]); $link = rtrim($array_match[0], '/'); $html_link = urlencode($link); $hash = $array_match[1] ? '\\#' . $array_match[1] : ''; // check if link is like (apage#aparagraph) // title $word = strip_tags(rtrim($matches[1], '/')); $html_word = strpos($word, '%%%') ? $word : urlencode($word); // check if title contain link (eg: wrap link on image) $group = elgg_get_page_owner_guid(); //if ($group == 0) $group = elgg_get_logged_in_user_guid(); no wiki for user ? $site_url = elgg_get_site_url(); $info = elgg_echo('markdown_wiki:create'); if (!$link) { // markdown syntax like [a link]() or [a link](#paragraph) $link = rtrim($matches[1], '/'); } if (strpos($link, '://') !== false) { if (strpos($link, $site_url) === false) { // external link return "<a rel='nofollow' target='_blank' href='" . $link . "' class='external'>{$matches['1']}</a><span class='elgg-icon external'></span>"; } else { // internal link with http:// return '<a href="' . $link . '">' . $matches[1] . '</a>'; } } else { if (preg_match('/^groupe?\\/(\\w+)\\/page\\/(.*)/', $link, $relative) || preg_match('/^(\\w+):(.*)/', $link, $relative)) { if (is_numeric($relative[1])) { if (is_numeric($relative[2])) { $page = get_entity($relative[2]); return "<a href='{$page->getUrl()}{$hash}'>{$matches[1]}</a>"; } elseif ($page_guid = search_markdown_wiki_by_title($relative[2], $relative[1])) { // page exists $page = get_entity($page_guid); return "<a href='{$page->getUrl()}{$hash}'>{$matches[1]}</a>"; } else { // page doesn't exists $relative[2] = urlencode($relative[2]); return "<a href='{$site_url}wiki/search?container_guid={$relative[1]}&q={$relative[2]}' class='tooltip s new' title=\"{$info}\">{$matches[1]}</a>"; } } else { if ($gtitle = search_group_by_title($relative[1])) { if ($page_guid = search_markdown_wiki_by_title($relative[2], $gtitle)) { // page exists $page = get_entity($page_guid); return "<a href='{$page->getUrl()}{$hash}'>{$matches[1]}</a>"; } else { // page doesn't exists $relative[2] = urlencode($relative[2]); return "<a href='{$site_url}wiki/search?container_guid={$gtitle}&q={$relative[2]}' class='tooltip s new' title=\"{$info}\">{$matches[1]}</a>"; } } else { return "<a href='{$site_url}wiki/search?container_guid={$group}&q={$relative[2]}' class='tooltip s new' title=\"{$info}\">{$matches[1]}</a>"; } } } elseif ($page_guid = search_markdown_wiki_by_title($link, $group)) { // page exists $page = get_entity($page_guid); return "<a href='{$page->getUrl()}{$hash}'>{$matches[1]}</a>"; } else { // page doesn't exists return "<a href='{$site_url}wiki/search?container_guid={$group}&q={$html_link}' class='tooltip s new' title=\"{$info}\">{$matches[1]}</a>"; } } }