Changeset 82 for img

Show
Ignore:
Timestamp:
03/19/10 00:13:22 (6 months ago)
Author:
daniel
Message:

- Added: UTF-8 wordwrap function
- Fixed: Set UTF-8 for htmlentities encoding
- Fixed: wordwrap doesn't break html escaped strings anymore

Location:
img/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • img/trunk/browse.php

    r67 r82  
    6363                 
    6464                $preview = dirname($row['name']) . '/preview/' . basename($row['name']); 
    65                 $images .= '<div class="previewimage"><a href="' . $row['name'] . '" class="lightbox" rel="lightbox"><img src="' . $preview . '" alt="' . htmlentities($row['original_name']) . '" /></a><br />' . "\n"; 
     65                $images .= '<div class="previewimage"><a href="' . $row['name'] . '" class="lightbox" rel="lightbox"><img src="' . $preview . '" alt="' . htmlentities($row['original_name'], ENT_QUOTES, 'UTF-8') . '" /></a><br />' . "\n"; 
    6666                $images .= '<a href="image.php?i=' . urlnumber_encode($row['id']) . '">Show</a></div>' . "\n"; 
    6767        } 
     
    8888        $pages = substr($pages, 0, -10) . '</p>'; 
    8989         
    90         outputHTML('<h2>' . one_wordwrap(htmlentities($tag_text), 5, '&shy;') . '</h2>' . $images . '<br style="clear: both;" />' . $pages, array('title' => 'Tag: ' . htmlentities($tag_text), 'lightbox' => true)); 
     90        outputHTML('<h2>' . htmlentities(one_wordwrap($tag_text, 5, '&shy;'), ENT_QUOTES, 'UTF-8', false) . '</h2>' . $images . '<br style="clear: both;" />' . $pages, array('title' => 'Tag: ' . htmlentities($tag_text, ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); 
    9191 
    9292} elseif(isset($_GET['user'])) { 
     
    114114        while ($row = $db->fetch($res)) { 
    115115                $preview = dirname($row['name']) . '/preview/' . basename($row['name']); 
    116                 $images .= '<div class="previewimage"><a href="' . $row['name'] . '" class="lightbox" rel="lightbox"><img src="' . $preview . '" alt="' . htmlentities($row['original_name']) . '" /></a><br />' . "\n"; 
     116                $images .= '<div class="previewimage"><a href="' . $row['name'] . '" class="lightbox" rel="lightbox"><img src="' . $preview . '" alt="' . htmlentities($row['original_name'], ENT_QUOTES, 'UTF-8') . '" /></a><br />' . "\n"; 
    117117                $images .= '<a href="image.php?i=' . urlnumber_encode($row['id']) . '">Show</a></div>' . "\n"; 
    118118        } 
     
    135135        $pages = substr($pages, 0, -10) . '</p>'; 
    136136         
    137         outputHTML('<h2>' . one_wordwrap(htmlentities(urldecode($_GET['user'])), 5, '&shy;') . '</h2>' . $images . '<br style="clear: both;" />' . $pages, array('title' => 'Tag: ' . htmlentities($_GET['user']), 'lightbox' => true)); 
     137        outputHTML('<h2>' . htmlentities(one_wordwrap(urldecode($_GET['user']), 5, '&shy;'), ENT_QUOTES, 'UTF-8', false) . '</h2>' . $images . '<br style="clear: both;" />' . $pages, array('title' => 'Tag: ' . htmlentities($_GET['user'], ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); 
    138138         
    139139} else { 
    140140 
    141141        // Get tags from db 
    142         $sql = "SELECT tag, text, count FROM tags ORDER BY count DESC"; 
     142        $sql = "SELECT tag, text, count FROM tags ORDER BY count DESC, ROWID DESC"; 
    143143        $sql .= (isset($_GET['tags']) && $_GET['tags'] == 'all') ? ';' : ' LIMIT 100;'; 
    144          
     144 
    145145        $res = $db->query($sql); 
    146146        $tags = array(); 
     
    148148        while ($row = $db->fetch($res)) { 
    149149                $tags[$row['tag']] = $row['count']; 
    150                 $texts[$row['tag']] = htmlentities($row['text']); 
     150                $texts[$row['tag']] = htmlentities($row['text'], ENT_QUOTES, 'UTF-8'); 
    151151        } 
    152152         
  • img/trunk/image.php

    r67 r82  
    4444$name = $row['location']; 
    4545$preview = dirname($name) . '/preview/' . basename($name); 
    46 $original_name = htmlentities($row['original_name']); 
     46$original_name = $row['original_name']; 
    4747$user = $row['user']; 
    4848 
     
    5151$tags = ''; 
    5252while ($row = $db->fetch($res)) { 
    53         $tags .= '<a href="browse.php?tag=' . urlencode($row['tag']) . '">' . htmlentities($row['text']) . '</a>, '; 
     53        $tags .= '<a href="browse.php?tag=' . urlencode($row['tag']) . '">' . htmlentities($row['text'], ENT_QUOTES, 'UTF-8') . '</a>, '; 
    5454} 
    5555$tags = substr($tags, 0, -2); 
    5656 
    5757// Generate HTML and code snippets for inserting the image 
    58 $output = '<h2 id="imagename"><a href="' . $name . '">' . one_wordwrap($original_name, 5, '&shy;') . '</a></h2> 
     58$output = '<h2 id="imagename"><a href="' . $name . '">' . htmlentities(one_wordwrap($original_name, 5, '&shy;'), ENT_QUOTES, 'UTF-8', false) . '</a></h2> 
    5959                        <a id="preview" href="' . $name . '" rel="lightbox" ><img src="' . $preview . '" alt="" /></a> 
    6060                        <p id="tags">Tags: ' . $tags . '<br /></p> 
     
    7272                                                <td>Preview</td> 
    7373                                                <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="' . url() . $name . '" /></td> 
    74                                                 <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="&lt;a href=&quot;' . url() . $name . '&quot;&gt;&lt;img src=&quot;' . url() . $preview . '&quot; alt=&quot;' . $original_name . ' - img.pew.cc&quot; /&gt;&lt;/a&gt;" /></td> 
     74                                                <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="&lt;a href=&quot;' . url() . $name . '&quot;&gt;&lt;img src=&quot;' . url() . $preview . '&quot; alt=&quot;' . htmlentities($original_name, ENT_QUOTES, 'UTF-8') . ' - img.pew.cc&quot; /&gt;&lt;/a&gt;" /></td> 
    7575                                                <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="[URL=' . url() . $name . '][IMG]' . url() . $preview . '[/IMG][/URL]" /></td> 
    7676                                        </tr> 
     
    7878                                                <td>Full</td> 
    7979                                                <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="' .  url() . $name . '" /></td> 
    80                                                 <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="&lt;img src=&quot;' . url() . $name . '&quot; alt=&quot;' . $original_name . ' - img.pew.cc&quot; /&gt;" /></td> 
     80                                                <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="&lt;img src=&quot;' . url() . $name . '&quot; alt=&quot;' . htmlentities($original_name, ENT_QUOTES, 'UTF-8') . ' - img.pew.cc&quot; /&gt;" /></td> 
    8181                                                <td><input onclick="this.select()" type="text" size="15" readonly="readonly" value="[IMG]' . url() . $name . '[/IMG]" /></td> 
    8282                                        </tr> 
     
    9292} 
    9393 
    94 outputHTML($output, array('title' => 'Image: ' . $original_name, 'lightbox' => true, 'header' => $header)); 
     94outputHTML($output, array('title' => 'Image: ' . htmlentities($original_name, ENT_QUOTES, 'UTF-8'), 'lightbox' => true, 'header' => $header)); 
    9595 
    9696?> 
  • img/trunk/lib/functions.php

    r78 r82  
    203203 
    204204/** 
     205 * Wordwrap an UTF-8 string 
     206 * Function by andrnag at yandex dot ru 
     207 * See http://de.php.net/manual/en/function.wordwrap.php#94452 
     208 * 
     209 * @param       sring                   $str                    Input string 
     210 * @param       integer                 $width                  The column width.  
     211 * @param       string                  $break                  The line is broken using the optional break  parameter.  
     212 * @return      string                                                  Returns the given string wrapped at the specified column.  
     213 */ 
     214function utf8_wordwrap($str, $width = 75, $break = "\n") // wordwrap() with utf-8 support 
     215{ 
     216        $str =  preg_split('/([\x20\r\n\t]++|\xc2\xa0)/sSX', $str, -1, PREG_SPLIT_NO_EMPTY); 
     217        $len = 0; 
     218        $return = ''; 
     219        foreach ($str as $val) { 
     220                $val .= ' '; 
     221                $tmp = mb_strlen($val, 'utf-8'); 
     222                $len += $tmp; 
     223                if ($len >= $width) { 
     224                        $return .= $break . $val; 
     225                        $len = $tmp; 
     226                } else 
     227                        $return .= $val; 
     228        } 
     229        return $return; 
     230} 
     231 
     232/** 
    205233 * Inserts a wrapping string if a word is longer than $width 
    206234 * 
     
    215243        $new_string = ''; 
    216244        foreach ($s as $k => $v) { 
    217                 if(strlen($v) > $width) $v = wordwrap($v, $width, $wrap, true); 
     245                if(strlen($v) > $width) $v = utf8_wordwrap($v, $width, $wrap); 
    218246                $new_string .= $v . ' '; 
    219247        } 
  • img/trunk/login.php

    r71 r82  
    7575                                        setcookie('openid_cookie', serialize(array($oid->GetIdentifier(), $cookie)), time() + 60 * 60 * 24 * 30); 
    7676                                } 
    77                                 errorMsg('Login successful.<br />You are now logged in as <a href="browse.php?user=' . urlencode($oid->GetIdentifier()) . '"><i>' . htmlentities($oid->GetIdentifier()) . '</i></a>', url()); 
     77                                errorMsg('Login successful.<br />You are now logged in as <a href="browse.php?user=' . urlencode($oid->GetIdentifier()) . '"><i>' . htmlentities($oid->GetIdentifier(), ENT_QUOTES, 'UTF-8') . '</i></a>', url()); 
    7878                        } else { 
    7979                                session_destroy(); 
     
    9191 
    9292if (!empty($_SESSION['openid_identity'])) { 
    93         outputHTML('You are logged in as <a href="browse.php?user=' . urlencode($_SESSION['openid_identity']) . '"><i>' . htmlentities($_SESSION['openid_identity']) . '</i></a><br /><br /><a href="login.php?action=logout">Logout</a>'); 
     93        outputHTML('You are logged in as <a href="browse.php?user=' . urlencode($_SESSION['openid_identity']) . '"><i>' . htmlentities($_SESSION['openid_identity'], ENT_QUOTES, 'UTF-8') . '</i></a><br /><br /><a href="login.php?action=logout">Logout</a>'); 
    9494} else { 
    9595        $output = '<h2>OpenID Login</h2> 
  • img/trunk/search.php

    r80 r82  
    108108        foreach ($images as $i) { 
    109109                $preview = dirname($full_images[$i]['location']) . '/preview/' . basename($full_images[$i]['location']); 
    110                 $output .= '<div class="previewimage"><a href="' . $full_images[$i]['location'] . '" class="lightbox" rel="lightbox"><img src="' . $preview . '" alt="' . htmlentities($full_images[$i]['original_name']) . '" /></a><br />' . "\n"; 
     110                $output .= '<div class="previewimage"><a href="' . $full_images[$i]['location'] . '" class="lightbox" rel="lightbox"><img src="' . $preview . '" alt="' . htmlentities($full_images[$i]['original_name'], ENT_QUOTES, 'UTF-8') . '" /></a><br />' . "\n"; 
    111111                $output .= '<a href="image.php?i=' . urlnumber_encode($i) . '">Show</a></div>' . "\n"; 
    112112        } 
     
    121121        $pages = substr($pages, 0, -10) . '</p>'; 
    122122         
    123         outputHTML('<h2>' . one_wordwrap(htmlentities($_GET['q']), 5, '&shy;') . '</h2>' . $output . '<br style="clear: both;" />' . $pages, array('title' => 'Search: ' . htmlentities($_GET['q']), 'lightbox' => true)); 
     123        outputHTML('<h2>' . htmlentities(one_wordwrap($_GET['q'], 5, '&shy;'), ENT_QUOTES, 'UTF-8', false) . '</h2>' . $output . '<br style="clear: both;" />' . $pages, array('title' => 'Search: ' . htmlentities($_GET['q'], ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); 
    124124         
    125125} else { 
  • img/trunk/tags.php

    r67 r82  
    3737         
    3838        while ($row = $db->fetch($res)) { 
    39                 $tags[] = htmlentities($row['text']); 
     39                $tags[] = htmlentities($row['text'], ENT_QUOTES, 'UTF-8'); 
    4040        } 
    4141