Get collection of all active plugins. Including network activated plugins.

@author Vova Feldman (@svovaf)
@since  1.0.9

@param int $blog_id Since 2.0.0

@return array[string]array
519961
private static function get_active_plugins( $blog_id = 0 ) {
            self::require_plugin_essentials();

            $active_plugin            = array();
            $all_plugins              = fs_get_plugins();
            $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );

            foreach ( $active_plugins_basenames as $plugin_basename ) {
                $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
            }

            return $active_plugin;
        }
795484
public function add_move_blog_link( $actions = array(), $blog_id = 0 ) {

		// Bail if main site for network.
		if ( (int) get_current_site()->blog_id === (int) $blog_id ) {
			return $actions;
		}

		$url = $this->admin_url( array(
			'action'  => 'move',
			'blog_id' => (int) $blog_id,
		) );

		if ( current_user_can( 'manage_networks' ) ) {
			$actions['move'] = '<a href="' . esc_url( $url ) . '" class="move">' . esc_html__( 'Move', 'wp-multi-network' ) . '</a>';
		}

		return $actions;
	}
1319198
protected function getPreview($blog_id, $content, $content_id) {
        $results=$this->extend('getPreview', $blog_id, $content, $content_id);
        if($results && is_array($results)) {
            $results=array_filter($results, function($v) {return !is_null($v);});
        
            if(count($results)>0) {
                return array_shift($results);
            }
        }
        
        
        //Detect if the record already exists or not so we can decide whether to create a new record or edit an existing
        $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
        if(!empty($existing) && $existing!==false && $existing->exists()) {
            $resultID=$content_id;
            
            $this->editPost($content_id, $content, false, true);
        }else {
            $resultID=$this->newPost($blog_id, $content, false, true);
            
            //Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
            if(is_object($resultID)) {
                return $resultID;
            }
            
            //Find the object
            $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($resultID))->first();
        }
        
        //Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
        if(is_object($resultID)) {
            return $resultID;
        }
        
        
        //Generate a preview token record
        $token=new KapostPreviewToken();
        $token->Code=sha1(uniqid(time().$resultID));
        $token->KapostRefID=$resultID;
        $token->write();
        
        
        //Return the details to kapost
        return array(
                    'url'=>Controller::join_links(Director::absoluteBaseURL(), 'kapost-service/preview', $resultID, '?auth='.$token->Code),
                    'id'=>$resultID
                );
    }
314640
private static function get_all_sites(
            $module_type = WP_FS__MODULE_TYPE_PLUGIN,
            $blog_id = null
        ) {
            $sites = self::get_account_option( 'sites', $module_type, $blog_id );

            if ( ! is_array( $sites ) ) {
                $sites = array();
            }

            return $sites;
        }
145625
private static function get_active_plugins_basenames( $blog_id = 0 ) {
            if ( is_multisite() && $blog_id > 0 ) {
                $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
            } else {
                $active_basenames = get_option( 'active_plugins' );
            }

            if ( is_multisite() ) {
                $network_active_basenames = get_site_option( 'active_sitewide_plugins' );

                if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
                    $active_basenames = array_merge( $active_basenames, $network_active_basenames );
                }
            }

            return $active_basenames;
        }
263610
public function index() {
        $plugins = Admin::getModels();
        $counts = array();

        // Gather record counts
        foreach ($plugins as $plugin) {
            foreach ($plugin['models'] as $model) {
                if ($model['installed']) {
                    $object = Admin::introspectModel($model['class']);

                    if ($object->hasMethod('getCount')) {
                        $count = $object->getCount();
                    } else {
                        $count = $object->find('count', array(
                            'cache' => array($model['class'], 'count'),
                            'cacheExpires' => '+24 hours'
                        ));
                    }

                    $counts[$model['class']] = $count;
                }
            }
        }

        $this->set('plugins', $plugins);
        $this->set('counts', $counts);
    }
