Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for "Edited on ..." in Answer-meta #24

Open
q2apro opened this issue Jul 31, 2018 · 2 comments
Open

Code for "Edited on ..." in Answer-meta #24

q2apro opened this issue Jul 31, 2018 · 2 comments

Comments

@q2apro
Copy link

q2apro commented Jul 31, 2018

Maybe this helps, it shows an edit notice directly under "Answered on ... by ..." like it can be found with the questions:

public function post_meta($post, $class, $prefix=null, $separator='<BR/>')
{
	// only link when there are actual revisions
	if(in_array($post['raw']['postid'], $this->rev_postids))
	{
		$url = qa_path_html('revisions/' . $post['raw']['postid']);
		
		// question meta
		if(isset($post['when_2']))
		{
			// $post['when_2']['data'] = '<a rel="nofollow" href="'.$url.'" class="'.$class.'-revised">' . $post['when_2']['data'] . '</a>';
			
			// prefix is only set "vor x Minuten", but after a week the date is displayed (no prefix), e.g. "Mär 3"
			$meta_before = !empty($post['when_2']['prefix']) ? $post['when_2']['prefix'] : '';
			$meta_before .= ' '.!empty($post['when_2']['data']) ? $post['when_2']['data'] : '';
			
			$post['what_2'] = '
				<div class="post-meta-edited">
					<a rel="nofollow" href="'.$url.'" class="'.$class.'-revised">' . $post['what_2'] . '</a> 
					'.$meta_before.'
				</div>
			';
			
			// $post['who_2']['suffix'] .= '';
			unset($post['who_2']);
			unset($post['when_2']);
		}
		// answer edit, q2a core does not give them a what_2 for the edit
		else if(isset($post['when']))
		{
			// get edit time and editor
			$lastedit = qa_db_read_one_assoc( 
							qa_db_query_sub('
								SELECT updated, userid
								FROM ^edit_history 
								WHERE postid = #
								ORDER BY `updated` DESC
								LIMIT 1
							', $post['raw']['postid'])
						);
			
			$meta_before_arr = qa_when_to_html(strtotime($lastedit['updated']), qa_opt('show_full_date_days'));
			
			$meta_before = isset($meta_before_arr['prefix']) ? $meta_before_arr['prefix'] : '';
			$meta_before .= $meta_before_arr['data'];
			
			$post['what_2'] = '
				<div class="post-meta-edited">
					<a rel="nofollow" href="'.$url.'" class="'.$class.'-revised">Edited</a> 
					'.$meta_before.'
				</div>
			';
		}
	}

	parent::post_meta($post, $class, $prefix, $separator);
}
@q2apro q2apro changed the title Code for "Edit on ..." in Answer-meta Code for "Edited on ..." in Answer-meta Jul 31, 2018
@svivian
Copy link
Owner

svivian commented Aug 13, 2018

What is the situation this works in? When does Q2A not have the what_2 but you need to show something in the edit history?

@q2apro
Copy link
Author

q2apro commented Aug 13, 2018

I did implement it for the answers and this happened, so I added the:

// answer edit, q2a core does not give them a what_2 for the edit

I did not dig into the issue. Just fixed the problem.

Could be that my qa-theme.php or one of my plugins removes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants