From fc4ea3e6e673cd9f26c211ba360562a57356f367 Mon Sep 17 00:00:00 2001
From: Rasmus Fuhse <krassmus@gmail.com>
Date: Tue, 16 Sep 2014 15:26:45 +0200
Subject: [PATCH] add github readme-import for description

---
 classes/MarketRelease.class.php   |  15 ++++
 controllers/myplugins.php         |   6 ++
 install.sql                       |   3 +-
 views/myplugins/_edit_release.php |  16 +++--
 views/myplugins/edit.php          |  17 +++++
 views/presenting/details.php      | 112 ++++++++++++++++--------------
 6 files changed, 112 insertions(+), 57 deletions(-)

diff --git a/classes/MarketRelease.class.php b/classes/MarketRelease.class.php
index 917499f..1b7e035 100644
--- a/classes/MarketRelease.class.php
+++ b/classes/MarketRelease.class.php
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'lib/datei.inc.php';
+require_once __DIR__."/../vendor/Parsedown.php";
 
 class MarketRelease extends SimpleORMap {
 
@@ -89,6 +90,20 @@ class MarketRelease extends SimpleORMap {
         if (!$this['version']) {
             $this['version'] = $manifest['version'];
         }
+        if ($this['repository_overwrites_descriptionfrom']) {
+            $readme = "";
+            $scanner = scandir($dir);
+            foreach ($scanner as $file) {
+                if (strtolower($file) === "readme.md" || strtolower($file) === "readme.markdown") {
+                    $readme = file_get_contents($dir."/".$file);
+                }
+            }
+            if ($readme) {
+                $html = Parsedown::instance()->text($readme);
+                $this->plugin['description'] = "<div>".$html."</div>";
+                $this->plugin->store();
+            }
+        }
         $hash = md5(uniqid());
         $plugin_raw = $GLOBALS['TMP_PATH']."/plugin_$hash.zip";
         create_zip_from_directory($dir, $plugin_raw);
diff --git a/controllers/myplugins.php b/controllers/myplugins.php
index 7a8cba3..6ace500 100644
--- a/controllers/myplugins.php
+++ b/controllers/myplugins.php
@@ -73,6 +73,9 @@ class MypluginsController extends PluginController {
             if (!isset($data["publiclyvisible"])) {
                 $data['publiclyvisible'] = 0;
             }
+            if (!isset($data["donationsaccepted"])) {
+                $data['donationsaccepted'] = 0;
+            }
             $this->marketplugin->setData($data);
             if ($this->marketplugin->isNew()) {
                 $this->marketplugin['user_id'] = $GLOBALS['user']->id;
@@ -116,6 +119,9 @@ class MypluginsController extends PluginController {
             $release_data = Request::getArray("release");
             if ($release_data['type'] !== "zipfile" || $_FILES['release_file']['tmp_path']) {
                 $release = new MarketRelease();
+                if (!isset($release_data['repository_overwrites_descriptionfrom'])) {
+                    $release_data['repository_overwrites_descriptionfrom'] = 0;
+                }
                 $release->setData($release_data);
                 $release['plugin_id'] = $this->marketplugin->getId();
                 $release['user_id'] = $GLOBALS['user']->id;
diff --git a/install.sql b/install.sql
index eafc817..36defb4 100644
--- a/install.sql
+++ b/install.sql
@@ -8,7 +8,8 @@ CREATE TABLE IF NOT EXISTS `pluginmarket_plugins` (
     `short_description` text NOT NULL,
     `release_type` varchar(255) default NULL,
     `approved` tinyint(2) NOT NULL default '0',
-    `publiclyvisible` TINYINT NOT NULL DEFAULT '1'
+    `publiclyvisible` TINYINT NOT NULL DEFAULT '1',
+    `donationsaccepted` TINYINT NOT NULL DEFAULT '1',
     `url` varchar(2000) default NULL,
     `classification` enum('firstclass','secondclass','none') NOT NULL default 'none',
     `language` enum('de','en','de_en') NOT NULL default 'de',
diff --git a/views/myplugins/_edit_release.php b/views/myplugins/_edit_release.php
index 2327c0b..798ed06 100644
--- a/views/myplugins/_edit_release.php
+++ b/views/myplugins/_edit_release.php
@@ -27,16 +27,16 @@ if ($_SERVER['HTTPS'] == 'on' && $_SERVER['SERVER_PORT'] != 443 ||
 
     <div>
         <label>
-            <input type="radio" name="release[type]" value="zipfile"<?= !$release['repository_download_url'] ? " checked" : "" ?>>
+            <input type="radio" name="release[type]" value="zipfile"<?= !$release['repository_download_url'] ? " checked" : "" ?> onChange="if (this.checked) { jQuery('fieldset.release_zip_upload').show(); jQuery('fieldset.release_internet_repository').hide(); } else { jQuery('fieldset.release_zip_upload').hide(); jQuery('fieldset.release_internet_repository').show(); }">
             <?= _("Als Datei") ?>
         </label>
         <label>
-            <input type="radio" name="release[type]" value="git"<?= $release['repository_download_url'] ? " checked" : "" ?>>
+            <input type="radio" name="release[type]" value="git"<?= $release['repository_download_url'] ? " checked" : "" ?> onChange="if (!this.checked) { jQuery('fieldset.release_zip_upload').show(); jQuery('fieldset.release_internet_repository').hide(); } else { jQuery('fieldset.release_zip_upload').hide(); jQuery('fieldset.release_internet_repository').show(); }">
             <?= _("Als Git-Branch") ?>
         </label>
     </div>
 
-    <fieldset>
+    <fieldset class="release_zip_upload"<?= $release['repository_download_url'] ? ' style="display: none;"' : "" ?>>
         <legend>
             <?= _("ZIP ausw�hlen") ?>
         </legend>
@@ -48,7 +48,7 @@ if ($_SERVER['HTTPS'] == 'on' && $_SERVER['SERVER_PORT'] != 443 ||
         </label>
     </fieldset>
 
-    <fieldset>
+    <fieldset class="release_internet_repository"<?= $release->isNew() || !$release['repository_download_url'] ? ' style="display: none;"' : "" ?>>
         <legend>
             <?= _("Git-Branch") ?>
         </legend>
@@ -60,10 +60,16 @@ if ($_SERVER['HTTPS'] == 'on' && $_SERVER['SERVER_PORT'] != 443 ||
         <p class="info">
             <?= _("Github.com und gitlab bieten zu jedem Branch und Tag den Download als ZIP-Datei an. Klicken Sie dort mit rechter Maustaste auf den Downloadbutton und kopieren Sie die URL, um sie hier einzuf�gen. Nach dem Speichern hier k�nnen Sie auf github bzw. gitlab Webhooks einrichten, damit der Marktplatz sich automatisch die neuste Version des Plugins vom Repository holt. Damit ist das Plugin auf dem Pluginmarktplatz immer brandaktuell.") ?>
         </p>
+
+        <label>
+            <input type="checkbox" name="release[repository_overwrites_descriptionfrom]" value="1"<?= $release['repository_overwrites_descriptionfrom'] ? " checked" : "" ?>>
+            <?= _("Readme-Datei dieses Repositorys als Beschreibung des Plugins verwenden") ?>
+        </label>
+
         <? if (!$release->isNew()) : ?>
         <p class="info">
             <?= _("Webhook-URL zum Einf�gen in github oder gitlab:") ?>
-            <input type="text" style="border: thin solid #cccccc; background-color: #eeeeee; width:100%;" value="<?= $DOMAIN_STUDIP.URLHelper::getLink("plugins.php/pluginmarket/upate/".$release->getId(), array('s' => $release->getSecurityHash()), true) ?>">
+            <input type="text" readonly style="border: thin solid #cccccc; background-color: #eeeeee; width:100%;" value="<?= $DOMAIN_STUDIP.URLHelper::getLink("plugins.php/pluginmarket/upate/".$release->getId(), array('s' => $release->getSecurityHash()), true) ?>">
         </p>
             <? if ($domain_warning) : ?>
             <p class="info"><?= htmlReady($domain_warning)  ?></p>
diff --git a/views/myplugins/edit.php b/views/myplugins/edit.php
index f50f05b..af0f171 100644
--- a/views/myplugins/edit.php
+++ b/views/myplugins/edit.php
@@ -33,6 +33,16 @@
             <input type="checkbox" name="data[publiclyvisible]" value="1"<?= $marketplugin->isNew() || $marketplugin['publiclyvisible'] ? " checked" : "" ?>>
         </label>
 
+        <label>
+            <?= _("In Benutzung bei") ?>
+            <textarea name="data[in_use]"><?= htmlReady($marketplugin['in_use']) ?></textarea>
+        </label>
+
+        <label>
+            <?= _("Projekthomepage") ?>
+            <input type="text" name="data[url]" value="<?= htmlReady($marketplugin['url']) ?>">
+        </label>
+
         <div>
             <?= _("Lizenz") ?>
             <input type="hidden" name="data[license]" value="GPL 2 or later">
@@ -40,6 +50,13 @@
                 <?= _("Stud.IP-Plugins m�ssen immer mindestens GPL 2 lizensiert sein. Durch das Hochladen erkl�ren Sie, dass auch Ihr Plugin unter der GPL liegt und liegen darf. Wenn Sie nicht das Recht haben, das zu entscheiden, laden Sie jetzt bitte nichts hoch.") ?>
             </p>
         </div>
+
+        <label>
+            <?= _("M�glichkeit zum Spenden einblenden") ?>
+            <input type="checkbox" name="data[donationsaccepted]" value="1"<?= $marketplugin->isNew() || $marketplugin['donationsaccepted'] ? " checked" : "" ?>>
+        </label>
+
+
     </fieldset>
 
     <?= $this->render_partial("myplugins/_edit_images.php", compact("marketplugin")) ?>
diff --git a/views/presenting/details.php b/views/presenting/details.php
index 66e7bc4..3b42917 100644
--- a/views/presenting/details.php
+++ b/views/presenting/details.php
@@ -34,6 +34,16 @@ if ($icon) {
 </ol>
 <? endif ?>
 
+<? if (trim($marketplugin['in_use'])) : ?>
+    <h2><?= _("In Benutzung bei") ?></h2>
+    <div><?= formatReady($marketplugin['in_use']) ?></div>
+<? endif ?>
+
+<? if ($marketplugin['url']) : ?>
+    <h2><?= _("Projekthomepage") ?></h2>
+    <div><?= formatLinks($marketplugin['url']) ?></div>
+<? endif ?>
+
 <h2><?= _("Zum Autor") ?></h2>
 <ul class="clean">
     <li>
@@ -88,60 +98,60 @@ if ($icon) {
 
 
 
-<?
-//Donations, wenn die Datenfelder "Flattr", "Bitcoin-Wallet" gesetzt sind
-$author = User::find($marketplugin['user_id']);
-$flattr_username = $author['datafields']->findBy("name", "Flattr")->val("content");
-$bitcoin_datafield = $author['datafields']->findBy("name", "Bitcoin-Wallet")->val("content");
-$paypal_datafield = $author['datafields']->findBy("name", "Paypal-Account (Email)")->val("content");
-?>
-
-<? if ($flattr_username || $bitcoin_wallet || $paypal_datafield) : ?>
-    <h2><?= _("Spenden") ?></h2>
-    <p class="info">
-        <?= _("Der Download ist kostenlos, aber man kann dem Autor mit einer Spende danken und zuk�nftige Entwicklungen anregen.") ?>
-    </p>
-<? endif ?>
-
-<div style="text-align: center;">
-    <? if ($flattr_username) : ?>
-        <script id='fbowlml'>(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//api.flattr.com/button/view/?uid=<?= urlencode(studip_utf8encode($flattr_username)) ?>&url='+encodeURIComponent(document.URL)+'&title=<?= urlencode(studip_utf8encode($marketplugin['name']." "._("f�r Stud.IP"))) ?>';f.title='Flattr';f.height=62;f.width=55;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('fbowlml');</script>
-    <? endif ?>
-
-    <? if ($bitcoin_wallet) : ?>
-        <script src="http://coinwidget.com/widget/coin.js"></script>
-        <script>
-            CoinWidgetCom.go({
-                wallet_address: "<?= htmlReady($bitcoin_wallet) ?>"
-                , currency: "bitcoin"
-                , counter: "count"
-                , alignment: "bl"
-                , qrcode: true
-                , auto_show: false
-                , lbl_button: "Donate"
-                , lbl_address: "My Bitcoin Address:"
-                , lbl_count: "donations"
-                , lbl_amount: "BTC"
-            });
-        </script>
-    <? endif ?>
-
-    <? if ($paypal_datafield) : ?>
-        <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" style="display: inline-block;">
-            <div><strong><img src="http://pics.ebaystatic.com/aw/pics/logos/logoPayPal_51x14.gif"></strong></div>
-            <input type="hidden" name="cmd" value="_donations">
-            <input type="hidden" name="business" value="<?= htmlReady($paypal_datafield) ?>">
-            <input type="hidden" name="lc" value="DE">
-            <input type="hidden" name="no_note" value="0">
-            <input type="hidden" name="currency_code" value="USD">
-            <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHostedGuest">
-            <input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen � mit PayPal.">
-            <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
-        </form>
+<? if ($marketplugin['donationsaccepted']) : ?>
+    <?
+    //Donations, wenn die Datenfelder "Flattr", "Bitcoin-Wallet" gesetzt sind
+    $author = User::find($marketplugin['user_id']);
+    $flattr_username = $author['datafields']->findBy("name", "Flattr")->val("content");
+    $bitcoin_datafield = $author['datafields']->findBy("name", "Bitcoin-Wallet")->val("content");
+    $paypal_datafield = $author['datafields']->findBy("name", "Paypal-Account (Email)")->val("content");
+    ?>
 
+    <? if ($flattr_username || $bitcoin_wallet || $paypal_datafield) : ?>
+        <h2><?= _("Spenden") ?></h2>
+        <p class="info">
+            <?= _("Der Download ist kostenlos, aber man kann dem Autor mit einer Spende danken und zuk�nftige Entwicklungen anregen.") ?>
+        </p>
     <? endif ?>
-</div>
 
+    <div style="text-align: center;">
+        <? if ($flattr_username) : ?>
+            <script id='fbowlml'>(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//api.flattr.com/button/view/?uid=<?= urlencode(studip_utf8encode($flattr_username)) ?>&url='+encodeURIComponent(document.URL)+'&title=<?= urlencode(studip_utf8encode($marketplugin['name']." "._("f�r Stud.IP"))) ?>';f.title='Flattr';f.height=62;f.width=55;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('fbowlml');</script>
+        <? endif ?>
+
+        <? if ($bitcoin_wallet) : ?>
+            <script src="http://coinwidget.com/widget/coin.js"></script>
+            <script>
+                CoinWidgetCom.go({
+                    wallet_address: "<?= htmlReady($bitcoin_wallet) ?>"
+                    , currency: "bitcoin"
+                    , counter: "count"
+                    , alignment: "bl"
+                    , qrcode: true
+                    , auto_show: false
+                    , lbl_button: "Donate"
+                    , lbl_address: "My Bitcoin Address:"
+                    , lbl_count: "donations"
+                    , lbl_amount: "BTC"
+                });
+            </script>
+        <? endif ?>
+
+        <? if ($paypal_datafield) : ?>
+            <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" style="display: inline-block;">
+                <div><strong><img src="http://pics.ebaystatic.com/aw/pics/logos/logoPayPal_51x14.gif"></strong></div>
+                <input type="hidden" name="cmd" value="_donations">
+                <input type="hidden" name="business" value="<?= htmlReady($paypal_datafield) ?>">
+                <input type="hidden" name="lc" value="DE">
+                <input type="hidden" name="no_note" value="0">
+                <input type="hidden" name="currency_code" value="EUR">
+                <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHostedGuest">
+                <input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen � mit PayPal.">
+                <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
+            </form>
+        <? endif ?>
+    </div>
+<? endif ?>
 
 
 
-- 
GitLab