]> git.mxchange.org Git - friendica.git/commitdiff
Move posted date widget to Content\Widget
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 25 May 2019 23:08:15 +0000 (19:08 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 25 May 2019 23:08:15 +0000 (19:08 -0400)
include/items.php
mod/network.php
src/Content/Widget.php
src/Module/Profile.php
view/templates/posted_date_widget.tpl [deleted file]
view/templates/widget/posted_date.tpl [new file with mode: 0644]

index a28e19a05a2cb11b9f3c8eeae17101dbb3f51c3c..25c857f1156a615a0efbbf914b0f815a37fb7fef 100644 (file)
@@ -446,80 +446,3 @@ function drop_item($id, $return = '')
                //NOTREACHED
        }
 }
-
-/* arrange the list in years */
-function list_post_dates($uid, $wall)
-{
-       $dnow = DateTimeFormat::localNow('Y-m-d');
-
-       $dthen = Item::firstPostDate($uid, $wall);
-       if (!$dthen) {
-               return [];
-       }
-
-       // Set the start and end date to the beginning of the month
-       $dnow = substr($dnow, 0, 8) . '01';
-       $dthen = substr($dthen, 0, 8) . '01';
-
-       $ret = [];
-
-       /*
-        * Starting with the current month, get the first and last days of every
-        * month down to and including the month of the first post
-        */
-       while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
-               $dyear = intval(substr($dnow, 0, 4));
-               $dstart = substr($dnow, 0, 8) . '01';
-               $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5)));
-               $start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
-               $end_month = DateTimeFormat::utc($dend, 'Y-m-d');
-               $str = L10n::getDay(DateTimeFormat::utc($dnow, 'F'));
-
-               if (empty($ret[$dyear])) {
-                       $ret[$dyear] = [];
-               }
-
-               $ret[$dyear][] = [$str, $end_month, $start_month];
-               $dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d');
-       }
-       return $ret;
-}
-
-function posted_date_widget($url, $uid, $wall)
-{
-       $o = '';
-
-       if (!Feature::isEnabled($uid, 'archives')) {
-               return $o;
-       }
-
-       // For former Facebook folks that left because of "timeline"
-       /*
-        * @TODO old-lost code?
-       if ($wall && intval(PConfig::get($uid, 'system', 'no_wall_archive_widget')))
-               return $o;
-       */
-
-       $visible_years = PConfig::get($uid, 'system', 'archive_visible_years', 5);
-
-       $ret = list_post_dates($uid, $wall);
-
-       if (!DBA::isResult($ret)) {
-               return $o;
-       }
-
-       $cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
-       $cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
-
-       $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('posted_date_widget.tpl'),[
-               '$title' => L10n::t('Archives'),
-               '$size' => $visible_years,
-               '$cutoff_year' => $cutoff_year,
-               '$cutoff' => $cutoff,
-               '$url' => $url,
-               '$dates' => $ret,
-               '$showmore' => L10n::t('show more')
-
-       ]);
-       return $o;
-}
index 30e31cea3c6ec579379b7b44884c90eb9b0ec05d..c8786b2f7b372b47fd5640e468fa77718e5d7e44 100644 (file)
@@ -154,7 +154,7 @@ function network_init(App $a)
 
        $a->page['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
        $a->page['aside'] .= ForumManager::widget(local_user(), $cid);
-       $a->page['aside'] .= posted_date_widget('network', local_user(), false);
+       $a->page['aside'] .= Widget::postedByYear('network', local_user(), false);
        $a->page['aside'] .= Widget::networks('network', defaults($_GET, 'nets', '') );
        $a->page['aside'] .= saved_searches($search);
        $a->page['aside'] .= Widget::fileAs('network', defaults($_GET, 'file', '') );
index e89245cd2bc40b0c4ed012fc6595159dde61c827..066c17413a3a8db9b56da401f1b5e481a339cb08 100644 (file)
@@ -15,9 +15,12 @@ use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\FileTag;
 use Friendica\Model\GContact;
+use Friendica\Model\Item;
 use Friendica\Model\Profile;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
+use Friendica\Util\Temporal;
 use Friendica\Util\XML;
 
 class Widget
@@ -444,4 +447,74 @@ class Widget
 
                return '';
        }
+
+       /**
+        * @param string $url Base page URL
+        * @param int    $uid User ID consulting/publishing posts
+        * @param bool   $wall True: Posted by User; False: Posted to User (network timeline)
+        * @return string
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       public static function postedByYear(string $url, int $uid, bool $wall)
+       {
+               $o = '';
+
+               if (!Feature::isEnabled($uid, 'archives')) {
+                       return $o;
+               }
+
+               $visible_years = PConfig::get($uid, 'system', 'archive_visible_years', 5);
+
+               /* arrange the list in years */
+               $dnow = DateTimeFormat::localNow('Y-m-d');
+
+               $ret = [];
+
+               $dthen = Item::firstPostDate($uid, $wall);
+               if ($dthen) {
+                       // Set the start and end date to the beginning of the month
+                       $dnow = substr($dnow, 0, 8) . '01';
+                       $dthen = substr($dthen, 0, 8) . '01';
+
+                       /*
+                        * Starting with the current month, get the first and last days of every
+                        * month down to and including the month of the first post
+                        */
+                       while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
+                               $dyear = intval(substr($dnow, 0, 4));
+                               $dstart = substr($dnow, 0, 8) . '01';
+                               $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5)));
+                               $start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
+                               $end_month = DateTimeFormat::utc($dend, 'Y-m-d');
+                               $str = L10n::getDay(DateTimeFormat::utc($dnow, 'F'));
+
+                               if (empty($ret[$dyear])) {
+                                       $ret[$dyear] = [];
+                               }
+
+                               $ret[$dyear][] = [$str, $end_month, $start_month];
+                               $dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d');
+                       }
+               }
+
+               if (!DBA::isResult($ret)) {
+                       return $o;
+               }
+
+
+               $cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
+               $cutoff = array_key_exists($cutoff_year, $ret);
+
+               $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/posted_date.tpl'),[
+                       '$title' => L10n::t('Archives'),
+                       '$size' => $visible_years,
+                       '$cutoff_year' => $cutoff_year,
+                       '$cutoff' => $cutoff,
+                       '$url' => $url,
+                       '$dates' => $ret,
+                       '$showmore' => L10n::t('show more')
+               ]);
+
+               return $o;
+       }
 }
