]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge branch 'Flattr' of git://github.com/tcitworld/poche into tcitworld-Flattr
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Tue, 10 Sep 2013 17:22:47 +0000 (19:22 +0200)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Tue, 10 Sep 2013 17:22:47 +0000 (19:22 +0200)
Conflicts:
inc/3rdparty/site_config

1  2 
inc/3rdparty/FlattrItem.class.php
inc/poche/Poche.class.php
inc/poche/config.inc.php
inc/poche/define.inc.php
tpl/view.twig

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..c940fcd65c63621da772c26030d1ee8389e947c2
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,49 @@@
++<?php
++/* 
++* Class for Flattr querying
++*/
++class FlattrItem {
++
++    public $status;
++    public $urltoflattr;
++    public $flattrItemURL;
++    public $numflattrs;
++
++    public function checkItem($urltoflattr) {
++        $this->cacheflattrfile($urltoflattr);
++        $flattrResponse = file_get_contents(CACHE . "/flattr/".base64_encode($urltoflattr).".cache");
++        if($flattrResponse != FALSE) {
++            $result = json_decode($flattrResponse);
++            if (isset($result->message)){
++                if ($result->message == "flattrable") {
++                    $this->status = FLATTRABLE;
++                }
++            } 
++            elseif ($result->link) {
++                $this->status = FLATTRED;
++                $this->flattrItemURL = $result->link;
++                $this->numflattrs = $result->flattrs;
++            }
++            else {
++                $this->status = NOT_FLATTRABLE;
++            }
++        }
++        else {
++            $this->status = "FLATTR_ERR_CONNECTION";
++        }
++    }
++
++    private function cacheflattrfile($urltoflattr) {
++        if (!is_dir(CACHE . '/flattr')) {
++            mkdir(CACHE . '/flattr', 0777);
++        }
++
++        // if a cache flattr file for this url already exists and it's been less than one day than it have been updated, see in /cache
++        if ((!file_exists(CACHE . "/flattr/".base64_encode($urltoflattr).".cache")) || (time() - filemtime(CACHE . "/flattr/".base64_encode($urltoflattr).".cache") > 86400)) {
++            $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr);
++            $flattrCacheFile = fopen(CACHE . "/flattr/".base64_encode($urltoflattr).".cache", 'w+');
++            fwrite($flattrCacheFile, $askForFlattr);
++            fclose($flattrCacheFile);
++        }
++    }
++}
index 534e660ade2a69f53d11c7fb9aaab2463d2eaf15,b0efe69a673f9e8f4f241a7964a0bb5e78fbdb5e..9db4a0346eb539b12dc75b887e0dbdb5efb5508e
@@@ -247,17 -247,23 +247,23 @@@ class Poch
                          $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
                          $tidy->cleanRepair();
                          $content = $tidy->value;
-                     }
-                     $tpl_vars = array(
 -                        // flattr checking
++                        # flattr checking
+                         $flattr = new FlattrItem();
 -                        $flattr->checkitem($entry['url']);
++                        $flattr->checkItem($entry['url']);
+                         $tpl_vars = array(
                          'entry' => $entry,
                          'content' => $content,
-                     );
+                         'flattr' => $flattr
+                         );
+                     }
                  }
                  else {
                      Tools::logm('error in view call : entry is null');
                  }
                  break;
-             default: # home, favorites and archive views
 -            default : // home, favorites and archive views
