News Article Submissions


With articles being such a large part of most PostNuke websites, the news submission modules get a great deal of use. Sites that allow their users to do more than just read content can sometimes find their users bothered by the extra features PostNuke provides. Not every user is tech savvy, but rather than require your users to learn about extra features, you can hack the modules to simply not use the features you do not need.

In addition, the Article Comments module is a very powerful feature of PostNuke, but it's very specific in how it handles posts. On many websites, it's popular to allow blog-style anonymous posting of comments. Although you can reduce security easily to allow unregistered posts, PostNuke does not provide the fields to allow anonymous visitors to enter identifying information. With the hack covered in this section, you can change all that.

Changing Default "Articles" to "No Category"

The Add Story module has a Category drop-down list box that provides another method of grouping articles. Articles that are not assigned a custom category name end up in the general "Articles" group. This can be confusing to general users who do not understand that "Articles" means "No Category." An easy fix for this problem is to change the way the catid is displayed.

Open the global language definitions file:

 /language/eng/global.php 

The variable defined as "Articles" and used to display the word is also in this file. The local definitions are not used by the function you are editing, so our new definition also goes here.

Add a new line under the _NOANONCOMMENTS definition with this content:

 define('_NOCATEGORY','No Category'); 

If you want to use different phrasing, this is where you need to place it. Now edit the Categories file in Add Story:

 /modules/NS-AddStory/addstory_categories.php 

Scroll down to roughly line 554 and find the following echo statement:

 echo "<option value=\"0\" $sel>"._ARTICLES."</option>"; 

Change the variable call to display the new words:

 echo "<option value=\"0\" $sel>"._NOCATEGORY."</option>"; 

The option value remains set to "0," so the actual functionality of the system remains the same.

Removing Article Categories

For some PostNuke users, having the additional category option for articles might be too complicated. Understanding the different topic groups with the accompanying icons tends to come a lot easier than discerning how the text category names fit in. It might also be that your PostNuke site just doesn't need the extra layer of article customization. And if your site is not using it, why have the form display the list box at all?

Removing the Article option for new stories is very straightforward. Edit the functions file in Add Story:

 /modules/NS-AddStory/addstory_functions.php 

Look for a function called storyEdit that begins around line 132. This function controls the display of all the main form elements in Add Story. At line 147, you should see this function call:

 SelectCategory($catid); 

Removing the selection requires only that you comment out that line. The catid for every article is still set to "0," but now your users do not have to be concerned by the additional choice in the form. You should also comment out the subsequent line break to tidy up the spacing in the form:

 // SelectCategory($catid); // echo "<br />"; 

Now you might notice that the "Only works if Articles category isn't selected" line is still visible as part of the Publish on Homepage option. This message is not needed now that the categories are gone. It is also found in the Functions file:

 /modules/NS-AddStory/addstory_functions.php 

Look at the top of the file near line 45 for these lines:

 echo "<input type=\"radio\" name=\"ihome\" value=\"0\"$sel1 />"._YES."&nbsp;"     ."<input type=\"radio\" name=\"ihome\" value=\"1\"$sel2 />"._NO.""     ."&nbsp;&nbsp;<span class=\"pn-normal\">[ "._ONLYIFCATSELECTED." ]</span><br />"; 

The last part of the echo statement is the important one, but it also ends the statement, so you can't just comment it out without adding back in the required semicolon and line break. Here is the changed code:

 echo "<input type=\"radio\" name=\"ihome\" value=\"0\"$sel1 />"._YES."&nbsp;"     ."<input type=\"radio\" name=\"ihome\" value=\"1\"$sel2 />"._NO."<br />"; //    ."&nbsp;&nbsp;<span class=\"pn-normal\">[ "._ONLYIFCATSELECTED." ]</span><br />"; 

Now, you have a clean and simplified Add Story form like the one in Figure 22.5.

Figure 22.5. Removing the Article categories for a simplified form.


Adding Names to Anonymous Comments

