Support Toolkit

BBCode Reparse: Cannot redeclare function... - Support Toolkit

BBCode Reparse: Cannot redeclare function...

by ascobol » Tue Jan 25, 2011 8:23 am

Hello,

I updated my forum to the newest version.
I also updated some of the mods.

If I want to reparse the BBcodes now with the STK (I use version 1.0.2.1-pl1) I get the following error:

Code: Select all

Fatal error: Cannot redeclare delete_drafts() (previously declared in /mnt/web7/10/01/51749901/htdocs/****/forum/includes/functions_save_full_drafts.php:21) in /mnt/web7/10/01/51749901/htdocs/****/forum/includes/functions_save_full_drafts.php on line 96


Here is the named php-file:

Code: Select all

<?php
/**
*
* functions_save_full_drafts.php
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
   exit;
}


/**
* deletes the draft posts and draft pms identified by the $draft_posts and $draft_pms parameters
*/
function delete_drafts($draft_posts, $draft_pms = '')
{
   global $db, $user;

   if (!is_array($draft_posts))
   {
      $draft_posts = array($draft_posts);
   }

   if (!is_array($draft_pms))
   {
      $draft_pms = array($draft_pms);
   }

   if ($draft_posts)
   {
      $sql = 'DELETE FROM ' . POSTS_TABLE . '
         WHERE ' . $db->sql_in_set('post_id', $draft_posts) . '
            AND poster_id = ' . $user->data['user_id'];
      $db->sql_query($sql);

      $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
         WHERE ' . $db->sql_in_set('post_msg_id', $draft_posts) . '
            AND in_message = 0
            AND poster_id = ' . $user->data['user_id'];
      $db->sql_query($sql);

      $sql = 'SELECT topic_id   FROM ' . TOPICS_TABLE . '
         WHERE ' . $db->sql_in_set('topic_first_post_id', $draft_posts) . '
            AND topic_poster = ' . $user->data['user_id'];
      $result = $db->sql_query($sql);
      $topic_ids = array();
      while ($row = $db->sql_fetchrow($result))
      {
         $topic_ids[] = $row['topic_id'];
      }
      $db->sql_freeresult($result);

      if (sizeof($topic_ids))
      {
         $sql = 'DELETE FROM ' . TOPICS_TABLE . '
            WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
               AND topic_poster = ' . $user->data['user_id'];
         $db->sql_query($sql);

         $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
            WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
         $db->sql_query($sql);

         $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
            WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
         $db->sql_query($sql);
      }
   }

   if ($draft_pms)
   {
      $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
         WHERE ' . $db->sql_in_set('msg_id', $draft_pms) . '
            AND author_id = ' . $user->data['user_id'];
      $db->sql_query($sql);

      $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . '
         WHERE ' . $db->sql_in_set('msg_id', $draft_pms) . '
            AND author_id = ' . $user->data['user_id'];
      $db->sql_query($sql);

      $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
         WHERE ' . $db->sql_in_set('post_msg_id', $draft_pms) . '
            AND in_message = 1
            AND poster_id = ' . $user->data['user_id'];
      $db->sql_query($sql);
   }

   return array();
}


