コード例 #1
0
 /**
  * Action: Issue Warning
  */
 public function save()
 {
     //-----------------------------------------
     // Init
     //-----------------------------------------
     $points = 0;
     $mq = 0;
     $mq_unit = 'd';
     $rpa = 0;
     $rpa_unit = 'd';
     $suspend = 0;
     $suspend_unit = 'd';
     $banGroup = 0;
     $removePoints = 0;
     $removePointsUnit = 'd';
     //-----------------------------------------
     // Validate
     //-----------------------------------------
     $errors = array();
     if ($this->request['reason'] === '') {
         /* No reason selected */
         $errors['reason'] = $this->lang->words['warnings_err_reason'];
     } else {
         $reason = intval($this->request['reason']);
         /* "Other" reason selected */
         if (!$reason) {
             /* Check we're actually allowed to use it */
             if (!$this->memberData['g_access_cp'] and !$this->settings['warnings_enable_other']) {
                 /* Nope */
                 $errors['reason'] = $this->lang->words['warnings_err_reason'];
             } else {
                 /* If we select "Other", we determine the number of points and when they expire */
                 $points = floatval($this->request['points']);
                 $removePoints = intval($this->request['remove']);
                 $removePointsUnit = $this->request['remove_unit'] == 'h' ? 'h' : 'd';
             }
         } else {
             $reason = $this->reasons[$reason];
             /* Check it's valid */
             if (!$reason['wr_id']) {
                 /* Nope */
                 $errors['reason'] = $this->lang->words['warnings_err_reason'];
             } else {
                 /* Can we override the number of points for this reason? */
                 if ($this->memberData['g_access_cp'] or $reason['wr_points_override']) {
                     // Yes, get value from input
                     $points = floatval($this->request['points']);
                 } else {
                     // No, take whatever the reason has set
                     $points = $reason['wr_points'];
                 }
                 /* Can we override when the points expire? */
                 if ($this->memberData['g_access_cp'] or $reason['wr_remove_override']) {
                     // Yes, get value from input
                     $removePoints = intval($this->request['remove']);
                     $removePointsUnit = $this->request['remove_unit'] == 'h' ? 'h' : 'd';
                 } else {
                     // No, take whatever the reason has set
                     $removePoints = intval($reason['wr_remove']);
                     $removePointsUnit = $reason['wr_remove_unit'];
                 }
             }
             $reason = $reason['wr_id'];
         }
         /* Now let's get the action */
         $newPointLevel = floatval($this->_member['warn_level'] + $points);
         $action = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'members_warn_actions', 'where' => "wa_points<={$newPointLevel}", 'order' => 'wa_points DESC', 'limit' => 1));
         if ($action) {
             /* We have an action. Can we override it's punishment? */
             if ($action['wa_override']) {
                 // Yes, get values from input
                 $mq = $this->request['mq_perm'] ? -1 : intval($this->request['mq']);
                 $mq_unit = $this->request['mq_unit'];
                 $rpa = $this->request['rpa_perm'] ? -1 : intval($this->request['rpa']);
                 $rpa_unit = $this->request['rpa_unit'];
                 $suspend = $this->request['suspend_perm'] ? -1 : intval($this->request['suspend']);
                 $suspend_unit = $this->request['suspend_unit'];
                 $banGroup = $this->request['ban_group'] ? intval($this->request['ban_group_id']) : 0;
             } else {
                 // No, do whatever the action says
                 $mq = intval($action['wa_mq']);
                 $mq_unit = $action['wa_mq_unit'];
                 $rpa = intval($action['wa_rpa']);
                 $rpa_unit = $action['wa_rpa_unit'];
                 $suspend = intval($action['wa_suspend']);
                 $suspend_unit = $action['wa_suspend_unit'];
                 $banGroup = intval($action['wa_ban_group']);
             }
         } else {
             /* We don't have an action - are we allowed to give a custom punishment? */
             if ($this->memberData['g_access_cp'] or $this->settings['warning_custom_noaction']) {
                 // Yes, get values from input
                 $mq = $this->request['mq_perm'] ? -1 : intval($this->request['mq']);
                 $mq_unit = $this->request['mq_unit'];
                 $rpa = $this->request['rpa_perm'] ? -1 : intval($this->request['rpa']);
                 $rpa_unit = $this->request['rpa_unit'];
                 $suspend = $this->request['suspend_perm'] ? -1 : intval($this->request['suspend']);
                 $suspend_unit = $this->request['suspend_unit'];
                 $banGroup = $this->request['ban_group'] ? intval($this->request['ban_group_id']) : 0;
             } else {
                 // We're not allowed to give a punishment so this is a verbal warning only.
                 // The values we set earlier during init are fine
             }
         }
     }
     if (!empty($errors)) {
         return $this->form($errors);
     }
     //-----------------------------------------
     // Parse
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
     $editor = new $classToLoad();
     $noteForMember = $editor->process($_POST['note_member']);
     $noteForMods = $editor->process($_POST['note_mods']);
     //-----------------------------------------
     // Save Log
     //-----------------------------------------
     /* If our points are going to expire, woprk out exactly when */
     $expireDate = 0;
     if ($removePoints) {
         IPSTime::setTimestamp(time());
         if ($removePointsUnit == 'h') {
             IPSTime::add_hours($removePoints);
         } else {
             IPSTime::add_days($removePoints);
         }
         $expireDate = IPSTime::getTimestamp();
     }
     /* Log */
     $warning = array('wl_member' => $this->_member['member_id'], 'wl_moderator' => $this->memberData['member_id'], 'wl_date' => time(), 'wl_reason' => $reason, 'wl_points' => $points, 'wl_note_member' => $noteForMember, 'wl_note_mods' => $noteForMods, 'wl_mq' => $mq, 'wl_mq_unit' => $mq_unit, 'wl_rpa' => $rpa, 'wl_rpa_unit' => $rpa_unit, 'wl_suspend' => $suspend, 'wl_suspend_unit' => $suspend_unit, 'wl_ban_group' => $banGroup, 'wl_expire' => $removePoints, 'wl_expire_unit' => $removePointsUnit, 'wl_acknowledged' => $this->settings['warnings_acknowledge'] ? 0 : 1, 'wl_content_app' => trim($this->request['from_app']), 'wl_content_id1' => $this->request['from_id1'], 'wl_content_id2' => $this->request['from_id2'], 'wl_expire_date' => $expireDate);
     /* Data Hook Location */
     $warning['actionData'] = $action;
     $warning['reasonsData'] = $this->reasons;
     IPSLib::doDataHooks($warning, 'memberWarningPre');
     unset($warning['actionData'], $warning['reasonsData']);
     $this->DB->insert('members_warn_logs', $warning);
     $warning['wl_id'] = $this->DB->getInsertId();
     /* Data Hook Location */
     $warning['actionData'] = $action;
     $warning['reasonsData'] = $this->reasons;
     IPSLib::doDataHooks($warning, 'memberWarningPost');
     unset($warning['actionData'], $warning['reasonsData']);
     //-----------------------------------------
     // Actually do it
     //-----------------------------------------
     $update = array();
     /* Add Points */
     if ($points) {
         $update['warn_level'] = $this->_member['warn_level'] + $points;
     }
     /* Set Punishments */
     if ($mq) {
         $update['mod_posts'] = $mq == -1 ? 1 : IPSMember::processBanEntry(array('unit' => $mq_unit, 'timespan' => $mq));
     }
     if ($rpa) {
         $update['restrict_post'] = $rpa == -1 ? 1 : IPSMember::processBanEntry(array('unit' => $rpa_unit, 'timespan' => $rpa));
     }
     if ($suspend) {
         if ($suspend == -1) {
             $update['member_banned'] = 1;
         } else {
             $update['temp_ban'] = IPSMember::processBanEntry(array('unit' => $suspend_unit, 'timespan' => $suspend));
         }
     }
     if ($banGroup > 0) {
         if (!$this->caches['group_cache'][$banGroup]['g_access_cp'] and !$this->caches['group_cache'][$banGroup]['g_is_supmod'] and $banGroup != $this->settings['guest_group']) {
             $update['member_group_id'] = $banGroup;
         }
     }
     if ($this->settings['warnings_acknowledge']) {
         $update['unacknowledged_warnings'] = 1;
     }
     /* Save */
     if (!empty($update)) {
         IPSMember::save($this->_member['member_id'], array('core' => $update));
     }
     //-----------------------------------------
     // Work out where this warning came from
     //-----------------------------------------
     if ($warning['wl_content_app'] and IPSLib::appIsInstalled($warning['wl_content_app'])) {
         $file = IPSLib::getAppDir($warning['wl_content_app']) . '/extensions/warnings.php';
         if (is_file($file)) {
             $classToLoad = IPSLib::loadLibrary($file, 'warnings_' . $warning['wl_content_app'], $warning['wl_content_app']);
             if (class_exists($classToLoad) and method_exists($classToLoad, 'getContentUrl')) {
                 $object = new $classToLoad();
                 $content = $object->getContentUrl($warning);
             }
         }
     }
     //-----------------------------------------
     // Send notifications
     //-----------------------------------------
     /* Init */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
     $notifyLibrary = new $classToLoad($this->registry);
     /* Send to member being warned */
     if ($this->settings['warnings_acknowledge'] or $noteForMember) {
         try {
             $notifyLibrary->setMember($this->_member);
             $notifyLibrary->setFrom($this->memberData);
             $notifyLibrary->setNotificationKey('warning');
             $notifyLibrary->setNotificationUrl("app=members&module=profile&section=warnings&member={$this->_member['member_id']}");
             $notifyLibrary->setNotificationTitle(sprintf($this->lang->words['warnings_notify'], $this->registry->output->buildUrl("app=members&module=profile&section=warnings&member={$this->_member['member_id']}")));
             $notifyLibrary->setNotificationText(sprintf($this->lang->words['warnings_notify_text'], $this->_member['members_display_name'], $this->memberData['members_display_name'], $reason ? $this->reasons[$reason]['wr_name'] : $this->lang->words['warnings_reasons_other'], $noteForMember ? sprintf($this->lang->words['warnings_notify_member_note'], $noteForMember) : '', $this->settings['warn_show_own'] ? sprintf($this->lang->words['warnings_notify_view_link'], $this->registry->output->buildUrl("app=members&module=profile&section=warnings&member={$this->_member['member_id']}")) : ''));
             $notifyLibrary->sendNotification();
         } catch (Exception $e) {
         }
     }
     /* And all mods that can warn and are super_mods (split this up because of: @link http://community.invisionpower.com/tracker/issue-36960-bad-warn-query/ */
     $mods = array();
     $mids = array();
     $gids = array();
     $canWarnMids = array();
     $canWarnGids = array();
     $this->DB->build(array('select' => 'member_id, allow_warn', 'from' => 'moderators', 'where' => 'is_group=0'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $mids[$row['member_id']] = $row['member_id'];
         if ($row['allow_warn']) {
             $canWarnMids[] = $row['member_id'];
         }
     }
     $this->DB->build(array('select' => 'group_id', 'from' => 'moderators', 'where' => 'is_group=1 AND allow_warn=1'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $gids[] = $row['group_id'];
         $canWarnGids[] = $row['group_id'];
     }
     foreach ($this->caches['group_cache'] as $id => $row) {
         if ($row['g_is_supmod']) {
             $gids[] = $row['g_id'];
         }
     }
     /* Limit this because it could go a bit wrong innit */
     if (count($gids)) {
         $this->DB->build(array('select' => 'member_id', 'from' => 'members', 'where' => 'member_group_id IN (' . implode(',', $gids) . ')', 'limit' => array(0, 750)));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $mids[$row['member_id']] = $row['member_id'];
         }
     }
     $_mods = IPSMember::load($mids, 'all');
     if (count($_mods)) {
         foreach ($_mods as $id => $row) {
             if ($row['member_id'] == $this->memberData['member_id']) {
                 continue;
             }
             if ($row['g_is_supmod'] or in_array($row['member_id'], $canWarnMids) or in_array($row['member_group_id'], $canWarnGids)) {
                 $mods[$row['member_id']] = $row;
             }
         }
     }
     if (count($mods)) {
         $notifyLibrary = new $classToLoad($this->registry);
         $notifyLibrary->setMultipleRecipients($mods);
         $notifyLibrary->setFrom($this->memberData);
         $notifyLibrary->setNotificationKey('warning_mods');
         $notifyLibrary->setNotificationUrl("app=members&module=profile&section=warnings&member={$this->_member['member_id']}");
         $notifyLibrary->setNotificationTitle(sprintf($this->lang->words['warnings_notify_mod'], $this->_member['members_display_name'], $this->registry->output->buildUrl("app=members&module=profile&section=warnings&member={$this->_member['member_id']}"), $this->memberData['members_display_name']));
         $notifyLibrary->setNotificationText(sprintf($this->lang->words['warnings_notify_text_mod'], $this->_member['members_display_name'], $this->memberData['members_display_name'], $this->registry->output->buildUrl("app=members&module=profile&section=warnings&member={$this->_member['member_id']}")));
         try {
             $notifyLibrary->sendNotification();
         } catch (Exception $e) {
         }
     }
     //-----------------------------------------
     // Boink
     //-----------------------------------------
     if (empty($content['url'])) {
         $this->registry->getClass('output')->redirectScreen($this->lang->words['warnings_done'], $this->settings['base_url'] . 'app=members&amp;module=profile&amp;section=warnings&amp;member=' . $this->_member['member_id']);
     } else {
         $this->registry->getClass('output')->redirectScreen($this->lang->words['warnings_done'], $content['url']);
     }
 }
