Beispiel #1
0
 function write()
 {
     $document = JFactory::getDocument();
     $config = EasyBlogHelper::getConfig();
     $mainframe = JFactory::getApplication();
     $acl = EasyBlogACLHelper::getRuleSet();
     $siteAdmin = EasyBlogHelper::isSiteAdmin();
     $my = JFactory::getUser();
     // set the editor title based on operation
     $editorTitle = '';
     // just to inform the view that this is edit operation
     $showDraftStatus = true;
     $isEdit = false;
     if (!EasyBlogHelper::isLoggedIn()) {
         EasyBlogHelper::showLogin();
         return;
     }
     if (!EasyBlogRouter::isCurrentActiveMenu('dashboard')) {
         $this->setPathway(JText::_('COM_EASYBLOG_DASHBOARD_BREADCRUMB'), EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard'));
     }
     $this->setPathway(JText::_('COM_EASYBLOG_DASHBOARD_WRITE_BREADCRUMB'));
     if (!$acl->rules->add_entry) {
         $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard', false), JText::_('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG'));
         $mainframe->close();
     }
     // enable datetime picker
     EasyBlogDateHelper::enableDateTimePicker();
     // Add the Calendar includes to the document <head> section
     JHTML::_('behavior.calendar');
     // Add modal behavior
     JHTML::_('behavior.modal');
     // Load the JEditor object
     if ($config->get('layout_editor_author')) {
         // Get user's parameters
         $userParams = EasyBlogHelper::getRegistry($my->params);
         $editorType = $userParams->get('editor', $config->get('layout_editor'));
         $editor = JFactory::getEditor($editorType);
     } else {
         $editor = JFactory::getEditor($config->get('layout_editor'));
     }
     $user = EasyBlogHelper::getTable('Profile', 'Table');
     $user->setUser($my);
     $model = $this->getModel('Blog');
     $categoriesModel = $this->getModel('Categories');
     $publishedOnly = true;
     $categoryItems = $categoriesModel->getParentCategories('', 'all', $publishedOnly, true);
     $categories = array();
     if ($categoryItems) {
         foreach ($categoryItems as $categoryItem) {
             $category = EasyBlogHelper::getTable('Category');
             $category->bind($categoryItem);
             $categories[] = $category;
         }
     }
     $trackbacksModel = $this->getModel('TrackbackSent');
     $blogContributed = '';
     $trackbacks = '';
     $external = '';
     $extGroupId = '';
     // @task: See if there's any uid in the query string.
     // @since 3.5
     $source = JRequest::getVar('source');
     $uid = JRequest::getInt('uid');
     // get blogid if exists
     $blogId = JRequest::getVar('blogid', '');
     // Test if draft id exists
     $draftId = JRequest::getVar('draft_id', '');
     // test if this is a under approval post or not.
     $underApproval = JRequest::getVar('approval', '');
     // Load blog table
     $blog = EasyBlogHelper::getTable('Blog', 'Table');
     $blog->load($blogId);
     // Test if this blog belongs to the team and the current browser is the team admin.
     $teamblogModel = $this->getModel('TeamBlogs');
     $teamContribution = $teamblogModel->getBlogContributed($blog->id);
     // Check if the person has access to create a new blog post
     if ($blog->id && $blog->created_by != $my->id && !$siteAdmin && empty($acl->rules->moderate_entry) && !$teamContribution) {
         $url = 'index.php?option=com_easyblog&view=dashboard';
         $mainframe->redirect(EasyBlogRouter::_($url, false), JText::_('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG'));
     }
     // This will be the team blog checking
     $isCurrentTeamAdmin = false;
     if ($teamContribution && !$siteAdmin && empty($acl->rules->moderate_entry)) {
         $isCurrentTeamAdmin = $teamblogModel->checkIsTeamAdmin($my->id, $teamContribution->team_id);
         // Test if the user has access to this team posting.
         if (!$isCurrentTeamAdmin && $blog->created_by != $my->id) {
             $url = 'index.php?option=com_easyblog&view=dashboard';
             $mainframe->redirect(EasyBlogRouter::_($url, false), JText::_('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG'));
         }
     }
     $tmpBlogData = EasyBlogHelper::getSession('tmpBlogData');
     $loadFromSession = false;
     $blogSource = '';
     if (isset($tmpBlogData)) {
         $loadFromSession = true;
         $blog->bind($tmpBlogData);
         // reprocess the date offset here.
         $tzoffset = EasyBlogDateHelper::getOffSet();
         if (!empty($blog->created)) {
             $date = EasyBlogHelper::getDate($blog->created, $tzoffset);
             $blog->created = $date->toMySQL();
         }
         if (!empty($blog->publish_up) && $blog->publish_up != '0000-00-00 00:00:00') {
             $date = EasyBlogHelper::getDate($blog->publish_up, $tzoffset);
             $blog->publish_up = $date->toMySQL();
         }
         if (!empty($blog->publish_down) && $blog->publish_down != '0000-00-00 00:00:00') {
             $date = EasyBlogHelper::getDate($blog->publish_down, $tzoffset);
             $blog->publish_down = $date->toMySQL();
         }
         //bind the content from previous form
         $blog->content = $tmpBlogData['write_content'];
         $blog->tags = array();
         if (isset($tmpBlogData['tags'])) {
             $blog->tags = $this->bindTags($tmpBlogData['tags']);
         }
         // metas
         $meta = new stdClass();
         $meta->id = '';
         $meta->keywords = isset($tmpBlogData['keywords']) ? $tmpBlogData['keywords'] : '';
         $meta->description = isset($tmpBlogData['description']) ? $tmpBlogData['description'] : '';
         if (isset($tmpBlogData['blog_contribute'])) {
             $blogContributed = $this->bindContribute($tmpBlogData['blog_contribute']);
         }
         $contributionSource = isset($tmpBlogData['blog_contribute_source']) ? $tmpBlogData['blog_contribute_source'] : '';
         if (!empty($contributionSource) && $contributionSource != 'easyblog' && !$uid) {
             $external = true;
             $extGroupId = $tmpBlogData['blog_contribute'];
             $blogSource = 'group';
         }
         if (!empty($contributionSource) && $contributionSource != 'easyblog' && $uid && $source == 'jomsocial.event') {
             $external = true;
             $uid = $tmpBlogData['blog_contribute'];
             $blogSource = 'event';
         }
     }
     // Check if this is an edited post and if it has draft.
     $draft = EasyBlogHelper::getTable('Draft', 'Table');
     $isDraft = false;
     if (!empty($draftId)) {
         $draft->load($draftId);
         $blog->load($draft->entry_id);
         $blog->bind($draft);
         $blog->tags = empty($draft->tags) ? array() : $this->bindTags(explode(',', $draft->tags));
         // metas
         $meta = new stdClass();
         $meta->id = '';
         $meta->keywords = $draft->metakey;
         $meta->description = $draft->metadesc;
         if (!empty($draft->trackbacks)) {
             $blog->unsaveTrackbacks = $draft->trackbacks;
         }
         if ($draft->blog_contribute) {
             $blogContributed = $this->bindContribute($draft->blog_contribute);
         }
         $blog->tags = array();
         if (!empty($draft->tags)) {
             $blog->tags = $this->bindTags(explode(',', $draft->tags));
         }
         $blog->set('id', $draft->entry_id);
         $blogId = $blog->id;
         $isDraft = true;
     } else {
         // We only want to load drafts that has a blog id.
         if ($blog->id) {
             $draft->loadByEntry($blog->id);
         }
     }
     // set page title
     if (!empty($blogId)) {
         $title = EasyBlogHelper::getPageTitle(JText::_('COM_EASYBLOG_DASHBOARD_EDIT_POST'));
         // @task: Set the page title
         parent::setPageTitle($title, false, $config->get('main_pagetitle_autoappend'));
         $editorTitle = JText::_('COM_EASYBLOG_DASHBOARD_EDIT_POST');
         // check if previous status is not Draft
         if ($blog->published == POST_ID_DRAFT) {
             $showDraftStatus = true;
         }
         $isEdit = true;
         //perform some title string formatting
         $blog->title = $this->escape($blog->title);
     } else {
         $title = EasyBlogHelper::getPageTitle(JText::_('COM_EASYBLOG_DASHBOARD_WRITE_POST'));
         // @task: Set the page title
         parent::setPageTitle($title, false, $config->get('main_pagetitle_autoappend'));
         $editorTitle = JText::_('COM_EASYBLOG_DASHBOARD_WRITE_POST');
         // set the default publishing status only if it is a brand new creation page.
         if (!$loadFromSession && !$isDraft) {
             // by default, all new post MUST BE set to draft
             $blog->published = $config->get('main_blogpublishing', '3');
         }
     }
     //get all tags ever created.
     $newTagsModel = $this->getModel('Tags');
     $blog->newtags = $newTagsModel->getTags();
     //prepare initial blog settings.
     $isPrivate = $config->get('main_blogprivacy', '0');
     $allowComment = $config->get('main_comment', 1);
     $allowSubscribe = $config->get('main_subscription', 1);
     $showFrontpage = $config->get('main_newblogonfrontpage', 0);
     $sendEmails = $config->get('main_sendemailnotifications', 1);
     $isSiteWide = isset($blog->issitewide) ? $blog->issitewide : '1';
     $teamblogModel = $this->getModel('TeamBlogs');
     $teams = !empty($blog->created_by) ? $teamblogModel->getTeamJoined($blog->created_by) : $teamblogModel->getTeamJoined($my->id);
     if (!empty($blog->id)) {
         $isPrivate = $blog->private;
         $allowComment = $blog->allowcomment;
         $allowSubscribe = $config->get('main_subscription') ? $blog->subscription : 0;
         $showFrontpage = $blog->frontpage;
         $sendEmails = $blog->send_notification_emails;
         //get user teamblog
         $teams = $teamblogModel->getTeamJoined($blog->created_by);
         //@task: List all trackbacks
         $trackbacks = $trackbacksModel->getSentTrackbacks($blogId);
     }
     if ($loadFromSession || $isDraft) {
         $isPrivate = $blog->private;
         $allowComment = $blog->allowcomment;
         $allowSubscribe = $blog->subscription;
         $showFrontpage = $blog->frontpage;
         $sendEmails = $blog->send_notification_emails;
     }
     $author = null;
     //if site admin then get get blog creator and include a javascript function to change author.
     if ($siteAdmin || !empty($acl->rules->moderate_entry) || isset($teamContribution) && $isCurrentTeamAdmin) {
         if (!empty($blog->created_by)) {
             $creator = JFactory::getUser($blog->created_by);
             $author = EasyBlogHelper::getTable('Profile', 'Table');
             $author->setUser($creator);
             unset($creator);
         }
     }
     //check if can upload image or not.
     $useImageManager = $config->get('main_media_manager', 1);
     if (!isset($meta)) {
         $meta = new stdClass();
         $meta->id = '';
         $meta->keywords = '';
         $meta->description = '';
     }
     if (empty($blog->created_by) || $blog->created_by == $my->id || $siteAdmin || !empty($acl->rules->moderate_entry) || $teamContribution) {
         $blog->tags = isset($blog->tags) && !empty($blog->tags) ? $blog->tags : array();
         if (!$loadFromSession && !$isDraft) {
             // get the tag only if it is not loaded from the session value
             if ($blogId) {
                 $tagsModel = $this->getModel('PostTag');
                 $blog->tags = $tagsModel->getBlogTags($blogId);
                 // get meta tags
                 $metaModel = $this->getModel('Metas');
                 $meta = $metaModel->getPostMeta($blogId);
             }
         }
         $onlyPublished = empty($blogId) ? true : false;
         $isFrontendWrite = true;
         $nestedCategories = '';
         $defaultCategory = JRequest::getInt('categoryId');
         $menu = JFactory::getApplication()->getMenu()->getActive();
         if ($menu && isset($menu->params)) {
             $param = EasyBlogHelper::getRegistry();
             $param->load($menu->params);
             $catId = $param->get('categoryId');
             if ($catId) {
                 $defaultCategory = $catId;
             }
         }
         // @task: If blog is being edited, it should contain a category_id property.
         $defaultCategory = empty($blog->category_id) ? $defaultCategory : $blog->category_id;
         if ($config->get('layout_dashboardcategoryselect') == 'select') {
             $nestedCategories = EasyBlogHelper::populateCategories('', '', 'select', 'category_id', $defaultCategory, true, $onlyPublished, $isFrontendWrite);
         }
         echo $this->showToolbar(__FUNCTION__, $user);
         $tpl = new CodeThemes('dashboard');
         $blogger_id = !isset($blog->created_by) ? $user->id : $blog->created_by;
         $content = $blog->intro;
         // Append the readmore if necessary
         if (!empty($blog->intro) && !empty($blog->content)) {
             $content .= '<hr id="system-readmore" />';
         }
         $content .= $blog->content;
         $defaultCategoryName = '';
         if (empty($defaultCategory)) {
             //get default category if configured.
             $defaultCategory = EasyBlogHelper::getDefaultCategoryId();
         }
         if (!empty($defaultCategory)) {
             $categoryTbl = EasyBlogHelper::getTable('Category');
             $categoryTbl->load($defaultCategory);
             $defaultCategoryName = $categoryTbl->title;
         }
         if ($draft->id != 0 && $isDraft) {
             if (!empty($draft->external_source)) {
                 $external = true;
                 $extGroupId = $draft->external_group_id;
             }
         } else {
             if (!$loadFromSession) {
                 // If writing is for an external source, we need to tell the editor to strip down some unwanted features
                 $external = JRequest::getVar('external', false);
                 //check if this is a external group contribution.
                 $extGroupId = EasyBlogHelper::getHelper('Groups')->getGroupContribution($blog->id);
                 if (!empty($extGroupId)) {
                     $external = $extGroupId;
                     $blogSource = 'group';
                 }
                 if (!empty($uid)) {
                     $external = $uid;
                     $blogSource = 'event';
                 }
                 $externalEventId = EasyBlogHelper::getHelper('Event')->getContribution($blog->id);
                 if (!empty($externalEventId)) {
                     $external = $externalEventId;
                     $blogSource = 'event';
                 }
             }
         }
         // If there's a tag (maybe from the draft area, we need to add the tags data back)
         if ($isDraft && !empty($blog->tags)) {
             $blog->newtags = array_merge($blog->newtags, $blog->tags);
         }
         // Add the breadcrumbs
         $breadcrumbs = array($editorTitle => '');
         $tpl->set('teamContribution', $teamContribution);
         $tpl->set('isCurrentTeamAdmin', $isCurrentTeamAdmin);
         $tpl->set('breadcrumbs', $breadcrumbs);
         $tpl->set('external', $external);
         $tpl->set('extGroupId', $extGroupId);
         $tpl->set('defaultCategory', $defaultCategory);
         $tpl->set('defaultCategoryName', $defaultCategoryName);
         $tpl->set('content', $content);
         $tpl->set('blogger_id', $blogger_id);
         $tpl->set('draft', $draft);
         $tpl->set('isDraft', $isDraft);
         $tpl->set('isPending', $underApproval);
         $tpl->set('isEdit', $isEdit);
         $tpl->set('showDraftStatus', $showDraftStatus);
         $tpl->set('editorTitle', $editorTitle);
         $tpl->set('meta', $meta);
         $tpl->set('editor', $editor);
         $tpl->set('trackbacks', $trackbacks);
         $tpl->set('categories', $categories);
         $tpl->set('blog', $blog);
         $tpl->set('user', $user);
         $tpl->set('isPrivate', $isPrivate);
         $tpl->set('allowComment', $allowComment);
         $tpl->set('subscription', $allowSubscribe);
         $tpl->set('trackbacks', $trackbacks);
         $tpl->set('frontpage', $showFrontpage);
         $tpl->set('author', $author);
         $tpl->set('useImageManager', $useImageManager);
         $tpl->set('nestedCategories', $nestedCategories);
         $tpl->set('teams', $teams);
         $tpl->set('isSiteWide', $isSiteWide);
         $tpl->set('send_notification_emails', $sendEmails);
         // @since: 3.5
         // The unique external source and id.
         $tpl->set('blogSource', $blogSource);
         $tpl->set('source', $source);
         $tpl->set('uid', $uid);
         // @since: 3.6
         // Media manager options
         $tpl->set('session', JFactory::getSession());
         // Load media manager and get info about the files.
         require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
         $mediamanager = new EasyBlogMediaManager();
         $userFolders = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'user'), 'folders');
         $userFiles = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'user'), 'files');
         $sharedFolders = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'shared'), 'folders');
         $sharedFiles = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'shared'), 'files');
         $tpl->set('userFolders', $userFolders);
         $tpl->set('userFiles', $userFiles);
         $tpl->set('sharedFolders', $sharedFolders);
         $tpl->set('sharedFiles', $sharedFiles);
         // @rule: Test if the user is already associated with Flickr
         $oauth = EasyBlogHelper::getTable('Oauth');
         $associated = $oauth->loadByUser($my->id, EBLOG_OAUTH_FLICKR);
         $tpl->set('flickrAssociated', $associated);
         echo $tpl->fetch('dashboard.write.php');
     } else {
         $mainframe->redirect(EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard', false), JText::_('COM_EASYBLOG_NO_PERMISSION_TO_EDIT_BLOG'), 'error');
     }
 }
