From b161d4073def64abf0b2c8d61a19f5f7a6673380 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Fri, 9 Aug 2013 18:30:30 +0100 Subject: Allow creation of webpages at channels other than your own. --- mod/webpages.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'mod') diff --git a/mod/webpages.php b/mod/webpages.php index f2026ea0b..9e885c14b 100644 --- a/mod/webpages.php +++ b/mod/webpages.php @@ -1,6 +1,6 @@ 1) $which = argv(1); @@ -20,14 +20,24 @@ function webpages_init(&$a) { profile_load($a,$which,$profile); -} - -function webpages_content(&$a) { + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + } // We can do better, but since editing only works for local users and all posts are webpages, return anyone else for now. -if (!local_user()) return; + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + if(! $perms['write_pages']) { + notice( t('Permission denied.') . EOL); + return; + } // Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages require_once ('include/conversation.php'); @@ -38,7 +48,7 @@ require_once ('include/conversation.php'); 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), 'bang' => (($group || $cid) ? '!' : ''), 'visitor' => 'block', - 'profile_uid' => local_user() + 'profile_uid' => intval($owner), ); $o .= status_editor($a,$x); @@ -47,7 +57,7 @@ require_once ('include/conversation.php'); // FIXME - we should sort these results, but it's not obvious what order yet. Alphabetical? Created order? $r = q("select * from item_id where uid = %d and service = 'WEBPAGE'", - intval(local_user()) + intval($owner) ); $pages = null; @@ -61,13 +71,13 @@ $r = q("select * from item_id where uid = %d and service = 'WEBPAGE'", //Build the base URL for edit links - $url = z_root() . "/editwebpage/" . $a->profile['channel_address']; + $url = z_root() . "/editwebpage/" . $which; // This isn't pretty, but it works. Until I figure out what to do with the UI, it's Good Enough(TM). return $o . replace_macros(get_markup_template("webpagelist.tpl"), array( '$baseurl' => $url, '$edit' => t('Edit'), '$pages' => $pages, - '$channel' => $a->profile['channel_address'], + '$channel' => $which, '$view' => t('View'), )); -- cgit v1.2.3 From 4ac5348b3f7cecceee62d92f53df0f4ab6c22074 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Fri, 9 Aug 2013 19:56:36 +0100 Subject: Small improvement --- mod/webpages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/webpages.php b/mod/webpages.php index 9e885c14b..8e3901d90 100644 --- a/mod/webpages.php +++ b/mod/webpages.php @@ -56,7 +56,7 @@ require_once ('include/conversation.php'); //Get a list of webpages. We can't display all them because endless scroll makes that unusable, so just list titles and an edit link. // FIXME - we should sort these results, but it's not obvious what order yet. Alphabetical? Created order? -$r = q("select * from item_id where uid = %d and service = 'WEBPAGE'", +$r = q("select * from item_id where uid = %d and service = 'WEBPAGE' order by sid asc", intval($owner) ); -- cgit v1.2.3 From 94335f237fdadd93b86b271526c25c2a77de9c40 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Sat, 10 Aug 2013 22:06:30 +0100 Subject: Initial shot at write_pages widget --- mod/page.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/page.php b/mod/page.php index 51b292f37..1bdc3027a 100644 --- a/mod/page.php +++ b/mod/page.php @@ -2,6 +2,8 @@ require_once('include/items.php'); require_once('include/conversation.php'); +require_once('include/page_widgets.php'); + function page_init(&$a) { // We need this to make sure the channel theme is always loaded. $which = argv(1); @@ -32,7 +34,6 @@ function page_content(&$a) { return; } - if(argc() < 3) { notice( t('Invalid item.') . EOL); return; @@ -57,12 +58,24 @@ function page_content(&$a) { dbesc($page_id), intval(ITEM_WEBPAGE) ); + logger('r: ' . print_r($r,true)); if(! $r) { notice( t('Item not found.') . EOL); return; } +// Use of widgets should be determined by Comanchie, but we don't have it yet, so... + + + if ($perms['write_pages']) { + $who = $channel_address; + $which = $r[0]['id']; + $o .= writepages_widget($who,$which); + } + + + xchan_query($r); $r = fetch_post_tags($r,true); $a->profile = array('profile_uid' => $u[0]['channel_id']); -- cgit v1.2.3 From 608e04c65eb2433a1cece9b5798f8577b611a288 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Wed, 14 Aug 2013 20:46:48 +0100 Subject: More progress on pages - extend writepages widget, add pagelist widget --- mod/editwebpage.php | 12 +++++------- mod/page.php | 6 +----- mod/webpages.php | 8 ++++++-- 3 files changed, 12 insertions(+), 14 deletions(-) (limited to 'mod') diff --git a/mod/editwebpage.php b/mod/editwebpage.php index 46c6b8817..f89be67c4 100644 --- a/mod/editwebpage.php +++ b/mod/editwebpage.php @@ -1,7 +1,8 @@ $jotplugins)); -//FIXME A return path with $_SESSION doesn't work for observer (at least, not here it doesn't). It'll WSoD instead of loading a sensible page. So, send folk -//back to the channel address until somebody figures out how to fix it - we can't send them back to webpages, because that could leak private pages they can't see -//when ACL is done. +//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 = 'channel' . '/' . $which; + $rp = '/webpages/' . $which; $o .= replace_macros($tpl,array( '$return_path' => $rp, diff --git a/mod/page.php b/mod/page.php index 1bdc3027a..4b2b95b6a 100644 --- a/mod/page.php +++ b/mod/page.php @@ -58,7 +58,6 @@ function page_content(&$a) { dbesc($page_id), intval(ITEM_WEBPAGE) ); - logger('r: ' . print_r($r,true)); if(! $r) { notice( t('Item not found.') . EOL); @@ -66,16 +65,13 @@ function page_content(&$a) { } // Use of widgets should be determined by Comanchie, but we don't have it yet, so... - - if ($perms['write_pages']) { + $chan = $a->channel['channel_id']; $who = $channel_address; $which = $r[0]['id']; $o .= writepages_widget($who,$which); } - - xchan_query($r); $r = fetch_post_tags($r,true); $a->profile = array('profile_uid' => $u[0]['channel_id']); diff --git a/mod/webpages.php b/mod/webpages.php index 8e3901d90..fb133eccf 100644 --- a/mod/webpages.php +++ b/mod/webpages.php @@ -21,13 +21,15 @@ function webpages_content(&$a) { profile_load($a,$which,$profile); +// Figure out who the page owner is. $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which) ); if($r) { $owner = intval($r[0]['channel_id']); } -// We can do better, but since editing only works for local users and all posts are webpages, return anyone else for now. + +// Get the observer, check their permissions $observer = $a->get_observer(); $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); @@ -40,6 +42,7 @@ function webpages_content(&$a) { } // Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages +// Nickname is set to the observers xchan, and profile_uid to the owners. This lets you post pages at other people's channels. require_once ('include/conversation.php'); $x = array( 'webpage' => 1, @@ -54,7 +57,7 @@ require_once ('include/conversation.php'); $o .= status_editor($a,$x); //Get a list of webpages. We can't display all them because endless scroll makes that unusable, so just list titles and an edit link. -// FIXME - we should sort these results, but it's not obvious what order yet. Alphabetical? Created order? +//TODO - this should be replaced with pagelist_widget $r = q("select * from item_id where uid = %d and service = 'WEBPAGE' order by sid asc", intval($owner) @@ -79,6 +82,7 @@ $r = q("select * from item_id where uid = %d and service = 'WEBPAGE' order by si '$pages' => $pages, '$channel' => $which, '$view' => t('View'), + '$preview' => '1', )); -- cgit v1.2.3