Changeset 1075

Show
Ignore:
Timestamp:
09/17/06 01:16:45 (2 years ago)
Author:
jm3
Message:

new user profile icons thumbnailing and code!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedmelinks/modules/utils.inc.php

    r1045 r1075  
    11<% 
    2         if( ! $cached_page_include ) 
    3                 session_register("cache"); 
    4         include_once( "env.inc.php" ); 
    5         include( get_root() . "/modules/prep-cache.inc.php" ); 
    6  
    7         function get_id_for_existing_link( $url, $u ) { 
    8                 $q = run_query( getQuery( "get_id_for_existing_link", $url, $u )); 
    9                 return mysql_result($q, 0, "id" ); 
    10         } 
    11  
    12         function diff_in_secs( $db_date_0, $db_date_1 ) { 
    13                 $dt0 =  strtotime( $db_date_0 ); 
    14                 $dt1 =  strtotime( $db_date_1 ); 
    15                 return( $dt0 - $dt1 ); 
    16         } 
    17  
    18         function get_db_date_diff_in_days( $qs ) { 
    19                 $con_fuq_slot = mysql_connect(); 
    20                 mysql_selectdb( getDBName() ); 
    21                 $q = mysql_query( $qs ); 
    22                 if( ! $q ) 
    23                         return undefined; 
    24                  
    25                 $d0 = mysql_result($q,0); 
    26                 $d1 = mysql_result($q,1); 
    27                 $diff = round( diff_in_secs( $d0, $d1 ) / 60 / 60 / 24, 4); 
    28                 return $diff > 0 ? $diff : 0; 
    29         } 
    30  
    31         function get_simple_rs( $qs ) { 
    32                 $con = mysql_connect(); 
    33                 mysql_selectdb( getDBName() ); 
    34                 $q = mysql_query( $qs ); 
    35                 if( ! $q ) 
    36                         return undefined; 
    37                  
    38                 return mysql_result($q,0); 
    39         } 
    40  
    41         function get_fuq_threshold() { return 2; } 
    42  
    43         function get_fuq( $u ) { 
    44     $con = mysql_connect(); 
    45     mysql_selectdb( getDBName() ); 
    46     $qs = getQuery( "get_fuq", $u ); 
     2if( ! $cached_page_include ) 
     3        session_register("cache"); 
     4include_once( "env.inc.php" ); 
     5include( get_root() . "/modules/prep-cache.inc.php" ); 
     6 
     7# returns the PATH to the newly created thumbnail 
     8function make_thumbnail_for_user( $u ) { 
     9        $i = get_profile_image( $u ); 
     10        $out = "/" . get_user_folder( $u ) . "/thumb.png"; 
     11        imagepng( get_png_thumbnail_from_image( $i ), get_root() . $out ); 
     12        return $out; 
     13
     14 
     15# returns an image OBJECT of the newly created thumbnail 
     16function get_png_thumbnail_from_image( $i ) { 
     17        $goal = 64; 
     18        list($width, $height, $type, $attr) = getimagesize( $i ); 
     19 
     20        #calculate which is the shorter side, re-map that to $goal, and calculate the new length of the longer side 
     21        $tall = ( $width < $height ) ? true : false; 
     22        $new_height = $new_width = $goal; 
     23        if( $tall ) { 
     24                $frac = $goal / $width; 
     25                $new_height = $height * $frac; 
     26        } else { 
     27                $frac = $goal / $height; 
     28                $new_width = $width * $frac; 
     29        } 
     30 
     31        switch( $type ){ 
     32                case 1 : $orig = imagecreatefromgif($i);  break; 
     33                case 2 : $orig = imagecreatefromjpeg($i); break; 
     34                case 3 : $orig = imagecreatefrompng($i);  break; 
     35                default: break; 
     36        } 
     37 
     38        # resize it: 
     39        $small = imagecreatetruecolor( $new_width, $new_height ); 
     40        imagecopyresampled( $small, $orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); 
     41        imagepng( $small, "icons/small.png" ); 
     42 
     43        # new black-bordered palette to copy onto: 
     44        $cropped = imagecreatetruecolor( $goal + 2, $goal + 2 ); 
     45        imagefill( $cropped, 0, 0, imagecolorallocate( $cropped, 0, 0, 0 )); 
     46 
     47        # crop image onto black 
     48        imagecopy($cropped, $small, 1, 1, ceil( ($new_width - $goal) / 2), ceil( ($new_height - $goal) / 2), $goal, $goal); 
     49 
     50        imagedestroy($small); 
     51        imagedestroy($orig); 
     52        return $cropped; 
     53
     54 
     55function get_id_for_existing_link( $url, $u ) { 
     56        $q = run_query( getQuery( "get_id_for_existing_link", $url, $u )); 
     57        return mysql_result($q, 0, "id" ); 
     58
     59 
     60function diff_in_secs( $db_date_0, $db_date_1 ) { 
     61        $dt0 =  strtotime( $db_date_0 ); 
     62        $dt1 =  strtotime( $db_date_1 ); 
     63        return( $dt0 - $dt1 ); 
     64
     65 
     66function get_db_date_diff_in_days( $qs ) { 
     67        $con_fuq_slot = mysql_connect(); 
     68        mysql_selectdb( getDBName() ); 
     69        $q = mysql_query( $qs ); 
     70        if( ! $q ) 
     71                return undefined; 
    4772         
    48     $q = mysql_query( $qs ); 
    49     $num_rows = mysql_affected_rows($con); 
     73        $d0 = mysql_result($q,0); 
     74        $d1 = mysql_result($q,1); 
     75        $diff = round( diff_in_secs( $d0, $d1 ) / 60 / 60 / 24, 4); 
     76        return $diff > 0 ? $diff : 0; 
     77
     78 
     79function get_simple_rs( $qs ) { 
     80        $con = mysql_connect(); 
     81        mysql_selectdb( getDBName() ); 
     82        $q = mysql_query( $qs ); 
     83        if( ! $q ) 
     84                return undefined; 
    5085         
    51     if( $num_rows == 1 ) 
    52                         return mysql_result($q, 0, "FUQ" ); 
    53                 else  
    54                         return 2; 
    55         } 
    56  
    57         function delta_time_between_links( $u, $raw = false ) { 
    58                 $value = get_db_date_diff_in_days( getQuery( "get_fuq_slot_delta_time_between_links", $u )) * 60; 
    59                 if( $raw ) 
    60                         return $value; 
    61                 else 
    62                         if( $value < 0.5 ) 
    63                                 return -1; 
    64                         else if( $value > 10 ) 
    65                                 return 1; 
    66                         else 
    67                                 return 0; 
    68         } 
    69  
    70         function recency( $u, $raw = false ) { 
    71                 $d0 =  get_simple_rs( getQuery( "get_fuq_slot_recency", $u )); 
    72  
    73                 $now = getdate(); 
    74                 $d1 = $now['year'] ."-". ($now['mon'] < 10 ? "0" : "" ) . $now['mon'] ."-". ($now['mday'] < 10 ? "0" : "" ) . $now['mday'] ." ". $now['hours'] .":". $now['minutes'] .":". $now['seconds']; 
    75                 $value = round( diff_in_secs( $d1, $d0 ) / 60 / 60 / 24, 3 ); 
     86        return mysql_result($q,0); 
     87
     88 
     89function get_fuq_threshold() { return 2; } 
     90 
     91function get_fuq( $u ) { 
     92        $con = mysql_connect(); 
     93        mysql_selectdb( getDBName() ); 
     94        $qs = getQuery( "get_fuq", $u ); 
     95 
     96        $q = mysql_query( $qs ); 
     97        $num_rows = mysql_affected_rows($con); 
     98 
     99        if( $num_rows == 1 ) 
     100                return mysql_result($q, 0, "FUQ" ); 
     101        else  
     102                return 2; 
     103
     104 
     105function delta_time_between_links( $u, $raw = false ) { 
     106        $value = get_db_date_diff_in_days( getQuery( "get_fuq_slot_delta_time_between_links", $u )) * 60; 
     107        if( $raw ) 
    76108                return $value; 
    77         } 
    78  
    79         function length_of_usage( $u, $raw = false ) { 
    80                 $r0 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id DESC LIMIT 1;" ); 
    81                 $r1 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id ASC LIMIT 1;" ); 
    82                 $value = round( diff_in_secs( $r0, $r1 ) / 60 / 60 / 24, 1 ); 
    83                 return $value; 
    84         } 
    85  
    86         #loops through the fuq metrics, calculating each of them, and mashes them together to re-calculate a users FUQ 
    87         function recalculate_fuq( $u ) { 
    88  
    89                 # calculate new fuq: 
    90                 $new_fuq = get_fuq( $u ); 
    91  
    92                 $slots = array(  
    93                         "delta_time_between_links" => 0,  
    94                         "length_of_usage" => 0  
    95                 ); 
    96  
    97                 foreach( $slots as $key => $value ) { $slots[$key] =  call_user_func( $key, $u ); } 
    98  
    99                 # mash together slot values here: 
    100                 # TBD 
    101  
    102                 #foreach( $slots as $slot ) { echo "\$slot = $slot<br>"; } 
    103  
    104                 return; 
    105  
    106                 # this method sig changed: run_query( getQuery( "update_fuq", $u, $new_fuq )); # and then set it 
    107                 # this will break now: return $new_fuq; 
    108         } 
    109  
    110         function run_query( $qs ) { 
    111     $con = mysql_connect(); 
    112     mysql_selectdb( getDBName() ); 
    113     $q = mysql_query( $qs ); 
    114     return $q; 
    115         } 
    116  
    117         function run_count( $qs ) { 
    118     $con = mysql_connect(); 
    119     mysql_selectdb( getDBName() ); 
    120                 $q = mysql_query( $qs ); 
    121  
    122                 if( $q ) 
    123                  return mysql_result($q,0); 
     109        else 
     110                if( $value < 0.5 ) 
     111                        return -1; 
     112                else if( $value > 10 ) 
     113                        return 1; 
    124114                else 
    125115                        return 0; 
    126         } 
    127  
    128         # usr dirs are of the path /usr/u/username 
    129         function get_user_folder( $u ) { 
    130                 if( !$u )  
    131                         return "usr/NO_PROFILE/"; 
     116
     117 
     118function recency( $u, $raw = false ) { 
     119        $d0 =  get_simple_rs( getQuery( "get_fuq_slot_recency", $u )); 
     120 
     121        $now = getdate(); 
     122        $d1 = $now['year'] ."-". ($now['mon'] < 10 ? "0" : "" ) . $now['mon'] ."-". ($now['mday'] < 10 ? "0" : "" ) . $now['mday'] ." ". $now['hours'] .":". $now['minutes'] .":". $now['seconds']; 
     123        $value = round( diff_in_secs( $d1, $d0 ) / 60 / 60 / 24, 3 ); 
     124        return $value; 
     125
     126 
     127function length_of_usage( $u, $raw = false ) { 
     128        $r0 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id DESC LIMIT 1;" ); 
     129        $r1 = get_simple_rs( "SELECT createDate FROM links WHERE submitter = '" . urlencode( $u ) . "' ORDER BY id ASC LIMIT 1;" ); 
     130        $value = round( diff_in_secs( $r0, $r1 ) / 60 / 60 / 24, 1 ); 
     131        return $value; 
     132
     133 
     134#loops through the fuq metrics, calculating each of them, and mashes them together to re-calculate a users FUQ 
     135function recalculate_fuq( $u ) { 
     136 
     137        # calculate new fuq: 
     138        $new_fuq = get_fuq( $u ); 
     139 
     140        $slots = array(  
     141                "delta_time_between_links" => 0,  
     142                "length_of_usage" => 0  
     143        ); 
     144 
     145        foreach( $slots as $key => $value ) { $slots[$key] =  call_user_func( $key, $u ); } 
     146 
     147        # mash together slot values here: 
     148        # TBD 
     149 
     150        #foreach( $slots as $slot ) { echo "\$slot = $slot<br>"; } 
     151 
     152        return; 
     153 
     154        # this method sig changed: run_query( getQuery( "update_fuq", $u, $new_fuq )); # and then set it 
     155        # this will break now: return $new_fuq; 
     156
     157 
     158function run_query( $qs ) { 
     159        $con = mysql_connect(); 
     160        mysql_selectdb( getDBName() ); 
     161        $q = mysql_query( $qs ); 
     162        return $q; 
     163
     164 
     165function run_count( $qs ) { 
     166        $con = mysql_connect(); 
     167        mysql_selectdb( getDBName() ); 
     168        $q = mysql_query( $qs ); 
     169 
     170        if( $q ) 
     171         return mysql_result($q,0); 
     172        else 
     173                return 0; 
     174
     175 
     176# usr dirs are of the path /usr/u/username 
     177function get_user_folder( $u ) { 
     178        if( !$u )  
     179                return "usr/NO_PROFILE/"; 
     180        else 
     181                return "usr/" . substr( $u, 0, 1 ) . "/" . $u; 
     182
     183 
     184function ajax_edit( $u, $tok, $type, $subtype, $l, $new_value, $use_xajax = false ) { 
     185        if( ! auth( $u, $tok ) ) 
     186                return; 
     187        $con = mysql_connect(); 
     188        mysql_selectdb( getDBName() ); 
     189 
     190        $new_value = o( $new_value ); 
     191        if( $type == "checkbox" ) 
     192                $new_value = ($new_value == 'false') ? "NULL" : 1; 
     193 
     194        $qs = getQuery( "edit_$subtype", "$new_value", $l, $u ); 
     195 
     196        if( $debug ) echo "DEBUG: $qs<br>"; 
     197        $arg = "$u, $tok, $type, $subtype, $l, $new_value, $use_xajax"; 
     198 
     199        $q = mysql_query( $qs ); 
     200        $num_rows = mysql_affected_rows($con); 
     201        $e = mysql_error($con); 
     202 
     203        if( $debug ) echo "\$q: $q<br>"; 
     204        if( $debug ) echo "\$num_rows: $num_rows<br>"; 
     205 
     206        if( $num_rows > 0 || ! $e ) 
     207                $success = "success"; 
     208 
     209        $safe_value = preg_replace( "/'/", "\'", $new_value ); 
     210         
     211        conClose( $con ); 
     212        if( $use_xajax ) { 
     213                $objResponse = new xajaxResponse(); 
     214                if( $success ) 
     215                        $objResponse->addScript( "update_" . $type . "_after_save( '$safe_value' );" ); 
    132216                else 
    133                         return "usr/" . substr( $u, 0, 1 ) . "/" . $u; 
    134         } 
    135  
    136         function ajax_edit( $u, $tok, $type, $subtype, $l, $new_value, $use_xajax = false ) { 
    137                 if( ! auth( $u, $tok ) ) 
     217                        $objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>$qs / $arg)</b>!!!" ); 
     218                #$objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>Database $e (edit_$subtype / $qs / $arg)</b>!!!" ); 
     219                // FIXME: in the above else case, also unroll the edit also so the user can try again 
     220                return $objResponse->getXML(); 
     221        } else 
     222                return $success ? true : ""; 
     223
     224 
     225function add_tags_from_request( $u, $newLinkID, $catNums, $con ) { 
     226        if( $debug ) echo "<hr>"; 
     227 
     228        $newCatNames = Array(); 
     229 
     230        foreach( $_POST as $paramName => $newCatName ) { 
     231                if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { 
     232                        array_push( $newCatNames, $newCatName ); 
     233                } 
     234        } 
     235 
     236        foreach( $_GET as $paramName => $newCatName ) { 
     237                if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { 
     238                        array_push( $newCatNames, $newCatName ); 
     239                } 
     240        } 
     241 
     242        if( $debug ) { 
     243                echo "User entered " . count( $newCatNames ) . " 'new' tags: "; 
     244                print_r( $newCatNames ); 
     245                echo "<br>And " . count( $catNums ) . " existing tags: "; 
     246                print_r( $catNums ); 
     247                echo "<br>"; 
     248        } 
     249 
     250        if( count( $newCatNames )) { 
     251                foreach( $newCatNames as $newCategoryName ) { 
     252                        if( $debug ) 
     253                                echo "First we add any tags that are actually new, then we tag the link w/all the remaining existing tags:<br />"; 
     254                        $categoryAlreadyExists = getIdForFolder( $newCategoryName, $u ); 
     255                        if( ! $categoryAlreadyExists ) { 
     256                                if( $debug ) 
     257                                        echo "User $u correctly claims s/he has no " . getCatName() . " called '$newCategoryName' yet...<br />"; 
     258                                $newCatNum = addFolder( $newCategoryName, $u ); 
     259                                if( $debug ) 
     260                                        echo "added $newCategoryName successfully as: \$newCatNum: $newCatNum<br />"; 
     261                                if( $newCatNum ) 
     262                                        array_push( $catNums, $newCatNum ); 
     263                        } else 
     264                                # user actually already had this tag, so just push it onto the rest of the existing tags to tag this link with 
     265                                array_push( $catNums, $categoryAlreadyExists ); 
     266                } 
     267        } else { 
     268                if( $debug ) 
     269                        echo "no new " . getCatsName() . " to be added, adding to existing " . getCatsName() . "...<br />"; 
     270        } 
     271 
     272        #starting sentinal value: 
     273        $q = "bogus query"; 
     274 
     275        if( $debug )  
     276                echo "<br />DEBUG: looping over " . (count($catNums)) . " tags"; 
     277        foreach( $catNums as $catNum ) { 
     278                if( ! $q || ! $catNum ) 
    138279                        return; 
    139                 $con = mysql_connect(); 
    140                 mysql_selectdb( getDBName() ); 
    141  
    142                 $new_value = o( $new_value ); 
    143                 if( $type == "checkbox" ) 
    144                         $new_value = ($new_value == 'false') ? "NULL" : 1; 
    145  
    146                 $qs = getQuery( "edit_$subtype", "$new_value", $l, $u ); 
    147  
    148                 if( $debug ) echo "DEBUG: $qs<br>"; 
    149                 $arg = "$u, $tok, $type, $subtype, $l, $new_value, $use_xajax"; 
    150  
     280                if( $debug ) echo "<br />"; 
     281 
     282                $qs = getQuery( "add_new_category_xref", $newLinkID, $catNum ); 
     283                if( $debug ) 
     284                        echo "DEBUG: $qs"; 
    151285                $q = mysql_query( $qs ); 
    152                 $num_rows = mysql_affected_rows($con); 
    153                 $e = mysql_error($con); 
    154  
    155                 if( $debug ) echo "\$q: $q<br>"; 
    156                 if( $debug ) echo "\$num_rows: $num_rows<br>"; 
    157  
    158                 if( $num_rows > 0 || ! $e ) 
    159                         $success = "success"; 
    160  
    161                 $safe_value = preg_replace( "/'/", "\'", $new_value ); 
    162                  
    163                 conClose( $con ); 
    164                 if( $use_xajax ) { 
    165                         $objResponse = new xajaxResponse(); 
    166                         if( $success ) 
    167                                 $objResponse->addScript( "update_" . $type . "_after_save( '$safe_value' );" ); 
    168                         else 
    169                                 $objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>$qs / $arg)</b>!!!" ); 
    170                         #$objResponse->addAssign( "content-hook", "innerHTML", "Oops, we messed up: <b>Database $e (edit_$subtype / $qs / $arg)</b>!!!" ); 
    171                         // FIXME: in the above else case, also unroll the edit also so the user can try again 
    172                         return $objResponse->getXML(); 
    173                 } else 
    174                         return $success ? true : ""; 
    175         } 
    176  
    177         function add_tags_from_request( $u, $newLinkID, $catNums, $con ) { 
    178                 if( $debug ) echo "<hr>"; 
    179  
    180                 $newCatNames = Array(); 
    181  
    182                 foreach( $_POST as $paramName => $newCatName ) { 
    183                         if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { 
    184                                 array_push( $newCatNames, $newCatName ); 
    185                         } 
    186                 } 
    187  
    188                 foreach( $_GET as $paramName => $newCatName ) { 
    189                         if( substr( $paramName, 0, strlen( "new_tag" )) == "new_tag" && $newCatName) { 
    190                                 array_push( $newCatNames, $newCatName ); 
    191                         } 
    192                 } 
    193  
    194                 if( $debug ) { 
    195                         echo "User entered " . count( $newCatNames ) . " 'new' tags: "; 
    196                         print_r( $newCatNames ); 
    197                         echo "<br>And " . count( $catNums ) . " existing tags: "; 
    198                         print_r( $catNums ); 
    199                         echo "<br>"; 
    200                 } 
    201  
    202                 if( count( $newCatNames )) { 
    203                         foreach( $newCatNames as $newCategoryName ) { 
    204                                 if( $debug ) 
    205                                         echo "First we add any tags that are actually new, then we tag the link w/all the remaining existing tags:<br />"; 
    206                                 $categoryAlreadyExists = getIdForFolder( $newCategoryName, $u ); 
    207                                 if( ! $categoryAlreadyExists ) { 
    208                                         if( $debug ) 
    209                                                 echo "User $u correctly claims s/he has no " . getCatName() . " called '$newCategoryName' yet...<br />"; 
    210                                         $newCatNum = addFolder( $newCategoryName, $u ); 
    211                                         if( $debug ) 
    212                                                 echo "added $newCategoryName successfully as: \$newCatNum: $newCatNum<br />"; 
    213                                         if( $newCatNum ) 
    214                                                 array_push( $catNums, $newCatNum ); 
    215                                 } else 
    216                                         # user actually already had this tag, so just push it onto the rest of the existing tags to tag this link with 
    217                                         array_push( $catNums, $categoryAlreadyExists ); 
    218                         } 
    219                 } else { 
    220                         if( $debug ) 
    221                                 echo "no new " . getCatsName() . " to be added, adding to existing " . getCatsName() . "...<br />"; 
    222                 } 
    223  
    224                 #starting sentinal value: 
    225                 $q = "bogus query"; 
    226  
    227                 if( $debug )  
    228                         echo "<br />DEBUG: looping over " . (count($catNums)) . " tags"; 
    229                 foreach( $catNums as $catNum ) { 
    230                         if( ! $q || ! $catNum ) 
    231                                 return; 
    232                         if( $debug ) echo "<br />"; 
    233  
    234                         $qs = getQuery( "add_new_category_xref", $newLinkID, $catNum ); 
    235                         if( $debug ) 
    236                                 echo "DEBUG: $qs"; 
    237                         $q = mysql_query( $qs ); 
    238                         if( ! $q ) { 
    239                                 $e = mysql_error($con); 
    240                                 $tok = get_mysql_dupe_error(); 
    241                                 if( ! strstr( $e, $tok)) { 
     286                if( ! $q ) { 
     287                        $e = mysql_error($con); 
     288                        $tok = get_mysql_dupe_error(); 
     289                        if( ! strstr( $e, $tok)) { 
    242290%> 
    243291<div class="attention warning"> 
     
    246294</div> 
    247295<% 
    248                                         break; 
    249                                 } else { 
    250                                         e( "already tagged w/that tag -- no worries!" ); 
    251                                         # fake a real result set so our caller thinks we succeeded, since we did 
    252                                         $q = 1; 
    253                                 } 
     296                                break; 
     297                        } else { 
     298                                e( "already tagged w/that tag -- no worries!" ); 
     299                                # fake a real result set so our caller thinks we succeeded, since we did 
     300                                $q = 1; 
    254301                        } 
    255302                } 
    256         return $q; 
     303        } 
     304return $q; 
    257305}  
    258306 
    259307 
    260        function get_mysql_dupe_error() { 
    261                return "Duplicate entry"; 
    262        
     308function get_mysql_dupe_error() { 
     309        return "Duplicate entry"; 
     310
    263311 
    264312        function dumpParams() { 
     
    911959        .peepBox { 
    912960                float: left;  
    913                 border: 1px solid #555555;  
    914                 height: 68px; 
    915                 width: 64px; 
    916                 padding: 1em; 
    917                 margin: 0.5em; 
     961                height: 90px; 
     962                width: 94px; 
     963                padding: 0.2em; 
     964                margin: 0.1em; 
    918965                background-color: #FFFFFF; 
    919966        } 
     
    929976<% 
    930977                        foreach( $argUsers as $user => $junk ) { 
     978                        $t = get_thumbnail_image( $user ); 
    931979%> 
    932980                <div class="peepBox" style="text-align: center"> 
    933                 <a href="/u/<%= $user %>"><% getSizedUserImage( $user, 58 ) %></a> 
    934  
    935                         <small><%= getBareUserLink( $user ) %></small><% 
    936                         if( $argUser == get_user() ) { %>&nbsp;<small><small>[<a class="subtle" href="remove?user=<%= $user %>">x</a>]</small></small> 
    937                         <% } %> 
     981                        <a href="/u/<%= $user %>"><img src="<%= $t %>" border="0" /></a> 
     982                        <br clear="all" /> 
     983                        <%= getBareUserLink( $user ) %> 
    938984                </div> 
    939985<% 
    940986                        $c++; 
    941                         if( $c % 4 == 0 ) 
     987                        if( $c % 7 == 0 ) 
    942988                                echo '<br clear="all"/>'; 
    943989                } 
     
    18271873} 
    18281874 
     1875function get_user_image( $u, $thingy ) { 
     1876        $exts = array( "gif", "jpg", "jpeg", "png" ); 
     1877        foreach ($exts as $ext) { 
     1878                $f = get_user_folder( $u ) . "/$thingy.$ext"; 
     1879                if( is_file( get_root() . "/" . $f )) { 
     1880                        return $f; 
     1881                } 
     1882        } 
     1883} 
     1884 
     1885function get_thumbnail_image( $u ) { 
     1886        if( ! is_file( get_user_image( $u, "thumb" )) && is_file( get_profile_image( $u ))) 
     1887                make_thumbnail_for_user( $u ); 
     1888        if( ! is_file( get_user_image( $u, "thumb" ))) 
     1889                return "/usr/NO_PROFILE/thumb.png"; 
     1890        else 
     1891                return get_user_image( $u, "thumb" ); 
     1892} 
     1893 
     1894function get_profile_image( $u ) { 
     1895        return get_user_image( $u, "profile" ); 
     1896} 
     1897 
    18291898function removeOldProfileImage( $u ) { 
    1830                 $exts = array( "gif", "jpg", "jpeg", "png" ); 
    1831                 foreach ($exts as $ext) { 
    1832                         $f =  get_root() . "/" . get_user_folder( $u ) . "/profile.$ext"; 
    1833                         if( is_file( $f )) { 
    1834                                 unlink( $f ); 
    1835                         } 
    1836                 } # end foreach 
    1837         } 
     1899        if( $u ) 
     1900                unlink( get_profile_image( $u )); 
     1901
    18381902 
    18391903function showUserImage( $u ) { 
     
    18421906 
    18431907function getSizedUserImage( $u, $pxl_size ) { 
    1844 ob_start(); 
    1845                 $exts = array( "gif", "jpg", "jpeg", "png" ); 
    1846                 foreach ($exts as $ext) { 
    1847                         $f = get_root() . "/" . get_user_folder( $u ) . "/profile.$ext"; 
    1848                         if( is_file( $f )) { 
    1849 %> 
    1850         <img src="/<%= get_user_folder( $u ) %>/profile.<%= $ext %>" width="<%= $pxl_size %>" class="profileImage" alt="" border="0" > 
    1851 <% 
    1852                                 return; 
    1853                         } 
    1854                 } # end foreach 
    1855 %> 
    1856         <img src="/usr/NO_PROFILE/profile.gif" height="<%= $pxl_size %>" class="profileImage" alt="" border="0" > 
    1857 <% 
     1908        ob_start(); 
     1909        $f = get_thumbnail_image( $u ); 
     1910        if( $f ) { 
     1911%> 
     1912        <img src="<%= $f %>" width="<%= $pxl_size %>" class="profileImage" alt="" border="0" > 
     1913<% 
     1914        } else { 
     1915%> 
     1916        <img src="/usr/NO_PROFILE/thumb.png" height="<%= $pxl_size %>" class="profileImage" alt="" border="0" > 
     1917<% 
     1918        } 
    18581919        $ret = ob_get_clean(); 
    18591920        echo $ret; 
    1860  
    1861         } 
     1921
    18621922 
    18631923function auth( $u, $tok ) { 
     
    28372897 
    28382898function getBareUserLink( $userId ) { 
    2839         return "<a title=\"view user info\" href=\"/u/" . $userId . "\">$userId</a>"; 
     2899        return "<a title=\"view user info\" href=\"/u/" . $userId . "\">" . getCompactString( $userId, 9 ) . "</a>"; 
    28402900} 
    28412901 
  • feedmelinks/testing/new-profile-icons.php

    r1072 r1075  
     1<html> 
     2<head> 
    13<title> 
    24        Test page: Create thumbnail for user 
    35<title> 
     6</head> 
     7<body bgcolor="cadetblue"> 
     8 
    49<% 
    510        include_once( "../modules/utils.inc.php" ); 
     
    1419                <option value="pheezy">pheezy</option> 
    1520                <option value="jm3">jm3</option> 
     21                <option value="NO_PROFILE">NO_PROFILE</option> 
    1622                <option value="eyeofaphrodite">eyeofaphrodite</option> 
    1723        </select> 
     
    2127        if( $user ) { 
    2228                $i = make_thumbnail_for_user( $user ); 
    23                 echo "created thumbnail: <br/><a href='$i'><img src='$i' border='0'/></a> <br/>"; 
     29                echo "created thumbnail: <p>$i</p> <a href='$i'><img src='$i' border='0'/></a> <br/>"; 
     30                $raw = get_profile_image( $user ); 
     31                echo "\nfrom: <a href='$raw'><img src='/$raw' border='0'/></a> <br/>"; 
    2432        } 
    2533         
    26         # returns the PATH to the newly created thumbnail 
    27         function make_thumbnail_for_user( $u ) { 
    28                 $i = get_profile_image( $u ); 
    29                 $out = "/" . get_user_folder( $u ) . "/thumb.png"; 
    30                 imagepng( get_png_thumbnail_from_image( $i ), get_root() . $out ); 
    31                 return $out; 
    32         } 
    33  
    34         # returns an image OBJECT of the newly created thumbnail 
    35         function get_png_thumbnail_from_image( $i ) { 
    36                 $goal = 64; 
    37                 list($width, $height, $type, $attr) = getimagesize( $i ); 
    38  
    39                 #calculate which is the shorter side, re-map that to $goal, and calculate the new length of the longer side 
    40                 $tall = ( $width < $height ) ? true : false; 
    41                 $new_height = $new_width = $goal; 
    42                 if( $tall ) { 
    43                         $frac = $goal / $width; 
    44                         $new_height = $height * $frac; 
    45                 } else { 
    46                         $frac = $goal / $height; 
    47                         $new_width = $width * $frac; 
    48                 } 
    49  
    50                 switch( $type ){ 
    51                         case 1 : $orig = imagecreatefromgif($i);  break; 
    52                         case 2 : $orig = imagecreatefromjpeg($i); break; 
    53                         case 3 : $orig = imagecreatefrompng($i);  break; 
    54                         default: break; 
    55                 } 
    56  
    57                 # resize it: 
    58                 $small = imagecreatetruecolor( $new_width, $new_height ); 
    59                 imagecopyresampled( $small, $orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); 
    60                 imagepng( $small, "icons/small.png" ); 
    61  
    62                 # new black-bordered palette to copy onto: 
    63                 $cropped = imagecreatetruecolor( $goal + 2, $goal + 2 ); 
    64                 imagefill( $cropped, 0, 0, imagecolorallocate( $cropped, 0, 0, 0 )); 
    65  
    66                 # crop image onto black 
    67                 imagecopy($cropped, $small, 1, 1, ceil( ($new_width - $goal) / 2), ceil( ($new_height - $goal) / 2), $goal, $goal); 
    68  
    69                 imagedestroy($small); 
    70                 imagedestroy($orig); 
    71                 return $cropped; 
    72         } 
    73  
    7434%> 
     35</body> 
     36</html> 
  • feedmelinks/users.php

    r856 r1075  
    8989        <br /> 
    9090 
    91         <% showUserImage( $userId ); %
     91        <img src="<%= get_profile_image( $userId ) %>" width="200" /
    9292 
    9393        <br />