Beispiel #2
0
 /**
  * Generates a html code for category selection.
  *
  * @access	public
  * @param	int		$parentId	if this option spcified, it will list the parent and all its childs categories.
  * @param	int		$userId		if this option specified, it only return categories created by this userId
  * @param	string	$outType	The output type. Currently supported links and drop down selection
  * @param	string	$eleName	The element name of this populated categeries provided the outType os dropdown selection.
  * @param	string	$default	The default selected value. If given, it used at dropdown selection (auto select)
  * @param	boolean	$isWrite	Determine whether the categories list used in write new page or not.
  * @param	boolean	$isPublishedOnly	If this option is true, only published categories will fetched.
  * @param	array 	$exclusion	A list of excluded categories that it should not be including
  */
 public static function populateCategories($parentId, $userId, $outType, $eleName, $default, $isWrite = false, $isPublishedOnly = false, $isFrontendWrite = false, $exclusion = array(), $attributes = '')
 {
     $catModel = EB::model('Category');
     $parentCat = null;
     if (!empty($userId)) {
         $parentCat = $catModel->getParentCategories($userId, 'blogger', $isPublishedOnly, $isFrontendWrite, $exclusion);
     } else {
         if (!empty($parentId)) {
             $parentCat = $catModel->getParentCategories($parentId, 'category', $isPublishedOnly, $isFrontendWrite, $exclusion);
         } else {
             $parentCat = $catModel->getParentCategories('', 'all', $isPublishedOnly, $isFrontendWrite, $exclusion);
         }
     }
     $ignorePrivate = false;
     switch ($outType) {
         case 'link':
             $ignorePrivate = false;
             break;
         case 'popup':
         case 'select':
         default:
             $ignorePrivate = true;
             break;
     }
     // Now let's do a loop to find it's child categories.
     if (!empty($parentCat)) {
         for ($i = 0; $i < count($parentCat); $i++) {
             $parent =& $parentCat[$i];
             //reset
             $parent->childs = null;
             EasyBlogHelper::buildNestedCategories($parent->id, $parent, $ignorePrivate, $isPublishedOnly, $isFrontendWrite, $exclusion);
         }
     }
     if ($isWrite) {
         $defaultCatId = EasyBlogHelper::getDefaultCategoryId();
         $default = empty($default) ? $defaultCatId : $default;
     }
     $formEle = '';
     if ($outType == 'select' && $isWrite) {
         $selected = !$default ? ' selected="selected"' : '';
         $formEle .= '<option value="0"' . $selected . '>' . JText::_('COM_EASYBLOG_SELECT_A_CATEGORY') . '</option>';
     }
     if ($parentCat) {
         foreach ($parentCat as $category) {
             if ($outType == 'popup') {
                 $formEle .= '<div class="category-list-item" id="' . $category->id . '"><a href="javascript:void(0);" onclick="eblog.dashboard.selectCategory(\'' . $category->id . '\')">' . $category->title . '</a>';
                 $formEle .= '<input type="hidden" id="category-list-item-' . $category->id . '" value="' . $category->title . '" />';
                 $formEle .= '</div>';
             } else {
                 $selected = $category->id == $default ? ' selected="selected"' : '';
                 $formEle .= '<option value="' . $category->id . '" ' . $selected . '>' . JText::_($category->title) . '</option>';
             }
             EasyBlogHelper::accessNestedCategories($category, $formEle, '0', $default, $outType);
         }
     }
     $html = '';
     $html .= '<select name="' . $eleName . '" id="' . $eleName . '" class="form-control" ' . $attributes . '>';
     if (!$isWrite) {
         $html .= '<option value="0">' . JText::_('COM_EASYBLOG_SELECT_PARENT_CATEGORY') . '</option>';
     }
     $html .= $formEle;
     $html .= '</select>';
     return $html;
 }
