Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: adaur/fluxrewrite-essentials
base: 13c71f21df
...
head fork: adaur/fluxrewrite-essentials
compare: 882b1cd4d4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 275 additions and 35 deletions.
  1. +84 −8 ReadMe.txt
  2. +32 −27 files/include/fluxrewrite.php
  3. +159 −0 files/install_mod.php
View
92 ReadMe.txt
@@ -37,6 +37,18 @@
#
+#---------[ 1. UP & RUN ]-------------------------------------------------------------------------------
+#
+
+install_mod.php
+
+#
+#---------[ 2. DELETE ]----------------------------------------------------------------------------
+#
+
+install_mod.php
+
+#
#---------[ 1. OPEN ]-------------------------------------------------------
#
@@ -131,6 +143,60 @@ function confirm_referrer($script, $error_msg = false)
}
#
+#---------[ 2. FIND ]----------------------------------------------------
+#
+
+//
+// Update posts, topics, last_post, last_post_id and last_poster for a forum
+//
+function update_forum($forum_id)
+{
+ global $db;
+
+ $result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
+ list($num_topics, $num_posts) = $db->fetch_row($result);
+
+ $num_posts = $num_posts + $num_topics; // $num_posts is only the sum of all replies (we have to add the topic posts)
+
+ $result = $db->query('SELECT last_post, last_post_id, last_poster FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
+ if ($db->num_rows($result)) // There are topics in the forum
+ {
+ list($last_post, $last_post_id, $last_poster) = $db->fetch_row($result);
+
+ $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.$db->escape($last_poster).'\' WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
+ }
+ else // There are no topics
+ $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post=NULL, last_post_id=NULL, last_poster=NULL WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
+}
+
+#
+#---------[ 4. REPLACE WITH ]------------------------------------------------
+#
+
+//
+// Update posts, topics, last_post, last_post_id and last_poster for a forum
+//
+function update_forum($forum_id)
+{
+ global $db;
+
+ $result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
+ list($num_topics, $num_posts) = $db->fetch_row($result);
+
+ $num_posts = $num_posts + $num_topics; // $num_posts is only the sum of all replies (we have to add the topic posts)
+
+ $result = $db->query('SELECT last_post, last_post_id, last_poster, subject, id, num_replies FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
+ if ($db->num_rows($result)) // There are topics in the forum
+ {
+ list($last_post, $last_post_id, $last_poster, $last_topic, $last_topic_id, $num_replies) = $db->fetch_row($result);
+
+ $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', num_replies='.$num_replies.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.$db->escape($last_poster).'\', last_topic=\''.$db->escape($last_topic).'\', last_topic_id='.$last_topic_id.' WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $db->error());
+ }
+ else // There are no topics
+ $db->query('UPDATE '.$db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post=NULL, last_post_id=NULL, last_poster=NULL, last_topic=NULL, last_topic_id=NULL, num_replies=NULL WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster/last_topic', __FILE__, __LINE__, $db->error());
+}
+
+#
#---------[ 8. OPEN ]---------------------------------------------------------
#
@@ -146,8 +212,20 @@ $forum_field = '<h3><a href="viewforum.php?id='.$cur_forum['fid'].'">'.pun_htmls
#---------[ 10. REPLACE BY ]-------------------------------------------------
#
-$forum_field = '<h3><a href="'.makeurl("forum-", $cur_forum['fid'], $cur_forum['forum_name'], false, false, true).'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a>'.(!empty($forum_field_new) ? ' '.$forum_field_new : '').'</h3>';
+$forum_field = '<h3><a href="'.makeurl("forum-", $cur_forum['fid'], $cur_forum['forum_name'], 1, false, false).'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a>'.(!empty($forum_field_new) ? ' '.$forum_field_new : '').'</h3>';
+
+#
+#---------[ 11. FIND ]---------------------------------------------
+#
+
+f.last_poster
+
+#
+#---------[ 12. ADD AFTER ]-------------------------------------------------
+#
+, f.last_topic, f.last_topic_id, f.num_replies
+
#
#---------[ 11. FIND ]---------------------------------------------
#
@@ -162,10 +240,8 @@ $forum_field = '<h3><a href="'.makeurl("forum-", $cur_forum['fid'], $cur_forum['
if ($cur_forum['last_post'] != '')
{
$num_pages_topic = ceil(($cur_forum['num_replies'] + 1) / $pun_user['disp_posts']);
- $last_post = '<a href="'.makeurl("topic-", $cur_forum['last_topic_id'], $cur_forum['last_topic'], false, $cur_forum['last_post_id'], false).'">'.format_time($cur_forum['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_forum['last_poster']).'</span>';
+ $last_post = '<a href="'.makeurl("topic-", $cur_forum['last_topic_id'], $cur_forum['last_topic'], $num_pages_topic, false, $cur_forum['last_post_id']).'">'.format_time($cur_forum['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_forum['last_poster']).'</span>';
}
-
- // TODO: make an install script for last_topic + ID
#
@@ -264,7 +340,7 @@ $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.pa
#
// Generate paging links
-$paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate_rewrited($num_pages, $p, 'forum-'.$id.'-'.makeurlname($cur_forum['forum_name']));
+$paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate_rewrited($num_pages, $p, 'forum-'.$id.'-'.clean_url($cur_forum['forum_name']));
#
#---------[ 26. FIND ]---------------------------------------------
@@ -276,7 +352,7 @@ $subject_multipage = '<span class="pagestext">[ '.paginate($num_pages_topic, -1,
#---------[ 27. REPLACE BY ]-------------------------------------------------
#
-$subject_multipage = '<span class="pagestext">[ '.paginate_rewrited($num_pages_topic, -1, 'topic-'.$cur_topic['id'].'-'.makeurlname($cur_topic['subject'])).' ]</span>';
+$subject_multipage = '<span class="pagestext">[ '.paginate_rewrited($num_pages_topic, -1, 'topic-'.$cur_topic['id'].'-'.clean_url($cur_topic['subject'])).' ]</span>';
#
#---------[ 26. FIND ]---------------------------------------------
@@ -347,7 +423,7 @@ $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.pa
#
// Generate paging links
-$paging_links = '<span class="pages-label">'.$lang_common['Pages'].': </span>'.paginate_rewrited($num_pages, $p, 'topic-'.$id.'-'.makeurlname($cur_topic['subject']));
+$paging_links = '<span class="pages-label">'.$lang_common['Pages'].': </span>'.paginate_rewrited($num_pages, $p, 'topic-'.$id.'-'.clean_url($cur_topic['subject']));
#
#---------[ 36. FIND ]---------------------------------------------
@@ -520,7 +596,7 @@ $num_pages_topic = ceil(($cur_search['num_replies'] + 1) / $pun_user['disp_posts
#
if ($num_pages_topic > 1)
- $subject_multipage = '<span class="pagestext">[ '.paginate_rewrited($num_pages_topic, -1, 'topic-'.$cur_search['tid'].'-'.makeurlname($cur_search['subject'])).' ]</span>';
+ $subject_multipage = '<span class="pagestext">[ '.paginate_rewrited($num_pages_topic, -1, 'topic-'.$cur_search['tid'].'-'.clean_url($cur_search['subject'])).' ]</span>';
else
$subject_multipage = null;
View
59 files/include/fluxrewrite.php
@@ -1,35 +1,48 @@
<?php
/*
- * FluxRewrite by adaur
+ * FluxRewrite by adaur (2011)
* URL Rewriting to FluxBB 1.4 :-)
*/
-function makeurl($type, $id, $name, $new_message = false, $post = false, $first_page = false) {
+function clean_url($name) {
+
+ /*
+ Cleans the string given:
+ - Removes all special caracters
+ - Sets every string in lower case
+ - Removes all similar caracters
+ */
+
+ $a = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ@()/[]|\'&';
+ $b = 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn---------';
+ $url = utf8_encode(strtr(utf8_decode($name), utf8_decode($a), utf8_decode($b)));
+ $url = preg_replace('/ /', '-', $url);
+ $url = trim(preg_replace('/[^a-z|A-Z|0-9|-]/', '', strtolower($url)), '-');
+ $url = preg_replace('/\-+/', '-', $url);
+ $url = urlencode($url);
+
+ return $url;
+}
+
+function makeurl($type, $id, $name, $page, $new_message = false, $post = false) {
/*
Rewrites the URL
$type: forum/topic
$id: ID
$name: forum name/topic subject
+ $page: specifies which page we have to display
$new_message: adds -new-message to the URL or not
$post: post to show up
- $first_page: adds -page-1 to the URL or not (avoid same content)
*/
- // Gentle replace of special chars
- $a = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ@()/[]|\'&';
- $b = 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn---------';
- $url = utf8_encode(strtr(utf8_decode($name), utf8_decode($a), utf8_decode($b)));
- $url = preg_replace('/ /', '-', $url);
- // Replace non alpha-num chars by - and trim possible last dashes
- $url=trim(preg_replace('/[^a-z|A-Z|0-9|-]/', '', strtolower($url)), '-');
- // Remove multiple occurences of -
- $url=preg_replace('/\-+/', '-', $url);
+ $url = clean_url($name);
+ $url = $url.'-page-'.$page;
if ($new_message === true)
- $url = $url .'-new-messages';
+ $url = $url.'-new-messages';
if ($first_page === true)
- $url = $url .'-page-1';
+ $url = $url.'-page-1';
$url = urlencode($type . $id .'-'. $url .'.html');
if ($post != null)
$url = $url.'#p'.$post;
@@ -37,22 +50,14 @@ function makeurl($type, $id, $name, $new_message = false, $post = false, $first_
return $url;
}
-function makeurlname($name) {
-
- $a = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ@()/[]|\'&';
- $b = 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn---------';
- $url = utf8_encode(strtr(utf8_decode($name), utf8_decode($a), utf8_decode($b)));
- $url = preg_replace('/ /', '-', $url);
- $url = trim(preg_replace('/[^a-z|A-Z|0-9|-]/', '', strtolower($url)), '-');
- $url = preg_replace('/\-+/', '-', $url);
- $url = urlencode($url);
-
- return $url;
-}
-
function paginate_rewrited($num_pages, $cur_page, $link)
{
global $lang_common;
+
+ /*
+ Rewrites the URL to pages
+ Same function as FluxBB's one
+ */
$pages = array();
$link_to_all = false;
View
159 files/install_mod.php
@@ -0,0 +1,159 @@
+<?php
+/***********************************************************************/
+// Some info about your mod.
+$mod_title = 'FluxRewrite Essentials';
+$mod_version = '2.0';
+$release_date = '2011-XX-XX';
+$author = 'adaur';
+$author_email = 'adaur.underground@gmail.com';
+
+// Versions of FluxBB this mod was created for. A warning will be displayed, if versions do not match
+$fluxbb_versions= array('1.4.7');
+
+// Set this to false if you haven't implemented the restore function (see below)
+$mod_restore = true;
+
+// This following function will be called when the user presses the "Install" button.
+function install()
+{
+ global $db, $db_type, $pun_config;
+
+ $db->add_field('forums', 'last_topic', 'VARCHAR(255)', true, null, 'last_poster');
+ $db->add_field('forums', 'last_topic_id', 'INT(10)', true, null, 'last_topic');
+ $db->add_field('forums', 'num_replies', 'INT(10)', true, null, 'last_topic_id');
+
+ // Update last_topic for each forum
+ $result = $db->query('SELECT id, last_post_id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
+ while ($cur_forum = $db->fetch_assoc($result))
+ {
+ if ($cur_forum['last_post_id'] > 0)
+ {
+ $result_subject = $db->query('SELECT t.id AS tid, t.subject FROM '.$db->prefix.'posts AS p LEFT JOIN '.$db->prefix.'topics AS t ON p.topic_id=t.id WHERE p.id='.$cur_forum['last_post_id']) or error('Unable to fetch topic subject', __FILE__, __LINE__, $db->error());
+ if ($db->num_rows($result_subject))
+ {
+ while ($row = $db->fetch_assoc($result_subject))
+ {
+ $db->query('UPDATE '.$db->prefix.'forums SET last_topic=\''.$db->escape($row['subject']).'\', last_topic_id='.$db->escape($row['tid']).' WHERE id='.$cur_forum['id']) or error('Unable to update last topic', __FILE__, __LINE__, $db->error());
+ }
+ }
+ }
+ }
+}
+
+// This following function will be called when the user presses the "Restore" button (only if $mod_uninstall is true (see above))
+function restore()
+{
+ global $db, $db_type, $pun_config;
+
+ $db->drop_field('forums', 'last_topic');
+ $db->drop_field('forums', 'last_topic_id');
+ $db->drop_field('forums', 'num_replies');
+}
+
+/***********************************************************************/
+
+// Circumvent maintenance mode
+define('PUN_TURN_OFF_MAINT', 1);
+define('PUN_ROOT', './');
+require PUN_ROOT.'include/common.php';
+
+// We want the complete error message if the script fails
+if (!defined('PUN_DEBUG'))
+{
+ define('PUN_DEBUG', 1);
+ define('PUN_SHOW_QUERIES', 1);
+}
+
+// Make sure we are running a FluxBB version that this mod works with
+$version_warning = !in_array($pun_config['o_cur_version'], $fluxbb_versions);
+
+$style = (isset($pun_user)) ? $pun_user['style'] : $pun_config['o_default_style'];
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title><?php echo pun_htmlspecialchars($mod_title) ?> installation</title>
+<link rel="stylesheet" type="text/css" href="style/<?php echo $style.'.css' ?>" />
+</head>
+<body>
+
+<div id="punwrap">
+<div id="puninstall" class="pun" style="margin: 10% 20% auto 20%">
+
+<?php
+
+if (isset($_POST['form_sent']))
+{
+ if (isset($_POST['install']))
+ {
+ // Run the install function (defined above)
+ install();
+
+?>
+<div class="block">
+ <h2><span>Installation successful</span></h2>
+ <div class="box">
+ <div class="inbox">
+ <p>Your database has been successfully prepared for <?php echo pun_htmlspecialchars($mod_title) ?>. See readme.txt for further instructions.</p>
+ </div>
+ </div>
+</div>
+<?php
+
+ }
+ else
+ {
+ // Run the restore function (defined above)
+ restore();
+
+?>
+<div class="block">
+ <h2><span>Restore successful</span></h2>
+ <div class="box">
+ <div class="inbox">
+ <p>Your database has been successfully restored.</p>
+ </div>
+ </div>
+</div>
+<?php
+
+ }
+}
+else
+{
+
+?>
+<div class="blockform">
+ <h2><span>Mod installation</span></h2>
+ <div class="box">
+ <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
+ <div><input type="hidden" name="form_sent" value="1" /></div>
+ <div class="inform">
+ <p>This script will update your database to work with the following modification:</p>
+ <p><strong>Mod title:</strong> <?php echo pun_htmlspecialchars($mod_title.' '.$mod_version) ?></p>
+ <p><strong>Author:</strong> <?php echo pun_htmlspecialchars($author) ?> (<a href="mailto:<?php echo pun_htmlspecialchars($author_email) ?>"><?php echo pun_htmlspecialchars($author_email) ?></a>)</p>
+ <p><strong>Disclaimer:</strong> Mods are not officially supported by FluxBB. Mods generally can't be uninstalled without running SQL queries manually against the database. Make backups of all data you deem necessary before installing.</p>
+<?php if ($mod_restore): ?>
+ <p>If you've previously installed this mod and would like to uninstall it, you can click the Restore button below to restore the database.</p>
+<?php endif; ?>
+<?php if ($version_warning): ?>
+ <p style="color: #a00"><strong>Warning:</strong> The mod you are about to install was not made specifically to support your current version of FluxBB (<?php echo $pun_config['o_cur_version']; ?>). This mod supports FluxBB versions: <?php echo pun_htmlspecialchars(implode(', ', $fluxbb_versions)); ?>. If you are uncertain about installing the mod due to this potential version conflict, contact the mod author.</p>
+<?php endif; ?>
+ </div>
+ <p class="buttons"><input type="submit" name="install" value="Install" /><?php if ($mod_restore): ?><input type="submit" name="restore" value="Restore" /><?php endif; ?></p>
+ </form>
+ </div>
+</div>
+<?php
+
+}
+
+?>
+
+</div>
+</div>
+
+</body>
+</html>

No commit comments for this range

Something went wrong with that request. Please try again.