Changeset 2744

Show
Ignore:
Timestamp:
12/29/06 05:18:34 (2 years ago)
Author:
graphittie
Message:
  • createNewProperty() 함수의 고도화. 관련된 getAttributesFromString() 함수/멤버함수의 루틴 강화. -> 티스토리 소스(rev.4690)를 옮겨옴.
Location:
branches/1.1-beta
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1-beta/components/Tattertools.Function.misc.php

    r2458 r2744  
    2929    } 
    3030 
    31     function getAttributesFromString($str) { 
     31    function getAttributesFromString($str, $caseSensitive=false) { 
    3232        $attributes = array(); 
    3333        preg_match_all('/([^=\s]+)\s*=\s*"([^"]*)/', $str, $matches);  
    34         for($i=0; $i<count($matches[0]); $i++) 
     34        for($i=0; $i<count($matches[0]); $i++) { 
     35            if(!$caseSensitive) 
     36                $matches[1][$i] = strtolower($matches[1][$i]); 
    3537            $attributes[$matches[1][$i]] = $matches[2][$i]; 
     38        } 
    3639        preg_match_all('/([^=\s]+)\s*=\s*\'([^\']*)/', $str, $matches); 
    37         for($i=0; $i<count($matches[0]); $i++) 
     40        for($i=0; $i<count($matches[0]); $i++) { 
     41            if(!$caseSensitive) 
     42                $matches[1][$i] = strtolower($matches[1][$i]); 
    3843            $attributes[$matches[1][$i]] = $matches[2][$i]; 
     44        } 
    3945        preg_match_all('/([^=\s]+)=([^\'"][^\s]*)/', $str, $matches); 
    40         for($i=0; $i<count($matches[0]); $i++) 
     46        for($i=0; $i<count($matches[0]); $i++) { 
     47            if(!$caseSensitive) 
     48                $matches[1][$i] = strtolower($matches[1][$i]); 
    4149            $attributes[$matches[1][$i]] = $matches[2][$i]; 
     50        } 
    4251        return $attributes; 
    4352    } 
  • branches/1.1-beta/lib/function/misc.php

    r2227 r2744  
    2929} 
    3030 
    31 function getAttributesFromString($str) { 
     31function getAttributesFromString($str, $caseSensitive=true) { 
    3232    $attributes = array(); 
    3333    preg_match_all('/([^=\s]+)\s*=\s*"([^"]*)/', $str, $matches);  
    34     for($i=0; $i<count($matches[0]); $i++) 
     34    for($i=0; $i<count($matches[0]); $i++) { 
     35        if(!$caseSensitive) 
     36            $matches[1][$i] = strtolower($matches[1][$i]); 
    3537        $attributes[$matches[1][$i]] = $matches[2][$i]; 
     38    } 
    3639    preg_match_all('/([^=\s]+)\s*=\s*\'([^\']*)/', $str, $matches); 
    37     for($i=0; $i<count($matches[0]); $i++) 
     40    for($i=0; $i<count($matches[0]); $i++) { 
     41        if(!$caseSensitive) 
     42            $matches[1][$i] = strtolower($matches[1][$i]); 
    3843        $attributes[$matches[1][$i]] = $matches[2][$i]; 
     44    } 
    3945    preg_match_all('/([^=\s]+)=([^\'"][^\s]*)/', $str, $matches); 
    40     for($i=0; $i<count($matches[0]); $i++) 
     46    for($i=0; $i<count($matches[0]); $i++) { 
     47        if(!$caseSensitive) 
     48            $matches[1][$i] = strtolower($matches[1][$i]); 
    4149        $attributes[$matches[1][$i]] = $matches[2][$i]; 
     50    } 
    4251    return $attributes; 
    4352} 
  • branches/1.1-beta/lib/view/view.php

    r2732 r2744  
    19161916    if ($tempInfo = getimagesize(ROOT."/attach/$owner/$filename")) { 
    19171917        list($originWidth, $originHeight, $type, $attr) = $tempInfo; 
     1918        if($originWidth <= 0 || $originHeight <= 0 ) return array($property, false); 
    19181919    } else { 
    19191920        return array($property, false); 
    19201921    } 
    19211922     
    1922     //if (eregi('alt=""', $property)) { 
    1923     //  $property = str_replace('alt=""', 'alt="'._text('사용자 삽입 이미지').'"', $property); 
    1924     //} else if (eregi('alt="[^"]+"', $property)) { 
    1925         // 이미 있으므로 통과 
    1926     //} else { 
    1927     //  $property .= ' alt="'._text('사용자 삽입 이미지').'"';   
    1928     //} 
     1923    $attributes = getAttributesFromString($property, false); 
     1924 
     1925    if(array_key_exists('width', $attributes)) { 
     1926        if(preg_match('/([\d.]+)(%?)/', $attributes['width'], $matches)) { 
     1927            if($matches[2] == '%') 
     1928                $attributes['width'] = round($originWidth * $matches[1] / 100); 
     1929            else 
     1930                $attributes['width'] = intval($matches[1]); 
     1931        } 
     1932    } 
    19291933     
    1930     // 현재 이미지의 가로 사이즈 계산. 
    1931     if (eregi('width="([0-9]*%?)"', $property, $temp)) { 
    1932         $currentWidth = $temp[1]; 
    1933         if (eregi("^([0-9]+)%$", $currentWidth)) { 
    1934             $currentWidth = $originWidth * ($temp[1]/100); 
    1935         } 
    1936     } else { 
    1937         $property .= ' width="1"'; 
     1934    if(array_key_exists('height', $attributes)) { 
     1935        if(preg_match('/([\d.]+)(%?)/', $attributes['height'], $matches)) { 
     1936            if($matches[2] == '%') 
     1937                $attributes['height'] = round($originHeight * $matches[1] / 100); 
     1938            else 
     1939                $attributes['height'] = intval($matches[1]); 
     1940        } 
    19381941    } 
    19391942     
    1940     // 현재 이미지의 세로 사이즈 계산. 
    1941     if (eregi('height="([0-9]*%?)"', $property, $temp)) { 
    1942         $currentHeight = $temp[1]; 
    1943         if (eregi("^([0-9]+)%$", $currentHeight)) { 
    1944             $currentHeight = $originHeight * ($temp[1]/100); 
    1945         } 
    1946     } else { 
    1947         $property .= ' height="1"'; 
     1943    // 가로, 세로 어느 쪽이든 0이면 이미지는 표시되지 않음. 따라서 계산할 필요 없음. 
     1944    if ($attributes['width'] === 0 || $attributes['height'] === 0) { 
     1945        return array($property, false); 
    19481946    } 
    19491947     
    19501948    // 가로만 지정된 이미지의 경우. 
    1951     if (isset($currentWidth) && !isset($currentHeight)) { 
     1949    if (isset($attributes['width']) && !isset($attributes['height'])) { 
    19521950        // 비어있는 세로를 가로의 크기를 이용하여 계산. 
    1953         $currentHeight = floor($originHeight * $currentWidth / $originWidth); 
     1951        $attributes['height'] = floor($originHeight * $attributes['width'] / $originWidth); 
    19541952    // 세로만 지정된 이미지의 경우. 
    1955     } else if (!isset($currentWidth) && isset($currentHeight)) { 
     1953    } else if (!isset($attributes['width']) && isset($attributes['height'])) { 
    19561954        // 비어있는 가로를 세로의 크기를 이용하여 계산. 
    1957         $currentWidth = floor($originWidth * $currentHeight / $originHeight); 
     1955        $attributes['width'] = floor($originWidth * $attributes['height'] / $originHeight); 
    19581956    // 둘 다 지정되지 않은 이미지의 경우. 
    1959     } else if (!isset($currentWidth) && !isset($currentHeight)) { 
     1957    } else if (!isset($attributes['width']) && !isset($attributes['height'])) { 
    19601958        // 둘 다 비어 있을 경우는 오리지널 사이즈로 대치. 
    1961         $currentWidth = $originWidth; 
    1962         $currentHeight = $originHeight; 
    1963     } 
    1964      
    1965     if ($currentWidth > $imageWidth) { 
     1959        $attributes['width'] = $originWidth; 
     1960        $attributes['height'] = $originHeight; 
     1961    } 
     1962 
     1963    if ($attributes['width'] > $imageWidth) { 
    19661964        $tempWidth = $imageWidth; 
    1967         $tempHeight = floor($currentHeight * $imageWidth / $currentWidth); 
     1965        $tempHeight = floor($attributes['height'] * $imageWidth / $attributes['width']); 
    19681966    } else { 
    1969         $tempWidth = $currentWidth; 
    1970         $tempHeight = $currentHeight; 
    1971     } 
    1972      
    1973     $property = eregi_replace('(^| )width="([0-9]+%?)"', '\1width="'.$tempWidth.'"', $property); 
    1974     $property = eregi_replace('(^| )height="([0-9]+%?)"', '\1height="'.$tempHeight.'"', $property); 
    1975      
    1976     if ($originWidth > $tempWidth || $originHeight > $tempHeight) { 
    1977         $onclickFlag = true; 
    1978     } else { 
    1979         $onclickFlag = false; 
    1980     } 
    1981      
     1967        $tempWidth = $attributes['width']; 
     1968        $tempHeight = $attributes['height']; 
     1969    } 
     1970 
     1971    $properties = array(); 
     1972    ksort($attributes); 
     1973    foreach($attributes as $key => $value) 
     1974        array_push($properties, "$key=\"$value\""); 
     1975    $property = implode(' ', $properties); 
     1976    $onclickFlag = ($originWidth > $tempWidth || $originHeight > $tempHeight); 
    19821977    return array($property, $onclickFlag); 
    19831978}