A quick change to the Permissions table allows unregistered site visitors to post comments to articles, but when those users try to make a post, the Your Name field comes up only as "Anonymous." You can edit the way the Comments module handles unregistered users and create input fields so the users can type in their identification instead. These changes turn the comments into a public blog style system similar to those currently found on many websites.

Only one file needs to be changed to make this work:

 /modules/NS-Comments/index.php 

However, many edits must be made in that single file to complete the effect. This section walks through the file changes from top to bottom to keep it simple, but note that the changes do not match up with the timing of the code as it's run to complete normal comment submission steps from a browser.

Look at Figure 22.6. Allowing anonymous posting has one major side effect. The (User information | Send a message) links are tied to the PostNuke account system. You need to remove those links to prevent failed lookups for users who are unregistered.

Figure 22.6. A basic article comment.


The website URL can be used by providing an additional field allowing anonymous users to enter their website address. Similarly, a user's email is displayed if the account toggle is set to make it public. You can also add in an email field to fill this account feature. If an anonymous user types in his email, it is displayed; otherwise, the field can be left blank, if he prefers.

You can begin the changes. Open the Comments index.php file identified previously in your editor. Proceed to line 307 where you should see the following lines within the DisplayKids function:

 if ($r_name != $anonymous) {     echo "<br /><span class=\"pn-normal\">(<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$r_name&amp;module=NS-User\">"._USERINFO."</a> | <a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Messages&amp;file=replypmsg&amp;send=1&amp;uname=$r_ name\">"._SENDAMSG."</a>)</span> "; } if (eregi("http://",$r_url)) {     echo "<span class=\"pn-normal\"><a class=\"pn-normal\" href=\"$r_url\" target=\ "window\">$r_url</a></span> "; } 

Tip

Add change comments so you can easily see why certain edits were made next time you open the file.


The first if statement writes out the PostNuke account links. It needs to be commented out. The second line writes out the website URL. The second statement is fine, except that on the page they normally appear together on the same line (see Figure 22.6). If you comment out the first line, the <br /> tag is not present for the following URL. That moves the URL up next to the date stamp, which does not look as good. Add in a <br /> tag to the second echo statement to fix that issue. The changed code looks like this:

 // if ($r_name != $anonymous) { //     echo "<br /><span class=\"pn-normal\">(<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$r_name&amp;module=NS-User\">"._USERINFO."</a> | <a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Messages&amp;file=replypmsg&amp;send=1&amp;uname=$r_ name\">"._SENDAMSG."</a>)</span> "; // } if (eregi("http://",$r_url)) {     echo "<br />\n<span class=\"pn-normal\"><a class=\"pn-normal\" href=\"$r_url\ " target=\"window\">$r_url</a></span> "; } 

A slight variant of the previous code is also in the DisplayKids function and it is found a few lines down at about line 369:

 if ($r_name != $anonymous) {     echo "<br /><span class=\"pn-normal\">(<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$r_name\">"._USERINFO."</a> | <a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Messages&amp;file=replypmsg&amp;send=1&amp;uname=$r_ name\">"._SENDAMSG."</a>)</span> "; } if (eregi("http://",$r_url)) {     echo "<span class=\"pn-normal\"><a class=\"pn-normal\" href=\"$r_url\" target=\"window\">".pnVarPrepForDisplay($r_url)."</a></span> "; } 

Make the same change with comment markers for the first statement and a break added to the second:

 // if ($r_name != $anonymous) { //     echo "<br /><span class=\"pn-normal\">(<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$r_name\">"._USERINFO."</a> | <a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=Messages&amp;file=replypmsg&amp;send=1&amp;uname=$r_ name\">"._SENDAMSG."</a>)</span> "; // } if (eregi("http://",$r_url)) {     echo "<br />\n<span class=\"pn-normal\"><a class=\"pn-normal\" href=\"$r_url\" target=\"window\">".pnVarPrepForDisplay($r_url)."</a></span> "; } 