/**
* lists draft posts and draft pms
* As written below, this function will output a list of draft posts and draft pms separated by appropriate captions.
* If you want to change this function so that it will output completely separate lists (draft posts or draft pms),
* just change $include_both_lists to false at the beginning of the function. In that case, it will output a list of draft pms
* whenever the $pm_drafts parameter is true (which it will be when the function gets called from the pm panel) and will output a
* list of draft posts whenever the $pm_drafts parameter is false (which it will be when the function gets called outside the pm panel).
* People who prefer separate lists or who have huge boards and prefer to skip the extra query that including both lists
* requires might want to make this change.
*/
function list_drafts($pm_drafts)
{
   // note: if you change true to false in the next line a user will only see pm drafts when he clicks
   // to see drafts from the pm area and will only see post drafts when he clicks to see drafts from anywhere else
   $include_both_lists = true;
   global $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
   $draftrows = array();
   $draft_post_num = $draft_pm_num = $row_count = 0;

   if ($include_both_lists || !$pm_drafts)
   {
      $sql = 'SELECT p.post_id, p.forum_id, p.topic_id, p.post_subject, p.post_time, t.topic_first_post_id, t.topic_title, f.forum_name
         FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f
         WHERE p.poster_id = ' . $user->data['user_id'] . '
            AND p.post_approved = ' . POST_DRAFT . '
            AND t.topic_id = p.topic_id
            AND f.forum_id = p.forum_id
         ORDER BY p.post_time DESC';
      $result = $db->sql_query($sql);
      while ($row = $db->sql_fetchrow($result))
      {
         $draftrows[] = $row;
         $draft_post_num++;
      }
      $db->sql_freeresult($result);
   }

   if ($include_both_lists || $pm_drafts)
   {
      $sql = 'SELECT DISTINCT pm.msg_id, pm.message_time, pm.message_subject
         FROM ' . PRIVMSGS_TABLE . ' pm, ' . PRIVMSGS_TO_TABLE . ' pt
         WHERE pm.msg_id = pt.msg_id
            AND pt.author_id = ' . $user->data['user_id'] . '
            AND pt.folder_id = ' . PM_DRAFT . '
         ORDER BY pm.message_time DESC';
      $result = $db->sql_query($sql);
      while ($row = $db->sql_fetchrow($result))
      {
         $draftrows[] = $row;
         $draft_pm_num++;
      }
      $db->sql_freeresult($result);
   }

   if ($include_both_lists && (!$draft_post_num || !$draft_pm_num))
   {
      if (!$draft_post_num && !$draft_pm_num)
      {
         $no_drafts_text = $user->lang['NO_SAVED_DRAFTS'];
      }
      else
      {
         $no_drafts_text = (!$draft_post_num) ? $user->lang['NO_SAVED_DRAFT_POSTS'] : $user->lang['NO_SAVED_DRAFT_PMS'];
      }
      $template->assign_vars(array(
         'S_NO_DRAFTS_TEXT'      => true,
         'NO_DRAFTS_TEXT'      => $no_drafts_text)
      );
   }

   if (!$include_both_lists && ((!$pm_drafts && !$draft_post_num) || ($pm_drafts && !$draft_pm_num)))
   {
      $no_drafts_text = (!$pm_drafts) ? $user->lang['NO_SAVED_DRAFT_POSTS'] : $user->lang['NO_SAVED_DRAFT_PMS'];
      $template->assign_vars(array(
         'S_NO_DRAFTS_TEXT'      => true,
         'NO_DRAFTS_TEXT'      => $no_drafts_text)
      );
   }

   foreach ($draftrows as $draft)
   {
      $link_topic = $link_forum = false;
      $view_topic_forum_url = $title = $caption_title = '';

      // insert an extra 'captions' row before the first post_draft row and again before the first private message draft row
      if ($row_count == 0 || $row_count == $draft_post_num)
      {
         $pm_draft = ($row_count >= $draft_post_num)? true : false;
         $caption_title = ($pm_draft) ? $user->lang['DRAFTS_PM_LIST'] : $user->lang['DRAFTS_POST_LIST'];
         // note that this if clause executes on the first loop of the for statement so $pm_draft will always be defined
      }

      if (!$pm_draft && $draft['topic_first_post_id'] != $draft['post_id'] && $auth->acl_get('f_read', $draft['forum_id']))
      {
         $link_topic = true;
         $view_topic_forum_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $draft['forum_id'] . '&amp;t=' . $draft['topic_id']);
         $title = $draft['topic_title'];
         $open_draft_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=edit&amp;p=' . $draft['post_id']);
      }
      else if (!$pm_draft && $auth->acl_get('f_read', $draft['forum_id']))
      {
         $link_forum = true;
         $view_topic_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
         $title = $draft['forum_name'];
         $open_draft_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&amp;mode=edit&amp;p=' . $draft['post_id']);
      }
      else if ($pm_draft)
      {
         $open_draft_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;mode=compose&amp;action=editdraft&amp;p=" . $draft['msg_id']);
      }

      $template_row = array(
         'CAPTION_TITLE'   => $caption_title,
         'DATE'         => ($pm_draft) ? $user->format_date($draft['message_time']) : $user->format_date($draft['post_time']),
         'DRAFT_SUBJECT'   => ($pm_draft) ? $draft['message_subject'] : $draft['post_subject'],
         'TITLE'         => $title,

         'DRAFT_ID'   => ($pm_draft) ? $draft['msg_id'] : $draft['post_id'],
         'FORUM_ID'   => ($pm_draft) ? '' : $draft['forum_id'],
         'TOPIC_ID'   => ($pm_draft) ? '' : $draft['topic_id'],

         'U_VIEW_TOPIC_FORUM'   => $view_topic_forum_url,
         'U_OPEN_DRAFT'         => $open_draft_url,

         'S_CAPTION_ROW'      => $caption_title,
         'S_LINK_TOPIC'      => $link_topic,
         'S_LINK_FORUM'      => $link_forum,
         'S_PM_DRAFT'      => $pm_draft,
         'S_PAD_SPACE'      => ($pm_draft && $draft_post_num) ? true : false
      );
      $template->assign_block_vars('draftrow', $template_row);
      $row_count++;
   }
   return $row_count;
}


