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

Changing code
#21

Oops, I forgot to use [php][/p­­hp]. I'll try to remember in the future. To bad I can't edit my post to fix that now. Any Idea how to combine the two id values so that they work?

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

I edited your post to use PHP tags.

Are you trying to code it so that you can either use a custom page ID or use the normal autoincrementing id column?

If so, replace:
PHP Code:
<?php 
if (mysql_num_rows(mysql_query("SELECT * FROM `".$mysql_table_prefix."pages` WHERE id = '$page_id'")) == 0) { //if page ID does not exist

With:
PHP Code:
<?php 
if (mysql_num_rows(mysql_query("SELECT * FROM `".$mysql_table_prefix."pages` WHERE id = '$page_id' OR page_id = '$page_id'")) == 0) { //if page ID does not exist

That will check whether the supplied Page ID matches either the id or page_id column in the pages table.

It's totally untested.

Have you completed the interview?
Reply
#23

In fact, there should probably be a check to make sure that the custom Page ID does not match with any of the autoincrementing IDs. I suppose that could be done in the admin panel. The admin panel should check when you enter a custom Page ID that it is not an integer.

Edit: And also check that none of the custom Page IDs match each other.

Have you completed the interview?
Reply
#24

No, that doesn't work. Well, it does display it correctly, but commenting results in a ban for an incorrect referrer. What does the referrer have to do with it? Bans only for the custom id.
EDIT: This is for post #22
The check sort of complicated. If someone decides to edit a value in the database, then they could mess everything up. One id might be good enough, but I'll try something with two.

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

After thinking about it, how about this?

1. Add another (varchar) column called 'page_id'.
2. Make it a required field when creating a new page.
3. Change occurrences in the code from 'id' to 'page_id'.
4. Make sure the code can validate it properly.
5. During upgrade to v1.1, I think I can get the installer to rename the 'id' column to 'page_id' and add a new id column to replace it.

Have you completed the interview?
Reply
#26

I just got everything working correctly. The comments display correctly, you can comment without getting banned, and there are two columns for each page (and comment) concerning the id. For the page, one column is called id, the other is custom_id. For the comments, one is called page_id, the other is custom_page_id. I need to fix a few things, then I'll show you what I changed. For now, I just did what you wrote in the post above. Later, I'll modify the admin panel, rss, and installer.
After trying some things out, I decided that it's easier and better to use only the customized id. The page id that is currently used should be left in only to make sure there are no duplicate comment sessions. Well, here is how you need to modify the code:
From "/comments/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 custom_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


function get_page_reference() { //get page reference

global $mysql_table_prefix, $page_id; //globalise variables

$page_reference_query = mysql_query("SELECT reference FROM `".$mysql_table_prefix."pages` WHERE custom_id = '$page_id'");
$page_reference_result = mysql_fetch_assoc($page_reference_query);
$page_reference = $page_reference_result["reference"];

return
$page_reference;

}
//end of get-page-reference function


function get_page_url() { //get page url

global $mysql_table_prefix, $page_id; //globalise variables

$page_url_query = mysql_query("SELECT url FROM `".$mysql_table_prefix."pages` WHERE custom_id = '$page_id'");
$page_url_result = mysql_fetch_assoc($page_url_query);
$page_url = strtolower($page_url_result["url"]);

return
$page_url;

}
//end of get-page-url function

In "/comments/includes/template/processor.php" you need to edit lines 33, 69, 75, and 92 so that "page_id = '$page_id'" is "custom_page_id = '$page_id'"

In "/comments/includes/functions/form.php" line 37 should be
PHP Code:
<?php 
} else if (mysql_num_rows(mysql_query("SELECT * FROM `".$mysql_table_prefix."pages` WHERE custom_id = $page_id AND is_form_enabled = '0'"))) {

Then, create the "custom_id" column in the 'pages' table as a varchar with a value of, say, the variable that you want to define as a separate comment section.

In the 'comments' table, you need to create a column "custom_page_id" as the same thing above. Make the values of "custom_id" and "custom_page_id" the same.

In the page you want to include, set the line to be, for example
PHP Code:
<?php 
$page_id
= $_GET['variable'];

Now, for integrating it into the admin panel... I'll update later.

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

Interesting. I'll take a closer look at this tomorrow.

It seems that you've also renamed the 'page_id' column in the subscribers table to 'custom_page_id'.

Also, why do you need two page id related columns in the comments table?

Have you completed the interview?
Reply
#28

Technically, you don't have to rename those columns, only change their type and value. I forgot about the subscribers column, but yes, you also have to rename that one, or create a new one with that name.

To answer your question, you don't. I left it in there just as a backup if I'll need it to be able to read both from the default id, and from the custom one.

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

When clicking on the 'RSS for this page' link, it would be good if the id in the URL uses the autoincrementing id column and not the custom page id. It seems a bit cleaner for it to use a number and not a string.

Have you completed the interview?
Reply
#30

I think a better approach could be this:

Add another (varchar) column called 'custom_page_id' in pages table.
- This is an optional column.
- When you create a new page in admin, it's exactly the same as now.
- However when you edit a page, you can optionally enter a custom id.
- If entered, it checks to make sure it doesn't already exist.

The validate_page_id() function does the following:
- Checks whether the supplied page id exists in the 'custom_page_id' column. If it does then it validates and the script uses its corresponding id.
- If the supplied page id does not exist in the 'custom_page_id' column, check whether it exists in the id column. If it does then it validates and the script uses it.
- If it doesn't exist in either column then it doesn't validate.

As it would always use the id column (and never the custom id column) throughout the code, this means the following:
- The id parameter in the URL for the 'RSS for this page' link would use the integer id as normal and not the custom string.
- You could in theory edit your custom id in the admin panel at anytime without it messing anything up. Just remember to update your change in the page too.

The upgrade would be really simple. Upon upgrade v1.1 would continue to use the id column as normal.

Creating a new page would remain really simple. Only enter a custom id if you want to.

(This is obviously a big fundamental change so I think it's important to take some time with this to get it right.)

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)