function folio_control_breadcrumb_recursive_find($page_ident, $url, $username) { // Find the root page information. $page = folio_page_select($page_ident); if (!$page) { // No results returned. Silent fail, as this could be a new record. return ''; } else { // Test for exit condition if ($page->parentpage_ident == -1 || $page->parentpage_ident == $page->page_ident) { // Exit, we've reach the homepage. return "<a href='{$url}{$username}/page/" . folio_page_encodetitle($page->title) . "'>" . stripslashes($page->title) . "</a> > "; } else { // Recurse. return folio_control_breadcrumb_recursive_find($page->parentpage_ident, $url, $username) . "<a href='{$url}{$username}/page/" . folio_page_encodetitle($page->title) . "'>" . stripslashes($page->title) . "</a> > "; } } }
/** * View a single wiki page. If the passed key is -1, then it will assume that we're pulling up a new page. * * @uses CFG * @param int $page_ident The page being viewed. -1 If we're trying to load a non-existing page. * @param string $page_title The title of the page. Important for when we're pulling up a page that hasn't been created yet. * @param int $created The created date for the page (optional, only used to pull up history pages, def = -1) * @param array $page The mysql page record. * @returns The html stuff to display a page. **/ function folio_page_view($page_ident, $page_title, $created = -1, $page, $username) { global $CFG; //global $profile_id; //global $page_owner; $url = $CFG->wwwroot; $userid = $_SESSION['userid']; // Declare variables. $body = ''; $title = 'Title'; $parentpage_ident = -1; if (!$page) { // No results returned. Offer to create a new page. if ($page_title == 'Home Page') { $page_body = "You can use this part of Elgg as a wiki, to collaboratively work on projects, " . "or to create an online portfolio.\n\nYou can create links to new pages by simply " . "enclosing the page title using double bracket characters. Here's an example " . "of a link to your <a href=\"{$url}{$username}/page/" . folio_page_encodetitle($page_title) . "/edit\">[[Home Page]]</a>."; } else { $page_body = "This page has not yet been created. <a href=\"{$url}{$username}/page/" . folio_page_encodetitle($page_title) . "/edit\">Click here to start editing it</a>."; } $page_title = ''; $creator = ''; $created = ''; $security_ident = $page_ident; } else { // Load values. $page_title = stripslashes($page->title); $page_body = folio_page_makelinks($username, stripslashes($page->body)); $created = gmdate("m/d/y h:i", intval($page->created)); $security_ident = intval($page->security_ident); $creator = intval($page->creator_ident); if ($creator < 1) { $creator = 'Anonymous'; } else { $creator = run("users:id_to_name", $creator); } } // Building the html control. $body .= <<<END <p>{$page_body}</p><br/><br/> \t\t<h1></h1> <p align=right><i>{$creator}, {$created} (GMT)</i></p> END; return $body; }
/** * Delete a single wiki page. Assumes that permission check has already been run. * Looks to see if there are any child pages, if so, doesn't allow deleting until those are * removed as well. * * @package folio * @param array $page The mysql page record. * @param string $page_title The passed in title used to access the page. Assumes that it has already * been decoded by the function in lib.php away from the URL form & into the normal presentation form. * @param string $username The username of the page owner. Used to create post link * to the finished page. * @returns HTML code to delete a folio page. **/ function folio_page_delete($page, $page_title, $username) { global $CFG; global $profile_id; global $language; global $page_owner; global $metatags; // Set url var $url = url; // Error, need a page record. if (!$page) { error('Sorry, but you can not delete a page that has not yet been created.'); } // Get children records. $pages = recordset_to_array(get_recordset_sql('SELECT * FROM ' . $CFG->prefix . 'folio_page p ' . "WHERE parentpage_ident = {$page->page_ident} AND newest = 1")); // Build results if ($pages) { // don't offer to delete pages with children. link to titles $run_result = 'Sorry, but you can not delete a page that has child pages under it. Delete each' . ' of the child pages, and then come back and delete this page.<br/>' . '<ul>'; foreach ($pages as $page) { $run_result .= "<li><a href=\"{$url}{$username}/page/" . folio_page_encodetitle($page->title) . "\">{$page->title}</a>"; } $run_result .= "</ul>"; } else { $run_result = <<<END <form method="post" name="elggform" action="{$url}_folio/action_redirection.php"> \t<h2>{$page_title}</h2> \t<p> Click the 'delete' button to completely remove this page. You will not be able to undo this process.<br/> \t\t<input type="hidden" name="action" value="folio:page:delete" /> \t\t<input type="hidden" name="page_ident" value="{$page->page_ident}" /> \t\t<input type="submit" value="Delete" /> \t</p> END; } return $run_result; }
function folio_control_childpagelist($username, $page, $profile_id) { global $CFG; $url = url; if (!$page) { // No pages passed. Can't show sub-pages of a page that doesnt' exist. return ''; } else { // Grab matching records. $pages = recordset_to_array(get_recordset_sql("SELECT DISTINCT w.* FROM " . $CFG->prefix . "folio_page w " . "INNER JOIN " . $CFG->prefix . "folio_page_security p ON w.security_ident = p.security_ident " . 'WHERE w.parentpage_ident = ' . $page->page_ident . ' AND w.page_ident <> ' . $page->page_ident . ' AND w.newest = 1 AND ' . folio_page_security_where('p', 'w', 'read', $profile_id) . ' ORDER BY title ')); $html = '<a href="' . $url . $username . '/page/' . folio_page_encodetitle($page->title) . '/addpage">Add a new page under this one</a><br/>'; if ($pages) { // Build html $html .= '<ul>'; foreach ($pages as $childpage) { // Load values. $html .= "<li><a href=\"{$url}" . $username . '/page/' . folio_page_encodetitle($childpage->title) . '">' . $childpage->title . "</a>\n"; } $html .= '</ul>'; } } return $html; }
/** * Translates [[Page Title]] to <a href=$url$username/page/$pagetitle/>>$pagetitle</a>. * Note that we don't have a decode, as this should only be called by the view procedure. * Encoded urls should not be stored in the database. * * @todo Implement some simple checks on the [[ ]] linking. Stuff like ]]] before [[..., title too long. * @param string $username The username of the owner of the page. * @param string $body The body that we're translating. * @return string The revised body. **/ function folio_page_makelinks($username, $body) { $i = true; $url = url; $body = run("weblogs:text:process", $body); while ($i) { $i = stripos($body, '[['); $end = stripos($body, ']]'); // Test find. if ($i === false | $end === false) { // Reached the end of the line - no more links. return $body; } else { // Translate title. $link = substr($body, $i + 2, $end - $i - 2); $body = substr($body, 0, $i) . "<a href=\"{$url}{$username}/page/" . folio_page_encodetitle($link) . "\">{$link}</a>" . substr($body, $end + 2); $i = true; } } }
// Potential Dup: w.* & children = 0, w.* & children = 1 // Filtering on children=1 is a problem, as moving a child of a page, leaves new=0 with the parentpage_ident still set, filtering out that // page. $pages = recordset_to_array(get_recordset_sql("SELECT DISTINCT w.*, children.newest children FROM {$prefix}folio_page w " . "INNER JOIN {$prefix}folio_page_security p ON w.security_ident = p.security_ident " . "LEFT OUTER JOIN {$prefix}folio_page children ON w.page_ident = children.parentpage_ident " . "WHERE w.parentpage_ident = {$page_ident} AND w.newest = 1 AND w.parentpage_ident <> w.page_ident AND " . folio_page_security_where('p', 'w', 'read', $profile_id) . 'ORDER BY title, children DESC')); $last_ident = -1; if ($pages) { foreach ($pages as $page) { $i = $page->page_ident; // Look to see if we're looking at a duplicate. if ($last_ident != $i) { // Update last_ident $last_ident = $i; // Load results $run_result .= intval($page->page_ident) . "\""; $run_result .= str_replace("\"", "'", $page->title) . "\""; $run_result .= str_replace("\"", "'", folio_page_encodetitle($page->title)) . "\""; if (is_null($page->children)) { // No kids. Value is interpreted as 'already loaded', so since no kids, set to already loaded. $run_result .= "true\""; } else { // Children, set loaded = false $run_result .= "false\""; } } // if ! dup } // foreach } // if $pages // Return wrapped up. echo $run_result;
// Also has the side effect of not loading other controls if the page hasnt' been // created yet. if ($ok) { // Build nice titles $html_title = "<a href='{$url}{$username}/subscribe/rss/page+page_comment/'><img border=0 src='{$url}_folio/images/xml.gif' /></a> {$name} : " . folio_control_breadcrumb($page, $username); $plain_title = $page->title; // See if we're trying to revert the page. Need to check security. if ($revert == 'T' && $ok_write) { // Revert $body = "<p align='center'><b>Restore this older version of the page.</b></p><br/>" . folio_page_edit($page, $permissions, $page_title, $username, $page->parentpage_ident); } else { // Just viewing. // Build warning if this is an older version of the page. if ($page->newest != 1) { // Create warning link $body = "<p align='center'><b>You are looking at an archived version of this page.</b><br/>" . "<a href='{$url}{$username}/page/" . folio_page_encodetitle($page_title) . "'>return to current version</a>"; if ($ok_write) { $body .= " :: " . "<a href='{$url}{$username}/page/{$page_ident}:{$created}/revert'>restore this version</a></p>\n"; } } else { $body = ''; } // Run the command to actually retrieve the content. $body .= folio_page_view($page_ident, $page_title, $created, $page, $username); } } else { // We don't have permissions, and so need some sort of title. $html_title = 'You do not have permission to view this page'; $plain_title = 'You do not have permission to view this page'; $body = 'You do not have permission to view this page. Please contact the page\'s' . ' owner and ask for the security to be set to <b>Public</b> or <b>Moderated</b>. ' . ' You will be able to view this page once that has been done. If this page belongs ' . ' to a community, you may also try to join the community. Once you are a member, ' . ' you will be able to see and edit the page.'; }
function folio_control_commentbox($item_ident, $item_type, $item_title, $item_url, $item_owner_ident, $item_owner_name, $item_owner_username) { $url = url . 'mod/folio/control/commentbox_postdata.php'; $ajaxprefix = 'folio_control_commentbox_'; $item_title = folio_page_encodetitle($item_title); $item_owner_username = folio_page_encodetitle($item_owner_username); /* This is now passed as $item_owner_ident if (logged_on) { $userid = $_SESSION['userid']; $comment_name = $_SESSION['name']; } else { $userid = -1; $comment_name = "Guest"; } */ $result = <<<END <div id="{$ajaxprefix}container"></div> <script type="text/javascript"> <!-- var {$ajaxprefix}div = document.getElementById('{$ajaxprefix}container'); var {$ajaxprefix}handleSuccess = function(o){ \tif(o.responseText !== undefined){ \t\t{$ajaxprefix}div.innerHTML = o.responseText; document.{$ajaxprefix}form.{$ajaxprefix}comment.value=''; \t} }; var {$ajaxprefix}handleFailure = function(o){ \tif(o.responseText !== undefined){ \t\t{$ajaxprefix}div.innerHTML = o.responseText; \t} }; var {$ajaxprefix}callback = { success:{$ajaxprefix}handleSuccess, failure:{$ajaxprefix}handleFailure, argument:['foo','bar'] }; function {$ajaxprefix}makeRequest(){ var postData = "item_ident={$item_ident}&item_type={$item_type}" + "&item_owner_name={$item_owner_name}&item_owner_username={$item_owner_username}&access=public&url={$item_url}&item_owner_ident={$item_owner_ident}&item_title={$item_title}&body=" + escape( document.{$ajaxprefix}form.{$ajaxprefix}comment.value ); \tvar request = YAHOO.util.Connect.asyncRequest('POST', "{$url}", {$ajaxprefix}callback, postData); } --> </script> <form name="{$ajaxprefix}form"> <p> <textarea name="{$ajaxprefix}comment" rows=2 style=" border: 1px solid #7F9DB9; color:#71717B; width: 95%; padding:3px;" id="{$ajaxprefix}comment" ></textarea> <input type="button" value="Send" onClick="{$ajaxprefix}makeRequest();" /> </p> </form> END; return $result; }
require_once '../includes.php'; // The security ident needs to be set by page_edit_security_post before this can run. if (!isset($security_ident)) { error('Page_Edit_post.php must be called after page_edit_security_post so that the former knows the security information'); } $page = new StdClass(); $page->title = folio_clean(required_param('page_title')); $page->body = required_param('page_body'); $page->page_ident = required_param('page_ident', PARAM_INT); $page->security_ident = $security_ident; $page->parentpage_ident = required_param('parentpage_ident', PARAM_INT); $page->newest = 1; $page->created = time(); $page->user_ident = required_param('user_ident'); $username = required_param('username'); // If the user isn't logged in, then set to -1 (anonymous) // Otherwise, set the last updater to their logged in information. if (isloggedin()) { $page->creator_ident = $_SESSION['userid']; } else { $page->creator_ident = -1; } // Modify old record by converting all records matching the conditions (folio, page, newest) to newest=false. set_field('folio_page', 'newest', 0, 'newest', 1, 'page_ident', $page->page_ident); //var_dump( $page ); // Insert new record into db. $insert_id = insert_record('folio_page', $page, true, 'page_ident'); // Set redirect $redirect_url = url . $username . '/page/' . folio_page_encodetitle(required_param('page_title')); // Create RSS record rss_additem($page->user_ident, $username, $page->creator_ident, $_SESSION['name'], $_SESSION['username'], 'page', $insert_id, '', $page->title, folio_page_makelinks($username, $page->body), $redirect_url, optional_param('folio_control_page_edit_security_custom', 'PUBLIC'));
/** * Builds the child nodes for the passed page_ident. * * @param int $page_ident The parent for whom we're retrieving children. * @param int $ignorepage_ident Optional. A page to leave out of the results (if found). Used by getNodeParents. **/ function folio_control_tree_getNodeChildren($ajaxprefix, $page_ident, $ignorepage_ident, $url, $previousresults, $profile_id) { global $CFG; $prefix = $CFG->prefix; // NOTE: The following query has the potential to return duplicates. However, the older mysq doesn't support subqueries, making it impossible // to do the query properly. Filter out dups in code. // Potential Dup: w.* & children = 0, w.* & children = 1 // Filtering on children=1 is a problem, as moving a child of a page, leaves new=0 with the parentpage_ident still set, filtering out that // page. $pages = recordset_to_array(get_recordset_sql("SELECT DISTINCT w.*, children.newest children FROM {$prefix}folio_page w " . "INNER JOIN {$prefix}folio_page_security p ON w.security_ident = p.security_ident " . "LEFT OUTER JOIN {$prefix}folio_page children ON w.page_ident = children.parentpage_ident " . "WHERE w.parentpage_ident = {$page_ident} AND w.newest = 1 AND w.parentpage_ident <> w.page_ident AND " . folio_page_security_where('p', 'w', 'read', $profile_id) . 'ORDER BY title DESC, children DESC')); // Set the parent node's name. $parentnode = $ajaxprefix . 'Node' . $page_ident; $last_ident = -1; $result = ''; if ($pages) { foreach ($pages as $page) { $i = $page->page_ident; // Look to see if we're looking at a duplicate. if ($last_ident != $i) { // Update last_ident $last_ident = $i; // Test to see if we're on the *ignore* page, in which case, insert the nodes that have been built thus far. if ($ignorepage_ident == $i) { $result = $previousresults . "\n" . $result; } else { if (is_null($page->children)) { // No kids $result = " var {$ajaxprefix}Node{$i} = {$ajaxprefix}buildNode( \"{$i}\", \"" . str_replace("\"", "'", $page->title) . "\", {$parentnode}, true, \"" . $url . folio_page_encodetitle($page->title) . "\");\n" . $result; } else { // Children, set loaded = false $result = " var {$ajaxprefix}Node{$i} = {$ajaxprefix}buildNode( \"{$i}\", \"" . str_replace("\"", "'", $page->title) . "\", {$parentnode}, false, \"" . $url . folio_page_encodetitle($page->title) . "\");\n" . $result; } } } else { // $last_ident == $i // Don't load, as it would be a duplicate record. } } // foreach } // if $pages return $result; }