Author Topic: How to provide URL / Post ID from a WB page?  (Read 318 times)

Offline svsanchez

  • Posts: 449
How to provide URL / Post ID from a WB page?
« on: September 19, 2018, 05:43:32 AM »
Hello!

I am trying to integrate my site to SPOT.IM in order to allow people to add comments to my pages. In order to do it, I need to define each page's URL and post ID:

    data-post-url="?????"
    data-post-id="?????">

I guess I have to put something like <?php page_description(); ?> there, changing the page_description part for something like page_url and page_id, but don't know exactly what to put there.

Could someone please tell me?

BIG THANKS!!!

Offline dbs

  • Betatester
  • **
  • Posts: 7553
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: How to provide URL / Post ID from a WB page?
« Reply #1 on: September 19, 2018, 10:02:11 AM »
Hi, it is for me unclear what you want.
data-post-url  could be WB_URL, but which format is your code. Is it html?

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2976
  • Gender: Female
Re: How to provide URL / Post ID from a WB page?
« Reply #2 on: September 19, 2018, 11:34:57 AM »
It's possible to do it. ;)
But you have to do little modifications in modules/news/view.php.

Any is located around line 500, the section where the Placeholders and Replacements for news output are defined.
Add to
$aPlaceHolders $addBracket(
    
'POST_LINK',
    
'POST_ID',
[
]

and to
$aReplacements = array(
    
$post_link,
    
$post_id,
[
]


Now, in Backend you can add your Links to the POST_FOOTER - Section using the new placeholders like:

?data-post-url=[POST_LINK]&data-post-id=[POST_ID]

This is just a rudimentary clue as to how and where the interface to SPOT.IM could be built. You can certainly find out the exact implementation based on these hints. Possibly somebody from the community also can help you


Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf ihnen Hirn vom Himmel !

Offline svsanchez

  • Posts: 449
Re: How to provide URL / Post ID from a WB page?
« Reply #3 on: September 20, 2018, 05:23:41 AM »
Hello, thank you for your replies. Darkviper, you said I have to do some modifications in modules/news/view.php BUT I'm trying to get the URL and ID of a NORMAL page.

For clarification, lets say that you create a new page, and you want to show in the CONTENT area of that page, the page's URL and the page's ID, like:

This page's URL is http://www.yoursite.com/pages/example.php and it's ID is 3

How can you do this?

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2976
  • Gender: Female
Re: How to provide URL / Post ID from a WB page?
« Reply #4 on: September 20, 2018, 10:14:06 AM »
Ok.  my example above was for use at News-Posts.
The implementation at whole pages is not too different.
You need the link to fall back to this page and additional an unique id for the page itself.

Add a code2 section to the bottom of the page.
Code: (code2-section) [Select]
<?php
// build the Link (URL) like:
    
$sPageUrl WB_URL.PAGES_DIRECTORY.$GLOBALS['wb']->page['link'].PAGE_EXTENSION;
// the ID  like:
    
$sPageId 'P'.(string) $GLOBALS['wb']->page['page_id'];
// Now you have the two important vars and can build the needed API calls for SPOT.IM
    
echo '<a href="https://spot.im?......">Comments</a><br>';
You wonder about the prefix 'P'? This is only for distinguishing page-related ID's and section-related ID's as e.g. occur in news posts or something else.
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf ihnen Hirn vom Himmel !

Offline svsanchez

  • Posts: 449
Re: How to provide URL / Post ID from a WB page?
« Reply #5 on: September 21, 2018, 03:57:32 AM »
Hello Dark, thanks a lot for your help. I tried to implement it but it didn't work (I'm not a coder so I most probably made a mistake). I added the code in my template, since this code has to go in ALL of my pages. This is what I added to my page's code:

Code: [Select]
<!-- SPOT.IM (MESSAGES) -->

<?php
// build the Link (URL) like:
    
$sPageUrl WB_URL.PAGES_DIRECTORY.$GLOBALS['wb']->page['link'].PAGE_EXTENSION;
// the ID  like:
    
$sPageId 'P'.(string) $GLOBALS['wb']->page['page_id'];
// Now you have the two important vars and can build the needed API calls for SPOT.IM
?>


<script async src="https://launcher.spot.im/spot/mySpotImNumber"
    data-spotim-module="spotim-launcher"
    data-post-url=$sPageUrl
    data-post-id=$sPageId>
</script>

<!-- END SPOT.IM (MESSAGES) -->

I am assuming that the Page's URL is stored in $sPageUrl and the page's ID is stored in sPageId, is that correct? Also, please note that I added ?> because I was getting an error without it.

If so, how do I put those values inside of the javascript's data-post-url and data-post-id?

Thanks again!

Offline Luisehahne

  • WebsiteBaker Org e.V.
  • **
  • Posts: 4156
  • Gender: Male
    • Webdesign und Entwicklung WebsiteBaker
Re: How to provide URL / Post ID from a WB page?
« Reply #6 on: September 21, 2018, 09:10:23 AM »
you have to echo the php variables in html script tags

Code: [Select]
<script async src="https://launcher.spot.im/spot/mySpotImNumber"
    data-spotim-module="spotim-launcher"
    data-post-url=<?php echo $sPageUrl?>
    data-post-id=<?php echo $sPageId?>
</script>

Dietmar
Immer nur von der Zukunft reden, die Gegenwart vergessen und auf die Vergangenheit schimpfen
Neues Unwort: Schnappatmung

Offline svsanchez

  • Posts: 449
Re: How to provide URL / Post ID from a WB page?
« Reply #7 on: September 21, 2018, 06:18:23 PM »
YESSS!!! Thanks a lot, it worked with the echo thing! There was only the last ">" missing to the code provided by Luisehahne, here is the complete code in case anyone else wants to add Spot.im commenting system to monetize their sites:

Code: [Select]
<?php
// build the Link (URL) like:
    
$sPageUrl WB_URL.PAGES_DIRECTORY.$GLOBALS['wb']->page['link'].PAGE_EXTENSION;
// the ID  like:
    
$sPageId 'P'.(string) $GLOBALS['wb']->page['page_id'];
// Now you have the two important vars and can build the needed API calls for SPOT.IM
?>



<script async src="https://launcher.spot.im/spot/mySpotImNumber"
    data-spotim-module="spotim-launcher"
    data-post-url=<?php echo $sPageUrl?>
    data-post-id=<?php echo $sPageId?>
    >

</script>

 

postern-length