From 8761800b92a6eb4bf3df361091cb85bb8459e959 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 4 Dec 2010 22:51:37 +0000 Subject: Fixes #2519 we can now register and load php libraries - blog plugin is using this git-svn-id: http://code.elgg.org/elgg/trunk@7532 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/blog/blog_lib.php | 287 -------------------------------------------------- mod/blog/lib/blog.php | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++ mod/blog/start.php | 16 +-- 3 files changed, 295 insertions(+), 295 deletions(-) delete mode 100644 mod/blog/blog_lib.php create mode 100644 mod/blog/lib/blog.php (limited to 'mod/blog') diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php deleted file mode 100644 index 4db3effde..000000000 --- a/mod/blog/blog_lib.php +++ /dev/null @@ -1,287 +0,0 @@ -status != 'published' && !$blog->canEdit())) { - $return['content'] = elgg_echo('blog:error:post_not_found'); - } else { - elgg_push_breadcrumb($blog->title, $blog->getURL()); - $return['content'] = elgg_view_entity($blog, TRUE); - //check to see if comment are on - if ($blog->comments_on != 'Off') { - $return['content'] .= elgg_view_comments($blog); - } - } - } else { - - $return['filter_context'] = $owner_guid ? 'mine' : 'everyone'; - - $options = array( - 'type' => 'object', - 'subtype' => 'blog', - 'full_view' => FALSE, - //'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int') - ); - - $loggedin_userid = get_loggedin_userid(); - if ($owner_guid) { - $options['owner_guid'] = $owner_guid; -/* - if ($owner_guid != $loggedin_userid) { - // do not show content header when viewing other users' posts - $content = elgg_view('page_elements/content_header_member', array('type' => 'blog')); - } - * - */ - } - - // show all posts for admin or users looking at their own blogs - // show only published posts for other users. - if (!(isadminloggedin() || (isloggedin() && $owner_guid == $loggedin_userid))) { - $options['metadata_name_value_pairs'] = array( - array('name' => 'status', 'value' => 'published'), - //array('name' => 'publish_date', 'operand' => '<', 'value' => time()) - ); - } - - $list = elgg_list_entities_from_metadata($options); - if (!$list) { - $return['content'] = elgg_echo('blog:none'); - } else { - $return['content'] = $list; - } - } - - return $return; -} - -/** - * Returns HTML to edit a blog post. - * - * @param int $guid - * @param int annotation id optional revision to edit - * @return string html - */ -function blog_get_page_content_edit($guid, $revision = NULL) { - $vars = array(); - if ($guid) { - $blog = get_entity((int)$guid); - - if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { - $vars['entity'] = $blog; - - if ($revision) { - $revision = get_annotation((int)$revision); - $vars['revision'] = $revision; - - if (!$revision || !($revision->entity_guid == $guid)) { - $content = elgg_echo('blog:error:revision_not_found'); - } - } - - elgg_push_breadcrumb($blog->title, $blog->getURL()); - elgg_push_breadcrumb(elgg_echo('edit')); - - $content = elgg_view('blog/forms/edit', $vars); - $sidebar = elgg_view('blog/sidebar_revisions', array('entity' => $blog)); - //$sidebar .= elgg_view('blog/sidebar_related'); - } else { - $content = elgg_echo('blog:error:post_not_found'); - } - } else { - elgg_push_breadcrumb(elgg_echo('blog:new')); - $content = elgg_view('blog/forms/edit', $vars); - //$sidebar = elgg_view('blog/sidebar_related'); - } - - return array( - 'content' => $content, - 'sidebar' => $sidebar, - 'header' => '', - 'filter' => '', - ); -} - -/** - * Show blogs with publish dates between $lower and $upper - * - * @param unknown_type $owner_guid - * @param unknown_type $lower - * @param unknown_type $upper - */ -function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) { - global $CONFIG; - - $now = time(); - - elgg_push_breadcrumb(elgg_echo('blog:archives')); - $content = elgg_view('page_elements/content_header_member', array('type' => 'blog')); - - if ($lower) { - $lower = (int)$lower; - } - - if ($upper) { - $upper = (int)$upper; - } - - $options = array( - 'type' => 'object', - 'subtype' => 'blog', - 'full_view' => FALSE, - 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'), - ); - - if ($owner_guid) { - $options['owner_guid'] = $owner_guid; - } - - // admin / owners can see any posts - // everyone else can only see published posts - if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { - if ($upper > $now) { - $upper = $now; - } - - $options['metadata_name_value_pairs'] = array( - array('name' => 'status', 'value' => 'published') - ); - } - - if ($lower) { - $options['metadata_name_value_pairs'][] = array( - 'name' => 'publish_date', - 'operand' => '>', - 'value' => $lower - ); - } - - if ($upper) { - $options['metadata_name_value_pairs'][] = array( - 'name' => 'publish_date', - 'operand' => '<', - 'value' => $upper - ); - } - - $list = elgg_list_entities_from_metadata($options); - if (!$list) { - $content .= elgg_echo('blog:none'); - } else { - $content .= $list; - } - - return array( - 'content' => $content, - 'filter' => '', - 'header' => '', - ); -} - -/** - * Returns a view of the user's friend's posts. - * - * @param int $user_guid - * @return string - */ -function blog_get_page_content_friends($user_guid) { - global $CONFIG; - - elgg_push_breadcrumb(elgg_echo('friends')); - - $return = array(); - - $return['filter_context'] = 'friends'; - - if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { - $return['content'] .= elgg_echo('friends:none:you'); - return $return; - } else { - $options = array( - 'type' => 'object', - 'subtype' => 'blog', - 'full_view' => FALSE, - 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'), - ); - - foreach ($friends as $friend) { - $options['container_guids'][] = $friend->getGUID(); - } - - // admin / owners can see any posts - // everyone else can only see published posts - if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { - if ($upper > $now) { - $upper = $now; - } - - $options['metadata_name_value_pairs'][] = array( - array('name' => 'status', 'value' => 'published') - ); - } - - $list = elgg_list_entities_from_metadata($options); - if (!$list) { - $return['content'] = elgg_echo('blog:none'); - } else { - $return['content'] = $list; - } - } - - return $return; -} - -/** - * Returns a list of years and months for all blogs optionally for a user. - * Very similar to get_entity_dates() except uses a metadata field. - * - * @param mixed $user_guid - */ -function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) { - global $CONFIG; - - $subtype = get_subtype_id('object', 'blog'); - - $q = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(mdv.string)) AS yearmonth - FROM {$CONFIG->dbprefix}entities e, {$CONFIG->dbprefix}metadata, {$CONFIG->dbprefix}metastrings mdn, {$CONFIG->dbprefix}metastrings mdv - WHERE e.guid = {$CONFIG->dbprefix}metadata.entity_guid - AND {$CONFIG->dbprefix}metadata.name_id = mdn.id - AND {$CONFIG->dbprefix}metadata.value_id = mdv.id - AND mdn.string = 'publish_date'"; - - if ($user_guid) { - $user_guid = (int)$user_guid; - $q .= " AND e.owner_guid = $user_guid"; - } - - if ($container_guid) { - $container_guid = (int)$container_guid; - $q .= " AND e.container_guid = $container_guid"; - } - - $q .= ' AND ' . get_access_sql_suffix('e'); - - return get_data($q); -} diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php new file mode 100644 index 000000000..4db3effde --- /dev/null +++ b/mod/blog/lib/blog.php @@ -0,0 +1,287 @@ +status != 'published' && !$blog->canEdit())) { + $return['content'] = elgg_echo('blog:error:post_not_found'); + } else { + elgg_push_breadcrumb($blog->title, $blog->getURL()); + $return['content'] = elgg_view_entity($blog, TRUE); + //check to see if comment are on + if ($blog->comments_on != 'Off') { + $return['content'] .= elgg_view_comments($blog); + } + } + } else { + + $return['filter_context'] = $owner_guid ? 'mine' : 'everyone'; + + $options = array( + 'type' => 'object', + 'subtype' => 'blog', + 'full_view' => FALSE, + //'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int') + ); + + $loggedin_userid = get_loggedin_userid(); + if ($owner_guid) { + $options['owner_guid'] = $owner_guid; +/* + if ($owner_guid != $loggedin_userid) { + // do not show content header when viewing other users' posts + $content = elgg_view('page_elements/content_header_member', array('type' => 'blog')); + } + * + */ + } + + // show all posts for admin or users looking at their own blogs + // show only published posts for other users. + if (!(isadminloggedin() || (isloggedin() && $owner_guid == $loggedin_userid))) { + $options['metadata_name_value_pairs'] = array( + array('name' => 'status', 'value' => 'published'), + //array('name' => 'publish_date', 'operand' => '<', 'value' => time()) + ); + } + + $list = elgg_list_entities_from_metadata($options); + if (!$list) { + $return['content'] = elgg_echo('blog:none'); + } else { + $return['content'] = $list; + } + } + + return $return; +} + +/** + * Returns HTML to edit a blog post. + * + * @param int $guid + * @param int annotation id optional revision to edit + * @return string html + */ +function blog_get_page_content_edit($guid, $revision = NULL) { + $vars = array(); + if ($guid) { + $blog = get_entity((int)$guid); + + if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) { + $vars['entity'] = $blog; + + if ($revision) { + $revision = get_annotation((int)$revision); + $vars['revision'] = $revision; + + if (!$revision || !($revision->entity_guid == $guid)) { + $content = elgg_echo('blog:error:revision_not_found'); + } + } + + elgg_push_breadcrumb($blog->title, $blog->getURL()); + elgg_push_breadcrumb(elgg_echo('edit')); + + $content = elgg_view('blog/forms/edit', $vars); + $sidebar = elgg_view('blog/sidebar_revisions', array('entity' => $blog)); + //$sidebar .= elgg_view('blog/sidebar_related'); + } else { + $content = elgg_echo('blog:error:post_not_found'); + } + } else { + elgg_push_breadcrumb(elgg_echo('blog:new')); + $content = elgg_view('blog/forms/edit', $vars); + //$sidebar = elgg_view('blog/sidebar_related'); + } + + return array( + 'content' => $content, + 'sidebar' => $sidebar, + 'header' => '', + 'filter' => '', + ); +} + +/** + * Show blogs with publish dates between $lower and $upper + * + * @param unknown_type $owner_guid + * @param unknown_type $lower + * @param unknown_type $upper + */ +function blog_get_page_content_archive($owner_guid, $lower=0, $upper=0) { + global $CONFIG; + + $now = time(); + + elgg_push_breadcrumb(elgg_echo('blog:archives')); + $content = elgg_view('page_elements/content_header_member', array('type' => 'blog')); + + if ($lower) { + $lower = (int)$lower; + } + + if ($upper) { + $upper = (int)$upper; + } + + $options = array( + 'type' => 'object', + 'subtype' => 'blog', + 'full_view' => FALSE, + 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'), + ); + + if ($owner_guid) { + $options['owner_guid'] = $owner_guid; + } + + // admin / owners can see any posts + // everyone else can only see published posts + if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { + if ($upper > $now) { + $upper = $now; + } + + $options['metadata_name_value_pairs'] = array( + array('name' => 'status', 'value' => 'published') + ); + } + + if ($lower) { + $options['metadata_name_value_pairs'][] = array( + 'name' => 'publish_date', + 'operand' => '>', + 'value' => $lower + ); + } + + if ($upper) { + $options['metadata_name_value_pairs'][] = array( + 'name' => 'publish_date', + 'operand' => '<', + 'value' => $upper + ); + } + + $list = elgg_list_entities_from_metadata($options); + if (!$list) { + $content .= elgg_echo('blog:none'); + } else { + $content .= $list; + } + + return array( + 'content' => $content, + 'filter' => '', + 'header' => '', + ); +} + +/** + * Returns a view of the user's friend's posts. + * + * @param int $user_guid + * @return string + */ +function blog_get_page_content_friends($user_guid) { + global $CONFIG; + + elgg_push_breadcrumb(elgg_echo('friends')); + + $return = array(); + + $return['filter_context'] = 'friends'; + + if (!$friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) { + $return['content'] .= elgg_echo('friends:none:you'); + return $return; + } else { + $options = array( + 'type' => 'object', + 'subtype' => 'blog', + 'full_view' => FALSE, + 'order_by_metadata' => array('name'=>'publish_date', 'direction'=>'DESC', 'as'=>'int'), + ); + + foreach ($friends as $friend) { + $options['container_guids'][] = $friend->getGUID(); + } + + // admin / owners can see any posts + // everyone else can only see published posts + if (!(isadminloggedin() || (isloggedin() && $owner_guid == get_loggedin_userid()))) { + if ($upper > $now) { + $upper = $now; + } + + $options['metadata_name_value_pairs'][] = array( + array('name' => 'status', 'value' => 'published') + ); + } + + $list = elgg_list_entities_from_metadata($options); + if (!$list) { + $return['content'] = elgg_echo('blog:none'); + } else { + $return['content'] = $list; + } + } + + return $return; +} + +/** + * Returns a list of years and months for all blogs optionally for a user. + * Very similar to get_entity_dates() except uses a metadata field. + * + * @param mixed $user_guid + */ +function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) { + global $CONFIG; + + $subtype = get_subtype_id('object', 'blog'); + + $q = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(mdv.string)) AS yearmonth + FROM {$CONFIG->dbprefix}entities e, {$CONFIG->dbprefix}metadata, {$CONFIG->dbprefix}metastrings mdn, {$CONFIG->dbprefix}metastrings mdv + WHERE e.guid = {$CONFIG->dbprefix}metadata.entity_guid + AND {$CONFIG->dbprefix}metadata.name_id = mdn.id + AND {$CONFIG->dbprefix}metadata.value_id = mdv.id + AND mdn.string = 'publish_date'"; + + if ($user_guid) { + $user_guid = (int)$user_guid; + $q .= " AND e.owner_guid = $user_guid"; + } + + if ($container_guid) { + $container_guid = (int)$container_guid; + $q .= " AND e.container_guid = $container_guid"; + } + + $q .= ' AND ' . get_access_sql_suffix('e'); + + return get_data($q); +} diff --git a/mod/blog/start.php b/mod/blog/start.php index 0d0c58ac8..9e3b8f300 100644 --- a/mod/blog/start.php +++ b/mod/blog/start.php @@ -14,14 +14,14 @@ * Notifications */ +elgg_register_event_handler('init', 'system', 'blog_init'); + /** * Init blog plugin. - * - * @return TRUE */ function blog_init() { - global $CONFIG; - require_once dirname(__FILE__) . '/blog_lib.php'; + + elgg_register_library('elgg:blog', elgg_get_plugin_path() . 'blog/lib/blog.php'); add_menu(elgg_echo('blog:blogs'), "pg/blog/", array()); @@ -47,8 +47,8 @@ function blog_init() { //add_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description'), 'profile, dashboard'); - $action_path = dirname(__FILE__) . '/actions/blog'; - + // register actions + $action_path = elgg_get_plugin_path() . 'blog/actions/blog'; elgg_register_action('blog/save', "$action_path/save.php"); elgg_register_action('blog/auto_save_revision', "$action_path/auto_save_revision.php"); elgg_register_action('blog/delete', "$action_path/delete.php"); @@ -92,6 +92,8 @@ function blog_runonce() { function blog_page_handler($page) { global $CONFIG; + elgg_load_library('elgg:blog'); + // push breadcrumb elgg_push_breadcrumb(elgg_echo('blog:blogs'), "pg/blog"); @@ -201,5 +203,3 @@ function blog_profile_menu($hook, $entity_type, $return_value, $params) { return $return_value; } - -elgg_register_event_handler('init', 'system', 'blog_init'); -- cgit v1.2.3