Example #1
0
 function doAction($action)
 {
     if ($action == 'use') {
         global $vbulletin;
         $itemtypeids = explode(',', $this->itemtype->data['options']['itemtypeids']);
         $newitemids = array();
         if (count($itemtypeids)) {
             foreach ($itemtypeids as $itemtypeid) {
                 $itemtypes[] = newItemType($itemtypeid);
             }
             foreach ($itemtypes as $itemtype_obj) {
                 if ($itemtype_obj) {
                     $itemtype = $itemtype_obj->data;
                     $itemoptions = array();
                     if ($itemtype_obj->options['use_duration']) {
                         $itemoptions['duration'] = $this->data['options']['duration'];
                     }
                     $item_new = array('type' => $itemtype['itemtypeid'], 'name' => "{$itemtype['name']}", 'description' => $vbulletin->db->escape_string($this->data['description']), 'price' => $this->data['price'], 'userid' => $vbulletin->userinfo['userid'], 'creator' => $vbulletin->userinfo['userid'], 'create_time' => TIMENOW, 'expire_time' => $this->data['expire_time'], 'status' => KBANK_ITEM_AVAILABLE, 'options' => serialize($itemoptions));
                     $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items'));
                     $newitemids[] = $vbulletin->db->insert_id();
                 }
             }
         }
         $item_new = array('status' => KBANK_ITEM_USED, 'expire_time' => TIMENOW);
         $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
         if (count($newitemids)) {
             $itemid = $newitemids[count($newitemids) - 1];
             //get the last new itemid
             $vbulletin->url = $vbulletin->kbank['phpfile'] . '?' . $vbulletin->session->vars['sessionurl'] . "do=myitems&itemid={$itemid}#item{$itemid}";
         }
     }
     return parent::doAction($action);
 }
