~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to html/ops/bbcode_convert_response2.php

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
// You should have received a copy of the GNU Lesser General Public License
17
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
 
 
20
 
 
21
 
require_once("../inc/db.inc");
22
 
require_once("../inc/util.inc");
23
 
require_once('../inc/sanitize_html.inc');
 
19
$cli_only = true;
 
20
require_once("../inc/util_ops.inc");
 
21
require_once('../inc/bbcode_convert.inc');
 
22
 
24
23
db_init();
25
24
 
26
25
set_time_limit(0);
27
26
 
28
 
function image_as_bb($text){
29
 
    // This function depends on sanitized HTML
30
 
 
31
 
    $pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
32
 
    $replacement = '[img]$2[/img]';
33
 
    $text = preg_replace($pattern, $replacement, $text);
34
 
 
35
 
    $pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
36
 
    $replacement = '[img]$2[/img]';
37
 
    $text = preg_replace($pattern, $replacement, $text);
38
 
 
39
 
    return $text;
40
 
}
41
 
 
42
 
function link_as_bb($text){
43
 
        /* This function depends on sanitized HTML */
44
 
    // Build some regex (should be a *lot* faster)
45
 
    $pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
46
 
    $replacement = '[url=$1]'; // Turns that URL into a hyperlink
47
 
    $text = preg_replace($pattern, $replacement, $text);
48
 
    $pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
49
 
    $replacement = '[url=$1]'; // Turns that URL into a hyperlink
50
 
    $text = preg_replace($pattern, $replacement, $text);
51
 
 
52
 
    $pattern = "@</a>@si";
53
 
    $replacement = '[/url]';
54
 
    $text = preg_replace($pattern, $replacement, $text);
55
 
    return $text;
56
 
}
57
 
 
58
 
function formatting_as_bb($text){
59
 
        /* This function depends on sanitized HTML */
60
 
    $in[]="<b>";$out[]="[b]";
61
 
    $in[]="</b>";$out[]="[/b]";
62
 
 
63
 
    $in[]="<i>";$out[]="[i]";
64
 
    $in[]="</i>";$out[]="[/i]";
65
 
 
66
 
    $in[]="<u>";$out[]="[u]";
67
 
    $in[]="</u>";$out[]="[/u]";
68
 
 
69
 
    $in[]="<b>";$out[]="[b]";
70
 
    $in[]="</b>";$out[]="[/b]";
71
 
 
72
 
    $in[]="<ul>";$out[]="[list]";
73
 
    $in[]="</ul>";$out[]="[/list]";
74
 
 
75
 
    $in[]="<ol>";$out[]="[list=1]";
76
 
    $in[]="</ol>";$out[]="[/list]";
77
 
 
78
 
    $in[]="<pre>";$out[]="[pre]";
79
 
    $in[]="</pre>";$out[]="[/pre]";
80
 
 
81
 
    $in[]="</br>";$out[]="\n";
82
 
    $in[]="<br/>";$out[]="\n";
83
 
    $in[]="<br>";$out[]="\n";
84
 
    $in[]="&gt;";$out[]=">";
85
 
    $in[]="&lt;";$out[]="<";
86
 
    $in[]="&amp;";$out[]="&";
87
 
 
88
 
    return str_replace($in, $out, $text);
89
 
}
90
 
 
91
 
function fix_text($text) {
92
 
    $text = sanitize_html($text);    
93
 
    $text = image_as_bb($text);
94
 
    $text = link_as_bb($text);
95
 
    $text = formatting_as_bb($text);
96
 
    return $text;
97
 
}
98
 
 
99
27
function fix_profile($profile) {
100
 
    $text = fix_text($profile->response2);
 
28
    $text = html_to_bbcode($profile->response2);
101
29
    if ($text != $profile->response2) {
102
30
        $query = "update profile set response2 = '".mysql_escape_string($text)."' where userid=".$profile->userid;
103
31
        //echo "$profile->response2\n\n";