function get_repo_json($file, $plugin) { //vars $current_time = time(); $expire_time = 24 * 60 * 60; $file_time = filemtime($file); //decisions, decisions if (file_exists($file) && $current_time - $expire_time < $file_time) { //echo 'returning from cached file'; return json_decode(file_get_contents($file)); } else { $json = array(); $json['repo'] = json_decode(get_content_from_github('http://github.com/api/v2/json/repos/show/darkwing/' . $plugin), true); $json['commit'] = json_decode(get_content_from_github('http://github.com/api/v2/json/commits/list/darkwing/' . $plugin . '/master'), true); $json['readme'] = json_decode(get_content_from_github('http://github.com/api/v2/json/blob/show/darkwing/' . $plugin . '/' . $json['commit']['commits'][0]['parents'][0]['id'] . '/Docs/' . $plugin . '.md'), true); $json['js'] = json_decode(get_content_from_github('http://github.com/api/v2/json/blob/show/darkwing/' . $plugin . '/' . $json['commit']['commits'][0]['parents'][0]['id'] . '/Source/' . $plugin . '.js'), true); echo "Apples"; file_put_contents($file, json_encode($json)); return $content; } }
<?php require_once '/usr/local/emhttp/plugins/NerdPack/include/NerdPackHelpers.php'; require_once '/usr/local/emhttp/plugins/NerdPack/include/DownloadHelpers.php'; // Only download repo update if the current one is 1 hour old or more if (!is_file($repo_file) || !empty($_GET['force']) || filemtime($repo_file) < time() - 3600) { get_content_from_github($pkg_repo, $repo_file); get_content_from_github($pkg_desc, $desc_file); } $pkgs_array = []; foreach ($pkgs_github_array as $pkg_github) { $pkg_nameArray = explode('-', $pkg_github['name']); // split package name into array $pkg_name = $pkg_nameArray[0]; if (sizeof($pkg_nameArray) > 4) { //if package name has a subset get it for ($ii = 1; $ii < sizeof($pkg_nameArray) - 3; $ii++) { $pkg_name .= '-' . $pkg_nameArray[$ii]; } } $pkg_version = $pkg_nameArray[sizeof($pkg_nameArray) - 3]; // get package version $pkg_nver = $pkg_name . '-' . str_replace('.', '_', $pkg_version); // add underscored version to package name $pkg_pattern = '/^' . $pkg_name . '.*/'; // search patter for packages $pkg = ['name' => $pkg_github['name'], 'pkgname' => $pkg_name, 'pkgnver' => $pkg_nver, 'pkgversion' => $pkg_version, 'size' => format_size($pkg_github['size'], 1, '?'), 'installed' => preg_grep($pkg_pattern, $pkgs_installed) ? 'yes' : 'no', 'installeq' => in_array(pathinfo($pkg_github['name'], PATHINFO_FILENAME), $pkgs_installed) ? 'yes' : 'no', 'downloaded' => preg_grep($pkg_pattern, $pkgs_downloaded) ? 'yes' : 'no', 'downloadeq' => in_array($pkg_github['name'], $pkgs_downloaded) ? 'yes' : 'no', 'config' => isset($pkg_cfg[$pkg_nver]) ? $pkg_cfg[$pkg_nver] : 'no', 'desc' => $pkgs_desc_array[$pkg_name]]; $pkgs_array[] = $pkg; } echo json_encode($pkgs_array);
if ($content_github['tag_name'] == $current_version && $content_github['target_commitish'] == '3.3.5') { return '0'; //no updates } elseif ($content_github['tag_name'] != $current_version && $content_github['target_commitish'] == '3.3.5') { return '1'; //update } elseif ($content_github['tag_name'] != $current_version && $content_github['target_commitish'] != '3.3.5') { return 'e2'; //can't find updates for this repo } } } //url to get the lastest version (still dont know how to separate the branches) $url = 'https://api.github.com/repos/FlameNET/FlameCMS/releases/latest'; //call function get_content_from_github($url) $content_github = get_content_from_github($url); $updated = check_updates($content_github, '1.1'); if ($updated == '1') { $update_link = 'https://github.com/FlameNET/FlameCMS/archive/v' . $content_github['tag_name'] . '.zip'; } else { //not counting with errors (e1 && e2) //no updates } ?> </div> </div> </div> <?php include MODULO . 'footer.php'; ?> <!-- Cargado archivos javascript al final para que la pagina cargue mas rapido -->
include_once "markdown.php"; if (is_array($content_github)) { $changed = 0; foreach ($content_github as $item) { // debug('item', $item); if ($item->type == 'file') { $id = pathinfo($item->name, PATHINFO_FILENAME); if (!array_key_exists($id, $content)) { $content[$id] = array('path' => $item->path, 'name' => $item->name, 'html_name' => $id . '.html', 'id' => $id, 'raw_url' => $config['github_url_raw'] . $item->path, 'sha' => '', 'date' => '', 'author' => '', 'title' => '', 'tags' => ''); } $content_item = $content[$id]; // debug('content_item', $content_item); if ($item->sha != $content_item['sha']) { $changed++; // debug('item', $item); $file = get_content_from_github($content_item['raw_url']); // debug('file', $file); $yaml_end = 0; if (substr($file, 0, 3) == '---' && ($yaml_end = strpos($file, '---', 4))) { // debug('yaml_end', $yaml_end); $metadata = Spyc::YAMLLoadString(substr($file, 4, $yaml_end)); // debug('metadata', $metadata); if (array_key_exists('date', $metadata)) { $content_item['date'] = $metadata['date']; } $content_item['author'] = array_key_exists('author', $metadata) ? $metadata['author'] : $config['author']; if (array_key_exists('title', $metadata)) { $content_item['title'] = $metadata['title']; } $yaml_end += 4; // remove the closing ---
/** * download the files from github */ function downlad_files($file, $manual_id, $cache) { // while (!empty($file)) { // remove each processed file, add the files to be processed for images // } foreach ($file as $key => $value) { // if ($key == 'inkscape-userinterface') { // debug('key', $key); // debug('value', $value); foreach ($value['published'] as $kkey => $vvalue) { // debug('vvalue', $vvalue); if (MANUAL_LOCAL_FILES_REQUEST) { // debug('vvalue', $vvalue); $content = file_get_contents(MANUAL_LOCAL_CONTENT_PATH . $vvalue['raw']); } elseif (!MANUAL_DEBUG_NO_HTTP_REQUEST) { // debug('http_request content', GITHUB_RAW_URL.$vvalue['raw']); $content = get_content_from_github(GITHUB_RAW_CONTENT_URL . $vvalue['raw']); } else { $content = "# Introduction"; /* $content = " ## La fenĂȘtre principale abcd (defgh) [blah] [test](image/inkscape-user_interface-fr.png) [test a](image/inkscape-user_interface-fr.png) "; */ } // debug('content', $content); $matches = array(); if (preg_match_all('/!\\[(.*?)\\]\\((.*?)\\)/', $content, $matches)) { // debug('matches', $matches); for ($i = 0; $i < count($matches[2]); $i++) { $item = $matches[2][$i]; if (array_key_exists('content/' . $key . '/' . $item, $cache)) { // debug('url', GITHUB_RAW_CONTENT_URL.$key.'/'.$item); if (MANUAL_LOCAL_FILES_REQUEST) { $image = file_get_contents(MANUAL_LOCAL_CONTENT_PATH . $key . '/' . $item); } else { $image = get_content_from_github(GITHUB_RAW_CONTENT_URL . $key . '/' . $item); } put_cache($key . '/' . $item, $image, $manual_id); $content = str_replace('![' . $matches[1][$i] . '](' . $item . ')', '![' . $matches[1][$i] . '](cache/' . $manual_id . '/' . $key . '/' . $item . ')', $content); // TODO: find a good way to correctly set the pictures and their paths } else { Manual_log::$warning[] = "The " . $key . '/' . $item . " is referenced but can't be found in the repository"; } } } $cache_filename = $vvalue['raw']; if (array_key_exists('render', $vvalue) && $vvalue['render']['source'] == 'md' && $vvalue['render']['target'] == 'html') { $content = Markdown($content); $cache_filename = $vvalue['render']['filename']; } // debug('content', $content); put_cache($cache_filename, $content, $manual_id); } // } } }
<?php $repo = 'https://api.github.com/repos/linuxserver/Aesir/tarball/master'; $file = '/boot/config/plugins/aesir-plugin/aesir-master.tar.gz'; $temp = '/tmp/aesir-master.tar.gz'; if (!is_file($temp)) { get_content_from_github($repo, $temp); } if (is_file($file) && is_file($temp)) { if (sha1_file($file) == sha1_file($temp)) { unlink($temp); } } echo json_encode(is_file($temp)); // get file from github function get_content_from_github($repo, $file) { $context = stream_context_create(array('http' => array('header' => 'User-Agent: unRAID'))); $download = file_get_contents($repo, false, $context); if (!empty($download)) { file_put_contents($file, $download); } unset($download); }