Skip to content

Added extension hook for reading modes#1714

Merged
Alkarex merged 3 commits intoFreshRSS:devfrom
kevinpapst:hook-readingmodes
Jan 1, 2018
Merged

Added extension hook for reading modes#1714
Alkarex merged 3 commits intoFreshRSS:devfrom
kevinpapst:hook-readingmodes

Conversation

@kevinpapst
Copy link
Copy Markdown
Contributor

@kevinpapst kevinpapst commented Dec 10, 2017

I am currently working on a full-fledged extension, which uses its own controllers and views.

Problem is: I cannot route the user to the page (controller/action) that I want him to see as there is currently no way of displaying additional links in the main UI.

To achieve my goal, I refactored the reading modes to be a simple array structure which gets injected into the hook. Extensions can then work on that navigation structure like that:

class MyExtension extends Minz_Extension
{
    public function init() {
	$this->registerHook('nav_reading_modes', array($this, 'addReadingModeToMenu'));
    }

    public function addReadingModeToMenu($menu) {
    	$request = Minz_Request::currentRequest();
	$menu[] = new FreshRSS_ReadingMode(
		'example',
		'example title',
		array_merge($request, array('c' => 'my', 'a' => 'any')),
		($request['c'] == 'my' && $request['a'] == 'any')
	);
	return $menu;
    }
}

Now extensions are capable of adding their own reading modes into the menu.

What do you think of this approach?

using hook for reading modes in navigation
@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Dec 10, 2017

Should all of that $readingModes definition stuff really go in the template? That looks like template pollution to me. But in principle I think it's clearer this way even without extensions.

@kevinpapst
Copy link
Copy Markdown
Contributor Author

kevinpapst commented Dec 10, 2017

True, its not the best place to keep that logic, but I was unsure where to put it otherwise. Any idea? We could create a base FreshRSS_Controller which extends Minz_Controller and then let the FreshRSS_index_Controller extend that new FreshRSS_Controller.
Extensions could also extend this controller if they want to display the nav_menu.phtml partial.

@Alkarex Alkarex added this to the 1.10.0 milestone Dec 10, 2017
@Alkarex
Copy link
Copy Markdown
Member

Alkarex commented Dec 10, 2017

I have not looked in details yet, but could this code be in FreshRSS_index_Controller and you could override FreshRSS_index_Controller when needed?

'name' => _i("view-normal"),
'title' => _t('index.menu.normal_view'),
'url' => array_merge($url_output, array('c' => Minz_Request::defaultControllerName(), 'a' => 'normal')),
'active' => (Minz_Request::controllerName() == Minz_Request::defaultControllerName() && $actual_view == 'normal'),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the "fast" string comparisons first, and use triple-equal, like:

'active' => $actual_view === 'normal' && Minz_Request::controllerName() === Minz_Request::defaultControllerName(),

and maybe the multiple Minz_Request::controllerName() === Minz_Request::defaultControllerName() could be factorised somehow

@kevinpapst
Copy link
Copy Markdown
Contributor Author

kevinpapst commented Dec 10, 2017

Updated the PR: refactored ReadingMode to a Model class.
Keeping it in IndexController would force Extensions to extend that IndexController, which I would prefer not to do. But I could still move it there, if you disagree with the model.

@Alkarex Alkarex modified the milestones: 1.11.0, 1.10.0 Jan 1, 2018
@Alkarex Alkarex merged commit a756878 into FreshRSS:dev Jan 1, 2018
@Alkarex
Copy link
Copy Markdown
Member

Alkarex commented Jan 1, 2018

Sorry for the delay.
Happy New Year 2018 :-)


