Assembla home | Assembla project page
 

Changeset 238

Show
Ignore:
Timestamp:
04/14/08 22:53:57 (7 months ago)
Author:
Slynderdale
Message:

PHP has been improved to display a link to the function's PHP manual page as well as return the function's description as well. All credit for these changes goes to kodekrash.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/Php.php

    r235 r238  
    3030 
    3131    /** 
     32     * Cleans up the given string and decodes and transliterates a UTF-8 string 
     33     * into corresponding ASCII characters 
     34     * 
     35     * @return string 
     36     */ 
     37    private function decode($str) 
     38    { 
     39        $str = str_replace( '—', '-', $str); 
     40        $str = trim(preg_replace(array('/<[^>]+>/ms', '/\s+/ms'), array( '', ' ' ), $str)); 
     41        return $this->decodeTranslit($str); 
     42    } 
     43 
     44    /** 
    3245     * Intercepts, processes, and responds with the result of prototype lookup 
    3346     * requests. 
     
    3952    { 
    4053        if (!isset($this->cache[$function])) { 
    41             $name = str_replace('_', '-', $function); 
    42             $contents = file_get_contents('http://php.net/manual/en/function.' . rtrim($name, '();') . '.php'); 
    43             $start = strpos($contents, '<div class="methodsynopsis dc-description">'); 
    44             $end = strpos($contents, '</div>', $start); 
    45             $contents = substr($contents, $start, $end-$start); 
    46             $contents = preg_replace(array('/<[^>]+>/ms', '/\s+/ms'), array('', ' '), $contents); 
    47             $contents = trim(str_replace(' ,', ',', $contents)); 
     54            $name = str_replace(array('_', ' '), '-', $function); 
     55            $tmp = file_get_contents('http://php.net/manual/en/function.' . rtrim($name, '();') . '.php'); 
     56            if( strpos( $tmp, '<p class="refpurpose dc-title">' ) !== false ) { 
     57               $contents = '[ '.$this->tinyUrl('http://php.net/'.$name).' ] '; 
     58               if (preg_match( '/<div class="methodsynopsis dc-description">(.*?)<\/div>/mis', $tmp, $m)) { 
     59                  $contents .= $this->_clean($m[1]); 
     60               } 
     61               if (preg_match( '/<p class="refpurpose dc-title">(.*?)<\/p>/mis', $tmp, $m)) { 
     62                  $m = explode( '-', $this->_clean($m[1]), 2); 
     63                  $contents .= ' - '.$m[1]; 
     64               } 
     65               $contents = trim(str_replace(' ,', ',', $contents)); 
     66            } 
     67            else { 
     68                  $contents = 'Nothing found'; 
     69            } 
    4870            $this->cache[$function] = $contents; 
    4971        }