18.8. Modifying the PHP-Nuke Submit News module

Figure 18-10. Administration panel: Submissions.

Administration panel: Submissions.

In this section we modify the PHP-Nuke Submit News module:

18.8.1. How to bypass article approval

The standard workflow for a news article is that the user writes it, submits it for approval by the administrator, the administrator reads it, approves and publishes it on the site. This has some advantages:

But it also has some disadvantages too:

Figure 18-11. Waiting Content block.

Waiting Content block.

Fortunately, to bypass article approval, the solution is relatively simple (see Automatic Article Posting):

You will also want to change the language file "defines", or edit these lines in the function submitStory (this is what is displayed when the submission is sent.

echo "<center><font class=\"title\">"._SUBSENT."</font><br><br>"
."<font class=\"content\"><b>"._THANKSSUB."</b><br><br>"
.""._SUBTEXT.""
."<br>"._WEHAVESUB." $waiting "._WAITING."";

18.8.1.1. The formatAidHeader() function

If you want to make the “Posted By Some_user” also be a link to the User's profile, then you can edit the function formatAidHeader in your mainfile.php. The following refers to PHP-Nuke 6.5 and above.

The function is simple: it takes an argument, the author id $aid, searches the nuke_authors table for that author id and, if found, it prints a link to the web page of the author. Only if the web page link fiels of nuke_authors is empty for that author, it prints a link to the author's e-mail (which is always there):

function formatAidHeader($aid) {
    global $prefix, $db;
    $sql = "SELECT url, email FROM ".$prefix."_authors WHERE aid='$aid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $url = $row[url];
    $email = $row[email];
    if (isset($url)) {
        $aid = "<a href=\"$url\">$aid</a>";
    } elseif (isset($email)) {
        $aid = "<a href=\"mailto:$email\">$aid</a>";
    } else {
        $aid = $aid;
    }
    echo "$aid";
}

You could easily change this behaviour. For example, you could take out the check against the $url and leave only the e-mail part, if you wanted the “Posted By Some_user” to be an e-mail link, rather than a link to a web page (see Change Posted by... Name (Website) to Name (Email)):

function formatAidHeader($aid) {
    global $prefix, $db;
    $sql = "SELECT url, email FROM ".$prefix."_authors WHERE aid='$aid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $url = $row[url];
    $email = $row[email];
     if (isset($email)) {
        $aid = "<a href=\"mailto:$email\">$aid</a>";
    } else {
        $aid = $aid;
    }
    echo "$aid";
}

You could make it even more sophisticated, by making “Posted By Some_user” a link to the user's profile (see Section 18.6.2 for the related subject of user profile redirection). The formatAidHeader function should then be:

function formatAidHeader($aid) { 
    global $prefix, $db;
    $sql = "SELECT url, email FROM ".$prefix."_authors WHERE aid='$aid'";
    $result = $db->sql_query($sql);
    if($row = $db->sql_fetchrow($result)) {
        $url = $row[url]; 
        $email = $row[email]; 
        if (isset($url)) { 
            $aid = "<a href=\"$url\">$aid</a>";
        } elseif (isset($email)) {  
            $aid = "<a href=\"mailto:$email\">$aid</a>"; 
        } else {
            $aid = $aid;
        } 
   }else {
        $sql = "SELECT user_id FROM ".$prefix."_users WHERE username='$aid'"; 
        $result = $db->sql_query($sql); 
        $row = $db->sql_fetchrow($result);
        $user_id = $row[user_id];
        $aid = "<a
        href=\"modules.php?name=Forums&file=profile
&mode=viewprofile&u=$user_id\">$aid</a>";
    }
    echo "$aid"; 
}