]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Widget.php
Preview for Videos and images / Video resolution selection
[friendica.git] / src / Content / Widget.php
index a7ce52cc466107f8ecaa1cbf1b9eb7c3ad799d24..139fd8ebb6131b9566d62c33fbd9bcac2b4ba253 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Content;
 
 use Friendica\Core\Addon;
+use Friendica\Core\Cache\Duration;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
-use Friendica\Model\FileTag;
-use Friendica\Model\GContact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\Profile;
+use Friendica\Model\Post;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
 class Widget
@@ -270,7 +267,7 @@ class Widget
 
                $extra_sql = self::unavailableNetworks();
 
-               $r = DBA::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql ORDER BY `network`",
+               $r = DBA::p("SELECT `network` FROM `contact` WHERE `uid` = ? AND NOT `deleted` AND `network` != '' $extra_sql GROUP BY `network` ORDER BY `network`",
                        local_user()
                );
 
@@ -309,19 +306,10 @@ class Widget
                        return '';
                }
 
-               $saved = DI::pConfig()->get(local_user(), 'system', 'filetags');
-               if (!strlen($saved)) {
-                       return;
-               }
-
                $terms = [];
-               foreach (FileTag::fileToArray($saved) as $savedFolderName) {
+               foreach (Post\Category::getArray(local_user(), Post\Category::FILE) as $savedFolderName) {
                        $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
                }
-               
-               usort($terms, function ($a, $b) {
-                       return strcmp($a['name'], $b['name']);
-               });
 
                return self::filter(
                        'file',
@@ -352,13 +340,8 @@ class Widget
                        return '';
                }
 
-               $saved = DI::pConfig()->get($uid, 'system', 'filetags');
-               if (!strlen($saved)) {
-                       return;
-               }
-
                $terms = array();
-               foreach (FileTag::fileToArray($saved, 'category') as $savedFolderName) {
+               foreach (Post\Category::getArray(local_user(), Post\Category::CATEGORY) as $savedFolderName) {
                        $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
                }
 
@@ -413,7 +396,7 @@ class Widget
                $entries = [];
                foreach ($commonContacts as $contact) {
                        $entries[] = [
-                               'url'   => Contact::magicLink($contact['url']),
+                               'url'   => Contact::magicLinkByContact($contact),
                                'name'  => $contact['name'],
                                'photo' => Contact::getThumb($contact),
                        ];
@@ -478,7 +461,13 @@ class Widget
 
                $ret = [];
 
-               $dthen = Item::firstPostDate($uid, $wall);
+               $cachekey = 'Widget::postedByYear' . $uid . '-' . (int)$wall;
+               $dthen = DI::cache()->get($cachekey);
+               if (empty($dthen)) {
+                       $dthen = Item::firstPostDate($uid, $wall);
+                       DI::cache()->set($cachekey, $dthen, Duration::HOUR);
+               }
+
                if ($dthen) {
                        // Set the start and end date to the beginning of the month
                        $dnow = substr($dnow, 0, 8) . '01';
@@ -520,9 +509,31 @@ class Widget
                        '$cutoff' => $cutoff,
                        '$url' => $url,
                        '$dates' => $ret,
+                       '$showless' => DI::l10n()->t('show less'),
                        '$showmore' => DI::l10n()->t('show more')
                ]);
 
                return $o;
        }
+
+       /**
+        * Display the account types sidebar
+        * The account type value is added as a parameter to the url
+        * 
+        * @param string $base        Basepath
+        * @param int    $accounttype Acount type
+        * @return string
+        */
+       public static function accounttypes(string $base, $accounttype)
+       {
+               $accounts = [
+                       ['ref' => 'person', 'name' => DI::l10n()->t('Persons')],
+                       ['ref' => 'organisation', 'name' => DI::l10n()->t('Organisations')],
+                       ['ref' => 'news', 'name' => DI::l10n()->t('News')],
+                       ['ref' => 'community', 'name' => DI::l10n()->t('Forums')],
+               ];
+
+               return self::filter('accounttype', DI::l10n()->t('Account Types'), '',
+                       DI::l10n()->t('All'), $base, $accounts, $accounttype);
+       }
 }