Index: /elgg/tags/20081112/mod/export/blogashtml.php =================================================================== --- /elgg/tags/20081112/mod/export/blogashtml.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/export/blog.php =================================================================== --- /elgg/tags/20081112/mod/export/blog.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/export/lib.php =================================================================== --- /elgg/tags/20081112/mod/export/lib.php (revision 33) +++ /elgg/tags/20081112/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 + + + <![CDATA[$name : $rssweblog]]> + + {$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 + + + <![CDATA[$title]]> + $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/20081112/mod/generic_comments/comment =================================================================== --- /elgg/tags/20081112/mod/generic_comments/comment (revision 33) +++ /elgg/tags/20081112/mod/generic_comments/comment (revision 33) @@ -0,0 +1,8 @@ +
  • + {{body}} +
    +

    + {{usericon}}{{postedname}} on {{posted}} # | {{links}} +

    +
    +
  • Index: /elgg/tags/20081112/mod/generic_comments/mysql.sql =================================================================== --- /elgg/tags/20081112/mod/generic_comments/mysql.sql (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/generic_comments/comment_page.php =================================================================== --- /elgg/tags/20081112/mod/generic_comments/comment_page.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/generic_comments/comments =================================================================== --- /elgg/tags/20081112/mod/generic_comments/comments (revision 33) +++ /elgg/tags/20081112/mod/generic_comments/comments (revision 33) @@ -0,0 +1,9 @@ +
    +

    {{comments_str}}

    +
    {{paging}}
    +
      + {{comments}} +
    +
    {{paging}}
    +
    + Index: /elgg/tags/20081112/mod/generic_comments/css =================================================================== --- /elgg/tags/20081112/mod/generic_comments/css (revision 33) +++ /elgg/tags/20081112/mod/generic_comments/css (revision 33) @@ -0,0 +1,3 @@ +/* + * Generic comments CSS file + */ Index: /elgg/tags/20081112/mod/generic_comments/action_redirection.php =================================================================== --- /elgg/tags/20081112/mod/generic_comments/action_redirection.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/generic_comments/comments_actions.php =================================================================== --- /elgg/tags/20081112/mod/generic_comments/comments_actions.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/generic_comments/postgres7.sql =================================================================== --- /elgg/tags/20081112/mod/generic_comments/postgres7.sql (revision 36) +++ /elgg/tags/20081112/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/20081112/mod/generic_comments/generic_comments.js =================================================================== --- /elgg/tags/20081112/mod/generic_comments/generic_comments.js (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/generic_comments/lib.php =================================================================== --- /elgg/tags/20081112/mod/generic_comments/lib.php (revision 33) +++ /elgg/tags/20081112/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 $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 + +
    + +

    $comment_form_text

    + +END; + + // $field = display_input_field(array("new_comment","","longtext")); + $field = <<< END + + + +END; + 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; + + // 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/20081112/mod/generic_comments/permissions_check.php =================================================================== --- /elgg/tags/20081112/mod/generic_comments/permissions_check.php (revision 33) +++ /elgg/tags/20081112/mod/generic_comments/permissions_check.php (revision 33) @@ -0,0 +1,18 @@ + Index: /elgg/tags/20081112/mod/commentwall/mysql.sql =================================================================== --- /elgg/tags/20081112/mod/commentwall/mysql.sql (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/commentwall/replyto.php =================================================================== --- /elgg/tags/20081112/mod/commentwall/replyto.php (revision 33) +++ /elgg/tags/20081112/mod/commentwall/replyto.php (revision 33) @@ -0,0 +1,14 @@ + Index: /elgg/tags/20081112/mod/commentwall/do_action.php =================================================================== --- /elgg/tags/20081112/mod/commentwall/do_action.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/commentwall/lib/commentwall_settings.php =================================================================== --- /elgg/tags/20081112/mod/commentwall/lib/commentwall_settings.php (revision 33) +++ /elgg/tags/20081112/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 + +END; + + $run_result .= templates_draw(array( + 'context' => 'databox', + 'name' => __gettext("Access level: "), + 'column1' => $select_box + ) + ); +?> Index: /elgg/tags/20081112/mod/commentwall/README.txt =================================================================== --- /elgg/tags/20081112/mod/commentwall/README.txt (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/commentwall/post.php =================================================================== --- /elgg/tags/20081112/mod/commentwall/post.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/commentwall/postgres7.sql =================================================================== --- /elgg/tags/20081112/mod/commentwall/postgres7.sql (revision 36) +++ /elgg/tags/20081112/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/20081112/mod/commentwall/template =================================================================== --- /elgg/tags/20081112/mod/commentwall/template (revision 33) +++ /elgg/tags/20081112/mod/commentwall/template (revision 33) @@ -0,0 +1,14 @@ +
    +
    + +
    + +
    +
    {{usertxt}}
    +
    {{date}}
    +
    {{text}}
    +
    {{replybar}}
    +
    +
    Index: /elgg/tags/20081112/mod/commentwall/lib.php =================================================================== --- /elgg/tags/20081112/mod/commentwall/lib.php (revision 105) +++ /elgg/tags/20081112/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 +
    + +
    + $frm_elements_common +
    +
    +
    +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 = "

    " . sprintf(__gettext("%s's comment wall"), user_info("name", page_owner())) . "

    "; + + if (($showalltxt) && ($wall)) + { + $html .= "
    wwwroot}mod/commentwall/index.php?owner=$owner\">" . __gettext("See all...") . "
    "; + } + + + $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 = "
    "; + + $html .= commentwall_displaywall_html($wall, true, $owner); + + $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/20081112/mod/commentwall/commentwall.js =================================================================== --- /elgg/tags/20081112/mod/commentwall/commentwall.js (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/commentwall/index.php =================================================================== --- /elgg/tags/20081112/mod/commentwall/index.php (revision 33) +++ /elgg/tags/20081112/mod/commentwall/index.php (revision 33) @@ -0,0 +1,31 @@ + Index: /elgg/tags/20081112/mod/commentwall/footer =================================================================== --- /elgg/tags/20081112/mod/commentwall/footer (revision 33) +++ /elgg/tags/20081112/mod/commentwall/footer (revision 33) @@ -0,0 +1,3 @@ + Index: /elgg/tags/20081112/mod/blog/rss2.php =================================================================== --- /elgg/tags/20081112/mod/blog/rss2.php (revision 33) +++ /elgg/tags/20081112/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 + + + <![CDATA[$name : $rssweblog]]> + + $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/20081112/mod/blog/friends.php =================================================================== --- /elgg/tags/20081112/mod/blog/friends.php (revision 33) +++ /elgg/tags/20081112/mod/blog/friends.php (revision 33) @@ -0,0 +1,27 @@ +' . $body . ''; + + templates_page_output($title, $body); + +?> Index: /elgg/tags/20081112/mod/blog/interesting.php =================================================================== --- /elgg/tags/20081112/mod/blog/interesting.php (revision 33) +++ /elgg/tags/20081112/mod/blog/interesting.php (revision 33) @@ -0,0 +1,27 @@ +' . $body . ''; + +templates_page_output($title, $body); + +?> Index: /elgg/tags/20081112/mod/blog/LICENSE =================================================================== --- /elgg/tags/20081112/mod/blog/LICENSE (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/blog/everyone.php =================================================================== --- /elgg/tags/20081112/mod/blog/everyone.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/blog/templates_preview.php =================================================================== --- /elgg/tags/20081112/mod/blog/templates_preview.php (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/blog/action_redirection.php =================================================================== --- /elgg/tags/20081112/mod/blog/action_redirection.php (revision 33) +++ /elgg/tags/20081112/mod/blog/action_redirection.php (revision 33) @@ -0,0 +1,12 @@ + Index: /elgg/tags/20081112/mod/blog/widget_css =================================================================== --- /elgg/tags/20081112/mod/blog/widget_css (revision 33) +++ /elgg/tags/20081112/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/20081112/mod/blog/lib.php =================================================================== --- /elgg/tags/20081112/mod/blog/lib.php (revision 129) +++ /elgg/tags/20081112/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 "\"default"; + } + 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"; + + $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 .= "
    "; + $body .= "

    " . $post->title . "

    "; + $body .= "

    " . strftime("%B %d, %Y", $post->posted) . "

    "; + $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_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($grp as $option){ + $run_result .="