/** * Check if the user has permission to perform the action. * * @param integer $projectId * @param string $action * * @return boolean */ function has_permission($action, $projectId = null, $fetchProjectRoles = false) { if (!$projectId) { $currentProject = current_project(); $projectId = $currentProject['id']; } if (!($user = current_user())) { $user = anonymous_user(); } return $user->hasPermission($action, $projectId, $fetchProjectRoles); }
/** * Converts the wiki [[page]] and [[text|page]] to HTML links. * * @param string $text * * @return string */ public static function wikiLinks($text) { return preg_replace_callback("|\\[\\[(?P<page>[\\w\\d\\-_]+)(\\|(?P<text>[\\s\\w\\d\\-_]+))?\\]\\]|", function ($matches) { $project = current_project(); if (!$project) { return $matches[0]; } if (!isset($matches['text'])) { $matches['text'] = $matches['page']; } return HTML::link($matches['text'], routePath('wiki_page', ['slug' => $matches['page']])); }, $text); }