Silverstripe hash link rewriting putting unwanted slash in link - hash

Ok so I am developing a site in Silverstripe CMS that is using anchor links on one of it's pages. Thing is that in Silverstripe there is a rewrite going on that puts slashes before the hash in your links.
So in the docs it explains that you can put this in your YAML to disable slashes before hashes: http://doc.silverstripe.org/en/developer_guides/templates/how_tos/disable_anchor_links/
Which I have done like so (YAML validates ok):
_config/app.yml:
SSViewer: rewrite_hash_links: false
And then in my template file this is how I am constructing my link with anchor:
Link
(note that this template file is for a dataobject, I'm not sure if that has any baring)
And the outputted link is:
/cnc-machining/#made-to-order
but should be:
/cnc-machining#made-to-order
I'm all out of ideas. Any pointers?

In your DataObject's getLink() method you can simply remove the trailing slash using rtrim:
public function getLink() {
//remove trailing slash from parent link
$parentLink = rtrim($this->ParentPage()->Link(), '/');
return $parentLink . '#' . $this->URLSegment;
}
Now in your template just run in DataObject's scope:
Link
Though i didn't notice any disadvantage with having the trailing slash in the url.
HTH, wmk

Related

Editing Typo3 CMS front-end page

I get a project that used TYPO3 CMS, the task is quite simple, adding cookie usage notice on the header part of the website.
I never working on TYPO3 before, but already reading the documentation. Somehow I can't figure out which file to edit. even the documentation tutorial and file structure is different than the project I handle.
I don't have any project documentation for the project either, and I don't want to ask you to do my task, but I'm blank at the moment and don't know where to find the respective file needed.
Any suggestion or clue how to handle the issue?
my index.php on root folder look like this:
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
} else {
error_reporting(E_ALL ^ E_NOTICE);
}
// ******************
// Constants defined
// ******************
define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
(PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
define('PATH_site', dirname(PATH_thisScript).'/');
if (#is_dir(PATH_site.'typo3/sysext/cms/tslib/')) {
define('PATH_tslib', PATH_site.'typo3/sysext/cms/tslib/');
} elseif (#is_dir(PATH_site.'tslib/')) {
define('PATH_tslib', PATH_site.'tslib/');
} else {
// define path to tslib/ here:
$configured_tslib_path = '';
// example:
// $configured_tslib_path = '/var/www/mysite/typo3/sysext/cms/tslib/';
define('PATH_tslib', $configured_tslib_path);
}
if (PATH_tslib=='') {
die('Cannot find tslib/. Please set path by defining $configured_tslib_path in ' . htmlspecialchars(basename(PATH_thisScript)) . '.');
}
// ******************
// include TSFE
// ******************
require (PATH_tslib.'index_ts.php');
edit: adding screenshot of the interface suggested by #Riccardo (typo3 ver 4.4.4)
Which version of TYPO3 are you running? As Bernd wrote, it is difficult to help you without further information.... I'll try to explain the first passages where you could gather some infos.
1) Access TYPO3 backend with a user with administrative privileges
2) Try to identify the main TypoScript template with this procedure:
click on template (1)
click on the "zero" page with the TYPO3 symbol (2)
you should see on the right a list of the TypoScript templates (3),
click on the one that is marked as "is Root"
2) After that, click on the first dropdown on the right area (with the "info/modify" item and select "TypoScript Object Browser" (a.k.a. TSOB)
3) After you have done that, you should see a "tree" that represents the TypoScript configuration;
be sure to have "setup" selected (1)
search for the object that builds your page, which should most likely be page = PAGE (2)
[answer edited]
I'm afraid I'll have to ask for a survey supplement
Can you identify in which part of the various objects the header of your site is rendered? My suspects would be focused on the [home2] or the [outer_frameset] object;
Hoping that they will contain the usual array with something like:
home2.10 = something
I think that the quickiest (and dirtiest) way to append something before the whole page would be something like
home2.1 = TEXT
home2.1.value = <div>whatever your message would be </div>
I don't know if you need something more complex than that...
Said that, I admit I never worked with frame inside TYPO3 and I think that the last time I did something with frames was...uh... maybe 9 years ago.
Don't change that index.php!!
As it is part of the core which gets overwritten on an update of TYPO3.
As there are very much options for configurating a page there can be no recipe matching all.
My best tip: get a TYPO3 profi to have a look into your installation so he can find which files are responsible for the page rendering and could include the cookie notice.
There also are some extensions which could render such a notice in your pages in a very easy way. But that all depends how your installation is configured. Nothing to say without further knowledge.

Redirect to last page when overlay comment-form is used

