Changeset 20831 for events

Show
Ignore:
Timestamp:
10/06/08 10:48:41 (2 months ago)
Author:
kenji
Message:

Add auto link of comments

Location:
events/phpframework/codeigniter/trunk/system/application
Files:
13 modified

Legend:

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

    r20307 r20831  
    174174| 
    175175*/ 
    176 $config['log_threshold'] = 1; 
     176$config['log_threshold'] = 4; 
    177177 
    178178/* 
  • events/phpframework/codeigniter/trunk/system/application/config/database.php

    r18734 r20831  
    4747$db['default']['db_debug'] = TRUE; 
    4848$db['default']['cache_on'] = FALSE; 
    49 $db['default']['cachedir'] = ""; 
     49$db['default']['cachedir'] = BASEPATH . "cache/"; 
    5050$db['default']['char_set'] = "utf8"; 
    5151$db['default']['dbcollat'] = "utf8_general_ci"; 
  • events/phpframework/codeigniter/trunk/system/application/controllers/public_timeline.php

    r20346 r20831  
    1111        function index() 
    1212        { 
     13                $this->output->enable_profiler(TRUE); 
     14 
    1315                $this->load->helper('url'); 
    1416                $this->load->model('Status_model', '', TRUE); 
    1517 
     18$this->db->cache_on(); 
     19                $data->list   = $this->Status_model->get_public_timeline(); 
     20$this->db->cache_off(); 
    1621 
    17                 $data->list   = $this->Status_model->get_public_timeline(); 
    1822                $data->title  = 'Phwittr'; 
    1923 
  • events/phpframework/codeigniter/trunk/system/application/controllers/status.php

    r20373 r20831  
    6666                        $data->image    = $this->session->userdata('image'); 
    6767                         
    68                         $comment = h($comment); 
     68                        $comment = auto_link(h($comment), 'url'); 
    6969                        if ($reply_username) { 
    7070                                $comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $reply_username), $reply_username) . ' ', $comment); 
  • events/phpframework/codeigniter/trunk/system/application/helpers/MY_url_helper.php

    r20754 r20831  
    11<?php 
    22 
     3/* 本来は HTML helper かな */ 
    34function h($string) 
    45{ 
    5     return htmlspecialchars($string, ENT_QUOTES); 
     6        return htmlspecialchars($string, ENT_QUOTES); 
    67} 
    78 
     9/* 本来は HTML helper かな */ 
    810function picture($username, $image, $size, $class) 
    911{ 
     
    6769} 
    6870 
     71/* 本来は HTML helper かな */ 
    6972function my_pict($size) 
    7073{ 
     
    7578} 
    7679 
     80/* 本来は HTML helper かな */ 
    7781function js($js = 'default', $timestamp = TRUE) 
    7882{ 
     
    123127        return $str; 
    124128} 
     129 
     130/* auto_link() を一部修正 */ 
     131if ( ! function_exists('auto_link')) 
     132{ 
     133        function auto_link($str, $type = 'both', $popup = FALSE) 
     134        { 
     135                if ($type != 'email') 
     136                {                
     137                        if (preg_match_all("#((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)) 
     138                        { 
     139                                $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; 
     140 
     141                                for ($i = 0; $i < sizeof($matches['0']); $i++) 
     142                                { 
     143                                        $period = ''; 
     144                                        if (preg_match("|\.$|", $matches['5'][$i])) 
     145                                        { 
     146                                                $period = '.'; 
     147                                                $matches['5'][$i] = substr($matches['5'][$i], 0, -1); 
     148                                        } 
     149 
     150                                        $str = str_replace($matches['0'][$i], 
     151                                                                                '<a href="http'. 
     152                                                                                $matches['3'][$i].'://'. 
     153                                                                                $matches['4'][$i]. 
     154                                                                                $matches['5'][$i].'"'.$pop.'>http'. 
     155                                                                                $matches['3'][$i].'://'. 
     156                                                                                $matches['4'][$i]. 
     157                                                                                $matches['5'][$i].'</a>'. 
     158                                                                                $period, $str); 
     159                                } 
     160                        } 
     161                } 
     162 
     163                if ($type != 'url') 
     164                {        
     165                        if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) 
     166                        { 
     167                                for ($i = 0; $i < sizeof($matches['0']); $i++) 
     168                                { 
     169                                        $period = ''; 
     170                                        if (preg_match("|\.$|", $matches['3'][$i])) 
     171                                        { 
     172                                                $period = '.'; 
     173                                                $matches['3'][$i] = substr($matches['3'][$i], 0, -1); 
     174                                        } 
     175 
     176                                        $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); 
     177                                } 
     178 
     179                        } 
     180                } 
     181                return $str; 
     182        } 
     183} 
  • events/phpframework/codeigniter/trunk/system/application/models/status_model.php

    r20315 r20831  
    66        { 
    77                parent::Model(); 
    8                 $this->load->helper('date'); 
    98        } 
    109 
     
    2423                        $statuses->reply_user_id = ''; 
    2524                } 
     25 
     26                $this->load->helper('date'); 
    2627                $statuses->comment       = $comment; 
    2728                $statuses->created_at    = mdate('%Y-%m-%d %H:%i:%s'); 
    2829 
    29                 $this->db->insert('statuses', $statuses); 
     30                if ($this->db->insert('statuses', $statuses)) 
     31                { 
     32                        $this->db->cache_delete('public_timeline', 'index'); 
     33                } 
    3034                $id = $this->db->insert_id(); 
    3135 
     
    6064                $statuses['user_id'] = $user_id; 
    6165 
    62                 return($this->db->delete('statuses', $statuses)); 
     66                if ($ret = $this->db->delete('statuses', $statuses)) 
     67                { 
     68                        $this->db->cache_delete('public_timeline', 'index'); 
     69                } 
     70 
     71                return $ret; 
    6372        } 
    6473 
  • events/phpframework/codeigniter/trunk/system/application/views/home/main.php

    r20301 r20831  
    3434                                <p class="murmur"> 
    3535                                <?=anchor(site_url('user/index/' . $row->username), $row->username)?> 
    36                                 <?php  
    37                                         $row->comment = h($row->comment); 
     36                                <?php 
     37                                        $row->comment = auto_link(h($row->comment), 'url'); 
    3838                                        if ($row->reply_username) { 
    3939                                                $row->comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $row->reply_username), $row->reply_username) . ' ', $row->comment); 
  • events/phpframework/codeigniter/trunk/system/application/views/home/main_archive.php

    r20302 r20831  
    3434                        <td> 
    3535                                <p class="murmur"> 
    36                                 <?php  
    37                                         $row->comment = h($row->comment); 
     36                                <?php 
     37                                        $row->comment = auto_link(h($row->comment), 'url'); 
    3838                                        if ($row->reply_username) { 
    3939                                                $row->comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $row->reply_username), $row->reply_username) . ' ', $row->comment); 
  • events/phpframework/codeigniter/trunk/system/application/views/home/main_reply.php

    r20297 r20831  
    3535                                <p class="murmur"> 
    3636                                <?=anchor(site_url('user/index/' . $row->username), $row->username)?> 
    37                                 <?=h($row->comment)?> 
     37                                <?=auto_link(h($row->comment), 'url')?> 
    3838                                <?=anchor(site_url('user/statuses/' . $row->username . '/' . $row->id), posted_time($row->created_at))?> 
    3939                                </p> 
  • events/phpframework/codeigniter/trunk/system/application/views/public_timeline/main.php

    r20374 r20831  
    1212                                <p class="murmur"> 
    1313                                <?=anchor(site_url('user/index/' . $row->username), $row->username)?> 
    14                                 <?php  
    15                                         $row->comment = h($row->comment); 
     14                                <?php 
     15                                        $row->comment = auto_link(h($row->comment), 'url'); 
    1616                                        if ($row->reply_username) { 
    1717                                                $row->comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $row->reply_username), $row->reply_username) . ' ', $row->comment); 
  • events/phpframework/codeigniter/trunk/system/application/views/public_timeline/main_logged_in.php

    r20302 r20831  
    3434                                <p class="murmur"> 
    3535                                <?=anchor(site_url('user/index/' . $row->username), $row->username)?> 
    36                                 <?php  
    37                                         $row->comment = h($row->comment); 
     36                                <?php 
     37                                        $row->comment = auto_link(h($row->comment), 'url'); 
    3838                                        if ($row->reply_username) { 
    3939                                                $row->comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $row->reply_username), $row->reply_username) . ' ', $row->comment); 
  • events/phpframework/codeigniter/trunk/system/application/views/user/main.php

    r20402 r20831  
    7171                        <td> 
    7272                                <p class="murmur"> 
    73                                 <?php  
    74                                         $row->comment = h($row->comment); 
     73                                <?php 
     74                                        $row->comment = auto_link(h($row->comment), 'url'); 
    7575                                        if ($row->reply_username) { 
    7676                                                $row->comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $row->reply_username), $row->reply_username) . ' ', $row->comment); 
  • events/phpframework/codeigniter/trunk/system/application/views/user/main_comment.php

    r20309 r20831  
    55                <?php foreach($list as $row):?> 
    66                                <p> 
    7                                 <?php  
    8                                         $row->comment = h($row->comment); 
     7                                <?php 
     8                                        $row->comment = auto_link(h($row->comment), 'url'); 
    99                                        if ($row->reply_username) { 
    1010                                                $row->comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $row->reply_username), $row->reply_username) . ' ', $row->comment);