function csp_po_collect_by_type($type){
	$res = array();
	if (empty($type) || ($type == 'wordpress')) {
		$res[] = csp_po_get_wordpress_capabilities();
	}
	if (empty($type) || ($type == 'plugins')) {
		//WARNING: Plugin handling is not well coded by WordPress core
		$err = error_reporting(0);
		$plugs = get_plugins(); 
		error_reporting($err);
		$textdomains = array();
		foreach($plugs as $key => $value) { 
			$data = csp_po_get_plugin_capabilities($key, $value);
			if (!$data['gettext_ready']) continue;
			if (in_array($data['textdomain'], $textdomains)) {
				for ($i=0; $i<count($res); $i++) {
					if ($data['textdomain'] == $res[$i]['textdomain']) {
						$res[$i]['child-plugins'][] = $data;
						break;
					}
				}
			}
			else{
				array_push($textdomains, $data['textdomain']);
				$res[] = $data;
			}
		}
	}
	if (isset($GLOBALS['wpmu_version'])) {
		if (empty($type) || ($type == 'plugins_mu')) {
			$plugs = array();
			$textdomains = array();
			if( is_dir( WPMU_PLUGIN_DIR ) ) {
				if( $dh = opendir( WPMU_PLUGIN_DIR ) ) {
					while( ( $plugin = readdir( $dh ) ) !== false ) {
						if( substr( $plugin, -4 ) == '.php' ) {
							$plugs[$plugin] = get_plugin_data( WPMU_PLUGIN_DIR . '/' . $plugin );
						}
					}
				}
			}		
			foreach($plugs as $key => $value) { 
				$data = csp_po_get_plugin_mu_capabilities($key, $value);
				if (!$data['gettext_ready']) continue;
				if (in_array($data['textdomain'], $textdomains)) {
					for ($i=0; $i<count($res); $i++) {
						if ($data['textdomain'] == $res[$i]['textdomain']) {
							$res[$i]['child-plugins'][] = $data;
							break;
						}
					}
				}
				else{
					array_push($textdomains, $data['textdomain']);
					$res[] = $data;
				}
			}
		}
	}
	if (empty($type) || ($type == 'themes')) {
		$themes = get_themes();
		//WARNING: Theme handling is not well coded by WordPress core
		$err = error_reporting(0);
		$ct = current_theme_info();
		error_reporting($err);
		foreach($themes as $key => $value) { 
			$data = csp_po_get_theme_capabilities($key, $value, $ct);
			if (!$data['gettext_ready']) continue;
			$res[] = $data;
		}	
	}
	return $res;
}
Ejemplo n.º 2
0
function csp_po_collect_by_type($type)
{
    $res = array();
    $do_compat_filter = $type == 'compat';
    $do_security_filter = $type == 'security';
    if ($do_compat_filter || $do_security_filter) {
        $type = '';
    }
    if (empty($type) || $type == 'wordpress') {
        if (!$do_compat_filter && !$do_security_filter) {
            $res[] = csp_po_get_wordpress_capabilities();
        }
    }
    if (empty($type) || $type == 'plugins') {
        //WARNING: Plugin handling is not well coded by WordPress core
        $err = error_reporting(0);
        $plugs = get_plugins();
        error_reporting($err);
        $textdomains = array();
        foreach ($plugs as $key => $value) {
            $data = null;
            if (dirname($key) == 'buddypress') {
                if ($do_compat_filter || $do_security_filter) {
                    continue;
                }
                $data = csp_po_get_buddypress_capabilities($key, $value);
                $res[] = $data;
                $data = csp_po_get_bbpress_on_buddypress_capabilities($key, $value);
                if ($data !== false) {
                    $res[] = $data;
                }
            } else {
                $data = csp_po_get_plugin_capabilities($key, $value);
                if (!$data['gettext_ready']) {
                    continue;
                }
                if (in_array($data['textdomain'], $textdomains)) {
                    for ($i = 0; $i < count($res); $i++) {
                        if ($data['textdomain'] == $res[$i]['textdomain']) {
                            $res[$i]['child-plugins'][] = $data;
                            break;
                        }
                    }
                } else {
                    if ($do_compat_filter && !isset($data['dev-hints'])) {
                        continue;
                    } elseif ($do_security_filter && !isset($data['dev-security'])) {
                        continue;
                    }
                    array_push($textdomains, $data['textdomain']);
                    $res[] = $data;
                }
            }
        }
    }
    if (csp_is_multisite()) {
        if (empty($type) || $type == 'plugins_mu') {
            $plugs = array();
            $textdomains = array();
            if (is_dir(WPMU_PLUGIN_DIR)) {
                if ($dh = opendir(WPMU_PLUGIN_DIR)) {
                    while (($plugin = readdir($dh)) !== false) {
                        if (substr($plugin, -4) == '.php') {
                            $plugs[$plugin] = get_plugin_data(WPMU_PLUGIN_DIR . '/' . $plugin);
                        }
                    }
                }
            }
            foreach ($plugs as $key => $value) {
                $data = csp_po_get_plugin_mu_capabilities($key, $value);
                if (!$data['gettext_ready']) {
                    continue;
                }
                if ($do_compat_filter && !isset($data['dev-hints'])) {
                    continue;
                } elseif ($do_security_filter && !isset($data['dev-security'])) {
                    continue;
                }
                if (in_array($data['textdomain'], $textdomains)) {
                    for ($i = 0; $i < count($res); $i++) {
                        if ($data['textdomain'] == $res[$i]['textdomain']) {
                            $res[$i]['child-plugins'][] = $data;
                            break;
                        }
                    }
                } else {
                    if ($do_compat_filter && !isset($data['dev-hints'])) {
                        continue;
                    } elseif ($do_security_filter && !isset($data['dev-security'])) {
                        continue;
                    }
                    array_push($textdomains, $data['textdomain']);
                    $res[] = $data;
                }
            }
        }
    }
    if (empty($type) || $type == 'themes') {
        $themes = function_exists('wp_get_themes') ? wp_get_themes() : get_themes();
        //WARNING: Theme handling is not well coded by WordPress core
        $err = error_reporting(0);
        $ct = function_exists('wp_get_theme') ? wp_get_theme() : current_theme_info();
        error_reporting($err);
        foreach ($themes as $key => $value) {
            $data = csp_po_get_theme_capabilities($key, $value, $ct);
            if (!$data['gettext_ready']) {
                continue;
            }
            if ($do_compat_filter && !isset($data['dev-hints'])) {
                continue;
            } elseif ($do_security_filter && !isset($data['dev-security'])) {
                continue;
            }
            $res[] = $data;
        }
    }
    return $res;
}