Example #2
0
 function doAction($action)
 {
     global $kbank, $vbulletin, $bbuserinfo, $permissions, $KBANK_HOOK_NAME;
     if ($action == 'enable') {
         $item = $this->data;
         eval('$tmp = "' . fetch_template('kbank_template_announce_enable') . '";');
         eval(standard_error($tmp));
     }
     if ($action == 'do_enable') {
         if ($this->ready2Enable()) {
             $vbulletin->input->clean_array_gpc('r', array('url' => TYPE_NOHTML, 'text' => TYPE_NOHTML));
             if (strlen($vbulletin->GPC['text']) > $this->itemtypedata['options']['text_max']) {
                 $vbulletin->GPC['text'] = substr($vbulletin->GPC['text'], 0, $this->itemtypedata['options']['text_max']) . '..';
             }
             $url_cutoff = array('javascript:', 'ftp://');
             $vbulletin->GPC['url'] = str_replace($url_cutoff, '', $vbulletin->GPC['url']);
             if (substr($vbulletin->GPC['url'], 0, 7) != 'http://') {
                 $vbulletin->GPC['url'] = 'http://' . $vbulletin->GPC['url'];
             }
             $item_new = array('status' => KBANK_ITEM_ENABLED, 'expire_time' => iif(!$this->data['options']['enabled'], iif($this->data['options']['duration'] > 0, TIMENOW + $this->data['options']['duration'] * 24 * 60 * 60, -1), $this->data['expire_time']), 'options' => serialize(array('url' => $vbulletin->GPC['url'], 'text' => $vbulletin->GPC['text'], 'enabled' => 1)));
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data['itemid']}"));
             //Update datastore
             updateAnnounceCache();
         }
     }
     if ($this->data['status'] == KBANK_ITEM_ENABLED and ($action == 'sell' or $action == 'gift')) {
         //Update datastore
         updateAnnounceCache();
     }
     if ($action == 'disable') {
         if ($this->ready2Disable()) {
             $item_new = array('status' => KBANK_ITEM_AVAILABLE);
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
             //Update datastore
             updateAnnounceCache();
         }
     }
     if ($action == 'work_real' && $KBANK_HOOK_NAME == KBANK_GLOBAL_START) {
         global $kbank_announces;
         $kbank_announces[] = array('url' => $this->data['options']['url'], 'text' => $vbulletin->kbankBBCodeParser->parse_bbcode($this->data['options']['text'], true), 'owner' => getUsername($this->data));
     }
     return parent::doAction($action);
 }
 function doAction($action)
 {
     global $kbank, $vbulletin, $bbuserinfo, $vbphrase, $KBANK_HOOK_NAME;
     $vbulletin->kbank['errors'][$this->data['itemid']] = array();
     //Reset errors
     if ($action == 'enable') {
         $item =& $this->data;
         $itemtypeoptions =& $this->itemtypedata['options'];
         if ($itemtypeoptions['postbg']) {
             //build backgrounds
             $postbg_options = '';
             $postbgs = explode("\r\n", $itemtypeoptions['postbg_list']);
             $isURLBackground = iif($this->data['options']['postbg'] == '', false, true);
             foreach ($postbgs as $postbg) {
                 if ($postbg) {
                     $tmp = explode(":", $postbg);
                     if (!isset($tmp[1])) {
                         $tmp[1] = basename($tmp[0]);
                     }
                     $selected = '';
                     if ($this->data['options']['postbg'] == $tmp[0]) {
                         $selected = ' selected="selected"';
                         $isURLBackground = false;
                     }
                     $postbg_options .= "<option value=\"{$tmp['0']}\"{$selected}>{$tmp['1']}</option>";
                 }
             }
             //build positions
             $postbg_positions = '';
             foreach ($this->itemtype->options['postbg_positions'] as $value => $name) {
                 $selected = '';
                 if ($this->data['options']['postbg_position'] == $value) {
                     $selected = ' selected="selected"';
                 }
                 $postbg_positions .= "<option value=\"{$value}\"{$selected}>{$name}</option>";
             }
         }
         eval('$tmp = "' . fetch_template('kbank_template_customize_postdisplay_enable') . '";');
         eval(standard_error($tmp, '', false));
     }
     if ($action == 'do_enable') {
         if ($this->ready2Enable()) {
             $vbulletin->input->clean_array_gpc('p', array('itemid' => TYPE_UINT, 'postbg_select' => TYPE_STR, 'postbg_url' => TYPE_STR, 'postbg_position' => TYPE_STR));
             if ($this->itemtypedata['options']['postbg']) {
                 if ($vbulletin->GPC['postbg_select'] != '-1') {
                     //background
                     if ($vbulletin->GPC['postbg_select'] == '0' and $this->itemtypedata['options']['postbg_url']) {
                         //Admin allow URL and user selected url mode
                         $postbg = $vbulletin->GPC['postbg_url'];
                         $pathinfo = pathinfo($postbg);
                         if (strpos($postbg, '?') or !in_array(strtolower($pathinfo['extension']), array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) {
                             $postbg = '';
                         }
                     } else {
                         $postbg = '';
                         $valid_postbgs = explode("\r\n", $this->itemtypedata['options']['postbg_list']);
                         foreach ($valid_postbgs as $valid_postbg) {
                             $tmp = explode(":", $valid_postbg);
                             if ($tmp[0] == $vbulletin->GPC['postbg_select']) {
                                 $postbg = $tmp[0];
                             }
                         }
                     }
                     $this->data['options']['postbg'] = $postbg;
                     //position
                     if (isset($this->itemtype->options['postbg_positions'][$vbulletin->GPC['postbg_position']])) {
                         $this->data['options']['postbg_position'] = $vbulletin->GPC['postbg_position'];
                     } else {
                         $keys = array_keys($this->itemtype->options['postbg_positions']);
                         $this->data['options']['postbg_position'] = $keys[0];
                     }
                 } else {
                     $this->data['options']['postbg'] = '';
                     $this->data['options']['postbg_position'] = '';
                 }
             }
             $this->data['options']['enabled'] = 1;
             $this->data['expire_time'] = iif(!$this->data['options']['enabled'], iif($this->data['options']['duration'] > 0, TIMENOW + $this->data['options']['duration'] * 24 * 60 * 60, -1), $this->data['expire_time']);
             //Optimizing....
             $options = array();
             foreach ($this->data['options'] as $key => $val) {
                 if ($val) {
                     $options[$key] = $val;
                 }
             }
             $item_new = array('status' => KBANK_ITEM_ENABLED, 'expire_time' => $this->data['expire_time'], 'options' => serialize($options));
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
         }
     }
     if ($action == 'disable') {
         if ($this->ready2Disable()) {
             $item_new = array('status' => KBANK_ITEM_AVAILABLE);
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
         }
     }
     if ($action == 'work') {
         //Check for running hook
         switch ($KBANK_HOOK_NAME) {
             case KBANK_POSTBIT_COMPLETE:
                 if (THIS_SCRIPT == 'showthread' or THIS_SCRIPT == 'showpost') {
                     //currently only work with showthread and showpost
                     $options = $this->data['options'];
                     $itemtypeoptions = $this->itemtypedata['options'];
                     global $post, $stylevar, $kbank_active_items;
                     if ($itemtypeoptions['postbg']) {
                         $postbg_position = str_replace(array('-', '_'), array(' ', '-'), $options['postbg_position']);
                         $background = "background: {$stylevar['alt1_bgcolor']} url({$options['postbg']}) {$postbg_position};";
                         $GLOBALS['customize_postdisplay_cache'][$post['postid']]['background'] = $background;
                     }
                     $foundOther = false;
                     $foundThis = false;
                     foreach ($GLOBALS['kbank_active_items'] as $userid => $useritems) {
                         if ($foundOther) {
                             break;
                         }
                         foreach ($useritems as $item) {
                             if ($foundTher) {
                                 break;
                             }
                             if (is_subclass_of($item, 'Item')) {
                                 if ($item->data['itemid'] == $this->data['itemid']) {
                                     $foundThis = true;
                                 }
                                 if ($foundThis and $item->itemtype->data['filename'] == substr(strrchr(__FILE__, DIRECTORY_SEPARATOR), 1)) {
                                     $foundOTher = true;
                                     break;
                                 }
                             }
                         }
                     }
                     if (!$foundOther) {
                         $css = '';
                         foreach ($GLOBALS['customize_postdisplay_cache'] as $postid => $cache) {
                             if ($itemtypeoptions['postbg_element']) {
                                 $elementid = str_replace('###', $postid, $itemtypeoptions['postbg_element']);
                             } else {
                                 $elementid = "post_message_{$postid}";
                             }
                             $css .= "#{$elementid} {\r\n";
                             foreach ($cache as $element) {
                                 $css .= $element . "\r\n";
                             }
                             $css .= "}\r\n";
                             $GLOBALS['customize_postdisplay_cache'] = array();
                         }
                         if ($css != '') {
                             $css = "<style type=\"text/css\">\r\n{$css}</style>\r\n";
                             $GLOBALS['headinclude'] .= "<!-- CSS automatically added by " . substr(strrchr(__FILE__, DIRECTORY_SEPARATOR), 1) . " at line " . __LINE__ . " -->\n" . $css;
                         }
                     }
                 }
                 break;
         }
     }
     return parent::doAction($action);
 }
 function doAction($action)
 {
     global $kbank, $vbulletin, $bbuserinfo, $vbphrase, $KBANK_HOOK_NAME;
     $vbulletin->kbank['errors'][$this->data['itemid']] = array();
     //Reset errors
     if ($action == 'enable') {
         $item = $this->data;
         $username_max = $this->itemtypedata['options']['username_max'];
         $username_colors_options = $this->buildOptions($item['options']['username_color']);
         $username_strong = $this->itemtypedata['options']['username_strong'];
         $usertitle_max = $this->itemtypedata['options']['usertitle_max'];
         $usertitle_colors_options = $this->buildOptions($item['options']['usertitle_color'], 'usertitle_colors', 'usertitle_color');
         if ($this->bypassEnableForm() or !$this->canEdit()) {
             $action = 'do_enable';
         } else {
             eval('$tmp = "' . fetch_template('kbank_template_customize_userinfo_enable') . '";');
             eval(standard_error($tmp));
         }
     }
     if ($action == 'do_enable') {
         if ($this->ready2Enable()) {
             if (!$this->bypassEnableForm() and $this->canEdit()) {
                 $vbulletin->input->clean_array_gpc('p', array('itemid' => TYPE_UINT, 'username' => TYPE_NOHTML, 'username_color' => TYPE_NOHTML, 'username_strong' => TYPE_UINT, 'usertitle' => TYPE_NOTHML, 'usertitle_color' => TYPE_NOHTML, 'confirm' => TYPE_STR));
                 if (strlen($vbulletin->GPC['username']) > $this->itemtypedata['options']['username_max']) {
                     $vbulletin->GPC['username'] = substr($vbulletin->GPC['username'], 0, $this->itemtypedata['options']['username_max']);
                 }
                 if (strlen($vbulletin->GPC['username']) > 0) {
                     //Check for illegal username
                     $usernames = explode(',', $vbulletin->options['illegalusernames']);
                     $illegal_found = array();
                     foreach ($usernames as $username) {
                         $username = trim($username);
                         if ($username and strpos(strtolower($vbulletin->GPC['username']), strtolower($username)) !== false) {
                             $illegal_found[] = trim($username);
                         }
                     }
                     if (count($illegal_found) > 0) {
                         //Found something illegal....
                         eval(standard_error(construct_phrase($vbphrase['kbank_itemshow_customize_userinfo_username_illegal'], $vbulletin->GPC['username'], implode(', ', $illegal_found))));
                     }
                     //Check for duplicate username
                     //Real usernames
                     if ($old_found = $vbulletin->db->query_first("\n\t\t\t\t\t\t\t\tSELECT userid, username\n\t\t\t\t\t\t\t\tFROM `" . TABLE_PREFIX . "user`\n\t\t\t\t\t\t\t\tWHERE LOWER(username) = '" . $vbulletin->db->escape_string(strtolower($vbulletin->GPC['username'])) . "'\n\t\t\t\t\t\t\t")) {
                         eval(standard_error(construct_phrase($vbphrase['kbank_itemshow_customize_userinfo_username_duplicate_realusername'], $vbulletin->GPC['username'], getUsername($old_found['userid']))));
                     }
                     //Our usernames
                     $old_found = false;
                     $old_userid = 0;
                     $old_items = $vbulletin->db->query_read("\n\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\titems.itemid as itemid,\n\t\t\t\t\t\t\t\t\titems.userid as userid,\n\t\t\t\t\t\t\t\t\titems.options as options\n\t\t\t\t\t\t\t\tFROM `" . TABLE_PREFIX . "kbank_items` as items\n\t\t\t\t\t\t\t\tINNER JOIN `" . TABLE_PREFIX . "kbank_itemtypes` as itemtypes ON (itemtypes.itemtypeid = items.type)\n\t\t\t\t\t\t\t\tWHERE itemtypes.filename = 'customize_userinfo.kbank.php'\n\t\t\t\t\t\t\t\t\tAND items.status > " . KBANK_ITEM_AVAILABLE . "\n\t\t\t\t\t\t\t\t\tAND (items.expire_time > " . TIMENOW . "\n\t\t\t\t\t\t\t\t\t\tOR items.expire_time < 0)\n\t\t\t\t\t\t\t\t\tAND items.itemid <> {$this->data['itemid']}\n\t\t\t\t\t\t\t");
                     while ($old_item = $vbulletin->db->fetch_array($old_items)) {
                         $old_item['options'] = unserialize($old_item['options']);
                         if (strtolower($old_item['options']['username']) == strtolower($vbulletin->GPC['username']) and $old_item['userid'] != $vbulletin->userinfo['userid']) {
                             $old_found = true;
                             $old_userid = $old_item['userid'];
                             break;
                         }
                     }
                     unset($old_item);
                     $vbulletin->db->free_result($old_items);
                     if ($old_found) {
                         eval(standard_error(construct_phrase($vbphrase['kbank_itemshow_customize_userinfo_username_duplicate'], $vbulletin->GPC['username'], getUsername($old_userid))));
                     }
                 }
                 $username_colors = explode(',', $this->itemtypedata['options']['username_colors']);
                 if (!count($username_colors) || !in_array($vbulletin->GPC['username_color'], $username_colors)) {
                     $vbulletin->GPC['username_color'] = 0;
                 }
                 if (!$this->itemtypedata['options']['username_strong']) {
                     $vbulletin->GPC['username_strong'] = 0;
                 }
                 if (strlen($vbulletin->GPC['usertitle']) > $this->itemtypedata['options']['usertitle_max']) {
                     $vbulletin->GPC['usertitle'] = substr($vbulletin->GPC['usertitle'], 0, $this->itemtypedata['options']['usertitle_max']);
                 }
                 if (strlen($vbulletin->GPC['usertitle']) > 0) {
                     //Check for illegal usertitle
                     $usertitles = explode(' ', $vbulletin->options['ctCensorWords']);
                     $illegal_found = array();
                     foreach ($usertitles as $usertitle) {
                         $usertitle = trim($usertitle);
                         if ($usertitle and strpos(strtolower($vbulletin->GPC['usertitle']), strtolower($usertitle)) !== false) {
                             $illegal_found[] = trim($usertitle);
                         }
                     }
                     if (count($illegal_found) > 0) {
                         //Found something illegal....
                         eval(standard_error(construct_phrase($vbphrase['kbank_itemshow_customize_userinfo_usertitle_illegal'], $vbulletin->GPC['usertitle'], implode(', ', $illegal_found))));
                     }
                 }
                 $usertitle_colors = explode(',', $this->itemtypedata['options']['usertitle_colors']);
                 if (!count($usertitle_colors) || !in_array($vbulletin->GPC['usertitle_color'], $usertitle_colors)) {
                     $vbulletin->GPC['usertitle_color'] = 0;
                 }
                 $this->data['options']['username'] = $vbulletin->GPC['username'];
                 if ($vbulletin->GPC['username']) {
                     //cache original username
                     $this->data['options']['username_original'] = $vbulletin->userinfo['username'];
                 }
                 $this->data['options']['username_color'] = $vbulletin->GPC['username_color'];
                 $this->data['options']['username_strong'] = $vbulletin->GPC['username_strong'];
                 $this->data['options']['usertitle'] = $vbulletin->GPC['usertitle'];
                 $this->data['options']['usertitle_color'] = $vbulletin->GPC['usertitle_color'];
                 $this->data['options']['enabled'] = 1;
                 $this->data['options']['edit_time']++;
                 $confirmstr = md5($this->data['itemid'] . $vbulletin->userinfo['userid']);
                 if ($this->itemtypedata['options']['edit_time'] != 0 and $this->data['options']['edit_time'] >= $this->itemtypedata['options']['edit_time'] and $vbulletin->GPC['confirm'] != $confirmstr) {
                     //This is the last time member can edit options ~> Display confirmation, skip
                     $item =& $this->data;
                     $userinfo_bak = $vbulletin->userinfo;
                     $newusername = $newusertitle = '';
                     $this->work($userinfo_bak);
                     if ($this->data['options']['username'] or $this->data['options']['username_color'] or $this->data['options']['username_strong']) {
                         $newusername = construct_phrase($vbphrase['kbank_itemshow_customize_userinfo_username'], $userinfo_bak['musername']);
                     }
                     if ($this->data['options']['usertitle'] or $this->data['options']['usertitle_color']) {
                         $newusertitle = construct_phrase($vbphrase['kbank_itemshow_customize_userinfo_usertitle'], $userinfo_bak['usertitle']);
                     }
                     eval('$tmp = "' . fetch_template('kbank_template_customize_userinfo_confirm') . '";');
                     eval(standard_error($tmp));
                 }
             }
             $this->data['expire_time'] = iif(!$this->data['options']['enabled'], iif($this->data['options']['duration'] > 0, TIMENOW + $this->data['options']['duration'] * 24 * 60 * 60, -1), $this->data['expire_time']);
             //Optimizing....
             $options = array();
             foreach ($this->data['options'] as $key => $val) {
                 if ($val) {
                     $options[$key] = $val;
                 }
             }
             $item_new = array('status' => KBANK_ITEM_ENABLED, 'expire_time' => $this->data['expire_time'], 'options' => serialize($options));
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
             if ($this->itemtypedata['options']['username_max'] > 0) {
                 //only store cache if this item allow customizing username
                 updateCustomizedUsernameCache();
             }
         }
     }
     if ($action == 'disable') {
         if ($this->ready2Disable()) {
             $item_new = array('status' => KBANK_ITEM_AVAILABLE);
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
             if ($this->itemtypedata['options']['username_max'] > 0) {
                 //only store cache if this item allow customizing username
                 updateCustomizedUsernameCache();
             }
         }
     }
     if ($action == 'work' and !$this->skip) {
         //Check for running hook
         switch ($KBANK_HOOK_NAME) {
             case KBANK_GLOBAL_START:
                 if ($this->itemtypedata['options']['reveal_invi']) {
                     //Invisible Revealing
                     if (!($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canseehidden'])) {
                         global $permissions;
                         $permissions['genericpermissions'] = $vbulletin->userinfo['permissions']['genericpermissions'] ^= $vbulletin->bf_ugp_genericpermissions['canseehidden'];
                     }
                 }
                 if ($vbulletin->userinfo['userid'] == $this->data['userid']) {
                     global $customize_userinfo_users;
                     //Real username Revealing
                     if ($this->itemtypedata['options']['reveal_username']) {
                         $customize_userinfo_users['disable_username'] = true;
                     }
                     //Real usertitle Revealing
                     if ($this->itemtypedata['options']['reveal_usertitle']) {
                         $customize_userinfo_users['disable_usertitle'] = true;
                     }
                 }
                 if ($this->bypassEnableForm()) {
                     $this->skip = true;
                 }
                 break;
             case KBANK_FETCH_MUSERNAME:
                 global $kbank_userinfo_tmp;
                 $this->work($kbank_userinfo_tmp);
                 break;
         }
     }
     return parent::doAction($action);
 }
Example #5
0
 function doAction($action)
 {
     global $vbulletin, $vbphrase, $KBANK_HOOK_NAME;
     if ($action == 'use') {
         if ($this->ready2Enable()) {
             $item_new = array('status' => KBANK_ITEM_USED_WAITING, 'expire_time' => iif($this->data['options']['duration'] > 0, TIMENOW + $this->data['options']['duration'] * 24 * 60 * 60, -1));
             $vbulletin->db->query_write(fetch_query_sql($item_new, 'kbank_items', "WHERE itemid = {$this->data[itemid]}"));
             if ($this->isAvatarItem and !$this->isSigPicItem) {
                 $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'] . "do=editavatar";
             } else {
                 if (!$this->isAvatarItem and $this->isSigPicItem) {
                     $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'] . "do=editsignature";
                 } else {
                     $vbulletin->url = "profile.php?" . $vbulletin->session->vars['sessionurl'];
                 }
             }
             eval(print_standard_redirect('kbank_use_successful'));
         }
     }
     if ($action == 'work' && $KBANK_HOOK_NAME == KBANK_GLOBAL_START && THIS_SCRIPT == 'profile') {
         global $permissions;
         $this->do_permissions($permissions, $this->itemtypedata['options']);
         //Update for later use (?)
         $vbulletin->userinfo['permissions'] = $permissions;
     }
     if ($action == 'work_expired') {
         global $vbphrase, $kbank_profile_images;
         $donow = true;
         $actionStatus = true;
         echo "Processing item ID#{$this->data[itemid]}<br/>";
         //Search for activating item
         if (!isset($kbank_profile_images[$this->data['userid']])) {
             $kbank_profile_images[$this->data['userid']] = array();
             $itemtypes = $vbulletin->db->query_read("\n\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\titems.itemid AS itemid\n\t\t\t\t\t\t\t, itemtypes.options AS itemtypeoptions\n\t\t\t\t\t\tFROM `" . TABLE_PREFIX . "kbank_items` AS items\n\t\t\t\t\t\tINNER JOIN `" . TABLE_PREFIX . "kbank_itemtypes` AS itemtypes ON (itemtypes.itemtypeid = items.type)\n\t\t\t\t\t\tWHERE itemtypes.filename = 'profile_images.kbank.php'\n\t\t\t\t\t\t\tAND items.status = " . KBANK_ITEM_USED_WAITING . "\n\t\t\t\t\t\t\tAND (items.expire_time > " . TIMENOW . "\n\t\t\t\t\t\t\t\tOR items.expire_time < 0)\n\t\t\t\t\t\t\tAND items.userid = {$this->data['userid']}\n\t\t\t\t\t");
             while ($itemtype = $vbulletin->db->fetch_array($itemtypes)) {
                 $tmp = unserialize($itemtype['itemtypeoptions']);
                 foreach ($this->vars as $var) {
                     $kbank_profile_images[$this->data['userid']][$var] = max($kbank_profile_images[$this->data['userid']][$var], $tmp[$var]);
                 }
             }
         }
         //Check for activating item
         $donow = false;
         foreach ($this->vars as $var) {
             if ($kbank_profile_images[$this->data['userid']][$var] < $this->itemtypedata['options'][$var]) {
                 $donow = true;
             }
         }
         if (!$donow) {
             //Found other stuff can handle everything
             echo 'User have other item(s), nothing to do now!<br/>';
         }
         $status = array();
         $message = array();
         if ($donow) {
             $owner = fetch_userinfo($this->data['userid']);
             cache_permissions($owner, false);
             //Apply activating options to owner permissions;
             $this->do_permissions($owner['permissions'], $kbank_profile_images[$this->data['userid']]);
             foreach (array('Avatar', 'SigPic') as $type) {
                 //If this item is this type
                 eval('$work = iif($this->is' . $type . 'Item,true,false);');
                 switch ($type) {
                     case 'Avatar':
                         $table = 'customavatar';
                         $fullname = 'avatar';
                         $bits = $vbulletin->bf_ugp_genericpermissions;
                         $permkey = 'genericpermissions';
                         $canuse = 'canuseavatar';
                         $dm = 'Userpic_Avatar';
                         break;
                     case 'SigPic':
                         $table = 'sigpic';
                         $fullname = 'sigpic';
                         $bits = $vbulletin->bf_ugp_signaturepermissions;
                         $permkey = 'signaturepermissions';
                         $canuse = 'cansigpic';
                         $dm = 'Userpic_Sigpic';
                         break;
                 }
                 if ($work) {
                     $removenow = false;
                     $updatedone = false;
                     $message[$type] = '';
                     $status[$type] = 'none';
                     //Check if user using system avatar
                     if ($type == 'Avatar' and $owner['avatarid'] != 0) {
                         //Check for System Avatar (only check with type = avatar)
                         echo 'User using System Avatar, do nothing!<br/>';
                     } else {
                         //Check for custom image
                         if ($customimg = $vbulletin->db->query_first("\n\t\t\t\t\t\t\t\t\tSELECT filedata, dateline, filename, filesize\n\t\t\t\t\t\t\t\t\tFROM `" . TABLE_PREFIX . $table . "`\n\t\t\t\t\t\t\t\t\tWHERE userid = " . intval($owner['userid']) . "\n\t\t\t\t\t\t\t\t\tORDER BY dateline DESC\n\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t")) {
                             $extension = trim(substr(strrchr(strtolower($customimg['filename']), '.'), 1));
                             $tmp_filename = DIR . "/includes/tmp_profile_images_{$customimg['dateline']}.{$extension}";
                             $tmp_file = fopen($tmp_filename, 'w');
                             fwrite($tmp_file, $customimg['filedata']);
                             fclose($tmp_file);
                             require_once DIR . '/includes/class_image.php';
                             $image =& vB_Image::fetch_library($vbulletin);
                             $imginfo = $image->fetch_image_info($tmp_filename);
                             if (!($owner['permissions'][$permkey] & $bits[$canuse])) {
                                 //Check if user can use Avatar/SigPic
                                 echo "User doesn't have permission to use {$type}<br/>";
                                 $removenow = true;
                             } else {
                                 if (!($owner['permissions'][$permkey] & $bits['cananimate' . $fullname]) and $imginfo['scenes'] > 1) {
                                     //gif, we will not process this one! remove now
                                     echo "GIF image found! Remove now!<br/>";
                                     $removenow = true;
                                 } else {
                                     if ($owner['permissions'][$fullname . 'maxwidth'] < $imginfo[0] or $owner['permissions'][$fullname . 'maxheight'] < $imginfo[1] or $owner['permissions'][$fullname . 'maxsize'] < $customimg['filesize']) {
                                         //Check if current custom image exceed user permission options
                                         echo "{$type} need to be updated/removed!<br/>";
                                         if ($newimg = $image->fetch_thumbnail(basename($tmp_filename), $tmp_filename, $owner['permissions'][$fullname . 'maxwidth'], $owner['permissions'][$fullname . 'maxheight'], $vbulletin->options['thumbquality'])) {
                                             //Trying to update with smaller size
                                             echo 'Updating with smaller size! ' . $owner['permissions'][$fullname . 'maxwidth'] . 'x' . $owner['permissions'][$fullname . 'maxheight'] . '<br/>';
                                             $status[$type] = 'update';
                                             $data =& datamanager_init($dm, $vbulletin, ERRTYPE_STANDARD, 'userpic');
                                             $data->set('userid', $owner['userid']);
                                             $data->set('dateline', TIMENOW);
                                             $data->set('filename', $customimg['filename']);
                                             $data->set('width', $newimg['width']);
                                             $data->set('height', $newimg['height']);
                                             $data->setr('filedata', $newimg['filedata']);
                                             if ($newimg['width'] <= $owner['permissions'][$fullname . 'maxwidth'] and $newimg['height'] <= $owner['permissions'][$fullname . 'maxheight'] and $newimg['filesize'] <= $owner['permissions'][$fullname . 'maxsize'] and $data->save()) {
                                                 $updatedone = true;
                                             } else {
                                                 $removenow = true;
                                             }
                                         } else {
                                             $removenow = true;
                                         }
                                     } else {
                                         echo "{$type} Size Is Okie, do nothing!<br/>";
                                     }
                                 }
                             }
                             //Send PM
                             if ($updatedone) {
                                 $message[$type] = construct_phrase($vbphrase['kbank_pm_profile_images_message_update'], $newimg['width'], $newimg['height'], $type);
                             }
                             if ($removenow) {
                                 //Just remove record
                                 echo 'Just remove!<br/>';
                                 $status[$type] = 'remove';
                                 $vbulletin->db->query_write("\n\t\t\t\t\t\t\t\t\t\t\tDELETE FROM `" . TABLE_PREFIX . $table . "`\n\t\t\t\t\t\t\t\t\t\t\tWHERE userid = " . intval($owner['userid']) . "\n\t\t\t\t\t\t\t\t\t\t");
                                 $message[$type] = construct_phrase($vbphrase['kbank_pm_profile_images_message_remove'], $type);
                             }
                             @unlink($tmp_filename);
                         } else {
                             echo "No Custom {$type} found, do nothing!<br/>";
                         }
                     }
                 }
             }
             if (isset($message['Avatar']) or isset($message['SigPic'])) {
                 //Send PM
                 $from = array('userid' => 1, 'username' => $vbphrase['kbank'], 'permissions' => array('pmsendmax' => 5));
                 $to =& $owner;
                 $subject = $vbphrase['kbank_pm_profile_images_subject'];
                 $message = construct_phrase($vbphrase['kbank_pm_profile_images_message'], $this->data['name'], vbdate($vbulletin->options['dateformat'] . ' ' . $vbulletin->options['timeformat'], $this->data['expire_time']), implode(', ', $message), $vbulletin->options['bburl'] . '/' . $vbulletin->kbank['phpfile'] . '?do=myitems', $vbulletin->options['bburl'] . '/usercp.php');
                 $result = kbank_sendPM($from, $to, $subject, $message, false);
             }
         }
         $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE `" . TABLE_PREFIX . "kbank_items`\n\t\t\t\t\tSET status = " . KBANK_ITEM_USED . "\n\t\t\t\t\tWHERE itemid = {$this->data['itemid']}\n\t\t\t\t");
         if (count($status) == 2) {
             //Really? Item with both options for Avatar & SigPic. Nothing's impossible!
             return "Avatar: {$status['Avatar']}; SigPic: {$status['SigPic']}";
         } else {
             foreach ($status as $tmp) {
                 return $tmp;
             }
         }
     }
     return parent::doAction($action);
 }