function post() { // logger('file upload: ' . print_r($_REQUEST,true)); $channel = $_REQUEST['channick'] ? get_channel_by_nick($_REQUEST['channick']) : null; if (!$channel) { logger('channel not found'); killme(); } $_REQUEST['source'] = 'file_upload'; if ($channel['channel_id'] != local_channel()) { $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']); $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']); $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']); $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']); } if ($_REQUEST['filename']) { $_REQUEST['allow_cid'] = perms2str($_REQUEST['contact_allow']); $_REQUEST['allow_gid'] = perms2str($_REQUEST['group_allow']); $_REQUEST['deny_cid'] = perms2str($_REQUEST['contact_deny']); $_REQUEST['deny_gid'] = perms2str($_REQUEST['group_deny']); $r = attach_mkdir($channel, get_observer_hash(), $_REQUEST); } else { $r = attach_store($channel, get_observer_hash(), '', $_REQUEST); } goaway(z_root() . '/' . $_REQUEST['return_url']); }
function post() { $using_api = false; if (\App::$data['api_info'] && array_key_exists('media', $_FILES)) { $using_api = true; $user_info = \App::$data['api_info']; $nick = $user_info['screen_name']; $channel = get_channel_by_nick($user_info['screen_name']); } elseif (argc() > 1) { $channel = get_channel_by_nick(argv(1)); } if (!$channel) { killme(); } $observer = \App::get_observer(); $def_album = get_pconfig($channel['channel_id'], 'system', 'photo_path'); $def_attach = get_pconfig($channel['channel_id'], 'system', 'attach_path'); $r = attach_store($channel, $observer ? $observer['xchan_hash'] : '', '', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'allow_cid' => '<' . $channel['channel_hash'] . '>')); if (!$r['success']) { notice($r['message'] . EOL); killme(); } if (intval($r['data']['is_photo'])) { $s = "\n\n" . $r['body'] . "\n\n"; } else { $s = "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n"; } if ($using_api) { return $s; } echo $s; killme(); }
function wall_attach_post(&$a) { $using_api = false; if ($a->data['api_info'] && array_key_exists('media', $_FILES)) { $using_api = true; $user_info = $a->data['api_info']; $nick = $user_info['screen_name']; $channel = get_channel_by_nick($user_info['screen_name']); } elseif (argc() > 1) { $channel = get_channel_by_nick(argv(1)); } if (!$channel) { killme(); } $observer = $a->get_observer(); // if($_FILES['userfile']['tmp_name']) { // $x = @getimagesize($_FILES['userfile']['tmp_name']); // logger('getimagesize: ' . print_r($x,true), LOGGER_DATA); // if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) { // $args = array( 'source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash'])); // $ret = photo_upload($channel,$observer,$args); // if($ret['success']) { // echo "\n\n" . $ret['body'] . "\n\n"; // killme(); // } // if($using_api) // return; // notice($ret['message']); // killme(); // } // } $def_album = get_pconfig($channel['channel_id'], 'system', 'photo_path'); $def_attach = get_pconfig($channel['channel_id'], 'system', 'attach_path'); $r = attach_store($channel, $observer ? $observer['xchan_hash'] : '', '', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'allow_cid' => '<' . $channel['channel_hash'] . '>')); if (!$r['success']) { notice($r['message'] . EOL); killme(); } if (intval($r['data']['is_photo'])) { $s = "\n\n" . $r['body'] . "\n\n"; } else { $s = "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n"; } if ($using_api) { return $s; } echo $s; killme(); }
function wall_attach_post(&$a) { if (argc() > 1) { $channel = get_channel_by_nick(argv(1)); } else { killme(); } $r = attach_store($channel, get_observer_hash()); if (!$r['success']) { notice($r['message'] . EOL); killme(); } echo "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n"; killme(); }
function wall_attach_post(&$a) { if (argc() > 1) { $channel = get_channel_by_nick(argv(1)); } elseif ($_FILES['media']) { require_once 'include/api.php'; $user_info = api_get_user($a); $nick = $user_info['screen_name']; $channel = get_channel_by_nick($user_info['screen_name']); } if (!$channel) { killme(); } $observer = $a->get_observer(); if ($_FILES['userfile']['tmp_name']) { $x = @getimagesize($_FILES['userfile']['tmp_name']); logger('getimagesize: ' . print_r($x, true), LOGGER_DATA); if ($x && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) { $args = array('source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash'])); $ret = photo_upload($channel, $observer, $args); if ($ret['success']) { echo "\n\n" . $ret['body'] . "\n\n"; killme(); } if ($using_api) { return; } notice($ret['message']); killme(); } } $r = attach_store($channel, $observer ? $observer['xchan_hash'] : ''); if (!$r['success']) { notice($r['message'] . EOL); killme(); } echo "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n"; killme(); }
function wall_upload_post(&$a) { $using_api = x($_FILES, 'media') ? true : false; if ($using_api) { require_once 'include/api.php'; $user_info = api_get_user($a); $nick = $user_info['screen_name']; } else { if (argc() > 1) { $nick = argv(1); } } $channel = $nick ? get_channel_by_nick($nick) : false; if (!$channel) { if ($using_api) { return; } notice(t('Channel not found.') . EOL); killme(); } $observer = $a->get_observer(); $args = array('source' => 'editor', 'album' => t('Wall Photos'), 'not_visible' => 1, 'contact_allow' => array($channel['channel_hash'])); $ret = photo_upload($channel, $observer, $args); if (!$ret['success']) { if ($using_api) { return; } notice($ret['message']); killme(); } $m = $ret['body']; if ($using_api) { return "\n\n" . $ret['body'] . "\n\n"; } else { echo "\n\n" . $ret['body'] . "\n\n"; } killme(); }
function widget_wiki_list($arr) { require_once "include/wiki.php"; $channel = null; if (argc() < 2 && local_channel()) { // This should not occur because /wiki should redirect to /wiki/channel ... $channel = \App::get_channel(); } else { $channel = get_channel_by_nick(argv(1)); // Channel being viewed by observer } if (!$channel) { return ''; } $wikis = wiki_list($channel, get_observer_hash()); if ($wikis) { return replace_macros(get_markup_template('wikilist.tpl'), array('$header' => t('Wiki List'), '$channel' => $channel['channel_address'], '$wikis' => $wikis['wikis'], '$showControls' => local_channel() === intval($channel['channel_id']) ? true : false)); } return ''; }
function post() { require_once 'include/wiki.php'; // /wiki/channel/preview // Render mardown-formatted text in HTML for preview if (argc() > 2 && argv(2) === 'preview') { $content = $_POST['content']; $resource_id = $_POST['resource_id']; require_once 'library/markdown.php'; $html = wiki_generate_toc(purify_html(Markdown($content))); $w = wiki_get_wiki($resource_id); $wikiURL = argv(0) . '/' . argv(1) . '/' . $w['urlName']; $html = wiki_convert_links($html, $wikiURL); json_return_and_die(array('html' => $html, 'success' => true)); } // Create a new wiki // /wiki/channel/create/wiki if (argc() > 3 && argv(2) === 'create' && argv(3) === 'wiki') { $nick = argv(1); $channel = get_channel_by_nick($nick); // Determine if observer has permission to create wiki $observer_hash = get_observer_hash(); // Only the channel owner can create a wiki, at least until we create a // more detail permissions framework if (local_channel() !== intval($channel['channel_id'])) { goaway('/' . argv(0) . '/' . $nick . '/'); } $wiki = array(); // Generate new wiki info from input name $wiki['postVisible'] = intval($_POST['postVisible']) === 0 ? 0 : 1; $wiki['rawName'] = $_POST['wikiName']; $wiki['htmlName'] = escape_tags($_POST['wikiName']); $wiki['urlName'] = urlencode($_POST['wikiName']); if ($wiki['urlName'] === '') { notice('Error creating wiki. Invalid name.'); goaway('/wiki'); } // Get ACL for permissions $acl = new \Zotlabs\Access\AccessList($channel); $acl->set_from_array($_POST); $r = wiki_create_wiki($channel, $observer_hash, $wiki, $acl); if ($r['success']) { $homePage = wiki_create_page('Home', $r['item']['resource_id']); if (!$homePage['success']) { notice('Wiki created, but error creating Home page.'); goaway('/wiki/' . $nick . '/' . $wiki['urlName']); } goaway('/wiki/' . $nick . '/' . $wiki['urlName'] . '/' . $homePage['page']['urlName']); } else { notice('Error creating wiki'); goaway('/wiki'); } } // Delete a wiki if (argc() > 3 && argv(2) === 'delete' && argv(3) === 'wiki') { $nick = argv(1); $channel = get_channel_by_nick($nick); // Only the channel owner can delete a wiki, at least until we create a // more detail permissions framework if (local_channel() !== intval($channel['channel_id'])) { logger('Wiki delete permission denied.' . EOL); json_return_and_die(array('message' => 'Wiki delete permission denied.', 'success' => false)); } $resource_id = $_POST['resource_id']; $deleted = wiki_delete_wiki($resource_id); if ($deleted['success']) { json_return_and_die(array('message' => '', 'success' => true)); } else { logger('Error deleting wiki: ' . $resource_id); json_return_and_die(array('message' => 'Error deleting wiki', 'success' => false)); } } // Create a page if (argc() === 4 && argv(2) === 'create' && argv(3) === 'page') { $nick = argv(1); $resource_id = $_POST['resource_id']; // Determine if observer has permission to create a page $channel = get_channel_by_nick($nick); if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['write']) { logger('Wiki write permission denied. ' . EOL); json_return_and_die(array('success' => false)); } } $name = $_POST['name']; //Get new page name if (urlencode(escape_tags($_POST['name'])) === '') { json_return_and_die(array('message' => 'Error creating page. Invalid name.', 'success' => false)); } $page = wiki_create_page($name, $resource_id); if ($page['success']) { json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . urlencode($page['page']['urlName']), 'success' => true)); } else { logger('Error creating page'); json_return_and_die(array('message' => 'Error creating page.', 'success' => false)); } } // Fetch page list for a wiki if (argc() === 5 && argv(2) === 'get' && argv(3) === 'page' && argv(4) === 'list') { $resource_id = $_POST['resource_id']; // resource_id for wiki in db $channel = get_channel_by_nick(argv(1)); $observer_hash = get_observer_hash(); if (local_channel() !== intval($channel['channel_id'])) { $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['read']) { logger('Wiki read permission denied.' . EOL); json_return_and_die(array('pages' => null, 'message' => 'Permission denied.', 'success' => false)); } } $page_list_html = widget_wiki_pages(array('resource_id' => $resource_id, 'refresh' => true, 'channel' => argv(1))); json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true)); } // Save a page if (argc() === 4 && argv(2) === 'save' && argv(3) === 'page') { $resource_id = $_POST['resource_id']; $pageUrlName = $_POST['name']; $pageHtmlName = escape_tags($_POST['name']); $content = $_POST['content']; //Get new content $commitMsg = $_POST['commitMsg']; if ($commitMsg === '') { $commitMsg = 'Updated ' . $pageHtmlName; } $nick = argv(1); $channel = get_channel_by_nick($nick); // Determine if observer has permission to save content if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['write']) { logger('Wiki write permission denied. ' . EOL); json_return_and_die(array('success' => false)); } } $saved = wiki_save_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'content' => $content)); if ($saved['success']) { $ob = \App::get_observer(); $commit = wiki_git_commit(array('commit_msg' => $commitMsg, 'resource_id' => $resource_id, 'observer' => $ob, 'files' => array($pageUrlName . '.md'))); if ($commit['success']) { json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true)); } else { json_return_and_die(array('message' => 'Error making git commit', 'success' => false)); } } else { json_return_and_die(array('message' => 'Error saving page', 'success' => false)); } } // Update page history // /wiki/channel/history/page if (argc() === 4 && argv(2) === 'history' && argv(3) === 'page') { $resource_id = $_POST['resource_id']; $pageUrlName = $_POST['name']; $nick = argv(1); $channel = get_channel_by_nick($nick); // Determine if observer has permission to read content if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['read']) { logger('Wiki read permission denied.' . EOL); json_return_and_die(array('historyHTML' => '', 'message' => 'Permission denied.', 'success' => false)); } } $historyHTML = widget_wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true)); } // Delete a page if (argc() === 4 && argv(2) === 'delete' && argv(3) === 'page') { $resource_id = $_POST['resource_id']; $pageUrlName = $_POST['name']; if ($pageUrlName === 'Home') { json_return_and_die(array('message' => 'Cannot delete Home', 'success' => false)); } // Determine if observer has permission to delete pages $nick = argv(1); $channel = get_channel_by_nick($nick); if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['write']) { logger('Wiki write permission denied. ' . EOL); json_return_and_die(array('success' => false)); } } $deleted = wiki_delete_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); if ($deleted['success']) { $ob = \App::get_observer(); $commit = wiki_git_commit(array('commit_msg' => 'Deleted ' . $pageUrlName, 'resource_id' => $resource_id, 'observer' => $ob, 'files' => null)); if ($commit['success']) { json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true)); } else { json_return_and_die(array('message' => 'Error making git commit', 'success' => false)); } } else { json_return_and_die(array('message' => 'Error deleting page', 'success' => false)); } } // Revert a page if (argc() === 4 && argv(2) === 'revert' && argv(3) === 'page') { $resource_id = $_POST['resource_id']; $pageUrlName = $_POST['name']; $commitHash = $_POST['commitHash']; // Determine if observer has permission to revert pages $nick = argv(1); $channel = get_channel_by_nick($nick); if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['write']) { logger('Wiki write permission denied.' . EOL); json_return_and_die(array('success' => false)); } } $reverted = wiki_revert_page(array('commitHash' => $commitHash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); if ($reverted['success']) { json_return_and_die(array('content' => $reverted['content'], 'message' => '', 'success' => true)); } else { json_return_and_die(array('content' => '', 'message' => 'Error reverting page', 'success' => false)); } } // Compare page revisions if (argc() === 4 && argv(2) === 'compare' && argv(3) === 'page') { $resource_id = $_POST['resource_id']; $pageUrlName = $_POST['name']; $compareCommit = $_POST['compareCommit']; $currentCommit = $_POST['currentCommit']; // Determine if observer has permission to revert pages $nick = argv(1); $channel = get_channel_by_nick($nick); if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['read']) { logger('Wiki read permission denied.' . EOL); json_return_and_die(array('success' => false)); } } $compare = wiki_compare_page(array('currentCommit' => $currentCommit, 'compareCommit' => $compareCommit, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); if ($compare['success']) { $diffHTML = '<table class="text-center" width="100%"><tr><td class="lead" width="50%">Current Revision</td><td class="lead" width="50%">Selected Revision</td></tr></table>' . $compare['diff']; json_return_and_die(array('diff' => $diffHTML, 'message' => '', 'success' => true)); } else { json_return_and_die(array('diff' => '', 'message' => 'Error comparing page', 'success' => false)); } } // Rename a page if (argc() === 4 && argv(2) === 'rename' && argv(3) === 'page') { $resource_id = $_POST['resource_id']; $pageUrlName = $_POST['oldName']; $pageNewName = $_POST['newName']; if ($pageUrlName === 'Home') { json_return_and_die(array('message' => 'Cannot rename Home', 'success' => false)); } if (urlencode(escape_tags($pageNewName)) === '') { json_return_and_die(array('message' => 'Error renaming page. Invalid name.', 'success' => false)); } // Determine if observer has permission to rename pages $nick = argv(1); $channel = get_channel_by_nick($nick); if (local_channel() !== intval($channel['channel_id'])) { $observer_hash = get_observer_hash(); $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash); if (!$perms['write']) { logger('Wiki write permission denied. ' . EOL); json_return_and_die(array('success' => false)); } } $renamed = wiki_rename_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'pageNewName' => $pageNewName)); if ($renamed['success']) { $ob = \App::get_observer(); $commit = wiki_git_commit(array('commit_msg' => 'Renamed ' . urldecode($pageUrlName) . ' to ' . $renamed['page']['htmlName'], 'resource_id' => $resource_id, 'observer' => $ob, 'files' => array($pageUrlName . '.md', $renamed['page']['fileName']), 'all' => true)); if ($commit['success']) { json_return_and_die(array('name' => $renamed['page'], 'message' => 'Wiki git repo commit made', 'success' => true)); } else { json_return_and_die(array('message' => 'Error making git commit', 'success' => false)); } } else { json_return_and_die(array('message' => 'Error renaming page', 'success' => false)); } } //notice('You must be authenticated.'); json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false)); }
function editblock_content(&$a) { if (argc() < 2) { notice(t('Item not found') . EOL); return; } $channel = get_channel_by_nick(argv(1)); if ($c) { $owner = intval($channel['channel_id']); } $o = ''; // Figure out which post we're editing $post_id = argc() > 2 ? intval(argv(2)) : 0; if (!($post_id && $channel)) { notice(t('Item not found') . EOL); return; } // Now we've got a post and an owner, let's find out if we're allowed to edit it if (!perm_is_allowed($channel['channel_id'], get_observer_hash(), 'write_pages')) { notice(t('Permission denied.') . EOL); return; } // We've already figured out which item we want and whose copy we need, so we don't need anything fancy here $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", intval($post_id), intval($channel['channel_id'])); if ($itm) { $item_id = q("select * from item_id where service = 'BUILDBLOCK' and iid = %d limit 1", $itm[0]['id']); if ($item_id) { $block_title = $item_id[0]['sid']; } } else { notice(t('Item not found') . EOL); return; } $plaintext = true; // You may or may not be a local user. // if(local_user() && feature_enabled(local_user(),'richtext')) // $plaintext = false; $mimeselect = ''; $mimetype = $itm[0]['mimetype']; if ($mimetype != 'text/bbcode') { $plaintext = true; } if (get_config('system', 'page_mimetype')) { $mimeselect = '<input type="hidden" name="mimetype" value="' . $mimetype . '" />'; } else { $mimeselect = mimetype_select($itm[0]['uid'], $mimetype); } $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit Block'))); $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$ispublic' => ' ', '$geotag' => '', '$nickname' => $channel['channel_address'], '$confirmdelete' => t('Delete block?'))); $tpl = get_markup_template("jot.tpl"); $jotplugins = ''; $jotnets = ''; call_hooks('jot_tool', $jotplugins); call_hooks('jot_networks', $jotnets); //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins)); // FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD instead of loading a sensible page. //So, send folk to the webpage list. $rp = 'blocks/' . $channel['channel_address']; $o .= replace_macros($tpl, array('$return_path' => $rp, '$action' => 'item', '$webpage' => ITEM_BUILDBLOCK, '$share' => t('Edit'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$weblink' => t('Insert web link'), '$youtube' => t('Insert YouTube video'), '$video' => t('Insert Vorbis [.ogg] video'), '$audio' => t('Insert Vorbis [.ogg] audio'), '$setloc' => t('Set your location'), '$noloc' => t('Clear browser location'), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], '$mimeselect' => $mimeselect, '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$baseurl' => $a->get_baseurl(), '$defloc' => $channel['channel_location'], '$visitor' => false, '$public' => t('Public post'), '$jotnets' => $jotnets, '$title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), '$placeholdertitle' => t('Set title'), '$pagetitle' => $block_title, '$category' => '', '$placeholdercategory' => t('Categories (comma-separated list)'), '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', '$bang' => '', '$profile_uid' => intval($channel['channel_id']), '$preview' => feature_enabled(local_user(), 'preview') ? t('Preview') : '', '$jotplugins' => $jotplugins, '$sourceapp' => $itm[0]['app'], '$defexpire' => '', '$feature_expire' => false, '$expires' => t('Set expiration date'))); $ob = get_observer_hash(); if ($itm[0]['author_xchan'] === $ob || $itm[0]['owner_xchan'] === $ob) { $o .= '<br /><br /><a class="block-delete-link" href="item/drop/' . $itm[0]['id'] . '" >' . t('Delete Block') . '</a><br />'; } return $o; }