コード例 #2
0
 /**
  * Build A Chart
  */
 private function _buildChart($startTime)
 {
     //-----------------------------------------
     // Silly Timezones
     //-----------------------------------------
     $this->DB->setTimeZone($this->memberData['time_offset']);
     //-----------------------------------------
     // Init Graph
     //-----------------------------------------
     require_once IPS_KERNEL_PATH . 'classGraph.php';
     /*noLibHook*/
     $graph = new classGraph();
     $graph->options['font'] = DOC_IPS_ROOT_PATH . '/public/style_captcha/captcha_fonts/DejaVuSans.ttf';
     $graph->options['width'] = 800;
     $graph->options['height'] = 300;
     $graph->options['style3D'] = 0;
     $graph->options['charttype'] = 'Area';
     $graph->options['showgridlinesx'] = 0;
     $graph->options['showdatalabels'] = 0;
     $graph->options['title'] = '';
     $graph->options['showlegend'] = 0;
     //-----------------------------------------
     // Add Labels
     //-----------------------------------------
     $labels = array();
     if ($this->days == 1) {
         for (IPSTime::setTimestamp($startTime); IPSTime::getTimestamp() < time() + 3600; IPSTime::add_minutes(60)) {
             $labels[] = date('ga', IPSTime::getTimestamp());
         }
     } else {
         for (IPSTime::setTimestamp($startTime); IPSTime::getTimestamp() < time(); IPSTime::add_days(1)) {
             $labels[] = date('M j', IPSTime::getTimestamp());
         }
     }
     $graph->addLabels($labels);
     //-----------------------------------------
     // Return
     //-----------------------------------------
     return $graph;
 }