Giter Site home page Giter Site logo

ougc-admin-post-edit's Introduction

OUGC Admin Post Edit

Allows administrators to edit additional post data.


Support

Please visit OUGC Network for more information about this project.

Thank You!

Remember this is a free release developed on free time, either for personal use or as custom requests.

Any contribution is welcome.

Thanks for downloading and using my plugins, I really appreciate it!

ougc-admin-post-edit's People

Contributors

mobeigi avatar sama34 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

korud xbdmhq

ougc-admin-post-edit's Issues

Inclusion of feature: Non-Member Usernames

Just upgraded from one version by MrBrechreiz to your newest version. The 1.1 version used before allowed me to enter usernames for guest accounts, or make posts to credit original authors in order to archive content that was in danger of being lost.

Describe the solution you'd like
Please include a checkbox for 'Registered Members' as a default setting.

While checked, it would act as it does now, ignore if the name entered into the username field is not that of a registered user.

If unchecked, it would assume the name entered is not a registered member. However, it would run a test against the member database to see if the name does exist. If it does, then a notification would appear that the name belongs to a registered member followed by (Proceed/Cancel).

Describe alternatives you've considered
No alternatives really. Everything else already covered in your latest, including the newer IP address style.

Additional context
I requested the earlier version in a forum found here:
http://mybbhacks.zingaburga.com/showthread.php?tid=5282
The second page includes an 'attachment' which is by 'MrBrechreiz', the version I had used.

Add form when adding new post

Is your feature request related to a problem? Please describe.
While this plugin original intention is to update an existing post information, it could be useful to be able to assign information when creating a post.

Describe the solution you'd like
Add the form when creating new threads or posts.

Describe alternatives you've considered
Possibly just add the option to change the post author.

Thread dateline is set to 0/fails to update

How to reproduce:

  • Make a new thread
  • Edit first post in thread, change username to another username
  • Now the threads 'dateline' will be set to 0 which is wrong

The problem is when the username is changed, this query:
$db->update_query('threads', $thread_update, "tid='{$thread['tid']}'");
Tries to update the dateline but its set to 0.

No offence but the code is kinda hard to follow so it was a pain debugging.
Anyway, I'm using the following code as a fix.
It uses $updateDate to see if date changed and if so, it updates the dateline by itself outside of the $update scope.
Perhaps you have a better solution in mind as I didn't want to spend any more time debugging.
Diff check the following with the current hook_editpost_end function in the repo.

