예제 #1
0
 /**
  * Binds the post data
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function bindPost(EasyBlogPost &$post, $data, $publish)
 {
     $config = EB::config();
     $acl = EB::acl();
     $my = JFactory::getUser();
     $postData = array();
     // Default properties
     $postData['doctype'] = EASYBLOG_POST_DOCTYPE_LEGACY;
     $postData['title'] = '';
     $postData['intro'] = '';
     $postData['content'] = '';
     $postData['tags'] = array();
     $postData['allowcomment'] = true;
     $postData['published'] = EASYBLOG_POST_PUBLISHED;
     $postData['created'] = EB::date()->toSql();
     $postData['publish_up'] = $postData['created'];
     $postData['created_by'] = $my->id;
     $postData['access'] = false;
     // Should these be read from configuration?
     $postData['frontpage'] = true;
     $postData['send_notification_emails'] = true;
     // Post title
     // title
     if (isset($data['title']) && !empty($data['title'])) {
         $postData['title'] = $data['title'];
     }
     // Tags from marsedit
     // mt_tags
     if (isset($data['mt_tags']) && !empty($data['mt_tags'])) {
         if (is_array($data['mt_tags'])) {
             $data['mt_tags'] = implode(',', $data['mt_tags']);
         }
         $postData['tags'] = $data['mt_tags'];
     }
     // Keywords could possibly be used as tags
     // mt_keywords
     if (!$postData['tags'] && isset($data['mt_keywords']) && $data['mt_keywords']) {
         $postData['tags'] = $data['mt_keywords'];
     }
     // Post status from mars edit
     // post_status
     if (isset($data['post_status'])) {
         $status = $data['post_status'];
         if ($status == 'publish' || $status == 'private') {
             $postData['published'] = EASYBLOG_POST_PUBLISHED;
         }
         if ($status == 'private' || $status == 'pending') {
             $postData['private'] = true;
         }
         if ($status == 'draft') {
             $postData['published'] = EASYBLOG_POST_UNPUBLISHED;
         }
         if ($status == 'schedule') {
             $postData['published'] = EASYBLOG_POST_SCHEDULED;
         }
     }
     // Determines if the post allow comments
     // mt_allow_comments
     if (isset($data['mt_allow_comments'])) {
         if (is_numeric($data['mt_allow_comments'])) {
             $postData['allowcomment'] = $data['mt_allow_comments'] == 1;
         } else {
             $postData['allowcomment'] = $data['mt_allow_comments'] == 'open';
         }
     }
     // Post content
     // description
     if (isset($data['description']) && !empty($data['description'])) {
         $postData['intro'] = $data['description'];
     }
     // If intro text is still empty, try to check for mt_excerpt
     if (!$postData['intro'] && isset($data['mt_excerpt']) && !empty($data['mt_excerpt'])) {
         $postData['intro'] = $data['mt_excerpt'];
     }
     // Main content
     // mt_text_more
     if (isset($data['mt_text_more']) && !empty($data['mt_text_more'])) {
         $postData['content'] = $data['mt_text_more'];
     }
     if (!$postData['content'] && isset($data['more_text']) && $data['more_text']) {
         $postData['content'] = $data['more_text'];
     }
     // Wordpress API? Doesn't seem like we need this
     // mt_convert_breaks
     // Wordpress API? Permalink?
     // wp_slug
     if (isset($data['wp_slug']) && !empty($data['wp_slug'])) {
         $postData['permalink'] = $data['wp_slug'];
     }
     // Get the timestamp from the post
     if (isset($data['date_created_gmt']) && $data['date_created_gmt']) {
         $date = EB::date($data['date_created_gmt']);
         $postData['created'] = $date->toSql();
     }
     // If user wants to set a custom date for the creation date
     if (isset($data['dateCreated']) && $data['dateCreated']) {
         $now = EB::date();
         $tsNow = $now->toUnix();
         $date = EB::date($data['dateCreated']);
         // We need to add additional 10 seconds becuse blogsy is always 5s faster
         $tsDate = $date->toUnix() + 10;
         if ($tsDate > $tsNow) {
             $postData['published'] = EASYBLOG_POST_SCHEDULED;
             $postData['created'] = $now->toSql();
             $postData['publish_up'] = $date->toSql();
         } else {
             $postData['created'] = $date->toSql();
         }
     }
     // Bind the post data now
     $post->bind($postData);
 }