function has_content()
 {
     if (carl_empty_html($this->content)) {
         return false;
     }
     return true;
 }
Beispiel #2
0
 /**
  * Present an interface to edit / create content
  */
 function run_editable()
 {
     $inline_edit =& get_reason_inline_editing($this->page_id);
     $active = $inline_edit->active_for_module($this);
     $class = $active ? 'editable editing' : 'editable';
     echo '<div id="pageContent" class="' . $class . '">' . "\n";
     if ($active) {
         $form = new Disco();
         $form->strip_tags_from_user_input = true;
         $form->allowable_HTML_tags = REASON_DEFAULT_ALLOWED_TAGS;
         $form->actions = array('save' => 'Save', 'save_and_finish' => 'Save and Finish Editing');
         $form->add_element('editable_content', html_editor_name($this->site_id), html_editor_params($this->site_id, $this->get_html_editor_user_id()));
         $form->set_display_name('editable_content', ' ');
         $form->set_value('editable_content', $this->content);
         $form->add_callback(array(&$this, 'process_editable'), 'process');
         $form->add_callback(array(&$this, 'where_to_editable'), 'where_to');
         $form->run();
     } else {
         $url = carl_make_link($inline_edit->get_activation_params($this));
         if (!carl_empty_html($this->content)) {
             $link = '<p><a href="' . $url . '" class="editThis">Edit Content</a></p>';
             $pre = '<div class="editRegion">';
             $post = '</div>';
             $output = $pre . $this->content . $link . $post;
         } else {
             $link = '<p><a href="' . $url . '" class="editThis">Create Content</a></p>';
             $pre = '<div class="editRegion">';
             $post = '</div>';
             $output = $pre . $link . $post;
         }
         echo $output;
     }
     echo '</div>' . "\n";
 }
	function process()
	{	
		$description = trim(tidy($this->get_value('description')));
		$content = trim(get_safer_html(tidy($this->get_value('post_content'))));
		if(carl_empty_html($description))
		{
			$words = explode(' ', $content, 31);
			unset($words[count($words)-1]);
			$description = implode(' ', $words).'…';
			$description = trim(tidy($description)); // we're tidying it twice so that if we chop off a closing tag tidy will stitch it back up again
		}
		
		if(!empty($this->user_netID))
		{
			$user_id = make_sure_username_is_user($this->user_netID, $this->site_info->id());
		}
		else
		{
			$user_id = $this->site_info->id();
		}
		
		if($this->hold_posts_for_review)
		{
			$status = 'pending';
		}
		else
		{
			$status = 'published';
		}

		$values = array (
			'status' => $status,
			'release_title' => trim(strip_tags($this->get_value('title'))),
			'author' => trim(strip_tags($this->get_value('author'))),
			'content' => $content,
			'description' => $description,
			'datetime' => date('Y-m-d H:i:s', time()),
			'keywords' => implode(', ', array(strip_tags($this->get_value('title')), date('Y'), date('F'))),
			'show_hide' => 'show',
			'new' => 0
		);
				
		$this->new_post_id = reason_create_entity( 
			$this->site_info->id(), 
			id_of('news'), 
			$user_id, 
			$values['release_title'], 
			$values
		);
		
		create_relationship(
			$this->new_post_id,
			$this->publication->id(),
			relationship_id_of('news_to_publication')
		);

		if ($this->successfully_submitted())
		{
			
			if($this->hold_posts_for_review)
			{
				echo '<p>Posts are being held for review on this publication. Please check back later to see if your post has been published.</p>';
				echo '<a href="?">Back to main page</a>';
			
			}
			else
			{
				echo '<p>Your post has been published.</p>';
				echo '<a href="'.carl_construct_redirect(array('story_id'=>$this->new_post_id)).'">View it.</a>';
			}
		}
		
		if($this->get_value('issue'))
		{
			create_relationship($this->new_post_id, $this->get_value('issue'), relationship_id_of('news_to_issue'));
		}
		
		if($this->get_value('section'))
		{
			create_relationship($this->new_post_id, $this->get_value('section'), relationship_id_of('news_to_news_section'));
		}
		
		if($this->get_value('categories'))
		{
			foreach($this->get_value('categories') as $category_id)
			{
				// Check to make sure ids posted actually belong to categories in the site
				if(array_key_exists($category_id, $this->categories))
				{
					create_relationship(
						$this->new_post_id,
						$category_id,
						relationship_id_of('news_to_category')
					);
				}
			}
		}
		
		$this->show_form = false;

		$this->do_notifications();
	}
	function run_error_checks()
	{
		foreach($this->forbidden as $field)
		{
			if($this->get_value($field))
			{
				$this->set_error($field,'This field must be left empty for your comment to work');
			}
		}
		$content = $this->get_value('comment_content');
		$content = str_replace('&nbsp;', ' ', $content);
		if (carl_empty_html(trim(tidy($content))))
		{
			$this->set_error('comment_content', 'You must write a comment in order to post a comment!');
		}
				
		$fields_to_tidy = array('comment_content');
		foreach($fields_to_tidy as $field)
		{
			if($this->get_value($field))
			{
				$tidied = trim(tidy($this->get_value($field)));
				if(empty($tidied) && in_array($field,$this->required))
				{
					if(!empty($this->elements[$field]['display_name']))
					{
						$display_name = $this->elements[$field]['display_name'];
					}
					else
					{
						$display_name = prettify_string($field);
					}
					$this->set_error($field,'Please fill in the '.$display_name.' field');
				}
				else 	
				{
					$tidy_errors = tidy_err($this->get_value($field));
					if(!empty($tidy_errors))
					{
						$msg = 'The html in the '.$field.' field is misformed.  Here is what the html checker has to say:<ul>';
						foreach($tidy_errors as $tidy_error)
						{
							$msg .= '<li>'.$tidy_error.'</li>';
						}
						$msg .= '</ul>';
						$this->set_error($field,$msg);
					}
				}
			}
		}
		if (!reason_check_authentication())
		{
			if ($this->is_comment_spam())
			{
				$this->set_error('comment_content', 'Your comment was rejected because it appears to be spam.');
			}
		}
	}