/**
* redirects the user to the forum he or she was in after the user saves or deletes a post or reply;
* The parameter $mode determines whether the draft is being saved ('save') or deleted ('') and
* the parameter $data is an array that includes information needed for where to redirect.
*/
function redirect_after_draft_post_action($mode, $data)
{
   global $phpbb_root_path, $phpEx, $user;
   $user->add_lang('ucp');
   $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']);
   meta_refresh(3, $redirect_url);
   $message = ($mode == 'save') ? $user->lang['DRAFT_SAVED'] : $user->lang['DRAFT_DELETED'];
   $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
   $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=main&amp;mode=drafts') . '">', '</a>', $user->lang['UCP_MAIN_DRAFTS']);
   trigger_error($message);
}


/**
* redirects the user after the user clicks to save a pm as a draft
*/
function redirect_after_save_draft_pm()
{
   global $phpbb_root_path, $phpEx, $user;
   $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox');
   meta_refresh(3, $redirect_url);
   $message = $user->lang['DRAFT_SAVED'];
   $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $redirect_url . '">', '</a>', $user->lang['PM_INBOX']);
   $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=drafts') . '">', '</a>', $user->lang['UCP_MAIN_DRAFTS']);
   trigger_error($message);
}


/**
* submits a pm draft as a live pm
*/
function submit_pmdraft_live($data, $recipients, $current_time)
{
   global $db, $user;

   $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
      SET folder_id = ' . PRIVMSGS_OUTBOX . '
      WHERE msg_id = ' . (int) $data['msg_id'] . '
         AND author_id = ' . $user->data['user_id'] . '
         AND user_id = ' . $user->data['user_id'];
   $db->sql_query($sql);

   $sql_ary = array();
   foreach ($recipients as $user_id => $type)
   {
      $sql_ary[] = array(
         'msg_id'      => (int) $data['msg_id'],
         'user_id'      => (int) $user_id,
         'author_id'      => (int) $data['from_user_id'],
         'folder_id'      => PRIVMSGS_NO_BOX,
         'pm_new'      => 1,
         'pm_unread'      => 1,
         'pm_forwarded'   => ($data['pm_forwarded']) ? 1 : 0
      );
   }
   $db->sql_multi_insert(PRIVMSGS_TO_TABLE, $sql_ary);

   $sql = 'UPDATE ' . USERS_TABLE . '
      SET user_new_privmsg = user_new_privmsg + 1, user_unread_privmsg = user_unread_privmsg + 1, user_last_privmsg = ' . time() . '
      WHERE ' . $db->sql_in_set('user_id', array_keys($recipients));
   $db->sql_query($sql);


   $sql = 'UPDATE ' . USERS_TABLE . '
      SET user_lastpost_time = ' . (int) $current_time . '
      WHERE user_id = ' . $data['from_user_id'];
   $db->sql_query($sql);
}


?>


I hope someone can help me, because for me the named lines (21 and 96) look ok.

Btw, the mod works with out problems and the forum too. Only if I try to reparse the BBcodes I get an error.
ascobol
Registered User
Posts: 4
Joined: Mon Oct 04, 2010 10:14 am

Re: BBCode Reparse: Cannot redeclare function...

by Leinad4Mind » Sat Jan 28, 2012 5:08 am

Same problem here...

EDIT: SOVLED!

Solution:

FIND:

Code: Select all

/**
* deletes the draft posts and draft pms identified by the $draft_posts and $draft_pms parameters
*/


AFTER:

Code: Select all

If (defined('IN_STK'))
{
      return;
}
else
{


FIND:

Code: Select all

?>


BEFORE:

Code: Select all

}
Want to access all my Premium MODs and Extensions? Check out my store
phpBB Portugal Translator and Moderator
User avatar
Leinad4Mind
Translator
Posts: 865
Joined: Sun Jun 01, 2008 11:08 pm

Re: BBCode Reparse: Cannot redeclare function...

by PiperB » Tue May 02, 2017 10:38 pm

Thank you for this fix, it's excellent. :)
<!-- IF U_LOVE_NOTEPAD++ -->
[td class=statement]I Notepad++ ![/td]
<!-- ENDNEVER --> <!-- tee hee --> :P
Whoa ooo whoa ooo whoa I'm a Lady!
User avatar
PiperB
Registered User
Posts: 173
Joined: Mon Nov 07, 2016 6:54 pm