$readingModes = array(
new FreshRSS_ReadingMode(
_i("view-normal"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just make the argument here "view-normal" and then above something like

$this->id = $name;
$this->name = _i($name);

This is in reference to #1758.

/** @var FreshRSS_ReadingMode $mode */
foreach ($readingModes as $mode) {
?>
<a class="view_normal btn <?php if ($mode->isActive()) { echo 'active'; } ?>" title="<?php echo $mode->getTitle(); ?>" href="<?php echo Minz_Url::display($mode->getUrlParams()); ?>">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then the ID would be part of the className here. Sorry for kind of polluting your PR but I figure it's easier to discuss this way than in #1758.

Copy link
Copy Markdown
Member

@aledeg aledeg Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the idea behind the class view_normal, view_global, and view_reading. We already had that. I think we just need a small adjustment on how you generate the reading modes.
@kevinpapst

@kevinpapst
Copy link
Copy Markdown
Contributor Author

kevinpapst commented Jan 2, 2018

I did not follow the changes in #1755. From a quick view I would say its slightly incompatible with my changes?"
Now extension can add views, which then would not have a shortcut. And the list of views could even be completely rewritten by the event, so the hard coded shortcuts in #1758 may result in unexpected behaviour.
I can add your changes @Frenzie then we have view IDs which can be hardwired to the shortcuts. In the unrealistic case that a view link is not existing in the list/DOM the JS would not trigger.
Is that what you suggested @Frenzie ? @aledeg any objections?

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jan 2, 2018

@kevinpapst I'm not entirely sure what you're suggesting with hardwiring but I suppose you mean what I mean, lol. I was suggesting to dynamically restore the HTML/DOM to the way it was or at least something close to it. That way a selector like #nav_menu_views .view-rss would work, although I mean that mostly for styling purposes.

I'm not the biggest fan of the JS using the DOM like in #1755 since my DOM might be different, but what I thought reasonable enough with classes could yield odd and unexpected results while using the nth child node. (Including not working, but that's pretty much the best case scenario.) Ideally the info from Minz_Request::currentRequest() would probably also be easily available to the JS. But that aside.

PS Incidentally, here is the first search result for a premade function that modifies a single parameter in the query string, although just the value of a=blabla would likely do. Anyway, that's just a quick brainstorm.

@aledeg
Copy link
Copy Markdown
Member

aledeg commented Jan 2, 2018

The problem is the class used. Before, each view had a different CSS class (view_normal, view_global, view_reading)(See https://github.com/FreshRSS/FreshRSS/pull/1755/files#diff-99959fbf8401f92306d451127be5e01a). Now, they all have the view_normal class.
I am not saying that my fix was perfect. But it fixes the issue at the moment.

What should be done is restoring a way to have a different CSS class for each of the buttons. This way we can revert the fix to its initial setting.

@kevinpapst
Copy link
Copy Markdown
Contributor Author

kevinpapst commented Jan 2, 2018

Ok, now I am slightly confused^^ Let me adjust the code and submit a PR hopefully tomorrow.

I am concerned about the changes in #1758 as they can fail in rare circumstances. The hardcoded index used in the get() call can be wrong if an extension manipulates the available reading modes in any way. So we are concerned about the same point but probably for different reasons ;-)
Therefor we need to re-add the class or an index to the links, which were previously available and I accidentaly removed them (I guess because they were just not used before @aledeg introduced his changes).

@aledeg
Copy link
Copy Markdown
Member

aledeg commented Jan 2, 2018

No hard feelings, we all make mistakes. I've recently rewrote a PR after Alkarex mentioned something I didn't see :)

@kevinpapst
Copy link
Copy Markdown
Contributor Author

Hahaha, I blame everything on you @aledeg ... nobody would have noticed without your changes LOL
I ping you with my fixes tomorrow for review.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jan 2, 2018

What should be done is restoring a way to have a different CSS class for each of the buttons. This way we can revert the fix to its initial setting.

@kevinpapst This is what I meant to convey in my comments, btw. I figured the translation ID could also serve well doing double duty as a className.

@aledeg
Copy link
Copy Markdown
Member

aledeg commented Jan 2, 2018

@kevinpapst @Frenzie I think we were all taking about the same thing :)

@kevinpapst kevinpapst deleted the hook-readingmodes branch January 2, 2018 21:35
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Jan 2, 2018
FreshRSS#907

CURLOPT_FOLLOWLOCATION open_basedir bug (FreshRSS#1657)

CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set
FreshRSS#1655 (comment)
https://stackoverflow.com/questions/6918623/curlopt-followlocation-cannot-be-activated
Manual merge dev

Add an entry in the subscription tool page

I reworked @Alkarex idea proposed in FreshRSS#1292. I though it was a good idea to merge everything in the same location.

Improve translation tools

I was not happy with the previous version. I refactored everything to make it reusable.
It allows me do do more verifications and to build a tool to handle the files themselves.

Merge pull request FreshRSS#1660 from aledeg/api-subscription-tool

Add an entry in the subscription tool page
Merge pull request FreshRSS#1658 from aledeg/improve-i18n-tools

Improve translation tools
Changelog 1247

FreshRSS#1660
FreshRSS#1292
FreshRSS#1247

Merge branch 'FreshRSS/dev' into github-update

[i18] nl/sub: add a few translations
Merge pull request FreshRSS#1661 from FreshRSS/Frenzie-patch-1

[i18] nl/sub: add a few translations
Reworded changelog 1247

FreshRSS#1660
FreshRSS#1292
FreshRSS#1247

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

CLI optimize database (FreshRSS#1663)

CLI optimize database FreshRSS#1583
And VACUUM in SQLite FreshRSS#918
Add VACUUM for PostgreSQL (Not tested yet)
A bit of Apache documentation (FreshRSS#1670)

FreshRSS#1666
FreshRSS#1669
FreshRSS#908
Merge branch 'FreshRSS/dev' into github-update

Delete unneeded update files

Move update scripts

Merge branch 'staging-branch' into github-update

Fix Travis syntax

Fix typo in nl i18n (FreshRSS#1675)


improve zh-cn i18n (FreshRSS#1678)


Move translation tools into the cli folder (FreshRSS#1673)

Translation tools must be used on cli. It is better to have them in the cli folder.
Add a Mastodon share (FreshRSS#1674)

See FreshRSS#1521 
Minor language

Small fix Mastodon share

$a['method'] can be undefined.
FreshRSS#1674
FreshRSS#1521

Changelog Mastodon

Merge pull request FreshRSS#1682 from Alkarex/fix_mastodon_share

Small fix Mastodon share
Merge branch 'FreshRSS/dev' into github-update

More update

Split post-update in disctinct file

Post-update will thus contain code from the new version

Better case for git

Fix link encoding in API (FreshRSS#1686)

FreshRSS#1683
Alkarex/EasyRSS#35
A bit of documentation for the API (FreshRSS#1689)

FreshRSS#1687
FreshRSS#443 (comment)

Merge branch 'FreshRSS/dev' into github-update

[docs] Configuration: some stylistic improvements (FreshRSS#1693)

The main purpose is to fix the `imapcted` typo that was exposed by FreshRSS#1259 (comment)
[FIX] FreshRSS#1690 - Also check pdo_pgsql extension in check_install()

[ADD] 'blankoworld' as contributor in CREDITS

Changelog 1690

FreshRSS#1690
FreshRSS#1691
FreshRSS#1692

I18n - DE (FreshRSS#1698)

* added missing german translations
Call idn_to_ascii with INTL_IDNA_VARIANT_UTS46

Under PHP 7.2, calling `idn_to_ascii($idn)` results in a deprecation warning: 'INTL_IDNA_VARIANT_2003 is deprecated'
See https://secure.php.net/manual/en/function.idn-to-ascii.php 

Therefore, if possible, `idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46)` should be used instead. `INTL_IDNA_VARIANT_UTS46` was introduced in PHP 5.4, so on versions before that, `idn_to_ascii($idn)` must still be used.

Fixed FreshRSS#1699
A bit more for git updates

Documentation updates (FreshRSS#1697)

* added documentation about updating FreshRSS
moved Installation to admin directory
linked some already existing documentation files
Update panel shows latest version message as success (FreshRSS#1701)

show latest version message as success, FIXES FreshRSS#1586
Merge branch 'FreshRSS/master' into FreshRSS/dev

Remove forgotten punycode line

Credits Craig Andrews

Merge pull request FreshRSS#1700 from candrews/patch-1

Call idn_to_ascii with INTL_IDNA_VARIANT_UTS46
Changelog  1586 1698 1699

FreshRSS#1586
FreshRSS#1701
FreshRSS#1698
FreshRSS#1699
FreshRSS#1700

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

Merge branch 'FreshRSS/dev' into github-update

Add more glyphs for opensans font (FreshRSS#1032)

* Add more glyphs for opensans font

* Update .htaccess to support woff2 file format

* Fixed browser support for new font face

* Fixed Origine theme css and .htaccess

* Deleted unneeded fonts

* Added stylefiles for OpenSans font

* Fixed all themes with new font css

* Avoid additional CSS file

* htaccess cache control public

* Font casing bug

* Remove TTF font

Too big, low need https://caniuse.com/#search=woff

* Changelog 1032

FreshRSS#1032
FreshRSS#1028

Extension function to override entry hash (FreshRSS#1707)

Extension function to override entry hash
FreshRSS#1706


Merge branch 'FreshRSS/dev' into github-update

Show existing extensions in admin panel (FreshRSS#1708)

* first draft

* display installed extension state

* fixed whitespace vs tabs

* added translation in all languages

* added error checks and log messages

* fixed tabs vs whitespace

* another try in fixing whitespaces

* another try in fixing whitespaces

* improved extension list translations

* using JSON from official extension repo

* improved version compare

* updated translations

* French translation

make sure that we do not exceed a certain file size for the users log file

renamed method

incorporated code review feedback

added new extension hook
using hook for reading modes in navigation

refactored ReadingModes to Model

Log rotation, use Minz_Log, new log constants

ADMIN_LOG, API_LOG, PSHB_LOG

Check requirement in CLI script (FreshRSS#1711)

* check requirements in actualize_script before executing, fixes FreshRSS#1710

* removed empty whiteline

* testing all requirements

* incorporated code review feedback

* removed code that is already executed in _cli.php

* added newline at eof

* fixed include problems

* fixed include problems

Merge branch 'dev' into logfilesize
Merge branch 'dev' into logfilesize
Changelog 1708 1711

FreshRSS#1708
FreshRSS#1711

Merge pull request FreshRSS#1712 from kevinpapst/logfilesize

Prevent logfile from growing unlimited
Changelog 1712

FreshRSS#1712
FreshRSS#1562

Use __DIR__ for relative include and require

For uniformity, and to avoid having PHP searching in include_path.
http://php.net/manual/function.include.php
FreshRSS#1715
FreshRSS#1711 (comment)

Merge pull request FreshRSS#1717 from Alkarex/dir_in_require

Use __DIR__ for relative include and require
fixed bug in catch block
added types to docblocks

Merge pull request FreshRSS#1724 from kevinpapst/exception-bug

ExtensionManager fixes
[doc] Extensions: translate various sections from French

See FreshRSS#1697 (comment)

* lowercase dir as pointed out by @kevinpapst in FreshRSS#1704 (comment)

* Add French translation with improvements suggested by @aledeg

Merge branch 'dev' into hebrew-i18n
Fix whitespace

Add message after log rotation

FreshRSS#1712
FreshRSS#1562

Minz Dispatcher Controllers path

FreshRSS#1704

Customisable constants.local.php (FreshRSS#1725)

FreshRSS#1562
FreshRSS#1607
FreshRSS#1656
FreshRSS#1705
FreshRSS#1712
Merge pull request FreshRSS#1726 from Alkarex/message_log_rotation

Add message after log rotation
i18n hebrew more

18n Hebrew more 2

Changelog 1716 1724 1725

https://github.com/FreshRSS/FreshRSS/pull/1716
FreshRSS#1724
FreshRSS#1725

Merge branch 'FreshRSS/dev' into Minz_Dispatcher_paths

Changelog 1729

Merge pull request #1716 from FreshRSS/hebrew-i18n

Add hebrew translation
Changelog 1716

https://github.com/FreshRSS/FreshRSS/pull/1716

Merge pull request FreshRSS#1729 from Alkarex/Minz_Dispatcher_paths

Minz Dispatcher Controllers path
added .editorconfig with basic settings

Minz Controllers directory uppercase

FreshRSS#1729

Merge pull request FreshRSS#1704 from Frenzie/doc-translate-extensions

[doc] Extensions: translate various sections from French
Merge pull request FreshRSS#1732 from kevinpapst/editorconfig

Added .editorconfig
Changelog 1697, 1704, 1732

FreshRSS#1697
FreshRSS#1704
FreshRSS#1732

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

fixed bug when adding a category and feed at the same time (FreshRSS#1731)

fixed bug when adding a category and feed at the same time

Changelog 1731

FreshRSS#1731

Fix favicon for open_basedir (FreshRSS#1733)

Remove open_basedir warning for CURLOPT_FOLLOWLOCATION with PHP 5.6.0- https://bugs.php.net/bug.php?id=65646
Remove warning for CURLOPT_FOLLOWLOCATION with open_basedir (FreshRSS#1734)

For PHP 5.6.0- http://www.php.net/ChangeLog-5.php#5.6.0
https://bugs.php.net/bug.php?id=65646
FreshRSS#1733
FreshRSS#1657
FreshRSS#1655
Prepare release of FreshRSS 1.9.0

Merge pull request FreshRSS#1720 from FreshRSS/dev

FreshRSS 1.9.0
Update FreshRSS version to 1.9.0

Merge branch 'FreshRSS/dev' into FreshRSS/master

[docs] Extensions: fix typo (FreshRSS#1735)


Merge branch 'FreshRSS/dev' into FreshRSS/master

New development version 1.9.1-dev

PHP 7.2: Fix a warning when retrieving the list of entries (FreshRSS#1739)

When retrieving the list of entries when the context was 'all' or 'starred', there was the following warning:

> Warning: count(): Parameter must be an array or an object that implements Countable in /home/alexis/FreshRSS/app/Controllers/indexController.php on line 206

I fixed that by changing how the array is tested.
Fixes link to the "update guidelines" (FreshRSS#1740)


Fixes link to the "update guidelines" (FreshRSS#1740)


Minor changes (FreshRSS#1747)


Tiny additions to .editorconfig (FreshRSS#1744)


Improving README in English and French (FreshRSS#1746)


Merge branch 'FreshRSS/master' into FreshRSS/dev

Adding new items to force-https.default.txt (FreshRSS#1745)


credits  RyDroid

FreshRSS#1747
FreshRSS#1746
FreshRSS#1745
FreshRSS#1744

[doc] Editing for better style (FreshRSS#1736)

* Also removed references to Persona authentication.
* Changed code comment about Persona because it's for HTTP auth
  in general. See FreshRSS@3d87609
  and FreshRSS#358 (comment)
[i18n] Add translation ignore/nl (FreshRSS#1752)


Add shortcuts to switch views (FreshRSS#1755)


Add mute strategy configuration (FreshRSS#1750)


Minor syntax

Merge pull request FreshRSS#1714 from kevinpapst/hook-readingmodes

Added extension hook for reading modes
Changelog 1739, 1745, 1750, 1755

FreshRSS#1739
FreshRSS#1745
FreshRSS#1750
FreshRSS#1755

Fix login bug when HTTP REMOTE_USER changes

YunoHost-Apps/freshrss_ynh#33

Merge pull request FreshRSS#1756 from Alkarex/YunoHost_HTTP_Auth

Fix login bug when HTTP REMOTE_USER changes
Changelog 1756

FreshRSS#1756
YunoHost-Apps/freshrss_ynh#33

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

Fix shortcuts triggering view switching

Merge pull request FreshRSS#1758 from aledeg/fix-nav-buttons

Fix shortcuts triggering view switching
Merge branch 'dev' into github-update
Merge branch 'dev' into github-update
@aledeg
Copy link
Copy Markdown
Member

aledeg commented Jan 23, 2018

@kevinpapst any news regarding the class fix?

@kevinpapst
Copy link
Copy Markdown
Contributor Author

Ups, totally forgot about it, thanks for the reminder. I'am on it right now

@kevinpapst
Copy link
Copy Markdown
Contributor Author

@aledeg see #1773
@Frenzie thanks, just did it as you proposed

@aledeg
Copy link
Copy Markdown
Member

aledeg commented Jan 25, 2018

@kevinpapst great!

aledeg added a commit that referenced this pull request Jan 26, 2018
aledeg added a commit to aledeg/FreshRSS that referenced this pull request Jan 26, 2018
I've introduced shortcuts to switch between view in FreshRSS#1755. They have been broken by FreshRSS#1714.
Then I've made an ugly fix in FreshRSS#1758.

This change revert all changes to have something better.

See FreshRSS#1757
Alkarex added a commit that referenced this pull request Jan 26, 2018
@Alkarex Alkarex modified the milestones: 1.11.0, 1.10.0 Feb 5, 2018
@Alkarex Alkarex mentioned this pull request Feb 14, 2018
mdemoss pushed a commit to mdemoss/FreshRSS that referenced this pull request Mar 25, 2021
mdemoss pushed a commit to mdemoss/FreshRSS that referenced this pull request Mar 25, 2021
I've introduced shortcuts to switch between view in FreshRSS#1755. They have been broken by FreshRSS#1714.
Then I've made an ugly fix in FreshRSS#1758.

This change revert all changes to have something better.

See FreshRSS#1757
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants