Index: /elgg/tags/20090118/mod/generic_comments/comment
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/comment (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/comment (revision 33)
@@ -0,0 +1,8 @@
+
+ {{body}}
+
+
Index: /elgg/tags/20090118/mod/generic_comments/mysql.sql
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/mysql.sql (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/mysql.sql (revision 33)
@@ -0,0 +1,24 @@
+CREATE TABLE `prefix_comments` (
+ ident int(11) NOT NULL auto_increment COMMENT '-> comment number',
+ object_id int(11) NOT NULL COMMENT '-> ident of object being commented on',
+ object_type varchar(128) NOT NULL COMMENT '-> type of object being commented on',
+ owner int(11) NOT NULL COMMENT '-> ident of user posting comment, if any',
+ postedname varchar(128) NOT NULL COMMENT '-> name of user posting comment',
+ body text NOT NULL COMMENT '-> text of comment',
+ posted int(11) NOT NULL COMMENT '-> time comment was posted',
+ PRIMARY KEY (ident),
+ KEY object_id (object_id),
+ KEY object_type (object_type),
+ KEY owner (owner)
+) ENGINE=MyISAM ;
+
+CREATE TABLE `prefix_watchlist` (
+ ident int(11) NOT NULL auto_increment COMMENT '-> watchlist number',
+ owner int(11) NOT NULL COMMENT '-> watchlist owner',
+ object_id int(11) NOT NULL COMMENT '-> id of object being watched',
+ object_type varchar(128) NOT NULL COMMENT '-> type of object being watched',
+ PRIMARY KEY (ident),
+ KEY owner (owner),
+ KEY object_id (object_id),
+ KEY object_type (object_type)
+) ENGINE=MyISAM ;
Index: /elgg/tags/20090118/mod/generic_comments/comment_page.php
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/comment_page.php (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/comment_page.php (revision 33)
@@ -0,0 +1,33 @@
+".__gettext("Either this page does not exist or you do not have permission to view it.")."";
+if ($object_id && $object_type) {
+ $access = get_access($object_id,$object_type,"read");
+ // need to check access here - the user should have access to the comments
+ // if and only if they have access to the object
+ if ($access == 'PUBLIC' || run("users:access_level_check",$access)) {
+ $title = __gettext('Comments on').' "'.get_title($object_id,$object_type).'"';
+ $back = ''.__gettext("Go back").'
';
+ $body = $back;
+ $body .= implode('',action('annotate',$object_id,$object_type,NULL,
+ array('comment_form_type'=>'separate')));
+ $body .= $back;
+ }
+}
+
+templates_page_setup();
+templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/generic_comments/comments
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/comments (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/comments (revision 33)
@@ -0,0 +1,9 @@
+
+
Index: /elgg/tags/20090118/mod/generic_comments/css
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/css (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/css (revision 33)
@@ -0,0 +1,3 @@
+/*
+ * Generic comments CSS file
+ */
Index: /elgg/tags/20090118/mod/generic_comments/action_redirection.php
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/action_redirection.php (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/action_redirection.php (revision 33)
@@ -0,0 +1,22 @@
+ 0) {
+ $_SESSION['messages'] = $messages;
+}
+
+if (defined('redirect_url')) {
+ header("Location: " . redirect_url);
+} else {
+ header("Location: " . url);
+}
+
+?>
Index: /elgg/tags/20090118/mod/generic_comments/comments_actions.php
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/comments_actions.php (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/comments_actions.php (revision 33)
@@ -0,0 +1,130 @@
+object_id = optional_param('object_id',0,PARAM_INT);
+ $comment->object_type = optional_param('object_type','');
+ $comment->body = trim(optional_param('new_comment'));
+ $comment->postedname = trim(optional_param('postedname'));
+ $commentbackup = $comment;
+ if (!empty($comment->object_id) && !empty($comment->body) && !empty($comment->postedname)) {
+ $object_owner = get_owner($comment->object_id,$comment->object_type);
+ $where = run("users:access_level_sql_where",$USER->ident);
+ if ($comment_form_type == 'integrated') {
+ $redirect_url = get_url($comment->object_id,$comment->object_type);
+ } elseif ($comment_form_type == 'separate') {
+ $redirect_url = $CFG->wwwroot."mod/generic_comments/comment_page.php?object_id={$comment->object_id}&object_type={$comment->object_type}";
+ }
+ if (run("spam:check",$comment->body) != true) {
+ // If we're logged on or comments are public, add one
+ if (isloggedin() || (!$CFG->disable_publiccomments && user_flag_get("publiccomments",$object_owner)) ) {
+ $comment->owner = $USER->ident;
+ $comment->posted = time();
+ $comment = plugin_hook("comment","create",$comment);
+ if (!empty($comment)) {
+ $insert_id = insert_record('comments',$comment);
+ $comment->ident = $insert_id;
+ $comment = plugin_hook("comment","publish",$comment);
+ $messages[] = __gettext("Your comment has been added."); // gettext variable
+ $ok = true;
+
+ // If we're logged on and not the owner of this post, add post to our watchlist
+ if (isloggedin() && $comment->owner != $object_owner) {
+ delete_records('watchlist','object_id',$comment->object_id,'object_type',$comment->object_type,'owner',$comment->owner);
+ $wl = new StdClass;
+ $wl->owner = $comment->owner;
+ $wl->object_id = $comment->object_id;
+ $wl->object_type = $comment->object_type;
+ insert_record('watchlist',$wl);
+ }
+
+ // Message comment if applicable
+ if ($comment->owner != $object_owner) {
+ $object_title = get_title($comment->object_id,$comment->object_type);
+ $message = __gettext(sprintf("You have received a comment from %s on '%s'. It reads as follows:", $comment->postedname, stripslashes($object_title)));
+ $message .= "\n\n" . stripslashes($comment->body) . "\n\n";
+ $message .= __gettext(sprintf("To reply and see other comments, click here: %s", $redirect_url));
+ $message = wordwrap($message);
+ message_user($object_owner,$comment->owner,stripslashes($object_title),$message);
+ }
+ }
+ }
+ } else {
+ $messages[] = __gettext("Your comment could not be posted. The system thought it was spam.");
+ }
+
+ // If river plugin installed then note comment
+ if (function_exists('river_save_event'))
+ {
+ $commenturl = $CFG->wwwroot."mod/generic_comments/comment_page.php?object_id={$comment->object_id}&object_type={$comment->object_type}&comment_sort=ASC";
+ $username = "owner) . "\">" . user_info("username", $comment->owner) . " ";
+ if (!isset($comment->owner))
+ {
+ $comment->owner = -1;
+ $username = __gettext("Anonymous user");
+ }
+
+ river_save_event($comment->owner, $comment->object_id, $comment->owner, $comment->object_type, $username . " " . __gettext("commented on") . " " . river_get_friendly_id($comment->object_type, $comment->object_id));
+
+ }
+
+ $xml = optional_param('returnformat','');
+ if (!empty($xml))
+ {
+ // If we are returning xml for the ajax response then output message and die.
+
+ if ($ok!=true) {
+ $ok = "1 \n";
+ } else {
+ $messages[] = __gettext(" Click here to refresh");
+ $ok = "0 \n";
+ }
+
+ $msg = implode("\n", $messages);
+ header("Content-type: text/xml");
+
+ echo "\n$msg \n$ok \n";
+ exit;
+ }
+ else {
+ define('redirect_url',$redirect_url);
+ }
+ }
+ break;
+
+
+ // Delete a comment
+ case "comment:delete":
+ $comment_id = optional_param('comment_delete',0,PARAM_INT);
+ require_confirm(__gettext('Are you sure you want to permanently delete this comment?'));
+
+ if (logged_on && !empty($comment_id)) {
+ $comment = get_record('comments','ident',$comment_id);
+ $comment = plugin_hook("comment","delete",$comment);
+ if (!empty($comment)) {
+ if ($comment->owner == $USER->ident || run("permissions:check",array("comment:delete",$_SESSION['userid'],$comment->object_id,$comment->object_type))) {
+ delete_records('comments','ident',$comment_id);
+ $messages[] = __gettext("Your comment was deleted.");
+ }
+ }
+ if (($comment_form_type == 'integrated') || ($comment_form_type == 'inline')) {
+ $redirect_url = get_url($comment->object_id,$comment->object_type);
+ } elseif ($comment_form_type == 'separate') {
+ $redirect_url = $CFG->wwwroot."mod/generic_comments/comment_page.php?object_id={$comment->object_id}&object_type={$comment->object_type}";
+ }
+ define('redirect_url',$redirect_url);
+ }
+ break;
+
+ // Edit a comment
+ case "comment:edit":
+ // need to add code for this case
+ }
+}
Index: /elgg/tags/20090118/mod/generic_comments/postgres7.sql
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/postgres7.sql (revision 36)
+++ /elgg/tags/20090118/mod/generic_comments/postgres7.sql (revision 36)
@@ -0,0 +1,25 @@
+CREATE TABLE prefix_comments (
+ ident SERIAL PRIMARY KEY,
+ object_id integer NOT NULL default '0',
+ object_type varchar(128) NOT NULL default '',
+ owner integer NOT NULL default '0',
+ postedname varchar(128) NOT NULL default '',
+ body text NOT NULL default '',
+ posted integer NOT NULL default '0'
+);
+
+CREATE INDEX prefix_comments_object_id_idx ON prefix_comments (object_id);
+CREATE INDEX prefix_comments_object_type_idx ON prefix_comments (object_type);
+CREATE INDEX prefix_comments_owner_idx ON prefix_comments (owner);
+
+CREATE TABLE prefix_watchlist (
+ ident SERIAL PRIMARY KEY,
+ owner integer NOT NULL default '0',
+ object_id integer NOT NULL default '0',
+ object_type varchar(128) NOT NULL default '',
+ UNIQUE (owner, object_id, object_type)
+);
+
+CREATE INDEX prefix_watchlist_object_id_idx ON prefix_watchlist (object_id);
+CREATE INDEX prefix_watchlist_object_type_idx ON prefix_watchlist (object_type);
+CREATE INDEX prefix_watchlist_owner_idx ON prefix_watchlist (owner);
Index: /elgg/tags/20090118/mod/generic_comments/generic_comments.js
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/generic_comments.js (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/generic_comments.js (revision 33)
@@ -0,0 +1,115 @@
+var http_Request = false;
+var success = false;
+var objectid = "";
+
+function showhide(oid)
+{
+ var e = document.getElementById(oid);
+ if(e.style.display == 'none') {
+ e.style.display = 'block';
+ } else {
+ e.style.display = 'none';
+ }
+}
+
+function getAjaxObj()
+{
+ var xmlHttp;
+
+ try
+ {
+ // Firefox, Opera 8.0+, Safari
+ xmlHttp=new XMLHttpRequest();
+ }
+ catch (e)
+ {
+ // Internet Explorer
+ try
+ {
+ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
+ }
+ catch (e)
+ {
+ try
+ {
+ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ catch (e)
+ {
+ return false;
+ }
+ }
+ }
+
+ return xmlHttp;
+}
+
+function alertContents()
+{
+ if (http_Request.readyState == 4) {
+ if (http_Request.status == 200) {
+
+ result = http_Request.responseXML;
+ message = result.getElementsByTagName('message')[0];
+
+ error = result.getElementsByTagName('error')[0];
+ if (error.textContent == '0') {
+ success = true;
+ }
+
+ if (success == true)
+ {
+ document.getElementById('ajaxmessages_' + objectid).innerHTML = '' + message.textContent + ' ';
+ document.getElementById('ajaxmessages_post_' + objectid).innerHTML = ' ';
+ }
+ else
+ {
+ document.getElementById('ajaxmessages_' + objectid).innerHTML = message.textContent;
+ }
+ } else {
+ alert('There was a problem with the request.');
+ }
+ }
+}
+
+function sendcomment(url, formid, oid)
+{
+ var parameters;
+ objectid = oid;
+
+ http_Request = getAjaxObj();
+
+ if (http_Request==false)
+ {
+ return false;
+ }
+
+ // Construct parameters
+ frm = document.getElementById(formid);
+
+ parameters = "";
+ for(var i = 0;i < frm.elements.length;i++)
+ {
+ element = frm.elements[i];
+
+ parameters = parameters + element.name +"=" + encodeURI( element.value ) + "&";
+ }
+ parameters = parameters + "returnformat=xml";
+
+ frm.new_comment.disabled=true;
+
+ // Post result
+ //http_Request.overrideMimeType('text/html');
+ http_Request.onreadystatechange = alertContents;
+ http_Request.open('POST', url, true);
+ http_Request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http_Request.setRequestHeader("Content-length", parameters.length);
+ http_Request.setRequestHeader("Connection", "close");
+ http_Request.send(parameters);
+
+ frm.new_comment.disabled=false;
+
+ if (success==true) {
+ frm.new_comment.value="";
+ }
+}
Index: /elgg/tags/20090118/mod/generic_comments/lib.php
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/lib.php (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/lib.php (revision 33)
@@ -0,0 +1,648 @@
+wwwroot}mod/generic_comments/generic_comments.js\">";
+
+ // create the generic_comments and generic watchlist table
+ $tables = $db->Metatables();
+ if (!in_array($CFG->prefix . "comments",$tables) || !in_array($CFG->prefix . "watchlist",$tables)) {
+ if (file_exists($CFG->dirroot . "mod/generic_comments/$CFG->dbtype.sql")) {
+ modify_database($CFG->dirroot . "mod/generic_comments/$CFG->dbtype.sql");
+ //reload system
+ header_redirect($CFG->wwwroot);
+ } else {
+ error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg generic comments. See the mod/generic_comments directory.");
+ }
+ print_continue("index.php");
+ exit;
+ }
+
+ $function['comments:init'][] = $CFG->dirroot . "mod/generic_comments/comments_actions.php";
+ $function['permissions:check'][] = $CFG->dirroot . "mod/generic_comments/permissions_check.php";
+
+ // Add annotation support
+ display_set_display_annotation_function("file::file", "generic_comments_displayobjectannotations");
+ display_set_display_annotation_function("mediastream::media", "generic_comments_displayobjectannotations");
+
+ // Register file river hook (if there)
+ if (function_exists('river_save_event'))
+ {
+ river_register_friendlyname_hook('file::file', 'generic_comments_get_friendly_name');
+ }
+ templates_add_context('embeddedcomments', 'mod/generic_comments/comments');
+ templates_add_context('embeddedcomment', 'mod/generic_comments/comment');
+ templates_add_context('css', 'mod/generic_comments/css', true, false);
+
+}
+
+function generic_comments_pagesetup() {
+// need to set up an admin option to allow comments to be editable
+
+}
+
+function generic_comments_get_friendly_name($object_type, $object_id)
+{
+ global $CFG;
+
+ if ($object_type == 'file::file')
+ return file_get_friendly_name($object_type, $object_id);
+
+ if ($object_type == 'mediastream::media')
+ return mediastream_get_friendly_name($object_type, $object_id);
+
+ return "";
+}
+
+function generic_comments_displayobjectannotations($object, $object_type, $view)
+{
+ $return = "";
+
+ if (($object_type == "file::file") || ($object_type == "mediastream::media"))
+ {
+ $txt = __gettext('Click to add or view comments.');
+ $int = implode('',action('annotate',$object->ident,$object_type,NULL,
+ array('comment_form_type'=>'inline', 'comment_sort'=>'ASC', 'comment_form_text'=>$txt)));
+
+ $return .= <<< END
+
+
+END;
+ $return .= implode('',action('annotate',$object->ident,$object_type,NULL,
+ array('comment_form_type'=>'summary', 'comment_sort'=>'ASC', 'comment_form_text'=>$txt)));
+
+ $return .= <<< END
+
+END;
+ }
+
+ return $return;
+}
+
+
+function generic_comments_annotate($object_id,$object_type,$parameters=NULL) {
+ global $CFG;
+ global $page_owner;
+ // prevent some notices
+ $comment_sort = null;
+ $commentsbody = null;
+ $sort_sequence = null;
+
+ $owner_username = user_info('username', $page_owner);
+// create a form to display comments for this object, and then display the comments for one page
+
+ $default_comment_form_text = __gettext("Add a comment"); // gettext variable
+ if (!$parameters) {
+ $comment_form_type = 'integrated';
+ $comment_form_text = $default_comment_form_text;
+ } else {
+ if (isset($parameters['comment_form_type'])) {
+ $comment_form_type = $parameters['comment_form_type'];
+ } else {
+ $comment_form_type = 'integrated';
+ }
+ if (isset($parameters['comment_form_text'])) {
+ $comment_form_text = $parameters['comment_form_text'];
+ } else {
+ $comment_form_text = $default_comment_form_text;
+ }
+ }
+
+ if (in_array($comment_form_type,array('integrated','separate'))) {
+
+ $item_details = "";
+ if (($object_type=="file::file") || (($object_type=="file::folder")))
+ $item_details = display_run_displayobject('file', $object_id, $object_type);
+ if ($object_type=="mediastream::media")
+ $item_details = display_run_displayobject('mediastream', $object_id, $object_type);
+
+ $run_result = <<< END
+
+
+
+END;
+
+ // get the comments
+
+ $commentsbody = "";
+
+ //which page of comments to display (page numbers are 0-based)
+ $page = optional_param('commentpage', 0, PARAM_INT);
+ $sort_sequence = optional_param('comment_sort','');
+ //$perpage = 20; // set to 0/false to disable paging
+ $perpage = 5; // set to 0/false to disable paging - set to 5 for testing - KJ
+ $offset = $page * $perpage;
+ if ($sort_sequence != 'DESC') {
+ $sort_sequence = 'ASC';
+ }
+ if ($comment_form_type == 'integrated') {
+ $thispageurl = generic_comments_add_parameter_to_url(get_url($object_id, $object_type),'comment_sort',$sort_sequence);
+ } elseif ($comment_form_type == 'separate') {
+ $thispageurl = $CFG->wwwroot."mod/generic_comments/comment_page.php?object_id=$object_id&object_type=$object_type&comment_sort=$sort_sequence";
+ }
+
+ if ($comments = get_records_sql("SELECT * FROM {$CFG->prefix}comments WHERE object_id = $object_id AND object_type = '$object_type' ORDER BY posted $sort_sequence")) {
+ $numcomments = count($comments);
+ $pagelinks = '';
+ if (!empty($perpage) && $numcomments > $perpage) {
+ $comments = array_slice($comments, $offset, $perpage);
+ $numpages = ceil($numcomments / $perpage);
+ $pagelinks = __gettext("Page: ");
+ for ($i = 1; $i <= $numpages; $i++) {
+ $pagenum = $i - 1;
+ if ($pagenum != $page) {
+ if ($pagenum) {
+ $pageurl = generic_comments_add_parameter_to_url($thispageurl,'commentpage',$pagenum);
+ }
+ //$pageurl = $thispageurl . (($pagenum) ? '.' . $pagenum : '');
+ $pagelinks .= ' ' . $i . ' ' ;
+ } else {
+ $pagelinks .= ' ' . $i . ' ';
+ }
+
+ }
+ //$thispageurl .= '.' . $page;
+ $thispageurl = generic_comments_add_parameter_to_url($thispageurl,'commentpage',$page);
+
+ }
+
+ foreach($comments as $comment) {
+ $commentmenu = "";
+ if (isloggedin() && ($comment->owner == $_SESSION['userid'] || run("permissions:check",array("comment:delete",$_SESSION['userid'],$comment->object_id,$comment->object_type)))) {
+ $Delete = __gettext("Delete");
+ $commentmenu = <<< END
+ $Delete
+END;
+ }
+ $comment->postedname = htmlspecialchars($comment->postedname, ENT_COMPAT, 'utf-8');
+
+ // turn commentor name into a link if they're a registered user
+ // add rel="nofollow" to comment links if they're not
+ if ($comment->owner > 0) {
+ $commentownerusername = user_info('username', $comment->owner);
+ $comment->postedname = '' . $comment->postedname . ' ';
+ $comment->icon = '' . user_icon_html($comment->owner,50) . " ";
+ $comment->body = run("weblogs:text:process", array($comment->body, false));
+ } else {
+ $comment->icon = " wwwroot . "_icons/data/default.png\" width=\"50\" height=\"50\" align=\"left\" alt=\"\" />";
+ $comment->body = run("weblogs:text:process", array($comment->body, true));
+ }
+
+ $commentsbody .= templates_draw(array(
+ 'context' => 'embeddedcomment',
+ 'postedname' => $comment->postedname,
+ 'body' => '' . $comment->body,
+ 'posted' => strftime("%A, %d %B %Y, %H:%M %Z",$comment->posted),
+ 'usericon' => $comment->icon,
+ 'permalink' => $thispageurl . "#cmt" . $comment->ident,
+ 'links' => $commentmenu
+ )
+ );
+
+ }
+ $commentsbody = templates_draw(array(
+ 'context' => 'embeddedcomments',
+ 'paging' => $pagelinks,
+ 'comments' => $commentsbody
+ )
+ );
+
+ }
+
+ $body = $item_details . $commentsbody . $run_result;
+ } elseif ($comment_form_type == 'summary') {
+ $count = count_records('comments','object_id',$object_id,'object_type',$object_type);
+ if (!isset($count) || $count == 0) {
+ $comment_count = "0 ".__gettext("comments").".";
+ } elseif ($count == 1) {
+ $comment_count = "1 ".__gettext("comment").".";
+ } else {
+ $comment_count = $count." ".__gettext("comments").".";
+ }
+
+ if ($parameters && strtoupper($parameters['comment_sort']) == 'DESC') {
+ $comment_sort = '&comment_sort=DESC';
+ }
+
+ $body = "$comment_count wwwroot}mod/generic_comments/comment_page.php?object_id=$object_id&object_type=$object_type$comment_sort\">$comment_form_text ";
+
+
+
+ } elseif ($comment_form_type == 'inline') {
+ // Funky javascript inline editing
+
+ $count = count_records('comments','object_id',$object_id,'object_type',$object_type);
+ if (!isset($count) || $count == 0) {
+ $comment_count = "0 ".__gettext("comments").".";
+ } elseif ($count == 1) {
+ $comment_count = "1 ".__gettext("comment").".";
+ } else {
+ $comment_count = $count." ".__gettext("comments").".";
+ }
+
+ if ($parameters && strtoupper($parameters['comment_sort']) == 'DESC') {
+ $comment_sort = '&comment_sort=DESC';
+ }
+
+ // $field = display_input_field(array("new_comment","","longtext"));
+ $field = <<< END
+
+END;
+ if (logged_on) {
+ $userid = $_SESSION['userid'];
+ } else {
+ $userid = -1;
+ }
+
+ /* There now follows a selection of nasty hacks. Yes yes, I know this is ugly, but it means that it falls back cleanly if no javascript is supported. TODO: There must be a better way, but i'm too tired just now to think of one.*/
+ if (logged_on) {
+ $comment_name = $_SESSION['name'];
+ } else {
+ $comment_name = __gettext("Guest");
+ }
+
+
+
+ $thispageurl = generic_comments_add_parameter_to_url(get_url($object_id, $object_type),'comment_sort',$sort_sequence);
+ $comment_name_enc = templates_draw(array(
+
+ 'context' => 'databox1',
+ 'name' => __gettext("Your name"),
+ 'column1' => " "
+
+ )
+ );
+ $postcomment = __gettext("Post comment...");
+
+ if ($comments = get_records_sql("SELECT * FROM {$CFG->prefix}comments WHERE object_id = $object_id AND object_type = '$object_type' ORDER BY posted $sort_sequence")) {
+ $numcomments = count($comments);
+ $pagelinks = '';
+ if (!empty($perpage) && $numcomments > $perpage) {
+ $comments = array_slice($comments, $offset, $perpage);
+ $numpages = ceil($numcomments / $perpage);
+ $pagelinks = __gettext("Page: ");
+ for ($i = 1; $i <= $numpages; $i++) {
+ $pagenum = $i - 1;
+ if ($pagenum != $page) {
+ if ($pagenum) {
+ $pageurl = generic_comments_add_parameter_to_url($thispageurl,'commentpage',$pagenum);
+ }
+ //$pageurl = $thispageurl . (($pagenum) ? '.' . $pagenum : '');
+ $pagelinks .= ' ' . $i . ' ' ;
+ } else {
+ $pagelinks .= ' ' . $i . ' ';
+ }
+
+ }
+ //$thispageurl .= '.' . $page;
+ $thispageurl = generic_comments_add_parameter_to_url($thispageurl,'commentpage',$page);
+
+ }
+
+ foreach($comments as $comment) {
+ $commentmenu = "";
+ if (isloggedin() && ($comment->owner == $_SESSION['userid'] || run("permissions:check",array("comment:delete",$_SESSION['userid'],$comment->object_id,$comment->object_type)))) {
+ $returnConfirm = __gettext("Are you sure you want to permanently delete this comment?");
+ $Delete = __gettext("Delete");
+ $commentmenu = <<< END
+ $Delete
+END;
+ }
+ $comment->postedname = htmlspecialchars($comment->postedname, ENT_COMPAT, 'utf-8');
+
+ // turn commentor name into a link if they're a registered user
+ // add rel="nofollow" to comment links if they're not
+ if ($comment->owner > 0) {
+ $commentownerusername = user_info('username', $comment->owner);
+ $comment->postedname = '' . $comment->postedname . ' ';
+ $comment->icon = '' . user_icon_html($comment->owner,50) . " ";
+ $comment->body = run("weblogs:text:process", array($comment->body, false));
+ } else {
+ $comment->icon = " wwwroot . "_icons/data/default.png\" width=\"50\" height=\"50\" align=\"left\" alt=\"\" />";
+ $comment->body = run("weblogs:text:process", array($comment->body, true));
+ }
+
+ $commentsbody .= templates_draw(array(
+ 'context' => 'embeddedcomment',
+ 'postedname' => $comment->postedname,
+ 'body' => '' . $comment->body,
+ 'posted' => strftime("%A, %d %B %Y, %H:%M %Z",$comment->posted),
+ 'usericon' => $comment->icon,
+ 'permalink' => $thispageurl . "#cmt" . $comment->ident,
+ 'links' => $commentmenu
+ )
+ );
+
+ }
+ $commentsbody = templates_draw(array(
+ 'context' => 'embeddedcomments',
+ 'paging' => $pagelinks,
+ 'comments' => $commentsbody
+ )
+ );
+ }
+
+ $bodyfrm = <<< END
+ $comment_count $comment_form_text
+
+END;
+ $body = "";
+ foreach (explode("\n",addslashes($bodyfrm)) as $line)
+ $body .= "document.write(\"" . trim($line) . "\");";
+
+ }
+ return $body;
+}
+
+function generic_comments_add_parameter_to_url($url,$name,$value) {
+ // Pick the correct separator to use
+ $separator = "?";
+ if (strpos($url,"?")!==false) {
+ $separator = "&";
+ }
+
+ // Find the location for the new parameter
+ $insertPosition = strlen($url);
+ if (strpos($url,"#")!==false) {
+ $insertPosition = strpos($url,"#");
+ }
+
+ // Build the new url
+ return substr_replace($url,"$separator$name=$value",$insertPosition,0);
+}
+
+
+function get_owner ($object_id, $object_type) {
+ // this is a temporary location - the code should be moved into elgglib
+ switch ($object_type) {
+ case 'file::file':
+ $table = 'files';
+ break;
+ case 'file::folder':
+ $table = 'file_folders';
+ break;
+ case 'blog::weblog':
+ $table = 'weblog_posts';
+ break;
+ case 'mediastream::media':
+ $table = 'mediastream_objects';
+ break;
+ default:
+ // this table does not exist (yet)
+ $table = 'metadata';
+ }
+
+ if ($object_type == 'profile::profile') {
+ $owner = $object_id;
+ } elseif ($object_type == 'file::folder' && $object_id < 0) {
+ // kludge for root folders
+ $owner = -$object_id;
+ } else {
+ $result = get_record($table,'ident',$object_id);
+ $owner = $result->owner;
+ }
+ return $owner;
+}
+
+function get_access ($object_id, $object_type,$access_category='read') {
+ // this is a temporary location - the code should be moved into elgglib
+
+ // the only valid access category is read right now, but this should change
+
+ switch ($object_type) {
+ case 'file::file':
+ $table = 'files';
+ break;
+ case 'file::folder':
+ $table = 'file_folders';
+ break;
+ case 'blog::weblog':
+ $table = 'weblog_posts';
+ break;
+ case 'mediastream::media':
+ $table = 'mediastream_objects';
+ break;
+ default:
+ // this table does not exist (yet)
+ $table = 'metadata';
+ }
+
+ if ($object_type == 'profile::profile') {
+ // no way to block access to profile comments right now
+ $access = 'PUBLIC';
+ } else {
+ $access = get_field($table,'access','ident',$object_id);
+ }
+
+ return $access;
+}
+
+function get_title ($object_id, $object_type) {
+ // this is a temporary location - the code should be moved into elgglib
+ switch ($object_type) {
+ case 'file::file':
+ $title = get_field('files','title','ident',$object_id);
+ break;
+ case 'file::folder':
+ if ($object_id < 0) {
+ $title = __gettext("Root folder");
+ } else {
+ $title = get_field('file_folders','name','ident',$object_id);
+ }
+ break;
+ case 'blog::weblog':
+ $title = get_field('weblog_posts','title','ident',$object_id);
+ break;
+ case 'mediastream::media':
+ $title = get_field('mediastream_objects','name','ident',$object_id);
+ break;
+ case 'profile::profile':
+ $title = __gettext("Profile for")." ".user_info('name',$object_id);
+ break;
+ default:
+ // this table does not exist (yet)
+ $title = get_field('metadata','title','ident',$object_id);
+ }
+
+ return $title;
+}
+
+
+function get_url($object_id, $object_type) {
+ global $CFG, $messages;
+ // this is a temporary location - the code should be moved into elgglib
+
+ switch ($object_type) {
+ case 'file::file':
+ $object_record = get_record('files','ident',$object_id);
+ $username = user_info('username',$object_record->files_owner);
+ if ($object_record->folder == -1) {
+ $url = $CFG->wwwroot.$username.'/files';
+ } else {
+ $url = $CFG->wwwroot.$username.'/files/'.$object_record->folder;
+ }
+ break;
+ case 'file::folder':
+ if ($object_id < 0) {
+ $username = user_info('username',-$object_id);
+ $url = $CFG->wwwroot.$username.'/files';
+ } else {
+ $object_record = get_record('file_folders','ident',$object_id);
+ if ($object_record) {
+ $username = user_info('username',$object_record->files_owner);
+ $url = $CFG->wwwroot.$username.'/files/'.$object_id;
+ } else {
+ $url = '';
+ }
+ }
+ break;
+ case 'blog::weblog':
+ $object_record = get_record('weblog_posts','ident',$object_id);
+ $username = user_info('username',$object_record->weblog);
+ $url = $CFG->wwwroot.$username.'/weblog/'.$object_record->ident.'.html';
+ break;
+ case 'mediastream::media':
+ $object_record = get_record('mediastream_objects','ident',$object_id);
+ $username = user_info('username',$object_record->owner);
+ $url = $CFG->wwwroot."/mod/mediastream/display.php?ident={$object_record->ident}&owner={$object_record->owner}&media={$object_record->mediatype}";
+ break;
+ case 'profile::profile':
+ $username = user_info('username',$object_id);
+ $url = $CFG->wwwroot.$username.'/profile';
+ break;
+ default:
+ $url = '';
+ // call the module_url function if it exists
+ $mod_pos = strpos($object_type,"::");
+ if ($mod_pos) {
+ $module = substr($object_type,0,$mod_pos);
+ $module_display_url = $module . '_url';
+ if ($module && function_exists($module_display_url)) {
+ $url = $module_display_url($object_id,$object_type);
+ }
+ }
+ }
+ return $url;
+}
+
+
+/**
+ * Returns the HTML to display a user's icon, with event hooks allowing for interception.
+ * Internally passes around a "user_icon" "display" event, with an object
+ * containing the elements 'html', 'icon' (being the icon ID), 'size', 'owner' and 'url'.
+ *
+ * @uses $CFG
+ * @param integer $user_id The unique ID of the user we want to display the icon for.
+ * @param integer $size The size of the icon we want to display (max: 100).
+ * @param boolean $urlonly If true, returns the URL of the icon rather than the full HTML.
+ * @return string Returns the icon HTML, or the default icon if something went wrong (eg the user didn't exist).
+ */
+/* function user_icon_html($user_id, $size = 100, $urlonly = false) {
+ global $CFG;
+ $extra = "";
+ $user_icon = new stdClass;
+ $user_icon->owner = $user_id;
+ $user_icon->size = $size;
+ if ($size < 100) {
+ $extra = "/h/$size/w/$size";
+ }
+ if ($user_icon->icon = user_info("icon",$user_id)) {
+ $user_icon->url = "{$CFG->wwwroot}_icon/user/{$user_icon->icon}{$extra}";
+ $user_icon->html = " url}\" border=\"0\" alt=\"user icon\" />";
+ if ($user_icon = plugin_hook("user_icon","display",$user_icon)) {
+ if ($urlonly) {
+ return $user_icon->url;
+ } else {
+ return $user_icon->html;
+ }
+ }
+ }
+ if ($urlonly) {
+ return -1;
+ } else {
+ return " wwwroot}_icon/user/-1{$extra}\" border=\"0\" alt=\"default user icon\" />";
+ }
+ }
+*/
+?>
Index: /elgg/tags/20090118/mod/generic_comments/permissions_check.php
===================================================================
--- /elgg/tags/20090118/mod/generic_comments/permissions_check.php (revision 33)
+++ /elgg/tags/20090118/mod/generic_comments/permissions_check.php (revision 33)
@@ -0,0 +1,18 @@
+
Index: /elgg/tags/20090118/mod/export/blogashtml.php
===================================================================
--- /elgg/tags/20090118/mod/export/blogashtml.php (revision 33)
+++ /elgg/tags/20090118/mod/export/blogashtml.php (revision 33)
@@ -0,0 +1,18 @@
+
+ */
+
+ require_once("../../includes.php");
+
+ if (isloggedin()) {
+
+ header('Content-Disposition: attachment');
+ header("Content-type: text/html");
+ echo export_blog_as_html($_SESSION['userid']);
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/export/blog.php
===================================================================
--- /elgg/tags/20090118/mod/export/blog.php (revision 33)
+++ /elgg/tags/20090118/mod/export/blog.php (revision 33)
@@ -0,0 +1,18 @@
+
+ */
+
+ require_once("../../includes.php");
+
+ if (isloggedin()) {
+
+ header('Content-Disposition: attachment');
+ header("Content-type: text/xml");
+ echo export_blog_as_rss($_SESSION['userid']);
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/export/lib.php
===================================================================
--- /elgg/tags/20090118/mod/export/lib.php (revision 33)
+++ /elgg/tags/20090118/mod/export/lib.php (revision 33)
@@ -0,0 +1,169 @@
+
+ */
+
+ function export_pagesetup() {
+ global $page_owner, $PAGE, $CFG;
+ if (defined('context') && context == 'weblog') {
+ if ($page_owner == $_SESSION['userid']) {
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:export:html',
+ 'html' => "wwwroot}mod/export/blogashtml.php/export.html\">". __gettext("Download blog as HTML") ." "
+ );
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:export:rss',
+ 'html' => "wwwroot}mod/export/blog.php/export.rss\">". __gettext("Download blog as RSS") ." "
+ );
+ }
+ }
+ }
+
+ function export_init() {
+ }
+
+ /**
+ * Exports a weblog as RSS
+ *
+ * @param int $blog_id The ID of the blog to export
+ * @return string The RSS feed
+ */
+ function export_blog_as_rss($blog_id = -1) {
+
+ global $CFG;
+
+ if ($blog_id < 0) {
+ $blog_id = $_SESSION['id'];
+ }
+ $blog_id = (int) $blog_id;
+
+ $name = user_info("name", $blog_id);
+ $username = user_info("username", $blog_id);
+
+ $rssweblog = __gettext("Weblog items");
+ $rssdescription = sprintf(__gettext("The weblog for %s, hosted on %s."),$name,$CFG->sitename);
+
+ $output .= <<< END
+
+
+
+
+ {$CFG->wwwroot}{$username}/weblog/
+END;
+
+ $where = run("users:access_level_sql_where",$_SESSION['userid']);
+ if ($posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$blog_id,null,'posted DESC','*')) {
+ foreach($posts as $entry) {
+ $title = (stripslashes($entry->title));
+ $link = url . $username . "/weblog/" . $entry->ident . ".html";
+ $body = (run("weblogs:text:process",stripslashes($entry->body)));
+ $pubdate = gmdate("D, d M Y H:i:s T", $entry->posted);
+ $keywordtags = "";
+ if ($keywords = get_records_select('tags','tagtype = ? AND ref = ?',array('weblog',$entry->ident))) {
+ foreach($keywords as $keyword) {
+ $keywordtags .= "\n\t\ttag)) . "]]> ";
+ }
+ }
+ $output .= <<< END
+
+ -
+
+ $link
+ $link
+ $pubdate $keywordtags
+
+
+
+END;
+ }
+ }
+
+ //$output .= run("weblogs:rss:getitems", array($blog_id, 10000,null,"complete"));
+
+ $output .= <<< END
+
+
+
+END;
+ return $output;
+ }
+
+ /**
+ * Exports a blog as HTML
+ *
+ * @param int $blog_id The blog to export
+ * @return string The HTML file
+ */
+ function export_blog_as_html($blog_id = -1) {
+
+ global $CFG;
+
+ if ($blog_id < 0) {
+ $blog_id = $_SESSION['id'];
+ }
+ $blog_id = (int) $blog_id;
+
+ $name = user_info("name", $blog_id);
+ $username = user_info("username", $blog_id);
+
+ $rssweblog = __gettext("Weblog items");
+ $rssdescription = sprintf(__gettext("The weblog for %s, hosted on %s."),$name,$CFG->sitename);
+
+ $output .= <<< END
+
+
+ {$name}: {$rssweblog}
+
+
+ {$name}: {$rssweblog}
+ {$rssdescription}
+
+ {$CFG->wwwroot}{$username}/weblog/
+
+END;
+
+ $where = run("users:access_level_sql_where",$_SESSION['userid']);
+ if ($posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$blog_id,null,'posted DESC','*')) {
+ foreach($posts as $entry) {
+ $title = (stripslashes($entry->title));
+ $link = url . $username . "/weblog/" . $entry->ident . ".html";
+ $body = (run("weblogs:text:process",stripslashes($entry->body)));
+ $pubdate = gmdate("D, d M Y H:i:s T", $entry->posted);
+ $keywordtags = "";
+ if ($keywords = get_records_select('tags','tagtype = ? AND ref = ?',array('weblog',$entry->ident))) {
+ foreach($keywords as $keyword) {
+ if (!empty($keywordtags))
+ $keywordtags .= ", ";
+ $keywordtags .= stripslashes($keyword->tag);
+ }
+ }
+ if (!empty($keywordtags)) {
+ $keywordtags = "Keywords: {$keywordtags}
";
+ }
+ $output .= <<< END
+
+
{$title}
+
{$pubdate}
+
{$link}
+ {$body}
+ {$keywordtags}
+
+
+END;
+ }
+ }
+
+ //$output .= run("weblogs:rss:getitems", array($blog_id, 10000,null,"complete"));
+
+ $output .= <<< END
+
+
+
+
+END;
+ return $output;
+ }
+
+?>
Index: /elgg/tags/20090118/mod/commentwall/mysql.sql
===================================================================
--- /elgg/tags/20090118/mod/commentwall/mysql.sql (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/mysql.sql (revision 33)
@@ -0,0 +1,12 @@
+CREATE TABLE `prefix_commentwall` (
+ `ident` int(11) NOT NULL auto_increment,
+
+ `wallowner` int(11) NOT NULL,
+
+ `comment_owner` int(11) NOT NULL,
+ `content` text NOT NULL,
+
+ `posted` int(11) NOT NULL,
+
+ PRIMARY KEY (`ident`)
+);
Index: /elgg/tags/20090118/mod/commentwall/replyto.php
===================================================================
--- /elgg/tags/20090118/mod/commentwall/replyto.php (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/replyto.php (revision 33)
@@ -0,0 +1,14 @@
+
Index: /elgg/tags/20090118/mod/commentwall/do_action.php
===================================================================
--- /elgg/tags/20090118/mod/commentwall/do_action.php (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/do_action.php (revision 33)
@@ -0,0 +1,85 @@
+\n$message \n$err \n\n";
+ }
+ else
+ {
+ header("Location: $returnurl");
+ exit;
+ }
+ }
+ else if($action == "commentwall::delete")
+ {
+ if (commentwall_deletecomment($ident))
+ {
+ // Success
+ }
+ else
+ {
+ // Fail
+ }
+
+ // Redirect
+ header("Location: $returnurl");
+ exit;
+ }
+
+ // Output the page
+ if ($displaymode=="xml") {
+ header("Content-type: text/xml");
+
+ echo $page;
+ }
+
+
+?>
Index: /elgg/tags/20090118/mod/commentwall/lib/commentwall_settings.php
===================================================================
--- /elgg/tags/20090118/mod/commentwall/lib/commentwall_settings.php (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/lib/commentwall_settings.php (revision 33)
@@ -0,0 +1,40 @@
+$title";
+ $run_result .= "$blurb
";
+
+ $pubtext = __gettext("Public");
+ $logitext = __gettext("Logged in users");
+ $pritext = __gettext("Private");
+ $fotext = __gettext("Friends only");
+
+ $select_box = <<< END
+
+ $pubtext
+ $logitext
+ $fotext
+ $pritext
+
+END;
+
+ $run_result .= templates_draw(array(
+ 'context' => 'databox',
+ 'name' => __gettext("Access level: "),
+ 'column1' => $select_box
+ )
+ );
+?>
Index: /elgg/tags/20090118/mod/commentwall/README.txt
===================================================================
--- /elgg/tags/20090118/mod/commentwall/README.txt (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/README.txt (revision 33)
@@ -0,0 +1,10 @@
+Comment Wall Widget
+Originally written, March 2007
+David Tosh, Curverider Ltd
+dave@curverider.co.uk
+
+USAGE:
+
+Install in the /mod/ folder of your Elgg installation.
+
+It will now appear as a widget option for your users.
Index: /elgg/tags/20090118/mod/commentwall/post.php
===================================================================
--- /elgg/tags/20090118/mod/commentwall/post.php (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/post.php (revision 33)
@@ -0,0 +1,36 @@
+Use this form to post a comment.");
+ $html .= commentwall_post_form($wallowner, $reply, false, "", $returnurl);
+
+ templates_page_output($title, $html);
+
+?>
Index: /elgg/tags/20090118/mod/commentwall/postgres7.sql
===================================================================
--- /elgg/tags/20090118/mod/commentwall/postgres7.sql (revision 36)
+++ /elgg/tags/20090118/mod/commentwall/postgres7.sql (revision 36)
@@ -0,0 +1,11 @@
+CREATE TABLE prefix_commentwall (
+ ident SERIAL PRIMARY KEY,
+
+ wallowner integer NOT NULL,
+
+ comment_owner integer NOT NULL,
+ content text NOT NULL,
+
+ posted integer NOT NULL
+
+);
Index: /elgg/tags/20090118/mod/commentwall/template
===================================================================
--- /elgg/tags/20090118/mod/commentwall/template (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/template (revision 33)
@@ -0,0 +1,14 @@
+
Index: /elgg/tags/20090118/mod/commentwall/lib.php
===================================================================
--- /elgg/tags/20090118/mod/commentwall/lib.php (revision 105)
+++ /elgg/tags/20090118/mod/commentwall/lib.php (revision 105)
@@ -0,0 +1,385 @@
+
+ */
+
+ /**
+ * Comment wall initialisation.
+ */
+ function commentwall_init()
+ {
+ global $CFG, $db,$function, $metatags, $template;
+
+ // Add meta tags
+ $metatags .= "";
+
+ // Define some templates
+ templates_add_context('commentwallobject', 'mod/commentwall/template');
+ templates_add_context('commentwallfooter', 'mod/commentwall/footer');
+ templates_add_context('css', 'mod/commentwall/css');
+
+ // Set up the database
+ $tables = $db->Metatables();
+ if (!in_array($CFG->prefix . "commentwall", $tables))
+ {
+ if (file_exists($CFG->dirroot . "mod/commentwall/$CFG->dbtype.sql"))
+ {
+ modify_database($CFG->dirroot . "mod/commentwall/$CFG->dbtype.sql");
+ //reload system
+ header_redirect($CFG->wwwroot);
+
+ }
+ else
+ {
+ error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg commentwall. See the mod/commentwall directory.");
+ }
+
+ print_continue($CFG->wwwroot);
+ exit;
+ }
+
+ // Add configuration options
+ $function['userdetails:edit:details'][] = $CFG->dirroot . "mod/commentwall/lib/commentwall_settings.php";
+ }
+
+ /**
+ * Comment wall page setup
+ */
+ function commentwall_pagesetup()
+ {
+
+ }
+
+ /** HACK: Output the given code as document.write */
+ function commentwall_todocwrite($text)
+ {
+ $body = "";
+ foreach (explode("\n",addslashes($text)) as $line)
+ $body .= "document.write(\"" . trim($line) . "\");\n";
+
+ return $body;
+ }
+
+ /**
+ * Retrieve the wall for a given userid.
+ *
+ * @return mixed Array of comment objects, else returns false.
+ * @param unknown_type $userid The user / wall we are retrieving
+ * @param unknown_type $limit Limit on the search
+ * @param unknown_type $offset Offset
+ */
+ function commentwall_getwall($userid, $limit = 3, $offset = 0)
+ {
+ global $CFG;
+
+ $query = "SELECT * from {$CFG->prefix}commentwall where wallowner=$userid ORDER BY posted DESC limit $limit offset $offset";
+
+ // echo $query;
+
+ return get_records_sql($query);
+ }
+
+ /**
+ * Add a comment to a wall.
+ * @param unknown_type $wall_id Which wall to post to
+ * @param unknown_type $poster_id
+ * @param unknown_type $text
+ */
+ function commentwall_addcomment($wall_id, $poster_id, $text)
+ {
+ global $CFG;
+
+ $newcomment = new stdClass;
+ $newcomment->wallowner = $wall_id;
+ $newcomment->comment_owner = $poster_id;
+ $newcomment->content = $text;
+ $newcomment->posted = time();
+
+ if ($newcomment->ident = insert_record("commentwall", $newcomment)) {
+ if ($newcomment->comment_owner != $newcomment->wallowner) {
+ notify_user($wall_id, __gettext("Someone has posted to your comment wall"), __gettext("Check it out") . ": " . $CFG->wwwroot . user_info("username", $wall_id) . "/profile/");
+ }
+ $newcomment = plugin_hook("commentwall","publish",$newcomment);
+ return $newcomment->ident;
+ }
+
+ $newcomment->ident = insert_record("commentwall", $newcomment);
+ $newcomment = plugin_hook("commentwall","publish",$newcomment);
+ return $newcomment->ident;
+ }
+
+ /**
+ * Delete the given object id.
+ *
+ * @param unknown_type $object_id
+ */
+ function commentwall_deletecomment($object_id)
+ {
+ global $CFG;
+
+ // Pull object
+ $comment = get_record_sql("SELECT * from {$CFG->prefix}commentwall where ident=$object_id");
+
+ // Check ownership (if you are either the wall owner or the comment owner you can delete this)
+ if ((commentwall_permissions_check($comment->wallowner)) || (commentwall_permissions_check($comment->comment_owner)))
+ {
+ if (!delete_records("commentwall", "ident", $comment->ident))
+ plugin_hook('commentwall','delete',$comment);
+ return false;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Reply to a given comment.
+ * @param unknown_type $comment_id
+ * @param unknown_type $wall_id Which wall to post to
+ * @param unknown_type $poster_id
+ * @param unknown_type $text
+ */
+ function commentwall_replyto($comment_id, $wall_id, $poster_id, $text)
+ {
+ global $CFG;
+
+ // Extract the comment we are replying to
+ $comment = get_record_sql("SELECT * from {$CFG->prefix}commentwall where ident=$comment_id");
+
+ $newcomment = new stdClass;
+ $newcomment->wallowner = $wall_id;
+ $newcomment->comment_owner = $poster_id;
+ $newcomment->content = $text;
+ $newcomment->posted = time();
+
+ return insert_record("commentwall", $newcomment, true);
+
+ }
+
+ /**
+ * Display post form.
+ */
+ function commentwall_post_form($wall_owner, $replyto = -1, $specialmode = false, $suffix = "", $returnurl = "")
+ {
+ global $CFG;
+
+ if ($returnurl=="")
+ $returnurl = urlencode($_SERVER['REQUEST_URI']);
+ $buttontxt = __gettext("Post comment");
+
+ $frm_elements_common = <<< END
+
+
+
+
+
+
+
+END;
+
+ $html = <<< END
+
+END;
+
+ return $html;
+ }
+
+ /**
+ * Display a comment.
+ *
+ * @param unknown_type $comment_obj
+ */
+ function commentwall_displaycomment($comment_obj)
+ {
+ global $CFG;
+
+ $html = "";
+
+ $owner_username = user_info("name", $comment_obj->wallowner);
+ $comment_owner_username = ($comment_obj->comment_owner != 0 ? user_info("name", $comment_obj->comment_owner) : __gettext("Anonymous User"));
+ $icon = ($comment_obj->comment_owner != 0 ? user_info('icon',$comment_obj->comment_owner) : -1);
+ $userlogo = user_icon_html($comment_obj->comment_owner,60,true); // $CFG->wwwroot.'_icon/user/'.$icon.'/w/50';
+ $userlink = ($comment_obj->comment_owner != 0 ? $CFG->wwwroot . user_info("username", $comment_obj->comment_owner) . "/" : "");
+
+ $date = date("l jS F Y, g:ia" ,$comment_obj->posted);
+ $text = $comment_obj->content;
+
+ $replytowall = __gettext("Post reply");
+ $replytootherwall = sprintf(__gettext("Reply on %s's wall"), $comment_owner_username);
+ $delete = __gettext("Delete");
+
+ $doaction = "{$CFG->wwwroot}mod/commentwall/do_action.php?owner=" . page_owner(). "&return_url=" .urlencode($_SERVER['REQUEST_URI']);
+
+ $replybar = "";
+ if (isloggedin())
+ {
+ //$replybar .= "$replytowall ";
+ if (($comment_obj->wallowner != $comment_obj->comment_owner) && ($comment_obj->comment_owner != 0))
+ $replybar .= "wwwroot}mod/commentwall/index.php?owner={$comment_obj->comment_owner}&wallowner={$comment_obj->comment_owner}&comment_owner={$_SESSION['userid']}&reply={$comment_obj->ident}&return_url=" .urlencode($_SERVER['REQUEST_URI'])."\">$replytootherwall | ";
+
+ if ((commentwall_permissions_check($comment_obj->comment_owner))
+ || (commentwall_permissions_check($comment_obj->wallowner)))
+ $replybar.= "ident}\">$delete ";
+ }
+
+
+ $html = templates_draw(
+ array(
+ 'context' => "commentwallobject",
+ 'userlogo' => $userlogo,
+ 'userlink' => $userlink,
+ 'usertxt' => $comment_owner_username,
+ 'date' => $date,
+ 'text' => $text,
+ 'replybar' => $replybar
+ )
+ );
+
+ return $html;
+ }
+
+ /**
+ * @param $wall List of objects.
+ */
+ function commentwall_display_footer($owner, $limit = 3, $offset = 0)
+ {
+ global $CFG;
+
+ $html = "";
+
+ $count = get_record_sql("SELECT count(ident) as ident from {$CFG->prefix}commentwall WHERE wallowner=$owner");
+ $count = $count->ident;
+
+ $qs = $_SERVER['REDIRECT_URL'];
+ if ($qs == "") $qs = $_SERVER['PHP_SELF'];
+
+ // See if we need to display a next button
+ $nextbutton = "";
+ if ($count - $offset > $limit)
+ $nextbutton = "" . __gettext("Back") . " ";
+
+ // See if we need to display a prev button
+ $prevbutton = "";
+ if (floor($offset / $limit) > 0)
+ $prevbutton = "" . __gettext("Forward") . " ";
+
+ return templates_draw(
+ array(
+ 'context' => 'commentwallfooter',
+ 'nextbutton' => $nextbutton,
+ 'prevbutton' => $prevbutton
+ )
+ );
+ }
+
+ /**
+ * Display a comment wall.
+ *
+ * @param unknown_type $wall
+ */
+ function commentwall_displaywall_html($wall,$showalltxt = false, $owner)
+ {
+ global $CFG;
+
+ $html = "";
+
+ // Get access permissions
+ $access = user_flag_get("commentwall_access", $owner);
+ if (!$access || $access == "PUBLIC") $access = "LOGGED_IN"; // If no access controls set then assume public
+
+ if (
+ ($owner == $_SESSION['userid']) || // Display if the current user owns it
+ ($access == "PUBLIC") || // Display if public
+ ( ($access == "LOGGED_IN") && (isloggedin()) ) || // If user needs to be logged in, check it
+ ( ($access == "FRIENDS_ONLY") && (isfriend($_SESSION['userid'],$owner))) || // If you can
+ ( ($access == "PRIVATE") && ($owner == $_SESSION['userid']) ) // If access is private then ensure that $owner is the current logged in user
+ )
+ {
+ // $owner = page_owner();
+ $html = "";
+
+ if (($showalltxt) && ($wall))
+ {
+ $html .= "";
+ }
+
+
+ $html .= commentwall_post_form(page_owner());
+
+ if (!$wall) {
+ $html .= "" . __gettext("No comments on this wall, why not be the first?") . "
";
+ return $html;
+ }
+
+ }
+
+ if (is_array($wall)) {
+ foreach ($wall as $w)
+ $html .= commentwall_displaycomment($w);
+ }
+
+ return $html;
+ }
+
+ /**
+ * Render the profile on a profile.
+ *
+ * @param unknown_type $owner
+ */
+ function commentwall_displayonprofile($owner, $limit = 3, $offset = 0)
+ {
+ global $CFG;
+ $html = "";
+
+ $wall = commentwall_getwall($owner, $limit, $offset);
+
+ $html = "";
+
+ return $html;
+ }
+
+/**
+ * Determines whether or not the current user has permission to do something with the comment.
+ *
+ * @param $owner The owner of the comment.
+ * @return boolean True or false.
+ */
+function commentwall_permissions_check($owner)
+{
+ global $CFG;
+
+ if (isloggedin()) {
+ if ($owner == $_SESSION['userid'] || user_flag_get('admin',$_SESSION['userid'])) {
+ return true;
+ }
+ if (user_info("user_type",$owner) == "community") {
+ if (record_exists('users','ident',$owner,'owner',$_SESSION['userid'],'user_type','community')) {
+ return true;
+ }
+ if (count_records_sql('SELECT count(u.ident) FROM '.$CFG->prefix.'friends f
+ JOIN '.$CFG->prefix.'users u ON u.ident = f.friend
+ WHERE u.ident = ? AND f.owner = ? AND u.user_type = ?',
+ array($owner,$_SESSION['userid'],'community'))) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+?>
Index: /elgg/tags/20090118/mod/commentwall/commentwall.js
===================================================================
--- /elgg/tags/20090118/mod/commentwall/commentwall.js (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/commentwall.js (revision 33)
@@ -0,0 +1,126 @@
+var http_Request = false;
+var success = false;
+var objectid = "";
+var thesuffix = "";
+
+var sURL = unescape(window.location.pathname);
+
+function cw_showhide(oid)
+{
+ var e = document.getElementById(oid);
+ if(e.style.display == 'none') {
+ e.style.display = 'block';
+ } else {
+ e.style.display = 'none';
+ }
+}
+
+function cw_hide(oid)
+{
+ var e = document.getElementById(oid);
+
+ e.style.display = 'none';
+
+}
+
+function cw_getAjaxObj()
+{
+ var xmlHttp;
+
+ try
+ {
+ // Firefox, Opera 8.0+, Safari
+ xmlHttp=new XMLHttpRequest();
+ }
+ catch (e)
+ {
+ // Internet Explorer
+ try
+ {
+ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
+ }
+ catch (e)
+ {
+ try
+ {
+ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ catch (e)
+ {
+ return false;
+ }
+ }
+ }
+
+ return xmlHttp;
+}
+
+function cw_alertContents()
+{
+ if (http_Request.readyState == 4) {
+ if (http_Request.status == 200) {
+
+ result = http_Request.responseXML;
+ message = result.getElementsByTagName('message')[0];
+
+ error = result.getElementsByTagName('error')[0];
+ if (error.textContent == '0') {
+ success = true;
+ }
+
+ if (success == true)
+ {
+ document.location.reload();
+ //document.getElementById('commentwall_post_ajaxmessages_' + objectid + thesuffix).innerHTML = '' + message.textContent + ' ';
+ document.getElementById('commentwall_post_link_' + objectid + thesuffix).innerHTML = ' ';
+
+
+ }
+ else
+ {
+ document.getElementById('commentwall_post_ajaxmessages_' + objectid + thesuffix).innerHTML = message.textContent;
+ }
+
+ } else {
+ alert('There was a problem with the request.');
+ }
+ }
+}
+
+function cw_sendcomment(url, formid, oid, suffix)
+{
+ var parameters;
+ objectid = oid;
+ if (suffix!='') thesuffix = suffix;
+
+ http_Request = cw_getAjaxObj();
+
+ if (http_Request==false)
+ {
+ return false;
+ }
+
+ // Construct parameters
+ frm = document.getElementById(formid + thesuffix);
+
+ parameters = "";
+ for(var i = 0;i < frm.elements.length;i++)
+ {
+ element = frm.elements[i];
+
+ parameters = parameters + element.name +"=" + encodeURI( element.value ) + "&";
+ }
+ parameters = parameters + "returnformat=xml";
+
+ // Post result
+ http_Request.onreadystatechange = cw_alertContents;
+ http_Request.open('POST', url, true);
+ http_Request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http_Request.setRequestHeader("Content-length", parameters.length);
+ http_Request.setRequestHeader("Connection", "close");
+ http_Request.send(parameters);
+
+ if (success==true) {
+ frm.text.value="";
+ }
+}
Index: /elgg/tags/20090118/mod/commentwall/index.php
===================================================================
--- /elgg/tags/20090118/mod/commentwall/index.php (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/index.php (revision 33)
@@ -0,0 +1,31 @@
+
Index: /elgg/tags/20090118/mod/commentwall/footer
===================================================================
--- /elgg/tags/20090118/mod/commentwall/footer (revision 33)
+++ /elgg/tags/20090118/mod/commentwall/footer (revision 33)
@@ -0,0 +1,3 @@
+
Index: /elgg/tags/20090118/mod/blog/rss2.php
===================================================================
--- /elgg/tags/20090118/mod/blog/rss2.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/rss2.php (revision 33)
@@ -0,0 +1,127 @@
+wwwroot . "news/weblog/rss/" . urlencode(trim($tag)) . "/rssstyles.xsl";
+ $xslurl = "";
+ } else {
+ $mainurl = $CFG->wwwroot . $info->username . "/weblog/";
+ $rssurl = $mainurl . "rss/" . $tagurl;
+ $xslurl = $mainurl . "rss/" . $tagurl . "rssstyles.xsl";
+ }
+
+ switch($modifier) {
+
+ case "all": $rssurl = $CFG->wwwroot . "_weblog/rss2.php?page_owner=-1&modifier=all";
+ $mainurl = $CFG->wwwroot . "_weblog/everyone.php";
+ $rssdescription = sprintf(__gettext("The most recent weblog posts on %s."),$sitename);
+ $rssweblog = $rssdescription;
+ break;
+ default: $name = (stripslashes(user_name($info->ident)));
+ $rssdescription = sprintf(__gettext("The weblog for %s, hosted on %s."),$name,$sitename);
+ break;
+
+ }
+
+ /* wwwroot}_rss/styles.xsl?url=$mainurl&rssurl=$rssurl"?> */
+ /* */
+ if (!empty($xslurl)) {
+ $output .= "\n\n";
+ }
+ $output .= <<< END
+
+
+
+
+ $mainurl
+END;
+ $modifier = optional_param('modifier');
+ $output .= run("weblogs:rss:getitems", array($page_owner, 10, $tag, $modifier));
+
+ $output .= <<< END
+
+
+
+END;
+ }
+
+ if ($output) {
+ header("Pragma: public");
+ header("Cache-Control: public");
+ header('Expires: ' . gmdate("D, d M Y H:i:s", (time()+3600)) . " GMT");
+
+ $if_none_match = (isset($_SERVER['HTTP_IF_NONE_MATCH'])) ? preg_replace('/[^0-9a-f]/', '', $_SERVER['HTTP_IF_NONE_MATCH']) : false;
+
+ $etag = md5($output);
+ header('ETag: "' . $etag . '"');
+
+ if ($if_none_match && $if_none_match == $etag) {
+ header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
+ exit;
+ }
+
+ header("Content-Length: " . strlen($output));
+
+ header("Content-type: text/xml; charset=utf-8");
+ echo $output;
+ }
+ // }
+ }
+}
Index: /elgg/tags/20090118/mod/blog/friends.php
===================================================================
--- /elgg/tags/20090118/mod/blog/friends.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/friends.php (revision 33)
@@ -0,0 +1,27 @@
+' . $body . '';
+
+ templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/blog/interesting.php
===================================================================
--- /elgg/tags/20090118/mod/blog/interesting.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/interesting.php (revision 33)
@@ -0,0 +1,27 @@
+' . $body . '';
+
+templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/blog/LICENSE
===================================================================
--- /elgg/tags/20090118/mod/blog/LICENSE (revision 33)
+++ /elgg/tags/20090118/mod/blog/LICENSE (revision 33)
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ , 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Index: /elgg/tags/20090118/mod/blog/everyone.php
===================================================================
--- /elgg/tags/20090118/mod/blog/everyone.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/everyone.php (revision 33)
@@ -0,0 +1,37 @@
+" . __gettext("You can filter this page to certain types of posts:") . "";
+ $body .= '';
+
+ $body .= run("weblogs:everyone:view");
+ $body = '' . $body . '
';
+
+ templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/blog/templates_preview.php
===================================================================
--- /elgg/tags/20090118/mod/blog/templates_preview.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/templates_preview.php (revision 33)
@@ -0,0 +1,58 @@
+".strftime("%A, %d %B %Y", time())."";
+
+ $postedName = __gettext("Unkind Guest"); // gettext variable
+ $bodyContent = __gettext(" I mock you, Babbage! Your difference engine will never catch on."); // gettext variable
+ $postedName2 = __gettext("Charles Babbage"); // gettext variable
+ $bodyContent2 = __gettext("Says you!"); // gettext variable
+ $fullName = __gettext("Charles Babbage"); // gettext variable
+ $title = __gettext("The Analytical Engine - introduction from Chapter VIII"); // gettext variable
+ $bodyContents = __gettext("The circular arrangement of the axes of the Difference Engine round the large central wheels led to the most extended prospects. The whole of arithmetic now appeared within the grasp of mechanism. A vague glimpse even of an Analytical Engine at length opened out, and I pursued with enthusiasm the shadowy vision. The drawings and the experiments were of the most costly kind. Draftsmen of the highest order were necessary to economize the labour of my own head; whilst skilled workmen were required to execute the experimental machinery to which I was obliged constantly to have recourse. In order to carry out my pursuits successfully, I had purchased a house with above a quarter of an acre of ground in a very quiet locality. My coach-house was now converted into a forge and a foundry, whilst my stables were transformed into a workshop. I built other extensive workshops myself, and had a fireproof building for my drawings and draftsmen. Having myself worked with a variety of tools, and having studied the art of constructing each of them, I at length laid it down as a principle - that, except in rare cases, I would never do anything myself if I could afford to hire another person who could do it for me.");
+
+ $weblogbody = $bodyContents;
+
+ $commentsbody = templates_draw(array(
+ 'context' => 'weblogcomment',
+ 'postedname' => "$postedName",
+ 'body' => "$bodyContent",
+ 'posted' => strftime("%A, %d %B %Y, %H:%M %Z", time())
+ )
+ );
+
+ $commentsbody .= templates_draw(array(
+ 'context' => 'weblogcomment',
+ 'postedname' => "$postedName2",
+ 'body' => "$bodyContent2",
+ 'posted' => strftime("%A, %d %B %Y, %H:%M %Z", time())
+ )
+ );
+
+ $commentsbody = templates_draw(array(
+ 'context' => 'weblogcomments',
+ 'comments' => $commentsbody
+ )
+ );
+
+ $body .= templates_draw(array(
+ 'context' => 'weblogpost',
+ 'date' => gmdate("H:i",time()),
+ 'username' => "charlesbabbage",
+ 'usericon' => "../../_templates/babbage.jpg",
+ 'body' => nl2br($weblogbody),
+ 'fullname' => "$fullName",
+ 'title' => "$title",
+ 'comments' => $commentsbody
+ )
+ );
+
+ $run_result .= templates_draw(array(
+ 'context' => 'contentholder',
+ 'title' => __gettext("Weblog post"),
+ 'body' => $body
+ )
+ );
+
+?>
Index: /elgg/tags/20090118/mod/blog/action_redirection.php
===================================================================
--- /elgg/tags/20090118/mod/blog/action_redirection.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/action_redirection.php (revision 33)
@@ -0,0 +1,12 @@
+
Index: /elgg/tags/20090118/mod/blog/widget_css
===================================================================
--- /elgg/tags/20090118/mod/blog/widget_css (revision 33)
+++ /elgg/tags/20090118/mod/blog/widget_css (revision 33)
@@ -0,0 +1,11 @@
+.weblog-title {
+ margin:10px 0 10px 10px;
+}
+
+.post {
+ margin:10px 0 10px 10px;
+}
+
+.info {
+ margin:10px 0 0px 0px;
+}
Index: /elgg/tags/20090118/mod/blog/lib.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib.php (revision 129)
+++ /elgg/tags/20090118/mod/blog/lib.php (revision 129)
@@ -0,0 +1,699 @@
+size = $size;
+ if ($size < 100) {
+ $extra = "/h/$size/w/$size";
+ }
+ $profile_icon = user_info("icon",$profile_id);
+ $user_type = user_type($profile_id);
+ $user_icon->icon = $icon_id;
+ if ($user_icon->icon != $profile_icon) {
+ $user_icon->url = "{$CFG->wwwroot}_icon/user/{$user_icon->icon}{$extra}";
+ $user_icon->html = " url}\" border=\"0\" alt=\"user icon\" />";
+ if ($urlonly) {
+ return $user_icon->url;
+ } else {
+ return $user_icon->html;
+ }
+ }
+ if ($urlonly) {
+ return -1;
+ } else {
+ $extensionContext = trim(optional_param('extension','weblog'));
+ if(array_key_exists($extensionContext,$CFG->weblog_extensions)
+ && array_key_exists('icon',$CFG->weblog_extensions[$extensionContext])){
+ $icon = $CFG->weblog_extensions[$extensionContext]['icon'];
+ return " ";
+ }
+ else{
+ return " wwwroot}_icon/user/$profile_icon{$extra}\" border=\"0\" alt=\"default user icon\" />";
+ }
+ }
+}
+
+function blog_pagesetup() {
+ // register links --
+ global $profile_id;
+ global $PAGE;
+ global $CFG;
+
+ $page_owner= $profile_id;
+
+ // main menu
+ if (isloggedin() && user_info("user_type", $_SESSION['userid']) != "external") {
+
+ if (defined("context") && context == "weblog" && $page_owner == $_SESSION['userid']) {
+
+ $PAGE->menu[]= array (
+ 'name' => 'weblog',
+ 'html' => "wwwroot}{$_SESSION['username']}/weblog\" class=\"selected\" >" . __gettext("Blog") . ' ');
+
+ } else {
+ $PAGE->menu[]= array (
+ 'name' => 'weblog',
+ 'html' => "wwwroot}{$_SESSION['username']}/weblog\" >" . __gettext("Blog") . ' ');
+ };
+ }
+
+ $weblog_username= user_info('username', $page_owner);
+
+ // submenu
+ if (defined("context") && context == "weblog") {
+
+ if ($page_owner != -1) {
+
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:rssfeed',
+ 'html' => "wwwroot}{$weblog_username}/weblog/rss/\"> wwwroot}mod/template/icons/rss.png\" border=\"0\" alt=\"rss\" /> "
+ );
+
+ if (run("permissions:check", "weblog") && logged_on) {
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:post',
+ 'html' => "wwwroot}{$weblog_username}/weblog/edit\">" . __gettext("Post a new entry") . ' ');
+ }
+
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:view',
+ 'html' => "wwwroot}{$weblog_username}/weblog/\">" . __gettext("View blog") . ' ');
+
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:archive',
+ 'html' => "wwwroot}{$weblog_username}/weblog/archive/\">" . __gettext("Archive") . ' ');
+
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:friends',
+ 'html' => "wwwroot}{$weblog_username}/weblog/friends/\">" . __gettext("Friends' blogs") . ' ');
+
+ if ($page_owner == $_SESSION['userid']) {
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:interesting',
+ 'html' => "wwwroot}{$weblog_username}/weblog/interesting/\">" . __gettext("Interesting posts") . ' ');
+ }
+ }
+
+ $PAGE->menu_sub[]= array (
+ 'name' => 'blog:everyone',
+ 'html' => "wwwroot}weblog/everyone\">" . __gettext("View all posts") . ' ');
+
+ }
+
+}
+
+function blog_init() {
+
+ global $CFG, $function;
+
+
+ // Load default template
+ $function['init'][] = $CFG->dirroot . "mod/blog/default_template.php";
+
+ // Functions to perform upon initialisation
+ $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_init.php";
+ $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_actions.php";
+
+ // Init for search
+ $function['search:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_init.php";
+ $function['search:all:tagtypes'][] = $CFG->dirroot . "mod/blog/lib/function_search_all_tagtypes.php";
+
+ // Function to search through weblog posts
+ $function['search:display_results'][] = $CFG->dirroot . "mod/blog/lib/function_search.php";
+ $function['search:display_results:rss'][] = $CFG->dirroot . "mod/blog/lib/function_search_rss.php";
+
+ // Edit / create weblog posts
+ $function['weblogs:edit'][] = $CFG->dirroot . "mod/blog/lib/weblogs_edit.php";
+ $function['weblogs:posts:add'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_add.php";
+ $function['weblogs:posts:edit'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_edit.php";
+
+ // View weblog posts
+ //$function['weblogs:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_post_field_wrapper.php";
+ $function['weblogs:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_view.php";
+ $function['weblogs:posts:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_view.php";
+
+ // Add assign list
+ $function['weblogs:assign:field'][] = $CFG->dirroot. "mod/blog/lib/weblogs_assign_field.php";
+
+ // Put this one before the Flag content form
+ $index = count($function['weblogs:posts:view:individual']);
+ for($i=0; $i < count($function['weblogs:posts:view:individual']);$i++ ){
+ $weblog_individual = $function['weblogs:posts:view:individual'][$i];
+ if(strpos($weblog_individual,"flag_form")>0){
+ $index = $i;
+ $flag_form = $weblog_individual;
+ }
+ }
+ $function['weblogs:posts:view:individual'][$index] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_view.php";
+ if(!empty($flag_form)){
+ $function['weblogs:posts:view:individual'][] = $flag_form;
+ }
+
+ $function['weblogs:friends:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_friends_view.php";
+ $function['weblogs:everyone:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_all_users_view.php";
+
+ // This is necessary to ensure that the blog text process function its the first one to be called
+ if(array_key_exists("weblogs:text:process",$function)){
+ $function['weblogs:text:process'] = array_merge(array($CFG->dirroot ."mod/blog/lib/weblogs_text_process.php"),$function['weblogs:text:process']);
+ }
+ else{
+ $function['weblogs:text:process'][] = $CFG->dirroot . "mod/blog/lib/weblogs_text_process.php";
+ }
+ $function['weblogs:archives:view'][] = $CFG->dirroot . "mod/blog/lib/archives_view.php";
+ $function['weblogs:archives:month:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_view_month.php";
+ $function['weblogs:interesting:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_interesting_view.php";
+
+ // Mark posts as interesting (or not)
+ $function['weblogs:interesting:form'][] = $CFG->dirroot . "mod/blog/lib/display_interesting_post_form.php";
+
+ // Edit / create weblog comments
+ $function['weblogs:comments:add'][] = $CFG->dirroot . "mod/blog/lib/weblogs_comments_add.php";
+
+ // Log on bar down the right hand side
+ // $function['profile:log_on_pane'][] = $CFG->dirroot . "units/weblogs/weblogs_user_info_menu.php";
+ $function['display:sidebar'][] = $CFG->dirroot . "mod/blog/lib/weblogs_user_info_menu.php";
+
+ // Weblog preview
+ $function['templates:preview'][] = $CFG->dirroot . "mod/blog/templates_preview.php";
+
+ // Establish permissions
+ $function['permissions:check'][] = $CFG->dirroot . "mod/blog/lib/permissions_check.php";
+
+ // Actions to perform when an access group is deleted
+ $function['groups:delete'][] = $CFG->dirroot . "mod/blog/lib/groups_delete.php";
+
+ // Publish static RSS file of posts
+ $function['weblogs:rss:getitems'][] = $CFG->dirroot . "mod/blog/lib/function_rss_getitems.php";
+ $function['weblogs:rss:publish'][] = $CFG->dirroot . "mod/blog/lib/function_rss_publish.php";
+
+ // Removing function from weblogs_init.php
+ $function['weblogs:html_activate_urls'][] = $CFG->dirroot . "mod/blog/lib/function_html_activate_urls.php";
+
+ //$CFG->widgets->display['blog'] = "blog_widget_display";
+ //$CFG->widgets->edit['blog'] = "blog_widget_edit";
+
+ $CFG->widgets->list[]= array ('name' => __gettext("Blog widget"),
+ 'description' => __gettext("Displays the latest blog posts from a blog of your choice."),
+ 'type' => "blog::blog");
+
+ $CFG->templates->variables_substitute['blog'][]= "blog_keyword";
+ $CFG->templates->variables_substitute['blogsummary'][]= "blog_summary_keyword";
+ $CFG->templates->variables_substitute['blogexecutivesummary'][] = "blog_executive_summary_keyword";
+
+ // Delete users
+ listen_for_event("user", "delete", "blog_user_delete");
+
+ // Display modules
+ if (!isset ($CFG->display_field_module)) {
+ $CFG->display_field_module= array ();
+ }
+
+ if (!array_key_exists("select", $CFG->display_field_module)) {
+ $CFG->display_field_module["select"]= "blog";
+ }
+
+ if (!array_key_exists("select_associative", $CFG->display_field_module)) {
+ $CFG->display_field_module["select_associative"]= "blog";
+ }
+
+ if (!array_key_exists("selectg", $CFG->display_field_module)) {
+ $CFG->display_field_module["selectg"]= "blog";
+ }
+ if (!array_key_exists("selectd", $CFG->display_field_module) && !array_key_exists("date_select", $CFG->display_field_module)) {
+ $CFG->display_field_module["selectd"]= "blog";
+ $CFG->display_field_module["date_select"]= "blog";
+ }
+ if (!array_key_exists("radio", $CFG->display_field_module)) {
+ $CFG->display_field_module["radio"]= "blog";
+ }
+ if (!array_key_exists("vertical_radio", $CFG->display_field_module)) {
+ $CFG->display_field_module["vertical_radio"]= "blog";
+ }
+
+ if (!isset ($CFG->weblog_extensions)) {
+ $CFG->weblog_extensions= array ();
+ }
+
+
+ //$CFG->weblog_extensions['weblog']= array ();
+}
+
+function blog_widget_display($widget) {
+
+ global $CFG;
+
+ $blog_id= widget_get_data("blog_id", $widget->ident);
+ $blog_posts= widget_get_data("blog_posts", $widget->ident);
+
+ $style = "";
+
+ $body= "";
+ $body .=$style;
+
+
+
+ if (empty ($blog_id)) {
+ global $page_owner;
+ $blog_id= $page_owner;
+ }
+ if (empty ($blog_posts)) {
+ $blog_posts= 1;
+ }
+
+ $body .='';
+ $where= run("users:access_level_sql_where", $_SESSION['userid']);
+ $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts");
+
+ if (is_array($posts) && !empty ($posts)) {
+ foreach ($posts as $post) {
+ $body .= run("weblogs:posts:view", $post);
+ }
+ }
+ $body .= '
';
+
+ return array ('title' => __gettext('Blog').' :: '.htmlspecialchars(user_name($blog_id), ENT_COMPAT, 'utf-8'), 'content' => $body);
+
+}
+
+// KJ - converted to widget sytem
+
+function blog_widget_edit($widget) {
+
+ global $CFG, $page_owner;
+
+ $blog_id= widget_get_data("blog_id", $widget->ident);
+ $blog_posts= widget_get_data("blog_posts", $widget->ident);
+ if (empty ($blog_posts)) {
+ $blog_posts= 1;
+ }
+ if (empty ($blog_id)) {
+ $blog_id= $page_owner;
+ }
+
+ $connections= get_records_sql("select u.ident, u.name from " . $CFG->prefix . "friends f join " . $CFG->prefix . "users u on u.ident = f.friend where f.owner = " . $_SESSION['userid'] . " order by u.name asc");
+ $data= new stdClass;
+ $data->ident= $page_owner;
+ $data->name= run("profile:display:name", $page_owner);
+ $connections[]= $data;
+ if ($page_owner != $_SESSION['userid']) {
+ $data= new stdClass;
+ $data->ident= $_SESSION['userid'];
+ $data->name= run("profile:display:name", $_SESSION['userid']);
+ $connections[]= $data;
+ }
+
+ $body= "" . __gettext("Blog widget") . " ";
+ $body .= "" . __gettext("This widget displays the last couple of blog posts from an individual user. To begin, select the user from your connections below:") . "
";
+
+ $body .= "\n";
+ if (is_array($connections) && !empty ($connections)) {
+ foreach ($connections as $connection) {
+ if ($connection->ident == $blog_id) {
+ $selected= "selected=\"selected\"";
+ } else {
+ $selected= "";
+ }
+ $body .= "ident . "\" $selected>" . $connection->name . " \n";
+ }
+ }
+ $body .= "
\n";
+
+ $body .= "" . __gettext("Then enter the number of blog posts you'd like to display:") . "
";
+
+ $body .= "
";
+
+ return $body;
+
+}
+
+function blog_keyword($vars) {
+ global $CFG, $db;
+
+ $body= "";
+
+ if (!isset ($vars[1])) {
+ $blog_posts= 2;
+ } else {
+ $blog_posts= $vars[1];
+ }
+
+ $where= run("users:access_level_sql_where", $_SESSION['userid']);
+
+ if (!isset ($vars[2]) || $vars[2] == "all") {
+ $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) order by posted desc limit $blog_posts");
+ } else {
+ $blog_id= (int) user_info_username('ident', $vars[2]);
+ $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts");
+ }
+
+ if (is_array($posts) && !empty ($posts)) {
+ foreach ($posts as $post) {
+ if (!isset($vars[3]) || $vars[3] != "slim") {
+ $body .= run("weblogs:posts:view", $post);
+ } else {
+ $body .= "";
+ $body .= "
" . $post->title . " ";
+ $body .= "
" . strftime("%B %d, %Y", $post->posted) . "
";
+ $body .= "
" . run("weblogs:text:process", $post->body) . "
";
+ $body .= "
" . __gettext("From:") . " wwwroot}" . user_info("username", $post->weblog) . "\">" . user_info("name", $post->weblog) . " - ";
+ $body .= "wwwroot}" . user_info("username", $post->weblog) . "/weblog/" . $post->ident . ".html\">" . __gettext("Read more") . "
";
+ $body .= "
";
+ }
+ }
+ }
+
+ return $body;
+}
+
+function blog_summary_keyword($vars) {
+ global $CFG;
+ $body= "";
+
+ if (!isset ($vars[1])) {
+ $blog_posts= 2;
+ } else {
+ $blog_posts= $vars[1];
+ }
+
+ $where= run("users:access_level_sql_where", $_SESSION['userid']);
+
+ if (!isset ($vars[2]) || $vars[2] == "all") {
+ $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) order by posted desc limit $blog_posts");
+ } else {
+ $blog_id= (int) user_info_username('ident', $vars[2]);
+ $posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts");
+ }
+
+ if (is_array($posts) && !empty ($posts)) {
+ foreach ($posts as $post) {
+ $body .= "";
+ }
+ }
+
+ return $body;
+}
+ function blog_executive_summary_keyword($vars) {
+ global $CFG;
+ $body = "";
+
+ if (!isset($vars[1])) {
+ $blog_posts = 2;
+ } else {
+ $blog_posts = $vars[1];
+ }
+
+ $where = run("users:access_level_sql_where",$_SESSION['userid']);
+
+ if (!isset($vars[2]) || $vars[2] == "all") {
+ $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) order by posted desc limit $blog_posts");
+ } else {
+ $blog_id = (int) user_info_username('ident',$vars[2]);
+ $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts where ($where) and weblog = $blog_id order by posted desc limit $blog_posts");
+ }
+
+ if (is_array($posts) && !empty($posts)) {
+ foreach($posts as $post) {
+ $body .= "";
+ $body .= "
weblog,100,true) ."\" align=\"left\" class=\"usericon\" />
";
+ $body .= "
" . $post->title . " ";
+ $body .= "
" . strftime("%B %d, %Y",$post->posted) . "
";
+ $postbodyarray = explode(" ", preg_replace( "|\w{3,10}://[\w\.\-_]+(:\d+)?[^\s\"\'<>\(\)\{\}]*|", "", strip_tags($post->body)), 30);
+ $body .= "
" . implode(" ", array_slice($postbodyarray,0,sizeof($postbodyarray) - 1)) . " ...
";
+ $body .= "
" . __gettext("From:") . " wwwroot}" . user_info("username",$post->weblog) . "\">" . user_info("name",$post->weblog) . " - ";
+ $body .= "wwwroot}" . user_info("username",$post->weblog) . "/weblog/" . $post->ident . ".html\">" . __gettext("Read more") . "
";
+ $body .= "
";
+ }
+ }
+
+ return $body;
+ }
+
+function blog_page_owner() {
+
+ $weblog_name= optional_param('weblog_name');
+ if (!empty ($weblog_name)) {
+ return (int) user_info_username('ident', $weblog_name);
+ }
+
+}
+
+// Removes all widgets for a user
+
+function blog_user_delete($object_type, $event, $object) {
+
+ global $CFG, $data;
+ if (!empty ($object->ident) && $object_type == "user" && $event == "delete") {
+ if ($posts= get_records_sql("select * from {$CFG->prefix}weblog_posts where owner = {$object->ident} or weblog = {$object->ident}")) {
+ foreach ($posts as $post_info) {
+ $post_info= plugin_hook("weblog_post", "delete", $post_info);
+ if (!empty ($post_info)) {
+ delete_records('weblog_posts', 'ident', $post_info->ident);
+ delete_records('weblog_comments', 'post_id', $post_info->ident);
+ delete_records('weblog_watchlist', 'weblog_post', $post_info->ident);
+ delete_records('tags', 'tagtype', 'weblog', 'ref', $post_info->ident);
+ }
+ }
+ }
+ execute_sql("update {$CFG->prefix}weblog_comments set owner = -1 where owner = {$object->ident}", false);
+ delete_records('weblog_watchlist', 'owner', $object->ident);
+ }
+ return $object;
+
+}
+
+/**
+ * Function that extends the display_input_field functionality for support:
+ *
+ * the 'select' input field that receives an assosiative array as parameter
+ *
+ * @param array $parameter an array where:
+ * 0 => input name to display (for forms etc)
+ * 1 => data
+ * 2 => type of input field
+ * 3 => reference name (for tag fields and so on)
+ * 4 => ID number (if any)
+ * 5 => Owner
+ * 6 => Array()
+ *@return string the string that represent the specified input type
+ */
+function blog_display_input_field($parameter) {
+ $cleanid= $parameter[0];
+
+ switch ($parameter[2]) {
+
+ case "vertical_radio":
+ foreach($parameter[6] as $option){
+ $run_result .= " ";
+ }
+ break;
+
+ case "vertical_radio_as":
+ foreach($parameter[6] as $key=>$option){
+ $run_result .= " ";
+ }
+ break;
+
+ case "radio":
+ foreach($parameter[6] as $option){
+ $run_result .= " ";
+ foreach ($parameter[6] as $option_value => $option) {
+ $run_result .= " ";
+ foreach($parameter[6] as $option){
+ $run_result .=" ";
+ foreach($parameter[6] as $optiong => $grp){
+ $run_result .=" ";
+ foreach($grp as $option){
+ $run_result .="
+ function select_date(form){
+ var date = \"\"+form.dd.value+\"/\"+form.mm.value+\"/\"+form.aaaa.value;
+ form.$cleanid.value = date;
+ }
+ ";
+ for($i=0;$i<31;$i++){
+ $data['dd'][] = ($i+1);
+ }
+ for($i=0;$i<12;$i++){
+ $data['mm'][] = ($i+1);
+ }
+ $ya = getdate();
+ for($i=0;$i<100;$i++){
+ $data['aaaa'][] = (($ya['year']-99)+$i);
+ }
+ $i = 0;
+ foreach($data as $key=>$option){
+ $run_result .= "$key ";
+ foreach($option as $valor){
+ $run_result .=" ";
+ break;
+
+ }
+ return $run_result;
+}
+
+function blog_display_output_field($parameter){
+ $cleanid= $parameter[0];
+
+ switch ($parameter[1]) {
+ case "radio":
+ case "select":
+ case "selectg":
+ case "vertical_radio":
+ case "select_associative":
+ $run_result .= $parameter[0];
+ break;
+ }
+ return $run_result;
+
+}
+
+function blog_validate_input_field(){
+
+}
+
+/**
+ * Return extension context name
+ *
+ * @param string $name extension context
+ */
+function blog_get_extension($extension=null, $prop=null, $default=null) {
+ global $CFG;
+
+ if (!isset($extension)) {
+ // get from param
+ $extension = trim(optional_param('extension', 'weblog'));
+ }
+ if (!isset($prop)) {
+ $prop = 'name';
+ }
+
+ if ($prop == 'name') {
+ $_default = __gettext('Blog');
+ } else {
+ $_default = null;
+ }
+
+ $default = (isset($default)) ? $default : $_default;
+
+ if (isset($CFG->weblog_extensions[$extension]) &&
+ is_array($CFG->weblog_extensions[$extension]) &&
+ array_key_exists($prop,$CFG->weblog_extensions[$extension])) {
+ // get extension context
+ $type = $CFG->weblog_extensions[$extension][$prop];
+ }
+
+ return isset($type) ? $type : $default;
+}
+
+/**
+ * Returns the extension context given a weblog_post object
+ *
+ * @param object $object A weblog_post object
+ * @return string The object extension context
+ */
+function blog_get_context($object){
+ global $CFG;
+ if(empty($object->extra_value)) {
+ return "weblog";
+ }
+
+ if(!empty($CFG->weblog_extensions)){
+ foreach($CFG->weblog_extensions as $extension => $config){
+ if(array_key_exists('values',$config) && in_array($object->extra_value,$config['values'])){
+ return strtolower($extension);
+ }
+ }
+ }
+}
+
+/**
+ * Returns the context type given an weblog_post object
+ *
+ * @param object $object Weblog_post object
+ * @return string The object's extension context type
+ */
+function blog_get_context_type($object){
+ global $CFG;
+ if(empty($object->extra_value)) {
+ return __gettext("Blog post");
+ }
+
+ if(!empty($CFG->weblog_extensions)){
+ $context = blog_get_context($object);
+ if(array_key_exists('type',$CFG->weblog_extensions[$context])){
+ return $CFG->weblog_extensions[$context]['type'];
+ }
+ }
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/README
===================================================================
--- /elgg/tags/20090118/mod/blog/README (revision 33)
+++ /elgg/tags/20090118/mod/blog/README (revision 33)
@@ -0,0 +1,204 @@
+-----------------------------------------------------------
+| BLOG MODULE: Configuration options and Extension points |
+-----------------------------------------------------------
+
+Configuration Options
+=====================
+
+POSTS_PER_PAGE (default value: 10)
+ To configure the max number of posts per page in (view blog, archive, friends posts,
+ interesting posts, all posts) you can change the constant 'POSTS_PER_PAGE' in
+ 'blog/lib/weblogs_init.php'.
+
+$CFG->assign_field (default value: false)
+ To configure if you want to show a select box that allows you assign a content to any
+ of your grups
+
+Extension points
+================
+
+You can extend the blog plug-in in many ways.
+Here the explanation for the avaible extension points.
+
+Add and Edit Forms
+------------------
+
+weblogs:posts:add:fields:before
+ File(s):
+ - blog/lib/weblogs_posts_add.php
+ - blog/lib/weblogs_posts_edit.php
+ Action:
+ Allow plugins to add extra fields before the post textarea
+ and behind the 'extrafield' field
+
+weblogs:posts:add:fields:after
+ File(s):
+ - blog/lib/weblogs_posts_add.php
+ - blog/lib/weblogs_posts_edit.php
+ Action:
+ Allow plugins to add extra fields after the post textarea
+ and behind the 'keywords' field
+ Know implementations:
+ The 'posticon' plug-in
+
+weblog:posts:extrafield
+ File(s):
+ - blog/lib/weblogs_posts_add.php
+ - blog/lib/weblogs_posts_edit.php
+ Action:
+ Add the extension field (see below) if it is avaible
+ Know implementations:
+
+weblog:nocontent:description
+ File(s):
+ - blog/lib/weblogs_view.php
+ Action:
+ Allows to add a customized description for empty contents page
+ Receive the contextExtension as parameter
+ Know implementations:
+
+
+Visualization
+-------------
+
+weblogs:posts:geticon
+ File(s):
+ - blog/lib/weblogs_posts_view.php
+ Action:
+ Show the post icon
+ Know implementations:
+ The 'posticon' plug-in
+
+weblogs:posts:getname
+ File(s):
+ - blog/lib/weblogs_posts_view.php
+ Action:
+ Allow plugins to set the name on the post
+ Know implementations:
+
+weblogs:text:process
+ File(s):
+ - blog/lib/weblogs_posts_view.php
+ Action:
+ Allow plugins to set add functionality to the process of the posts text
+ Know implementations:
+ The 'files' plug-in (unit/files/weblogs_text_process.php)
+
+Extension Context
+=================
+This special feature allows to you to use the blog infraestructure to build your own plug-in.
+For example:
+ You want to build a basic 'projects' plug-in that allows people to add a 'project'
+ with the following phases: Formultating proyect, Active project, Finished project.
+
+ A easy way to build that is to modify the blog plug-in to show a field that allow
+ to select the project phase and automatically add 'Project' and ' project'
+ tags but without let the user modify them, except of course throught an specified
+ selection mechanism.
+
+To build that kind of extensions the blog plug-in add a 'extension context' mechanism
+that allows to you:
+
+ - Add an extra field to show the avaible options throught the 'weblog:posts:extrafield'
+ extension point.
+
+ - Change all the blog links without to change any code.
+ p.e int the 'projects' example the weblog plug-ins turn into:
+
+ http://yoursite/elgg/weblog/ http://yoursite/elgg/projects/
+ http://yoursite/elgg/weblog/archive http://yoursite/elgg/projects/archive
+ http://yoursite/elgg/weblog/edit http://yoursite/elgg/projects/edit
+ (...)
+
+ - Change the blog related strings without to change any code.
+ p.e. :: Blog turn into :: Projects
+
+ - Filter the list pages with the context tags.
+ p.e.:
+ For the 'projects' example the 'view projects' list doesn't show any
+ post that doesn't have the following tags:
+ 'Project', 'Formultating project', 'Active project', 'Finished project'
+
+ On another hand the normal blog list doesn't show the posts that have the
+ previous tags.
+
+Adding a extension context
+--------------------------
+
+1. In your '_init' function configure your context in the '$CFG->weblog_extensions' variable:
+ For example:
+ $CFG->weblog_extensions['projects']= array ();
+ $CFG->weblog_extensions['projects']['name']= __gettext("Projects");
+ $CFG->weblog_extensions['projects']['type']= __gettext("Project");
+ $CFG->weblog_extensions['projects']['field']= __gettext("Project type:");
+ $CFG->weblog_extensions['projects']['values']= array (__gettext("Formulating Project"), __gettext("Active Project"), __gettext("Ended Project"));
+ $CFG->weblog_extensions['projects']['icon']= $CFG->wwwroot."mod/projects/icons/images/projecticon.gif";
+
+2. Listen for the 'publish', 'republish' events
+ For example:
+ listen_for_event('weblog_post', 'publish', 'projects_new');
+ listen_for_event('weblog_post', 'republish', 'projects_new');
+
+3. Implement the callback function.
+ For example:
+ function projects_new($object_type, $event, $object) {
+ global $CFG;
+ $values = $CFG->weblog_extensions['projects']['values'];
+ if (!empty ($object->ident) && $object_type == "weblog_post" && ($event == "publish" || $event == "republish") &&
+ in_array($object->extra_value,$values)) {
+ insert_tags_from_string (__gettext("Project"), 'weblog', $object->ident, $object->access, $object->owner);
+ insert_tags_from_string ($object->extra_value, 'weblog', $object->ident, $object->access, $object->owner);
+ }
+ return $object;
+ }
+
+4. Configure the field visualization (weblog:posts:extrafield option).
+ For example:
+ $function["weblog:posts:extrafield"][] = $CFG->dirroot ."mod/projects/projects_blog_extension_view.php";
+
+ ------- the 'projects_blog_extension_view.php' file ----------
+ if(isset($parameter)){
+ $extensionContext = $parameter[0];
+ if($extensionContext=="projects"){
+ $extraField = $parameter[1];
+ $extraValue = $parameter[2];
+ $extraSelected = $parameter[3];
+
+ if(isset($extraField) && isset($extraValue)){
+ $run_result .= templates_draw(array('context'=>'databoxvertical',
+ 'name'=>$extraField,
+ 'contents'=>display_input_field(array('new_weblog_extra',$extraSelected,'vertical_radio',null,null,null,
+ $extraValue))
+ )
+ );
+ }
+ }
+ }
+
+ NOTE:
+ When the "weblog:posts:extrafield" is called it gets four parameters:
+ parameter[0] = extensionContext ('projects' in the example)
+ parameter[1] = field name ('Project type' in the example)
+ parameter[2] = field values (array(__gettext("Formulating Project"), __gettext("Active Project"), __gettext("Ended Project") in the example)
+ parameter[3] = selected value
+
+ In the display_input_field function you can use: 'select', 'radio', 'vertical_radio' for field visualization
+
+5. Add the rewrite configuration. You must to add the 'extension' parameter to all those URL to configure the context
+ For example:
+
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/?$ mod/blog/index.php?weblog_name=$1&extension=projects
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/new$ mod/blog/edit.php?weblog_name=$1&extension=projects
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/edit\/([0-9]+)$ mod/blog/edit.php?profile_name=$1&weblog_post_id=$2&action=edit&extension=projects
+ RewriteRule ^[A-Za-z0-9]+\/projects\/([0-9]+)\.html$ mod/blog/view_post.php?post=$1&extension=projects
+ RewriteRule ^[A-Za-z0-9]+\/projects\/([0-9]+)\.html.([0-9]+)$ mod/log/view_post.php?post=$1&commentpage=$2&extension=projects
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/friends\/?$ mod/blog/friends.php?weblog_name=$1&extension=projects
+ ReWriteRule ^([A-Za-z0-9]+)\/projects\/friends\/skip=([0-9]+)$ mod/blog/friends.php?weblog_name=$1&weblog_offset=$2&extension=projects
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/interesting\/?$ mod/blog/interesting.php?weblog_name=$1&extension=projects
+ ReWriteRule ^([A-Za-z0-9]+)\/projects\/interesting\/skip=([0-9]+)$ mod/blog/interesting.php?weblog_name=$1&weblog_offset=$2&extension=projects
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/archive\/?$ mod/blog/archive.php?weblog_name=$1&extension=projects
+ RewriteRule ^([A-Za-z0-9]+)\/projects\/archive\/([0-9]+)\/([0-9]+)\/?$ mod/blog/archive_month.php?weblog_name=$1&year=$2&month=$3&extension=projects
+ ReWriteRule ^projects\/everyone$ mod/blog/everyone.php?extension=projects
+ ReWriteRule ^projects\/everyone\/(people|communities|commented|uncommented)$ mod/blog/everyone.php?extension=projects&filter=$1
+ ReWriteRule ^projects\/everyone\/skip/([0-9]+)$ mod/blog/everyone.php?extension=projects&weblog_offset=$1
+
Index: /elgg/tags/20090118/mod/blog/index.php
===================================================================
--- /elgg/tags/20090118/mod/blog/index.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/index.php (revision 33)
@@ -0,0 +1,36 @@
+' . $body . '';
+
+ templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/blog/templates/blog_toolbarbutton.html
===================================================================
--- /elgg/tags/20090118/mod/blog/templates/blog_toolbarbutton.html (revision 33)
+++ /elgg/tags/20090118/mod/blog/templates/blog_toolbarbutton.html (revision 33)
@@ -0,0 +1,3 @@
+
+{{image}}
+
Index: /elgg/tags/20090118/mod/blog/templates/blog_comment.html
===================================================================
--- /elgg/tags/20090118/mod/blog/templates/blog_comment.html (revision 33)
+++ /elgg/tags/20090118/mod/blog/templates/blog_comment.html (revision 33)
@@ -0,0 +1,8 @@
+
+ {{body}}
+
+
Index: /elgg/tags/20090118/mod/blog/templates/blog_toolbar.html
===================================================================
--- /elgg/tags/20090118/mod/blog/templates/blog_toolbar.html (revision 33)
+++ /elgg/tags/20090118/mod/blog/templates/blog_toolbar.html (revision 33)
@@ -0,0 +1,3 @@
+
+{{buttons}}
+
Index: /elgg/tags/20090118/mod/blog/templates/blog_comments.html
===================================================================
--- /elgg/tags/20090118/mod/blog/templates/blog_comments.html (revision 33)
+++ /elgg/tags/20090118/mod/blog/templates/blog_comments.html (revision 33)
@@ -0,0 +1,10 @@
+
+
+
Index: /elgg/tags/20090118/mod/blog/templates/blog_post.html
===================================================================
--- /elgg/tags/20090118/mod/blog/templates/blog_post.html (revision 33)
+++ /elgg/tags/20090118/mod/blog/templates/blog_post.html (revision 33)
@@ -0,0 +1,18 @@
+
+
+
{{title}}
+
+ {{body}}
+
+
+
+ {{postedby}} {{fullname}}
+ {{links}}
+ {{commentslink}}
+
+
+ {{comments}}
+
+
Index: /elgg/tags/20090118/mod/blog/view_post.php
===================================================================
--- /elgg/tags/20090118/mod/blog/view_post.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/view_post.php (revision 33)
@@ -0,0 +1,55 @@
+weblog = -1;
+ $post->owner = -1;
+ $post->title = __gettext("Access denied or post not found");
+ $post->posted = time();
+ $post->ident = -1;
+ $post->body = __gettext("Either this blog post doesn't exist or you don't currently have access privileges to view it.");
+ }
+
+ global $page_owner;
+ global $profile_id;
+ $profile_id = $post->weblog;
+ $page_owner = $post->weblog;
+
+ $type = blog_get_extension($extensionContext, 'name');
+
+ $title = run("profile:display:name") . " :: " . $type . " :: " . stripslashes($post->title);
+ templates_page_setup();
+
+ $time = gmstrftime("%B %d, %Y",$post->posted);
+ $body = "\n";
+
+ $body .= run("weblogs:posts:view:individual",$post);
+
+ templates_page_output($title, $body);
+
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/default_template.php
===================================================================
--- /elgg/tags/20090118/mod/blog/default_template.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/default_template.php (revision 33)
@@ -0,0 +1,6 @@
+
Index: /elgg/tags/20090118/mod/blog/INSTALL
===================================================================
--- /elgg/tags/20090118/mod/blog/INSTALL (revision 33)
+++ /elgg/tags/20090118/mod/blog/INSTALL (revision 33)
@@ -0,0 +1,31 @@
+Elgg blog plug-in
+Curverider
+Initial concept: Dave Tosh and Ben Werdmuller
+Programming and development: Dave Tosh, Ben Werdmuller, Sven Edge and Diego Ramírez
+
+
+To use, the 'blog' folder must sit in the 'mod' folder of your Elgg installation.
+
+To go in .htaccess:
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/?$ mod/blog/index.php?weblog_name=$1
+ReWriteRule ^([A-Za-z0-9]+)\/weblog\/skip=([0-9]+)$ mod/blog/index.php?weblog_name=$1&weblog_offset=$2
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/edit$ mod/blog/edit.php?profile_name=$1
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/edit\/([0-9]+)$ mod/blog/edit.php?profile_name=$1&weblog_post_id=$2&action=edit
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/archive\/?$ mod/blog/archive.php?weblog_name=$1
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/archive\/([0-9]+)\/([0-9]+)\/?$ mod/blog/archive_month.php?weblog_name=$1&year=$2&month=$3
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/friends\/?$ mod/blog/friends.php?weblog_name=$1
+ReWriteRule ^([A-Za-z0-9]+)\/weblog\/friends\/skip=([0-9]+)$ mod/blog/friends.php?weblog_name=$1&weblog_offset=$2
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/interesting\/?$ mod/blog/interesting.php?weblog_name=$1
+ReWriteRule ^([A-Za-z0-9]+)\/weblog\/interesting\/skip=([0-9]+)$ mod/blog/interesting.php?weblog_name=$1&weblog_offset=$2
+RewriteRule ^[A-Za-z0-9]+\/weblog\/([0-9]+)\.html$ mod/blog/view_post.php?post=$1
+RewriteRule ^[A-Za-z0-9]+\/weblog\/([0-9]+)\.html.([0-9]+)$ mod/log/view_post.php?post=$1&commentpage=$2
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/rss\/(.+)\/?$ mod/blog/rss2.php?weblog_name=$1&tag=$2&modifier=is
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/rssnot\/(.+)\/?$ mod/blog/rss2.php?weblog_name=$1&tag=$2&modifier=not
+RewriteRule ^(([A-Za-z0-9])[A-Za-z0-9]+)\/weblog\/rss\/?$ _rss/static.php?username=$1&userref=$2&type=weblog
+RewriteRule ^([A-Za-z0-9]+)\/weblog\/category\/([^\/]+)\/?$ mod/blog/index.php?weblog_name=$1&filter=$2
+ReWriteRule ^([A-Za-z0-9]+)\/weblog\/category\/([^\/]+)\/skip=([0-9]+)$ mod/blog/index.php?weblog_name=$1&filter=$2&weblog_offset=$3
+ReWriteRule ^weblog\/everyone$ mod/blog/everyone.php
+ReWriteRule ^weblog\/everyone\/(people|communities|commented|uncommented)$ mod/blog/everyone.php?filter=$1
+ReWriteRule ^weblog\/everyone\/skip/([0-9]+)$ mod/blog/everyone.php?weblog_offset=$1
+
+
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_view.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_view.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_view.php (revision 33)
@@ -0,0 +1,116 @@
+weblog_extensions)){
+ if($extensionContext!='weblog' && array_key_exists($extensionContext,$CFG->weblog_extensions)){
+ $extraType = (array_key_exists('type',$CFG->weblog_extensions[$extensionContext]))?$CFG->weblog_extensions[$extensionContext]['type']:"";
+ $filter = $extraType;
+ }
+ //Not show the extra context contents
+ $nofilter = array();
+ foreach($CFG->weblog_extensions as $key => $value){
+ if($key!='weblog' && array_key_exists('type',$value)){
+ $nofilter[] = $value['type'];
+ }
+ if($key!='weblog' && array_key_exists('values',$value)){
+ if(is_array($value['values'])){
+ $nofilter=array_merge($value['values'],$nofilter);
+ }
+ else{
+ $nofilter[] = $value['type'];
+ }
+ }
+ }
+ $nofilter = implode(',',array_map(array($db,'qstr'),$nofilter));
+}
+
+// Get all posts in the system that we can see
+
+$where = run("users:access_level_sql_where",$_SESSION['userid']);
+if (empty($filter) && empty($nofilter)) {
+ $posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$profile_id,null,'posted DESC','*',$weblog_offset,POSTS_PER_PAGE);
+ $numberofposts = count_records_select('weblog_posts','('.$where.') AND weblog = '.$profile_id);
+}
+else if(!empty($nofilter) && empty($filter)){
+ $posts = get_records_sql("select * from ".$CFG->prefix."weblog_posts WHERE ($where) AND weblog = $profile_id AND ident not in (select distinct ref from ".$CFG->prefix."tags where tagtype='weblog' AND tag in ($nofilter)) order by posted desc limit $weblog_offset,".POSTS_PER_PAGE);
+ $numberofposts = get_record_sql("select count(*) as numberofposts from ".$CFG->prefix."weblog_posts WHERE ($where) AND weblog = $profile_id AND ident not in (select distinct ref from ".$CFG->prefix."tags where tagtype='weblog' AND tag in ($nofilter))");
+ $numberofposts = $numberofposts->numberofposts;
+}
+else {
+ $where = str_replace("access","wp.access",$where);
+ $where = str_replace("owner","wp.owner",$where);
+ $filter = (is_array($filter)) ? array_map(array($db,'qstr'),$filter):$db->qstr($filter);
+ $posts = get_records_sql("select * from ".$CFG->prefix."tags t join ".$CFG->prefix."weblog_posts wp on wp.ident = t.ref where ($where) AND t.tagtype = 'weblog' AND wp.weblog = $profile_id AND t.tag in( " . $filter . ") order by posted desc limit $weblog_offset,".POSTS_PER_PAGE);
+ $numberofposts = get_record_sql("select count(wp.ident) as numberofposts from ".$CFG->prefix."tags t join ".$CFG->prefix."weblog_posts wp on wp.ident = t.ref where ($where) AND t.tagtype = 'weblog' AND wp.weblog = $profile_id AND t.tag in (" . $filter.")");
+ $numberofposts = $numberofposts->numberofposts;
+}
+
+if (!empty($posts)) {
+
+ $lasttime = "";
+
+ foreach($posts as $post) {
+
+ $time = ucfirst(strftime("%B %d, %Y",$post->posted));
+ if ($time != $lasttime) {
+ $run_result .= "\n";
+ $lasttime = $time;
+ }
+
+ $run_result .= run("weblogs:posts:view",$post);
+
+ }
+
+ if (!empty($filter)) {
+ $filterlink = "category/".urlencode($filter)."/";
+ } else {
+ $filterlink = "";
+ }
+
+ $weblog_name = htmlspecialchars(optional_param('weblog_name'), ENT_COMPAT, 'utf-8');
+
+ if ($numberofposts - ($weblog_offset + POSTS_PER_PAGE) > 0) {
+ $display_weblog_offset = $weblog_offset + POSTS_PER_PAGE;
+ $back = __gettext("Back");
+ $run_result .= <<< END
+
+ << $back
+
+END;
+ }
+ if ($weblog_offset > 0) {
+ $display_weblog_offset = $weblog_offset - POSTS_PER_PAGE;
+ if ($display_weblog_offset < 0) {
+ $display_weblog_offset = 0;
+ }
+ $next = __gettext("Next");
+ $run_result .= <<< END
+
+ $next >>
+
+END;
+ }
+
+}
+else{
+ $type =(isset($extraType))?$extraType:$extensionContext;
+ $emptyText = "".sprintf(__gettext("There is no content in this %s yet."), strtolower($type))."
";
+ $empty = run("weblog:nocontent:description",$type);
+ $emptyText = (empty($empty))?$emptyText:$empty;
+ $run_result = $emptyText;
+}
+?>
Index: /elgg/tags/20090118/mod/blog/lib/archives_view.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/archives_view.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/archives_view.php (revision 33)
@@ -0,0 +1,98 @@
+dbtype == 'mysql') {
+ $field = 'EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(posted))';
+} elseif ($CFG->dbtype == 'postgres7') {
+ $field = 'to_char(TIMESTAMP WITH TIME ZONE \'epoch\' + posted * interval \'1 second\',\'YYYYMM\')';
+}
+$extensionContext = trim(optional_param('extension','weblog'));
+$where3="";
+if(is_array($CFG->weblog_extensions)){
+ if($extensionContext!='weblog' && array_key_exists($extensionContext,$CFG->weblog_extensions)){
+ if(array_key_exists('type',$CFG->weblog_extensions[$extensionContext])){
+ $extraType = $CFG->weblog_extensions[$extensionContext]['type'];
+ $where3 = "AND ident IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag=".$db->qstr($extraType).")";
+ }
+ }
+ else{
+ //Not show the extra context contents
+ $nofilter = array();
+ foreach($CFG->weblog_extensions as $key => $value){
+ if($key!='weblog' && array_key_exists('type',$value)){
+ $nofilter[] = $value['type'];
+ }
+ if($key!='weblog' && array_key_exists('values',$value)){
+ if(is_array($value['values'])){
+ $nofilter=array_merge($value['values'],$nofilter);
+ }
+ else{
+ $nofilter[] = $value['type'];
+ }
+ }
+ }
+ if(!empty($nofilter)){
+ $nofilter = implode(',',array_map(array($db,'qstr'),$nofilter));
+ $where3 = "AND ident not IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag in (".$nofilter."))";
+ }
+ }
+}
+
+if ($archives = get_records_sql('SELECT DISTINCT '.$field.' as archivestamp, posted
+ FROM '.$CFG->prefix.'weblog_posts wp
+ WHERE wp.weblog = ? '.$where3.' ORDER BY posted DESC',array($profile_id))) {
+
+
+// If there are any archives ...
+$archive = __gettext("Weblog Archive"); // gettext variable
+$run_result .= "";
+
+ // Get the name of the weblog user
+
+ $weblog_name = htmlspecialchars(optional_param('weblog_name'), ENT_COMPAT, 'utf-8');
+
+ // Run through them
+
+ $lastyear = 0;
+
+ foreach($archives as $archive) {
+
+ // Extract the year and the month
+
+ $year = strftime("%Y", $archive->posted);;
+ $month = strftime("%m", $archive->posted);;
+
+ if ($year != $lastyear) {
+ if ($lastyear != 0) {
+ $run_result .= "";
+ }
+ $lastyear = $year;
+ $run_result .= "";
+ $run_result .= "";
+
+ // If there are no posts to archive, say so!
+
+} else {
+ $type =(isset($extraType))?$extraType:$extensionContext;
+ $run_result = "".sprintf(__gettext("You currently don't have any %s to archive"), strtolower($type))."
";
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/function_html_activate_urls.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/function_html_activate_urls.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/function_html_activate_urls.php (revision 33)
@@ -0,0 +1,51 @@
+]*>.*?'si",
+ "']*>.*? 'si",
+ "''si",
+ "''si",
+ "'<[^>]+>'si"
+ );
+
+ foreach($url_tags as $url_tag)
+ {
+ preg_match_all($url_tag, $str, $matches, PREG_SET_ORDER);
+ foreach($matches as $match)
+ {
+ $key = "<" . md5($match[0]) . ">";
+ $search[] = $key;
+ $replace[] = $match[0];
+ }
+ }
+
+ $str = str_replace($replace, $search, $str);
+
+ // indicate where urls end if they have these trailing special chars
+ $sentinals = array("/&(quot|#34);/i", // Replace html entities
+ "/&(lt|#60);/i",
+ "/&(gt|#62);/i",
+ "/&(nbsp|#160);/i",
+ "/&(iexcl|#161);/i",
+ "/&(cent|#162);/i",
+ "/&(pound|#163);/i",
+ "/&(copy|#169);/i");
+
+ $str = preg_replace($sentinals, "\\0", $str);
+
+ // URL into links
+ $str =
+ preg_replace( "|(\w{3,10}://[\w\.\-_]+(:\d+)?[^\s\"\'<>\(\)\{\}]{0,40})[^\s\"\'<>\(\)\{\}]*|",
+ '$1 ', $str );
+
+ $str = str_replace("", '', $str);
+ $run_result = str_replace($search, $replace, $str);
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_user_info_menu.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_user_info_menu.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_user_info_menu.php (revision 33)
@@ -0,0 +1,64 @@
+";
+ $body .= "".__gettext("View your activity") . " ";
+
+ $run_result .= "";
+ $run_result .= templates_draw(array(
+ 'context' => 'sidebarholder',
+ 'title' => $title,
+ 'body' => $body,
+ )
+ );
+ $run_result .= " ";
+
+} else {
+
+ $posts = count_records_select('weblog_posts','('.run("users:access_level_sql_where",$profile_id).") and owner = $profile_id");
+
+ if (logged_on || (isset($page_owner) && $page_owner != -1)) {
+
+ $title = __gettext("Blog");
+
+ $weblog_username = user_info('username', $profile_id);
+ $body = <<< END
+
+END;
+ if (user_type($page_owner) == "person") {
+ $personalWeblog = __gettext("Personal blog");
+ $body .= <<< END
+ $personalWeblog
+END;
+ } else if (user_type($page_owner) == "community") {
+ $communityWeblog = __gettext("Community blog");
+ $body .= <<< END
+ $communityWeblog
+END;
+ }
+ $blogArchive = __gettext("Weblog Archive");
+ $friendWeblog = __gettext("Friends blog");
+ $body .= <<< END
+ $blogArchive
+ $friendWeblog
+END;
+
+ $run_result .= " ";
+ }
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_posts_edit.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_posts_edit.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_posts_edit.php (revision 33)
@@ -0,0 +1,137 @@
+weblog;
+
+$username = user_info('username', $post->weblog);
+
+//Getting the field from the context extension
+$extensionContext = trim(optional_param('extension','weblog'));
+
+if (!($aver=run("permissions:check", array("weblog:edit",$post->owner,$post->weblog)))) {
+ $messages[] = __gettext("Permission denied");
+ $messages[] = __gettext("You can modify only your own content!");
+ $redirect_url = url . user_info('username', $_SESSION['userid']) . "/$extensionContext/";
+ header_redirect($redirect_url);
+}
+
+
+$contentType = blog_get_extension($extensionContext, 'type', __gettext('Post'));
+$extraType = blog_get_extension($extensionContext, 'type');
+$extraField = blog_get_extension($extensionContext, 'field');
+$extraValue = blog_get_extension($extensionContext, 'values');
+$extraTypes = blog_get_extension($extensionContext, 'extra_type', array());
+$extraSelected = "";
+
+if(is_array($CFG->weblog_extensions) && array_key_exists($extensionContext,$CFG->weblog_extensions) && is_array($CFG->weblog_extensions[$extensionContext])){
+
+ if ($tags = get_records_select('tags',"tagtype = ? and ref = ?",array('weblog',$post->ident),'ident ASC')) {
+ $first = true;
+ foreach($tags as $key => $tag) {
+ if(is_array($extraValue) && !in_array($tag->tag,$extraValue) && trim($tag->tag)!=$extraType && !in_array($tag->tag,$extraTypes) ){
+ if (empty($first)) {
+ $keywords .= ", ";
+ }
+ $keywords .= stripslashes($tag->tag);
+ $first = false;
+ }
+ else{
+ $extraSelected=$tag->tag;
+ }
+ }
+ }
+}
+
+
+$editPost = sprintf(__gettext("Edit a %s"),$contentType);
+$postTitle = sprintf(__gettext("%s title:"),$contentType);
+$postBody = sprintf(__gettext("%s body:"),$contentType);
+$Keywords = __gettext("Keywords (Separated by commas):");
+$keywordDesc = __gettext("Keywords commonly referred to as 'Tags' are words that represent the weblog post you have just made. This will make it easier for others to search and find your posting.");
+$accessRes = __gettext("Access restrictions:"); // gettext variable
+$postButton = __gettext("Publish");
+
+
+$body = <<< END
+
+
+END;
+
+$run_result .= $body;
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_view_month.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_view_month.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_view_month.php (revision 33)
@@ -0,0 +1,80 @@
+weblog_extensions)){
+ if($extensionContext!='weblog' && array_key_exists($extensionContext,$CFG->weblog_extensions)){
+ if(array_key_exists('type',$CFG->weblog_extensions[$extensionContext])){
+ $extraType = $CFG->weblog_extensions[$extensionContext]['type'];
+ $where2 = "AND ident IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag=".$db->qstr($extraType).")";
+ }
+ }
+ else{
+ //Not show the extra context contents
+ $nofilter = array();
+ foreach($CFG->weblog_extensions as $key => $value){
+ if($key!='weblog' && array_key_exists('type',$value)){
+ $nofilter[] = $value['type'];
+ }
+ if($key!='weblog' && array_key_exists('values',$value)){
+ if(is_array($value['values'])){
+ $nofilter=array_merge($value['values'],$nofilter);
+ }
+ else{
+ $nofilter[] = $value['type'];
+ }
+ }
+ }
+ if(!empty($nofilter)){
+ $nofilter = implode(',',array_map(array($db,'qstr'),$nofilter));
+ $where2 = "AND ident not IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag in (".$nofilter."))";
+ }
+ }
+}
+
+$posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$profile_id ." $where2
+ AND posted >= ".mktime(0,0,0,$month,1,$year)."
+ AND posted < ".mktime(0,0,0,($month + 1), 1, $year),
+ null,'posted ASC');
+
+if (!empty($posts)) {
+
+ $lasttime = "";
+
+ $run_result .= "\n";
+
+ foreach($posts as $post) {
+
+ $time = ucfirst(strftime("%B %d, %Y", $post->posted));
+ if ($time != $lasttime) {
+ $run_result .= "\n";
+ $lasttime = $time;
+ }
+
+ $run_result .= run("weblogs:posts:view",$post);
+
+ }
+
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/function_search_rss.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/function_search_rss.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/function_search_rss.php (revision 33)
@@ -0,0 +1,33 @@
+qstr($parameter[1]) . "";
+ $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ") and " . $searchline;
+ $searchline = str_replace("access", "wp.access", $searchline);
+ $searchline = str_replace("owner", "wp.weblog", $searchline);
+ if ($refs = get_records_sql('SELECT wp.ident,wp.owner,wp.weblog,wp.ident,wp.title,u.name,t.ref FROM '.$CFG->prefix.'tags t
+ JOIN '.$CFG->prefix.'weblog_posts wp ON wp.ident = t.ref
+ JOIN '.$CFG->prefix.'users u ON u.ident = t.owner
+ WHERE ('.$searchline.') ORDER BY wp.posted DESC LIMIT 50')) {
+ foreach($refs as $post) {
+ $run_result .= "\t- \n";
+ $run_result .= "\t\t
name));
+ if ($post->title != "") {
+ $run_result .= " :: " . (stripslashes($post->title));
+ }
+ $weblogusername = user_info('username', $post->weblog);
+ $run_result .= "]]> \n";
+ $run_result .= "\t\t " . url . $weblogusername . "/weblog/" . $post->ident . ".html\n";
+ $run_result .= "\t \n";
+ }
+ }
+
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/groups_delete.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/groups_delete.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/groups_delete.php (revision 33)
@@ -0,0 +1,20 @@
+ident);
+
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_posts_add.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_posts_add.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_posts_add.php (revision 33)
@@ -0,0 +1,127 @@
+
+
+ $addPost
+
+END;
+
+ if(isset($CFG->assign_field) && $CFG->assign_field){
+ $body .= run("weblogs:assign:field");
+ }
+
+ $body .= templates_draw(array(
+ 'context' => 'databoxvertical',
+ 'name' => $postTitle,
+ 'contents' => display_input_field(array("new_weblog_title",$contentTitle,"text"))
+ )
+ );
+
+ // Add the extension field if it is avaible
+ $body .= run("weblog:posts:extrafield",array($extensionContext,$extraField, $extraValue));
+
+ // Add the fields before the post textarea
+ //$body .= run("weblogs:posts:add:fields:before",$_SESSION['userid']);
+ $body .= run("weblogs:posts:add:fields:before",$page_owner);
+
+ // Add the weblog toolbar
+ $buttons = run("display:content:toolbar");
+ if(!empty($buttons)){
+ $body.=$buttons;
+ }
+
+
+ $body .= templates_draw(array(
+ 'context' => 'databoxvertical',
+ 'name' => $postBody,
+ 'contents' => display_input_field(array("new_weblog_post",$contentBody,"weblogtext"))
+ )
+ );
+
+ // Add the fields after the post textarea
+ //$body .= run("weblogs:posts:add:fields:after",$_SESSION['userid']);
+ $body .= run("weblogs:posts:add:fields:after",$page_owner);
+
+
+ $body .= templates_draw(array(
+ 'context' => 'databox',
+ 'name' => $Keywords,
+ 'column1' => "$keywordDesc ",
+ 'column2' => display_input_field(array("new_weblog_keywords","","keywords","weblog"))
+ )
+ );
+
+ $body .= templates_draw(array(
+ 'context' => 'databoxvertical',
+ 'name' => $accessRes,
+ 'contents' => run("display:access_level_select",array("new_weblog_access",default_access))
+ )
+ );
+
+ $body .= <<< END
+
+
+
+
+
+
+
+END;
+
+ } else {
+
+ $body = '';
+ $run_result .= "" . __gettext("You must be logged in to post a new entry. You may do so using the login pane to the right of the screen.") . "
";
+
+ }
+
+ $run_result .= $body;
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/function_rss_publish.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/function_rss_publish.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/function_rss_publish.php (revision 33)
@@ -0,0 +1,84 @@
+dirroot.'lib/uploadlib.php');
+/*
+ * Function to publish weblog posts as RSS, either a static file or return output
+ *
+ * $parameter[0] is the numeric id of the user to publish
+ *
+ * $parameter[1] is true to return a string of RSS, or false to publish static file.
+ * (Defaults to publishing file)
+ *
+ */
+
+ $run_result = false;
+
+ if (isset($parameter) && is_array($parameter)) {
+
+ $userid = (int) $parameter[0];
+ if ($userid > 0) {
+ $username = user_info('username', $userid);
+ }
+ if ($username) {
+
+ // make output dirs if they don't already exist
+ $publish_folder = substr($username,0,1);
+
+ $publish_folder = "rss/" . $publish_folder . "/" . $username ;
+
+ make_upload_directory($publish_folder,false);
+
+ $rssfile = $CFG->dataroot.$publish_folder.'/weblog.xml';
+
+ //generate rss
+ $sitename = sitename;
+ $rssweblog = __gettext("Weblog");
+
+ $info = get_record('users','ident',$userid);
+ $name = stripslashes(user_name($info->ident));
+ $username = $info->username;
+ $mainurl = $CFG->wwwroot . $username . "/weblog/";
+ $rssurl = $mainurl . "rss/";
+ $rssdescription = sprintf(__gettext("The weblog for %s, hosted on %s."),$name,$sitename);
+ $output = <<< END
+
+
+
+
+
+ Elgg
+ $mainurl
+END;
+
+ // WEBLOGS
+ $output .= run("weblogs:rss:getitems", array($userid, 10, ""));
+ $output .= <<< END
+
+
+
+END;
+
+ if ($parameter[1] === true) {
+
+ $run_result = $output;
+
+ } else {
+
+ // write to file
+ if ($handle = fopen($rssfile, "wb")) {
+ $writeresult = fwrite($handle, $output);
+ $closeresult = fclose($handle);
+ if ($writeresult && $closeresult) {
+ $run_result = true;
+ }
+ } else {
+ error_log("failed to open $rssfile for writing!");
+ }
+
+ }
+
+ } // if ($username)
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_text_process.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_text_process.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_text_process.php (revision 33)
@@ -0,0 +1,62 @@
+s and force escaping if necessary
+ $numlt = substr_count($run_result, "<");
+ $numgt = substr_count($run_result, ">");
+ if ($numlt != $numgt) {
+ $run_result = htmlspecialchars($run_result, ENT_COMPAT, 'utf-8');
+ }
+
+ if(run("video:text:process",$run_result)!=null){
+ $run_result = run("video:text:process",$run_result);
+ }
+
+ // URLs to links
+ $run_result = run("weblogs:html_activate_urls", $run_result);
+
+ // Remove the evil font tag
+ $run_result = preg_replace("/]*>/i","",$run_result);
+ $run_result = preg_replace("/<\/font>/i","",$run_result);
+
+ // add rel="nofollow" to any links
+ if ($addrelnofollow) {
+ $run_result = preg_replace('/]*)\s+rel=/i', '
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_all_users_view.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_all_users_view.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_all_users_view.php (revision 33)
@@ -0,0 +1,171 @@
+created > 60)) {
+// $_SESSION['friends_posts_cache']->created = time();
+// $_SESSION['friends_posts_cache']->data = get_records_select('weblog_posts','('.$where1. ') AND ('.$where2.')',null,'posted DESC','*',$weblog_offset,25);
+// }
+// $posts = $_SESSION['friends_posts_cache']->data;
+
+$extensionContext = trim(optional_param('extension','weblog'));
+if(is_array($CFG->weblog_extensions)){
+ if($extensionContext!='weblog' && array_key_exists($extensionContext,$CFG->weblog_extensions)){
+ if(array_key_exists('type',$CFG->weblog_extensions[$extensionContext])){
+ $extraType = $CFG->weblog_extensions[$extensionContext]['type'];
+ $where3 = "AND ident IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag=".$db->qstr($extraType).")";
+ }
+ }
+ else{
+ //Not show the extra context contents
+ $nofilter = array();
+ foreach($CFG->weblog_extensions as $key => $value){
+ if($key!='weblog' && array_key_exists('type',$value)){
+ $nofilter[] = $value['type'];
+ }
+ if($key!='weblog' && array_key_exists('values',$value)){
+ if(is_array($value['values'])){
+ $nofilter=array_merge($value['values'],$nofilter);
+ }
+ else{
+ $nofilter[] = $value['type'];
+ }
+ }
+ }
+ if(!empty($nofilter)){
+ $nofilter = implode(',',array_map(array($db,'qstr'),$nofilter));
+ $where3 = "AND ident not IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag in (".$nofilter."))";
+ }
+ }
+ $where1 = '('.$where1.') ' . $where3;
+}
+
+$removefilter = ' ( ' . __gettext("Remove filter") . ' )';
+
+switch ($view_filter) {
+ case "people":
+ $where1 = '(' . $where1 . ') AND owner = weblog';
+ $run_result .= '' . __gettext("Filtered: Showing personal blog posts") . $removefilter . '
';
+ break;
+ case "communities":
+ $where1 = '(' . $where1 . ') AND owner != weblog';
+ $run_result .= '' . __gettext("Filtered: Showing community blog posts") . $removefilter . '
';
+ break;
+ case "commented":
+ //a join would be better, but doesn't work with users:access_level_sql_where anyway - sven
+ $where1 = '(' . $where1 . ') AND (SELECT COUNT(ident) FROM ' . $CFG->prefix . 'weblog_comments WHERE post_id = ' . $CFG->prefix . 'weblog_posts.ident) > 0';
+ $run_result .= '' . __gettext("Filtered: Showing posts with comments") . $removefilter . '
';
+ break;
+ case "uncommented":
+ $where1 = '(' . $where1 . ') AND (SELECT COUNT(ident) FROM ' . $CFG->prefix . 'weblog_comments WHERE post_id = ' . $CFG->prefix . 'weblog_posts.ident) = 0';
+ $run_result .= '' . __gettext("Filtered: Showing posts with no comments") . $removefilter . '
';
+ break;
+ case "date":
+ //expect a YYYYMMDD value
+ $view_filter_value = (int) $view_filter_value;
+ $view_filter = '';
+ if (strlen($view_filter_value) == 8) {
+ $year = substr($view_filter_value, 0, 4);
+ $month = substr($view_filter_value, 4, 2);
+ $day = substr($view_filter_value, 6, 2);
+ $start = gmmktime(0,0,0, $month, $day, $year);
+ $end = gmmktime(0,0,0, $month, $day + 1, $year);
+ if ($start && $end) {
+ $where1 = '(' . $where1 . ') AND (posted BETWEEN ' . $start . ' AND ' . $end . ')';
+ $nicedate = gmstrftime("%B %d, %Y", $start);
+ $run_result .= '' . __gettext("Filtered: Showing posts from ") . $nicedate . $removefilter . '
';
+ $view_filter = 'date';
+ }
+ }
+ break;
+ case "tag":
+ if ($view_filter_value ) {
+ $sql_filter_value = $db->qstr($view_filter_value); // adodb's escaping + quote-surrounding function
+ $html_filter_value = htmlspecialchars($view_filter_value);
+ $where1 = '(' . $where1 . ') AND ident IN (SELECT ref FROM ' . $CFG->prefix . 'tags WHERE tag =' . $sql_filter_value . ' AND tagtype = "weblog")';
+ $run_result .= '' . __gettext("Filtered: Showing posts tagged with ") . '"' . $html_filter_value . '"' . $removefilter . '
';
+ }
+ break;
+ default:
+ $view_filter = '';
+ break;
+}
+error_log($where1);
+
+$posts = get_records_select('weblog_posts', $where1, null, 'posted DESC', '*', $weblog_offset, POSTS_PER_PAGE);
+$numberofposts = count_records_select('weblog_posts', $where1);
+
+if (!empty($posts)) {
+
+ $lasttime = "";
+
+ foreach($posts as $post) {
+
+ $time = ucfirst(gmstrftime("%B %d, %Y",$post->posted));
+ if ($time != $lasttime) {
+ $run_result .= "\n";
+ $lasttime = $time;
+ }
+
+ $run_result .= run("weblogs:posts:view",$post);
+
+ }
+
+ $weblog_name = htmlspecialchars(optional_param('weblog_name'), ENT_COMPAT, 'utf-8');
+
+ if ($view_filter) {
+ $filterurl = '&filter=' . urlencode($view_filter);
+ if ($view_filter_value) {
+ $filterurl .= '&filtervalue=' . urlencode($view_filter_value);
+ }
+ } else {
+ $filterurl = '';
+ }
+
+ if ($numberofposts - ($weblog_offset + POSTS_PER_PAGE) > 0) {
+ $display_weblog_offset = $weblog_offset + POSTS_PER_PAGE;
+ $back = __gettext("Back"); // gettext variable
+ $run_result .= <<< END
+
+ << $back
+
+
+END;
+ }
+ if ($weblog_offset > 0) {
+ $display_weblog_offset = $weblog_offset - POSTS_PER_PAGE;
+ if ($display_weblog_offset < 0) {
+ $display_weblog_offset = 0;
+ }
+ $next = __gettext("Next"); // gettext variable
+ $run_result .= <<< END
+
+ $next >>
+
+
+END;
+ }
+
+}
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_friends_view.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_friends_view.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_friends_view.php (revision 33)
@@ -0,0 +1,128 @@
+user_id;
+ $first=false;
+ }
+}
+$where2 .= ")";
+
+//Getting the field from the context extension
+$extensionContext = trim(optional_param('extension','weblog'));
+
+$where3 = "";
+if(is_array($CFG->weblog_extensions)){
+ if($extensionContext!='weblog' && array_key_exists($extensionContext,$CFG->weblog_extensions)){
+ if(array_key_exists('type',$CFG->weblog_extensions[$extensionContext])){
+ $extraType = $CFG->weblog_extensions[$extensionContext]['type'];
+ $where3 = "AND ident IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag=".$db->qstr($extraType).")";
+ }
+ }
+ else{
+ //Not show the extra context contents
+ $nofilter = array();
+ foreach($CFG->weblog_extensions as $key => $value){
+ if($key!='weblog' && array_key_exists('type',$value)){
+ $nofilter[] = $value['type'];
+ }
+ if($key!='weblog' && array_key_exists('values',$value)){
+ if(is_array($value['values'])){
+ $nofilter=array_merge($value['values'],$nofilter);
+ }
+ else{
+ $nofilter[] = $value['type'];
+ }
+ }
+ }
+ if(!empty($nofilter)){
+ $nofilter = implode(',',array_map(array($db,'qstr'),$nofilter));
+ $where3 = "AND ident not IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag in (".$nofilter."))";
+ }
+ }
+}
+
+$where1 = run("users:access_level_sql_where",$_SESSION['userid']);
+// if (!isset($_SESSION['friends_posts_cache']) || (time() - $_SESSION['friends_posts_cache']->created > 60)) {
+// $_SESSION['friends_posts_cache']->created = time();
+// $_SESSION['friends_posts_cache']->data = get_records_select('weblog_posts','('.$where1.') AND ('.$where2.')',null,'posted DESC','*',$weblog_offset,25);
+// }
+// $posts = $_SESSION['friends_posts_cache']->data;
+error_log('('.$where1.') AND ('.$where2.') '.$where3);
+$posts = get_records_select('weblog_posts','('.$where1.') AND ('.$where2.') '.$where3,null,'posted DESC','*',$weblog_offset,POSTS_PER_PAGE);
+$numberofposts = count_records_select('weblog_posts','('.$where1.') AND ('.$where2.') ' .$where3);
+if (!empty($posts)) {
+
+ $lasttime = "";
+
+ foreach($posts as $post) {
+
+ $time = gmstrftime("%B %d, %Y",$post->posted);
+ if ($time != $lasttime) {
+ $run_result .= "\n";
+ $lasttime = $time;
+ }
+
+ $run_result .= run("weblogs:posts:view",$post);
+
+ }
+
+ $weblog_name = htmlspecialchars(optional_param('weblog_name'), ENT_COMPAT, 'utf-8');
+
+ if ($numberofposts - ($weblog_offset + POSTS_PER_PAGE) > 0) {
+ $display_weblog_offset = $weblog_offset + POSTS_PER_PAGE;
+ $back = __gettext("Back"); // gettext variable
+ $run_result .= <<< END
+
+ << $back
+
+
+END;
+ }
+ if ($weblog_offset > 0) {
+ $display_weblog_offset = $weblog_offset - POSTS_PER_PAGE;
+ if ($display_weblog_offset < 0) {
+ $display_weblog_offset = 0;
+ }
+ $next = __gettext("Next"); // gettext variable
+ $run_result .= <<< END
+
+ $next >>
+
+END;
+ }
+
+}
+else{
+ $type =(isset($extraType))?$extraType:$extensionContext;
+ $run_result = "".sprintf(__gettext("Your friends currently don't have any %s"), strtolower($type))."
";
+}
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_interesting_view.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_interesting_view.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_interesting_view.php (revision 33)
@@ -0,0 +1,114 @@
+weblog_post;
+ }
+} else {
+ $where2 .= "''";
+}
+$where2 = "ident IN (" . $where2 . ")";
+
+//Getting the field from the context extension
+$extensionContext = trim(optional_param('extension','weblog'));
+
+$where3="";
+if(is_array($CFG->weblog_extensions)){
+ if($extensionContext!='weblog' && array_key_exists($extensionContext,$CFG->weblog_extensions)){
+ if(array_key_exists('type',$CFG->weblog_extensions[$extensionContext])){
+ $extraType = $CFG->weblog_extensions[$extensionContext]['type'];
+ $where3 = "AND ident IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag=".$db->qstr($extraType).")";
+ }
+ }
+ else{
+ //Not show the extra context contents
+ $nofilter = array();
+ foreach($CFG->weblog_extensions as $key => $value){
+ if($key!='weblog' && array_key_exists('type',$value)){
+ $nofilter[] = $value['type'];
+ }
+ if($key!='weblog' && array_key_exists('values',$value)){
+ if(is_array($value['values'])){
+ $nofilter=array_merge($value['values'],$nofilter);
+ }
+ else{
+ $nofilter[] = $value['type'];
+ }
+ }
+ }
+ if(!empty($nofilter)){
+ $nofilter = implode(',',array_map(array($db,'qstr'),$nofilter));
+ $where3 = "AND ident not IN(select ref FROM ".$CFG->prefix."tags WHERE tagtype='weblog' AND tag in (".$nofilter."))";
+ }
+ }
+}
+
+$where1 = run("users:access_level_sql_where",$_SESSION['userid']);
+$posts = get_records_select('weblog_posts','('.$where1.') AND ('.$where2.') '.$where3,null,'posted DESC','*',$weblog_offset,POSTS_PER_PAGE);
+$numberofposts = count_records_select('weblog_posts','('.$where1.') AND ('.$where2.') '.$where3);
+if (!empty($posts)) {
+
+ $lasttime = "";
+
+ foreach($posts as $post) {
+
+ $time = gmstrftime("%B %d, %Y",$post->posted);
+ if ($time != $lasttime) {
+ $run_result .= "\n";
+ $lasttime = $time;
+ }
+
+ $run_result .= run("weblogs:posts:view",$post);
+
+ }
+
+ $weblog_name = htmlspecialchars(optional_param('weblog_name'), ENT_COMPAT, 'utf-8');
+
+ if ($numberofposts - ($weblog_offset + POSTS_PER_PAGE) > 0) {
+ $display_weblog_offset = $weblog_offset + POSTS_PER_PAGE;
+ $back = __gettext("Back"); // gettext variable
+ $run_result .= <<< END
+
+ << $back
+
+END;
+ }
+ if ($weblog_offset > 0) {
+ $display_weblog_offset = $weblog_offset - POSTS_PER_PAGE;
+ if ($display_weblog_offset < 0) {
+ $display_weblog_offset = 0;
+ }
+ $next = __gettext("Next"); // gettext variable
+ $run_result .= <<< END
+
+ $next >>
+
+END;
+ }
+
+}
+else{
+ $type =(isset($extraType))?$extraType:$extensionContext;
+ $run_result = "".sprintf(__gettext("You haven't marked any %s as interesting "), strtolower($type))."
";
+}
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_edit.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_edit.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_edit.php (revision 33)
@@ -0,0 +1,20 @@
+
Index: /elgg/tags/20090118/mod/blog/lib/permissions_check.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/permissions_check.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/permissions_check.php (revision 33)
@@ -0,0 +1,33 @@
+owner
+ if (is_array($parameter) && $parameter[0] == "weblog:edit") {
+ if ($parameter[1] == $_SESSION['userid'] && logged_on && user_info("user_type",$profile_id) != "external") {
+ $run_result = true;
+ }
+ }
+ }
+?>
Index: /elgg/tags/20090118/mod/blog/lib/display_interesting_post_form.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/display_interesting_post_form.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/display_interesting_post_form.php (revision 33)
@@ -0,0 +1,41 @@
+ ";
+ $run_result .= "";
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_assign_field.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_assign_field.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_assign_field.php (revision 33)
@@ -0,0 +1,48 @@
+
+ * @copyright Corporación Somos más - 2007
+ */
+
+global $page_owner, $USER, $CFG;
+
+if (isset ($parameter)) {
+ $selected = $page_owner;
+ $field_label = __gettext("Assign to:");
+ $options = array ();
+
+ $options[$USER->ident] = __gettext("Own");
+ if ($communities = get_records_select('users', 'owner = ? AND user_type = ?', array ($USER->ident,'community'))) {
+ foreach ($communities as $community) {
+ $options[$community->ident] = __gettext("Community") . ": " . $community->name;
+ }
+ }
+
+ if ($communities = get_records_sql("SELECT u.* FROM " . $CFG->prefix . "friends f
+ JOIN " . $CFG->prefix . 'users u ON u.ident = f.friend
+ WHERE u.user_type = ? AND u.owner <> ? AND f.owner = ?', array ('community',$USER->ident,$USER->ident))) {
+ foreach ($communities as $community) {
+ $options[$community->ident] = __gettext("Community") . ": " . $community->name;
+ }
+ }
+
+ if ($selected == $USER->ident && count($options)>1) {
+ $run_result .= templates_draw(array (
+ 'context' => 'databoxvertical',
+ 'name' => $field_label,
+ 'contents' => display_input_field(array (
+ 'assign_to',
+ $selected,
+ 'select_associative',
+ null,
+ null,
+ null,
+ $options
+ )
+ )));
+ }
+
+}
+?>
Index: /elgg/tags/20090118/mod/blog/lib/function_search.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/function_search.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/function_search.php (revision 33)
@@ -0,0 +1,123 @@
+returned_items) && $PAGE->returned_items == "accounts") {
+ $handle = 0;
+}
+
+if ((isset($parameter) && $parameter[0] == "weblog" || $parameter[0] == "weblogall") && $handle) {
+
+ if ($parameter[0] == "weblog") {
+ $search_exclusions[] = "weblogall";
+ $owner = optional_param('owner',0,PARAM_INT);
+ $searchline = "tagtype = 'weblog' AND owner = $owner AND tag = " . $db->qstr($parameter[1]) . "";
+ $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ") AND " . $searchline;
+ $searchline = str_replace("owner","t.owner",$searchline);
+ if ($refs = get_records_select('tags t',$searchline)) {
+ $searchline = "";
+ foreach($refs as $ref) {
+ if ($searchline != "") {
+ $searchline .= ",";
+ }
+ $searchline .= $ref->ref;
+ }
+ $searchline = " wp.ident in (" . $searchline . ")";
+ if (!empty($PAGE->search_type_unformatted)) {
+ $searchline .= " AND p.user_type = " . $PAGE->search_type;
+ }
+ if (!$posts = get_records_sql('SELECT wp.ident,u.name,u.username,u.ident as userid, wp.title, wp.ident, wp.weblog, wp.owner, wp.posted
+ FROM '.$CFG->prefix.'weblog_posts wp JOIN '.$CFG->prefix.'users u ON u.ident = wp.owner
+ JOIN '.$CFG->prefix.'users p on p.ident = wp.weblog
+ WHERE ('.$searchline.') ORDER BY posted DESC')) {
+ $posts = array(); // avoid warnings
+ }
+ // TODO I don't like this, but I can't understand why it's there, so I'm leaving it.
+ $name = '';
+ $username = '';
+ if (count($posts) >= 1) {
+ $keys = array_keys($posts);
+ $p = $posts[$keys[0]];
+ if (!empty($p)) {
+ // $name = stripslashes($p->name);
+ $name = run("profile:display:name",$p->userid);
+ $username = $p->username;
+ }
+ }
+ $run_result .= "$weblogPosted " . $name . " $inCategory '".$parameter[1]."' \n";
+ $run_result .= "[ $rssForBlog " . $name . " $inCategory '".$parameter[1]."' ]
\n";
+ }
+ } else {
+ $icon = "default.png";
+ }
+ $searchline = "tagtype = 'weblog' and tag = " . $db->qstr($parameter[1]) . "";
+ $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ") AND " . $searchline;
+ $searchline = str_replace("owner","t.owner",$searchline);
+ if (!empty($PAGE->search_type_unformatted)) {
+ $searchline .= " AND u.user_type = " . $PAGE->search_type;
+ }
+ $sql = "SELECT DISTINCT u.* FROM ".$CFG->prefix.'tags t JOIN '.$CFG->prefix.'users u ON u.ident = t.owner WHERE ('.$searchline.')';
+ if ($parameter[0] == "weblog") {
+ $sql .= " and u.ident != " . $owner;
+ }
+ if ($users = get_records_sql($sql)) {
+ if ($parameter[0] == "weblog") {
+ $run_result .= "$otherUsers '".$parameter[1]."' \n";
+ } else {
+ $run_result .= "$otherUsers2 '".$parameter[1]."' \n";
+ }
+ $body = "";
+ $i = 1;
+ $w = 100;
+ if (sizeof($users) > 4) {
+ $w = 50;
+ }
+ foreach($users as $key => $info) {
+ $friends_userid = $info->ident;
+ $friends_name = user_name($info->ident);
+ $info->icon = run("icons:get",$info->ident);
+ $friends_menu = run("users:infobox:menu",array($info->ident));
+ $link_keyword = urlencode($parameter[1]);
+ $friends_icon = user_icon_html($info->ident,$w);
+ $body .= <<< END
+
+
+
+ {$friends_icon}
+
+ {$friends_name}
+ {$friends_menu}
+
+
+
+END;
+ if ($i % 5 == 0) {
+ $body .= "\n \n";
+ }
+ $i++;
+ }
+ $body .= "
";
+ $run_result .= $body;
+ }
+
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/function_rss_getitems.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/function_rss_getitems.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/function_rss_getitems.php (revision 33)
@@ -0,0 +1,82 @@
+ 0) {
+ // $username = user_info('username', $userid);
+ //}
+ // if ($username) {
+
+ $numrows = (int) $parameter[1];
+ if (!$numrows) {
+ $numrows = 10;
+ }
+
+ $tag = trim($parameter[2]);
+ if (isset($parameter[3]) && $parameter[3] == "not") {
+ $entries = get_records_sql('SELECT wp.*, u.username FROM '.$CFG->prefix.'weblog_posts wp JOIN '.$CFG->prefix.'users u ON u.ident = wp.weblog
+ WHERE wp.weblog = ? AND wp.access = ?
+ AND (SELECT count(ident) FROM '.$CFG->prefix.'tags t WHERE t.tagtype = ? AND t.tag = ? AND t.ref = wp.ident) = ?
+ ORDER BY wp.posted DESC LIMIT '.$numrows,array($userid,'PUBLIC','weblog',$tag,0));
+ } else if (isset($parameter[3]) && $parameter[3] == "all") {
+ $entries = get_records_sql('SELECT wp.*, u.username FROM '.$CFG->prefix.'weblog_posts wp JOIN '.$CFG->prefix.'users u ON u.ident = wp.weblog WHERE wp.access = ?
+ AND (SELECT count(ident) FROM '.$CFG->prefix.'tags t WHERE t.tagtype = ? AND t.tag = ? AND t.ref = wp.ident) = ?
+ ORDER BY wp.posted DESC LIMIT '.$numrows,array('PUBLIC','weblog',$tag,0));
+ } else if ($tag) {
+ $entries = get_records_sql('SELECT wp.*, u.username FROM '.$CFG->prefix.'tags t JOIN '.$CFG->prefix.'weblog_posts wp ON wp.ident = t.ref
+ JOIN '.$CFG->prefix.'users u on u.ident = wp.weblog
+ WHERE wp.weblog = ? AND wp.access = ? AND t.tag = ? AND t.tagtype = ?
+ ORDER BY wp.posted DESC limit '.$numrows,array($userid,'PUBLIC',$tag,'weblog'));
+ } else {
+ // $entries = get_records_select('weblog_posts','weblog = ? AND access = ?',array($userid,'PUBLIC'),'posted DESC','*',0,$numrows);
+ $entries = get_records_sql('SELECT wp.*, u.username FROM '.$CFG->prefix.'weblog_posts wp JOIN '.$CFG->prefix.'users u ON u.ident = wp.weblog
+ WHERE wp.weblog = ? AND wp.access = ?
+ ORDER BY wp.posted DESC LIMIT '.$numrows, array($userid, 'PUBLIC'));
+
+ }
+
+ if (is_array($entries) && sizeof($entries) > 0) {
+ foreach($entries as $entry) {
+ $title = (stripslashes($entry->title));
+ $link = url . $entry->username . "/weblog/" . $entry->ident . ".html";
+ $body = (run("weblogs:text:process",stripslashes($entry->body)));
+ $pubdate = gmdate("D, d M Y H:i:s T", $entry->posted);
+ $keywordtags = "";
+ if ($keywords = get_records_select('tags','tagtype = ? AND ref = ?',array('weblog',$entry->ident))) {
+ foreach($keywords as $keyword) {
+ $keywordtags .= "\n\t\ttag)) . "]]> ";
+ }
+ }
+ $run_result .= <<< END
+
+ -
+
+ $link
+ $link
+ $pubdate $keywordtags
+
+
+
+END;
+ }
+ } else {
+ //$run_result .= "no items";
+ }
+
+ // } // if ($username)
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_comments_add.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_comments_add.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_comments_add.php (revision 33)
@@ -0,0 +1,71 @@
+
+
+ $addComment
+
+END;
+
+ $field = display_input_field(array("new_weblog_comment","","longtext"));
+ if (logged_on) {
+ $userid = $_SESSION['userid'];
+ } else {
+ $userid = -1;
+ }
+ $field .= <<< END
+
+
+
+
+
+END;
+
+ $run_result .= templates_draw(array(
+
+ 'context' => 'databox1',
+ 'name' => __gettext("Your comment text"),
+ 'column1' => $field
+
+ )
+ );
+
+ if (logged_on) {
+ $comment_name = $_SESSION['name'];
+ } else {
+ $comment_name = __gettext("Guest");
+ }
+
+ $run_result .= templates_draw(array(
+
+ 'context' => 'databox1',
+ 'name' => __gettext("Your name"),
+ 'column1' => " "
+
+ )
+ );
+
+ $run_result .= templates_draw(array(
+
+ 'context' => 'databox1',
+ 'name' => ' ',
+ 'column1' => " "
+
+ )
+ );
+
+ $run_result .= <<< END
+
+
+
+END;
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_actions.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_actions.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_actions.php (revision 33)
@@ -0,0 +1,252 @@
+title = trim(optional_param('new_weblog_title'));
+ $post->body = trim(optional_param('new_weblog_post'));
+ $post->access = trim(optional_param('new_weblog_access'));
+ $post->icon = optional_param('new_weblog_icon',user_info("icon",$_SESSION['userid']),PARAM_INT);
+ if (logged_on && !empty($post->body) && !empty($post->access) && run("permissions:check", "weblog")) {
+
+ $post->posted = time();
+ $post->owner = $USER->ident;
+ $post->weblog = $page_owner;
+ if(isset($CFG->assign_field) && $CFG->assign_field){
+ $assigned = optional_param('assign_to',null,PARAM_INT);
+ if(!empty($assigned)){
+ $post->weblog = $assigned;
+ }
+ }
+
+ $post = plugin_hook("weblog_post","create",$post);
+
+ if (!empty($post)) {
+ $insert_id = insert_record('weblog_posts',$post);
+ $post->ident = $insert_id;
+ $value = trim(optional_param('new_weblog_keywords'));
+ insert_tags_from_string ($value, 'weblog', $insert_id, $post->access, $post->owner);
+
+ $extra_value = trim(optional_param('new_weblog_extra'));
+ $post->extra_value = $extra_value;
+
+ $post = plugin_hook("weblog_post","publish",$post);
+ $rssresult = run("weblogs:rss:publish", array($page_owner, false));
+ $rssresult = run("profile:rss:publish", array($page_owner, false));
+ $type = strtolower(blog_get_extension($extensionContext, 'type', 'post'));
+
+ // redirect to post view
+ define('redirect_url', url.user_info('username', $post->weblog)."/{$extensionContext}/{$post->ident}.html");
+ if (user_type($post->weblog) == "person") {
+ $messages[] = sprintf(__gettext("Your %s has been added."),$type);
+ }
+ else{
+ $messages[] = sprintf(__gettext("Your %s has been added to the %s group."),$type,user_info("name",$post->weblog));
+ }
+ } else {
+ define('redirect_url', url.user_info('username', $post->weblog)."/{$extensionContext}/");
+ }
+ } else {
+ $messages[] = __gettext("Your post wasn't added to the blog. This was probably because it was empty, or you don't currently have permission to post in this blog.");
+ }
+ break;
+
+ // Edit a weblog post
+ case "weblogs:post:edit":
+ $post = new StdClass;
+ $post->title = trim(optional_param('edit_weblog_title'));
+ $post->body = trim(optional_param('new_weblog_post'));
+ $post->access = trim(optional_param('edit_weblog_access'));
+ $post->icon = optional_param('edit_weblog_icon',user_info("icon",$_SESSION['userid']),PARAM_INT);
+ $post->ident = optional_param('edit_weblog_post_id',0,PARAM_INT);
+ if (logged_on && !empty($post->body) && !empty($post->access) && !empty($post->ident)) {
+ $exists = false;
+ if ($oldpost = get_record('weblog_posts','ident',$post->ident)) {
+ if (run("permissions:check", array("weblog:edit", $oldpost->owner,$oldpost->weblog))) {
+ $exists = true;
+ }
+ }
+
+ if (!empty($exists)) {
+ $post->posted = $oldpost->posted;
+ $post->owner = $oldpost->owner;
+ $post->weblog = $oldpost->weblog;
+ $post = plugin_hook("weblog_post","update",$post);
+ if (!empty($post)) {
+ update_record('weblog_posts',$post);
+ delete_records('tags','tagtype','weblog','ref',$post->ident);
+ $value = trim(optional_param('edit_weblog_keywords'));
+ insert_tags_from_string ($value, 'weblog', $post->ident, $post->access, $oldpost->owner);
+ $post = get_record('weblog_posts','ident',$post->ident);
+
+ $extra_value = trim(optional_param('new_weblog_extra'));
+ $post->extra_value = $extra_value;
+
+ $post = plugin_hook("weblog_post","republish",$post);
+ $rssresult = run("weblogs:rss:publish", array($oldpost->weblog, false));
+ $rssresult = run("profile:rss:publish", array($oldpost->weblog, false));
+ $messages[] = __gettext("The weblog post has been modified."); // gettext variable
+ }
+ }
+ define('redirect_url',url . user_info("username",$page_owner) . "/$extensionContext/" . $post->ident . ".html");
+ }
+ break;
+
+ //Mark a weblog post as interesting
+ case "weblog:interesting:on":
+ $weblog_post = optional_param('weblog_post',0,PARAM_INT);
+ if (logged_on && !empty($weblog_post)) {
+ $wl = new StdClass;
+ $wl->weblog_post = $weblog_post;
+ $wl->owner = $USER->ident;
+ if (insert_record('weblog_watchlist',$wl)) {
+ $messages[] = __gettext("This weblog post has now been added to your 'interesting' list.");
+ }
+ define('redirect_url',url . user_info("username",$page_owner) . "/$extensionContext/" . $weblog_post . ".html");
+ }
+ break;
+
+ //Remove an 'interesting' flag
+ case "weblog:interesting:off":
+ $weblog_post = optional_param('weblog_post',0,PARAM_INT);
+ if (logged_on && !empty($weblog_post)) {
+ if (delete_records('weblog_watchlist','weblog_post',$weblog_post,'owner',$USER->ident)) {
+ $messages[] = __gettext("You are no longer monitoring this weblog post.");
+ }
+ define('redirect_url',url . user_info("username",$page_owner) . "/$extensionContext/" . $weblog_post . ".html");
+ }
+ break;
+
+ // Delete a weblog post
+ case "delete_weblog_post":
+ $id = optional_param('delete_post_id',0,PARAM_INT);
+ require_confirm(__gettext('Are you sure you want to permanently delete this weblog post?'));
+
+ if (logged_on && !empty($id)) {
+ if ($post_info = get_record('weblog_posts','ident',$id)) {
+ if (run("permissions:check", array("weblog:edit", $post_info->owner,$post_info->weblog))) {
+ $post_info = plugin_hook("weblog_post","delete",$post_info);
+ if (!empty($post_info)) {
+ delete_records('weblog_posts','ident',$id);
+ delete_records('weblog_comments','post_id',$id);
+ delete_records('weblog_watchlist','weblog_post',$id);
+ delete_records('tags','tagtype','weblog','ref',$id);
+ $rssresult = run("weblogs:rss:publish", array($post_info->weblog, false));
+ $rssresult = run("profile:rss:publish", array($post_info->weblog, false));
+ $messages[] = __gettext("The selected weblog post was deleted."); // gettext variable - NOT SURE ABOUT THIS POSITION!!!
+ }
+ } else {
+ $messages[] = __gettext("You do not appear to have permission to delete this weblog post. It was not deleted."); // gettext variable
+ }
+ }
+ global $redirect_url;
+ $redirect_url = url . user_info('username', $post_info->weblog) . "/$extensionContext/";
+ define('redirect_url',$redirect_url);
+ }
+ break;
+
+ // Create a weblog comment
+ case "weblogs:comment:add":
+ $comment = new StdClass;
+ $comment->post_id = optional_param('post_id',0,PARAM_INT);
+ $comment->body = trim(optional_param('new_weblog_comment'));
+ $comment->postedname = trim(optional_param('postedname'));
+ $commentbackup = $comment;
+ if (!empty($comment->post_id) && !empty($comment->body) && !empty($comment->postedname)) {
+ $where = run("users:access_level_sql_where",$USER->ident);
+ if ($post = get_record_select('weblog_posts','('.$where.') AND ident = '.$comment->post_id)) {
+ if (run("spam:check",$comment->body) != true) {
+ // If we're logged on or comments are public, add one
+ if (logged_on || (!$CFG->disable_publiccomments && user_flag_get("publiccomments",$post->owner)) ) {
+ $comment->owner = $USER->ident;
+ $comment->posted = time();
+ $comment = plugin_hook("weblog_comment","create",$comment);
+ if (!empty($comment)) {
+ $insert_id = insert_record('weblog_comments',$comment);
+ $comment->ident = $insert_id;
+ $comment = plugin_hook("weblog_comment","publish",$comment);
+
+ $messages[] = __gettext("Your comment has been added."); // gettext variable
+
+ // If we're logged on and not the owner of this post, add post to our watchlist
+ if (logged_on && $comment->owner != $post->owner) {
+ delete_records('weblog_watchlist','weblog_post',$comment->post_id,'owner',$comment->owner);
+ $wl = new StdClass;
+ $wl->owner = $comment->owner;
+ $wl->weblog_post = $comment->post_id;
+ insert_record('weblog_watchlist',$wl);
+ }
+
+ // Email comment if applicable
+ if ($comment->owner != $post->owner) {
+ $message = sprintf(__gettext("You have received a comment from %s on your blog post '%s'. It reads as follows:"), $comment->postedname, stripslashes($post->title));
+ $message .= "\n\n" . stripslashes($comment->body) . "\n\n";
+ $message .= sprintf(__gettext("To reply and see other comments on this blog post, click here: %s"), $CFG->wwwroot . user_info("username",$post->weblog) . "/weblog/" . $post->ident . ".html");
+ $message = wordwrap($message);
+ message_user($post->owner,$comment->owner,stripslashes($post->title),$message);
+ }
+
+ // If river plugin installed then note comment
+ if (function_exists('river_save_event'))
+ {
+ $un = user_info("username", $comment->owner);
+
+ $commenturl = $CFG->wwwroot."$un/weblog/{$comment->post_id}.html#cmt{$comment->ident}";
+ $username = "owner) . "\">$un ";
+ if (!isset($comment->owner))
+ {
+ $comment->owner = -1;
+ $username = __gettext("Anonymous user");
+ }
+
+ river_save_event($post->owner, $comment->ident, $comment->owner, "weblog_post::post", $username . " " . __gettext("commented on") . " " . river_get_friendly_id("weblog_post::post", $comment->post_id));
+
+ }
+ }
+ }
+ } else {
+ $messages[] = __gettext("Your comment could not be posted. The system thought it was spam.");
+ }
+ define('redirect_url',url . user_info("username",$post->owner) . "/$extensionContext/" . $commentbackup->post_id . ".html");
+ }
+ } else {
+ $messages[] = __gettext("Your comment body or name is empty.");
+ }
+ break;
+
+
+ // Delete a weblog comment
+ case "weblog_comment_delete":
+ $comment_id = optional_param('weblog_comment_delete',0,PARAM_INT);
+ require_confirm(__gettext('Are you sure you want to permanently delete this weblog comment?'));
+
+ if (logged_on && !empty($comment_id)) {
+ $commentinfo = get_record_sql('SELECT wc.*,wp.owner AS postowner,wp.ident AS postid
+ FROM '.$CFG->prefix.'weblog_comments wc
+ LEFT JOIN '.$CFG->prefix.'weblog_posts wp ON wp.ident = wc.post_id
+ WHERE wc.ident = ' . $comment_id);
+ $commentinfo = plugin_hook("weblog_comment","delete",$commentinfo);
+ if (!empty($commentinfo)) {
+ if ($commentinfo->owner == $USER->ident || run("permissions:check", "weblog")) {
+ delete_records('weblog_comments','ident',$comment_id);
+ $messages[] = __gettext("Your comment was deleted.");
+ }
+ }
+ $redirect_url = url . user_info('username', $commentinfo->postowner) . "/$extensionContext/" . $commentinfo->postid . ".html";
+ define('redirect_url',$redirect_url);
+ }
+ break;
+}
+
+if (defined('redirect_url')) {
+ header_redirect(redirect_url);
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/function_search_all_tagtypes.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/function_search_all_tagtypes.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/function_search_all_tagtypes.php (revision 33)
@@ -0,0 +1,6 @@
+
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_posts_view.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_posts_view.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_posts_view.php (revision 33)
@@ -0,0 +1,281 @@
+owner])) {
+
+ $author = "";
+
+ $stuff = get_record('users','ident',$post->owner);
+
+ $author->fullname = htmlspecialchars(user_name($post->owner), ENT_COMPAT, 'utf-8');
+
+ if ($stuff->icon == -1 || $post->owner == -1) {
+ $author->icon = 0;
+ } else {
+ if ($icon = get_record('icons','ident',$stuff->icon)) {
+ $author->icon = $icon->ident;
+ } else {
+ $author->icon = 0;
+ }
+ }
+
+ $post_authors[$post->owner] = $author;
+
+ //}
+ //if (!isset($post->authors[$post->weblog])) {
+ if ($post->weblog != $post->owner) {
+ $community = "";
+
+ $stuff2 = get_record('users','ident',$post->weblog);
+
+ $community->fullname = htmlspecialchars($stuff2->name, ENT_COMPAT, 'utf-8');
+
+ if (empty($stuff2->icon) || $stuff2->icon == -1) {
+ $community->icon = 0;
+ } else {
+ if ($icon = get_record('icons','ident',$stuff2->icon)) {
+ $community->icon = $icon->ident;
+ } else {
+ $community->icon = 0;
+ }
+ }
+
+ $post_authors[$post->weblog] = $community;
+ }
+ //}
+
+ $postedby = __gettext("Posted by");
+ $commentsStr = __gettext("Comments");
+
+ $date = gmdate("H:i",$post->posted);
+
+ $username = user_info('username', $post->owner);
+
+
+ // Allow plugins to set special icons
+ $specialicon = run("weblogs:posts:geticon",$post);
+
+ // If there is no special icon for this post, set to the default
+ if ($specialicon == NULL) {
+ $usericon = $post_authors[$post->owner]->icon;
+ if ($usericon == "default.png") {
+ $usericon = $post_authors[$post->weblog]->icon;
+ }
+ } else {
+ $usericon = $specialicon;
+ }
+ if ($usericon == 0) {
+ $usericon = -1;
+ }
+ // Allow plugins to set the name on the post
+ $specialname = run("weblogs:posts:getname",$post);
+ if (empty($specialname)) {
+ $fullname = $post_authors[$post->owner]->fullname;
+ } else {
+ $fullname = $specialname;
+ }
+
+ $title = get_access_description($post->access);
+ $title .= htmlspecialchars($post->title, ENT_COMPAT, 'utf-8');
+
+ if ($post->owner != $post->weblog) {
+ if (empty($specialicon) && $post_authors[$post->owner]->icon == -1) {
+ $usericon = $post_authors[$post->weblog]->icon;
+ }
+
+ //$fullname .= " @ " . $post_authors[$post->weblog]->fullname;
+ $fullname = sprintf(__gettext("%s - %s"),$post_authors[$post->weblog]->fullname,$fullname);
+ $username = user_info('username', $post->weblog);
+ }
+
+ //Getting the field from the context extension
+ $extensionContext = trim(optional_param('extension','weblog'));
+ $extraType = blog_get_extension($extensionContext, 'type');
+ $extraField = blog_get_extension($extensionContext, 'field');
+ $extraValue = blog_get_extension($extensionContext, 'values');
+ $extraTypes = blog_get_extension($extensionContext, 'extra_type', array());
+ $filter = $extraType;
+
+ $body = run("weblogs:text:process", $post->body);
+ $More = __gettext("More");
+ $Keywords = __gettext("Keywords:");
+ $anyComments = __gettext("comment(s)");
+
+ $postTitle = "ident}.html\">$title ";
+ $body = str_replace("{{more}}","ident}.html\">$More ... ",$body);
+ $keywords = display_output_field(array("","keywords","weblog","weblog",$post->ident,$post->owner));
+
+ if ($keywords) {
+ $body .= <<< END
+
+
+ $Keywords {$keywords}
+
+
+END;
+ }
+ // if ($post->owner == $_SESSION['userid'] && logged_on) {
+ if (run("permissions:check",array("weblog:edit",$post->owner,$post->weblog))) {
+ $Edit = __gettext("Edit");
+ $Delete = __gettext("Delete");
+ $links = <<< END
+ | $Edit |
+ $Delete
+END;
+ } else {
+ $links = "";
+ }
+ $links .= run("weblog:post:links",$post);
+
+ if (!isset($_SESSION['comment_cache'][$post->ident]) || (time() - $_SESSION['comment_cache'][$post->ident]->created > 120)) {
+ $numcomments = count_records('weblog_comments','post_id',$post->ident);
+ $_SESSION['comment_cache'][$post->ident]->created = time();
+ $_SESSION['comment_cache'][$post->ident]->data = $numcomments;
+ }
+ $numcomments = $_SESSION['comment_cache'][$post->ident]->data;
+
+ $comments = "| ident}.html\">$numcomments $anyComments ";
+
+ if (isset($individual) && ($individual == 1)) {
+ // looking at an individual post and its comments
+
+ $commentsbody = "";
+
+ if ($post->ident > 0) {
+ // if post exists and is visible
+
+ //which page of comments to display (page numbers are 0-based)
+ $page = optional_param('commentpage', 0, PARAM_INT);
+ $perpage = 20; // set to 0/false to disable paging
+ $offset = $page * $perpage;
+ $thispageurl = $CFG->wwwroot . $username . "/$extensionContext/" . $post->ident . ".html";
+
+ if ($comments = get_records('weblog_comments','post_id',$post->ident,'posted ASC')) {
+ $numcomments = count($comments);
+ $pagelinks = '';
+ if (!empty($perpage) && $numcomments > $perpage) {
+ $comments = array_slice($comments, $offset, $perpage);
+ $numpages = ceil($numcomments / $perpage);
+ $pagelinks = __gettext("Page: ");
+ for ($i = 1; $i <= $numpages; $i++) {
+ $pagenum = $i - 1;
+ if ($pagenum != $page) {
+ $pageurl = $thispageurl . (($pagenum) ? '.' . $pagenum : '');
+ $pagelinks .= ' ' . $i . ' ' ;
+ } else {
+ $pagelinks .= ' ' . $i . ' ';
+ }
+
+ }
+ $thispageurl .= '.' . $page;
+ }
+
+ foreach($comments as $comment) {
+ $commentmenu = "";
+ if (logged_on && ($comment->owner == $_SESSION['userid'] || run("permissions:check",array("weblog:edit",$post->owner)))) {
+ $Delete = __gettext("Delete");
+ $commentmenu = <<< END
+ $Delete
+END;
+ }
+ $comment->postedname = htmlspecialchars($comment->postedname, ENT_COMPAT, 'utf-8');
+
+ // turn commentor name into a link if they're a registered user
+ // add rel="nofollow" to comment links if they're not
+ if ($comment->owner > 0) {
+ $commentownerusername = user_info('username', $comment->owner);
+ $comment->postedname = '' . $comment->postedname . ' ';
+ $comment->icon = '' . user_icon_html($comment->owner,50) . " ";
+ $comment->body = run("weblogs:text:process", array($comment->body, false));
+ } else {
+ $comment->icon = user_icon_html(-1,50);
+ $comment->body = run("weblogs:text:process", array($comment->body, true));
+ }
+
+ $commentsbody .= templates_draw(array(
+ 'context' => 'weblogcomment',
+ 'postedname' => $comment->postedname,
+ 'body' => '' . $comment->body,
+ 'posted' => strftime("%A, %d %B %Y, %H:%M %Z",$comment->posted),
+ 'usericon' => $comment->icon,
+ 'permalink' => $thispageurl . "#cmt" . $comment->ident,
+ 'links' => $commentmenu
+ )
+ );
+
+ }
+ $commentsbody = templates_draw(array(
+ 'context' => 'weblogcomments',
+ 'paging' => $pagelinks,
+ 'comments' => $commentsbody,
+ 'comments_str' => $commentsStr
+ )
+ );
+
+ }
+
+ $run_result .= templates_draw(array(
+ 'context' => 'weblogpost',
+ 'date' => $date,
+ 'username' => $username,
+ 'usericon' => icon_html($usericon/*user_info_username("ident",$username)*/),
+ 'body' => $body,
+ 'fullname' => $fullname,
+ 'title' => $postTitle,
+ 'comments' => $commentsbody,
+ 'links' => $links,
+ 'postedby' => $postedby
+ )
+ );
+
+ if (logged_on || (!$CFG->disable_publiccomments && user_flag_get("publiccomments",$post->owner)) ) {
+ $run_result .= run("weblogs:comments:add",$post);
+ } else {
+ $run_result .= "" . __gettext("You must be logged in to post a comment.") . "
";
+ }
+
+ $run_result .= run("weblogs:interesting:form",$post->ident);
+
+ } else {
+ // post is missing or prohibited
+
+ $run_result .= templates_draw(array(
+ 'context' => 'weblogpost',
+ 'date' => "",
+ 'username' => "",
+ 'usericon' => user_icon_html(-1),
+ 'body' => $body,
+ 'fullname' => "",
+ 'title' => $postTitle,
+ 'comments' => "",
+ 'links' => $links,
+ 'postedby' => $postedby
+ )
+ );
+ }
+ } else {
+
+ $run_result .= templates_draw(array(
+ 'context' => 'weblogpost',
+ 'date' => $date,
+ 'username' => $username,
+ 'usericon' => icon_html($usericon/*user_info_username("ident",$username)*/),
+ 'body' => $body,
+ 'fullname' => $fullname,
+ 'title' => $postTitle,
+ 'commentslink' => $comments,
+ 'links' => $links,
+ 'postedby' => $postedby
+ )
+ );
+ }
+}
+
+?>
Index: /elgg/tags/20090118/mod/blog/lib/weblogs_init.php
===================================================================
--- /elgg/tags/20090118/mod/blog/lib/weblogs_init.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/lib/weblogs_init.php (revision 33)
@@ -0,0 +1,37 @@
+ident,PARAM_INT),PARAM_INT);
+ } else {
+ $profile_id = optional_param('profile_id',optional_param('profileid',-1,PARAM_INT),PARAM_INT);
+ }
+}
+
+global $page_owner;
+
+$page_owner = $profile_id;
+
+global $page_userid;
+
+$page_userid = user_info('username', $profile_id);
+
+// Add RSS to metatags, only if we are on a user page
+
+if (!empty($page_userid)) {
+ global $metatags;
+ $metatags .= " \n";
+}
+
+// Maximun items per page
+define('POSTS_PER_PAGE',10);
+?>
Index: /elgg/tags/20090118/mod/blog/archive.php
===================================================================
--- /elgg/tags/20090118/mod/blog/archive.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/archive.php (revision 33)
@@ -0,0 +1,26 @@
+
Index: /elgg/tags/20090118/mod/blog/edit.php
===================================================================
--- /elgg/tags/20090118/mod/blog/edit.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/edit.php (revision 33)
@@ -0,0 +1,37 @@
+
Index: /elgg/tags/20090118/mod/blog/archive_month.php
===================================================================
--- /elgg/tags/20090118/mod/blog/archive_month.php (revision 33)
+++ /elgg/tags/20090118/mod/blog/archive_month.php (revision 33)
@@ -0,0 +1,25 @@
+
Index: /elgg/tags/20090118/mod/browser/lib.php
===================================================================
--- /elgg/tags/20090118/mod/browser/lib.php (revision 129)
+++ /elgg/tags/20090118/mod/browser/lib.php (revision 129)
@@ -0,0 +1,92 @@
+menu[] = array( 'name' => 'browse',
+ 'html' => '' . __gettext("Browse") . ' ');
+ }
+
+
+ // Advanced search function
+ function browser_advanced_search($type, $display, $filter) {
+
+ global $CFG, $db;
+ $sql = "";
+
+ $filter = preg_replace("/([A-Za-z_0-9]*)\:\:/i", "", $filter);
+
+ $sort = optional_param('sort', '');
+ $sortcriteria = optional_param('sortcriteria', '');
+ $recent = optional_param('recent','');
+
+ switch($display) {
+
+ case "users":
+ $where = " u.user_type = 'person' ";
+ break;
+ case "communities":
+ $where = " u.user_type = 'community' ";
+ break;
+ case "projects":
+ //this is taken care of in index.php
+ break;
+ default:
+ $where = " 1 ";
+ break;
+
+ }
+
+ $having = '';
+ if ($sort == "yes") {
+
+ switch($sortcriteria) {
+ case "1-10":
+ $having = " HAVING members > 0 AND members < 11";
+ break;
+ case "11-100":
+ $having = " HAVING members > 10 AND members < 101";
+ break;
+ case "101-1000":
+ $having = " HAVING members > 100 AND members < 1001";
+ break;
+ case "1000":
+ $having = " HAVING members > 1000";
+ break;
+ }
+
+ }
+
+ $formatted_filter = $db->qstr($filter);
+ $formatted_filter_wild = $db->qstr("%" . $filter . "%");
+
+ $sql = "SELECT u.ident, u.username, u.name, u.icon, u.user_type, COUNT(m.ident) AS members "; // assumes GROUP BY u.ident
+ switch($type) {
+
+ //wildcards
+ case "name": $sql .= "FROM ".$CFG->prefix."users u JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE $where AND u.name LIKE " . $formatted_filter_wild . " GROUP BY u.ident $having ORDER BY members DESC, name DESC";
+ break;
+ case "schools": $sql .= "FROM ".$CFG->prefix."users u JOIN ".$CFG->prefix."profile_data p ON u.ident = p.owner JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE $where AND p.value LIKE " . $formatted_filter_wild . " AND p.name IN ('highschool', 'university') GROUP BY u.ident $having ORDER BY members DESC, name DESC";
+ break;
+
+ // equals
+ case "email": $sql .= "FROM ".$CFG->prefix."users u JOIN ".$CFG->prefix."tags t ON u.ident = t.owner JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE $where AND t.tag = " . $formatted_filter . " AND t.tagtype = 'emailaddress' GROUP BY u.ident $having ORDER BY members DESC, name DESC";
+ break;
+ case "interests": $sql .= "FROM ".$CFG->prefix."users u JOIN ".$CFG->prefix."tags t ON u.ident = t.owner JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE $where AND t.tag = " . $formatted_filter . " AND t.tagtype = 'interests' GROUP BY u.ident $having ORDER BY members DESC, name DESC";
+ break;
+ case "expertise": $sql .= "FROM ".$CFG->prefix."users u JOIN ".$CFG->prefix."tags t ON u.ident = t.owner JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE $where AND t.tag = " . $formatted_filter . " AND t.tagtype = 'skills' GROUP BY u.ident $having ORDER BY members DESC, name DESC";
+ break;
+ case "language": $sql .= "FROM ".$CFG->prefix."users u JOIN ".$CFG->prefix."tags t ON u.ident = t.owner JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE $where AND t.tag = " . $formatted_filter . " AND t.tagtype = 'languages' GROUP BY u.ident $having ORDER BY members DESC, name DESC";
+ break;
+
+ }
+
+ return $sql;
+ }
+
+?>
Index: /elgg/tags/20090118/mod/browser/index.php
===================================================================
--- /elgg/tags/20090118/mod/browser/index.php (revision 168)
+++ /elgg/tags/20090118/mod/browser/index.php (revision 168)
@@ -0,0 +1,240 @@
+prefix." browse page
+
+ // Run includes
+ require_once("../../includes.php");
+
+ global $search_sql;
+ global $filter;
+ global $searchtype;
+ global $db;
+ global $CFG;
+
+ define("context", "network");
+
+ // Quick config: this changes the number of search results on the page
+ $CFG->browser_search_results = 20;
+
+ $search_sql = "";
+
+ $title = __gettext("Browser");
+ $display = optional_param('display', '', PARAM_ALPHANUM);
+ $filter = trim(optional_param('filter', ''));
+ $searchtype = optional_param('searchtype', '');
+ $offset = optional_param('offset', 0, PARAM_INT);
+ $displayicons = optional_param('displayicons','');
+ $drilldown = optional_param('drilldown',-1,PARAM_INT);
+ $offset = optional_param('offset',0,PARAM_INT);
+
+ $access_string = run("users:access_level_sql_where",$_SESSION['userid']);
+ $access_string = str_replace("access","t.access",str_replace("owner","t.owner",$access_string));
+
+ if (!empty($searchtype)) {
+ $filter = $searchtype . "::" . $filter;
+ }
+
+ if ($displayicons == '') {
+ if (empty($_COOKIE['displayicons'])) {
+ $displayicons = 0;
+ } else {
+ $displayicons = $_COOKIE['displayicons'];
+ }
+ } else {
+ if ($displayicons != 1) {
+ $displayicons = 0;
+ }
+ setcookie("displayicons",$displayicons,time() + (86400 * 365));
+ }
+
+ $userunderline = "";
+ $communitiesunderline = "";
+ $allunderline = "";
+
+ switch($display) {
+ case "communities":
+ $usertypefilter = " u.user_type = 'community' ";
+ $communitiesunderline = ' style="text-decoration: underline;" ';
+ break;
+ case "users":
+ $usertypefilter = " u.user_type = 'person' ";
+ $userunderline = ' style="text-decoration: underline;" ';
+ break;
+ case "projects":
+ $usertypefilter = " u.user_type = 'project' ";
+ $projectsunderline = ' style="text-decoration: underline;" ';
+ break;
+ default:
+ $display = '';
+ $usertypefilter = ' 1=1 ';
+ $allunderline = ' style="text-decoration: underline;" ';
+ break;
+ }
+
+ $functionbody = "
+
+ global \$search_sql;
+ global \$filter;
+ global \$searchtype;
+
+ \$passed = \$matches[1];
+ \$searchtype = \$passed;
+ \$search_sql = browser_advanced_search(\$passed,'$display',\$filter);
+ return \"\";
+
+ ";
+
+ $filter = preg_replace_callback("/([A-Za-z_0-9]*)\:\:/i",create_function('$matches',$functionbody),$filter);
+
+ $displayfilter = $filter;
+ if (!empty($searchtype)) {
+ $displayfilter = $searchtype . "::" . $displayfilter;
+ }
+ $displayfilter = htmlspecialchars($displayfilter);
+
+ $all = __gettext("All");
+ $communities = __gettext("Communities");
+ $users = __gettext("Users");
+ $projects = __gettext("Projects");
+ $browse = __gettext("Browse");
+ $filter_text = __gettext("Filter");
+
+ $body = <<< END
+
+ $browse ::
+
+ $all |
+ $users |
+ $communities |
+ $projects |
+
+
+
+
+END;
+
+ if (empty($search_sql)) {
+ $formatted_filter = $db->qstr($filter);
+
+ if (empty($filter)) {
+ $search_sql = "SELECT u.ident, u.username, u.name, u.icon, u.user_type, COUNT(m.ident) AS members FROM ".$CFG->prefix."users u LEFT OUTER JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE " . $usertypefilter . " GROUP BY u.ident, u.username, u.name, u.icon, u.user_type ORDER BY members DESC, name DESC";
+ $count_sql = "SELECT COUNT(DISTINCT u.ident) AS numberofusers, COUNT(m.ident) AS members FROM ".$CFG->prefix."users u LEFT OUTER JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE " . $usertypefilter . "";
+ } else {
+ if (empty($searchtype)) {
+ $search_sql = "SELECT u.ident, u.username, u.name, u.icon, u.user_type, COUNT(m.ident) AS members FROM ".$CFG->prefix."tags t JOIN ".$CFG->prefix."users u ON u.ident = t.owner LEFT OUTER JOIN ".$CFG->prefix."friends m ON m.friend = u.ident LEFT OUTER JOIN ".$CFG->prefix."profile_data p ON p.owner = u.ident WHERE ($access_string) AND (t.tag = $formatted_filter OR (p.name = 'minibio' AND p.value LIKE '%$filter%') OR u.username LIKE '%$filter%' OR u.name LIKE '%$filter%') AND " . $usertypefilter . " GROUP BY u.ident, u.username, u.name,u.icon,u.user_type ORDER BY members DESC, name DESC";
+ $count_sql = "SELECT COUNT(DISTINCT u.ident) AS numberofusers, COUNT(m.ident) AS members FROM ".$CFG->prefix."tags t JOIN ".$CFG->prefix."users u ON u.ident = t.owner LEFT OUTER JOIN ".$CFG->prefix."friends m ON m.friend = u.ident LEFT OUTER JOIN ".$CFG->prefix."profile_data p ON p.owner = u.ident WHERE ($access_string) AND (t.tag = $formatted_filter OR (p.name = 'minibio' AND p.value LIKE '%$filter%') OR u.username LIKE '%$filter%' OR u.name LIKE '%$filter%') AND " . $usertypefilter . "";
+ }
+ }
+
+ }
+
+ $search_sql .= sql_paging_limit($offset, $CFG->browser_search_results);
+
+ if ($results = get_records_sql($search_sql)) {
+
+ if ($displayicons) {
+ $icontoggle = "Hide icons ";
+ } else {
+ $icontoggle = "Show icons ";
+ }
+
+ $name = __gettext("Name");
+ $description = __gettext("Description");
+ $connections = __gettext("Connections");
+ $posts = __gettext("Posts");
+ $type = __gettext("Type");
+
+ $body .= <<< END
+
+
+
+ $icontoggle
+ $name
+ $description
+ $connections
+ $posts
+ $type
+
+
+END;
+
+ foreach($results as $result) {
+
+ $blogposts = count_records("weblog_posts", "weblog", $result->ident);
+ $description = get_field("profile_data", "value", "owner", $result->ident, "name", 'minibio');
+
+ $icon_html = user_icon_html($result->ident);
+
+ $name = htmlspecialchars($result->name);
+
+ $iconcode = "wwwroot}{$result->username}\">{$icon_html} ";
+ if (!$displayicons) {
+ // Uncomment this if we move to Javascript unhide
+ // $iconcode = "".$iconcode." ";
+ $iconcode = " ";
+ }
+
+ $rowspan = "";
+ $plus = "";
+
+ if (!empty($filter)) {
+ if ($drilldown != $result->ident) {
+ $plus = "ident."#drilldown".$result->ident."\">+ ";
+ } else {
+ $plus = "- ";
+ $rowspan = "rowspan=\"2\"";
+ }
+ }
+
+ $body .= <<< END
+
+
+
+ $iconcode
+ {$name}
+ {$description}
+ {$result->members}
+ {$blogposts}
+ {$result->user_type}
+
+END;
+
+ }
+
+ $body .= <<< END
+
+
+
+END;
+
+ if (!empty($count_sql) && $search_total = get_record_sql($count_sql)) {
+ $search_total = $search_total->numberofusers;
+ } else {
+ $search_total = 0;
+ }
+
+ if ($search_total > $CFG->browser_search_results) {
+
+ $i = 1;
+ while (($i * $CFG->browser_search_results) - $CFG->browser_search_results < $search_total) {
+
+ $body .= "browser_search_results) - ($CFG->browser_search_results))."\">";
+ $body .= $i;
+ $body .= " ";
+ $i++;
+
+ }
+
+ }
+
+
+ } else {
+ }
+
+ templates_page_setup();
+ templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/widget/ajax_add_widget.php
===================================================================
--- /elgg/tags/20090118/mod/widget/ajax_add_widget.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/ajax_add_widget.php (revision 33)
@@ -0,0 +1,35 @@
+default_access,$display_order);
+$widget = get_record('widgets','ident',$widget_id);
+$result = '';
+$result .= '';
+$result .= ''.$display_id.' ';
+$result .= ''.$_SESSION['userid'].' ';
+$result .= ''.$widget_id.' ';
+$result .= ' ';
+$result .= ' ';
+header('Content-Type: application/xml');
+print $result;
+?>
Index: /elgg/tags/20090118/mod/widget/css
===================================================================
--- /elgg/tags/20090118/mod/widget/css (revision 33)
+++ /elgg/tags/20090118/mod/widget/css (revision 33)
@@ -0,0 +1,53 @@
+/* profile - widgets */
+
+#profile_widgets {
+ position:relative;
+}
+
+.widgets_even {
+ float:left;
+ width:330px;
+}
+
+.widgets_odd {
+ float:right;
+ width:330px;
+}
+
+.widget {
+ border: 1px solid #BBDCE9; /*#95BDCD;*/
+ margin-bottom: 5px;
+ padding: 0;
+}
+
+.widget .widget_content {
+ padding: 10px;
+}
+.widget .widget_content h3 {
+ padding:0;
+ margin:0;
+}
+
+.widget .widget_menu {
+ display: block;
+ background-color: #E2F0F6; /*#CBE5EF;*/
+ margin: 0px;
+ padding-left: 10px;
+ border-top: 1px solid #BBDCE9;
+ font-size:0.8em;
+}
+
+.widget h2 {
+ border:0;
+ border-bottom:1px solid #BBDCE9;
+ padding:0;
+ margin:0 0 10px 0;
+ color:#666;
+ background-color: #E2F0F6;
+ font-size:1.1em;
+}
+
+.widget .widget_content h2 a {
+ background:url(http://elgg.net/_templates/icons/arrow.gif) no-repeat left;
+ padding:0 0 0 10px;
+}
Index: /elgg/tags/20090118/mod/widget/delete.php
===================================================================
--- /elgg/tags/20090118/mod/widget/delete.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/delete.php (revision 33)
@@ -0,0 +1,67 @@
+owner;
+
+ // Do we have permission to touch this?
+ // If so, wipe it!
+ if (run("permissions:check","profile")) {
+
+ widget_destroy($widget->ident);
+ widget_reorder($page_owner,$widget->location,$widget->location_id);
+
+ }
+
+ // Get the username of the widget owner
+ $username = user_info("username",$widget->owner);
+
+ // Add a message
+ $messages[] = __gettext("Widget deleted.");
+ $_SESSION['messages'] = $messages;
+
+ // Redirect back to the relevant location
+ switch( $widget->location ) {
+ case 'profile':
+ case '':
+ $redirect_url = $CFG->wwwroot . $username . "/profile/";
+ break;
+ default:
+ // get module from the widget type
+ $module = '';
+ $mod_pos = strpos($widget->type,"::");
+ if ($mod_pos) {
+ $module = substr($widget->type,0,$mod_pos);
+ }
+ $redirect_url = widget_get_display_url($module).'?'.widget_get_display_query();
+ break;
+ }
+ header("Location: " . $redirect_url);
+ exit;
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/widget/init.php
===================================================================
--- /elgg/tags/20090118/mod/widget/init.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/init.php (revision 33)
@@ -0,0 +1,6 @@
+
Index: /elgg/tags/20090118/mod/widget/insert.php
===================================================================
--- /elgg/tags/20090118/mod/widget/insert.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/insert.php (revision 33)
@@ -0,0 +1,52 @@
+owner;
+
+ // Do we have permission to touch this?
+ // If so, reorder widgets!
+ if (run("permissions:check","profile")) {
+
+ $insert_widget->display_order = $before_widget->display_order - 5;
+ update_record('widgets',$insert_widget);
+ widget_reorder($page_owner,$insert_widget->location,$insert_widget->location_id);
+
+ }
+ }
+
+ // no real need to return a response, but just in case
+ // someone looks for one
+
+ header("Content-Type: application/xml");
+ print 'Success! ';
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/widget/postgres7.sql
===================================================================
--- /elgg/tags/20090118/mod/widget/postgres7.sql (revision 36)
+++ /elgg/tags/20090118/mod/widget/postgres7.sql (revision 36)
@@ -0,0 +1,22 @@
+
+CREATE TABLE prefix_widget_data (
+ ident SERIAL PRIMARY KEY,
+ widget integer NOT NULL,
+ name varchar(128) NOT NULL,
+ value text NOT NULL
+) ;
+
+CREATE INDEX prefix_widget_data_idx ON prefix_widget_data (widget);
+
+CREATE TABLE prefix_widgets (
+ ident SERIAL PRIMARY KEY,
+ owner integer NOT NULL,
+ type varchar(128) NOT NULL,
+ location varchar(128) NOT NULL,
+ location_id integer NOT NULL,
+ wcolumn integer NOT NULL,
+ display_order integer NOT NULL,
+ access varchar(128) NOT NULL
+) ;
+
+CREATE INDEX prefix_widgets_idx ON prefix_widgets (owner,display_order,access);
Index: /elgg/tags/20090118/mod/widget/move.php
===================================================================
--- /elgg/tags/20090118/mod/widget/move.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/move.php (revision 33)
@@ -0,0 +1,78 @@
+owner;
+
+ // Do we have permission to touch this?
+ // If so, move it
+ if (run("permissions:check","profile")) {
+
+ if ($move == "up") {
+ widget_moveup($widget);
+ } else if ($move == "down") {
+ widget_movedown($widget);
+ } else if ($move == "1") {
+ widget_move_before($widget,$widget->display_order,0);
+ } else if ($move == "2") {
+ widget_move_before($widget,$widget->display_order,1);
+ }
+ }
+
+ // Get the username of the widget owner
+ $username = user_info("username",$widget->owner);
+
+ // Add a message
+ $messages[] = __gettext("Widget moved.");
+ $_SESSION['messages'] = $messages;
+
+ // Redirect back to the relevant location
+ switch( $widget->location ) {
+ case 'profile':
+ case '':
+ $redirect_url = $CFG->wwwroot . $username . "/profile/";
+ break;
+ default:
+ // get module from the widget type
+ $module = '';
+ $mod_pos = strpos($widget->type,"::");
+ if ($mod_pos) {
+ $module = substr($widget->type,0,$mod_pos);
+ }
+ $redirect_url = widget_get_display_url($module).'?'.widget_get_display_query();
+ break;
+ }
+
+ header("Location: " . $redirect_url);
+ exit;
+
+ }
+
+?>
Index: /elgg/tags/20090118/mod/widget/lib.php
===================================================================
--- /elgg/tags/20090118/mod/widget/lib.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/lib.php (revision 33)
@@ -0,0 +1,674 @@
+dirroot . "mod/widget/init.php";
+
+ // Initialise the 'allcontent' widget array - i.e., widgets where Javascript is allowed
+
+ if (!isset($CFG->widgets->allcontent)) {
+ $CFG->widgets->allcontent = array();
+ }
+
+ // register the widgets that this module provides
+
+ $CFG->widgets->list[] = array(
+ 'name' => gettext("Text box"),
+ 'description' => gettext("Displays the text of your choice."),
+ 'type' => "widget::text"
+ );
+ if (!in_array($CFG->prefix . "widget_data",$METATABLES) || !in_array($CFG->prefix . "widgets",$METATABLES)) {
+ if (file_exists($CFG->dirroot . "mod/widget/$CFG->dbtype.sql")) {
+ modify_database($CFG->dirroot . "mod/widget/$CFG->dbtype.sql");
+ //reload system
+ header_redirect($CFG->wwwroot);
+
+ } else {
+ error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg widgets. See the mod/widget directory.");
+ }
+ print_continue("index.php");
+ exit;
+ }
+
+ // Delete users
+ listen_for_event("user","delete","widget_user_delete");
+ }
+
+// Get widgets for a particular user
+
+ function widget_for_user_sql($user_id,$location=NULL,$location_id=NULL,$column) {
+ global $CFG;
+ // Get access list for this user
+ $where = run("users:access_level_sql_where",$user_id);
+
+ $where2 = '';
+
+ // Get the sql to select a list of widgets
+ if (isset($location)) {
+ $where2 .= " AND location = '$location'";
+ }
+ if (isset($location_id)) {
+ $where2 .= " AND location_id = $location_id";
+ }
+ if (isset($column)) {
+ $where2 .= " AND wcolumn = $column";
+ }
+
+ $sql = "SELECT * FROM ".$CFG->prefix."widgets WHERE ($where) $where2 AND owner = $user_id ORDER BY display_order ASC";
+
+ return $sql;
+ }
+
+ function widget_for_user($user_id,$location='',$location_id=0,$column=NULL) {
+
+ $widgets = get_records_sql(widget_for_user_sql($user_id,$location,$location_id,$column));
+
+ // Return them
+ return $widgets;
+
+ }
+
+ function widget_for_user_count($user_id,$location=NULL,$location_id=NULL, $column=NULL) {
+
+ $count = get_record_sql('SELECT COUNT(*) as count FROM ('.widget_for_user_sql($user_id,$location,$location_id,$column).') AS q1');
+
+ return $count->count;
+ }
+
+ function widget_for_user_paginated($user_id,$location=NULL,$location_id=NULL,$column=NULL,$offset=0,$count=0) {
+ $widgets = get_records_sql(widget_for_user_sql($user_id,$location,$location_id,$column).sql_paging_limit($offset,$count));
+
+ // Return them
+ return $widgets;
+ }
+
+// Gets data with a particular name for a particular widget ID
+
+ function widget_get_data($name, $ident) {
+
+ global $db, $CFG;
+
+ $value = get_record("widget_data", "name", $name, "widget", $ident);
+ if (!empty($value) && !empty($value->value)) {
+ $value = $value->value;
+ } else {
+ $value = '';
+ }
+
+ return $value;
+
+ }
+
+ // for compatibility - remove ASAP
+
+ function adash_get_data($name, $ident) {
+ return widget_get_data($name, $ident);
+ }
+
+
+// Sets data with a particular name for a particular widget ID
+
+ function widget_set_data($name, $ident, $value) {
+ $data = new stdClass;
+ $data->name = $name;
+ $data->widget = $ident;
+ $data->value = $value;
+ if ($existing = widget_get_data($name,$ident)) {
+ $data->ident = $existing->ident;
+ return update_record('widget_data',$data);
+ } else {
+ return insert_record('widget_data',$data);
+ }
+ }
+
+// Removes data for a particular widget ID
+
+ function widget_remove_data($ident) {
+ delete_records('widget_data','widget',$ident);
+ }
+
+// Removes a widget
+
+ function widget_destroy($ident) {
+ if ($widget = get_record('widgets','ident',$ident)) {
+ if ($widget = plugin_hook("widget","delete",$widget)) {
+ delete_records('widgets','ident',$ident);
+ widget_remove_data($ident);
+ }
+ }
+ }
+
+// Removes all widgets for a user
+
+ function widget_user_delete($object_type, $event, $object) {
+ global $CFG;
+ if (!empty($object->ident) && $object_type == "user" && $event == "delete") {
+ if ($widgets = get_records("widgets","owner",$object->ident)) {
+ foreach($widgets as $widget) {
+ widget_destroy($widget->ident);
+ }
+ }
+ }
+ return $object;
+ }
+
+// Creates a widget
+
+function widget_create($location,$location_id,$column,$type,$owner=0,$access='PUBLIC',$display_order=0) {
+
+ $widget = new stdClass;
+ if ($owner) {
+ $widget->owner = $owner;
+ } else {
+ $widget->owner = $_SESSION['userid'];
+ }
+ $widget->type = $type;
+ $widget->location = $location;
+ $widget->location_id = $location_id;
+ $widget->wcolumn = $column;
+ $widget->access = $access;
+ $widget->display_order = $display_order;
+ $id = insert_record('widgets',$widget);
+ widget_reorder($widget->owner,$widget->location,$widget->location_id);
+
+ return $id;
+}
+
+// generates the query information to ensure that a widget function returns to a display
+// page with the correct information
+
+ function widget_get_display_query() {
+ $q = '';
+ $params = array_merge($_GET,$_POST);
+ if ($params) {
+ foreach($params as $k => $v) {
+ if ((strpos($k,'_widget') !== 0) && (strpos($k,'widget_data') !== 0) && $k != 'wid') {
+ $q .= '&'.$k .'='.$v;
+ }
+ }
+ }
+ if ($q) {
+ $q = substr($q,1);
+ }
+ return $q;
+ }
+
+ function widget_get_non_display_query() {
+ $q = '';
+ if ($_GET) {
+ foreach($_GET as $k => $v) {
+ if (strpos($k,'_dwidget') !== 0) {
+ $q .= '&'.$k .'='.$v;
+ }
+ }
+ }
+ if ($q) {
+ $q = substr($q,1);
+ }
+ return $q;
+ }
+
+// asks the appropriate module what URL is used to display this widget
+
+ function widget_get_display_url($module) {
+ $redirect_url = '';
+ $module_widget_display_url = $module . '_widget_display_url';
+ if ($module && function_exists($module_widget_display_url)) {
+ $redirect_url = $module_widget_display_url();
+ }
+ return $redirect_url;
+ }
+
+
+// Returns HTML for a particular widget
+// (Assumes a widget object taken from the database)
+
+ function widget_display($widget,$collapsed=0) {
+
+ global $CFG;
+ global $PAGE;
+
+ $widget_menu_template = '';
+
+ $widget_template = <<%s
+%s
+
+%s
+
+
+
+END;
+
+ $body = '';
+ $title = '';
+
+ // get module from the widget type
+ $module = '';
+ $mod_pos = strpos($widget->type,"::");
+ if ($mod_pos) {
+ $module = substr($widget->type,0,$mod_pos);
+ }
+
+ // If the handler for displaying this particular widget type exists,
+ // run it - otherwise display nothing
+
+ if ($collapsed) {
+ $mod_widget_display = $module . '_widget_display_collapsed';
+ } else {
+ $mod_widget_display = $module . '_widget_display';
+ }
+ if ($module && function_exists($mod_widget_display)) {
+ $widget_array = $mod_widget_display($widget);
+ if (isset($widget_array['content'])) {
+ $body = $widget_array['content'];
+ } else {
+ $body = '';
+ }
+ if (isset($widget_array['title'])) {
+ $title = $widget_array['title'];
+ } else {
+ $title = '';
+ }
+ if (isset($widget_array['menu'])) {
+ $menu = $widget_array['menu'];
+ } else {
+ $menu = array();
+ }
+ } else {
+ $result = '';
+ $title = '';
+ $menu = array();
+ if (!empty($CFG->widgets->display[$widget->type])) {
+ $body = $CFG->widgets->display[$widget->type]($widget);
+ } else {
+ $body = "";
+ }
+ }
+ if ($menu) {
+ // menu generation goes here
+ $menu_html = ''."\n";
+ foreach ($menu as $menu_item) {
+ $menu_html .= ''.$menu_item['text'].' '."\n";
+ }
+ $menu_html .= ' '."\n";
+ }
+
+ if (!empty($menu_html)) {
+ $menu_bit = sprintf($widget_menu_template,$menu_html);
+ } else {
+ $menu_bit = '';
+ }
+
+ $body = sprintf($widget_template,$title,$menu_bit,$body);
+
+ // If we have permission, display edit buttons
+
+ if (isloggedin() && run("permissions:check","profile")) {
+
+ $q = widget_get_display_query($widget);
+
+ // print("widget_get_display_query: $q");
+ $edit_msg = gettext("Edit widget");
+ $delete_msg = gettext("Delete widget");
+ $moveup_msg = gettext("Move up");
+ $movedown_msg = gettext("Move down");
+ $moveright_msg = gettext("Move right");
+ $moveleft_msg = gettext("Move left");
+ $img_template = ' ';
+ $edit_img = sprintf($img_template,$edit_msg,$edit_msg,"16-em-pencil.png");
+ $delete_img = sprintf($img_template,$delete_msg,$delete_msg,"16-em-cross.png");
+ $moveup_img = sprintf($img_template,$moveup_msg,$moveup_msg,"16-em-open.png");
+ $movedown_img = sprintf($img_template,$movedown_msg,$movedown_msg,"16-em-down.png");
+ $moveright_img = sprintf($img_template,$moveright_msg,$moveright_msg,"16-em-right.png");
+ $moveleft_img = sprintf($img_template,$moveleft_msg,$moveleft_msg,"16-em-left.png");
+
+ $body .= "";
+ }
+
+ // Return HTML
+
+ return $body;
+
+ }
+
+// Create a pagination line with links to first, previous, next and last widgets
+
+ function widget_get_paginator($url,$owner,$location,$location_id,$offset,$count,$total,$collapsed) {
+ // print("In widget_get_paginator: offset: $offset, count: $count, total: $total\n");
+ $search_template = gettext("Showing %s to %s of %s results");
+ $q = widget_get_non_display_query();
+ if ($q) {
+ $q .= '&';
+ }
+ $query_string = "{$q}_dwidget_collapsed=$collapsed&_dwidget_count=$count&_dwidget_total=$total&_dwidget_location=$location&_dwidget_location_id=$location_id&_dwidget_owner=$owner";
+ $paging_url ="$url?$query_string&_dwidget_offset=";
+ $start_paging_link = '<< ';
+ if ($count > $total) {
+ $end_paging_link = '>> ';
+ } else {
+ $end_paging_link = '>> ';
+ }
+
+ if ($offset + $count < $total) {
+ $new_offset = $offset+$count;
+ $report = sprintf($search_template,$offset+1,$new_offset,$total);
+ $next_link = '';
+ // $next_link .= gettext('Next');
+ $next_link .= '> ';
+ } else {
+ $report = sprintf($search_template,$offset+1,$total,$total);
+ $next_link = '>';
+ }
+ if ($offset > 0) {
+ $new_offset = $offset - $count;
+ if ($new_offset < 0) {
+ $new_offset = 0;
+ }
+ $previous_link = '';
+ // $previous_link .= gettext('Previous');
+ $previous_link .= '< ';
+ } else {
+ $previous_link = '<';
+ }
+
+ $paging_style = <<
+ .paging_widget {
+ width:430px;
+ text-align: center;
+ }
+ .paging_widget a {
+ font-weight: bold;
+ text-decoration: underline;
+ }
+
+END;
+
+ $pagination = "";
+ return $pagination;
+ }
+
+// Returns HTML that displays all widgets belonging to a particular user, in the current order
+// Optionally these widgets can be restricted to a particular location and location_id, displayed
+// in columns, paginated and/or the widgets collapsed (restricted to one line)
+
+ function widget_page_display($owner=0,$location='',$location_id=0,$columns=1,$count=0,$collapsed=0) {
+ if (!$owner) {
+ $owner = $_SESSION['userid'];
+ }
+ $offset = optional_param('_dwidget_offset',0,PARAM_INT);
+ $total = optional_param('_dwidget_total',0,PARAM_INT);
+ // print("In widget_page_display: offset: $offset, count: $count, total: $total\n");
+ $html = '';
+ if ($count) {
+ // handle pagination
+ if (!$total) {
+ $total = widget_for_user_count($owner,$location, $location_id);
+ }
+ $widgets = widget_for_user_paginated($owner,$location, $location_id,NULL,$offset,$count);
+ if ($widgets) {
+ $paginator = widget_get_paginator(widget_get_display_url($location),$owner,$location, $location_id,$offset,$count,$total,$collapsed);
+ $html .= $paginator;
+ $html .= widget_get_html($widgets,$columns,$collapsed);
+ }
+ $html .= $paginator;
+ } else {
+ $widgets = widget_for_user($owner,$location, $location_id);
+ if ($widgets) {
+ $html .= widget_get_html($widgets,$columns,$collapsed);
+ }
+ }
+ return $html;
+ }
+
+ function widget_get_html($widgets,$columns,$collapsed) {
+ if ($columns) {
+ $i = 0;
+ $html_odd = '';
+ $html_even = '';
+ $html = '';
+ foreach ($widgets as $widget) {
+ if ($widget->wcolumn == 0) {
+ $html_even .= "\n".'';
+ $html_even .= widget_display($widget,$collapsed);
+ $html_even .= '
';
+ } elseif ($widget->wcolumn == 1) {
+ $html_odd .= "\n".'';
+ $html_odd .= widget_display($widget,$collapsed);
+ $html_odd .= '
';
+ }
+ $i++;
+ }
+ $html = ''."\n".$html_even."\n".'
'."\n".''."\n".$html_odd."\n".'
'."\n";
+ } else {
+ foreach ($widgets as $widget) {
+ $html .= "\n".'';
+ $html .= widget_display($widget,$collapsed);
+ $html .= '
';
+ }
+ }
+ return $html;
+ }
+
+
+
+
+// Reorders widgets for a particular user, location and column
+
+ function widget_reorder($owner,$location=NULL,$location_id=NULL,$column=NULL) {
+
+ $widgets = widget_for_user($owner,$location,$location_id,$column);
+ if (is_array($widgets) && !empty($widgets)) {
+ $order = array();
+ $i = 1;
+ foreach($widgets as $widget) {
+ $order[$widget->ident] = $i * 10;
+ $i++;
+ }
+ foreach($order as $ident => $display_order) {
+ $widget = new StdClass;
+ $widget->display_order = $display_order;
+ $widget->ident = $ident;
+ update_record('widgets',$widget);
+ }
+ }
+
+ }
+
+// Move a widget up
+ function widget_moveup($widget) {
+ $widget->display_order = $widget->display_order - 11;
+ update_record('widgets',$widget);
+ widget_reorder($widget->owner,$widget->location,$widget->location_id,$widget->wcolumn);
+ }
+
+// Move a widget down
+ function widget_movedown($widget) {
+ $widget->display_order = $widget->display_order + 11;
+ update_record('widgets',$widget);
+ widget_reorder($widget->owner,$widget->location,$widget->location_id,$widget->wcolumn);
+ }
+
+// move a widget to specified column and before the specified position
+
+ function widget_move_before($widget,$display_order,$column) {
+ $widget->display_order = $display_order - 1;
+ $widget->wcolumn = $column;
+ update_record('widgets',$widget);
+ widget_reorder($widget->owner,$widget->location,$widget->location_id,$widget->wcolumn);
+ }
+
+ // move a widget to specified column and after the specified position
+
+ function widget_move_after($widget,$display_order,$column) {
+ $widget->display_order = $display_order + 1;
+ $widget->wcolumn = $column;
+ update_record('widgets',$widget);
+ widget_reorder($widget->owner,$widget->location,$widget->location_id,$widget->wcolumn);
+ }
+
+
+ function widget_finish_edit_form($widget,$body,$ajax=0) {
+
+ global $CFG;
+
+ $access_bit = ' '.gettext("Access: ") . run("display:access_level_select",array("_widget_access",$widget->access));
+ if ($ajax) {
+ $form = "\n";
+ // Return HTML
+ return $body;
+
+ }
+
+// Functions to display and edit plain text widgets
+
+ function widget_widget_display($widget) {
+ switch($widget->type) {
+ case 'widget::text':
+ return widget_text_widget_display($widget);
+ break;
+ }
+ }
+
+ function widget_widget_edit($widget) {
+ switch($widget->type) {
+ case 'widget::text':
+ return widget_text_widget_edit($widget);
+ break;
+ }
+ }
+
+ function widget_text_widget_display($widget) {
+
+ global $CFG;
+
+ $text_title = widget_get_data("widget_text_title",$widget->ident);
+ $text_body = widget_get_data("widget_text_body",$widget->ident);
+
+ if (empty($text_body)) {
+ $text_body = gettext("This text box is undefined. If you are the widget owner, click 'edit widget' to add your own content.");
+ }
+
+ $body = "" . nl2br($text_body) . "
";
+
+ return array('title'=>$text_title,'content'=>$body);
+
+ }
+
+ function widget_text_widget_edit($widget) {
+
+ global $CFG, $page_owner;
+
+ $widget_text_title = widget_get_data("widget_text_title",$widget->ident);
+ $widget_text_body = widget_get_data("widget_text_body",$widget->ident);
+
+
+ $body = "" . gettext("Text box") . " ";
+ $body .= "" . gettext("This widget displays the text content of your choice. All you need to do is enter the title and body below:") . "
";
+
+ $body .= "" . display_input_field(array("widget_data[widget_text_title]",$widget_text_title,"text")) . "
";
+ $body .= "" . display_input_field(array("widget_data[widget_text_body]",$widget_text_body,"longtext")) . "
";
+
+ return $body;
+ }
+
+?>
Index: /elgg/tags/20090118/mod/widget/ajax_delete_widget.php
===================================================================
--- /elgg/tags/20090118/mod/widget/ajax_delete_widget.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/ajax_delete_widget.php (revision 33)
@@ -0,0 +1,31 @@
+owner;
+
+ // Do we have permission to touch this?
+ // If so, wipe it!
+ if (run("permissions:check","profile")) {
+
+ widget_destroy($widget->ident);
+ widget_reorder($page_owner,$widget->location,$widget->location_id,$widget->column);
+
+ }
+ }
+}
+
+$result = '';
+$result .= '';
+$result .= ''.$id.' ';
+$result .= ' ';
+header('Content-Type: application/xml');
+print $result;
+?>
Index: /elgg/tags/20090118/mod/widget/ajax_start_edit_widget.php
===================================================================
--- /elgg/tags/20090118/mod/widget/ajax_start_edit_widget.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/ajax_start_edit_widget.php (revision 33)
@@ -0,0 +1,20 @@
+owner;
+ if (run("permissions:check","profile")) {
+ $result = '';
+ $result .= '';
+ $result .= ''.$id.' ';
+ $result .= ' ';
+ $result .= ' ';
+ header('Content-Type: application/xml');
+ print $result;
+ }
+}
+?>
Index: /elgg/tags/20090118/mod/widget/ajax_move_widget.php
===================================================================
--- /elgg/tags/20090118/mod/widget/ajax_move_widget.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/ajax_move_widget.php (revision 33)
@@ -0,0 +1,30 @@
+owner;
+ if (run("permissions:check","profile")) {
+ widget_move_before($widget,$display_order,$column);
+ $result = '';
+ $result .= '';
+ $result .= ''.$id.' ';
+ //$result .= ' ';
+ $result .= ' ';
+ header('Content-Type: application/xml');
+ print $result;
+ }
+}
+?>
Index: /elgg/tags/20090118/mod/widget/mysql.sql
===================================================================
--- /elgg/tags/20090118/mod/widget/mysql.sql (revision 33)
+++ /elgg/tags/20090118/mod/widget/mysql.sql (revision 33)
@@ -0,0 +1,22 @@
+CREATE TABLE `prefix_widget_data` (
+ `ident` int(11) NOT NULL auto_increment,
+ `widget` int(11) NOT NULL,
+ `name` varchar(128) NOT NULL,
+ `value` text NOT NULL,
+ PRIMARY KEY (`ident`),
+ KEY `widget` (`widget`)
+) ;
+
+CREATE TABLE `prefix_widgets` (
+ `ident` int(11) NOT NULL auto_increment,
+ `owner` int(11) NOT NULL,
+ `type` varchar(128) NOT NULL,
+ `location` varchar(128) NOT NULL,
+ `location_id` int(11) NOT NULL,
+ `wcolumn` int(11) NOT NULL,
+ `display_order` int(11) NOT NULL,
+ `access` varchar(128) NOT NULL,
+ PRIMARY KEY (`ident`),
+ KEY `owner` (`owner`,`display_order`,`access`),
+ KEY `location_id` (`location_id`)
+) ;
Index: /elgg/tags/20090118/mod/widget/manage_widgets.php
===================================================================
--- /elgg/tags/20090118/mod/widget/manage_widgets.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/manage_widgets.php (revision 33)
@@ -0,0 +1,314 @@
+wwwroot}mod/yui/build/yahoo/yahoo.js" >
+
+
+
+
+
+
+
+
+
+
+
+
+END;
+ $explanation = " wwwroot}mod/template/images/widgets.gif\" alt=\"widgets layout\" align=\"right\">" .__gettext("Hover your mouse over the name of each widget to find out more about it. Drag widgets from the widgets column into either profile column. You can also move widgets around within the profile columns. Edit any widget by clicking on it.")."
";
+ $widget_template = <<
+
+
+
+
+END;
+
+ $widget_list_element_template = '%s ';
+ $column_list_element_template = '%s ';
+ $widget_list = '';
+ $do_init = '';
+
+ if (is_array($CFG->widgets->list) && !empty($CFG->widgets->list)) {
+ foreach($CFG->widgets->list as $widget) {
+ if (!$widget['type']) {
+ $widget['type'] = $widget['id'];
+ }
+ $widget_list .= sprintf($widget_list_element_template,$widget['description'],$widget['description'],$widget['type'],$widget['name']);
+ $do_init .= 'new YAHOO.example.DDList("wli_'.$widget['type'].'");'."\n";
+ }
+ }
+
+ $first_column_list = '';
+
+ if ($widgets = widget_for_user($page_owner,'profile',0,0)) {
+ foreach($widgets as $widget) {
+ $name = 'Unknown';
+ $description = '';
+ foreach($CFG->widgets->list as $widget_class) {
+ if ($widget_class['type'] == $widget->type) {
+ $name = $widget_class['name'];
+ $description = $widget_class['description'];
+ break;
+ }
+ }
+ $first_column_list .= sprintf($column_list_element_template,$description,$description,$widget->ident,$name);
+ $do_init .= 'new YAHOO.example.DDList("eli_'.$widget->ident.'");'."\n";
+ //$do_init .= 'YAHOO.util.DDM.getElement("eli_'.$widget->ident.'").did='.$widget->display_order.';'."\n";
+ $do_init .= 'YAHOO.util.DDM.getElement("eli_'.$widget->ident.'").column=0;'."\n";
+ }
+ }
+
+ $second_column_list = '';
+
+ if ($widgets = widget_for_user($page_owner,'profile',0,1)) {
+ foreach($widgets as $widget) {
+ $name = 'Unknown';
+ $description = '';
+ foreach($CFG->widgets->list as $widget_class) {
+ if ($widget_class['type'] == $widget->type) {
+ $name = $widget_class['name'];
+ $description = $widget_class['description'];
+ break;
+ }
+ }
+ $second_column_list .= sprintf($column_list_element_template,$description,$description,$widget->ident,$name);
+ $do_init .= 'new YAHOO.example.DDList("eli_'.$widget->ident.'");'."\n";
+ //$do_init .= 'YAHOO.util.DDM.getElement("eli_'.$widget->ident.'").did='.$widget->display_order.';'."\n";
+ $do_init .= 'YAHOO.util.DDM.getElement("eli_'.$widget->ident.'").column=1;'."\n";
+ }
+ }
+
+ $title = __gettext("Manage Widgets");
+ $body = sprintf($top_bit_template,$do_init).sprintf($widget_template,$widget_list,$first_column_list,$second_column_list);
+
+} else {
+ $body = __gettext("You must be logged-in to manage your widgets");
+}
+
+// Output to the screen
+templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/widget/ajax_test.php
===================================================================
--- /elgg/tags/20090118/mod/widget/ajax_test.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/ajax_test.php (revision 33)
@@ -0,0 +1,18 @@
+';
+$result .= '';
+$result .= ''.$display_id.','.$type.' ';
+$result .= ''.$widget_id.' ';
+$result .= ' ';
+$result .= ' ';
+header('Content-Type: application/xml');
+print $result;
+?>
Index: /elgg/tags/20090118/mod/widget/edit.php
===================================================================
--- /elgg/tags/20090118/mod/widget/edit.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/edit.php (revision 33)
@@ -0,0 +1,124 @@
+owner;
+
+ // Initialise page
+ $body = "";
+ $title = __gettext("Edit widget");
+ templates_page_setup();
+
+ // If action is specified
+
+ if (!empty($action) && ($action == "widget:save" || $action == "widget:save:ajax")) {
+
+ // Get the username of the widget owner
+ // KJ - why?
+ $username = user_info("username",$widget->owner);
+
+ // Get any data
+ $js_override = optional_param('widget_allcontent');
+ if ($js_override == "yes"
+ && in_array($widget->type, $CFG->widgets->allcontent)) {
+ $widget_data = optional_param('widget_data','',null);
+ } else {
+ $widget_data = optional_param('widget_data','',PARAM_CLEAN);
+ }
+
+ if (!empty($widget_data)) {
+
+ widget_remove_data($widget->ident);
+
+ if (is_array($widget_data)) {
+ foreach($widget_data as $key => $value) {
+ widget_set_data($key, $widget->ident, $value);
+ }
+ }
+ }
+
+ // Save access
+ $widget->access = optional_param('_widget_access',$CFG->default_access);
+ update_record('widgets',$widget);
+
+ if ($action == "widget:save") {
+
+ // Add a message
+ $messages[] = __gettext("Widget edited.");
+ $_SESSION['messages'] = $messages;
+
+ // Redirect back to the relevant location
+ switch( $widget->location ) {
+ case 'profile':
+ case '':
+ $redirect_url = $CFG->wwwroot . $username . "/profile/";
+ break;
+ default:
+ // get module from the widget type
+ $module = '';
+ $mod_pos = strpos($widget->type,"::");
+ if ($mod_pos) {
+ $module = substr($widget->type,0,$mod_pos);
+ }
+ $redirect_url = widget_get_display_url($module).'?'.widget_get_display_query();
+ break;
+ }
+
+ header("Location: " . $redirect_url);
+ exit;
+
+ } else {
+
+ $result = '';
+ $result .= '';
+ $result .= ''.$widget->ident.' ';
+ $result .= ' ';
+ header('Content-Type: application/xml');
+ print $result;
+
+ }
+
+ } else {
+
+ // Do we have permission to touch this?
+ // If so, display edit screen
+ if (run("permissions:check","profile")) {
+
+ $body = widget_edit($widget);
+
+ } else {
+
+ $body = "" . __gettext("You do not have permission to edit this widget.") . "
";
+ }
+
+ }
+
+ // Output to the screen
+ templates_page_output($title, $body);
+ }
+
+?>
Index: /elgg/tags/20090118/mod/widget/README.txt
===================================================================
--- /elgg/tags/20090118/mod/widget/README.txt (revision 33)
+++ /elgg/tags/20090118/mod/widget/README.txt (revision 33)
@@ -0,0 +1,156 @@
+*Widget API*
+
+The Elgg widget module is designed to have a very simple API with as much as
+possible handled by the widget module itself.
+
+If you want to create a plugin that supplies widgets, then your module needs
+to provide two functions to generate HTML that displays and edits your
+widgets:
+
+module_widget_display($widget)
+
+which displays the widget pointed to by $widget
+
+and
+
+module_widget_edit($widget)
+
+which generates an edit form for the widget pointed to by $widget.
+
+In both cases, "module" should be replaced by the name of your module.
+
+Your edit form should not be a complete form - it can include some
+introductory text and the fields you want to edit (with the names
+widget_data[field_name], where "field_name" is the name of the field you want
+to edit). It should not include a "form" tag or submit button - these will be
+added automatically.
+
+You can see examples of display and edit functions in the widget module itself
+in mod/widget/lib.php. They, of course, are called widget_widget_display and
+widget_widget_edit.
+
+When you are creating the HTML to display and edit your widgets, you can use
+the widget_get_data($field_name,$widget->ident) function to get any data
+associated with your widget.
+
+If you want to register your widgets publicly and allow users to add them to
+their dashboards, then you can add a widget declaration to your module_init
+function (replace "module" in module_init by the name of your module).
+
+Here is the example from the widget module itself, which registers a simple
+text widget.
+
+
+$CFG->widgets->list[] = array(
+ 'name' => __gettext("Text box"),
+ 'description' => __gettext("Displays the text of your choice."),
+ 'type' => "text",
+ 'module' => "widget"
+);
+
+You can register multiple widget types for the same module and can access this
+information through the $widget->widget_type field when displaying or editing
+your widget.
+
+If all you want to do is register widgets with the Elgg dashboard, then this
+is probably all the API that you need to know.
+
+*Dashboard-like Pages*
+
+The widget system has more functionality that supports adding dashboard-like
+pages to your own module.
+
+If you want to display widgets on your own module page, then you need to
+provide another function:
+
+module_widget_display_url()
+
+(where "module" is the name of your module), which returns the URL of the
+page in your module responsible for displaying widgets.
+
+Eg. $CFG->wwwroot.'mod/module/view_widgets.php'
+
+You can use:
+
+widget_create($module,$location,$location_id,$type,$owner,$access,$display_order)
+
+to create your widget, where
+
+- $module is the name of your module
+- $location is an arbitrary string to describe the widget location
+- $location_id is an arbitrary number to describe the widget location
+(you can use location, location_id, or both, depending upon your
+application)
+- $type - the type of widget that you are creating
+
+The remaining 3 parameters are optional:
+
+- $owner is the user_id of the owner of the widget - if you do not provide
+this or set it to 0, then the widget will be owned by the current logged in
+user
+
+- $access - defaults to 'PUBLIC'
+
+- $display order - defaults to first if not provided or set to 0. You
+can set this to a large number (eg. 10000) if you want this to be the
+last widget displayed. The widgets are reshuffled as soon as they are
+inserted, so you can safely use 0 or 10000 each time you are creating a
+widget and it will always go first or at the end respectively.
+
+widget_create returns $widget->ident (the widget id).
+
+Note: the Elgg dashboard uses location = "dashboard" and location_id = 0.
+So creating a widget with these parameters is another way to place a
+widget on the owner's dashboard. Currently the dashboard system does
+not use dashboards with location_id set to something other than 0, but
+reserves the right to do so in future. So if you want to create your
+own dashboard-like pages, use a location other than "dashboard".
+
+To add or change widget data fields, you can use:
+
+widget_set_data($field_name, $widget->ident, $field_value)
+
+If the field_name record does not exist, it will be created when you set its
+value.
+
+To display widgets, you can use:
+
+widget_page_display($owner,$location,$location_id,$count,$collapsed)
+
+All the parameters are optional. widget_page_display() with no parameters
+returns all of the widgets of the currently logged-in user.
+
+If you set $owner to zero, the currently-logged-in user will be used as well.
+
+$location and $location_id can be used to display widgets associated with
+particular locations.
+
+$count is used to determine the number of widgets that should be displayed per
+page. Set this to 0 if you want all the widgets to be displayed on the same page.
+
+$collapsed determines if you want the widgets to be displayed in collapsed
+view (one line per widget). Set this to 1 if you want a collapsed view.
+
+If you want to display collapsed widgets, your module needs to supply another
+function,
+
+module_widget_display_collapsed($widget)
+
+which displays the collapsed widget pointed to by $widget
+
+(where "module" should be replaced by the name of your module).
+
+Keep in mind that various links to edit, delete and move your widget will
+appear on the same line, so your actual collapsed display area needs to be
+restricted to about 350 pixels or less.
+
+
+
+
+
+
+
+
+
+
+
Index: /elgg/tags/20090118/mod/widget/js/DDList_kj.js
===================================================================
--- /elgg/tags/20090118/mod/widget/js/DDList_kj.js (revision 33)
+++ /elgg/tags/20090118/mod/widget/js/DDList_kj.js (revision 33)
@@ -0,0 +1,196 @@
+/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
+
+var clone_i = 0;
+var current_el = '';
+
+/**
+ * @class a YAHOO.util.DDProxy implementation. During the drag over event, the
+ * dragged element is inserted before the dragged-over element.
+ *
+ * @extends YAHOO.util.DDProxy
+ * @constructor
+ * @param {String} id the id of the linked element
+ * @param {String} sGroup the group of related DragDrop objects
+ */
+YAHOO.example.DDList = function(id, sGroup, config) {
+
+ if (id) {
+ this.init(id, sGroup, config);
+ this.initFrame();
+ // this.logger = this.logger || YAHOO;
+ }
+
+ var s = this.getDragEl().style;
+ s.borderColor = "transparent";
+ s.backgroundColor = "#f6f5e5";
+ s.opacity = 0.76;
+ s.filter = "alpha(opacity=76)";
+};
+
+// YAHOO.example.DDList.prototype = new YAHOO.util.DDProxy();
+YAHOO.extend(YAHOO.example.DDList, YAHOO.util.DDProxy);
+
+YAHOO.example.DDList.prototype.startDrag = function(x, y) {
+ //this.logger.log(this.id + " startDrag");
+
+ var dragEl = this.getDragEl();
+ var clickEl = this.getEl();
+
+ dragEl.innerHTML = clickEl.innerHTML;
+ dragEl.className = clickEl.className;
+ dragEl.style.color = clickEl.style.color;
+ dragEl.style.border = "1px solid blue";
+
+};
+
+YAHOO.example.DDList.prototype.endDrag = function(e) {
+ // disable moving the linked element
+};
+
+// KJ - change list only after a drop, not just a drag over
+
+YAHOO.example.DDList.prototype.onDragOver = function(e, id) {
+ // YAHOO.log("DROP: " + id, "warn");
+};
+
+YAHOO.example.DDList.prototype.onDrag = function(e, id) {
+
+};
+
+YAHOO.example.DDList.prototype.onMouseDown = function(e) {
+ var el = this.getEl()
+ //alert("onMouseDown"+" el.id="+el.id+"#"+el.id.charAt(0));
+ if (el.id.charAt(0) == 'e') {
+ handle_widget_start_edit(el);
+ }
+};
+
+YAHOO.example.DDList.prototype.onDragDrop = function(e, id) {
+ // this.logger.log(this.id.toString() + " onDragOver " + id);
+ var el;
+
+ if (id.charAt(0) == 'l') {
+ // the user has dropped a widget on a new widget which has just been created and
+ // not been processed by the server
+ // ignore this drop
+ } else {
+
+ if ("string" == typeof id) {
+ el = YAHOO.util.DDM.getElement(id);
+ } else {
+ el = YAHOO.util.DDM.getBestMatch(id).getEl();
+ }
+
+ var mid = YAHOO.util.DDM.getPosY(el) + ( Math.floor(el.offsetTop / 2));
+ //this.logger.log("mid: " + mid);
+ //alert(YAHOO.util.Event.getPageY(e)+'#'+mid);
+ if (el.id.charAt(0) == 'g' || YAHOO.util.Event.getPageY(e) < mid) {
+ var el2 = this.getEl();
+ //YAHOO.util.DDM.getElement('dyn').innerHTML = ''+el.id+' (column: '+el.column+')
';
+ var p = el.parentNode;
+ if (el.id.charAt(0) == 'g') {
+ // delete operation
+ if (el2.id.charAt(0) == 'e') {
+ handle_widget_delete(el2);
+ }
+ } else if (el2.id.charAt(0) == 'w') {
+ if (el.id.charAt(0) != 'w') {
+ // first column, so clone
+ var el2_clone = el2.cloneNode(true);
+ el2_clone.id = 'li_'+clone_i;
+ // make new widget draggable
+ new YAHOO.example.DDList(el2_clone.id);
+ el2_clone.column = el.column;
+ if (current_el) {
+ current_el.className = 'sortList';
+ }
+ current_el = el2_clone;
+ p.insertBefore(el2_clone, el);
+ current_el.className = 'sortListWorking';
+ if (el.id.charAt(0) == 'h') {
+ // add to end
+ var sUrl = wwwroot+'mod/widget/ajax_add_widget.php?display_id='+clone_i+'&type='+el2.id.substring(4)+'&column='+el.column+'&owner='+user_id;
+ } else {
+ // add before el
+ var sUrl = wwwroot+'mod/widget/ajax_add_widget.php?display_id='+clone_i+'&type='+el2.id.substring(4)+'&column='+el.column+'&before='+el.id.substring(4)+'&owner='+user_id;
+ }
+ clone_i ++;
+ // Initiate the HTTP GET request.
+ var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, { success:successHandler, failure:failureHandler });
+ }
+ } else {
+ if (el.id.charAt(0) !== 'w') {
+ // other columns, so just resort
+ el2.column = el.column;
+ p.insertBefore(el2, el);
+ handle_widget_move(el2.id,el.id,el.column);
+ }
+ }
+ }
+ }
+};
+
+YAHOO.example.DDList.prototype.onDragEnter = function(e, id) {
+ // this.logger.log(this.id.toString() + " onDragEnter " + id);
+ // this.getDragEl().style.border = "1px solid #449629";
+};
+
+YAHOO.example.DDList.prototype.onDragOut = function(e, id) {
+ // I need to know when we are over nothing
+ // this.getDragEl().style.border = "1px solid #964428";
+};
+
+YAHOO.example.DDList.prototype.toString = function() {
+ return "DDList " + this.id;
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+
+YAHOO.example.DDListBoundary = function(id, sGroup, config) {
+ if (id) {
+ this.init(id, sGroup, config);
+ // this.logger = this.logger || YAHOO;
+ this.isBoundary = true;
+ }
+};
+
+// YAHOO.example.DDListBoundary.prototype = new YAHOO.util.DDTarget();
+YAHOO.extend(YAHOO.example.DDListBoundary, YAHOO.util.DDTarget);
+
+YAHOO.example.DDListBoundary.prototype.toString = function() {
+ return "DDListBoundary " + this.id;
+};
+
+function successHandler(o){
+ var root = o.responseXML.documentElement;
+ var oResult = root.getElementsByTagName('result')[0].firstChild.nodeValue;
+ var oUid = root.getElementsByTagName('uid')[0].firstChild.nodeValue;
+ var oForm = root.getElementsByTagName('edit_form')[0].firstChild.nodeValue;
+ var oWid = root.getElementsByTagName('wid')[0].firstChild.nodeValue;
+
+ // Format and display results in the response container.
+ //YAHOO.util.DDM.getElement('dyn').innerHTML = ''+ oResult + "("+oWid+")(User ID:"+oUid+")
";
+ YAHOO.util.DDM.getElement('formarea').innerHTML = ''+ oForm + "
";
+ if (current_el) {
+ current_el.className = 'sortList';
+ }
+ el = YAHOO.util.DDM.getElement('li_'+oResult);
+ current_el = el;
+ el.className = 'sortListCurrent';
+ //el.wid = oWid;
+ el.id = 'eli_'+oWid;
+}
+
+/*
+ *
+ * This is a simple failure handler that will display
+ * the HTTP status code and status message if the resource
+ * returns a non-2xx code.
+ *
+ */
+function failureHandler(o){
+ YAHOO.util.DDM.getElement('formarea').innerHTML = o.status + " " + o.statusText;
+}
+
+
Index: /elgg/tags/20090118/mod/widget/add.php
===================================================================
--- /elgg/tags/20090118/mod/widget/add.php (revision 33)
+++ /elgg/tags/20090118/mod/widget/add.php (revision 33)
@@ -0,0 +1,86 @@
+owner = $page_owner;
+ $widget->type = $widget_type;
+ $widget->access = "user" . $_SESSION['userid'];
+ $widget->location = "profile";
+ $widget->location_id = 0;
+ $widget_id = insert_record('widgets',$widget);
+
+ $messages[] = __gettext("Widget added.");
+ $_SESSION['messages'] = $messages;
+
+ widget_reorder($page_owner,'profile',0);
+
+ $username = user_info("username",$page_owner);
+ header("Location: " .$CFG->wwwroot."mod/widget/edit.php?widget=" . $widget_id);
+ exit;
+
+ }
+
+ // Iterate through the types of widgets we can add
+ if (is_array($CFG->widgets->list) && !empty($CFG->widgets->list)) {
+
+ $body = "" . __gettext("Select a widget type from the list below:") . "
";
+
+ foreach($CFG->widgets->list as $widget) {
+ $body .= "";
+
+ }
+
+ }
+
+ } else {
+ $body = "" . __gettext("You do not have permission to add widgets to this profile.") . "
";
+ }
+
+ // Output to the screen
+ templates_page_output($title, $body);
+
+?>
Index: /elgg/tags/20090118/mod/rpc/TODO
===================================================================
--- /elgg/tags/20090118/mod/rpc/TODO (revision 33)
+++ /elgg/tags/20090118/mod/rpc/TODO (revision 33)
@@ -0,0 +1,3 @@
+* Continue documenting the code
+* Clean up cruft and redundant code
+* More testing with other clients
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/library_mt_xmlrpc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/library_mt_xmlrpc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/library_mt_xmlrpc.php (revision 33)
@@ -0,0 +1,299 @@
+ $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Get a weblog instance
+ $weblog = run('weblogs:instance', array('user_id' => $username,
+ 'blog_id' => $blogid));
+
+ // Minimum of one, no maximum (for now)
+ if ($numberOfPosts >= 1)
+ {
+ // Get the posts
+ $posts = array_slice($weblog->getPosts(), 0, $numberOfPosts);
+
+ // Global results array
+ $result = array();
+
+ if (sizeof($posts) > 0)
+ {
+ foreach($posts as $post_id)
+ {
+ // Get the post object
+ $post = $weblog->getPost($post_id);
+
+ // Local array to hold a single post
+ $entry = array();
+
+ // Fill the post array, same for blogger and metaWeblog
+ $entry['dateCreated'] = new IXR_Date($post->getPosted());
+ $entry['userid'] = (int) $weblog->getIdent(); // is username for now
+ $entry['postid'] = (int) $post->getIdent();
+ $entry['title'] = $post->getTitle();
+ }
+ return $entry;
+ }
+ else
+ {
+ // Numbers of requested posts can't be provided, raise an XML-RPC error
+ return new IXR_Error(806, "No Such Item");
+ }
+ }
+ else
+ {
+ // Wrong amount of requested posts, raise an XML-RPC error
+ return new IXR_Error(805, "Amount parameter must be 1 or more");
+ }
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ // returns an array of structs containing String categoryId and String categoryName; on failure, fault.
+ function mt_getCategoryList($params, $method)
+ {
+ // Number of parameters
+ $nr_params = 3;
+
+ // Do we have the required number of parameters?
+ if (count($params) != $nr_params)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ $username = $params[1];
+ $password = $params[2];
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ $cats = array();
+
+ if ($auth['status'] == true)
+ {
+ // Global results array
+ $results = array();
+
+ /* TODO think of a way to possibly use categories (or not) because it doesn't work.
+ * Some clients _need_ the categories so just provide them with a default one.
+ */
+
+ $results['categoryId'] = '999';
+ $results['categoryName'] = 'Default category';
+
+ // Append
+ $cats[] = $results;
+
+ return $cats;
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /* TODO Right now this function only returns a list of tags, which is not quite what the spec demands.
+ * Unfortunately elgg doesn't do categories, so think of something else
+ */
+ function mt_getPostCategories($params, $method)
+ {
+ // Number of parameters
+ $nr_params = 3;
+
+ // Do we have the required number of parameters?
+ if (count($params) != $nr_params)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ $postId = (int) $params[0];
+ $username = $params[1];
+ $password = $params[2];
+
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Global results array
+ $results = array();
+
+ /* TODO think of a way to possibly use categories (or not) because it doesn't work.
+ * Som clients _need_ the categories so just provide them with a default one.
+ */
+
+ $results['categoryId'] = '999';
+ $results['categoryName'] = 'Default category';
+
+ return $results;
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /* TODO This function will always return true. Categories aren't available in elgg so
+ * think of something else
+ */
+ function mt_setPostCategories($params, $method)
+ {
+ // Number of parameters
+ $nr_params = 4;
+
+ // Do we have the required number of parameters?
+ if (count($params) != $nr_params)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ $postId = $params[0];
+ $username = $params[1];
+ $password = $params[2];
+ $categories = $params[3];
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Array to hold the decoded tag id's
+ $tagIds = array();
+
+ // Unpack the encoded categories/tags
+ foreach($categories as $value)
+ {
+ // Process the following:
+ // (string) $value['categoryId']
+ // (boolean)$value['isPrimary']
+ }
+
+ /* TODO categories don't map to tags, think of something else */
+ return true;
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ function mt_supportedMethods()
+ {
+ // TODO We will return the handler array. Not very safe since its content depends
+ // on the library loading order. It will do for now.
+ // Refactor to use the introsppection API
+
+ $result = array();
+
+ // $handlers is declared global so we can fetch it via $GLOBALS
+ foreach($GLOBALS['handlers'] as $key => $value)
+ {
+ $result[] = $key;
+ }
+
+ return $result;
+ }
+
+ function mt_supportedTextFilters($params, $method)
+ {
+ // Not supported, return an empty array
+
+ $result = array();
+
+ return $result;
+ }
+
+ /* This function just sets the access level to public*/
+ function mt_publishPost($params, $method)
+ {
+ // Number of parameters
+ $nr_params = 3;
+
+ // Do we have the required number of parameters?
+ if ($params->getNumParams() != $nr_params)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ $postId = $params[0];
+ $username = $params[1];
+ $password = $params[2];
+
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Publish means public access
+ $access = "PUBLISH";
+
+ $post = run('posts:instance', array('id' => $postId));
+
+ $post->setAccess($access);
+
+ if ($post->save() == true)
+ {
+ return true;
+ }
+ else
+ {
+ // The status hasn't been saved, raise an XML-RPC error
+ return new IXR_Error(-32500, "Unable to publish post");
+ }
+
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/library_blogger_xmlrpc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/library_blogger_xmlrpc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/library_blogger_xmlrpc.php (revision 33)
@@ -0,0 +1,714 @@
+ $username,
+ "password" => $password));
+ if ($auth['status'] == true)
+ {
+ $user = run('users:instance', array('user_id' => $username));
+ $post = run('posts:instance');
+
+ $post->setOwner($user->getIdent());
+ $post->setWeblog($blogid);
+
+ $title = "";
+
+ // Access level, only public or private supported
+ if ($publish == true)
+ {
+ $access = "PUBLIC";
+ }
+ else
+ {
+ $access = "user".$user->getIdent();
+ }
+
+ $post->setAccess($access);
+
+ if ($api == "blogger")
+ {
+ $post->setTitle($title);
+ $post->setBody($content);
+ }
+ else
+ {
+ // TODO possibly handle interesting mt extensions
+ // (String) mt_text_more (the value for the additional entry text, combine with {{cut}}?)
+ // (String) mt_excerpt (the value for the excerpt field)
+ // (Boolean) mt_allow_comments (Elgg only handles this as a global and not per post option)
+ $post->setTitle($content['title']);
+ $post->setBody($content['description']);
+ }
+
+ // Save first because we need a postid to be able to add the tags later
+ $post->save();
+
+ // We support mt_keywords if request is metaWeblog
+ if ($api != "blogger" && array_key_exists('mt_keywords', $content) && $post->getIdent() != "")
+ {
+ $keywords = $content['mt_keywords'];
+ $tags = explode(',', $keywords);
+ sort($tags);
+
+ foreach ($tags as $tag_name)
+ {
+ $tag = new Tag('tags:instance');
+ $tag->setOwner($user->getIdent());
+ $tag->setRef($post->getIdent()); // new post id should be available
+ $tag->setTagName($tag_name);
+ $tag->setAccess($access);
+ $tag->save();
+ }
+ }
+
+ // Do we have a new post id?
+ if ($post->getIdent() != "")
+ {
+ return $post->getIdent();
+ }
+ else
+ {
+ // No new post id available, item hasn't been saved so raise an XML-RPC error
+ return new IXR_Error(-32500, "Unable to save item");
+ }
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ function generic_editPost($params, $method)
+ {
+ // TODO editPost is almost similar to newPost, try to merge them
+
+ // Number of parameters
+ $nr_params = null;
+
+ if ($method == "blogger.editPost")
+ {
+ $api = "blogger";
+ $nr_params = 6;
+ }
+ elseif($method == "metaWeblog.editPost")
+ {
+ $api = "metaWeblog";
+ $nr_params = 5;
+ }
+
+ // Do we have the required number of parameters?
+ if (count($params) != $nr_params)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ if ($api == "blogger")
+ {
+ $postid = $params[1];
+ $username = $params[2];
+ $password = $params[3];
+ $content = $params[4];
+ $publish = $params[5];
+ }
+ else
+ {
+ $postid = $params[0];
+ $username = $params[1];
+ $password = $params[2];
+ $content = $params[3];
+ $publish = $params[4];
+ }
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ $post = run('posts:instance', array('id' => $postid));
+ $user = run('users:instance', array('user_id' => $username));
+
+ // Access level, only public or private supported
+ if ($publish == true)
+ {
+ $access = "PUBLIC";
+ }
+ else
+ {
+ $access = "user".$user->getIdent();
+ }
+
+ $post->setAccess($access);
+
+ if ($api == "blogger")
+ {
+ $post->setTitle($title);
+ $post->setBody($content);
+ }
+ else
+ {
+ // TODO possibly handle interesting mt extensions
+ // (String) mt_text_more (the value for the additional entry text, combine with {{cut}}?)
+ // (String) mt_excerpt (the value for the excerpt field)
+
+ $post->setTitle($content['title']);
+ $post->setBody($content['description']);
+
+ // We support mt_keywords
+ if (array_key_exists('mt_keywords', $content) && $result != false)
+ {
+ // Delete existing tags first
+ $post->deleteTags();
+
+ // Crunch and set the keywords as tags
+ $keywords = $content['mt_keywords'];
+ $tags = explode(',', $keywords);
+
+ foreach ($tags as $tag)
+ {
+ $tag = new Tag('tags:instance');
+ $tag->setOwner($user->getIdent());
+ $tag->setRef($post->getIdent());
+ $tag->setTagName($tag);
+ $tag->setAccess($access);
+ $tag->save();
+ }
+ }
+ }
+
+ // Do we have a succesfull save?
+ if ($post->save() == true)
+ {
+ return true;
+ }
+ else
+ {
+ // Modification are not saved, raise an XML-RPC error
+ return new IXR_Error(-32500, "Unable to update item");
+ }
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /*
+ */
+ function blogger_deletePost($params, $method)
+ {
+ // Parse parameters
+ $postid = $params[1];
+ $username = $params[2];
+ $password = $params[3];
+ $publish = (boolean) $params[4]; // not used
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ $post = run('posts:instance', array('id' => $postid));
+
+ if ($post->delete() == true)
+ {
+ return true;
+ }
+ else
+ {
+ // Message not deleted, raise an XML-RPC error
+ return new IXR_Error(-32500, "Unable to delete post");
+ }
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /*
+ * Description: Returns a list of the most recent posts in the system.
+ *
+ * Parameters: String appkey, String blogid, String username, String password, int numberOfPosts
+ *
+ * Return value: on success, array of structs containing ISO.8601 dateCreated, String userid,
+ * String postid, String content; on failure, fault
+ *
+ * Notes: dateCreated is in the timezone of the weblog; blogid and
+ * blogid parameters are not being used
+ */
+ function generic_getRecentPosts($params, $method)
+ {
+ // Number of parameters
+ $nr_params = null;
+
+ if ($method == "blogger.getRecentPosts")
+ {
+ $api = "blogger";
+ $nr_params = 5;
+ }
+ elseif($method == "metaWeblog.getRecentPosts")
+ {
+ $api = "metaWeblog";
+ $nr_params = 4;
+ }
+
+ // Do we have the required number of parameters?
+ if (count($params) != $nr_params)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ if ($api == "blogger")
+ {
+ $blogid = $params[1];
+ $username = $params[2];
+ $password = $params[3];
+ $numberOfPosts = (int) $params[4];
+ }
+ elseif($api == "metaWeblog")
+ {
+ $blogid = $params[0];
+ $username = $params[1];
+ $password = $params[2];
+ $numberOfPosts = (int) $params[3];
+ }
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ // Load the user
+ $user = run('users:instance', array('user_id' => $username));
+ $user_id = $user->getIdent();
+
+ if ($auth['status'] == true)
+ {
+ // Minimum of one, no maximum (for now)
+ if ($numberOfPosts >= 1)
+ {
+ $weblog = run('weblogs:instance', array('user_id' => $user_id,
+ 'blog_id' => $blogid));
+
+ // Get the posts
+ $posts = array_slice($weblog->getPosts(), 0, $numberOfPosts);
+
+ // Global results array
+ $result = array();
+
+ if (!empty($posts)) {
+
+ foreach($posts as $post_id)
+ {
+ $post = $weblog->getPost($post_id);
+
+ // Local array to hold a single post
+ $entry = array();
+
+ // Fill the post array, same for blogger and metaWeblog
+ $entry['dateCreated'] = new IXR_Date($post->getPosted());
+ $entry['userid'] = $weblog->getIdent(); // is username
+ $entry['postid'] = $post->getIdent();
+
+ // Here the API's differ
+ if ($api == "blogger")
+ {
+ $entry['content'] = $post->getBody();
+ }
+ else
+ {
+ $entry['title'] = $post->getTitle();
+ $entry['description'] = $post->getBody();
+ $entry['url'] = $post->getUrl();
+ $entry['permalink'] = $post->getPermaLink();
+ }
+
+ // We support tags as mt_keywords
+ $tags = $post->getTags();
+
+ if (!empty($tags)) {
+
+ $keywords = array();
+
+ foreach($tags as $tag_id)
+ {
+ $tag = $post->getTag($tag_id);
+
+ $keywords[] = $tag->getTagName();
+ }
+
+ $str_keywords = implode(',', $keywords);
+
+
+ // Add the keywords
+ $entry['mt_keywords'] = $str_keywords;
+ }
+
+ // Add it to the results array
+ $result[] = $entry;
+ }
+
+ return $result;
+ }
+ else
+ {
+ // Numbers of requested posts can't be provided, raise an XML-RPC error
+ return new IXR_Error(806, "No Such Item");
+ }
+ }
+ else
+ {
+ // Wrong amount of requested posts, raise an XML-RPC error
+ return new IXR_Error(805, "Amount parameter must be 1 or more");
+ }
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /*
+ * Description: Returns a list of weblogs to which an author has posting privileges.
+ *
+ * Parameters: String appkey, String username, String password
+ *
+ * Return value: on success, array of structs containing String url, String blogid,
+ * String blogName; on failure, fault
+ *
+ * Notes: Currently elgg only provides one weblog per user; appkey is not being used
+ */
+ function blogger_getUsersBlogs($params, $method)
+ {
+ // Do we have the required number of parameters?
+ if (count($params) != 3)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ $username = $params[1];
+ $password = $params[2];
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Load the user
+ $user = run('users:instance', array('user_id' => $username));
+ $user_id = $user->getIdent();
+
+ // Get the user's blogs
+ $blogs = $user->getBlogs();
+
+ // Result array
+ $result = array();
+
+ foreach ($blogs as $blog_id)
+ {
+ // Load the weblog
+ $weblog = run('weblogs:instance', array('user_id' => $user_id,
+ 'blog_id' => $blog_id));
+
+ // Array to hold the weblog data
+ $value = array();
+
+ $value['url'] = $weblog->getUrl();
+ $value['blogid'] = $weblog->getIdent();
+ $value['blogName'] = $weblog->getTitle();
+
+ // Add it to the result array
+ $result[] = $value;
+ }
+
+ return $result;
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /*
+ * Description: Returns information about an author in the system.
+ *
+ * Parameters: String appkey, String username, String password
+ *
+ * Return value: on success, struct containing String userid, String firstname,
+ * String lastname, String nickname, String email, String url; on failure, fault
+ *
+ * Notes: firstname is the Elgg username up to the first space character, and lastname
+ * is the username after the first space character. nickname is elgg username.
+ * appkey is not being used.
+ */
+ function blogger_getUserInfo($params, $method)
+ {
+ // Do we have the required number of parameters?
+ if (count($params) != 3)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ $username = $params[1];
+ $password = $params[2];
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Get user info
+ $user = run('users:instance', array("user_id" => $username));
+
+ // Global result array
+ $result = array();
+
+ // Fill the results array
+ $result['userid'] = $user->getUserName();
+ $result['firstname'] = $user->getFirstName();
+ $result['lastname'] = $user->getLastName();
+ $result['nickname'] = $user->getUserName();
+ $result['email'] = $user->getEmail();
+ $result['url'] = $user->getPersonalUrl();
+
+ return $result;
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ function metaweblog_getPost($params, $method)
+ {
+ // Do we have the required number of parameters?
+ if (count($params) != 3)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(-32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+ //$param = $params->getParam(0);
+ $postid = $params[0];
+ $username = $params[1];
+ $password = $params[2];
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ $weblog = run('weblogs:instance', array('id' => $username));
+
+ $post = $weblog->getPost($postid);
+
+ // Global results array
+ $entry = array();
+
+ // Fill the post array
+ $entry['dateCreated'] = new IXR_Date($post->getPosted());
+ $entry['userid'] = $username;
+ $entry['postid'] = $postid;
+ $entry['title'] = $post->getTitle();
+ $entry['description'] = $post->getBody();
+ $entry['url'] = $post->getUrl();
+ $entry['permalink'] = $post->getPermaLink();
+
+ // Support mt_keywords
+ $tags = $post->getTags();
+
+ if (!empty($tags)) {
+
+ $keywords = array();
+
+ foreach($tags as $tag_id)
+ {
+ $tag = $post->getTag($tag_id);
+
+ $keywords[] = $tag->getTagName();
+ }
+
+ $str_keywords = implode(',', $keywords);
+
+ // Add the keywords
+ $entry['mt_keywords'] = $str_keywords;
+ }
+
+ return $entry;
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+
+ /*
+ * Description: Uploads a file to your webserver.
+ *
+ * Parameters: String blogid, String username, String password, struct file
+ *
+ * Return value: URL to the uploaded file.
+ *
+ * Notes: the struct file should contain two keys: base64 bits (the base64-encoded contents of
+ * the file) and String name (the name of the file). The type key (media type of the file) is
+ * currently ignored.
+ */
+ function metaweblog_newMediaObject($params, $method)
+ {
+ // Do we have the required number of parameters?
+ if (count($params) != 4)
+ {
+ // Raise an XML-RPC error
+ return new IXR_Error(0, -32602, "Invalid method parameters");
+ }
+
+ // Parse parameters
+
+ $blogid = $params[0];
+ $username = $params[1];
+ $password = $params[2];
+ $file = $params[3];
+
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ // Get the file type and contents
+ $type = $file['type'];
+ $bits = $file['bits'];
+ $name = $file['name'];
+
+ // New user object
+ $user = run('users:instance', array('user_id' => $username));
+
+ // New file object
+ $file = run('files:instance');
+
+ // Get the upload folder id
+ $storage_id = $user->getFolderId("Weblog storage");
+
+ // Open or create the default upload folder
+ if ($storage_id == "")
+ {
+ $folder = run('folders:instance');
+
+ $folder->setOwner($user->getIdent());
+ $folder->setFilesOwner($blogid);
+ $folder->setName('Weblog storage');
+ $folder->setParent(-1);
+ $folder->setAccess('PUBLIC');
+ $folder->save();
+ }
+ else
+ {
+ $folder = run('folders:instance', array('id' => $storage_id));
+ }
+
+ // Prepare the file
+ $file->setOwner($user->getIdent());
+ $file->setFilesOwner($blogid);
+ $file->setAccess('PUBLIC'); // No access information available, assume public
+ $file->setFolder($folder->getIdent());
+ $file->setOriginalName($name);
+
+ $stored = $file->saveBase64Data($bits);
+
+ // A file id is returned, if all is well
+ if (is_numeric($stored['value']))
+ {
+ // TODO the MT spec defines the return type as a string,
+ // the metaWeblog spec as a struct with key 'url'.
+ // Find out which one (most) clients use. For now use the struct
+
+ // Return the URL as a struct
+ $uri['url'] = $file->getUrl();
+
+ return $uri;
+ }
+ else
+ {
+ // No url, raise an XML-RPC error
+ return new IXR_Error(-2, $stored['message']);
+ }
+ }
+ else
+ {
+ // Invalid credentials, raise an XML-RPC error
+ return new IXR_Error($auth['code'], $auth['message']);
+ }
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/xmlrpc_server.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/xmlrpc_server.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/xmlrpc_server.php (revision 33)
@@ -0,0 +1,121 @@
+ 100 Errors encountered by the XML parser
+
+ Other commonly used error codes
+
+
+
+ -32700 parse error. not well formed
+ -32701 parse error. unsupported encoding
+ -32702 parse error. invalid character for encoding
+ -32600 server error. invalid xml-rpc. not conforming to spec.
+ -32601 server error. requested method not found
+ -32602 server error. invalid method parameters
+ -32603 server error. internal xml-rpc error
+ -32500 application error
+ -32400 system error
+ -32300 transport error
+ */
+
+ global $CFG;
+ global $RPC;
+
+ require_once $CFG->dirroot . "mod/rpc/lib/IXR_Library.inc.php";
+
+ /**
+ * Elgg class extension to enable:
+ * - delayed excecution
+ * - passing method name to functions
+ */
+ Class Elgg_Server extends IXR_Server
+ {
+ function Elgg_Server($callbacks = false, $data = false)
+ {
+ $this->setCapabilities();
+ if ($callbacks)
+ {
+ $this->callbacks = $callbacks;
+ }
+ $this->setCallbacks();
+ }
+
+ function serve($data = false)
+ {
+ parent::serve($data);
+ }
+
+ function call($methodname, $args)
+ {
+ if (!$this->hasMethod($methodname))
+ {
+ return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
+ }
+ $method = $this->callbacks[$methodname];
+ // Perform the callback and send the response
+ if (count($args) == 1)
+ {
+ // If only one paramater just send that instead of the whole array
+ $args = $args[0];
+ }
+ // Are we dealing with a function or a method?
+ if (substr($method, 0, 5) == 'this:')
+ {
+ // It's a class method - check it exists
+ $method = substr($method, 5);
+ if (!method_exists($this, $method)) {
+ return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
+ }
+ // Call the method
+ $result = $this->$method($args);
+ }
+ else
+ {
+ // It's a function - does it exist?
+ if (!function_exists($method))
+ {
+ return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
+ }
+ // Call the function
+ $result = $method($args, $methodname);
+ }
+ return $result;
+ }
+ }
+
+ // Load the XML-RPC API's
+
+ foreach($RPC->handlers["library"] as $lib)
+ {
+ include_once $lib;
+ }
+
+ // Set the content type
+ header("Content-type: text/xml; charset=utf-8");
+
+ // Fire up the server
+ $server = new Elgg_Server($RPC->handlers["mapping"]);
+
+ // Serve the request
+ $server->serve();
+
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_elgg_user.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_elgg_user.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_elgg_user.php (revision 33)
@@ -0,0 +1,10 @@
+ 'getUserIcon');
+
+ // Add the handlers to the global handlers array
+ $RPC->addMapping($handlers);
+ $RPC->addLibrary(dirname(__FILE__)."/library_elgg_user.php");
+
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_livejournal_xmlrpc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_livejournal_xmlrpc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_livejournal_xmlrpc.php (revision 33)
@@ -0,0 +1,10 @@
+ 'lj_getFriends');
+
+ $RPC->addMapping($handlers);
+ $RPC->addLibrary(dirname(__FILE__)."/library_livejournal_xmlrpc.php");
+
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/library_elgg_user.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/library_elgg_user.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/library_elgg_user.php (revision 33)
@@ -0,0 +1,25 @@
+ $username));
+
+ return $user->getUserIcon();
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/library_livejournal_xmlrpc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/library_livejournal_xmlrpc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/library_livejournal_xmlrpc.php (revision 33)
@@ -0,0 +1,141 @@
+ $username));
+
+ if (!$user->exists())
+ {
+ return new IXR_Error(806, "No such user");
+
+ }
+/*
+ if (array_key_exists('auth_method', $request) && $request['auth_method'] !=Â "")
+ {
+ // Check credentials
+ $auth = run('rpc:auth', array("username" => $username,
+ "password" => $password));
+
+ if ($auth['status'] == true)
+ {
+ }
+ else
+ {
+ }
+ }
+*/
+ // Always return a struct containing keys, fill according to parameters:
+ // - friendsgroup
+ // - friendsof
+ // - friends
+
+ $result = array();
+ $result['friends'] = array();
+ $limit = "";
+
+ if ($params['friendlimit'])
+ {
+ $limit = $params['friendlimit'];
+ }
+
+ if ($params['includefriendof'] && $params['includefriendof'] == 1)
+ {
+ $result['friendsof'] = array();
+
+ $friends_of = $user->getFriendOf($limit);
+
+ $friends = array();
+
+ // Only if people have linked to this user...
+ if(count($friends_of) > 0)
+ {
+ foreach ($friends_of as $friend_id)
+ {
+ $temp = array();
+
+ $friend = run('users:instance', array('user_id' => $friend_id));
+
+ $tmp['username'] = $friend->getUserName();
+ $tmp['fullname'] = $friend->getName();
+ $tmp['fgcolor'] = "#FFFFFF";
+ $tmp['bgcolor'] = "#000000";
+ $tmp['groupmask'] = (int) 0; // TODO find out what the bits are about
+
+ $friends[] = $tmp;
+ }
+ }
+
+ $result['friendsof'] = $friends;
+ }
+
+ if ($content['includegroups'] && $content['includegroups'] == 1)
+ {
+ $result['friendsgroup'] = array();
+ }
+
+ $user_friends = $user->getFriends($limit);
+
+ $friends = array();
+
+ // Only if the user has friends...
+ if(count($user_friends) > 0)
+ {
+ foreach ($user_friends as $friend_id)
+ {
+ $temp = array();
+
+ $friend = run('users:instance', array('user_id' => $friend_id));
+
+ $tmp['username'] = $friend->getUserName();
+ $tmp['fullname'] = $friend->getName();
+ $tmp['fgcolor'] = "#FFFFFF";
+ $tmp['bgcolor'] = "#000000";
+ $tmp['groupmask'] = (int) 0; // TODO find out what the bits are about
+
+ $friends[] = $tmp;
+ }
+ }
+
+ $result['friends'] = $friends;
+
+ return $result;
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_mt_xmlrpc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_mt_xmlrpc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_mt_xmlrpc.php (revision 33)
@@ -0,0 +1,18 @@
+ 'mt_getRecenPostTitles',
+ 'mt.getCategoryList' => 'mt_getCategoryList',
+ 'mt.getPostCategories' => 'mt_getPostCategories',
+ 'mt.setPostCategories' => 'mt_setPostCategories',
+ 'mt.supportedMethods' => 'mt_supportedMethods',
+ 'mt.supportedTextFilters' => 'mt_supportedTextFilters',
+ 'mt.publishPost' => 'mt_publishPost');
+
+ // Add the handlers to the global handlers array
+
+ $RPC->addMapping($handlers);
+ $RPC->addLibrary(dirname(__FILE__)."/library_mt_xmlrpc.php");
+
+?>
Index: /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_blogger_xmlrpc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_blogger_xmlrpc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/xmlrpc/handlers_blogger_xmlrpc.php (revision 33)
@@ -0,0 +1,21 @@
+ 'generic_newPost',
+ 'blogger.editPost' => 'generic_editPost',
+ 'blogger.deletePost' => 'blogger_deletePost',
+ 'blogger.getRecentPosts' => 'generic_getRecentPosts',
+ 'blogger.getUsersBlogs' => 'blogger_getUsersBlogs',
+ 'blogger.getUserInfo' => 'blogger_getUserInfo',
+ 'metaWeblog.newPost' => 'generic_newPost',
+ 'metaWeblog.getRecentPosts' => 'generic_getRecentPosts',
+ 'metaWeblog.editPost' => 'generic_editPost',
+ 'metaWeblog.getPost' => 'metaweblog_getPost',
+ 'metaWeblog.newMediaObject' => 'metaweblog_newMediaObject');
+
+ // Add the handlers to the global handlers array
+ $RPC->addMapping($handlers);
+ $RPC->addLibrary(dirname(__FILE__)."/library_blogger_xmlrpc.php");
+
+?>
Index: /elgg/tags/20090118/mod/rpc/debug/xmlrpc-debug-proxy.py
===================================================================
--- /elgg/tags/20090118/mod/rpc/debug/xmlrpc-debug-proxy.py (revision 33)
+++ /elgg/tags/20090118/mod/rpc/debug/xmlrpc-debug-proxy.py (revision 33)
@@ -0,0 +1,141 @@
+#!/usr/bin/python
+
+"""HTTP debugging proxy
+
+(Presumably) originally by Sam Rushing
+ http://www.nightmare.com/medusa/programming.html
+
+Modified by Phillip Pearson
+ http://www.myelin.co.nz/notes/xmlrpc-debug-proxy.html
+ (Changes placed in the public domain; do what you will)
+
+
+A very small proxy for HTTP that dumps out what it sees, so you can debug your
+XML-RPC without having to decipher the output from a packet sniffer.
+
+This is basically the proxy used in the Medusa asynchronous sockets tutorial
+(available on http://www.nightmare.com/medusa/programming.html) with a minor
+adjustment to make it flush its buffers before closing any connections. Without
+that it will drop off important things like :)
+
+Syntax: xmlrpc-debug-proxy.py
+
+This will listen on port 8000+ and proxy through to :
+
+e.g. 'aproxy.py localhost 80' listens on localhost:8080 and proxies through to
+ the local web server on port 80.
+
+To debug stuff connecting to Radio, run 'xmlrpc-debug-proxy.py localhost 5335'
+and point your scripts at http://localhost:13335/RPC2 (instead of
+http://localhost:5335/RPC2)
+
+"""
+
+import asynchat
+import asyncore
+import socket
+import string
+
+class proxy_server (asyncore.dispatcher):
+
+ def __init__ (self, host, port):
+ asyncore.dispatcher.__init__ (self)
+ self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+ self.set_reuse_addr()
+ self.there = (host, port)
+ here = ('', port + 8000)
+ self.bind (here)
+ self.listen (5)
+
+ def handle_accept (self):
+ print 'New connection'
+ proxy_receiver (self, self.accept())
+
+class proxy_sender (asynchat.async_chat):
+
+ "Sends data to the server"
+
+ def __init__ (self, receiver, address):
+ asynchat.async_chat.__init__ (self)
+ self.receiver = receiver
+ self.set_terminator (None)
+ self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
+ self.buffer = ''
+ self.set_terminator ('\n')
+ self.connect (address)
+
+ def handle_connect (self):
+ print 'Sender connected'
+
+ def collect_incoming_data (self, data):
+ self.buffer = self.buffer + data
+
+ def found_terminator (self):
+ data = self.buffer
+ self.buffer = ''
+ print '==> (%d) %s' % (self.id, repr(data))
+ self.receiver.push (data + '\n')
+
+ def handle_close (self):
+ print 'Sender closing (inbuf len %d (%s), ac_in %d, ac_out %d )' % (
+ len( self.buffer ),
+ self.buffer,
+ len( self.ac_in_buffer ),
+ len( self.ac_out_buffer )
+ )
+
+ if len( self.buffer ):
+ self.found_terminator()
+
+ self.receiver.close_when_done()
+ self.close()
+
+class proxy_receiver (asynchat.async_chat):
+
+ "Receives data from the caller"
+
+ channel_counter = 0
+
+ def __init__ (self, server, (conn, addr)):
+ asynchat.async_chat.__init__ (self, conn)
+ self.set_terminator ('\n')
+ self.server = server
+ self.id = self.channel_counter
+ self.channel_counter = self.channel_counter + 1
+ self.sender = proxy_sender (self, server.there)
+ self.sender.id = self.id
+ self.buffer = ''
+
+ def collect_incoming_data (self, data):
+ self.buffer = self.buffer + data
+
+ def found_terminator (self):
+ import re
+ data = re.sub( r'\:8080', '', self.buffer )
+ data = re.sub( r'localhost', self.server.there[0], data )
+ self.buffer = ''
+ print '<== (%d) %s' % (self.id, repr(data))
+ self.sender.push (data + '\n')
+
+ def handle_close (self):
+ print 'Receiver closing (inbuf len %d (%s), ac_in %d, ac_out %d )' % (
+ len( self.buffer ),
+ self.buffer,
+ len( self.ac_in_buffer ),
+ len( self.ac_out_buffer )
+ )
+
+ if len( self.buffer ):
+ self.found_terminator()
+
+ self.sender.close_when_done()
+ self.close()
+
+if __name__ == '__main__':
+ import sys
+ import string
+ if len(sys.argv) < 3:
+ print 'Usage: %s ' % sys.argv[0]
+ else:
+ ps = proxy_server (sys.argv[1], string.atoi (sys.argv[2]))
+ asyncore.loop()
Index: /elgg/tags/20090118/mod/rpc/lib/function_load_post.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/function_load_post.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/function_load_post.php (revision 33)
@@ -0,0 +1,17 @@
+
Index: /elgg/tags/20090118/mod/rpc/lib/class_elggobject.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/class_elggobject.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/class_elggobject.php (revision 33)
@@ -0,0 +1,62 @@
+ident;
+ }
+
+ /**
+ * Get the object's owner id
+ *
+ * @return int The owner id
+ */
+ function getOwner()
+ {
+ return $this->getOwner();
+ }
+
+ /*
+ * Get the object's tag URI
+ *
+ * @return string The object's tag URI
+ */
+ function getTagUri()
+ {
+ if (!isset($this->user_username) || $this->user_username == "")
+ {
+ if ($this->owner == -1)
+ {
+ $user = new User($this->ident);
+ }
+ else
+ {
+ $user = new User($this->owner);
+ }
+
+ $this->user_username = $user->getUserName();
+ }
+
+ // TODO handle the year
+
+ $url = parse_url(url);
+
+ $this->_tag_uri = "tag:".$this->user_username."@".$url['host'].",2005:".$this->type.":".$this->ident;
+
+ return $this->_tag_uri;
+ }
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/lib/IXR_Library.inc.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/IXR_Library.inc.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/IXR_Library.inc.php (revision 33)
@@ -0,0 +1,826 @@
+ htmlspecialchars)
+ Site: http://scripts.incutio.com/xmlrpc/
+ Manual: http://scripts.incutio.com/xmlrpc/manual.php
+ Made available under the Artistic License: http://www.opensource.org/licenses/artistic-license.php
+*/
+
+
+class IXR_Value {
+ var $data;
+ var $type;
+ function IXR_Value ($data, $type = false) {
+ $this->data = $data;
+ if (!$type) {
+ $type = $this->calculateType();
+ }
+ $this->type = $type;
+ if ($type == 'struct') {
+ /* Turn all the values in the array in to new IXR_Value objects */
+ foreach ($this->data as $key => $value) {
+ $this->data[$key] = new IXR_Value($value);
+ }
+ }
+ if ($type == 'array') {
+ for ($i = 0, $j = count($this->data); $i < $j; $i++) {
+ $this->data[$i] = new IXR_Value($this->data[$i]);
+ }
+ }
+ }
+ function calculateType() {
+ if ($this->data === true || $this->data === false) {
+ return 'boolean';
+ }
+ if (is_integer($this->data)) {
+ return 'int';
+ }
+ if (is_double($this->data)) {
+ return 'double';
+ }
+ // Deal with IXR object types base64 and date
+ if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
+ return 'date';
+ }
+ if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
+ return 'base64';
+ }
+ // If it is a normal PHP object convert it in to a struct
+ if (is_object($this->data)) {
+
+ $this->data = get_object_vars($this->data);
+ return 'struct';
+ }
+ if (!is_array($this->data)) {
+ return 'string';
+ }
+ /* We have an array - is it an array or a struct ? */
+ if ($this->isStruct($this->data)) {
+ return 'struct';
+ } else {
+ return 'array';
+ }
+ }
+ function getXml() {
+ /* Return XML for this value */
+ switch ($this->type) {
+ case 'boolean':
+ return ''.(($this->data) ? '1' : '0').' ';
+ break;
+ case 'int':
+ return ''.$this->data.' ';
+ break;
+ case 'double':
+ return ''.$this->data.' ';
+ break;
+ case 'string':
+ return ''.htmlspecialchars($this->data).' ';
+ break;
+ case 'array':
+ $return = ''."\n";
+ foreach ($this->data as $item) {
+ $return .= ' '.$item->getXml()." \n";
+ }
+ $return .= ' ';
+ return $return;
+ break;
+ case 'struct':
+ $return = ''."\n";
+ foreach ($this->data as $name => $value) {
+ $return .= " $name ";
+ $return .= $value->getXml()." \n";
+ }
+ $return .= ' ';
+ return $return;
+ break;
+ case 'date':
+ case 'base64':
+ return $this->data->getXml();
+ break;
+ }
+ return false;
+ }
+ function isStruct($array) {
+ /* Nasty function to check if an array is a struct or not */
+ $expected = 0;
+ foreach ($array as $key => $value) {
+ if ((string)$key != (string)$expected) {
+ return true;
+ }
+ $expected++;
+ }
+ return false;
+ }
+}
+
+
+class IXR_Message {
+ var $message;
+ var $messageType; // methodCall / methodResponse / fault
+ var $faultCode;
+ var $faultString;
+ var $methodName;
+ var $params;
+ // Current variable stacks
+ var $_arraystructs = array(); // The stack used to keep track of the current array/struct
+ var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
+ var $_currentStructName = array(); // A stack as well
+ var $_param;
+ var $_value;
+ var $_currentTag;
+ var $_currentTagContents;
+ // The XML parser
+ var $_parser;
+ function IXR_Message ($message) {
+ $this->message = $message;
+ }
+ function parse() {
+ // first remove the XML declaration
+ $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message);
+ if (trim($this->message) == '') {
+ return false;
+ }
+ $this->_parser = xml_parser_create();
+ // Set XML parser to take the case of tags in to account
+ xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
+ // Set XML parser callback functions
+ xml_set_object($this->_parser, $this);
+ xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
+ xml_set_character_data_handler($this->_parser, 'cdata');
+ if (!xml_parse($this->_parser, $this->message)) {
+ /* die(sprintf('XML error: %s at line %d',
+ xml_error_string(xml_get_error_code($this->_parser)),
+ xml_get_current_line_number($this->_parser))); */
+ return false;
+ }
+ xml_parser_free($this->_parser);
+ // Grab the error messages, if any
+ if ($this->messageType == 'fault') {
+ $this->faultCode = $this->params[0]['faultCode'];
+ $this->faultString = $this->params[0]['faultString'];
+ }
+ return true;
+ }
+ function tag_open($parser, $tag, $attr) {
+ $this->currentTag = $tag;
+ switch($tag) {
+ case 'methodCall':
+ case 'methodResponse':
+ case 'fault':
+ $this->messageType = $tag;
+ break;
+ /* Deal with stacks of arrays and structs */
+ case 'data': // data is to all intents and puposes more interesting than array
+ $this->_arraystructstypes[] = 'array';
+ $this->_arraystructs[] = array();
+ break;
+ case 'struct':
+ $this->_arraystructstypes[] = 'struct';
+ $this->_arraystructs[] = array();
+ break;
+ }
+ }
+ function cdata($parser, $cdata) {
+ $this->_currentTagContents .= $cdata;
+ }
+ function tag_close($parser, $tag) {
+ $valueFlag = false;
+ switch($tag) {
+ case 'int':
+ case 'i4':
+ $value = (int)trim($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ break;
+ case 'double':
+ $value = (double)trim($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ break;
+ case 'string':
+ $value = (string)trim($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ break;
+ case 'dateTime.iso8601':
+ $value = new IXR_Date(trim($this->_currentTagContents));
+ // $value = $iso->getTimestamp();
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ break;
+ case 'value':
+ // "If no type is indicated, the type is string."
+ if (trim($this->_currentTagContents) != '') {
+ $value = (string)$this->_currentTagContents;
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ }
+ break;
+ case 'boolean':
+ $value = (boolean)trim($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ break;
+ case 'base64':
+ $value = base64_decode($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ $valueFlag = true;
+ break;
+ /* Deal with stacks of arrays and structs */
+ case 'data':
+ case 'struct':
+ $value = array_pop($this->_arraystructs);
+ array_pop($this->_arraystructstypes);
+ $valueFlag = true;
+ break;
+ case 'member':
+ array_pop($this->_currentStructName);
+ break;
+ case 'name':
+ $this->_currentStructName[] = trim($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ break;
+ case 'methodName':
+ $this->methodName = trim($this->_currentTagContents);
+ $this->_currentTagContents = '';
+ break;
+ }
+ if ($valueFlag) {
+ /*
+ if (!is_array($value) && !is_object($value)) {
+ $value = trim($value);
+ }
+ */
+ if (count($this->_arraystructs) > 0) {
+ // Add value to struct or array
+ if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
+ // Add to struct
+ $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
+ } else {
+ // Add to array
+ $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
+ }
+ } else {
+ // Just add as a paramater
+ $this->params[] = $value;
+ }
+ }
+ }
+}
+
+
+class IXR_Server {
+ var $data;
+ var $callbacks = array();
+ var $message;
+ var $capabilities;
+ function IXR_Server($callbacks = false, $data = false) {
+ $this->setCapabilities();
+ if ($callbacks) {
+ $this->callbacks = $callbacks;
+ }
+ $this->setCallbacks();
+ $this->serve($data);
+ }
+ function serve($data = false) {
+ if (!$data) {
+ global $HTTP_RAW_POST_DATA;
+ // CHANGE FROM UPSTREAM START - http://bugs.php.net/bug.php?id=41293
+ if (isset($HTTP_RAW_POST_DATA)) {
+ $input = $HTTP_RAW_POST_DATA;
+ } else {
+ $input = implode("\r\n", file('php://input'));
+ }
+ if (empty($input)) {
+ error_log('XML-RPC server accepts POST requests only.');
+ die('XML-RPC server accepts POST requests only.');
+ }
+ $data = $input;
+ // CHANGE FROM UPSTREAM END
+ }
+ $this->message = new IXR_Message($data);
+ if (!$this->message->parse()) {
+ $this->error(-32700, 'parse error. not well formed');
+ }
+ if ($this->message->messageType != 'methodCall') {
+ $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
+ }
+ $result = $this->call($this->message->methodName, $this->message->params);
+ // Is the result an error?
+ if (is_a($result, 'IXR_Error')) {
+ $this->error($result);
+ }
+ // Encode the result
+ $r = new IXR_Value($result);
+ $resultxml = $r->getXml();
+ // Create the XML
+ $xml = <<
+
+
+
+ $resultxml
+
+
+
+
+
+EOD;
+ // Send it
+ $this->output($xml);
+ }
+ function call($methodname, $args) {
+ if (!$this->hasMethod($methodname)) {
+ return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
+ }
+ $method = $this->callbacks[$methodname];
+ // Perform the callback and send the response
+ if (count($args) == 1) {
+ // If only one paramater just send that instead of the whole array
+ $args = $args[0];
+ }
+ // Are we dealing with a function or a method?
+ if (substr($method, 0, 5) == 'this:') {
+ // It's a class method - check it exists
+ $method = substr($method, 5);
+ if (!method_exists($this, $method)) {
+ return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
+ }
+ // Call the method
+ $result = $this->$method($args);
+ } else {
+ // It's a function - does it exist?
+ if (!function_exists($method)) {
+ return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
+ }
+ // Call the function
+ $result = $method($args);
+ }
+ return $result;
+ }
+
+ function error($error, $message = false) {
+ // Accepts either an error object or an error code and message
+ if ($message && !is_object($error)) {
+ $error = new IXR_Error($error, $message);
+ }
+ $this->output($error->getXml());
+ }
+ function output($xml) {
+ $xml = ''."\n".$xml;
+ $length = strlen($xml);
+ header('Connection: close');
+ header('Content-Length: '.$length);
+ header('Content-Type: text/xml');
+ header('Date: '.date('r'));
+ echo $xml;
+ exit;
+ }
+ function hasMethod($method) {
+ return in_array($method, array_keys($this->callbacks));
+ }
+ function setCapabilities() {
+ // Initialises capabilities array
+ $this->capabilities = array(
+ 'xmlrpc' => array(
+ 'specUrl' => 'http://www.xmlrpc.com/spec',
+ 'specVersion' => 1
+ ),
+ 'faults_interop' => array(
+ 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
+ 'specVersion' => 20010516
+ ),
+ 'system.multicall' => array(
+ 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
+ 'specVersion' => 1
+ ),
+ );
+ }
+ function getCapabilities($args) {
+ return $this->capabilities;
+ }
+ function setCallbacks() {
+ $this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
+ $this->callbacks['system.listMethods'] = 'this:listMethods';
+ $this->callbacks['system.multicall'] = 'this:multiCall';
+ }
+ function listMethods($args) {
+ // Returns a list of methods - uses array_reverse to ensure user defined
+ // methods are listed before server defined methods
+ return array_reverse(array_keys($this->callbacks));
+ }
+ function multiCall($methodcalls) {
+ // See http://www.xmlrpc.com/discuss/msgReader$1208
+ $return = array();
+ foreach ($methodcalls as $call) {
+ $method = $call['methodName'];
+ $params = $call['params'];
+ if ($method == 'system.multicall') {
+ $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');
+ } else {
+ $result = $this->call($method, $params);
+ }
+ if (is_a($result, 'IXR_Error')) {
+ $return[] = array(
+ 'faultCode' => $result->code,
+ 'faultString' => $result->message
+ );
+ } else {
+ $return[] = array($result);
+ }
+ }
+ return $return;
+ }
+}
+
+class IXR_Request {
+ var $method;
+ var $args;
+ var $xml;
+ function IXR_Request($method, $args) {
+ $this->method = $method;
+ $this->args = $args;
+ $this->xml = <<
+
+{$this->method}
+
+
+EOD;
+ foreach ($this->args as $arg) {
+ $this->xml .= '';
+ $v = new IXR_Value($arg);
+ $this->xml .= $v->getXml();
+ $this->xml .= " \n";
+ }
+ $this->xml .= ' ';
+ }
+ function getLength() {
+ return strlen($this->xml);
+ }
+ function getXml() {
+ return $this->xml;
+ }
+}
+
+
+class IXR_Client {
+ var $server;
+ var $port;
+ var $path;
+ var $useragent;
+ var $response;
+ var $message = false;
+ var $debug = false;
+ // Storage place for an error message
+ var $error = false;
+ function IXR_Client($server, $path = false, $port = 80) {
+ if (!$path) {
+ // Assume we have been given a URL instead
+ $bits = parse_url($server);
+ $this->server = $bits['host'];
+ $this->port = isset($bits['port']) ? $bits['port'] : 80;
+ $this->path = isset($bits['path']) ? $bits['path'] : '/';
+ // Make absolutely sure we have a path
+ if (!$this->path) {
+ $this->path = '/';
+ }
+ } else {
+ $this->server = $server;
+ $this->path = $path;
+ $this->port = $port;
+ }
+ $this->useragent = 'The Incutio XML-RPC PHP Library';
+ }
+ function query() {
+ $args = func_get_args();
+ $method = array_shift($args);
+ $request = new IXR_Request($method, $args);
+ $length = $request->getLength();
+ $xml = $request->getXml();
+ $r = "\r\n";
+ $request = "POST {$this->path} HTTP/1.0$r";
+ $request .= "Host: {$this->server}$r";
+ $request .= "Content-Type: text/xml$r";
+ $request .= "User-Agent: {$this->useragent}$r";
+ $request .= "Content-length: {$length}$r$r";
+ $request .= $xml;
+ // Now send the request
+ if ($this->debug) {
+ echo ''.htmlspecialchars($request)."\n \n\n";
+ }
+ $fp = @fsockopen($this->server, $this->port);
+ if (!$fp) {
+ $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
+ return false;
+ }
+ fputs($fp, $request);
+ $contents = '';
+ $gotFirstLine = false;
+ $gettingHeaders = true;
+ while (!feof($fp)) {
+ $line = fgets($fp, 4096);
+ if (!$gotFirstLine) {
+ // Check line for '200'
+ if (strstr($line, '200') === false) {
+ $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
+ return false;
+ }
+ $gotFirstLine = true;
+ }
+ if (trim($line) == '') {
+ $gettingHeaders = false;
+ }
+ if (!$gettingHeaders) {
+ $contents .= trim($line)."\n";
+ }
+ }
+ if ($this->debug) {
+ echo ''.htmlspecialchars($contents)."\n \n\n";
+ }
+ // Now parse what we've got back
+ $this->message = new IXR_Message($contents);
+ if (!$this->message->parse()) {
+ // XML error
+ $this->error = new IXR_Error(-32700, 'parse error. not well formed');
+ return false;
+ }
+ // Is the message a fault?
+ if ($this->message->messageType == 'fault') {
+ $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
+ return false;
+ }
+ // Message must be OK
+ return true;
+ }
+ function getResponse() {
+ // methodResponses can only have one param - return that
+ return $this->message->params[0];
+ }
+ function isError() {
+ return (is_object($this->error));
+ }
+ function getErrorCode() {
+ return $this->error->code;
+ }
+ function getErrorMessage() {
+ return $this->error->message;
+ }
+}
+
+
+class IXR_Error {
+ var $code;
+ var $message;
+ function IXR_Error($code, $message) {
+ $this->code = $code;
+ $this->message = $message;
+ }
+ function getXml() {
+ $xml = <<
+
+
+
+
+ faultCode
+ {$this->code}
+
+
+ faultString
+ {$this->message}
+
+
+
+
+
+
+EOD;
+ return $xml;
+ }
+}
+
+
+class IXR_Date {
+ var $year;
+ var $month;
+ var $day;
+ var $hour;
+ var $minute;
+ var $second;
+ function IXR_Date($time) {
+ // $time can be a PHP timestamp or an ISO one
+ if (is_numeric($time)) {
+ $this->parseTimestamp($time);
+ } else {
+ $this->parseIso($time);
+ }
+ }
+ function parseTimestamp($timestamp) {
+ $this->year = date('Y', $timestamp);
+ $this->month = date('Y', $timestamp);
+ $this->day = date('Y', $timestamp);
+ $this->hour = date('H', $timestamp);
+ $this->minute = date('i', $timestamp);
+ $this->second = date('s', $timestamp);
+ }
+ function parseIso($iso) {
+ $this->year = substr($iso, 0, 4);
+ $this->month = substr($iso, 4, 2);
+ $this->day = substr($iso, 6, 2);
+ $this->hour = substr($iso, 9, 2);
+ $this->minute = substr($iso, 12, 2);
+ $this->second = substr($iso, 15, 2);
+ }
+ function getIso() {
+ return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second;
+ }
+ function getXml() {
+ return ''.$this->getIso().' ';
+ }
+ function getTimestamp() {
+ return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
+ }
+}
+
+
+class IXR_Base64 {
+ var $data;
+ function IXR_Base64($data) {
+ $this->data = $data;
+ }
+ function getXml() {
+ return ''.base64_encode($this->data).' ';
+ }
+}
+
+
+class IXR_IntrospectionServer extends IXR_Server {
+ var $signatures;
+ var $help;
+ function IXR_IntrospectionServer() {
+ $this->setCallbacks();
+ $this->setCapabilities();
+ $this->capabilities['introspection'] = array(
+ 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
+ 'specVersion' => 1
+ );
+ $this->addCallback(
+ 'system.methodSignature',
+ 'this:methodSignature',
+ array('array', 'string'),
+ 'Returns an array describing the return type and required parameters of a method'
+ );
+ $this->addCallback(
+ 'system.getCapabilities',
+ 'this:getCapabilities',
+ array('struct'),
+ 'Returns a struct describing the XML-RPC specifications supported by this server'
+ );
+ $this->addCallback(
+ 'system.listMethods',
+ 'this:listMethods',
+ array('array'),
+ 'Returns an array of available methods on this server'
+ );
+ $this->addCallback(
+ 'system.methodHelp',
+ 'this:methodHelp',
+ array('string', 'string'),
+ 'Returns a documentation string for the specified method'
+ );
+ }
+ function addCallback($method, $callback, $args, $help) {
+ $this->callbacks[$method] = $callback;
+ $this->signatures[$method] = $args;
+ $this->help[$method] = $help;
+ }
+ function call($methodname, $args) {
+ // Make sure it's in an array
+ if ($args && !is_array($args)) {
+ $args = array($args);
+ }
+ // Over-rides default call method, adds signature check
+ if (!$this->hasMethod($methodname)) {
+ return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
+ }
+ $method = $this->callbacks[$methodname];
+ $signature = $this->signatures[$methodname];
+ $returnType = array_shift($signature);
+ // Check the number of arguments
+ if (count($args) != count($signature)) {
+ // print 'Num of args: '.count($args).' Num in signature: '.count($signature);
+ return new IXR_Error(-32602, 'server error. wrong number of method parameters');
+ }
+ // Check the argument types
+ $ok = true;
+ $argsbackup = $args;
+ for ($i = 0, $j = count($args); $i < $j; $i++) {
+ $arg = array_shift($args);
+ $type = array_shift($signature);
+ switch ($type) {
+ case 'int':
+ case 'i4':
+ if (is_array($arg) || !is_int($arg)) {
+ $ok = false;
+ }
+ break;
+ case 'base64':
+ case 'string':
+ if (!is_string($arg)) {
+ $ok = false;
+ }
+ break;
+ case 'boolean':
+ if ($arg !== false && $arg !== true) {
+ $ok = false;
+ }
+ break;
+ case 'float':
+ case 'double':
+ if (!is_float($arg)) {
+ $ok = false;
+ }
+ break;
+ case 'date':
+ case 'dateTime.iso8601':
+ if (!is_a($arg, 'IXR_Date')) {
+ $ok = false;
+ }
+ break;
+ }
+ if (!$ok) {
+ return new IXR_Error(-32602, 'server error. invalid method parameters');
+ }
+ }
+ // It passed the test - run the "real" method call
+ return parent::call($methodname, $argsbackup);
+ }
+ function methodSignature($method) {
+ if (!$this->hasMethod($method)) {
+ return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
+ }
+ // We should be returning an array of types
+ $types = $this->signatures[$method];
+ $return = array();
+ foreach ($types as $type) {
+ switch ($type) {
+ case 'string':
+ $return[] = 'string';
+ break;
+ case 'int':
+ case 'i4':
+ $return[] = 42;
+ break;
+ case 'double':
+ $return[] = 3.1415;
+ break;
+ case 'dateTime.iso8601':
+ $return[] = new IXR_Date(time());
+ break;
+ case 'boolean':
+ $return[] = true;
+ break;
+ case 'base64':
+ $return[] = new IXR_Base64('base64');
+ break;
+ case 'array':
+ $return[] = array('array');
+ break;
+ case 'struct':
+ $return[] = array('struct' => 'struct');
+ break;
+ }
+ }
+ return $return;
+ }
+ function methodHelp($method) {
+ return $this->help[$method];
+ }
+}
+
+
+class IXR_ClientMulticall extends IXR_Client {
+ var $calls = array();
+ function IXR_ClientMulticall($server, $path = false, $port = 80) {
+ parent::IXR_Client($server, $path, $port);
+ $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
+ }
+ function addCall() {
+ $args = func_get_args();
+ $methodName = array_shift($args);
+ $struct = array(
+ 'methodName' => $methodName,
+ 'params' => $args
+ );
+ $this->calls[] = $struct;
+ }
+ function query() {
+ // Prepare multicall, then call the parent::query() method
+ return parent::query('system.multicall', $this->calls);
+ }
+}
+
+?>
Index: /elgg/tags/20090118/mod/rpc/lib/class_rpc_config.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/class_rpc_config.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/class_rpc_config.php (revision 33)
@@ -0,0 +1,28 @@
+handlers["mapping"] = array();
+ $this->handlers["library"] = array();
+ }
+
+ function addMapping($mapping)
+ {
+ if(is_array($mapping))
+ {
+ $this->handlers["mapping"] = $this->handlers["mapping"] + $mapping;
+ }
+ }
+
+ function addLibrary($library)
+ {
+ $this->handlers["library"][] = $library;
+ }
+ }
+
+?>
Index: /elgg/tags/20090118/mod/rpc/lib/class_folder.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/class_folder.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/class_folder.php (revision 33)
@@ -0,0 +1,313 @@
+exists = false;
+
+ if ($var != "")
+ {
+ if (is_numeric($var))
+ {
+ $folder = get_record('file_folders','ident',$var);
+ }
+ else
+ {
+ $folder = get_record('file_folders','name',$var);
+ }
+
+ if (!empty($folder)) {
+ $this->ident = $folder->ident;
+ $this->owner = $folder->owner;
+ $this->files_owner = $folder->files_owner;
+ $this->parent = $folder->parent;
+ $this->name = $folder->name;
+ $this->access = $folder->access;
+
+ $this->exists = true;
+ }
+
+ if ($folder_childs = get_records('file_folders','parent',$var)) {
+ foreach ($folder_childs as $child) {
+ $this->child_folders[] = $child->ident;
+ }
+ }
+
+ if ($file_childs = get_records('files','parent',$var)) {
+ foreach ($file_childs as $child) {
+ $this->child_files[] = $child->ident;
+ }
+ }
+
+ if ($folder_tags = get_records('tags','tagtype','folder','ref',$var)) {
+ // An aray of Tag objects
+ foreach ($folder_tags as $tag) {
+ $this->tags[] = $tag->ident;
+ }
+ }
+ }
+ }
+
+ // Utility function
+ /**
+ *
+ */
+ function exists()
+ {
+ return $this->exists;
+ }
+
+ /**
+ * Returns path without leading $CFG->dataroot
+ */
+ function getPersonalStorage()
+ {
+ $textlib = textlib_get_instance();
+ // User's personal filesystem storage location
+ $user = run('users:instance', array('user_id' => $this->files_owner));
+ $this->username = $user->getUserName();
+
+ $personal_folder = 'files/' . $textlib->substr($this->username,0,1) . "/" . $this->username . "/";
+
+ return $personal_folder;
+ }
+
+ /**
+ *
+ */
+ function setupPersonalStorage()
+ {
+ global $CFG;
+
+ $textlib = textlib_get_instance();
+ // Finally, create the default user filesystem folder, if not available
+ $user = run('users:instance', array('user_id' => $this->owner));
+ $this->username = $user->getUserName();
+
+ $base_folder = $CFG->dataroot . 'files/' . $textlib->substr($this->username,0,1);
+ $personal_folder = $base_folder . "/" .$this->username;
+
+ if (!file_exists($base_folder))
+ {
+ mkdir($base_folder);
+ }
+
+ if (!file_exists($personal_folder))
+ {
+ mkdir($personal_folder);
+ }
+ }
+
+ /**
+ *
+ */
+ function getParent()
+ {
+ return $this->parent;
+ }
+
+ function getChildFolders()
+ {
+ return $this->child_folders;
+ }
+
+ /**
+ *
+ */
+ function getChildFiles()
+ {
+ return $this->child_files;
+ }
+
+ /**
+ *
+ */
+ function getOwner()
+ {
+ return $this->owner;
+ }
+
+ /**
+ *
+ */
+ function getFilesOwner()
+ {
+ return $this->files_owner;
+ }
+
+ /**
+ *
+ */
+ function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ *
+ */
+ function getAccess()
+ {
+ return $this->access;
+ }
+
+ /**
+ *
+ */
+ function setOwner($val)
+ {
+ $this->owner = $val;
+ }
+
+ /**
+ *
+ */
+ function setFilesOwner($val)
+ {
+ $this->files_owner = $val;
+ }
+
+ /**
+ *
+ */
+ function setParent($val)
+ {
+ $this->parent = $val;
+ }
+
+ /**
+ *
+ */
+ function setName($val)
+ {
+ $this->name = $val;
+ }
+
+ /**
+ *
+ */
+ function getTags()
+ {
+ return $this->tags;
+ }
+
+ /**
+ *
+ */
+ function deleteTags()
+ {
+ $value = false;
+
+ foreach ($this->tags as $tag_id)
+ {
+ $tag = run('tags:instance', array('id' => $tag_id));
+ $value = $tag->delete();
+ }
+
+ return $value;
+ }
+
+ /**
+ *
+ */
+ function getTag($tag_id)
+ {
+ return run('tags:instance', array("id" => $tag_id));
+ }
+
+ /**
+ *
+ */
+ function setAccess($val = "PUBLIC")
+ {
+ $this->access = $val;
+ }
+
+ /**
+ *
+ */
+ function save()
+ {
+ $this->setupPersonalStorage();
+ $ff = new StdClass;
+ $ff->parent = $this->parent;
+ $ff->name = $this->name;
+ $ff->access = $this->access;
+ if ($this->exists == true)
+ {
+ // Owner is still unmutable
+ $ff->ident = $this->ident;
+ if (update_record('file_folders',$ff)) {
+ return $this->ident;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ $ff->owner = $this->owner;
+ $ff->files_owner = $this->files_owner;
+ if ($this->ident = insert_record('file_folders',$ff)) {
+
+ $this->exists = true;
+
+ return $this->ident;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ function delete()
+ {
+ // TODO refactor to handle more sophisticated operations like cut, paste, move
+
+ // Also delete all subfolders and files
+ $deleted = delete_records('file_folders','ident',$this->ident);
+
+ // Delete tags
+ $this->deleteTags();
+
+ // Reassign the parent id, default Elgg action when parent folder is being deleted
+ foreach ($this->child_folders as $child)
+ {
+ $folder = run('folders:instance', array('id' => $child));
+ $folder->setParent($this->parent);
+ $folder->save();
+ }
+
+ // Reassign the parent id, default Elgg action when parent folder is being deleted
+ foreach ($this->child_files as $child)
+ {
+ $folder = run('filess:instance', array('id' => $child));
+ $folder->setParent($this->parent);
+ $folder->save();
+ }
+
+ return $deleted;
+ }
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/lib/class_tag.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/class_tag.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/class_tag.php (revision 33)
@@ -0,0 +1,154 @@
+exists = false;
+
+ // Parameter passed, assume an existing tag
+ if ($var != "")
+ {
+ if ($result = get_record('tags','ident',$var)) {
+ $this->ident = $result->ident;
+ $this->tag = $result->tag;
+ $this->tagtype = $result->tagtype;
+ $this->ref = $result->ref;
+ $this->access = $result->access;
+ $this->owner = $result->owner;
+
+ // Does the requested id exist
+ $this->exists = true;
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ function getTagName()
+ {
+ return $this->tag;
+ }
+
+ /**
+ *
+ */
+ function getTagType()
+ {
+ return $this->tagtype;
+ }
+
+ /**
+ *
+ */
+ function getRef()
+ {
+ return $this->ref;
+ }
+
+ /**
+ *
+ */
+ function getAccess()
+ {
+ return $this->access;
+ }
+
+ /**
+ *
+ */
+ function setTagName($val)
+ {
+ $this->tag = trim($val);
+ }
+
+ /**
+ *
+ */
+ function setTagType($val = "weblog")
+ {
+ $this->tagtype = $val;
+ }
+
+ /**
+ *
+ */
+ function setRef($val)
+ {
+ $this->ref = $val;
+ }
+
+ /**
+ *
+ */
+ function setAccess($val = "PUBLIC")
+ {
+ $this->access = $val;
+ }
+
+ /**
+ *
+ */
+ function setOwner($val)
+ {
+ $this->owner = $val;
+ }
+
+ /**
+ *
+ */
+ function delete()
+ {
+ if ($this->exists == true)
+ {
+ return delete_records('tags','ident',$this->ident);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ *
+ */
+ function save()
+ {
+ $t = new StdClass;
+ $t->tagtype = 'weblog';
+ $t->access = $this->access;
+ $t->tag = $this->tag;
+ $t->ref = $this->ref;
+ $t->owner = $this->owner;
+ // Always delete existing tags
+ if ($this->exists == false)
+ {
+ if ($this->ident = insert_record('tags',$t)) {
+ $this->exists = true;
+ return $this->ident;
+ }
+ return false;
+ }
+ else
+ {
+ $t->ident = $this->ident;
+ if (update_record('tags',$t)) {
+ return $this->ident;
+ }
+ return false;
+ }
+ }
+ }
+?>
Index: /elgg/tags/20090118/mod/rpc/lib/class_user.php
===================================================================
--- /elgg/tags/20090118/mod/rpc/lib/class_user.php (revision 33)
+++ /elgg/tags/20090118/mod/rpc/lib/class_user.php (revision 33)
@@ -0,0 +1,384 @@
+exists = false;
+
+ // Both username or userid may be passed
+ if (is_numeric($var))
+ {
+ // Numeric, we probably received a userid
+ $info = get_record('users','ident',$var);
+ }
+ elseif(is_string($var))
+ {
+ // String, we probably recieved a username
+ $info = get_record('users','username',$var);
+ }
+
+ if (!empty($info)) {
+ $this->exists = true;
+
+ $this->ident = $info->ident;
+ $this->username = $info->username;
+ $this->email = $info->email;
+ $this->name = user_name($info->ident);
+ $this->alias = $info->alias;
+ $this->code = $info->code;
+ $this->icon_quota = $info->icon_quota;
+ $this->file_quota = $info->file_quota;
+ $this->user_type = $info->user_type;
+ $this->owner = $info->owner;
+
+ ereg('^([a-zA-Z]*) (.*)', $this->name, $groups);
+ $this->firstname = trim($groups[1]);
+ $this->lastname = trim($groups[2]);
+
+ // Load the weblog id's, starting with communities
+
+ // Need to select two fields to collect instead of just u.ident else
+ // this very handy datalib function will return false...
+ $communities = get_records_sql('SELECT DISTINCT u.ident,u.name
+ FROM '.$CFG->prefix.'friends f
+ JOIN '.$CFG->prefix.'users u
+ ON u.ident = f.friend
+ WHERE f.owner = ?
+ AND u.user_type = ?',array($this->ident,'community'));
+
+ $this->blogs = array();
+
+ // Add the own weblog id (is same as user id)
+ $this->blogs[] = $this->ident;
+
+ // Add the communities
+ if ($communities) {
+ foreach($communities as $community) {
+ $this->blogs[] = $community->ident;
+ }
+ }
+
+ $this->icon = user_icon_html($info->ident,100,true);
+ }
+ }
+
+ /**
+ *
+ */
+ function exists()
+ {
+ return $this->exists;
+ }
+
+ /**
+ *
+ */
+ function getUserName()
+ {
+ return $this->username;
+ }
+
+ /**
+ *
+ */
+ function getEmail()
+ {
+ return $this->email;
+ }
+
+ /**
+ *
+ */
+ function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ *
+ */
+ function getAlias()
+ {
+ return $this->alias;
+ }
+
+ /**
+ *
+ */
+ function getCode()
+ {
+ return $this->code;
+ }
+
+
+ {{usericon}}{{postedname}} on {{posted}} # | {{links}} +
+