├── boot.php ├── lang └── de_de.lang ├── package.yml ├── LICENSE ├── README.md └── lib └── feeds_github_markdown.php /boot.php: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /lang/de_de.lang: -------------------------------------------------------------------------------- 1 | feeds_github = GitHub 2 | feeds_github_md = GitHub 3 | feeds_github_user_name = GitHub User-Name 4 | feeds_github_repo_name = GitHub Repo-Name 5 | feeds_github_branch = GitHub Branch 6 | -------------------------------------------------------------------------------- /package.yml: -------------------------------------------------------------------------------- 1 | package: feeds_github_markdown 2 | version: '1.0.0' 3 | author: Friends Of REDAXO 4 | 5 | page: 6 | hidden: true 7 | 8 | requires: 9 | redaxo: '^5.14' 10 | php: 11 | version: '>=8.1' 12 | packages: 13 | feeds: '^4.0.0-dev' 14 | 15 | conflicts: 16 | packages: 17 | yfeed: '<=1.3.0' 18 | feeds: '<4.0.0-dev' 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Friends Of REDAXO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## feeds github markdown loader 2 | 3 | This AddOn allows you to import markdown (.md) files from GitHub repositories into your REDAXO installation. 4 | 5 | # Requirements 6 | 7 | - [REDAXO](https://github.com/redaxo/redaxo) 5.14 or higher 8 | - [feeds AddOn](https://github.com/FriendsOfREDAXO/feeds) (>=4.0.0-dev) installed and activated 9 | - php Version 8.1 or higher 10 | 11 | 12 | # Installation 13 | 14 | 1. Download the GitHub-Feeds AddOn via installer from the REDAXO AddOn repository or from the releases section of this repository. 15 | 2. Install the AddOn in your REDAXO backend using the AddOn installer. 16 | 17 | 18 | # Usage 19 | 20 | 1. Create a stream in the feeds AddOn and choose GitHub as the source type. 21 | 2. Configure the AddOn to your needs, e.g. set the repository name and branch. 22 | 23 | 24 | # Automation with cronjob 25 | 26 | You can set up a cronjob to automatically import the content from your GitHub repository. This way, you can make sure that the content is always up-to-date and does not require manual intervention. 27 | 28 | 29 | # Support 30 | If you need help with this AddOn, please open an issue in the GitHub repository or contact the author. 31 | 32 | 33 | Credits: 34 | [Ali Kemal Tuncel](https://github.com/alikmltncl61) 35 | -------------------------------------------------------------------------------- /lib/feeds_github_markdown.php: -------------------------------------------------------------------------------- 1 | rex_i18n::msg('feeds_github_user_name'), 15 | 'name' => 'user_name', 16 | 'type' => 'string', 17 | ], 18 | [ 19 | 'label' => rex_i18n::msg('feeds_github_repo_name'), 20 | 'name' => 'repo_name', 21 | 'type' => 'string', 22 | ], 23 | [ 24 | 'label' => rex_i18n::msg('feeds_github_branch'), 25 | 'name' => 'branch', 26 | 'type' => 'string', 27 | 'default' => 'main', 28 | ], 29 | ]; 30 | } 31 | public function fetch() 32 | { 33 | # Hier wird die API abgefragt und die Daten in die Datenbank geschrieben 34 | # Falls ein Unterordner angegeben wurde, wird dieser in die URL eingebaut, sonst wird der Root-Ordner abgefragt 35 | $url = ""; 36 | 37 | if ($this->typeParams['repo_name'] == "") { 38 | $url = "https://api.github.com/repos/" . $this->typeParams['user_name'] . "/" . "contents?ref=" . $this->typeParams['branch']; 39 | } else { 40 | $url = "https://api.github.com/repos/" . $this->typeParams['user_name'] . "/" . $this->typeParams['repo_name'] . "/" . "contents?ref=" . $this->typeParams['branch']; 41 | } 42 | 43 | # Prüfen ob die URL erreichbar ist 44 | $options = array( 45 | 'http' => array( 46 | 'method' => 'HEAD', 47 | 'header' => array( 48 | "User-Agent: PHP\r\n" 49 | ) 50 | ) 51 | ); 52 | $context = stream_context_create($options); 53 | $head = @get_headers($url, 1, $context); 54 | # Wenn die URL nicht erreichbar ist, wird die Funktion abgebrochen 55 | if (strpos($head[0], 'HTTP/1.1 404 Not Found') !== false || strpos($head[0], 'HTTP/1.1 403 Forbidden') !== false) { 56 | return; 57 | } else if (strpos($head[0], 'HTTP/1.1 200 OK') !== false) { 58 | # Wenn die URL erreichbar ist, werden die Daten abgefragt 59 | $options = array( 60 | 'http' => array( 61 | 'method' => 'GET', 62 | 'header' => array( 63 | "User-Agent: PHP\r\n" 64 | ) 65 | ) 66 | ); 67 | $context = stream_context_create($options); 68 | $contents = file_get_contents($url, false, $context); 69 | $contents = json_decode($contents, true); 70 | # Wenn die Daten erfolgreich abgefragt wurden, werden sie in die Datenbank geschrieben 71 | if (is_array($contents) && !empty($contents)) { 72 | # Nur Dateien mit der Endung .md werden importiert 73 | foreach ($contents as $content) { 74 | if (substr($content['name'], -3) == ".md") { 75 | $item = new rex_feeds_item($this->streamId, $content['sha']); 76 | $item->setContentRaw(file_get_contents($content['download_url'])); 77 | $item->setContent(strip_tags(file_get_contents($content['download_url']))); 78 | $item->setUrl($content['html_url']); 79 | $item->setDate(new DateTime()); 80 | $item->setRaw($content); 81 | $this->updateCount($item); 82 | $item->save(); 83 | } 84 | } 85 | self::registerExtensionPoint($this->streamId); 86 | } 87 | } 88 | } 89 | } 90 | --------------------------------------------------------------------------------