Now scroll down to line 605. You see lines nearly identical to the first set you changed, but this time they are part of the DisplayTopic function:

 if($name != $anonymous) {     echo "<br />\n<span class=\"pn-normal\">(<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$name&amp;module=NS-User\">"._USERINFO."</a> <a href=\"modules.php?op=modload&amp;name=Messages&amp;file=replypmsg&amp;send=1&amp;uname=$ name\">"._SENDAMSG."</a>)</span>\n "; } if(eregi("http://",$url)) {     echo "<span class=\"pn-normal\"><a class=\"pn-normal\" href=\"$url\" target=\"window\">".pnVarPrepForDisplay($url)."</a></span>\n "; } 

Complete the same set of changes to these lines:

 // if($name != $anonymous) { //     echo "<br />\n<span class=\"pn-normal\">(<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$name&amp;module=NS-User\">"._USERINFO."</a> <a href=\"modules.php?op=modload&amp;name=Messages&amp;file=replypmsg&amp;send=1&amp;uname= $name\">"._SENDAMSG."</a>)</span>\n "; // } if(eregi("http://",$url)) {     echo "<br />\n <span class=\"pn-normal\"><a class=\"pn-normal\" href=\"$url\" target=\"window\">".pnVarPrepForDisplay($url)."</a></span>\n "; } 

Now scroll down to the reply function and around line 861 find this section of code:

 echo "<span class=\"pn-title\">"._YOURNAME.":</span> "; if (pnUserLoggedIn()) {     echo "<a href=\"user.php\">" . pnUserGetVar('uname') . "</a> <span class=\" pn- normal\">[ <a class=\"pn-normal\" href=\"user.php?module=NS- User&amp;op=logout\">"._LOGOUT."</a> ]</span><br /><br />"; } else {     echo "<span class=\"pn-normal\">".pnVarPrepForStore($anonymous)."";     echo " <span class=\"pn-normal\">[ <a class=\"pn-normal\" href=\"user.php\">"._NEWUSER."</a> ]</span><br /><br />"; } 

The code writes out the username of the user if logged in, and write out the "Anonymous" text if not. You can also see this in Figure 22.7, which displays a standard comment post.

Figure 22.7. Adding an anonymous comment to an article.


