This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Integrating with dynamic links (Outdated)
#1

Commentics, as you all know, is a great comment script with many features. With the release of version 1.1, extra functionality has been added. On of the key features of 1.1, in my opinion, is the ability to integrate Commentics in dynamic links, such as "www.example.com/comment_page.php?variable=value". This tutorial explains how to integrate Commentics efficiently with such links.

There are several things to determine before you start, though. Some links are meant to determine which layout the site will have: ("comment_page.php?layout=article1"), others are just to determine some value: ("comment_page.php?time=800"). Sometimes, you want to put those together: ("comment_page.php?layout=article1&time=800"). Nevertheless, exactly one variable determines the layout. In some cases, you want two or more variables for the layout: ("comment_page?layout=articlepart1&sublayout=articlepart2") and ("comment_page?layout=articlepart2&sublayout=articlepart5"). First, I'll explain the first case.

Lets start by going to the dynamic page that you want to add a comment section to: ("www.example.com/comment_page.php?layout=article1").
Open up the Commentics back-end, and go to "manage->pages".
Copy the url, and paste it into the "new page URL" box.
Add a reference, and add the page. For now, let's leave it at that.
Open the source of the page that needs the comments section, and go to the include lines:
PHP Code:
<?php 
$page_id
= "1";
$path_to_comments_folder = "comments/";
define ('IN_COMMENTICS', 'true'); //no need to edit this line
require $path_to_comments_folder . "includes/commentics.php"; //no need to edit this line
?>
Now, instead of the page ID that's supposed to be there, you can add a string. In our case, lets change "$page_id = "1";" to:
PHP Code:
<?php 
$page_id
= $_GET['layout'];
where 'layout' is the name of the layout-changing variable.
Go back to the admin panel, and edit the page which you created earlier.
In the "Custom ID" field, input the name of 'value' where 'value' is the value of the variable: ("comment_page.php?layout=article1") will make 'value' = article1; This requires that you know the variable name of the page you need.
Save the changes, and you're done!

If you have a lot of pages already, this method will be slow and tedious, though. For this reason, I've created a piece of code which will make the process a lot faster and easier. This code should be put in "comments/includes/commentics.php" after the section called "ADMIN DETECTION".
PHP Code:
<?php 
/**************************************************ADMIN ADDITION**************************************************/
if ($is_admin){ if (isset($_POST['submit'])) {

$reference = $_POST['reference'];
$url = $_POST['url'];
$custom_id = $_POST['custom_id'];

$reference = sanitize($reference);
$url = sanitize($url);
$custom_id = sanitize($custom_id);

mysql_query("INSERT INTO pages (reference, url, is_form_enabled, dated, custom_id) VALUES ('$reference', '$url', '1', NOW(), '$custom_id')");
?>
<div style="border: 1px solid; margin: 10px 0px; padding: 5px 5px 5px 25px; float: left; color: #4F8A10; background-color: #E8FCDC;">Page added: [<?php echo $reference; ?>] [<?php echo $url; ?>]</div>
<div style="clear: left;"></div>
<?php } ?>

<form name="add_page" id="add_page" action="<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
Reference: <input type="text" name="reference" size="30" maxlength="250"/>&nbsp;
URL: <input type="text" name="url" size="45" maxlength="250" value="<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>"/>&nbsp;
Custom ID: <input type="text" name="custom_id" size="30" maxlength="250" value="<?php echo $_GET['value']; ?>"/> <!--MAKE SUR YOU CHANGE $_GET['value'] to your variable name-->
<input type="submit" class="button" name="submit" title="Add Page" value="Add Page"/>
</form><?php }
/******************************************************************************************************************/
What it does is adds an extra field, and fills in everything except the reference. All you need to do is modify "$_GET['value']" to be the name of your variable: (comment_page.php?my_layout_variable=article1) would change it into "$_GET['my_layout_variable']". The only other requirement is that you need to set yourself to be detected as an administrator via the backend in "settings->admin detection".

For the second case, it is very prefferable to create another variable to determine the comments section id. If that's not possible, follow everything above, but try setting the custom id to be "variable1"+"variable2", so: (comment_[age.php?layout=article2&sublayout=article5) would have a custom id of "article1article5", and the include script would be
PHP Code:
<?php 
$page_id
= $_GET['layout']+$_GET['sublayout'];
Do likewise for the code above if you plan on using the code to simplify things.

When you are done with the code that you put into "commentics.php", it is advised to delete it, as it will still be on the page, even after it has been successfully added. It is included as a simplification of the process, but it is not styled, or fully developed. It is possible that I will include the above code in an add-on. No guarantees, but I might do it.


If you have any questions, comments, or feel that I've missed something, I'll be glad to help. If I decide to change something, I doubt that it'll be possible for *me* to change this post, so make sure you read the rest of the thread for further changes, if any.

