fnagel / t3extblog

A record based blog extension for TYPO3 CMS. Easy to use and packed with features (incl. comments, subscriptions for comments and posts, Wordpress like subscription manager, reasonable email sending in FE and BE, GDPR ready, BE modules, Dashboard widgets, RSS, Sitemap, ...). Flexible and powerful!
http://typo3.org/extensions/repository/view/t3extblog
GNU General Public License v2.0
33 stars 19 forks source link

Email-Links in Postsubscribe Email shows wrong URL when Typo3 is installed in a subfolder #164

Closed danielDigitalArt closed 6 years ago

danielDigitalArt commented 7 years ago

I have a typo3-installation in a subfolder, so it can be reached like so: domain.tld/sub/

When a user posted a comment and subscribes to the Blogpost, he gets an opt-in Email when the comment is being published by an admin. In this email the Link to the Post and the Link for the subscription confirmation is shown.

Currently these Links do not contain the subfolder, the link is written like: domain.tld/subscription/subscription/post/... (i created an additional Page for the subscriptions, named subscription). When i add the subfolder into the url and call it in the browser, i get the correct page: domain.tld/sub/subscription/subscription/post/...

I researched in the plugin folder, and could find the email templates and also the uri/actionViewHelper, which generates the urls for the emails. When i logged the output from the viewHelper, i could see that it returns the url without the subfolder, but logging the output of the BaseActionViewHelper returned a URL which contains the subfolder-name. The output from BaseActionViewHelper cannot be used here, because it was made to return a backend url, thats why you would see something like this: domain.tld/sub/typo3/...

Is there a way to fix the output of the URLs?

fnagel commented 7 years ago

I'm not quite sure how to fix this but it definitely looks like a bug.

Can you give me some info on your configuration? See https://github.com/fnagel/t3extblog/blob/master/CONTRIBUTING.md

Some ideas:

Some background: We use a custom URI VH as wee need to generate FE links in the BE. Sadly, this is not supported by default so we have a VH that reproduces what the default fluid VH does.

Not sure why this does not respect your sub folder config but it might be a flaw in the general concept of this functionality.

It's similar to what https://github.com/Kephson/reint_mailtask_example does. Would you mind trying if this works for your installation?

danielDigitalArt commented 7 years ago

Hi,

i have now tried some things, first i copied the whole page into a dev-environment, because i cant just try and disable Realurl in live mode.

No Matter if Realurl is disabled or not, you wont see the subfolder in the mail for the subscription. (cant be a cache problem, because you can see, when realurl is disabled, the URL gets ugly)

Now some Info about the environment: Typo3 Version 7.6.11 PHP-Version: 7.0.14 (Livesite has 5.6) Pluginversion: 2.2.1

Config: Constant:

plugin.tx_t3extblog.persistence.storagePid = 12
plugin.tx_t3extblog.settings.blogsystem.pid = 22
plugin.tx_t3extblog.settings.subscriptionManager.admin.mailTo.email = mail@domain.tld
plugin.tx_t3extblog.settings.subscriptionManager.pid = 43

plugin.tx_t3extblog.settings.blogName = Blogname
plugin.tx_t3extblog.settings.emailFrom = mail@domain.tld
plugin.tx_t3extblog.settings.emailTo = mail@domain.tld

plugin.tx_t3extblog.settings.subscriptionManager.comment.admin.mailTo.email = mail@domain.tld

plugin.tx_t3extblog.settings.previewImage.width = 446px

Setup:

plugin.tx_t3extblog {
   settings {
    blogsystem {
      posts {
         paginate  {
                itemsPerPage = 4
                insertAbove = 1
                insertBelow = 1
                maximumNumberOfLinks = 50
               }
          metadata {
                enable = 1
                twitterCards {
                       enable = 1
                       site = mail@domain.tld
                       }
               }
      }
     comments {
                allowed = 1
                allowedUntil = 0
                approvedByDefault = 1
                subscribeForComments = 1
                spamCheck.enable = 0
     }
      pid = 22
    }
subscriptionManager.admin.mailTo.email = mail@domain.tld
subscriptionManager.pid = 43
    }
}
plugin.tx_t3extblog {
   view {
        templateRootPath >
        templateRootPaths {
            20 = fileadmin/templates/plugins/t3extblog/templates/
            10 = EXT:t3extblog/Resources/Private/Templates/
        }
        partialRootPath >
        partialRootPaths {
            20 = fileadmin/templates/plugins/t3extblog/partials/
            10 = EXT:t3extblog/Resources/Private/Partials/
        }
        layoutRootPath >
        layoutRootPaths {
            20 = fileadmin/templates/plugins/t3extblog/layouts/
            10 = EXT:t3extblog/Resources/Private/Layouts/
        }
    }
}
plugin.tx_t3extblog.settings.latestPosts.paginate.maximumNumberOfLinks= 1
plugin.tx_t3extblog.settings.blogsystem.posts.paginate.itemsPerPage = 12
plugin.tx_t3extblog.settings.blogsystem.posts.paginate.insertAbove = 0
[globalVar = TSFE:id=2]
plugin.tx_t3extblog.settings.blogsystem.posts.paginate.itemsPerPage = 8
plugin.tx_t3extblog.settings.blogsystem.posts.paginate.insertBelow = 0
plugin.tx_t3extblog.settings.blogsystem.posts.paginate.insertAbove = 0
[END]