In this section of code, you add new form inputs to gather the submitter's name, email, and website URL. The anonymous user is also usually prompted at this point to log in/ register. This is done using the user.php link after the name is written to the page. Leave this link to keep the registration option available to anonymous posters. Examine the following changed code:

 echo "<span class=\"pn-title\">"._YOURNAME.":</span> "; if (pnUserLoggedIn()) {     echo "<a href=\"user.php\">" . pnUserGetVar('uname') . "</a> <span class=\ "pn-normal\">[ <a class=\"pn-normal\" href=\"user.php?module=NS- User&amp;op=logout\">"._LOGOUT."</a> ]</span><br /><br />"; } else {     echo "<br />\n<input type=\"text\" name=\"aname\" value=\"\" /> <span class=\"pn- normal\">[ <a class=\"pn-normal\" href=\"user.php\">"._NEWUSER."</a> ]</span><br /><br />";     echo "<span class=\"pn-title\">"._UREALEMAIL.":</span><br />"         ."<input type=\"text\" name=\"aemail\" value=\"\" size=\"30\" maxlength=\"60\" /><br /><br />";     echo "<span class=\"pn-title\">"._YOURHOMEPAGE.":</span><br />"         ."<input type=\"text\" name=\"aurl\" value=\"http://\" size=\"30\" maxlength=\"100\" /><br /><br />"; //    echo "<span class=\"pn-normal\">".pnVarPrepForStore($anonymous).""; //    echo "<span class=\"pn-normal\">[ <a class=\"pn-normal\" href=\"user.php\">"._NEWUSER."</a> ]</span><br /><br />"; } 

The name and email fields have been left blank to invite the user to fill them out. The URL input includes the "http://" start, which is required for URL display. The names of the three new inputs are aname, aemail, and aurl to designate anonymous user information separate from the normal form. And the size and maxlength attributed for the inputs were taken from the PostNuke user account system, so they match with limitations already present in the database.

You can, at this point, save your changes and take a look at the initial comment form. It displays the same as what's shown in Figure 22.8.

Figure 22.8. Adding your name and email to your comments.


Now move down to the replyPreview function at about line 910. The first thing the function does is gather in all the variables submitted from the previous form. You added three new variables, so those need to be added to this part of the function for it to know about them. This is the original source:

 function replyPreview() {     list($pid,          $sid,          $subject,          $comment,          $xanonpost,          $mode,          $order,          $thold,          $posttype) = pnVarCleanFromInput('pid',                                           'sid',                                           'subject',                                           'comment',                                           'xanonpost',                                           'mode',                                           'order',                                           'thold',                                           'posttype'); 

The new form inputs were entered just before the subject field, so add them to the same place in the list assignment for consistency. The changed code looks like this:

 function replyPreview() {     list($pid,          $sid,          $aname,          $aemail,          $aurl,          $subject,          $comment,          $xanonpost,          $mode,          $order,          $thold,          $posttype) = pnVarCleanFromInput('pid',                                           'sid',                                           'aname',                                           'aemail',                                           'aurl',                                           'subject',                                           'comment',                                           'xanonpost',                                           'mode',                                           'order',                                           'thold',                                           'posttype'); 

In the comment preview, the comment is posted at the top with the user's name, and below the preview is a copy of the original entry form. The next change fixes the display of the name field in the preview itself. Look for this if statement starting at line 959:

 if (pnUserLoggedIn() && !$xanonpost) {     echo pnUserGetVar('uname'); } else {     echo "".pnVarPrepForDisplay($anonymous).""; } 

The first branch displays the normal username; leave it alone. The second branch displays the $anonymous variable for all users who are not currently logged in. Review the following changes:

 if (pnUserLoggedIn() && !$xanonpost) {     echo pnUserGetVar('uname'); } else { if ($aname == "") { $aname = $anonymous; } echo "".pnVarPrepForDisplay($aname).""; // echo "".pnVarPrepForDisplay($anonymous).""; } 

The $aname variable was set up when you added it to the beginning of the function. At this point, the form doesn't know whether the user has entered her name or left the field blank. So within the second branch, check for an empty $aname variable, and if found, set it to the default $anonymous. Then, the $aname can be echoed normally to handle both possible events.

Note

Setting the empty $aname variable to $anonymous autopopulates the field in the form below. It will be obvious to anyone leaving the field blank that "Anonymous" will be used for their name if they do not fill in the field.


A short bit down from there at line 987, the duplicate of the submission form is started. The preview form does not yet have the three new input fields, so you can add them now. Here is the original source to edit:

 echo "<form action=\"modules.php\" method=\"post\"><div><span class=\"pn-title\">". _YOURNAME.":</span> "; if (pnUserLoggedIn()) {     echo "<a href=\"user.php\">" . pnUserGetVar('uname') . "</a> <span class=\"pn- normal\">[ <a class=\"pn-normal\" href=\"user.php?module=NS- User&amp;op=logout\">"._LOGOUT."</a> ]</span><br /><br />"; } else {     echo "<span class=\"pn-normal\">".pnVarPrepForStore($anonymous)."</span><br /><br />"; } 

Change it to look like this code; all of the additions are in the second branch of the if statement:

 echo "<form action=\"modules.php\" method=\"post\"><div><span class=\"pn-title\">". _YOURNAME.":</span> "; if (pnUserLoggedIn()) {     echo "<a href=\"user.php\">" . pnUserGetVar('uname') . "</a> <span class=\"pn- normal\">[ <a class=\"pn-normal\" href=\"user.php?module=NS- User&amp;op=logout\">"._LOGOUT."</a> ]</span><br /><br />"; } else {     echo "<br />"         ."<input type=\"text\" name=\"aname\" value=\"".pnVarPrepForDisplay($aname)."\" /> <span class=\"pn-normal\"><br /><br />";     echo "<span class=\"pn-title\">"._UREALEMAIL.":</span><br />"         ."<input type=\"text\" name=\"aemail\" value=\"".pnVarPrepForDisplay($aemail)."\" size=\"30\" maxlength=\"60\" /><br /><br />";     echo "<span class=\"pn-title\">"._YOURHOMEPAGE.":</span><br />"         ."<input type=\"text\" name=\"aurl\" value=\"".pnVarPrepForDisplay($aurl)."\" size=\"30\" maxlength=\"100\" /><br /><br />"; //    echo "<span class=\"pn-normal\">".pnVarPrepForStore($anonymous)."</span><br /><br />"; } 

The inputs are similar to the tags added in the initial submission form. What's been changed is the addition of the $aname, $aemail, and $aurl to the values of the tags. The initial <br /> was added to place the Name input on the line below the label; the names of logged-in users normally appear to the right of the label on the same line. And the original line is commented out at the last.

You can now test the preview screen with a comment test submission. It will look like the form in Figure 22.8, but the entered content autopopulates the fields in the preview form.

Next, you alter the CreateTopic function to use these new fields when it creates a database table entry for a new comment. The function starts at about line 1057 with a header similar to the replyPreview function you changed earlier:

 function CreateTopic () {     list($xanonpost,          $subject,          $comment,          $pid,          $sid,          $host_name,          $mode,          $order,          $thold,          $posttype,          $req) = pnVarCleanFromInput('xanonpost',                                           'subject',                                           'comment',                                           'pid',                                           'sid',                                           'host_name',                                           'mode',                                           'order',                                           'thold',                                           'posttype',                                           'req'); 

Add in the three new variables exactly as you did before, placing them before the subject references:

 function CreateTopic () {     list($xanonpost,          $aname,          $aemail,          $aurl,          $subject,          $comment,          $pid,          $sid,          $host_name,          $mode,          $order,          $thold,          $posttype,          $req) = pnVarCleanFromInput('xanonpost',                                           'aname',                                           'aemail',                                           'aurl',                                           'subject',                                           'comment',                                           'pid',                                           'sid',                                           'host_name',                                           'mode',                                           'order',                                           'thold',                                           'posttype',                                           'req'); 

The very last change assigns the new variables' content to the standard variables used to add content to the database. Scroll down to about line 1117 in CreateTopic() and find the following code:

 if (pnUserLoggedIn() && (!$xanonpost)) {     $uname = pnUserGetVar('uname');     $email = pnUserGetVar('femail');     $url   = pnUserGetVar('url');     $score = 1; } else {     $uname = "";     $email = "";     $url   = "";     $score = 0; } 

The first half of the statement takes the global user information available when a user is logged in and assigns it to variables in preparation for the database addition. The else sets the same variables to null values. You again change the second branch of the if statement with the following additions:

 if (pnUserLoggedIn() && (!$xanonpost)) {     $uname = pnUserGetVar('uname');     $email = pnUserGetVar('femail');     $url   = pnUserGetVar('url');     $score = 1; } else {     if ($aname != $anonymous) {        $uname = $aname;        $email = $aemail;        $url   = $aurl;     } else {        $uname = "";        $email = "";        $url   = "";     }     $score = 0; } 

The nested if ($aname != $anonymous) checks to see if the user entered his name or left the field with "Anonymous." If the former, then the regular name, email, and website variables are assigned the values from the new form fields. If the latter, the fields are left blank as they were in the original code. The score remains "0" for the second branch, just because there seems to be no reason to give an unregistered poster free points.

Figure 22.9 shows the results of the completed hack. The first post was done using a registered account. The email address is set to private and does not appear. The second comment was performed anonymously but with all fields completed. Now, anyone can visit your site and post their thoughts.

Figure 22.9. Public blog-style comments with identity fields.




    PostNuke Content Management
    PostNuke Content Management
    ISBN: 0672326868
    EAN: 2147483647
    Year: 2003
    Pages: 207
    Authors: Kevin Hatch

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net