index 1a515073ddd845adde68edbeac15dcabf3fbcf50..30dee0cb56dafa7e89a821fc0a2ca47b18a2e5fa 100644 (file)
@@ -193,7 +193,7 @@ class Profile extends BaseModule
                        $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
                        $commvisitor = $commpage && $remote_contact;
 
-                       $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
+                       $a->page['aside'] .= Widget::postedByYear(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
                        $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : ''));
                        $a->page['aside'] .= Widget::tagCloud();
 
diff --git a/view/templates/posted_date_widget.tpl b/view/templates/posted_date_widget.tpl
deleted file mode 100644 (file)
index 7833aee..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<script>
-
-function showHideDates() {
-       if( $('#posted-date-selector-drop').is(':visible')) {
-               $('#posted-date-selector-drop').hide();
-               $('#posted-date-collapse').html(window.showMore);
-
-       } else {
-               $('#posted-date-selector-drop').show();
-               $('#posted-date-collapse').html(window.showFewer);
-       }
-}
-
-function dateSubmit(dateurl) {
-       window.location.href = dateurl;
-}
-
-</script>
-
-
-<div id="datebrowse-sidebar" class="widget">
-       <h3>{{$title}}</h3>
-       <ul id="posted-date-selector" class="datebrowse-ul">
-               {{foreach $dates as $y => $arr}}
-
-               {{if $y == $cutoff_year}}
-               </ul>
-               <ul id="posted-date-selector-drop" class="datebrowse-ul" style="display: none;">
-               {{/if}} 
-
-               <li id="posted-date-selector-year-{{$y}}" class="tool">
-                       <a class="datebrowse-link" href="#" onclick="openClose('posted-date-selector-{{$y}}'); return false;">{{$y}}</a>
-               </li>
-               <li id="posted-date-selector-{{$y}}" class="tool posted-date-selector-months" style="display: none;">
-                       <ul class="datebrowse-ul">
-                               {{foreach $arr as $d}}
-                               <li class="tool">
-                                       <a class="datebrowse-link" href="#" onclick="dateSubmit('{{$url}}/{{$d.1}}/{{$d.2}}'); return false;">{{$d.0}}</a>
-                               </li>
-                               {{/foreach}}
-                       </ul>
-               </li>
-               {{/foreach}}
-       </ul>
-       {{if $cutoff}}
-       <ul class="datebrowse-ul">
-               <li onclick="showHideDates(); return false;" id="posted-date-collapse" class="fakelink tool">{{$showmore}}</li>
-       </ul>
-       {{/if}}
-</div>
diff --git a/view/templates/widget/posted_date.tpl b/view/templates/widget/posted_date.tpl
new file mode 100644 (file)
index 0000000..42c04d2
--- /dev/null
@@ -0,0 +1,43 @@
+<script>
+function showHideDates() {
+       if( $('#posted-date-selector-drop').is(':visible')) {
+               $('#posted-date-selector-drop').hide();
+               $('#posted-date-collapse').html(window.showMore);
+
+       } else {
+               $('#posted-date-selector-drop').show();
+               $('#posted-date-collapse').html(window.showFewer);
+       }
+}
+</script>
+
+<div id="datebrowse-sidebar" class="widget">
+       <h3>{{$title}}</h3>
+       <ul id="posted-date-selector" class="datebrowse-ul">
+               {{foreach $dates as $y => $arr}}
+
+               {{if $y == $cutoff_year}}
+               </ul>
+               <ul id="posted-date-selector-drop" class="datebrowse-ul" style="display: none;">
+               {{/if}} 
+
+               <li id="posted-date-selector-year-{{$y}}" class="tool">
+                       <a class="datebrowse-link" href="#" onclick="openClose('posted-date-selector-{{$y}}'); return false;">{{$y}}</a>
+               </li>
+               <li id="posted-date-selector-{{$y}}" class="tool posted-date-selector-months" style="display: none;">
+                       <ul class="datebrowse-ul">
+                               {{foreach $arr as $d}}
+                               <li class="tool">
+                                       <a class="datebrowse-link" href="{{$url}}/{{$d.1}}/{{$d.2}}">{{$d.0}}</a>
+                               </li>
+                               {{/foreach}}
+                       </ul>
+               </li>
+               {{/foreach}}
+       </ul>
+       {{if $cutoff}}
+       <ul class="datebrowse-ul">
+               <li onclick="showHideDates(); return false;" id="posted-date-collapse" class="fakelink tool">{{$showmore}}</li>
+       </ul>
+       {{/if}}
+</div>