++            default: # home, favorites and archive views 
                  $entries = $this->store->getEntriesByView($view, $this->user->getId());
                  $tpl_vars = array(
                      'entries' => '',
index 7f1b8c92b2d83438319f23baa4b20804ec89fb47,a1917295fbb292c205bc4efb9c259d1fc8bbd06f..45526695acc28adf3db3a112d939ca8858223395
@@@ -37,6 -40,6 +37,7 @@@ require_once __DIR__ . '/../../inc/3rdp
  require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedItem.php';
  require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedWriter.php';
  require_once __DIR__ . '/../../inc/3rdparty/feedwriter/DummySingleItemFeed.php';
++require_once __DIR__ . '/../../inc/3rdparty/FlattrItem.class.php';
  
  if (DOWNLOAD_PICTURES) {
      require_once __DIR__ . '/../../inc/poche/pochePictures.php';
index 53c275ddb555a8b2bba79faec40c72167c463458,62777282a34687d9c193e23c71e4c14d66af9cd3..40f77b5c29ed3cb70519d7d39e831697481e59a2
@@@ -20,8 -20,9 +20,13 @@@ define ('DEBUG_POCHE', FALSE)
  define ('DOWNLOAD_PICTURES', FALSE);
  define ('SHARE_TWITTER', TRUE);
  define ('SHARE_MAIL', TRUE);
 -define ('SHARE_SHAARLI', TRUE);
 +define ('SHARE_SHAARLI', FALSE);
  define ('SHAARLI_URL', 'http://myshaarliurl.com');
+ define ('FLATTR', TRUE);
++define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url=');
++define ('NOT_FLATTRABLE', '0');
++define ('FLATTRABLE', '1');
++define ('FLATTRED', '2');
  define ('ABS_PATH', 'assets/');
  define ('TPL', __DIR__ . '/../../tpl');
  define ('LOCALE', __DIR__  . '/../../locale');
diff --cc tpl/view.twig
index 285087723b2e008b4be4bac3bd2090b4fa13d957,283cfb5b5fdd19c2f06c01c91d57acfb110e7e6e..ee16afa6164665daf55292cccb5c0f4e9a4f1a32
@@@ -11,6 -11,7 +11,7 @@@
                      {% if constant('SHARE_TWITTER') == 1 %}<li><a href="https://twitter.com/home?status={{entry.title|url_encode}}%20{{ entry.url|url_encode }}%20via%20@getpoche" target="_blank" class="tool twitter" title="{% trans "tweet" %}"><span>{% trans "tweet" %}</span></a></li>{% endif %}
                      {% if constant('SHARE_MAIL') == 1 %}<li><a href="mailto:?subject={{ entry.title|url_encode }}&amp;body={{ entry.url|url_encode }}%20via%20@getpoche" class="tool email" title="{% trans "email" %}"><span>{% trans "email" %}</span></a></li>{% endif %}
                      {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&amp;title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %}
 -                    {% if constant('FLATTR') == 1 %}{% if flattr.status == "flattrable" %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr" title="flattr"><span>flattr</span></a></li>{% elseif flattr.status == "flattred" %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr"><span>flattr</span>{{ flattr.numflattrs }}</a></li>{% else %}{% endif %}{% endif %}
++                    {% if constant('FLATTR') == 1 %}{% if flattr.status == constant('FLATTRABLE') %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr" target="_blank" title="{% trans "flattr" %}"><span>flattr</span></a></li>{% elseif flattr.status == constant('FLATTRED') %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr" target="_blank" title="{% trans "flattr" %}"><span>flattr</span>{{ flattr.numflattrs }}</a></li>{% endif %}{% endif %}
                  </ul>
              </div>
              <header class="mbm">
@@@ -31,6 -32,7 +32,7 @@@
                      {% if constant('SHARE_TWITTER') == 1 %}<li><a href="https://twitter.com/home?status={{entry.title|url_encode}}%20{{ entry.url|url_encode }}%20via%20@getpoche" target="_blank" class="tool twitter" title="{% trans "tweet" %}"><span>{% trans "tweet" %}</span></a></li>{% endif %}
                      {% if constant('SHARE_MAIL') == 1 %}<li><a href="mailto:?subject={{ entry.title|url_encode }}&amp;body={{ entry.url|url_encode }}%20via%20@getpoche" class="tool email" title="{% trans "email" %}"><span>{% trans "email" %}</span></a></li>{% endif %}
                      {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&amp;title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %}
 -                    {% if constant('FLATTR') == 1 %}{% if flattr.status == "flattrable" %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr" title="flattr"><span>flattr</span></a></li>{% elseif flattr.status == "flattred" %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr"><span>flattr</span>{{ flattr.numflattrs }}</a></li>{% else %}{% endif %}{% endif %}
++                    {% if constant('FLATTR') == 1 %}{% if flattr.status == constant('FLATTRABLE') %}<li><a href="http://flattr.com/submit/auto?url={{ entry.url }}" class="tool flattr" target="_blank" title="{% trans "flattr" %}"><span>flattr</span></a></li>{% elseif flattr.status == constant('FLATTRED') %}<li><a href="{{ flattr.flattrItemURL }}" class="tool flattr" target="_blank" title="{% trans "flattr" %}"><span>flattr</span>{{ flattr.numflattrs }}</a></li>{% endif %}{% endif %}
                  </ul>
                  <p>{% trans "this article appears wrong?" %} <a href="https://github.com/inthepoche/poche/issues/new">{% trans "create an issue" %}</a> {% trans "or" %} <a href="mailto:support@inthepoche.com?subject=Wrong%20display%20in%20poche&amp;body={{ entry.url|url_encode }}">{% trans "contact us by mail" %}</a></p>
              </div>