public function query($sql) { if ($sql == null) { return false; } $result = @self::_query($sql, $this->wpdb->dbh); if (!$result || @MainWPDB::num_rows($result) == 0) { return false; } return $result; }
function prepare_items($globalIgnoredPluginConflicts = array(), $globalIgnoredThemeConflicts = array()) { $this->globalIgnoredPluginConflicts = $globalIgnoredPluginConflicts; $this->globalIgnoredThemeConflicts = $globalIgnoredThemeConflicts; $orderby = 'wp.url'; if (!isset($_GET['orderby'])) { $_order_by = get_option('mainwp_managesites_orderby'); $_order = get_option('mainwp_managesites_order'); if (!empty($_order_by)) { $_GET['orderby'] = $_order_by; $_GET['order'] = $_order; } } else { MainWPUtility::update_option('mainwp_managesites_orderby', $_GET['orderby']); MainWPUtility::update_option('mainwp_managesites_order', $_GET['order']); } if (isset($_GET['orderby'])) { if ($_GET['orderby'] == 'site') { $orderby = 'wp.name ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc'); } else { if ($_GET['orderby'] == 'url') { $orderby = 'wp.url ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc'); } else { if ($_GET['orderby'] == 'group') { $orderby = 'GROUP_CONCAT(gr.name ORDER BY gr.name SEPARATOR ", ") ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc'); } else { if ($_GET['orderby'] == 'status') { $orderby = 'CASE true WHEN ((pluginConflicts <> "[]") AND (pluginConflicts IS NOT NULL) AND (pluginConflicts <> "")) THEN 1 WHEN (offline_check_result = -1) THEN 2 WHEN (wp_sync.sync_errors IS NOT NULL) AND (wp_sync.sync_errors <> "") THEN 3 ELSE 4 + (CASE plugin_upgrades WHEN "[]" THEN 0 ELSE 1 + LENGTH(plugin_upgrades) - LENGTH(REPLACE(plugin_upgrades, "\\"Name\\":", "\\"Name\\"")) END) + (CASE theme_upgrades WHEN "[]" THEN 0 ELSE 1 + LENGTH(theme_upgrades) - LENGTH(REPLACE(theme_upgrades, "\\"Name\\":", "\\"Name\\"")) END) + (CASE wp_upgrades WHEN "[]" THEN 0 ELSE 1 END) END ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc'); } else { if ($_REQUEST['orderby'] == 'last_post') { $orderby = 'wp_sync.last_post_gmt ' . ($_GET['order'] == 'asc' ? 'asc' : 'desc'); } } } } } } $perPage = $this->get_items_per_page('mainwp_managesites_per_page'); $currentPage = $this->get_pagenum(); $no_request = !isset($_REQUEST['s']) && !isset($_REQUEST['g']) && !isset($_REQUEST['status']); if (!isset($_REQUEST['status'])) { if ($no_request) { $_status = get_option('mainwp_managesites_filter_status'); if (!empty($_status)) { $_REQUEST['status'] = $_status; } } else { MainWPUtility::update_option('mainwp_managesites_filter_status', ''); } } else { MainWPUtility::update_option('mainwp_managesites_filter_status', $_REQUEST['status']); } if (!isset($_REQUEST['g'])) { if ($no_request) { $_g = get_option('mainwp_managesites_filter_group'); if (!empty($_g)) { $_REQUEST['g'] = $_g; } } else { MainWPUtility::update_option('mainwp_managesites_filter_group', ''); } } else { MainWPUtility::update_option('mainwp_managesites_filter_group', $_REQUEST['g']); } $where = null; if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') { if ($_REQUEST['status'] == 'online') { $where = 'wp.offline_check_result = 1'; } else { if ($_REQUEST['status'] == 'offline') { $where = 'wp.offline_check_result = -1'; } else { if ($_REQUEST['status'] == 'disconnected') { $where = 'wp_sync.sync_errors != ""'; } else { if ($_REQUEST['status'] == 'update') { $where = '(wp_optionview.wp_upgrades != "[]" OR wp.plugin_upgrades != "[]" OR wp.theme_upgrades != "[]")'; } } } } } if (isset($_REQUEST['g']) && $_REQUEST['g'] != '') { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($_REQUEST['g'], true)); $totalRecords = $websites ? MainWPDB::num_rows($websites) : 0; if ($websites) { @MainWPDB::free_result($websites); } if (isset($_GET['orderby']) && $_GET['orderby'] == 'group') { $orderby = 'wp.url'; } $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($_REQUEST['g'], true, $orderby, ($currentPage - 1) * $perPage, $perPage, $where)); } else { if (isset($_REQUEST['status']) && $_REQUEST['status'] != '') { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesForCurrentUser(true, null, $orderby, false, false, $where)); $totalRecords = $websites ? MainWPDB::num_rows($websites) : 0; if ($websites) { @MainWPDB::free_result($websites); } $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesForCurrentUser(true, null, $orderby, ($currentPage - 1) * $perPage, $perPage, $where)); } else { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesForCurrentUser(true, isset($_REQUEST['s']) && $_REQUEST['s'] != '' ? $_REQUEST['s'] : null, $orderby)); $totalRecords = $websites ? MainWPDB::num_rows($websites) : 0; if ($websites) { @MainWPDB::free_result($websites); } $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesForCurrentUser(true, isset($_REQUEST['s']) && $_REQUEST['s'] != '' ? $_REQUEST['s'] : null, $orderby, ($currentPage - 1) * $perPage, $perPage)); } } $this->set_pagination_args(array('total_items' => $totalRecords, 'per_page' => $perPage)); $this->items = $websites; }