// Hook: editpost_end/datahandler_post_update
function hook_editpost_end(&$dh)
{
  global $fid, $ougc_adminpostedit, $mybb;

  $ougc_adminpostedit = '';

  if(!is_moderator($fid, 'caneditposts') || !is_member($mybb->settings['ougc_adminpostedit_groups']))
  {
    return;
  }

  global $lang, $templates, $pid, $db;

  $this->load_language();

  $post = get_post($pid);

  $p = array(
    'dateline'		=> $post['dateline'],
    'uid'			=> $post['uid'],
    'username'		=> $post['username'],
    'ipaddress'		=> my_inet_ntop($db->unescape_binary($post['ipaddress'])),
    'silent'		=> ''
  );

  $timestamp = (int)$p['dateline'];

  $search_username = htmlspecialchars_uni(trim($p['username']));

  if($mybb->request_method == 'post')
  {
    $input = $mybb->get_input('ougc_adminpostedit', 2);

    $timestamp = (int)$input['timestamp'];

    $search_username = htmlspecialchars_uni(trim($input['username']));

    $post_update_data = array();

    if($p['dateline'] != $input['timestamp'] && TIME_NOW >= $input['timestamp'])
    {
      $p['dateline'] = $post_update_data['dateline'] = (int)$input['timestamp'];
      
      $updateDate = true;
    }

    if($p['username'] != $input['username'])
    {
      if($user = get_user_by_username($input['username'], array('fields' => array('username'))))
      {
        $p['uid'] = $post_update_data['uid'] = (int)$user['uid'];
        $p['username'] = $user['username'];
        $post_update_data['username'] = $db->escape_string($p['username']);

        $update = true;
      }
    }

    if($p['ipaddress'] != $input['ipaddress'])
    {
      if(preg_match('#^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$#', $input['ipaddress']))
      {
        $ipaddress = array_map('intval', explode('.', $input['ipaddress']));
        if(!($ipaddress[0] > 255 || $ipaddress[1] > 255 || $ipaddress[2] > 255 || $ipaddress[3] > 255))
        {
          $p['ipaddress'] = implode('.', $ipaddress);
          $post_update_data['ipaddress'] = $db->escape_binary(my_inet_pton($p['ipaddress']));
        }
      }
    }

    if($input['silent'])
    {
      $p['silent'] = ' checked="checked"';
    }

    if($dh instanceof PostDataHandler)
    {
      $dh->post_update_data = array_merge($dh->post_update_data, $post_update_data);

      $thread = get_thread($dh->data['tid']);
      
      if(isset($update))
      {
        global $plugins;

        $forum = get_forum($dh->data['fid']);

        $user = get_user($dh->post_update_data['uid']);

        $update_query = array();
        if($thread['dateline'] > $user['lastpost'])
        {
          $update_query['lastpost'] = "'{$thread['dateline']}'";
        }
        if($forum['usepostcounts'])
        {
          $update_query['postnum'] = 'postnum+1';
        }
        if($forum['usethreadcounts'])
        {
          $update_query['threadnum'] = 'threadnum+1';
        }

        if(!empty($update_query))
        {
          $db->update_query('users', $update_query, "uid='{$user['uid']}'", 1, true);
        }

        $user = get_user($dh->data['uid']);

        $update_query = array();
        if($thread['dateline'] < $user['lastpost'])
        {
          $update_query['lastpost'] = "'{$thread['dateline']}'";
        }
        if($forum['usepostcounts'])
        {
          $update_query['postnum'] = 'postnum-1';
        }
        if($forum['usethreadcounts'])
        {
          $update_query['threadnum'] = 'threadnum-1';
        }

        if(!empty($update_query))
        {
          $db->update_query('users', $update_query, "uid='{$user['uid']}'", 1, true);
        }

        if($thread['firstpost'] == $post['pid'])
        {
          $thread_update = array(
            'uid'		=> $dh->post_update_data['uid'],
            'username'	=> $dh->post_update_data['username']
          );

          $db->update_query('threads', $thread_update, "tid='{$thread['tid']}'");
        }

        $plugins->add_hook('datahandler_post_update_end', array($this, 'hook_datahandler_post_update_end'));
      }
      
      if(isset($updateDate))
      {
        if($thread['firstpost'] == $post['pid'])
        {
          $thread_update = array(
            'dateline'	=> $dh->post_update_data['dateline']
          );

          $db->update_query('threads', $thread_update, "tid='{$thread['tid']}'");
        }
      }

      return;
    }
  }

  $ougc_adminpostedit = eval($templates->render('ougcadminpostedit'));
}

When a non-thread post gets author changed the threadcount is still changed

This one should be a relatively simple change.

This should resolve the issue

			if(isset($update))
			{
				global $plugins;

				$forum = get_forum($dh->data['fid']);
				$thread = get_thread($dh->data['tid']);

				$user = get_user($dh->post_update_data['uid']);

				$update_query = array();
				if($thread['dateline'] > $user['lastpost'])
				{
					$update_query['lastpost'] = "'{$thread['dateline']}'";
				}
				if($forum['usepostcounts'])
				{
					$update_query['postnum'] = 'postnum+1';
				}
				if($forum['usethreadcounts'])
				{
					if($thread['firstpost'] == $post['pid']){
						$update_query['threadnum'] = 'threadnum+1';
					} else {
						$update_query['threadnum'] = 'threadnum';
					}
				}

				if(!empty($update_query))
				{
					$db->update_query('users', $update_query, "uid='{$user['uid']}'", 1, true);
				}

				$user = get_user($dh->data['uid']);

				$update_query = array();
				if($thread['dateline'] < $user['lastpost'])
				{
					$update_query['lastpost'] = "'{$thread['dateline']}'";
				}
				if($forum['usepostcounts'])
				{
					$update_query['postnum'] = 'postnum-1';
				}
				if($forum['usethreadcounts'])
				{
					if($thread['firstpost'] == $post['pid']){
					        $update_query['threadnum'] = 'threadnum-1';
					} else {
						$update_query['threadnum'] = 'threadnum';
					}
				}

				if(!empty($update_query))
				{
					$db->update_query('users', $update_query, "uid='{$user['uid']}'", 1, true);
				}

				if($thread['firstpost'] == $post['pid'])
				{
					$thread_update = array(
						'uid'		=> $dh->post_update_data['uid'],
						'username'	=> $dh->post_update_data['username'],
						'dateline'	=> $dh->post_update_data['dateline']
					);

					$db->update_query('threads', $thread_update, "tid='{$thread['tid']}'");
				}

				$plugins->add_hook('datahandler_post_update_end', array($this, 'hook_datahandler_post_update_end'));
			}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.