Beispiel #3
0
 function display($tpl = null)
 {
     // @rule: Test for user access if on 1.6 and above
     if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
         if (!JFactory::getUser()->authorise('easyblog.manage.blog', 'com_easyblog')) {
             JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'), 'error');
             JFactory::getApplication()->close();
         }
     }
     // Load the front end language file.
     $lang = JFactory::getLanguage();
     $lang->load('com_easyblog', JPATH_ROOT);
     // Initial variables.
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $app = JFactory::getApplication();
     $acl = EasyBlogACLHelper::getRuleSet();
     $config = EasyBlogHelper::getConfig();
     // Load the JEditor object
     $editor = JFactory::getEditor($config->get('layout_editor', 'tinymce'));
     // Enable datetime picker
     EasyBlogDateHelper::enableDateTimePicker();
     // required variable initiation.
     $meta = null;
     $blogContributed = array();
     $tags = null;
     $external = '';
     $extGroupId = '';
     // Event id state.
     $externalEventId = '';
     //Load blog table
     $blogId = JRequest::getVar('blogid', '');
     $blog = EasyBlogHelper::getTable('Blog', 'Table');
     $blog->load($blogId);
     $tmpBlogData = EasyBlogHelper::getSession('tmpBlogData');
     $loadFromSession = false;
     // Initialize default tags.
     $blog->tags = array();
     if (isset($tmpBlogData)) {
         $loadFromSession = true;
         $blog->bind($tmpBlogData);
         // reprocess the date offset here.
         $tzoffset = EasyBlogDateHelper::getOffSet();
         if (!empty($blog->created)) {
             $date = EasyBlogHelper::getDate($blog->created, $tzoffset);
             $blog->created = $date->toMySQL();
         }
         if (!empty($blog->publish_up) && $blog->publish_up != '0000-00-00 00:00:00') {
             $date = EasyBlogHelper::getDate($blog->publish_up, $tzoffset);
             $blog->publish_up = $date->toMySQL();
         }
         if (!empty($blog->publish_down) && $blog->publish_down != '0000-00-00 00:00:00') {
             $date = EasyBlogHelper::getDate($blog->publish_down, $tzoffset);
             $blog->publish_down = $date->toMySQL();
         }
         //bind the content from previous form
         $blog->content = $tmpBlogData['write_content'];
         if (isset($tmpBlogData['tags'])) {
             $blog->tags = $this->bindTags($tmpBlogData['tags']);
         }
         // metas
         $meta = new stdClass();
         $meta->id = '';
         $meta->keywords = isset($tmpBlogData['keywords']) ? $tmpBlogData['keywords'] : '';
         $meta->description = isset($tmpBlogData['description']) ? $tmpBlogData['description'] : '';
         if (isset($tmpBlogData['blog_contribute'])) {
             $blogContributed = $this->bindContribute($tmpBlogData['blog_contribute']);
         }
         $contributionSource = isset($tmpBlogData['blog_contribute_source']) ? $tmpBlogData['blog_contribute_source'] : '';
         if (!empty($contributionSource) && $contributionSource != 'easyblog') {
             $external = true;
             $extGroupId = $tmpBlogData['blog_contribute'];
             $externalEventId = $tmpBlogData['blog_contribute'];
         }
         $blog->unsaveTrackbacks = '';
         if (!empty($tmpBlogData['trackback'])) {
             $blog->unsaveTrackbacks = $tmpBlogData['trackback'];
         }
     }
     $draft = EasyBlogHelper::getTable('Draft', 'Table');
     $draft_id = JRequest::getVar('draft_id', '');
     $isDraft = false;
     $pending_approval = JRequest::getVar('approval', '');
     if (!empty($draft_id)) {
         //first check if the logged in user have the required acl or not.
         if (empty($acl->rules->add_entry) || empty($acl->rules->publish_entry) || empty($acl->rules->manage_pending)) {
             $message = JText::_('COM_EASYBLOG_BLOGS_BLOG_NO_PERMISSION_TO_CREATE_BLOG');
             $app->enqueueMessage($message, 'error');
             $app->redirect(JRoute::_('index.php?option=com_easyblog&view=blogs', false));
         }
         $draft->load($draft_id);
         $blog->load($draft->entry_id);
         $blog->bind($draft);
         $blog->tags = $this->bindTags(explode(',', $draft->tags));
         $blog->newtags = $blog->tags;
         $tags = $blog->tags;
         // metas
         $meta = new stdClass();
         $meta->id = '';
         $meta->keywords = $draft->metakey;
         $meta->description = $draft->metadesc;
         $blog->unsaveTrackbacks = '';
         if (!empty($draft->trackbacks)) {
             $blog->unsaveTrackbacks = $draft->trackbacks;
         }
         if ($draft->blog_contribute) {
             $blogContributed = $this->bindContribute($draft->blog_contribute);
         }
         $blog->set('id', $draft->entry_id);
         $blogId = $blog->id;
         $isDraft = true;
     }
     // set page title
     if (!empty($blogId)) {
         $doc->setTitle(JText::_('COM_EASYBLOG_BLOGS_EDIT_POST') . ' - ' . $config->get('main_title'));
         $editorTitle = JText::_('COM_EASYBLOG_BLOGS_EDIT_POST');
         // check if previous status is not Draft
         if ($blog->published != POST_ID_DRAFT) {
             $isEdit = true;
         }
     } else {
         $doc->setTitle(JText::_('COM_EASYBLOG_BLOGS_NEW_POST'));
         $editorTitle = JText::_('COM_EASYBLOG_BLOGS_NEW_POST');
         if (!$loadFromSession && !$isDraft) {
             // set to 'publish' for new blog in backend.
             $blog->published = $config->get('main_blogpublishing', '1');
         }
     }
     $author = null;
     if (!empty($blog->created_by)) {
         $creator = JFactory::getUser($blog->created_by);
         $author = EasyBlogHelper::getTable('Profile', 'Table');
         $author->setUser($creator);
         unset($creator);
     } else {
         $creator = JFactory::getUser($my->id);
         $author = EasyBlogHelper::getTable('Profile', 'Table');
         $author->setUser($creator);
         unset($creator);
     }
     //Get tag
     if (!$loadFromSession && !$isDraft) {
         $tagModel = EasyBlogHelper::getModel('PostTag', true);
         $tags = $tagModel->getBlogTags($blogId);
     }
     $tagsArray = array();
     if ($tags) {
         foreach ($tags as $data) {
             $tagsArray[] = $data->title;
         }
         $tagsString = implode(",", $tagsArray);
     }
     //prepare initial blog settings.
     $isPrivate = $config->get('main_blogprivacy', '0');
     $allowComment = $config->get('main_comment', 1);
     $allowSubscribe = $config->get('main_subscription', 1);
     $showFrontpage = $config->get('main_newblogonfrontpage', 0);
     $sendEmails = $config->get('main_sendemailnotifications', 0);
     $isSiteWide = isset($blog->issitewide) ? $blog->issitewide : '1';
     $tbModel = EasyBlogHelper::getModel('TeamBlogs', true);
     $teamBlogJoined = $tbModel->getTeamJoined($author->id);
     if (!empty($blog->id)) {
         $isPrivate = $blog->private;
         $allowComment = $blog->allowcomment;
         $allowSubscribe = $blog->subscription;
         $showFrontpage = $blog->frontpage;
         $sendEmails = $blog->send_notification_emails;
         //get user teamblog
         $teamBlogJoined = $tbModel->getTeamJoined($blog->created_by);
         if (!$isDraft) {
             $blogContributed = $tbModel->getBlogContributed($blog->id);
         }
     }
     if ($loadFromSession || $isDraft) {
         $isPrivate = $blog->private;
         $allowComment = $blog->allowcomment;
         $allowSubscribe = $blog->subscription;
         $showFrontpage = $blog->frontpage;
         $sendEmails = $blog->send_notification_emails;
     }
     if (count($blogContributed) > 0 && $blogContributed) {
         for ($i = 0; $i < count($teamBlogJoined); $i++) {
             $joined = $teamBlogJoined[$i];
             if ($joined->team_id == $blogContributed->team_id) {
                 $joined->selected = 1;
                 continue;
             }
         }
     }
     //get all tags ever created.
     $newTagsModel = EasyBlogHelper::getModel('Tags');
     if (isset($blog->newtags)) {
         $blog->newtags = array_merge($blog->newtags, $newTagsModel->getTags());
     } else {
         $blog->newtags = $newTagsModel->getTags();
     }
     //get tags used in this blog post
     if (!$loadFromSession && !$isDraft && $blogId) {
         $tagsModel = EasyBlogHelper::getModel('PostTag');
         $blog->tags = $tagsModel->getBlogTags($blogId);
     }
     //@task: List all trackbacks
     $trackbacksModel = EasyBlogHelper::getModel('TrackbackSent');
     $trackbacks = $trackbacksModel->getSentTrackbacks($blogId);
     // get meta tags
     if (!$loadFromSession && !$isDraft) {
         $metaModel = EasyBlogHelper::getModel('Metas');
         $meta = $metaModel->getPostMeta($blogId);
     }
     //perform some title string formatting
     $blog->title = $this->escape($blog->title);
     $blogger_id = !isset($blog->created_by) ? $my->id : $blog->created_by;
     $defaultCategory = empty($blog->category_id) ? EasyBlogHelper::getDefaultCategoryId() : $blog->category_id;
     $category = EasyBlogHelper::getTable('Category');
     $category->load($defaultCategory);
     $content = $blog->intro;
     // Append the readmore if necessary
     if (!empty($blog->intro) && !empty($blog->content)) {
         $content .= '<hr id="system-readmore" />';
     }
     $content .= $blog->content;
     //check if this is a external group contribution.
     $blog_contribute_source = 'easyblog';
     $external = false;
     $extGroupId = EasyBlogHelper::getHelper('Groups')->getGroupContribution($blog->id);
     $externalEventId = EasyBlogHelper::getHelper('Event')->getContribution($blog->id);
     $extGroupName = '';
     if (!empty($extGroupId)) {
         $external = $extGroupId;
         $blog_contribute_source = EasyBlogHelper::getHelper('Groups')->getGroupSourceType();
         $extGroupName = EasyBlogHelper::getHelper('Groups')->getGroupContribution($blog->id, $blog_contribute_source, 'name');
     }
     if (!empty($externalEventId)) {
         $external = $externalEventId;
         $blog_contribute_source = EasyBlogHelper::getHelper('Event')->getSourceType();
     }
     //site wide or team contribution
     $teamblogModel = EasyBlogHelper::getModel('TeamBlogs');
     $teams = !empty($blog->created_by) ? $teamblogModel->getTeamJoined($blog->created_by) : $teamblogModel->getTeamJoined($my->id);
     $this->assignRef('teams', $teams);
     $this->assignRef('isDraft', $isDraft);
     $joomlaVersion = EasyBlogHelper::getJoomlaVersion();
     $my = JFactory::getUser();
     $blogger_id = $my->id;
     $nestedCategories = '';
     $categoryselecttype = $config->get('layout_dashboardcategoryselect') == 'multitier' ? 'select' : $config->get('layout_dashboardcategoryselect');
     if ($categoryselecttype == 'select') {
         $nestedCategories = EasyBlogHelper::populateCategories('', '', 'select', 'category_id', $blog->category_id, true, true, false);
     }
     // Load media manager and get info about the files.
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php';
     $mediamanager = new EasyBlogMediaManager();
     $userFolders = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'user'), 'folders');
     $userFiles = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'user'), 'files');
     $sharedFolders = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'shared'), 'folders');
     $sharedFiles = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'shared'), 'files');
     // @rule: Test if the user is already associated with Flickr
     $oauth = EasyBlogHelper::getTable('Oauth');
     $associated = $oauth->loadByUser($my->id, EBLOG_OAUTH_FLICKR);
     $jConfig = EasyBlogHelper::getJConfig();
     $this->set('flickrAssociated', $associated);
     $this->assignRef('userFolders', $userFolders);
     $this->assignRef('userFiles', $userFiles);
     $this->assignRef('sharedFolders', $sharedFolders);
     $this->assignRef('sharedFiles', $sharedFiles);
     $this->assignRef('jConfig', $jConfig);
     $this->assignRef('my', $my);
     $this->assignRef('content', $content);
     $this->assignRef('category', $category);
     $this->assignRef('blogger_id', $blogger_id);
     $this->assignRef('joomlaversion', $joomlaVersion);
     $this->assignRef('isEdit', $isEdit);
     $this->assignRef('editorTitle', $editorTitle);
     $this->assignRef('blog', $blog);
     $this->assignRef('meta', $meta);
     $this->assignRef('editor', $editor);
     $this->assignRef('tagsString', $tagsString);
     $this->assignRef('acl', $acl);
     $this->assignRef('isPrivate', $isPrivate);
     $this->assignRef('allowComment', $allowComment);
     $this->assignRef('subscription', $allowSubscribe);
     $this->assignRef('frontpage', $showFrontpage);
     $this->assignRef('trackbacks', $trackbacks);
     $this->assignRef('author', $author);
     $this->assignRef('nestedCategories', $nestedCategories);
     $this->assignRef('teamBlogJoined', $teamBlogJoined);
     $this->assignRef('isSiteWide', $isSiteWide);
     $this->assignRef('draft', $draft);
     $this->assignRef('config', $config);
     $this->assignRef('pending_approval', $pending_approval);
     $this->assignRef('external', $external);
     $this->assignRef('extGroupId', $extGroupId);
     $this->assignRef('externalEventId', $externalEventId);
     $this->assignRef('extGroupName', $extGroupName);
     $this->assignRef('blog_contribute_source', $blog_contribute_source);
     $this->assignRef('categoryselecttype', $categoryselecttype);
     $this->assignRef('send_notification_emails', $sendEmails);
     parent::display($tpl);
 }