Beispiel #5
0
 function get_more_link_markup()
 {
     $item = $this->passed_vars['item'];
     $markup_string = '';
     if (!carl_empty_html($item->get_value('content')) && isset($this->passed_vars['link_to_full_item']) && !empty($this->passed_vars['link_to_full_item'])) {
         $markup_string .= '<li class="more">';
         $markup_string .= '<a href="' . $this->passed_vars['link_to_full_item'] . '">';
         $markup_string .= 'Read more of &#8220;';
         $markup_string .= $item->get_value('release_title');
         $markup_string .= '&#8221;';
         $markup_string .= '</a>';
         $markup_string .= '</li>' . "\n";
     }
     return $markup_string;
 }
 function _get_maintainer_info($maintainer)
 {
     // Check to see if it's before or after 7 am, and set the last colleague->ldap sync time appropriately.
     if (carl_date('G') < 7) {
         $ldap_last_sync_time = strtotime('7 am yesterday');
     } else {
         $ldap_last_sync_time = strtotime('7 am today');
     }
     /*	Either of the following conditions will fire the ldap->reason sync:
     			1: the cached info predates the last colleague->ldap sync (presumed to be daily by 7 am.)
     			2: the primary maintainer has been changed since the last ldap->reason sync. */
     if ($this->parent->site_info->get_value('cache_last_updated') <= date('Y-m-d', $ldap_last_sync_time) || $this->parent->site_info->get_value('username_cache') != $this->parent->site_info->get_value('primary_maintainer')) {
         $dir = new directory_service();
         if ($dir->search_by_attribute('ds_username', $maintainer, array('ds_email', 'ds_fullname'))) {
             $email = $dir->get_first_value('ds_email');
             $full_name = $dir->get_first_value('ds_fullname');
             // lets fall back to the maintainer username if a valid full name is not found for the user
             $full_name = !carl_empty_html($full_name) ? $full_name : trim(strip_tags($maintainer));
             $values = array('email_cache' => $email, 'name_cache' => $full_name, 'cache_last_updated' => date('Y-m-d H:i:s'), 'username_cache' => $maintainer);
             $update_vals = array('ldap_cache' => $values);
             reason_include_once('function_libraries/admin_actions.php');
             /* I know this is nonstandard, but it's the only way right now 
             			to update the entity without creating an archive and changing 
             			the last_updated field on all the sites every day... */
             $sqler = new SQLER();
             foreach ($update_vals as $table => $fields) {
                 $sqler->update_one($table, $fields, $this->parent->site_info->id());
             }
         }
     } else {
         $email = $this->parent->site_info->get_value('email_cache');
         $full_name = $this->parent->site_info->get_value('name_cache');
     }
     return array('email' => $email, 'full_name' => $full_name);
 }
Beispiel #7
0
 function get_content_section()
 {
     if (carl_empty_html($this->item->get_value('content'))) {
         return $this->alter_content($this->item->get_value('description'));
     } else {
         return $this->alter_content($this->item->get_value('content'));
     }
 }