PDA

View Full Version : Obtaining Unique URL for each page? (VB5.2)


karlm
07-23-2016, 11:39 AM
How would I obtain the unique URL for a page so I can call it from PHP/HTML, please?

I guess it would be similar to the post identifier, clicking on it gives the URL to that post in a popup window.

Replicant
07-23-2016, 11:54 AM
So you want to get the url of a nodeid? Where is the nodeid coming from? See the attachment for php usage of the function getAbsoluteNodeUrl()

This can also be done entirely with javascript and AJAX calling route/getAbsoluteUrl

karlm
07-23-2016, 01:27 PM
Forgive my ignorance, I'm reasonably experienced in programming of old but today's languages are somewhat over my head.

So please allow me to ask for an answer that I can digest a little easier.

I need a means to call the URL of the current page so a script can ensure it has the correct values. In short, I'm looking at replacing the 'comments' used in 'articles' of VB5 so instead of a boring plain box with some bot deterrent questions, a guest can leave a comment on each page.

Disqus seems like the obvious answer as although VB5 can have 'guests' commenting, aside from checking IP addresses and such there's no real way to tell one guest from another. With Disqus I get to see who they actually are whilst not having to be a registered member and still retain a high level of moderation over such comments.

They supply a default code to apply to web pages, which I've done.

I edited my 'article' page (default template 36) to have a PHP module at the bottom of the page. I pasted their code into the PHP module and it says I have to find the Unique URL to ensure content isn't mixed up with other content.

<div id="disqus_thread></div>
<script>

/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables */
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//antimisandry.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
So, while you've very kindly assisted with guiding me to what I may need, I have no idea how that is applied in this case.

Here is their explanation (https://help.disqus.com/customer/en/portal/articles/2158629) for what is needed:
These variables should be defined by using your CMS’ or platform’s dynamic values, if available. For example, the Disqus WordPress plugin defines these variables by default using the following PHP values:

this.page.url = '<?php echo get_permalink(); ?>';
this.page.identifier = '<?php echo dsq_identifier_for_post($post); ?>';I hope this clarifies what I'm looking for and clarifies my absolute lack of comprehension on the topic. :)

Here's an example of where I'm using it (not trying to spam, so please delete this link if it's considered spam)

http://antimisandry.com/articles/cultural-myths-mythbusting/593831-study-findings-on-domestic-violent-present-challenging-picture

Replicant
07-23-2016, 02:21 PM
Ok, that's pretty easy to do as the information is already in every page. Probably won't need the php module either. There is a canonical url in the header if every page. This can be retrieved and the variable set for disqus using jquery and set to the this.page.url variable. For the this.page.identifier variable, you can use the pageData.nodeid variable that is embedded in the page.

Here is what the header code for the canonical url looks like.
<link rel="canonical" href="http://www.example.com/articles/1234-article-name"/>

karlm
07-23-2016, 04:22 PM
Yeah, all of that flew like Concord over my head lol...

I received your PM and will eagerly accept your kind offer :)

Replicant
07-24-2016, 03:10 AM
Open one of the articles on your site, enable sitebuilder, drag an ad module down below the article, edit the module, paste this code into an ad and save. You can select who sees it during the configuration of the module.
You will also want to disable comments for Articles to make the comment box disappear. You may have to hide the comments disabled message with CSS. I started a Discus account and tested the functionality, it works as expected. I am a bit confused as to why use the outside forum since the guest user has to signup for a discus account to post. Why not just have the user sign up to your forum instead?

<div id="disqus_thread"></div>
<script type=" text/javascript " >
PAGE_IDENTIFIER = pageData.nodeid;
window.onload = function () {
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i ++) {
if (links[i].getAttribute("rel") === "canonical") {
PAGE_URL = links[i].getAttribute("href")
}
}
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//antimisandry.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

karlm
07-24-2016, 11:38 AM
The reason being is because there are already hundreds of thousands of Disqus users registered, this enables some level of control over guest comments without each & every guest being named "guest". I'm just trialling it for now...

Thank you so kindly for your assistance with the code & support in how to implement it. I really appreciate the help.

noypiscripter
07-25-2016, 02:27 AM
Instead of looping through all the link tags and looking for canonical, the canonical href can be retrieved using a single line:

document.querySelector('link[rel="canonical"]').href


--------------- Added 1469420994 at 1469420994 ---------------

If the discus code is inserted after the jQuery include, you can also use:

$('link[rel="canonical"]').attr('href')

Replicant
07-25-2016, 02:53 AM
If the discus code is inserted after the jQuery include, you can also use:

$('link[rel="canonical"]').attr('href')

Thanks Glenn. The code is in an ad module for easy usergroup administration without writing custom templates. This is the Jquery code I had come up with originally. I battled this one because the code is before jquery loads. I'm not very proficient with pure JS so I have to hit places like Stack Exchange for answers to get it done. I didn't particularly like the looping, but this one was taking way too much time and there aren't that many link tags to cause a severe performance hit, so I rolled with it.

noypiscripter
07-25-2016, 01:34 PM
Actually, if you use window onload handler, you can safely use jQuery inside the handler as the jQuery has been loaded completely at that point even if the script was inserted before the jQuery include. Although I don't like using window onload for this particular issue because if a thread has multiple large images, the browser has to wait for them to be completely loaded before the Discus code is executed and initialized. And besides, window onload is not necessary.

I recommend using pure JS without window onload.

final kaoss
02-16-2019, 01:17 AM
Hi thanks for some of these helpful replys, I'm trying to add disqus to the vbulletin archive. (using vb4 though)

Any help on what to fill in here?

this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable