aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-23 19:25:14 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-23 19:25:14 +0000
commitb3e6ac6960e56001d80243f694fe2109211a5fce (patch)
treef8dfebc35a3fabda7a615b389b8758b88358f63b /mod
parentc71f11c1b7a4a2ee634acd50582e5202da5389cc (diff)
downloadelgg-b3e6ac6960e56001d80243f694fe2109211a5fce.tar.gz
elgg-b3e6ac6960e56001d80243f694fe2109211a5fce.tar.bz2
Added an ElggBlog class to override the time_created field.
Added extra language files. git-svn-id: http://code.elgg.org/elgg/trunk@5486 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod')
-rw-r--r--mod/blog/actions/blog/auto_save_revision.php2
-rw-r--r--mod/blog/actions/blog/save.php5
-rw-r--r--mod/blog/blog_lib.php128
-rw-r--r--mod/blog/languages/en.php5
-rw-r--r--mod/blog/start.php16
-rw-r--r--mod/blog/views/default/blog/forms/edit.php4
-rw-r--r--mod/blog/views/default/object/blog.php2
7 files changed, 47 insertions, 115 deletions
diff --git a/mod/blog/actions/blog/auto_save_revision.php b/mod/blog/actions/blog/auto_save_revision.php
index fa9010e90..a67939e9f 100644
--- a/mod/blog/actions/blog/auto_save_revision.php
+++ b/mod/blog/actions/blog/auto_save_revision.php
@@ -33,7 +33,7 @@ if ($title && $description) {
$error = elgg_echo('blog:error:post_not_found');
}
} else {
- $blog = new ElggObject();
+ $blog = new ElggBlog();
$blog->subtype = 'blog';
// force draft and private for autosaves.
diff --git a/mod/blog/actions/blog/save.php b/mod/blog/actions/blog/save.php
index 0ca063496..eca711f60 100644
--- a/mod/blog/actions/blog/save.php
+++ b/mod/blog/actions/blog/save.php
@@ -34,7 +34,7 @@ if ($guid) {
$revision_value = $blog->description;
$new_post = FALSE;
} else {
- $blog = new ElggObject();
+ $blog = new ElggBlog();
$blog->subtype = 'blog';
$success_forward_url = get_input('forward');
$new_post = TRUE;
@@ -100,9 +100,10 @@ foreach ($values as $name => $default) {
break;
case 'publish_date':
- if (empty($value)) {
+ if (!$value = strtotime($value)) {
$value = time();
}
+
$values[$name] = $value;
break;
diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php
index 993728dcc..6f52e53ec 100644
--- a/mod/blog/blog_lib.php
+++ b/mod/blog/blog_lib.php
@@ -98,120 +98,34 @@ function blog_get_page_content_edit($guid, $revision = NULL) {
}
/**
- * Saves a blog
- *
- * @param array $info An array of name=>value pairs to save to the blog entity
+ * Returns an appropriate excerpt for a blog.
*
- * @return array('success' => BOOL, 'message' => string);
+ * @param string $text
+ * @return string
*/
-function blog_save_blog($info) {
- // store errors to pass along
- $error = FALSE;
-
- if ($info['guid']) {
- $entity = get_entity($info['guid']);
- if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
- $blog = $entity;
- } else {
- $error = elgg_echo('blog:error:post_not_found');
- }
- } else {
- $blog = new ElggObject();
- $blog->subtype = 'blog';
- }
-
- // check required vars
- $required = array('title', 'description');
-
- // load from POST and do sanity and access checking
- foreach ($info as $name => $value) {
- if (in_array($name, $required) && empty($value)) {
- $error = elgg_echo("blog:error:missing:$name");
- }
-
- if ($error) {
- break;
- }
-
- switch ($name) {
- case 'tags':
- if ($value) {
- $info[$name] = string_to_tag_array($value);
- } else {
- unset ($info[$name]);
- }
- break;
-
- case 'excerpt':
- // restrict to 300 chars
- if ($value) {
- $value = substr(strip_tags($value), 0, 300);
- } else {
- $value = substr(strip_tags($info['description']), 0, 300);
- }
- $info[$name] = $value;
- break;
-
- case 'container_guid':
- // this can't be empty.
- if (!empty($value)) {
- if (can_write_to_container($user->getGUID(), $value)) {
- $info[$name] = $value;
- } else {
- $error = elgg_echo("blog:error:cannot_write_to_container");
- }
- } else {
- unset($info[$name]);
- }
- break;
+function blog_make_excerpt($text) {
+ return substr(strip_tags($text), 0, 300);
+}
- // don't try to set the guid
- case 'guid':
- unset($info['guid']);
- break;
+/**
+ * Extended class to override the time_created
+ */
+class ElggBlog extends ElggObject {
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
- default:
- $info[$name] = $value;
- break;
- }
+ // override the default file subtype.
+ $this->attributes['subtype'] = 'blog';
}
- // assign values to the entity, stopping on error.
- if (!$error) {
- foreach ($info as $name => $value) {
- if (!$blog->$name = $value) {
- $error = elgg_echo('blog:error:cannot_save');
- break;
- }
+ /**
+ * Override the value returned for time_created
+ */
+ public function __get($name) {
+ if ($name == 'time_created') {
+ $name = 'time_created';
}
- }
-
- // only try to save base entity if no errors
- if (!$error && !$blog->save()) {
- $error = elgg_echo('blog:error:cannot_save');
- }
- if ($error) {
- $return = array(
- 'success' => FALSE,
- 'message' => $error
- );
- } else {
- $return = array(
- 'success' => TRUE,
- 'message' => elgg_echo('blog:message:saved')
- );
+ return $this->get($name);
}
-
- return $return;
-}
-
-/**
- * Returns an appropriate excerpt for a blog.
- *
- * @param string $text
- * @return string
- */
-function blog_make_excerpt($text) {
- return substr(strip_tags($text), 0, 300);
} \ No newline at end of file
diff --git a/mod/blog/languages/en.php b/mod/blog/languages/en.php
index 4d448856e..8a7f7d8dc 100644
--- a/mod/blog/languages/en.php
+++ b/mod/blog/languages/en.php
@@ -28,17 +28,22 @@ $english = array(
'blog:status' => 'Status',
'blog:status:draft' => 'Draft',
'blog:status:published' => 'Published',
+ 'blog:status:unsaved_draft' => 'Recovered Draft',
'blog:revision' => 'Revision',
'blog:auto_saved_revision' => 'Auto Saved Revision',
+ 'blog:owner_title' => '%s\'s blogs',
// messages
'blog:message:saved' => 'Blog post saved.',
'blog:error:cannot_save' => 'Cannot save blog post.',
'blog:error:cannot_write_to_container' => 'Insufficient access to save blog to group.',
+ 'blog:error:post_not_found' => 'This post has been removed or is invalid.',
'blog:messages:warning:draft' => 'There is an unsaved draft of this post!',
'blog:edit_revision_notice' => '(Old version)',
+
+
);
add_translation('en', $english); \ No newline at end of file
diff --git a/mod/blog/start.php b/mod/blog/start.php
index 0015efcf1..d0c4c5157 100644
--- a/mod/blog/start.php
+++ b/mod/blog/start.php
@@ -29,7 +29,10 @@ function blog_init() {
global $CONFIG;
require_once dirname(__FILE__) . '/blog_lib.php';
- add_menu(elgg_echo('blog'), "{$CONFIG->wwwroot}pg/blog/", array());
+ add_menu(elgg_echo('blog:blogs'), "{$CONFIG->wwwroot}pg/blog/", array());
+
+ // run the setup upon activations or to upgrade old installations.
+ run_function_once('blog_runonce', '1269370108');
elgg_extend_view('css', 'blog/css');
@@ -60,6 +63,15 @@ function blog_init() {
}
/**
+ * Register entity class for object:blog -> ElggBlog
+ */
+function blog_runonce() {
+ if (!update_subtype('object', 'blog', 'ElggBlog')) {
+ add_subtype('object', 'blog', 'ElggBlog');
+ }
+}
+
+/**
* Dispatches blog pages.
* To maintain URL backward compatibility, expects old-style URLs like:
* pg/blog/[username/[read|edit|archive|new/[time_start|guid/[time_end|title]]]]
@@ -176,7 +188,7 @@ function blog_page_setup() {
if ($page_owner instanceof ElggGroup && get_context() == 'groups') {
if($page_owner->blog_enable != "no") {
$url = "{$CONFIG->wwwroot}pg/blog/{$page_owner->username}/items";
- add_submenu_item(elgg_echo("blog:groups:group_blogs"), $url);
+ add_submenu_item(elgg_echo('blog:groups:group_blogs'), $url);
}
}
}
diff --git a/mod/blog/views/default/blog/forms/edit.php b/mod/blog/views/default/blog/forms/edit.php
index 83ee8208e..b2b494c7a 100644
--- a/mod/blog/views/default/blog/forms/edit.php
+++ b/mod/blog/views/default/blog/forms/edit.php
@@ -33,7 +33,7 @@ $draft_warning = '';
if (isset ($vars['entity'])) {
$blog = $vars['entity'];
- if ($blog && ($blog instanceof ElggObject) && ($blog->getSubtype() == 'blog')) {
+ if (elgg_instanceof($blog, 'object', 'blog')) {
// passed in values override sticky values in input views
// if in a sticky form, don't send the overrides and let the view figure it out.
//if (!elgg_is_sticky_form()) {
@@ -140,7 +140,7 @@ $publish_date_label = elgg_echo('blog:publish_date');
$publish_date_input = elgg_view('input/datepicker', array(
'internalname' => 'publish_date',
'internalid' => 'blog_publish_date',
- 'value' => $vars['publish_date']
+ 'value' => $values['publish_date']
));
// hidden inputs
diff --git a/mod/blog/views/default/object/blog.php b/mod/blog/views/default/object/blog.php
index 3df1813fa..fb996fb19 100644
--- a/mod/blog/views/default/object/blog.php
+++ b/mod/blog/views/default/object/blog.php
@@ -66,7 +66,7 @@ if ($full) {
$comments = '';
}
$like = elgg_view_likes($blog);
- $owner_title = sprintf(elgg_echo('blog:owner_title'), $user->name);
+ $owner_title = sprintf(elgg_echo('blog:owner_title'), $owner->name);
echo <<<___END
<div class="blogpost clearfloat">