Description: Some of the users on our site wanted the option of hiding their stories from the story archive without deleting them and thereby losing all their reviews.
Requirements: Works in 3.2.1
Revision: 1 Apr 2007 - Added functionality for checking the validation status of a story and returning it to the original value (1 or 2), thanks to input from Tammy.
Modify stories.php:
Around Line 368: Insert the Hide/Unhide code between the Edit and Add New Chapter options..
// First, make sure the story is already validated so people can't self-validate by hiding/unhiding their story
if ($story['validated'] != "0") {
// Then, check the hide status of the story.
if ($story['validated'] != "H" && $story['validated'] != "I") {
// It's not currently hidden, so offer the chance to hide
$output .= "<a href=""stories.php?action=hide&sid=".$story['sid'"]."">"._HIDE."</a> - ";
} else {
// It's already hidden, offer the chance to unhide
$output .= "<a href=""stories.php?action=unhide&sid=".$story['sid'"]."">"._UNHIDE."</a> - ";
}
}
Insert the hide and unhide functions after the delete function, around line 854:
function hide() {
global $tableprefix, $tpl, $store, $storiespath, $useruid, $admin, $sid, $chapid, $logging;
// Hide functionality
$valq = dbquery("SELECT validated FROM ".$tableprefix."fanfiction_stories WHERE sid = '".$sid."'");
list($valstat) = dbrow($valq);
if ( $valstat == "2") {
dbquery("UPDATE ".$tableprefix."fanfiction_stories SET validated = 'I' WHERE sid = '$sid'");
} else {
dbquery("UPDATE ".$tableprefix."fanfiction_stories SET validated = 'H' WHERE sid = '$sid'");
}
return "<center>"._ACTIONSUCCESSFUL."</center><a href=""stories.php?action=viewstories">return</a>";"
}
// end hide
function unhide() {
global $tableprefix, $tpl, $store, $storiespath, $useruid, $admin, $sid, $chapid, $logging;
// Unhide functionality
$valq = dbquery("SELECT validated FROM ".$tableprefix."fanfiction_stories WHERE sid = '".$sid."'");
list($valstat) = dbrow($valq);
if ( $valstat == "I") {
// Unhide functionality for "trusted story"
dbquery("UPDATE ".$tableprefix."fanfiction_stories SET validated = '2' WHERE sid = '".$sid."'");
} else {
// Unhide functionality for "untrusted story"
dbquery("UPDATE ".$tableprefix."fanfiction_stories SET validated = '1' WHERE sid = '".$sid."'");
}
return "<center>"._ACTIONSUCCESSFUL."</center><a href=""stories.php?action=viewstories">return</a>";"
}
// end unhide
And add hide and unhide to the case statement, somewhere before the "default" line.
case "hide":
$output .= hide($sid);
break;
case "unhide":
$output .= unhide($sid);
break;
Then, to make sure it's hidden from people's favorite stories list, as well, modify user/favst.php.
At around line 84 (this is all one line, cropped here to make it easier to read):
$storyquery = "SELECT stories.*, "._PENNAMEFIELD." as penname, fav.comments as comments,
UNIX_TIMESTAMP(stories.date) as date, UNIX_TIMESTAMP(stories.updated) as updated FROM
".$tableprefix."fanfiction_stories as stories, ".$tableprefix."fanfiction_favorites as
fav, "._AUTHORTABLE." WHERE fav.uid = '$uid' AND fav.type = 'ST' AND stories.uid = "
._UIDFIELD." AND stories.validated <> 'H' AND stories.validated <> 'I'
AND fav.item = stories.sid "._ORDERBY;
Finally, in languages/en.php, add the following lines:
define ("_HIDE", "Hide");
define ("_UNHIDE", "Unhide");
If you can think of anything I've missed regarding this mod, or if you have ideas or suggestions, please let me know.
Thank you!
Why don't you make it into a module so people don't have to modify their files?
Why don't you make it into a module so people don't have to modify their files?
Umm... because I've been mucking about with PHP for just a few months and don't know exactly what you mean by that? π Is a module a script that modifies the code when run? I'm sorry, I thought "MOD" was short for modification, not module. π
Could you perhaps add to your instructions precisely where the inserts will go please? I just had a look at my stories.php and there was no way i could clearly see the parts i needed
something perhaps like:
find this:
if($reviewsallowed) $output .= ($story['reviews'] ? "<a href=""reviews.php?type=ST&item=".$story['sid'"]."">".$story['reviews']."</a>" : "0");
if(!$autovalidate) $output .= "</td><td class="tblborder" align="center">".($story['validated'] > 0 ? _YES : _NO);
$output .= "</td><td class="tblborder" align="center">".($story['count'] ? $story['count'] : "0")."</td></tr>";
add this code after
your new code
and before this
if($hidechapters && $hidechapters != "hide") {
while($chapter = dbassoc($query2)) {
$output .="<tr><td class="tblborder"> <a href=""viewstory.php?sid=".$story['sid'"]."&chapter=".$chapter['inorder']."">$chapter[title]</a></td>";
that is the code in my stories.php around line 368 and i havent really got a clue where exactly i should insert your code, so we can see exactly what it should be inserted between.
this is a mod that I am very interested in and have had a few requests from members so it is extremely exciting to see you have done one.
thanks very much
jacci
why is nothing ever easy?
url: http://www.pretendercentre.com/missingpieces/
php: 5.2.5 msql: 5.0.45-community
efic version: 3.4.3 latest patches: yes
bridges: none mods: challenges, displayword, beta-search
Sure. I hope this helps. The code for the hide options is in the "viewstories" function of stories.php. Here are the surrounding lines.
I've added hard returns here to make it easier to read.
while($story = dbassoc($sresult)) {
$query2 = dbquery("SELECT chapid, title, inorder, rating, reviews, validated, count FROM ".$tableprefix."fanfiction_chapters WHERE sid = '".$story['sid']
."' ORDER BY inorder");
$chapters = dbnumrows($query2);
$output .= "<tr><td class="tblborder"><a href=""viewstory.php?sid=".$story['sid'"]."">".stripslashes($story['title'])."</a> ".ratingpics($story['rating'])
." <strong>"._COMPLETE.":</strong> <a href=""stories.php?action=viewstories&sid=".$story['sid'"]."&com=".$story['completed']."">
<a href=""stories.php?action=viewstories&sid=".$story['sid'"]."&com=".($story['completed'] == 1 ? "no">"._YES : "yes">"._NO)."</a></td>
<td class="tblborder" colspan="3"><a href=""stories.php?action=editstory&sid=".$story['sid'"]."">"._EDIT."</a> -
<a href=""stories.php?action=delete&sid=".$story['sid'"]."">"._DELETE."</a> - ";
// MOD START
if ($story['validated'] != "0") {
if ($story['validated'] != "H" && $story['validated'] != "I") {
// Not currently hidden
$output .= "<a href=""stories.php?action=hide&sid=".$story['sid'"]."">"._HIDE."</a> - ";
} else {
$output .= "<a href=""stories.php?action=unhide&sid=".$story['sid'"]."">"._UNHIDE."</a> - ";
}
}
// MOD END
$output .= "<a href=""stories.php?action=newchapter&sid=".$story['sid'"]."&inorder=$chapters">"._ADDNEWCHAPTER."</a></td>
<td class="tblborder" align="center">";
And then in user/favst.php:
else if(!isset($_POST['submit'])) {
// MOD ADD
// $storyquery = "SELECT stories.*, "._PENNAMEFIELD." as penname, fav.comments as comments, UNIX_TIMESTAMP(stories.date) as date,
UNIX_TIMESTAMP(stories.updated) as updated FROM ".$tableprefix."fanfiction_stories as stories, ".$tableprefix."fanfiction_favorites as fav,
"._AUTHORTABLE." WHERE fav.uid = '$uid' AND fav.type = 'ST' AND stories.uid = "._UIDFIELD." AND fav.item = stories.sid "._ORDERBY;
$storyquery = "SELECT stories.*, "._PENNAMEFIELD." as penname, fav.comments as comments, UNIX_TIMESTAMP(stories.date) as date,
UNIX_TIMESTAMP(stories.updated) as updated FROM ".$tableprefix."fanfiction_stories as stories, ".$tableprefix."fanfiction_favorites as fav,
"._AUTHORTABLE." WHERE fav.uid = '$uid' AND fav.type = 'ST' AND stories.uid = "._UIDFIELD." AND stories.validated <> 'H'
AND stories.validated <> 'I' AND fav.item = stories.sid "._ORDERBY;
// MOD END
As you can see, in favst.php I did not replace the original line, I commented it out so it would be quick to go back, if necessary. The modification is on the uncommented line.
thanks i am going to give this a whirl when i can pluck up the courage to mess with those files.
jacci
why is nothing ever easy?
url: http://www.pretendercentre.com/missingpieces/
php: 5.2.5 msql: 5.0.45-community
efic version: 3.4.3 latest patches: yes
bridges: none mods: challenges, displayword, beta-search
Just a warning. If you validate a story to "story" instead of "chapter" when an author hides the story then unhides it, this will cause the validation to be "chapter" instead of "story".
thanks i am going to give this a whirl when i can pluck up the courage to mess with those files.
jacci
Save a copy of the original file. π
Just a warning. If you validate a story to "story" instead of "chapter" when an author hides the story then unhides it, this will cause the validation to be "chapter" instead of "story".
I'm not sure I'm following that. I guess I don't understand the difference. In the SQL tables, validation is either "0" for unvalidated or "1" for validated. I don't see anything about setting validation to "chapter" or "story". Please explain more.
I'm not sure I'm following that. I guess I don't understand the difference. In the SQL tables, validation is either "0" for unvalidated or "1" for validated. I don't see anything about setting validation to "chapter" or "story". Please explain more.
It's 0, 1, or 2 in the database.
0 = not validated.
1 = validated to the current chapter. New chapters must be validated by the admin.
2 = validated for entire story. New chapters are automatically valid.
You must edit the story to select the "story" (2) validation.
I see. So if I understand correctly, I should add an additional check in the "Unhide" function that checks if the author is "trusted" (new submissions are automatically validated) or not and set the validation code accordingly. If the author is "trusted", set the story's validation number to "2" when un-hiding, otherwise "1".
Don't worry, i always save copy of the origingal, my coding skills are... rudimentary and i am likely to screw it up, so backup is my friend. π
why is nothing ever easy?
url: http://www.pretendercentre.com/missingpieces/
php: 5.2.5 msql: 5.0.45-community
efic version: 3.4.3 latest patches: yes
bridges: none mods: challenges, displayword, beta-search
I see. So if I understand correctly, I should add an additional check in the "Unhide" function that checks if the author is "trusted" (new submissions are automatically validated) or not and set the validation code accordingly. If the author is "trusted", set the story's validation number to "2" when un-hiding, otherwise "1".
No, the 2 validation is totally separate from a trusted author. You need to save whether or not the story is a 2 or a 1. Probably by changing the H to H1 and H2.
Don't worry, i always save copy of the origingal, my coding skills are... rudimentary and i am likely to screw it up, so backup is my friend. π
Amen! I am so glad our site admin has a test site for me to break... I mean, improve... yes, improve.
No, the 2 validation is totally separate from a trusted author. You need to save whether or not the story is a 2 or a 1. Probably by changing the H to H1 and H2.
Sadly, the validation field in the stories table is a single-character field (char(1)). My original plan for the mod was to make hidden stories = -1, but that's two characters as well. I could modify the field in the database to 2 characters, or make it numeric rather than character, but people tend to get really nervous when you start making changes to the database structure. I'd have really liked going the negative route, because then when you're doing the part where you hide the stories from people's favorites, you could pull only stories whose validation number is > 0. Hidden stories whose validation was 1 could now be -1 when hidden, and those with 2 would be -2 when hidden.
As it is, without modifying the database, I could introduce a second single character value, like "I" for stories whose validation was 2. That would be in the "Hide" function, and then "Unhide" would look at whether the validation is "H" or "I" and return the value to "1" or "2".
I'll be back soon with the modified code. Thank you so much for your assistance! It's a lot easier to do these things when you have other people to bounce ideas off of. π
EDIT: New code inserted in original post, along with a note about the revision. Thank you again!
*interested*
Does this work for 3.3.1?
archive:
site:
Available for skin/mod commission! π
I am interested too. The module though seems like a better option for trying it out without messing with the files. I would like that.
I charge into the light and need only yours to find my way. Archive of One:
