1 | #!/usr/bin/env php |
||
2 | <?php |
||
3 | // This file is part of BOINC. |
||
4 | // http://boinc.berkeley.edu |
||
5 | // Copyright (C) 2009 University of California |
||
6 | // |
||
7 | // BOINC is free software; you can redistribute it and/or modify it |
||
8 | // under the terms of the GNU Lesser General Public License |
||
9 | // as published by the Free Software Foundation, |
||
10 | // either version 3 of the License, or (at your option) any later version. |
||
11 | // |
||
12 | // BOINC is distributed in the hope that it will be useful, |
||
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
15 | // See the GNU Lesser General Public License for more details. |
||
16 | // |
||
17 | // You should have received a copy of the GNU Lesser General Public License |
||
18 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
19 | |||
20 | // This script converts the old file-based news (project_news.inc) |
||
21 | // into the new forum-based format. |
||
22 | |||
23 | error_reporting(E_ALL); |
||
24 | ini_set('display_errors', true); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
25 | ini_set('display_startup_errors', true); |
||
26 | |||
27 | require_once("../project/project_news.inc"); |
||
28 | require_once("../inc/forum_db.inc"); |
||
29 | require_once("../inc/forum.inc"); |
||
30 | require_once("../inc/bbcode_convert.inc"); |
||
31 | |||
32 | $forum_name = "News"; |
||
33 | $forum_desc = "News from this project"; |
||
34 | |||
35 | echo "This script exports project news from the project_news.inc file |
||
36 | to a message board. |
||
37 | Do you want to do this (y/n)? "; |
||
38 | |||
39 | $stdin = fopen("php://stdin", "r"); |
||
40 | $x = trim(fgets($stdin)); |
||
41 | if ($x != "y") { |
||
42 | exit; |
||
43 | } |
||
44 | |||
45 | while (1) { |
||
46 | echo "Enter the email address of admin account to appear as poster: "; |
||
47 | $x = trim(fgets($stdin)); |
||
48 | $user = BoincUser::lookup("email_addr='$x'"); |
||
49 | if (!$user) { |
||
50 | echo "No such user\n"; |
||
51 | continue; |
||
52 | } |
||
53 | BoincForumPrefs::lookup($user); |
||
54 | if (!$user->prefs->privilege(S_ADMIN)) { |
||
55 | echo "User doesn't have admin privileges"; |
||
56 | continue; |
||
57 | } |
||
58 | break; |
||
59 | } |
||
60 | |||
61 | $category = BoincCategory::lookup("orderID=0 and is_helpdesk=0"); |
||
62 | if (!$category) { |
||
63 | die("can't find category"); |
||
64 | } |
||
65 | |||
66 | $forum = BoincForum::lookup("parent_type=0 and title='$forum_name'"); |
||
67 | if ($forum) { |
||
68 | die("News forum already exists"); |
||
69 | } |
||
70 | |||
71 | $now = time(); |
||
72 | $forum_id = BoincForum::insert("(category, orderID, title, description, timestamp, is_dev_blog, parent_type) values ($category->id, -1, '$forum_name', '$forum_desc', $now, 1, 0)"); |
||
73 | $forum = BoincForum::lookup_id($forum_id); |
||
74 | |||
75 | foreach (array_reverse($project_news) as $item) { |
||
76 | $content = $item[1]; |
||
77 | if (isset($item[2])) { |
||
78 | $title = $item[2]; |
||
79 | } else { |
||
80 | $n = strpos($content, ". "); |
||
81 | if ($n) { |
||
82 | $title = substr($content, 0, $n); |
||
83 | } else { |
||
84 | $title = $content; |
||
85 | } |
||
86 | } |
||
87 | $when = strtotime($item[0]); |
||
88 | $title = html_to_bbcode($title); |
||
89 | $title = str_replace("\n", " ", $title); |
||
90 | $title = _mysql_escape_string($title); |
||
91 | $content = html_to_bbcode($content); |
||
92 | $content = str_replace("\n", " ", $content); |
||
93 | $content = _mysql_escape_string($content); |
||
94 | |||
95 | $thread_id = BoincThread::insert("(forum, owner, title, create_time, timestamp, replies) values ($forum_id, $user->id, '$title', $when, $when, 0)"); |
||
96 | if (!$thread_id) { |
||
97 | echo "thread insert failed\n"; |
||
98 | echo "title: [$title]\n"; |
||
99 | echo "when: $when\n"; |
||
100 | exit; |
||
101 | } |
||
102 | |||
103 | $id = BoincPost::insert("(thread, user, timestamp, content) values ($thread_id, $user->id, $when, '$content')"); |
||
104 | if (!$id) die("post insert"); |
||
105 | |||
106 | $forum->update("threads=threads+1, posts=posts+1"); |
||
107 | } |
||
108 | |||
109 | echo " |
||
110 | |||
111 | Project news has been successfully converted from |
||
112 | html/project/project_news.inc to forum format. |
||
113 | Change your index.php to use |
||
114 | show_news(0, 5) |
||
115 | to show news and related links. |
||
116 | |||
117 | If everything looks OK, you can delete html/project/project_news.inc |
||
118 | |||
119 | "; |
||
120 | ?> |
||
121 |