<commit_before><?php

namespace GPlane\PluginsMarket\Controllers;

use Option;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Exceptions\PrettyPageException;

class MarketController extends Controller
{
    public function show()
    {
        return view('GPlane\PluginsMarket::market');
    }

    public function ajaxPluginList()
    {
        $installed_plugins_version_list = self::loadInstalledPluginList();
        $raw_list = self::getPluginList();
        if (empty($raw_list)) {
            return response()->json(array('recordsTotal' => 0, 'data' => array()));
        }
        $plugins_list = array();
        $plugin_name_list = array_keys($raw_list);
        foreach ($plugin_name_list as $plugin_name) {
            $each_plugin = self::getSinglePluginInfo($raw_list[$plugin_name]);
            if (!$each_plugin) {
                continue;
            } else {
                $version_status = '';
                if (
                    (!empty($raw_list[$plugin_name]['isPreview']) && $raw_list[$plugin_name]['isPreview']) ||
                    (!empty($each_plugin[0]['version']) && stripos($each_plugin[0]['version'], 'rc') > 0) ||
                    (!empty($each_plugin[0]['version']) && stripos($each_plugin[0]['version'], 'beta') > 0) ||
                    (!empty($each_plugin[0]['version']) && stripos($each_plugin[0]['version'], 'alpha') > 0)) {
                    $version_status = 'preview';
                } elseif (!empty($each_plugin[0]['version']) && !empty($installed_plugins_version_list[$each_plugin['name']]) && version_compare($each_plugin[0]['version'], $installed_plugins_version_list[$each_plugin['name']]) == 1) {
                    $version_status = 'new';
                }
                $each_plugin['versionStatus'] = $version_status;
                $plugins_list[] = $each_plugin;
            }
        }
        return response()->json($plugins_list);
    }

    public static function loadInstalledPluginList()
    {
        $version_list = array();
        $resource = opendir(base_path('plugins'));
        while ($file_name = @readdir($resource)) {
            if ($file_name == '.' || $file_name == '..')
                continue;
            $plugin_path = base_path('plugins').'/'.$file_name;
            if (is_dir($plugin_path)) {
                $plugin_info = json_decode(file_get_contents($plugin_path.'/package.json'), true);
                $version_list[$plugin_info['name']] = $plugin_info['version'];
            }<commit_msg>Fix detection of new version plugins<commit_after><?php

namespace GPlane\PluginsMarket\Controllers;

use Option;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Exceptions\PrettyPageException;

class MarketController extends Controller
{
    public function show()
    {
        return view('GPlane\PluginsMarket::market');
    }

    public function ajaxPluginList()
    {
        $installed_plugins_version_list = self::loadInstalledPluginList();
        $raw_list = self::getPluginList();
        if (empty($raw_list)) {
            return response()->json(array('recordsTotal' => 0, 'data' => array()));
        }
        $plugins_list = array();
        $plugin_name_list = array_keys($raw_list);
        foreach ($plugin_name_list as $plugin_name) {
            $each_plugin = self::getSinglePluginInfo($raw_list[$plugin_name]);
            if (!$each_plugin) {
                continue;
            } else {
                $version_status = '';
                if (
                    (!empty($raw_list[$plugin_name]['isPreview']) && $raw_list[$plugin_name]['isPreview']) ||
                    (stripos(end($each_plugin['version']), 'rc') > 0) ||
                    (stripos(end($each_plugin['version']), 'beta') > 0) ||
                    (stripos(end($each_plugin['version']), 'alpha') > 0)) {
                    $version_status = 'preview';
                } elseif (!empty($installed_plugins_version_list[$each_plugin['name']]) && version_compare(end($each_plugin['version']), $installed_plugins_version_list[$each_plugin['name']]) == 1) {
                    $version_status = 'new';
                }
                $each_plugin['versionStatus'] = $version_status;
                $plugins_list[] = $each_plugin;
            }
        }
        return response()->json($plugins_list);
    }

    public static function loadInstalledPluginList()
    {
        $version_list = array();
        $resource = opendir(base_path('plugins'));
        while ($file_name = @readdir($resource)) {
            if ($file_name == '.' || $file_name == '..')
                continue;
            $plugin_path = base_path('plugins').'/'.$file_name;
            if (is_dir($plugin_path)) {
                $plugin_info = json_decode(file_get_contents($plugin_path.'/package.json'), true);
                $version_list[$plugin_info['name']] = $plugin_info['version'];
            }
{'fraction_non_alphanumeric': 0.15496661946186527, 'fraction_numerical': 0.003641513251062108, 'mean_word_length': 2.476793248945148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1064832', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1363, 'n_words': 209}