I've got a view (phase4) with some custom content type content in it, where the users may comment on.
When the users want to comment, the comment form should appear in a modal form. I solved this by using the admin overlay.
Adding following function to my custom module:
function phase2_admin_paths_alter(&$paths) {
$paths['comment/reply/*'] = TRUE;
}
and using following link:
Comment
to open the comment form in a modal way. So far so good... but....
How do I redirect the user back to the page, the user was coming from.
I know that I have to overwrite the #action of the form in the template_form_FORMID_alter, like
$form['#action'] = $lasturl;
but how do I get the last url, so that it is reusable (so hardcoding the url isn't an option)?
My first idea was that I transfer the last url by adding it to the url as a $_GET-parameter, but it looks like this:
www.example.com/phase4#overlay=comment/reply/161%3Furl%3Dphase4
I also tried it with drupal_get_destination(), but either with no success, because of the tranformation of the "?" and the "=" in the url.
Are there other ways to find out where the user was coming from?
Note: phase4 isn't the alias of node 161. Phase 4 is a view, where node 161 is an element of.
Cheers
Tom
You have to use the drupal_get_destination() function with l() function to create such links.
$destination = drupal_get_destination(); // Store current path
Comment

Smarty seems to ignore addTemplateDir

I'm working in a Zend Framework based application (Shopware).
I add a template dir in my controller like this:
class Shopware_Controllers_Backend_Pricify extends Shopware_Controllers_Backend_ExtJs
{
public function init()
{
$this->View()->addTemplateDir(dirname(__FILE__) . "/../../Views/backend/");
parent::init();
}
}
But somehow, smarty always looks in the (not existing) part of the controller action:
Unable to load template snippet 'backend/mycontroller/model/main.js' in 'snippet:string:{include file="backend/pricify/model/main.js"} in Smarty/sysplugins/smarty_internal_templatebase.php on line 128
The Controller works over loading via ext js, but I do not see that this is a problem. When I var_dump template directories, the correct dir is included. I debugged the code far into smarty, but never found the part, where the directories are checked.
I'm aware, that this may be a problem within the software stack, but since I do not know where to search, I ask here. If I need to post additional data, please tell me.
I found, that the problem was that shopware extends CamelCase to camel_case folders.

Prevent Gmail from creating links for URLs and email addresses

Problem is Gmail automatically creates hyperlinks for all website URLs and email addresses. I do not want to create a link.
var mailClient = new SmtpClient();
var netMail = new MailMessage();
msg = "I do not want www.google.com as a link at recipient end. <br/>";
msg += "I want my email addrress myemail#myudomain.com as html without a link";
var cr = new NetworkCredential("########", "###########");
netMail.From = new MailAddress("#########m####.###", "######");
netMail.To.Add(new MailAddress("abc#xyz.com"));
netMail.Subject = "Test Mail";
netMail.IsBodyHtml = true;
netMail.Body = msg;
mailClient.Host = "xyz.com";
mailClient.Port = 25;
mailClient.EnableSsl = false;
mailClient.Credentials = cr;
mailClient.Send(netMail);
Any solution?
I had a same issue and found out if you use email like this;
<a rel="nofollow" style='text-decoration:none; color:#333'>test#mydomain.com</a>
email providers does not tend to follow email as a link.
Hope this helps.
There's no way to stop creating URLs, because its automatically checked by the email provider that whether the text is a valid URL.
Only way to overcome this is, deceiving the parser. Just put spaces, HTML tags, whatever in such a way that the parser can't identify like URL etc.
Here are a few code examples:
http:<span>//foolishedsiteparser.com</span>
_http://www.parsersmashed.com
noonesemail<x>#</x>linkdead.com>
And the result is the following:
http://foolishedsiteparser.com
_http://www.parsersmashed.com
noonesemail#linkdead.com
I was able to get around this issue just by adding <a style="color: #000000">link text</a> (notice there is no href).
I haven't tried using attributes besides style but I would imagine you could. The email system that I use (Blackbaud NetCommunity) will strip out a plain <a> tag, so I had to have at least one attribute.
Taking a cue from perilbrain's answer, I implemented the following regex that I use for this:
var unlink = function (val) {
return val.replace(/([#\.:])/g, '<span>$1</span>');
};
Note that this function replaces globally on whatever is passed in -- it would probably be too aggressive for blocks of natural text as in the OP's example, but often templates are parameterized and this works great when you can just pass it a url or email (I actually implemented it as a template helper function so that it does exactly that).
The function converts the following inputs:
john.doe#gmail.com
http://johndoe.com
into this:
john<span>.</span>doe<span>#</span>gmail<span>.</span>com
http<span>:</span>//johndoe<span>.</span>com
Note that I tried a fake short tag like <x> as shown in the accepted answer and found that GMail "intelligently" replaced it with <u> tags, which I assume is a feature, but was not desirable. In my testing, <span> tags prevent linking with no visual side-effects.
None of the solutions listed here seem to work any more. I experimented a little with the idea of non-printable Unicode characters and found this sequence to work:
<span>foo‌.‌bar‌.‌com</span>
Where ‌ is the ZERO WIDTH NON-JOINER character.
Nailed it!
This does not prevent emails from being turned into links, but it allows you to set the font color and remove the underline of that link.
It works in all email clients I tested in on litmus.com - including Outlook 2010, 2013, 2016 (also on Windows), Outlook.com, iPhone 6s, iPad, gmail web interface and Apple Mail 8, 9
Variation 1:
A link which does not react when clicked upon
bjorn#rosell.dk
Variation 2:
A mailto-link. Works in almost all clients. Outlook.com does however style it blue and with underline.
bjorn#rosell.dk
I have one unmentioned solution for textual emails: Use similar unicode characters. For example one dot leader (U+2024) instead of dot. Compare, how looks Běhej.com and Běhej․com (the first one is with regular dot).
I had a dot com in the title of my confirmation message.
Inspired by #perilbrain, I revolved my problem like this
domain.com => domain<span>.</span>
php
$titre = str_replace(".", "<span>.</span>", $titre);
simple !
For now simple wrapping by <span> is not working, I suggest replace # by its html-entity alternative
function disable_email_link($email) {
//encoder https://mothereff.in/html-entities
$email = str_replace('#', '#', $email);
$email = str_replace('.', '<span>.</span>', $email);
return $email;
}
Also if your email contains phone numbers you can escape it by disable_tel_link function:
function wrap_span_letters($string) {
$res = "";
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
$res .= "<span>$string[$i]</span>";
}
return $res;
}
function disable_tel_link($phone) {
return wrap_span_letters($phone);
}
Eventhough this is a old thread i want to help people who might get here. I found that adding a span inside the link makes google not see it as a link see below:
www.<span></span>link.dk
i had the same problem so after few mins found out how to fix it.
the thing is if you target the element directly it won't work because gmail will automatically add aa "a" tag in there so you have to go one step farther and declare a class for that "a" tag. in my case the email was in a "" tag which i found it easier to work with. so what i did was create a class like this:
.email_contact a {color:#ffffff!important; text-decoration: none!important;}
there is no "a" tag in my code but since gmail will add it automatically then you should catch it there. now you just have to use that class where ever you put your email add such as "span" or "div" and boom! fixed.
While not the ideal solution, it may be an option for some. As of 3/12/2020, If you disable Multipart and send plain text only emails, you'll get the following hyperlinked results. Results appear to be the same whether at the beginning of a new line/sentence or mid sentence.
Suppose your display url is "abcdUrl.com"
To prevent gmail from showing as a link, wrap it in an anchor tag
<a href="" style="text-decoration:none;color:#333;">
abcdUrl.com
</a>
This works well in gmail.

Mediawiki process tag after templates tranclusion

Is there any way to do something like that.
I have next wiki text:
{{template_open_tag}}
{{template_some_data}}
{{template_close_tag}}
And there are templates:
{{template_open_tag}}
<my-tag>
{{template_some_data}}
bla-bla-bla...
{{template_close_tag}}
</my-tag>
But tag '<bold>' processed already when first template transluded and wiki render this page like:
bla-bla-bla...
</my-tag>
But I want to see:
**bla-bla-bla...**
In my extension:
$wgHooks['ParserFirstCallInit'][] = 'myTagInit';
function myTagInit( &$parser ) {
$parser->setHook( 'my-tag', 'myTagRender' );
}
function myTagRender( $input, $args, $parser, $frame) {
return "**".$input."**";
}
Thank you.
P.S.
And don't ask me why I need this strange markup and don't want to use something like this:
{{template_tag|{{template_some_data}}}}
And {{template_open_tag}} like:
<my-tag>{{{1}}}</my-tag>
To warn you -- this sort of structure will likely be phased out entirely in future versions of MediaWiki, due to its inconsistent behavior and the difficulties it causes with structures like tags and sections.
The correct and future-proof way to do it is indeed to contain both your start and end in one template and pass the middle in as a parameter, eg {{template_tag|{{template_some_data}}}}
Set $wgUseTidy to true to make MediaWiki remove unclosed tags only after all the templates have been evaluated. Alternatively, you can use wikimarkup - as Adrian said - which does not suffer from this limitation.
Update: AFAIK XML-style extension tags are evaluated before way template including happens, so piecing them together from multiple templates is not possible. (Event <ext>{{{1}}}</ext> does not work pre-1.16, though you can make it work in 1.16 with recursiveTagParse.)
instead of using <bold> use ''' in both your {{template_open_tag}} and {{template_close_tag}} and it should render as bla-bla-bla...
Also, you can't do:
{{template_open_tag}}
{{template_some_data}}
{{template_close_tag}}
You have to do
{{template_open_tag}}{{template_some_data}}{{template_close_tag}}