]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added an ElggBlog class to override the time_created field.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 23 Mar 2010 19:25:14 +0000 (19:25 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 23 Mar 2010 19:25:14 +0000 (19:25 +0000)
Added extra language files.

git-svn-id: http://code.elgg.org/elgg/trunk@5486 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/blog/actions/blog/auto_save_revision.php
mod/blog/actions/blog/save.php
mod/blog/blog_lib.php
mod/blog/languages/en.php
mod/blog/start.php
mod/blog/views/default/blog/forms/edit.php
mod/blog/views/default/object/blog.php

index fa9010e90c36b4e923d2c91b16bf621868408925..a67939e9f6c394a48b8244aa583b9d4faa5cc3bf 100644 (file)
@@ -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.
index 0ca063496610aa38fdd8b8e705ba4ce32042fafb..eca711f60c3257f3d122cb2fd29458bbe9e8ab3f 100644 (file)
@@ -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;
 
index 993728dcc7f2d3d4a263c0e587facd13ac72a0e1..6f52e53ec91b6153ab776ae2d3383e9f7df46b4f 100644 (file)
@@ -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
index 4d448856e414918838042fc47f9cecfff3f7f4f1..8a7f7d8dc6d66428e6ce9f0291cb2c7f2fa1b755 100644 (file)
@@ -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
index 0015efcf17d21a27689ab6ae0a81ca0f28ee477c..d0c4c515743105af2991dd00b84b852d141d7d96 100644 (file)
@@ -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');
 
@@ -59,6 +62,15 @@ function blog_init() {
        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:
@@ -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);
                }
        }
 }
index 83ee8208e80e9f4baa560665db0e54c8b8b7114b..b2b494c7a4bdb642c88913349a26ee53a25f42ce 100644 (file)
@@ -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
index 3df1813fa005bc771e81b7939b8c710ad511f353..fb996fb19f6b012e7432df3ff8c55e852b164e2d 100644 (file)
@@ -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">