/** * Class entry point * * @param object Registry reference * @return @e void [Outputs to screen] */ public function doExecute(ipsRegistry $registry) { $this->registry->class_localization->loadLanguageFile(array('public_reports')); $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries'); $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary'); $this->registry->setClass('reportLibrary', new $classToLoad($this->registry)); /* What to do */ switch ($this->request['do']) { case 'change_status': $this->output = $this->_changeStatus(); break; } }
/** * Runs any additional sql files * * @return @e void */ public function sqlSteps() { /* INIT */ $vars = $this->getVars(); $output = array(); $errors = array(); $id = intval($this->request['id']); $id = $id < 1 ? 1 : $id; $sql_files = array(); /* Any "extra" configs required for this driver? */ if (is_file(IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->settings['sql_driver']) . '_install.php')) { require_once IPS_ROOT_PATH . 'setup/sql/' . strtolower($this->settings['sql_driver']) . '_install.php'; /*noLibHook*/ $extra_install = new install_extra($this->registry); } /* Run any sql files we found */ if (is_file($this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ips_DBRegistry::getDriverType()) . '_sql_' . $id . '.php')) { /* INIT */ $new_id = $id + 1; $count = 0; $SQL = array(); /* Get the sql file */ require_once $this->app_full_path . 'setup/versions/install/sql/' . $vars['app_directory'] . '_' . strtolower(ips_DBRegistry::getDriverType()) . '_sql_' . $id . '.php'; /*noLibHook*/ $this->DB->return_die = 1; /* Run the queries */ foreach ($SQL as $query) { $this->DB->allow_sub_select = 1; $this->DB->error = ''; $query = str_replace("<%time%>", time(), $query); if ($extra_install and method_exists($extra_install, 'process_query_insert')) { $query = $extra_install->process_query_insert($query); } $this->DB->query($query); if ($this->DB->error) { $errors[] = $query . "<br /><br />" . $this->DB->error; } else { $count++; } } $output[] = sprintf($this->lang->words['redir__sql_run'], $count); /* Show redirect... */ $this->showRedirectScreen($vars['app_directory'], $output, $errors, $this->getNextURL('sql_steps', $vars) . '&id=' . $new_id); } else { $output[] = $this->lang->words['redir__nomore_sql']; /* Show redirect... */ $this->showRedirectScreen($vars['app_directory'], $output, $errors, $this->getNextURL('next_check', $vars)); } }
/** * Rebuild the member cache array if it is outdated * * @return integer New 'total reports' count */ public function rebuildMemberCacheArray() { $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries'); $class_perm = $this->buildQueryPermissions(); $total = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as reports', 'from' => array('rc_reports_index' => 'rep'), 'where' => $class_perm . " AND stat.is_active=1", 'add_join' => array(array('from' => array('rc_classes' => 'rcl'), 'where' => 'rcl.com_id=rep.rc_class'), array('from' => array('rc_status' => 'stat'), 'where' => 'stat.status=rep.status')))); $reports_by_plugin = array(); $this->DB->build(array('select' => 'rep.id, rep.title, rep.num_reports, rep.exdat1, rep.exdat2, rep.exdat3', 'from' => array('rc_reports_index' => 'rep'), 'where' => $class_perm . " AND (stat.is_active=1 OR stat.is_new=1) AND rcl.onoff=1", 'order' => 'stat.is_new ASC', 'add_join' => array(array('select' => 'stat.is_active, stat.is_new', 'from' => array('rc_status' => 'stat'), 'where' => 'stat.status=rep.status'), array('select' => 'rcl.com_id, rcl.com_id, rcl.my_class, rcl.extra_data, rcl.app', 'from' => array('rc_classes' => 'rcl'), 'where' => 'rcl.com_id=rep.rc_class')))); $this->DB->execute(); while ($row = $this->DB->fetch()) { if ($row['my_class'] != '') { $reports_by_plugin[$row['app']][$row['my_class']][] = $row; } } $build_member_cache_array['report_temp'] = array(); foreach ($reports_by_plugin as $app => $plugins) { if (IPSLib::appIsInstalled($app)) { foreach ($plugins as $plugin_name => $reports_array) { $this->loadPlugin($plugin_name, $app); $this->plugins[$plugin_name]->updateReportsTimestamp($reports_array, $build_member_cache_array); } } } $build_member_cache_array['report_last_updated'] = time(); $build_member_cache_array['report_num'] = $total['reports']; if (count($build_member_cache_array) > 0) { IPSMember::packMemberCache($this->memberData['member_id'], $build_member_cache_array); } return $total['reports']; }
/** * Execute selected method * * @access public * @param object Registry object * @return void */ public function doExecute(ipsRegistry $registry) { //----------------------------------------- // Load basic things //----------------------------------------- $this->registry->class_localization->loadLanguageFile(array('public_reports')); $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries'); require_once IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php'; $this->registry->setClass('reportLibrary', new reportLibrary($this->registry)); //----------------------------------------- // Check permissions... //----------------------------------------- $showReportCenter = false; $this->member_group_ids = array($this->memberData['member_group_id']); $this->member_group_ids = array_diff(array_merge($this->member_group_ids, explode(',', $this->memberData['mgroup_others'])), array('')); $report_center = array_diff(explode(',', $this->settings['report_mod_group_access']), array('')); foreach ($report_center as $groupId) { if (in_array($groupId, $this->member_group_ids)) { $showReportCenter = true; } } if ($this->request['do'] and $this->request['do'] != 'report' and !$showReportCenter) { $this->registry->output->showError('no_reports_permission', 2018, true); } $this->registry->output->setTitle($this->lang->words['main_title']); //----------------------------------------- // Which road are we going to take? //----------------------------------------- switch ($this->request['do']) { default: case 'report': $this->_initReportForm(); break; case 'showMessage': $this->_viewReportedMessage(); break; case 'index': $this->_displayReportCenter(); break; case 'process': $this->_processReports(); break; case 'findfirst': $this->findFirstReport(); break; case 'show_methods': $this->_showNotificationMethods(); break; case 'save_methods': $this->_saveNotificationMethods(); break; case 'show_report': $this->_displayReport(); break; case 'save_comment': $this->_saveComment(); break; } //----------------------------------------- // Output //----------------------------------------- $this->registry->getClass('output')->addContent($this->output); $this->registry->output->sendOutput(); }
/** * Post save * Accepts an array of GENERIC data and allows manipulation after it's added to DB * * @param string Type of action (edit/add) * @param array Array of GENERIC data (comment_xxxx) * @param int Comment id (if available) * @param int Parent id * @return array Array of GENERIC data */ public function postSave($type, array $array, $commentId = 0, $parentId = 0) { $_cnt = $this->DB->buildAndFetch(array('select' => 'count(*) as total', 'from' => 'rc_comments', 'where' => 'rid=' . $parentId)); $this->DB->update('rc_reports_index', array('num_comments' => intval($_cnt['total']), 'date_updated' => IPS_UNIX_TIME_NOW, 'updated_by' => $this->memberData['member_id']), "id=" . $parentId); $report = $this->fetchParent($parentId); //----------------------------------------- // Notify other moderators //----------------------------------------- if ($type == 'add') { $this->registry->class_localization->loadLanguageFile(array('public_reports')); $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries'); $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary'); $this->registry->setClass('reportLibrary', new $classToLoad($this->registry)); $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportNotifications.php', 'reportNotifications'); $notify = new $classToLoad($this->registry); $this->registry->getClass('reportLibrary')->loadPlugin($report['my_class'], $report['app']); if (is_object($this->registry->getClass('reportLibrary')->plugins[$report['my_class']])) { if ($report['extra_data'] && $report['extra_data'] != 'N;') { $this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->_extra = unserialize($report['extra_data']); } else { $this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->_extra = array(); } $report_data = $this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->formatReportData($report); $notify->initNotify($this->registry->getClass('reportLibrary')->plugins[$report['my_class']]->getNotificationList(IPSText::cleanPermString($report['mod_group_perm']), $report_data), $report_data); $notify->sendReplyNotifications($array['comment_text']); } } //----------------------------------------- // Mark read //----------------------------------------- $this->registry->classItemMarking->markRead(array('forumID' => 0, 'itemID' => $report['id']), 'core'); return $array; }
/** * Track * * @param string HTTP Referrer * @param string Query string * @param int Member ID */ public static function track($referrer, $queryString, $memberId) { foreach (self::$engines as $engine) { if (preg_match($engine['match'], $referrer)) { $obj = new self(); $keywords = trim($obj->{$engine['parser']}($referrer)); if (!empty($keywords)) { ipsRegistry::DB()->allow_sub_select = 1; ipsRegistry::DB()->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_seo_queries.php', 'core_seo_queries'); ipsRegistry::DB()->buildFromCache('ipseo_increment_keyword_count', IPSText::parseCleanValue($keywords), 'core_seo_queries'); ipsRegistry::DB()->allow_sub_select = 1; ipsRegistry::DB()->execute(); ipsRegistry::DB()->insert('search_visitors', array('date' => time(), 'member' => intval($memberId), 'engine' => $engine['name'], 'keywords' => $keywords, 'url' => $queryString)); } break; } } }
/** * Main function executed automatically by the controller * * @param object $registry Registry object * @return @e void */ public function doExecute(ipsRegistry $registry) { //----------------------------------------- // Load basic things //----------------------------------------- $this->registry->class_localization->loadLanguageFile(array('public_reports')); $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_report_queries.php', 'report_sql_queries'); $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php', 'reportLibrary'); $this->registry->setClass('reportLibrary', new $classToLoad($this->registry)); //----------------------------------------- // Check permissions... //----------------------------------------- if ($this->request['do'] and $this->request['do'] != 'report' and !IPSMember::isInGroup($this->memberData, explode(',', IPSText::cleanPermString($this->settings['report_mod_group_access'])))) { $this->registry->output->showError('no_reports_permission', 2018, true, null, 403); } $this->registry->output->setTitle($this->lang->words['main_title'] . ' - ' . ipsRegistry::$settings['board_name']); //----------------------------------------- // Which road are we going to take? //----------------------------------------- switch ($this->request['do']) { default: case 'report': $this->_initReportForm(); break; case 'showMessage': $this->_viewReportedMessage(); break; case 'index': $this->_displayReportCenter(); break; case 'process': $this->_processReports(); break; case 'findfirst': $this->findFirstReport(); break; case 'show_report': $this->_displayReport(); break; } if ($this->request['do'] and $this->request['do'] != 'report') { /* Init some data */ $_tabs = array(); $_activeNav = array('primary' => 'reported_content', 'secondary' => 'reports'); $moderator = $this->registry->class_forums->getModerator(); $this->registry->class_localization->loadLanguageFile(array('public_modcp'), 'core'); /** * Loop through all apps and get plugins * * @note When updating this code below remember to update also the core in public_core_modcp_modcp */ foreach (IPSLib::getEnabledApplications() as $appDir => $appData) { if (is_dir(IPSLib::getAppDir($appDir) . '/extensions/modcp')) { try { foreach (new DirectoryIterator(IPSLib::getAppDir($appDir) . '/extensions/modcp') as $file) { if (!$file->isDot() && $file->isFile()) { if (preg_match("/^plugin_(.+?)\\.php\$/", $file->getFileName(), $matches)) { //----------------------------------------- // We load each plugin so it can determine // if it should show based on permissions //----------------------------------------- $classToLoad = IPSLib::loadLibrary($file->getPathName(), 'plugin_' . $appDir . '_' . $matches[1], $appDir); $_plugins[$appDir][$matches[1]] = new $classToLoad($this->registry); if ($_plugins[$appDir][$matches[1]]->canView($moderator)) { //----------------------------------------- // Hacky solution - we want forum plugins to // come first as they're the most used //----------------------------------------- if ($appDir == 'forums' and !empty($_tabs[$_plugins[$appDir][$matches[1]]->getPrimaryTab()])) { array_unshift($_tabs[$_plugins[$appDir][$matches[1]]->getPrimaryTab()], array($_plugins[$appDir][$matches[1]]->getSecondaryTab(), $appDir, $matches[1])); } else { $_tabs[$_plugins[$appDir][$matches[1]]->getPrimaryTab()][] = array($_plugins[$appDir][$matches[1]]->getSecondaryTab(), $appDir, $matches[1]); } } } } } } catch (Exception $e) { } } } // Move trash can to the bottom - if available if (isset($_tabs['deleted_content'])) { $trashCan = $_tabs['deleted_content']; unset($_tabs['deleted_content']); $_tabs['deleted_content'] = $trashCan; } $this->output = $this->registry->output->getTemplate('modcp')->portalPage($this->output, $_tabs, $_activeNav); } //----------------------------------------- // Output //----------------------------------------- $this->registry->getClass('output')->addContent($this->output); $this->registry->output->sendOutput(); }
/** * getCloudData * * Filters: * limit Limit the number of tags returned * visible The number of visible tags * noCache Bypass any caching and always fetch fresh * * @param array Filters (limit, visible) * @return @e array */ public function getCloudData($filters = array()) { /* INIT */ $where = array(); $data = array(); $raw = array(); $nums = array('min' => 0, 'max' => 0, 'count' => 0); $final = array('tags' => array(), 'nums' => array()); /* Clean up filters */ $filters['limit'] = intval($filters['limit']); $filters['offset'] = intval($filters['offset']); $filters['visible'] = !isset($filters['visible']) ? 1 : intval($filters['visible']); if ($this->getApp() && $this->getArea() && $this->getRelId()) { $where[] = "t.tag_aai_lookup='" . $this->_getKey(array('meta_id' => $this->getRelId())) . "'"; } else { if ($this->getApp() && $this->getArea() && $this->getParentId()) { $where[] = "t.tag_aap_lookup='" . $this->_getKey(array('meta_parent_id' => $this->getParentId())) . "'"; } } if ($this->getApp()) { $where[] = "t.tag_meta_app='" . $this->DB->addSlashes($this->getApp()) . "'"; } if ($this->getArea()) { $where[] = "t.tag_meta_area='" . $this->DB->addSlashes($this->getArea()) . "'"; } /* Test against cache class */ if (empty($filters['noCache'])) { $cacheKey = 'tagCloud-' . md5(implode('&', $where)); $cached = $this->registry->getClass('cacheSimple')->get($cacheKey); if ($cached !== null && is_array($cached['data'])) { $cached['data']['cached'] = $cached['time']; return $cached['data']; } } /* Still here? Fetch from the database */ $this->DB->allow_sub_select = true; $this->DB->loadCacheFile(IPSLib::getAppDir('core') . '/sql/' . ips_DBRegistry::getDriverType() . '_tag_queries.php', 'public_tag_sql_queries'); $this->DB->buildFromCache('getCloudData', array('where' => $where, 'limit' => array($filters['offset'], $filters['limit'])), 'public_tag_sql_queries'); $o = $this->DB->execute(); while ($tag = $this->DB->fetch()) { $raw[$tag['times'] . '.' . md5($tag['tag_text'])] = $tag; if (empty($nums['min']) or $nums['min'] > $tag['times']) { $nums['min'] = $tag['times']; } if ($nums['max'] < $tag['times']) { $nums['max'] = $tag['times']; } $nums['count'] += $tag['times']; } /* Sort it */ krsort($raw); require_once IPS_ROOT_PATH . 'sources/classes/tags/bootstrap.php'; /*noLibHook*/ /* Now give out some useful data */ foreach ($raw as $key => $data) { /* Get plugin class to work out 'section' */ if (!isset($this->plugins[$data['tag_meta_area']])) { $this->plugins[$data['tag_meta_area']] = classes_tags_bootstrap::run($data['tag_meta_app'], $data['tag_meta_area']); } /* Section */ $section = $this->plugins[$data['tag_meta_area']]->getSearchSection(); /* Work out a percentage */ $percent = sprintf('%.2F', $data['times'] / $nums['max'] * 100); $final['tags'][] = array('tag' => $data['tag_text'], 'count' => $data['times'], 'app' => $data['tag_meta_app'], 'section' => $section, 'percent' => $percent, 'weight' => sprintf('%.2F', $percent / 100)); } $final['nums'] = $nums; /* Cache */ $this->registry->getClass('cacheSimple')->set($cacheKey, $final); return $final; }
/** * Restore posts * @param array $where */ public function restoreRecentPost($where) { $date = IPS_UNIX_TIME_NOW - 86400; $PRE = trim(ipsRegistry::dbFunctions()->getPrefix()); $query = array(); $remap = array('post_id' => 'pid', 'post_topic_id' => 'topic_id', 'post_author_id' => 'post_author_id'); foreach (array('post_id', 'post_topic_id', 'post_forum_id', 'post_author_id') as $k) { if (!empty($where[$k])) { $query[] = is_array($where[$k]) ? $remap[$k] . ' IN (' . implode(',', $where[$k]) . ')' : $remap[$k] . '=' . intval($where[$k]); } } if (count($query)) { $this->DB->loadCacheFile(IPSLib::getAppDir('forums') . '/sql/' . ips_DBRegistry::getDriverType() . '_topics_queries.php', 'topics_sql_queries'); $this->DB->buildFromCache('restoreRecentPost', array('query' => $query, 'date' => $date), 'topics_sql_queries'); $this->DB->allow_sub_select = true; $this->DB->execute(); } }