PageRenderTime 29ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/misc/conversion/update_ariel_links.php

http://github.com/phpbb/customisation-db
PHP | 124 lines | 81 code | 19 blank | 24 comment | 9 complexity | 461dcf26ecb99bbafd29a13d95ad9a12 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Titania
  5. * @copyright (c) 2008 phpBB Customisation Database Team
  6. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2
  7. *
  8. */
  9. /**
  10. * Update links in the forums to redirect to Titania instead of Ariel (for phpbb.com)
  11. */
  12. /**
  13. * @ignore
  14. */
  15. define('IN_TITANIA', true);
  16. define('IN_TITANIA_CONVERT', true);
  17. if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', './');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. require TITANIA_ROOT . 'common.' . PHP_EXT;
  20. titania::add_lang('manage');
  21. // Give founders access
  22. if (phpbb::$user->data['user_type'] != USER_FOUNDER)
  23. {
  24. titania::needs_auth();
  25. }
  26. // Hopefully this helps
  27. @set_time_limit(0);
  28. $limit = 2500;
  29. $forum_ids = array(
  30. 15, 16, 17, 22, 23, 35, 94, // 2.0 forums
  31. 69, 70, 71, 72, // 3.0 Modification forums
  32. 73, 74, 185, // 3.0 Styles forums
  33. 225, // Automod
  34. );
  35. $start = request_var('start', 0);
  36. // Rewritten URLs
  37. $contrib_view = 'http://www.phpbb.com/customise/db/contribution/$1/';
  38. $contrib_view_full = '<a class="postlink" href="' . $contrib_view . '">' . $contrib_view . '</a>';
  39. // Count
  40. $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . POSTS_TABLE . '
  41. WHERE ' . phpbb::$db->sql_in_set('forum_id', $forum_ids);
  42. phpbb::$db->sql_query($sql);
  43. $total = phpbb::$db->sql_fetchfield('cnt');
  44. phpbb::$db->sql_freeresult();
  45. $sql = 'SELECT post_id, post_text FROM ' . POSTS_TABLE . '
  46. WHERE ' . phpbb::$db->sql_in_set('forum_id', $forum_ids) . '
  47. ORDER BY post_id ASC';
  48. $result = phpbb::$db->sql_query_limit($sql, $limit, $start);
  49. while ($row = phpbb::$db->sql_fetchrow($result))
  50. {
  51. $md5 = md5($row['post_text']);
  52. $original = $row['post_text'];
  53. // Rewrite the full URLs
  54. $replace = array(
  55. '#<a class="postlink" href="http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/index(?:\.|&\#46;)php\?i=queue&amp;mode=overview&amp;contrib_id=([0-9]+)">.+</a>#',
  56. '#<a class="postlink" href="http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/index(?:\.|&\#46;)php\?i=misc&amp;mode=display&amp;contrib_id=([0-9]+)">.+</a>#',
  57. );
  58. $row['post_text'] = preg_replace($replace, $contrib_view_full, $row['post_text']);
  59. // Rewrite the unparsed URLs
  60. $replace = array(
  61. '#http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/index(?:\.|&\#46;)php\?i=queue&amp;mode=overview&amp;contrib_id=([0-9]+)#',
  62. '#http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/index(?:\.|&\#46;)php\?i=misc&amp;mode=display&amp;contrib_id=([0-9]+)#',
  63. );
  64. $row['post_text'] = preg_replace($replace, $contrib_view, $row['post_text']);
  65. // Rewrite the download URLs
  66. $replace = array(
  67. '#<a class="postlink" href="http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/download/([0-9]+)/?">(.+)</a>#',
  68. '#<a class="postlink" href="http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/index(?:\.|&\#46;)php\?i=misc&amp;mode=display&amp;download=1&amp;contrib_id=([0-9]+)">(.+)</a>#',
  69. );
  70. $row['post_text'] = preg_replace($replace, '<a class="postlink" href="http://www.phpbb.com/customise/db/download/contrib_$1">$2</a>', $row['post_text']);
  71. $replace = array(
  72. '#http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/download/([0-9]+)/?"#',
  73. '#http(?:\:|&\#58;)//www(?:\.|&\#46;)phpbb(?:\.|&\#46;)com/(?:styles|mods)/db/index(?:\.|&\#46;)php\?i=misc&amp;mode=display&amp;download=1&amp;contrib_id=([0-9]+)#',
  74. );
  75. $row['post_text'] = preg_replace($replace, 'http://www.phpbb.com/customise/db/download/contrib_$1', $row['post_text']);
  76. // Remove selected tags stuff
  77. $replace = "#\n\[b:[a-z0-9]+\]Selected tags:\[/b:[a-z0-9]+\]\n\[list.+\]\[/list:o:[a-z0-9]+\]\n#";
  78. $row['post_text'] = preg_replace($replace, '', $row['post_text']);
  79. if (md5($row['post_text']) != $md5)
  80. {
  81. // Post was updated
  82. $sql = 'UPDATE ' . POSTS_TABLE . '
  83. SET post_text = \'' . phpbb::$db->sql_escape($row['post_text']) . '\'
  84. WHERE post_id = ' . $row['post_id'];
  85. phpbb::$db->sql_query($sql);
  86. }
  87. }
  88. phpbb::$db->sql_freeresult($result);
  89. if (($start + $limit) >= $total)
  90. {
  91. trigger_error('Completed!');
  92. }
  93. else
  94. {
  95. // Still more to do
  96. $next = append_sid(TITANIA_ROOT . 'update_ariel_links.' . PHP_EXT, "start=" . ($start + $limit));
  97. $display_message = '...done with ' . ($start + $limit) . ' of ' . $total;
  98. }
  99. $display_message .= '<br /><br /><a href="' . $next . '">Manual Continue</a>';
  100. // Meta refresh only if no errors
  101. if (!headers_sent())
  102. {
  103. meta_refresh(0, $next);
  104. }
  105. trigger_error($display_message);