$error = elgg_echo('blog:error:post_not_found');
}
} else {
- $blog = new ElggObject();
+ $blog = new ElggBlog();
$blog->subtype = 'blog';
// force draft and private for autosaves.
$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;
break;
case 'publish_date':
- if (empty($value)) {
+ if (!$value = strtotime($value)) {
$value = time();
}
+
$values[$name] = $value;
break;
}
/**
- * 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
'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
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');
register_action('blog/delete', FALSE, "$action_path/delete.php");
}
+/**
+ * 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:
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);
}
}
}
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()) {
$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
$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">