<?php

if(!defined("IN_MYBB"))
{
  die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("datahandler_user_update", "profilepni_update");

function profilepni_info()
{
  return array(
    "name"           => "Profile Playstation Network ID",
    "description"    => "Adds a Playstation Network ID to the User CP",
    "website"        => "http://www.xpresionzone.net/",
    "author"         => "Walkman 5.0",
    "authorsite"     => "http://www.xpresionzone.net/",
    "version"        => "1.1",
    "guid"           => "11c8d8bf95166e6eb737c23a9387a91b",
    "compatibility"  => "16*"
  );
}

function profilepni_activate()
{
  global $db;
  
  /* TODO: Should the possibility be added to disable pni from admin cp? */
  $db->query("ALTER TABLE ".TABLE_PREFIX."users ADD pni VARCHAR(200) NOT NULL AFTER msn");
  
  /* TODO: Language support? */
  require_once MYBB_ROOT."inc/adminfunctions_templates.php";

  /* Insert fields into usercp for editing */
  find_replace_templatesets('usercp_profile','#{\$user\[\'yahoo\'\]\}\" /\></td>#',
         '{$user[\'yahoo\']}" /></td>
</tr>
<tr>
<td><span class="smalltext"> Playstation Network ID:</span></td>
</tr>
<tr>
<td><input type="text" class="textbox" name="pni" size="25" value="{$user[\'pni\']}" /></td>
</tr>');

  /* Insert fields into member profile */
  find_replace_templatesets('member_profile','#{\$memprofile\[\'msn\'\]\}</a></td>#',
        '{$memprofile[\'msn\']}</a></td>
</tr>
<tr>
<td class="trow2"><strong>Playstation Network ID:</strong></td>
<td class="trow2">{$memprofile[\'pni\']}</td>
</tr>');
}

function profilepni_deactivate()
{
  global $db;

  $db->query("ALTER TABLE ".TABLE_PREFIX."users DROP COLUMN pni");

  require_once MYBB_ROOT."inc/adminfunctions_templates.php";

  find_replace_templatesets('usercp_profile',
      preg_quote('#{$user[\'yahoo\']}" /></td>
</tr>
<tr>
<td><span class="smalltext">Playstation Network ID</span></td>
</tr>
<tr>
<td><input type="text" class="textbox" name="pni" size="25" value="{$user[\'pni\']}" /></td>
</tr>#'),
      '{$user[\'yahoo\']}" /></td>',0);

   find_replace_templatesets('member_profile',
        preg_quote('#{$memprofile[\'msn\']}</a></td>
</tr>
<tr>
<td class="trow2"><strong>Playstation Network ID:</strong></td>
<td class="trow2">{$memprofile[\'pni\']}</td>
</tr>#'),
      '{$memprofile[\'msn\']}</a></td>',0);
}

function profilepni_update($pni)
{
  global $mybb;

  if (isset($mybb->input['pni']))
   {
      $pni->user_update_data['pni'] = $mybb->input['pni'];
   }
}