private function getButtons(GWF_PM $pm) { $transid = 'pm_trans_' . $pm->getID(); $u = GWF_Session::getUser(); $buttons = ''; if (false !== ($prevs = $pm->getReplyToPrev())) { foreach ($prevs as $prev) { $buttons .= GWF_Button::prev($prev->getDisplayHREF(), $this->module->lang('btn_prev')); } } if (!$pm->hasDeleted($u)) { $buttons .= GWF_Button::delete($pm->getDeleteHREF($u->getID()), $this->module->lang('btn_delete')); } else { $buttons .= GWF_Button::restore($pm->getRestoreHREF(), $this->module->lang('btn_restore')); } if ($pm->canEdit($u)) { $buttons .= GWF_Button::edit($pm->getEditHREF(), $this->module->lang('btn_edit')); } $buttons .= GWF_Button::options($pm->getAutoFolderHREF(), $this->module->lang('btn_autofolder')); if (!$pm->isGuestPM()) { $buttons .= GWF_Button::reply($pm->getReplyHREF(), $this->module->lang('btn_reply')) . PHP_EOL . GWF_Button::quote($pm->getQuoteHREF(), $this->module->lang('btn_quote')); } $u2 = $pm->getOtherUser($u); $buttons .= GWF_Button::ignore($pm->getIgnoreHREF($pm->getOtherUser($u)), $this->module->lang('btn_ignore', array($u2->display('user_name')))); $buttons .= GWF_Button::translate($pm->getTranslateHREF(), $this->module->lang('btn_translate'), '', 'gwfGoogleTrans(\'' . $transid . '\'); return false;'); if (false !== ($nexts = $pm->getReplyToNext())) { foreach ($nexts as $next) { $buttons .= GWF_Button::next($next->getDisplayHREF(), $this->module->lang('btn_next')); } } return $buttons; }
/** * Put all your PMs into auto-folders. * @return string */ private function onAutoFolder() { $user = GWF_Session::getUser(); $userid = GWF_Session::getUserID(); if (false === ($pmo = GWF_PMOptions::getPMOptions($user))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (0 >= ($peak = $pmo->getAutoFolderValue())) { return $this->module->message('msg_auto_folder_off'); } $del = GWF_PM::OWNER_DELETED; # count pm from and to user. $conditions = "(pm_owner={$userid} AND pm_options&{$del}=0)"; $db = gdo_db(); $pms = GDO::table('GWF_PM'); $sorted = array(); if (false === ($result = $pms->select('*', $conditions))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } # Sort By UID while (false !== ($row = $db->fetchAssoc($result))) { $pm = new GWF_PM($row); $other_user = $pm->getOtherUser($user); $other_uid = $other_user->getID(); if (!isset($sorted[$other_uid])) { $sorted[$other_uid] = array(); } $sorted[$other_uid][] = $pm; } $db->free($result); $back = ''; foreach ($sorted as $uid => $pms) { if (count($pms) < $peak) { continue; } $other_user = $pms[0]->getOtherUser($user); $foldername = $other_user->getVar('user_name'); # Create the folder if not exists. if (false === ($folder = GWF_PMFolder::getByName($foldername, $user))) { $folder = GWF_PMFolder::fakeFolder($user->getID(), $foldername); if (false === $folder->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $back .= $this->module->message('msg_auto_folder_created', array($other_user->displayUsername())); } $moved = 0; foreach ($pms as $pm) { if (false !== $pm->move($user, $folder)) { $moved++; } } if ($moved > 0) { $back .= $this->module->message('msg_auto_folder_moved', array($moved, $other_user->displayUsername())); } } return $back . $this->module->message('msg_auto_folder_done'); }