Whats Related Editor

Wednesday, November 09 2005 @ 02:57 PM EST

Contributed by: tomw

After looking at whats needed for making What's Related editable, I decided to not make a plugin and instead just hack the core files. It ended up with only two small changes to the core files and a new file to edit the what's related entries.

What the changes do is add a link to the What's Related block for story editors entitled "Edit What's Related". The change for this is added to article.php.

Edit the story editor so that if the related block has something in it, then nothing is changed. If its empty then it is filled normally. This requires one addition/change to story.php.

Created a new admin file called related.php which is the editor for the What's Related entries.

The only change in functionality is that once the what's related links are created they are not refreshed on an edit.

Here is what I have done for those who are interested:

-------------------- Addition to article.php -----------------------------------
Right after (row 204 in 1.3.11)

$related = STORY_whatsRelated ($A['related'], $A['uid'], $A['tid']);
Add:

if (SEC_hasRights('story.edit')) {
$related = $related . '<li><a href="' . $_CONF['site_admin_url'] . '/related.php?story=' . $story . '">' . $LANG01[
}

-------------------------End of Addition to article.php ----------------------------

------------------------ Changes to story.php -------------------------------------
Replace: at Line 1130 in 1.3.11

//Get the related URLs

$related = addslashes (implode ("n",
STORY_extractLinks ("$introtext $bodytext")));

With:

if (empty($old_sid)) {
$rel_sid = $sid;
} else {
$rel_sid = $old_sid;
}
$rel_result = DB_query("SELECT related from WHERE sid = ''");
$relA = DB_fetchArray($rel_result);
$related = $relA['related'];
if (empty($related)) {
$related = addslashes (implode ("n",
STORY_extractLinks ("$introtext $bodytext")));

}

-------------- End Changes to story.php --------------------------------------

------------------------------- File related.php --------------------------------------------
<?php

/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.3 |
// +---------------------------------------------------------------------------+
// | related.php |
// | |
// | Geeklog group administration page. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2005 by the following authors: |
// | |
// | Authors: Tom Willett - tomw@pigstye.net |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | 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. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
//

/**
* This file is the Geeklog related administration page
*
* @author Tom Willett <tomw@pigstye.net>
*/

/**
* Geeklog common function library
*/
require_once ('../lib-common.php');

/**
* Verifies that current user even has access to the page to this point
*/
require_once ('auth.inc.php');

$display = '';
$story = $_GET['story'];
$mode = $_POST['Mode'];

// Make sure user has rights to access this page
if (!SEC_hasRights ('story.edit')) {
$display .= COM_siteHeader ('menu');
$display .= COM_startBlock ($MESSAGE[30], '',
COM_getBlockTemplate ('_msg_block', 'header'));
$display .= $MESSAGE[32];
$display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
$display .= COM_siteFooter ();
COM_accessLog ("User tried to illegally access the group administration screen.");
echo $display;
exit;
}

/**
* Shows the related editor form
*
* @param string $sid ID of story to edit
* @return string HTML for related editor
*
*/
function editrelated($sid = '')
{
global $_TABLES, $_CONF, $_USER, $LANG01, $LANG03, $LANG09, $LANG11, $LANG10, $LANG32;

$result = DB_query("SELECT title, related from " . $_TABLES['stories'] . " WHERE sid=''");
$A = DB_fetchArray($result);
$related = $A['related']; $rels = explode("n",stripslashes($related));
$retval = COM_startBlock ($LANG01[4] . ' ' . $LANG11[1], '',
COM_getBlockTemplate ('_msg_block', 'header'));
$retval .= '<p>' . $LANG10[8] . ': ' . $A['title'] . '</p>';
$retval .="<form method="post" action="/related.php?story=" enctype="application/x-www-for
$retval .= "<table border="0" cellpadding="4"><tr><th>" . $LANG03[16] . "</th><th>" . $LANG09[51] . "</th></tr>";
$i = 0;
foreach($rels as $rel) {
$match = array();
if (preg_match("/<a[s]+[^>]*?href[s]?=[s"']+(.*?)["']+.*?>([^<]+|.*?)?</a>/",$rel,$match)){
$retval .= '<tr><td><input type="text" size="25" name="title' . $i . '" value="' . $match[2] . '"></td>';
$retval .= '<td><input type="text" size="55" name="link' .$i . '" value="' . $match[1] . '"></td></tr>';
$i=$i+1;
} else { if (!empty($rel)) {
$retval .= '<tr><td>' . $rel . '</td><td></td></tr>';
}
} }

$retval .= '<tr><td><input type="text" size="25" name="title' . $i . '"></td>';
$retval .= '<td><input type="text" size="55" name="link' .$i . '"></td></tr>';
$retval .= '</table><p>';
$retval .= '<input type="submit" name="Mode" value="' . $LANG32[23] . '">';
$retval .= '<input type="submit" name="Mode" value="Return"></p></form>';
$retval .= '<p>&nbsp</p>';
$retval .= '<p>To delete an entry clear the Title field and save it.</p>';
$retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
return $retval;
}



/**
* Save related to the database
*
* @param string $story ID of story to save related
* @param string $related Data to save
* @return string HTML refresh or error message
*
*/
function saverelated ($story, $related)
{
global $_CONF, $_TABLES, $_USER, $LANG_ACCESS, $VERBOSE;

DB_query("UPDATE SET related = '$related' WHERE sid = '$story'");
}

// MAIN

if ($mode == $LANG32[23]) {
$i=0;
$related="";
$title = 'title' . $i; $$title = $_POST[$title];
while (isset($$title)) {
$link = 'link' . $i; $$link = $_POST[$link];
if ($$title <> "" ) { if ($related <> "") {
$related .= "n"; }
$related .='<a href="' . $$link . '">' . $$title . '</a>';
}
$i=$i+1;
$title = 'title' . $i;
$$title = $_POST[$title];
}
saverelated($story,addslashes($related));

$display = COM_siteHeader($LANG01[4] . ' ' . $LANG11[1]);
$display .= editrelated($story);
$display .= COM_siteFooter(); } elseif ($mode == 'Return') {
$display = COM_refresh($_CONF['site_url'] . "/article.php?story=$story");

} else {

$display = COM_siteHeader($LANG01[4] . ' ' . $LANG11[1]);
$display .= editrelated($story);
$display .= COM_siteFooter();
}

echo $display;

?>
--------------------- End File related.php --------------------------------------------

0 comments



http://gplugs.pigstye.net/article.php/20051109145720435