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

Changing code
#11

I cleaned up the code a bit for Commentics v1.1.

This is the referrer section in comments/includes/app/processor.php

PHP Code:
<?php 
/* Check Referrer */
if (isset($_SERVER['HTTP_REFERER'])) { //if referrer available
$referrer = clean_url($_SERVER['HTTP_REFERER']); //get and clean referrer
$page_url = clean_url(get_page_url()); //get and clean page URL
if ($referrer != $page_url) { //if referrer does not match page URL
ban(BAN_REASON_INCORRECT_REFERRER); //ban user for incorrect referrer
}
} else {
error(ERROR_MESSAGE_NO_REFERRER); //reject user for no referrer
}

I added this new function in comments/includes/functions/processor.php

PHP Code:
<?php 
function clean_url ($url) { //cleans up a URL

$url = strtolower($url); //convert to lowercase

if (stripos($url, "?") !== false) { //remove any parameters
$parameter = substr($url, stripos($url, "?"));
$url = str_ireplace($parameter, "", $url);
}

$url = urldecode($url); //decode any special characters

return $url; //return cleaned URL

} //end of clean-url function

Have you completed the interview?
Reply
#12

(17-Jul-2010, 10:40 PM)Static Wrote:  I need help locating the place where the page id is set into the database, and the places where it's used that are important. I found the following files which seem relevant:
- App/processor.php
- Functions/processor.php
- Admin/Pages/manage_pages.php

The validate_page_id() function in comments/includes/functions/page.php is quite pertinent.

Have you completed the interview?
Reply
#13

Thanks, I'll look into it. However, the roadmap says
Code:
[Bug Fix] Removes default value for text columns in installer
[Bug Fix] Preserves URL parameters (and adjusts referrer check)
Does that mean you beat me to it? Either way, great!

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

I haven't (yet) changed anything to do with the Page ID.

I only integrated the Preserve Query add-on and added the change in post #11.

Were you expecting something else?

Have you completed the interview?
Reply
#15

No, I wasn't really. Does the installation have anything to do with the type of the 'id' column? If so, how do I change the id type to string? If it helps, I have phpMyAdmin installed.

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

Yes the installer sets the type of the id column in the pages table.

Go to the pages table in phpMyAdmin and click on the 'Structure' tab at the top.

On the id row, click the edit button (at the right under 'Action').

Change the 'Type' to varchar.
Set your desired maximum length (e.g. 250)
Make the 'Attributes' blank.
Deselect the auto_increment.

Click Save.

P.S. Note also that the RSS file, comments/rss.php, expects the Page ID in the URL to be a number.
P.S. Obviously you will need to re-write the Manage -> Pages page in the admin panel.

Have you completed the interview?
Reply
#17

I figured out how to change it in phpMyAdmin before you posted Wink. I'll fix the rss and manage pages along with the installer later, first, I'll have to make it work. I'll update when I get something to work.

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

If it was me I would add another column to the pages table called 'page_id'.

I think it's important for the id column to autoincrement so that it's always unique.

Have you completed the interview?
Reply
#19

I just got it working with a text ID. All I modified was the following in "/includes/functions/page.php":
PHP Code:
<?php 
function validate_page_id() { //validate page ID

global $mysql_table_prefix, $page_id; //globalise variables

if (!isset($page_id) || empty($page_id)) { //if no page ID
?><span class="page_id_alert"><?php echo ALERT_MESSAGE_NO_PAGE_ID;?></span><?php
die();
} else if (
ctype_graph($page_id) && strlen($page_id) < 250) { //if page ID validates
if (mysql_num_rows(mysql_query("SELECT * FROM `".$mysql_table_prefix."pages` WHERE id = '$page_id'")) == 0) { //if page ID does not exist
?><span class="page_id_alert"><?php echo ALERT_MESSAGE_MISMATCHING_PAGE_ID;?></span><?php
die();
}
} else {
//page ID did not validate
?><span class="page_id_alert"><?php echo ALERT_MESSAGE_INVALID_PAGE_ID;?></span><?php
die();
}

}
//end of validate-page-id function
Of course, I had to modify the id through phpMyAdmin, which is trivial. How I have set it up is by setting the id in the included page to be the value of the variable that I want. Then set the id of the page (in mySQL) to be one of the variable names. Now, I'll work on making it work by just getting the last part of the url. example:
Code:
example.php?variable=value

PS: I was writing this before you posted. Having another column might be a good idea. I see it as a way to make sure each page can't have the same id so that you don't get two different comment sessions with the same ID. Not sure how it would work together though. Not letting two pages have the same ID seems easier. I'll have to think over it. By the way, I didn't know how to call the "comment sessions", so I just called them that. What should I have called them?

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

I know what you mean when you say "comment sessions". I can't currently think of a clearer short way to say it.

Please remember to use PHP tags when posting (mostly) PHP code. I'm going to add that to the forum rules.

Have you completed the interview?
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by noblues
09-Jun-2014, 10:11 PM
Last Post by Steven
10-Oct-2013, 09:51 PM
Last Post by 2hands
30-Dec-2012, 01:34 AM
Last Post by 2hands
24-Jun-2012, 08:56 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)