module.tx_t3extblog < plugin.tx_t3extblog

The funny thing i have seen is, that the admin-email shows the correct subfolder, but it coult be because the Mail might get generated in Frontend context like you mentioned.

When i tested the second option, the Email was sent with the correct subfolder in the url, so it really seems to be related to the backend context.

Ill try the Kephson example, and see if this helps.

*Edit: As far as i can see it, the argument of the "setCreateAbsoluteUri" function should be true, because in the Emailtemplate you can see the following: Link: <t3b:uri.action extensionName="T3extblog" pluginName="Blogsystem" controller="Post" action="list" pageUid="{settings.blogsystem.pid}" absolute="true" additionalParams="{L: subscriber.sysLanguageUid}" /> At least that is what i could see here: https://github.com/Kephson/reint_mailtask_example/issues/2

fnagel commented 7 years ago

No Matter if Realurl is disabled or not, you wont see the subfolder in the mail for the subscription.

Ok, just wanted to exclude another layer and therefore error source.

Please try changing https://github.com/fnagel/t3extblog/blob/master/Classes/ViewHelpers/Frontend/Uri/ActionViewHelper.php#L127

into ->setCreateAbsoluteUri((bool) $this->arguments['absolute'])

danielDigitalArt commented 7 years ago

Hey,

sorry for the late Response, was really busy these days.

I tried your suggestion, but sadly it didnt work either. I also tried to hardcode the value for the absolute variable by setting: ->setCreateAbsoluteUri(true) Its still like the actionviewhelper doesn't even notice that it is in a subfolder.

danielDigitalArt commented 7 years ago

Any Ideas?

fnagel commented 7 years ago

No, not really. Did you try reint_mailtask_example? Did it work?

fnagel commented 7 years ago

Any feedback on this issue?

danielDigitalArt commented 7 years ago

Hi, ive tried to install the example, sadly typo3 7 throws an error when i tried to install the extension.

danielDigitalArt commented 6 years ago

Right now i found a solution which is quite hackish. The Idea came from here: https://stackoverflow.com/questions/34255934/typo3-uribuilder-and-realurl-link

Solution: let the uribuilder build the link relatively: ->setCreateAbsoluteUri(false)

let typo3 generate the link (it will default to folder, which adds the subfolders-name and because of the backend context the uricomponent "/typo3", which is then removed by a str_replace:

return str_replace('/typo3','',\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($uri));

so in the End the function looks like this:

    protected function renderFrontendLink($action = NULL, array $arguments = array(), $controller, $extensionName, $pluginName, $pageUid, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', $linkAccessRestrictedPages = FALSE, array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL) {
        if ($controller === NULL || $extensionName === NULL || $pluginName === NULL) {
            throw new \Exception('Missing arguments for extbase link generation from BE context. Check your template!');
        }

        $uriBuilder = $this->controllerContext->getUriBuilder();

        $this->buildFrontend($pageUid);
        $uri = $uriBuilder->reset()
            ->setTargetPageUid($pageUid)
            ->setTargetPageType($pageType)
            ->setNoCache($noCache)
            ->setUseCacheHash(!$noCacheHash)
            ->setSection($section)
            ->setFormat($format)
            ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
            ->setArguments($this->uriFor($action, $arguments, $controller, $extensionName, $pluginName, $format, $additionalParams))
            ->setCreateAbsoluteUri(false)
            ->setAddQueryString($addQueryString)
            ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
            ->setAddQueryStringMethod($addQueryStringMethod)
            ->buildFrontendUri();

        return str_replace('/typo3','',\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($uri));
    }
fnagel commented 6 years ago

@danielDigitalArt Would you mind testing this with the 3.x release? Some relevant parts have changed there, perhaps it works for you.

If that does not work out, you may want to try this branch in which I modified the TS generation in BE context: https://github.com/fnagel/t3extblog/tree/typoscript-generation

danielDigitalArt commented 6 years ago

Hi, have tested the new Version just right now, it seems to be working right now. The only thing to mention here is, that you need to set config.baseURL in Typoscript, config.absRefPrefix wont do the trick for the link generation here.

fnagel commented 6 years ago

@danielDigitalArt Did you test the 3.x (master branch) version or the "typoscript-genration" branch? Just to be sure :-)

danielDigitalArt commented 6 years ago

Hi, i removed the older Version and cloned the latest Version from github into the extension folder. After installation it says: 3.0.2-dev as the current Version.

So im not really sure which Version would be the correct one.

fnagel commented 6 years ago

Ok, thanks for the feedback. By default, you should have used the master branch.