999175
private static function get_user_opted_in_module_ids_map( $fs_user_id ) {
            self::$_static_logger->entrance();

            if ( ! is_multisite() ) {
                $installs = array_merge(
                    self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN ),
                    self::get_all_sites( WP_FS__MODULE_TYPE_THEME )
                );
            } else {
                $sites = self::get_sites();

                $installs = array();
                foreach ( $sites as $site ) {
                    $blog_id = self::get_site_blog_id( $site );

                    $installs = array_merge(
                        $installs,
                        self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id ),
                        self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id )
                    );
                }
            }

            $module_ids_map = array();
            foreach ( $installs as $install ) {
                if ( is_object( $install ) &&
                     FS_Site::is_valid_id( $install->id ) &&
                     FS_User::is_valid_id( $install->user_id ) &&
                     ( $install->user_id == $fs_user_id )
                ) {
                    $module_ids_map[ $install->plugin_id ] = true;
                }
            }

            return $module_ids_map;
        }
801593
private function get_site_options( $blog_id = 0 ) {
            if ( 0 == $blog_id || $blog_id == $this->_blog_id ) {
                return $this->_options;
            }

            return FS_Option_Manager::get_manager( $this->_id, true, $blog_id );
        }
908988
public function getPluginActivities() {
		$activities = $this->getActivities();

		if ( ! isset( $activities[ $this->plugin ] ) ) {
			$activities[ $this->plugin ] = array();
		}

		return $activities[ $this->plugin ];
	}
102101
public function getUserRoles($user_id)
    {
        $roles = array();

        foreach ((array) get_sites() as $site) {

            //Get user role
            if ($site->blog_id != 1) {
                $userSettings = get_user_meta($user_id, $this->db->prefix . $site->blog_id . '_capabilities', true);
            } else {
                $userSettings = get_user_meta($user_id, $this->db->prefix . 'capabilities', true);
            }

            //Store to settings array
            if (is_array($userSettings)) {
                $roles[$site->blog_id] = key($userSettings);
            } else {
                $roles[$site->blog_id] = false;
            }
        }

        return $roles;
    }
752705
public function all($blogId, array $params = array())
    {
        $endpoint = '/admin/blogs/'.$blogId.'/articles.json';
        $data = $this->request($endpoint, 'GET', $params);
        return $this->createCollection(Article::class, $data['articles']);
    }
266787
public static function runOnBlog( int $blog_id, callable $callback, ...$args ) {
		switch_to_blog( $blog_id );
		$result = call_user_func_array( $callback, $args );
		switch_to_blog( get_current_blog_id() );

		return $result;
	}
997122
function getBookIds() {

		/** @var $wpdb \wpdb */
		global $wpdb;

		$sql = "SELECT blogs_id FROM {$this->dbTable} WHERE users_id = %d AND deleted = 0 ";

		return $wpdb->get_col( $wpdb->prepare( $sql, $this->userId ) ); // @codingStandardsIgnoreLine
	}
795687
public function getClientActiveProjects($client_id)
    {
        $result = $this->getClientProjects( $client_id );
        if ( $result->isSuccess() ) {
            $projects = array();
            foreach ($result->data as $project) {
                if ($project->active == "true") {
                    $projects[$project->id] = $project;
                }
            }
            $result->data = $projects;
        }

        return $result;
    }
1307082
public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
            $this->_logger->entrance();

            $install = $this->get_install_by_blog_id( $context_blog_id );

            if ( ! is_object( $install ) ) {
                // Site not connected.
                return;
            }

            if ( ! self::is_site_active( $context_blog_id ) ) {
                // Site not yet active (can be in spam mode, archived, deleted...).
                return;
            }

            $current_blog_id = get_current_blog_id();

            $this->switch_to_blog( $context_blog_id );

            // Send re-activation event.
            $this->sync_install( array(
                'is_active' => true,
            ) );

            $this->switch_to_blog( $current_blog_id );
        }
273574
private function is_premium_plugin_active( $plugin_id = false ) {
            if ( $plugin_id != $this->_fs->get_id() ) {
                return $this->_fs->is_addon_activated( $plugin_id, true );
            }

            return is_plugin_active( $this->_fs->premium_plugin_basename() );
        }
829450
private function get_network( $network_id ) {
		global $wpdb;

		// Load network data
		$networks = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT * FROM $wpdb->site WHERE id = %d",
				$network_id
			)
		);

		if ( ! empty( $networks ) ) {
			// Only care about domain and path which are set here
			return $networks[0];
		}

		return false;
	}