Changeset 19976

Show
Ignore:
Timestamp:
09/26/08 21:33:26 (5 years ago)
Author:
kenji
Message:

Update helper to show picture and Add helper to show posted time

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/codeigniter/trunk/system/application/helpers/MY_url_helper.php

    r19450 r19976  
    66} 
    77 
    8 function picture($size) 
     8function picture($username, $image, $size, $class) 
    99{ 
    10         $CI =& get_instance(); 
    11         $username = $CI->session->userdata('username'); 
    12         $image = $CI->session->userdata('image'); 
     10        $str  = ''; 
     11        $attr = ''; 
     12 
     13        if ($username) 
     14        { 
     15                $attr = 'alt="' . $username . '" '; 
     16        } 
     17 
     18        if ($class) 
     19        { 
     20                $attr .= 'class="' . $class . '" '; 
     21        } 
     22 
    1323        if ($image) 
    1424        { 
     
    1626                $ext = '.' . end($x); 
    1727                $raw_name = str_replace($ext, '', $image); 
     28 
    1829                if ($size == 31) 
    1930                { 
     
    3243        switch ($size) { 
    3344                case 24: 
    34                         $str = '<img src="' . base_url() . $filename . '" height="24" width="24">'; 
     45                        $str = '<img src="' . base_url() . $filename . '" ' . $attr . 'height="24" width="24" />'; 
    3546                        break; 
    3647                case 31: 
    37                         $str = '<img src="' . base_url() . $filename . '" height="31" width="31">'; 
     48                        $str = '<img src="' . base_url() . $filename . '" ' . $attr . 'height="31" width="31" />'; 
    3849                        break; 
    3950                case 48: 
    40                         $str = '<img src="' . base_url() . $filename . '" height="48" width="48">'; 
     51                        $str = '<img src="' . base_url() . $filename . '" ' . $attr . 'height="48" width="48" />'; 
    4152                        break; 
    4253                case 73: 
    43                         $str = '<img src="' . base_url() . $filename . '" height="73" width="73">'; 
     54                        $str = '<img src="' . base_url() . $filename . '" ' . $attr . 'height="73" width="73" />'; 
    4455                        break; 
    4556        } 
     
    4758        return $str; 
    4859} 
     60 
     61function my_pict($size) 
     62{ 
     63        $CI =& get_instance(); 
     64        $image = $CI->session->userdata('image'); 
     65 
     66        return picture('', $image, $size, ''); 
     67} 
     68 
     69 
     70/* 本来は date helper かな */ 
     71function posted_time($time) 
     72{ 
     73        $elapsed = time() - $time; 
     74 
     75        if ($elapsed < 60) 
     76        { 
     77                $str = (intval($elapsed / 5) + 1) * 5 . '秒以内'; 
     78        } 
     79        else if ($elapsed < 60 * 60) 
     80        { 
     81                $str = '約' . round($elapsed / 60) . '分前'; 
     82        } 
     83        else if ($elapsed < 60 * 60 * 24) 
     84        { 
     85                $str = '約' . round($elapsed / (60 * 60)) . '時間前'; 
     86        } 
     87        else 
     88        { 
     89                $str = date('h:i A F d, Y', $time); 
     90        } 
     91 
     92        return $str; 
     93}