I'm giving you three guesses...
Reply
#2

Ah, yes, there is one thing I forgot to mention. If you don't want someone to see an "invalid id" error if they decide to enter something in the url, then add a check against it.
PHP Code:
<?php 
switch($_GET['layout'])
{
case
'article1': case 'article2': case 'article3': /*etc...*/
define('VALID_COMMENT_PAGE','true');
break;
//only one break required
}

Then shove the include script into an if statement:
PHP Code:
<?php 
if(defined('VALID_COMMENT_PAGE'))
{
$page_id = $_GET['value'];
$path_to_comments_folder = "comments/";
define ('IN_COMMENTICS', 'true'); //no need to edit this line
require $path_to_comments_folder . "includes/commentics.php"; //no need to edit this line
}

One advantage of this is that you can add an optional else statement to show something else when a comment system isn't supposed to be there. Enjoy!

I'm giving you three guesses...
Reply
#3

I should have added this a while ago.

With the Arbitrary ID add-on, dynamic links are automatically added, so you have to do almost nothing. There are a couple of drawbacks with that add-on, such as a user entering a value into the URL that you didn't anticipate, but that's how all arbitrary IDs work. I've added how to deal with that too. For more information, go to the Arbitrary ID thread under add-ons: http://www.commentics.org/forum/showthread.php?tid=56

I'm giving you three guesses...
Reply
#4

Is there a way to make this work with two categories?
url.php?restaurant=1 and url2.php?attraction=1

They have seperate ID's but some have the same Custom ID, like "1" in the example above.

I know. I'm a pain. Smile
Reply
#5

I'm not quite sure what you mean, but you can try:
PHP Code:
<?php 
if(isset($_GET['restaurant']) && $_GET['restaurant'] != null && $_GET['restaurant'] != "")
{
$page_id = $_GET['restaurant'];
}
if(isset(
$_GET['attraction']) && $_GET['attraction'] != null && $_GET['attraction'] != "")
{
$page_id = $_GET['attraction'];
}

What this does is check if the restaurant variable exists, and isn't empty. If so, it sets the page id to be the value of that variable. Then, it does the same for the attraction variable. This means that if both are set, then attractions will override restaurants. This can be fixed by adding:
PHP Code:
<?php 
if(isset($_GET['restaurant']) && $_GET['restaurant'] != null && $_GET['restaurant'] != "" && isset($_GET['attraction']) && $_GET['attraction'] != null && $_GET['attraction'] != "")
{
$page_id = $_GET['restaurants']+$_GET['attractions'];
}

Hope that this isn't too confusing, and that it helped too...

These examples assume that it's the same page, but with different variables:

an_url.php?restaurants=1
an_url.php?attractions=1
an_url.php?restaurants=1&attractions=1

with all the base URLs being the same.
Oh, you edited the post above. Let me fix mine.

I'm giving you three guesses...
Reply
#6

Hmmm... thanks for that.
What I have is two different urls:
attractions_and_entertainment_in_provo.php?attraction=ID
list_of_restaurants_in_provo.php?restaurant=ID

So that is close to what I would need.
What is happening right now is that the comment page with customID of 2 and ID 4 is being used for both urls, when I want another comment page with customID of 2 and ID 5 being used on the other. Does that make sense?
Reply
#7

If you know the name of the variable, you can do:
PHP Code:
<?php 
$page_id
= "restaraunts".$_GET['restaurants'];

That should work.

You see, this tutorial wasn't really meant for variables with a number value. I forgot to take that into account Blush

BTW, this could be the reason for the incorrect referrer bans you were having earlier.

I'm giving you three guesses...
Reply
#8

It doesn't seem to detect it now. Is it possible to use the url path + customID to locate the correct comment page?
(http://www.provohappening.com/list_of_re...aurant=205)

thanks for all your help btw
Reply
#9

I think that you forgot to add the id in the backend.

My add-on can really help. It adds the page automatically, and it has a certain variable that you can use to do just that.
You can use
PHP Code:
<?php 
$page_id
= "http://www.yoursite.com".$_SERVER['REQUEST_URI'];
For it right now without the add-on.

If you decide to use the add-on, then change
PHP Code:
<?php 
$arbitrary_id_reference
= '';//Your value/variable here
to
PHP Code:
<?php 
$arbitrary_id_reference
= $current_page_url;//Your value/variable here

I'm giving you three guesses...
Reply
#10

I guess I must be missing something.
PHP Code:
<?php 
$page_id
= "http://www.yoursite.com".$_SERVER['REQUEST_URI'];

has been added and works fine, but it doesn't pull up the connected comment page with that url.
I've added the arbritary-id to commentics and changed the insert script to fit it, and the reference var without any progress.
Maybe this will help.


Attached Files Thumbnail(s)
   
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)