Description: Adds a banner field for stories and outputs them on the Table of Contents and listings IF the person has toggled to show them.
Requirements: min. eFic 3.5.1
Mod History: 2010-04-15: released
File edits: stories.php, user/editprefs.php, includes/get_session_vars.php
Instructions: Please back-up your database and files before using this mod! If you want to revert back, you will have to delete/reverse the MySQL changes.
Notes: It is recommended that you do this in a test environment first to check that it's working OK. π I've literally posted this at 1am straight after thinking it through and implementing.
1. MySQL table changes
(Please remember to add prefixes.)
Add a bannerurl to the stories table:
ALTER TABLE fanfiction_stories ADD COLUMN bannerurl varchar (255) ;
Add a showbanners to the prefs table:
ALTER TABLE fanfiction_authorprefs ADD COLUMN showbanners int(1) ;
Add the input field in the story form:
INSERT INTO fanfiction_codeblocks (code_text, code_type, code_module) VALUES ('$bannerurl = $stories['bannerurl'];
$output .= "<br /><label for=\"bannerurl\">Story Banner URL: </label> <input type=\"text\" class=\"textbox\" name=\"bannerurl\" id=\"bannerurl\"".($bannerurl ? " value=\"".htmlentities($bannerurl)."\"" : "")."/><hr />";', 'storyform', 'storybanners')
Add the {banner} in the story block:
INSERT INTO `dramione_archive`.`fanfiction_codeblocks` (`code_id`, `code_text`, `code_type`, `code_module`) VALUES (NULL, '$tpl->assign("banner", $stories["bannerurl"] && _USERALLOWBANNERS ? "<div class=\"banner\"><img src="\"$stories[bannerurl"]\" alt=\"$stories[title]\" /></div>" : "");', 'storyblock', 'storybanners');
2. includes/get_session_vars.php
Find:
define("USERUID", $userdata['uid']);
Add after:
define("_USERALLOWBANNERS", $userdata['showbanners']);
(This appears twice, so do it both times.)
Find:
if(!defined("USERUID")) define("USERUID", 0);
Add after:
if(!defined("_USERALLOWBANNERS")) define ("_USERALLOWBANNERS", 0);
3. user/editprefs.php
Find:
$useralertson = isset($_POST['useralertson']) && $_POST['useralertson'] == "on" ? 1 : 0;
Add below:
$showbanners = isset($_POST['showbanners']) && $_POST['showbanners'] == "on" ? 1 : 0;
In the UPDATE query, find:
sortby = '$sortby',
Replace with:
sortby = '$sortby', showbanners = '$showbanners'
Find:
$output .= "<label>"._DISPLAYINDEX." <input name="storyindex" type="checkbox" class="checkbox"".($user['storyindex'] ? " checked" : "")."></label><a href=""#"" class="pophelp">[?]<span>"._HELP_TOC."</span></a><br />";
Add:
$output .= "<label>Show Story Banners: <input name="showbanners" type="checkbox" class="checkbox"".($user['showbanners'] ? " checked" : "")."/></label><a href=""#"" class="pophelp">[?]<span>If you want to see story banners, tick this box.</span></a><br />";
(You might want to change "Show Story Banners" to a constant.)
4. stories.php
After:
include("includes/storyform.php");
Add:
function imgurl_exists($url) {
if(@file_get_contents($url,0,NULL,0,1)){return 1;}else{ return 0;}
}
(This hasn't been tested fully yet, so it might be replaced by something else soon.)
Find the newstory() function. In it, find:
$title = isset($_POST['title']) ? descript(strip_tags($_POST['title'], $allowed_tags)) : "";
Add below:
$bannerurl = isset($_POST['bannerurl']) && imgurl_exists($_POST['bannerurl']) ? $_POST['bannerurl'] : "";
Find:
$insert = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stories (title, summary, storynotes, catid, classes, charid, rid, date, updated, uid, validated, rr, completed, wordcount, featured, coauthors) VALUES ('".addslashes($title)."', '".addslashes(format_story($summary))."', '".addslashes(format_story($storynotes))."', '".($catid ? implode(",", $catid) : "")."', '".($classes? implode(",", $classes) : "")."', '".($charid ? implode(",", $charid) : "")."', '$rid', now(), now(), '$uid', '$validated', '$rr', '$complete', '$wordcount', '$feat', '$coauthors')");
Replace with:
#$insert = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stories (title, summary, storynotes, catid, classes, charid, rid, date, updated, uid, validated, rr, completed, wordcount, featured, coauthors) VALUES ('".addslashes($title)."', '".addslashes(format_story($summary))."', '".addslashes(format_story($storynotes))."', '".($catid ? implode(",", $catid) : "")."', '".($classes? implode(",", $classes) : "")."', '".($charid ? implode(",", $charid) : "")."', '$rid', now(), now(), '$uid', '$validated', '$rr', '$complete', '$wordcount', '$feat', '$coauthors')");
$insert = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stories (title, summary, storynotes, catid, classes, charid, rid, date, updated, uid, validated, rr, completed, wordcount, featured, coauthors, bannerurl) VALUES ('".addslashes($title)."', '".addslashes(format_story($summary))."', '".addslashes(format_story($storynotes))."', '".($catid ? implode(",", $catid) : "")."', '".($classes? implode(",", $classes) : "")."', '".($charid ? implode(",", $charid) : "")."', '$rid', now(), now(), '$uid', '$validated', '$rr', '$complete', '$wordcount', '$feat', '$coauthors', '$bannerurl')");
Find:
$insertstory = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stories (title, summary, storynotes, catid, classes, charid, rid, date, updated, uid, validated, rr, completed, wordcount, featured, coauthors) VALUES ('".addslashes($title)."', '".addslashes(format_story($summary))."', '".addslashes(format_story($storynotes))."', '".($catid ? implode(",", $catid) : "")."', '".($classes ? implode(",", $classes) : "")."', '".($charid ? implode(",", $charid) : "")."', '$rid', now(), now(), '$uid', '$validated', '$rr', '$complete', '$wordcount', '$feat', '$coauthors')");
Replace with:
#$insertstory = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stories (title, summary, storynotes, catid, classes, charid, rid, date, updated, uid, validated, rr, completed, wordcount, featured, coauthors) VALUES ('".addslashes($title)."', '".addslashes(format_story($summary))."', '".addslashes(format_story($storynotes))."', '".($catid ? implode(",", $catid) : "")."', '".($classes ? implode(",", $classes) : "")."', '".($charid ? implode(",", $charid) : "")."', '$rid', now(), now(), '$uid', '$validated', '$rr', '$complete', '$wordcount', '$feat', '$coauthors')");
$insertstory = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stories (title, summary, storynotes, catid, classes, charid, rid, date, updated, uid, validated, rr, completed, wordcount, featured, coauthors, bannerurl) VALUES ('".addslashes($title)."', '".addslashes(format_story($summary))."', '".addslashes(format_story($storynotes))."', '".($catid ? implode(",", $catid) : "")."', '".($classes ? implode(",", $classes) : "")."', '".($charid ? implode(",", $charid) : "")."', '$rid', now(), now(), '$uid', '$validated', '$rr', '$complete', '$wordcount', '$feat', '$coauthors', '$bannerurl')");
Find the editstory() function. In it, find:
$title = isset($_POST['title']) ? strip_tags(descript($_POST['title']), $allowed_tags) : "";
Add below:
$bannerurl = isset($_POST['bannerurl']) && imgurl_exists($_POST['bannerurl']) ? $_POST['bannerurl'] : "";
Find:
$updatequery = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET title = '".addslashes($title)."', summary = '".addslashes(format_story($summary))."', storynotes = '".addslashes(format_story($storynotes))."', rr = '".($rr ? 1 : 0)."', completed = '".($complete ? 1 : 0)."', validated = '$validated', rid = '$rid', classes = '".(is_array($classes) ? implode(",", $classes) : $classes)."', charid = '".(is_array($charid) ? implode(",", $charid) : $charid)."', catid = '".(is_array($catid) ? implode(",", $catid) : $catid)."', coauthors = '".(is_array($coauthors) ? implode(",", $coauthors) : $coauthors)."', featured = '$feat' WHERE sid = '$sid'");
Replace with:
#$updatequery = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET title = '".addslashes($title)."', summary = '".addslashes(format_story($summary))."', storynotes = '".addslashes(format_story($storynotes))."', rr = '".($rr ? 1 : 0)."', completed = '".($complete ? 1 : 0)."', validated = '$validated', rid = '$rid', classes = '".(is_array($classes) ? implode(",", $classes) : $classes)."', charid = '".(is_array($charid) ? implode(",", $charid) : $charid)."', catid = '".(is_array($catid) ? implode(",", $catid) : $catid)."', coauthors = '".(is_array($coauthors) ? implode(",", $coauthors) : $coauthors)."', featured = '$feat' WHERE sid = '$sid'");
$updatequery = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET title = '".addslashes($title)."', summary = '".addslashes(format_story($summary))."', storynotes = '".addslashes(format_story($storynotes))."', rr = '".($rr ? 1 : 0)."', completed = '".($complete ? 1 : 0)."', validated = '$validated', rid = '$rid', classes = '".(is_array($classes) ? implode(",", $classes) : $classes)."', charid = '".(is_array($charid) ? implode(",", $charid) : $charid)."', catid = '".(is_array($catid) ? implode(",", $catid) : $catid)."', coauthors = '".(is_array($coauthors) ? implode(",", $coauthors) : $coauthors)."', featured = '$feat', bannerurl = '$bannerurl' WHERE sid = '$sid'");
5. storyindex.tpl and listings.tpl
In your desired skin, use {banner} in storyindex.tpl/listings.tpl to output the image. The banner has a CSS class: .banner. π
End!
archive:
site:
Available for skin/mod commission! π
You have no checks on the file itself to see if it's a valid image file. This may make your site vulnerable to attack.
http://hungred.com/how-to/php-check-remote-email-url-image-link-exist/ ?
ETA: k that's not fool-proof either.
ETA 2: http://stackoverflow.com/questions/1363925/check-whether-image-exists-on-remote-url
I'm not familiar with cURL. All I know is that sometimes it doesn't let people submit certain words?
archive:
site:
Available for skin/mod commission! π
A lot of times CURL is disabled. I wouldn't count on being able to use it. Ideally, you'd probably want to make them use the image upload feature and then have them select from a drop down. This would let you check the file for scripting. As a bonus it would also let you control the size of the banners so people didn't upload huge ones and break your site layouts.