Beispiel #1
0
 function get()
 {
     if (observer_prohibited(true)) {
         return login();
     }
     if (!feature_enabled(\App::$profile_uid, 'wiki')) {
         notice(t('Not found') . EOL);
         return;
     }
     $tab = 'wiki';
     require_once 'include/wiki.php';
     require_once 'include/acl_selectors.php';
     require_once 'include/conversation.php';
     // TODO: Combine the interface configuration into a unified object
     // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
     $wiki_owner = false;
     $showNewWikiButton = false;
     $showCommitMsg = false;
     $hidePageHistory = false;
     $pageHistory = array();
     $local_observer = null;
     $resource_id = '';
     // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1
     $nick = argv(1);
     $channel = get_channel_by_nick($nick);
     // The channel who owns the wikis being viewed
     if (!$channel) {
         notice('Invalid channel' . EOL);
         goaway('/' . argv(0));
     }
     // Determine if the observer is the channel owner so the ACL dialog can be populated
     if (local_channel() === intval($channel['channel_id'])) {
         $local_observer = \App::get_channel();
         $wiki_owner = true;
         // Obtain the default permission settings of the channel
         $channel_acl = array('allow_cid' => $local_observer['channel_allow_cid'], 'allow_gid' => $local_observer['channel_allow_gid'], 'deny_cid' => $local_observer['channel_deny_cid'], 'deny_gid' => $local_observer['channel_deny_gid']);
         // Initialize the ACL to the channel default permissions
         $x = array('lockstate' => $local_observer['channel_allow_cid'] || $local_observer['channel_allow_gid'] || $local_observer['channel_deny_cid'] || $local_observer['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '');
     } else {
         // Not the channel owner
         $channel_acl = $x = array();
     }
     switch (argc()) {
         case 2:
             // Configure page template
             $wikiheaderName = t('Wiki');
             $wikiheaderPage = t('Sandbox');
             require_once 'library/markdown.php';
             $content = t('"# Wiki Sandbox\\n\\nContent you **edit** and **preview** here *will not be saved*."');
             $renderedContent = Markdown(json_decode($content));
             $hide_editor = false;
             $showPageControls = false;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = false;
             $hidePageHistory = true;
             $showCommitMsg = false;
             break;
         case 3:
             // /wiki/channel/wiki -> No page was specified, so redirect to Home.md
             $wikiUrlName = urlencode(argv(2));
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/Home');
         case 4:
             // GET /wiki/channel/wiki/page
             // Fetch the wiki info and determine observer permissions
             $wikiUrlName = urlencode(argv(2));
             $pageUrlName = urlencode(argv(3));
             $w = wiki_exists_by_name($channel['channel_id'], $wikiUrlName);
             if (!$w['resource_id']) {
                 notice('Wiki not found' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1));
             }
             $resource_id = $w['resource_id'];
             if (!$wiki_owner) {
                 // Check for observer permissions
                 $observer_hash = get_observer_hash();
                 $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
                 if (!$perms['read']) {
                     notice('Permission denied.' . EOL);
                     goaway('/' . argv(0) . '/' . argv(1));
                 }
                 if ($perms['write']) {
                     $wiki_editor = true;
                 } else {
                     $wiki_editor = false;
                 }
             } else {
                 $wiki_editor = true;
             }
             $wikiheaderName = urldecode($wikiUrlName);
             $wikiheaderPage = urldecode($pageUrlName);
             $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             if (!$p['success']) {
                 notice('Error retrieving page content' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             }
             $content = $p['content'] !== '' ? htmlspecialchars_decode($p['content'], ENT_COMPAT) : '"# New page\\n"';
             // Render the Markdown-formatted page content in HTML
             require_once 'library/markdown.php';
             $html = wiki_generate_toc(purify_html(Markdown(json_decode($content))));
             $renderedContent = wiki_convert_links($html, argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             $hide_editor = false;
             $showPageControls = $wiki_editor;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = $wiki_editor;
             $hidePageHistory = false;
             $showCommitMsg = true;
             $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             break;
         default:
             // Strip the extraneous URL components
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/' . $pageUrlName);
     }
     $wikiModalID = random_string(3);
     $wikiModal = replace_macros(get_markup_template('generic_modal.tpl'), array('$id' => $wikiModalID, '$title' => t('Revision Comparison'), '$ok' => t('Revert'), '$cancel' => t('Cancel')));
     $is_owner = local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false;
     $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
     $o .= replace_macros(get_markup_template('wiki.tpl'), array('$wikiheaderName' => $wikiheaderName, '$wikiheaderPage' => $wikiheaderPage, '$hideEditor' => $hide_editor, '$showPageControls' => $showPageControls, '$showNewWikiButton' => $showNewWikiButton, '$showNewPageButton' => $showNewPageButton, '$hidePageHistory' => $hidePageHistory, '$showCommitMsg' => $showCommitMsg, '$channel' => $channel['channel_address'], '$resource_id' => $resource_id, '$page' => $pageUrlName, '$lockstate' => $x['lockstate'], '$acl' => $x['acl'], '$bang' => $x['bang'], '$content' => $content, '$renderedContent' => $renderedContent, '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''), '$pageRename' => array('pageRename', t('Enter the new name:'), '', ''), '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'), '$pageHistory' => $pageHistory['history'], '$wikiModal' => $wikiModal, '$wikiModalID' => $wikiModalID, '$commit' => 'HEAD', '$embedPhotos' => t('Embed image from photo albums'), '$embedPhotosModalTitle' => t('Embed an image from your albums'), '$embedPhotosModalCancel' => t('Cancel'), '$embedPhotosModalOK' => t('OK'), '$modalchooseimages' => t('Choose images to embed'), '$modalchoosealbum' => t('Choose an album'), '$modaldiffalbum' => t('Choose a different album...'), '$modalerrorlist' => t('Error getting album list'), '$modalerrorlink' => t('Error getting photo link'), '$modalerroralbum' => t('Error getting album')));
     head_add_js('library/ace/ace.js');
     // Ace Code Editor
     return $o;
 }
Beispiel #2
0
 function get()
 {
     require_once 'include/wiki.php';
     require_once 'include/acl_selectors.php';
     // TODO: Combine the interface configuration into a unified object
     // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
     $wiki_owner = false;
     $showNewWikiButton = false;
     $showCommitMsg = false;
     $hidePageHistory = false;
     $pageHistory = array();
     $local_observer = null;
     $resource_id = '';
     // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1
     $nick = argv(1);
     $channel = get_channel_by_nick($nick);
     // The channel who owns the wikis being viewed
     if (!$channel) {
         notice('Invalid channel' . EOL);
         goaway('/' . argv(0));
     }
     // Determine if the observer is the channel owner so the ACL dialog can be populated
     if (local_channel() === intval($channel['channel_id'])) {
         $local_observer = \App::get_channel();
         $wiki_owner = true;
         // Obtain the default permission settings of the channel
         $channel_acl = array('allow_cid' => $local_observer['channel_allow_cid'], 'allow_gid' => $local_observer['channel_allow_gid'], 'deny_cid' => $local_observer['channel_deny_cid'], 'deny_gid' => $local_observer['channel_deny_gid']);
         // Initialize the ACL to the channel default permissions
         $x = array('lockstate' => $local_observer['channel_allow_cid'] || $local_observer['channel_allow_gid'] || $local_observer['channel_deny_cid'] || $local_observer['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '');
     } else {
         // Not the channel owner
         $channel_acl = $x = array();
     }
     switch (argc()) {
         case 2:
             // Configure page template
             $wikiheader = t('Wiki Sandbox');
             $content = '"# Wiki Sandbox\\n\\nContent you **edit** and **preview** here *will not be saved*."';
             $hide_editor = false;
             $showPageControls = false;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = false;
             $hidePageHistory = true;
             $showCommitMsg = false;
             break;
         case 3:
             // /wiki/channel/wiki -> No page was specified, so redirect to Home.md
             $wikiUrlName = urlencode(argv(2));
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/Home');
         case 4:
             // GET /wiki/channel/wiki/page
             // Fetch the wiki info and determine observer permissions
             $wikiUrlName = urlencode(argv(2));
             $pageUrlName = urlencode(argv(3));
             $w = wiki_exists_by_name($channel['channel_id'], $wikiUrlName);
             if (!$w['resource_id']) {
                 notice('Wiki not found' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1));
             }
             $resource_id = $w['resource_id'];
             if (!$wiki_owner) {
                 // Check for observer permissions
                 $observer_hash = get_observer_hash();
                 $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
                 if (!$perms['read']) {
                     notice('Permission denied.' . EOL);
                     goaway('/' . argv(0) . '/' . argv(1));
                 }
                 if ($perms['write']) {
                     $wiki_editor = true;
                 } else {
                     $wiki_editor = false;
                 }
             } else {
                 $wiki_editor = true;
             }
             $wikiheader = urldecode($wikiUrlName) . ': ' . urldecode($pageUrlName);
             // show wiki name and page
             $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             if (!$p['success']) {
                 notice('Error retrieving page content' . EOL);
                 goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName);
             }
             $content = $p['content'] !== '' ? $p['content'] : '"# New page\\n"';
             $hide_editor = false;
             $showPageControls = $wiki_editor;
             $showNewWikiButton = $wiki_owner;
             $showNewPageButton = $wiki_editor;
             $hidePageHistory = false;
             $showCommitMsg = true;
             $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
             break;
         default:
             // Strip the extraneous URL components
             goaway('/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/' . $pageUrlName);
     }
     // Render the Markdown-formatted page content in HTML
     require_once 'library/markdown.php';
     $o .= replace_macros(get_markup_template('wiki.tpl'), array('$wikiheader' => $wikiheader, '$hideEditor' => $hide_editor, '$showPageControls' => $showPageControls, '$showNewWikiButton' => $showNewWikiButton, '$showNewPageButton' => $showNewPageButton, '$hidePageHistory' => $hidePageHistory, '$showCommitMsg' => $showCommitMsg, '$channel' => $channel['channel_address'], '$resource_id' => $resource_id, '$page' => $pageUrlName, '$lockstate' => $x['lockstate'], '$acl' => $x['acl'], '$bang' => $x['bang'], '$content' => $content, '$renderedContent' => Markdown(json_decode($content)), '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''), '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'), '$pageHistory' => $pageHistory['history']));
     head_add_js('library/ace/ace.js');
     // Ace Code Editor
     return $o;
 }