I would like to adjust my "Featured Story" block to be a "Featured Recommendation" block pointing toward Tammy's module, but I'm a little unsure of where to start. I was hoping that it would be as simple as changing something in the tables of my sql database, but that does not appear to be the case. How do I force the block to look at the fanfiction_recommendations table rather than the fanfiction_stories table?
A similar post was made on a previous thread ( https://efiction.org/forums/index.php?topic=5966.0 ), but there were no real answers (at least that I could use).
I suspect I need to change some things in "blocks/featured/featured.php":
<?php
// ----------------------------------------------------------------------
// eFiction 3.2
// Copyright (c) 2007 by Tammy Keefer
// Valid HTML 4.01 Transitional
// Based on eFiction 1.1
// Copyright (C) 2003 by Rebecca Smallwood.
// http://efiction.sourceforge.net/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
if(!defined("_CHARSET")) exit( );
if(!defined("_CHARSET")) exit( );
$content = "";
$count = 0;
$limit = isset($blocks['featured']['limit']) ? $blocks['featured']['limit'] : false;
$use_tpl = isset($blocks['featured']['tpl']) && $blocks['featured']['tpl'] ? true : false;
$query = dbquery(_STORYQUERY." AND stories.featured = '1'".($limit ? " LIMIT $limit" : ""));
while($stories = dbassoc($query))
{
if(!isset($blocks['featured']['allowtags'])) $stories['summary'] = strip_tags($stories['summary']);
$stories['summary'] = truncate_text(stripslashes($stories['summary']), (isset($blocks['featured']['sumlength']) ? $blocks['featured']['sumlength'] : 75));
if(!$use_tpl) $content .= "<div class='featuredstory'>".title_link($stories)." "._BY." ".author_link($stories)." ".$ratingslist[$stories['rid']]['name']."<br />".$stories['summary']."</div>";
else {
$tpl->newBlock("featuredblock");
include(_BASEDIR."includes/storyblock.php");
}
}
if($use_tpl && dbnumrows($query) > 0) $tpl->gotoBlock("_ROOT");
?>
What do I need to change? And is this the only file that needs adjustment? Suggestions? I can't be the only person who has wanted to do this. π³
You don't have to change merely that. You also have to change the block's admin.php (which in this case creates the Admin > Blocks > Options choices of summary length and strip tags and so on) but especially its init.php (which installs into fanfiction_blocks the necessary info to make the block work).
So anywhere it says 'featured' you'd need to change that to something else. Most of the block is concerned with the admin options. Here's what looks like where it pulls the stories to be featured.
$query = dbquery(_STORYQUERY." AND stories.featured = '1'".($limit ? " LIMIT $limit" : ""));
So you would have to add a featured field to the fanfiction_recommendations.
You may also have to change includes/storyblock.php if this works out to be true.
else {
$tpl->newBlock("featuredblock");
include(_BASEDIR."includes/storyblock.php");
}
I'd suggest making sure the first part of that if statement is true so you don't have to worry about that.
I have been thinking of trying something like this but haven't gotten around to it. I run an eFiction based site (currently down) that is 100% recommendations.
And that's just the block. You'd have to do something completely else if you want a "featured recommendations" section on the browse page, to show the active and retired like it does with featured stories.
I will perhaps try to experiment with this sometime in the coming week.
You'd also need to edit the database itself as there's no field in the recommendations table to store featured status for a recommendation.
You'd also need to edit the database itself as there's no field in the recommendations table to store featured status for a recommendation.
But there is. That's what sort of made me want to add a featured recommendation block. For a bit there I thought the featured story block would read the featured recommendations, but no go. Still have the pretty blue flag by the story title, though. π
Ahh. It's been a while since I looked at that. There's probably more to it than just this, but the first step would be to have the query point to the recommendations table and not the stories table.
There's probably more to it than just this, but the first step would be to have the query point to the recommendations table and not the stories table.
Can you tell me where the code points to the table? I'm thinking I need to change something here, in featured.php:
$query = dbquery(_STORYQUERY." AND stories.featured = '1'".($limit ? " LIMIT $limit" : ""));
while($stories = dbassoc($query))
Is that right? I'm not very familiar with sql, obviously, so I'm a little uncertain.
Well, stories.featured should probably be recommendations.featured. Also _STORYQUERY should be changed. It might be helpful to find where _STORYQUERY is defined (stories.php maybe?) but I think it's probably just a select for the stories table.
The while statement is the beginning of the rest that follows in the curly braces. I think you'd need to change $stories (to like $recommendations). Same with all the stuff in the curly braces. Call it whatever you want, then later when it's like $recommendations['summary'] (or the recommender's comments, or whatever field you like) it will be using the $query defined just above. You might actually be okay not renaming $stories at all, but it's probably better to do it.
You'll also want to change all these: $blocks['featured'] to something like $blocks['featuredrecs']. Change init.php to match so it names the block 'featuredrecs' or whatever you wish to call it. As long as they match and are not 'featured'.
Also _STORYQUERY should be changed. It might be helpful to find where _STORYQUERY is defined (stories.php maybe?) but I think it's probably just a select for the stories table.
I found this defined in includes/queries.php
define ("_STORYQUERY", "SELECT stories.*, "._PENNAMEFIELD." as penname, UNIX_TIMESTAMP(stories.date) as date, UNIX_TIMESTAMP(stories.updated) as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 ");
and added another line to queries.php that looks like this:
define ("_RECOMENDATIONQUERY", "SELECT recommendations.*, "._PENNAMEFIELD." as penname, UNIX_TIMESTAMP(recomendations.date) as date, UNIX_TIMESTAMP(recommendations.updated) as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_recommendations as recommendations) WHERE "._UIDFIELD." = recommendations.uid AND recommendations.validated > 0 ");
- Now, first do I need to do something with "._PENNAMEFIELD." as penname?
- Second, should I be deleting UNIX_TIMESTAMP(recommendations.updated), since there is no "updated" field in the table of the database?
- Third, is it right to use "._AUTHORTABLE."?
- Fourth, do I even need all of this bits defined to get this to work?
I figure I need to determine how this works before trying to alter featured.php...
You don't need to define it there. You can just edit the query in the block itself to be the query. I defined the story query in the includes because eFiction needs that in a huge number of places so it was easier to put it in one place and then that definition everywhere else. You will need to remove the updated field and the author information. You can probably lift the query from the browse page in the recommendations module that pulls the recommendation info.
You can probably lift the query from the browse page in the recommendations module that pulls the recommendation info.
Awesome. I shall try this. π
Cool. Look what you accomplished while all I did was take a nap. ; )
I forgot to mention that you'll also want to change the instances of $blocks['featured'] in the block's admin.php to whatever you're going to call the block. Otherwise they won't match up and you'd be editing the Featured block and not the Featured Recs. Especially because of this you've got to make it standard across the board:
$blockquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_blocks WHERE block_name = 'featured'");
block_name is defined in init.php (which installs the block info into the database).
dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_blocks(`block_name`, `block_title`, `block_status`, `block_file`, `block_variables`) VALUES('featured', 'Featured Stories', '0', 'featured/featured.php', '');");
For the most part this is the stuff that can be changed in the Admin > Blocks (or skin's variables.php file). The block_name is what becomes {blockname_title} for the skin variable (where 'blockname' equals whatever you've set block_name to). And in case you're curious the corresponding for {blockname_content} is whatever you set $content to in the main file (in this case, featured.php). The featured block works a little differently than some with the $content =""; so I thought you might like to know that. It was most of the work on the block I built to get $content where I needed it to be.
The block is complete. Version 1.0 will be posted shortly.
