function install($pattern) { if (is_git_url($pattern)) { // checkout git repository into tmp directory // ROOT_PATH . "plugins" . DIRECTORY_SEPARATOR print "Try loading the plugin from " . $pattern . "... \n"; $tmp_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-' . time(); exec('git clone ' . $pattern . ' ' . $tmp_name . ' 2>&1', $ret, $err); $pkg_info = $tmp_name . DIRECTORY_SEPARATOR . 'package.json'; if (file_exists($pkg_info)) { try { $pkg_info = json_decode(file_get_contents($pkg_info), true); } catch (Error $e) { print 'Not a valid plugin: package.json could not be read.'; return true; } if (!empty($pkg_info['name'])) { $plugin_path = ROOT_PATH . 'plugins' . DIRECTORY_SEPARATOR . $pkg_info['name']; if (!file_exists($plugin_path)) { rename($tmp_name, $plugin_path); $pattern = $pkg_info['name']; // proceed with this id } else { print 'Plugin ' . $pkg_info['name'] . ' is already installed'; return true; } } else { print 'No name specified in package.json.'; return true; } } else { print 'No package.json found in repository'; return true; } } _apply($pattern, function ($id) { $tmp = new Plugin(); $tmp->setId($id); // check if plugin files exist if (!file_exists($tmp->getPath())) { global $plugin_urls; if ($plugin_urls) { if (isset($plugin_urls[$id])) { print "Found " . $id . " in plugins.json.\n"; install($plugin_urls[$id]); // try installing from git repository return true; // cancel apply loop } } print "No plugin found with that name. Skipping.\n"; return true; // cancel apply loop } if (!file_exists($tmp->getPath() . 'package.json')) { print "Path exists, but no package.json found. Skipping.\n"; return true; // cancel apply loop } // check if plugin is already installed $plugin = PluginQuery::create()->findPk($id); if ($plugin) { _loadPluginClass($plugin)->install(); print "Re-installed plugin {$id}.\n"; } else { $plugin = new Plugin(); $plugin->setId($id); $plugin->save(); _loadPluginClass($plugin)->install(); print "Installed plugin {$id}.\n"; } global $argv; if ($argv[count($argv) - 1] == '--private') { $plugin->setIsPrivate(true); $plugin->save(); print "Set plugin {$id} to private.\n"; } }); }
function download_from_git($url) { if (is_git_url($url)) { // checkout git repository into tmp directory // ROOT_PATH . "plugins" . DIRECTORY_SEPARATOR print "Try loading the plugin from git " . $url . "... \n"; // downlaod zip $tmp_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-' . time(); exec('git clone ' . $url . ' ' . $tmp_name . ' 2>&1', $ret, $err); $pkg_info = $tmp_name . DIRECTORY_SEPARATOR . 'package.json'; if (file_exists($pkg_info)) { try { $pkg_info = json_decode(file_get_contents($pkg_info), true); } catch (Error $e) { print 'Not a valid plugin: package.json could not be read.'; return true; } if (!empty($pkg_info['name'])) { $plugin_path = ROOT_PATH . 'plugins' . DIRECTORY_SEPARATOR . $pkg_info['name']; if (!file_exists($plugin_path)) { rename($tmp_name, $plugin_path); install($pkg_info['name']); } else { print 'Plugin ' . $pkg_info['name'] . ' seems to be already installed'; return true; } } else { print 'No name specified in package.json.'; return true; } } else { print 'No package.json found in repository'; return true; } } else { print 'Not a valid git repository url: ' . $url; } }