Changeset 2744
- Timestamp:
- 12/29/06 05:18:34 (2 years ago)
- Location:
- branches/1.1-beta
- Files:
-
- 3 modified
-
components/Tattertools.Function.misc.php (modified) (1 diff)
-
lib/function/misc.php (modified) (1 diff)
-
lib/view/view.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1-beta/components/Tattertools.Function.misc.php
r2458 r2744 29 29 } 30 30 31 function getAttributesFromString($str ) {31 function getAttributesFromString($str, $caseSensitive=false) { 32 32 $attributes = array(); 33 33 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]); 35 37 $attributes[$matches[1][$i]] = $matches[2][$i]; 38 } 36 39 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]); 38 43 $attributes[$matches[1][$i]] = $matches[2][$i]; 44 } 39 45 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]); 41 49 $attributes[$matches[1][$i]] = $matches[2][$i]; 50 } 42 51 return $attributes; 43 52 } -
branches/1.1-beta/lib/function/misc.php
r2227 r2744 29 29 } 30 30 31 function getAttributesFromString($str ) {31 function getAttributesFromString($str, $caseSensitive=true) { 32 32 $attributes = array(); 33 33 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]); 35 37 $attributes[$matches[1][$i]] = $matches[2][$i]; 38 } 36 39 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]); 38 43 $attributes[$matches[1][$i]] = $matches[2][$i]; 44 } 39 45 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]); 41 49 $attributes[$matches[1][$i]] = $matches[2][$i]; 50 } 42 51 return $attributes; 43 52 } -
branches/1.1-beta/lib/view/view.php
r2732 r2744 1916 1916 if ($tempInfo = getimagesize(ROOT."/attach/$owner/$filename")) { 1917 1917 list($originWidth, $originHeight, $type, $attr) = $tempInfo; 1918 if($originWidth <= 0 || $originHeight <= 0 ) return array($property, false); 1918 1919 } else { 1919 1920 return array($property, false); 1920 1921 } 1921 1922 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 } 1929 1933 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 } 1938 1941 } 1939 1942 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); 1948 1946 } 1949 1947 1950 1948 // 가로만 지정된 이미지의 경우. 1951 if (isset($ currentWidth) && !isset($currentHeight)) {1949 if (isset($attributes['width']) && !isset($attributes['height'])) { 1952 1950 // 비어있는 세로를 가로의 크기를 이용하여 계산. 1953 $ currentHeight = floor($originHeight * $currentWidth/ $originWidth);1951 $attributes['height'] = floor($originHeight * $attributes['width'] / $originWidth); 1954 1952 // 세로만 지정된 이미지의 경우. 1955 } else if (!isset($ currentWidth) && isset($currentHeight)) {1953 } else if (!isset($attributes['width']) && isset($attributes['height'])) { 1956 1954 // 비어있는 가로를 세로의 크기를 이용하여 계산. 1957 $ currentWidth = floor($originWidth * $currentHeight/ $originHeight);1955 $attributes['width'] = floor($originWidth * $attributes['height'] / $originHeight); 1958 1956 // 둘 다 지정되지 않은 이미지의 경우. 1959 } else if (!isset($ currentWidth) && !isset($currentHeight)) {1957 } else if (!isset($attributes['width']) && !isset($attributes['height'])) { 1960 1958 // 둘 다 비어 있을 경우는 오리지널 사이즈로 대치. 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) { 1966 1964 $tempWidth = $imageWidth; 1967 $tempHeight = floor($ currentHeight * $imageWidth / $currentWidth);1965 $tempHeight = floor($attributes['height'] * $imageWidth / $attributes['width']); 1968 1966 } 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); 1982 1977 return array($property, $onclickFlag); 1983 1978 }
