public
Description: The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.
Homepage: http://chyrp.net/
Clone URL: git://github.com/vito/chyrp.git
Click here to lend your support to: chyrp and make a donation at www.pledgie.com !
A more dynamic video embed_tag_for scaling method. Closing #196 since it was 
indirectly affected (its actual issue has already been fixed). [#196 
state:resolved]
vito (author)
Thu Aug 28 16:44:59 -0700 2008
commit  c052e58651a3931fae92a12ae359981932c59f20
tree    9045b80423aad9f4dcd899262d358b22fd7ba832
parent  9eea494f1f3622490e456f7e78f4c570886b8f8c
...
82
83
84
85
86
87
88
 
 
 
 
 
89
90
 
 
 
91
92
 
93
94
95
96
97
98
99
100
101
102
103
104
105
 
106
107
108
...
82
83
84
 
 
 
 
85
86
87
88
89
90
 
91
92
93
94
 
95
96
97
 
 
 
 
 
 
 
 
 
 
 
98
99
100
101
0
@@ -82,27 +82,20 @@
0
     public function embed_tag_for($post, $max_width = 500) {
0
       $post->embed = preg_replace("/&([[:alnum:]_]+)=/", "&\\1=", $post->embed);
0
 
0
-      if (preg_match("/width=(\"|')([0-9]+)(\"|') height=(\"|')([0-9]+)(\"|')/", $post->embed, $scale)) {
0
-        $match  = $scale[0];
0
-        $width  = $scale[2];
0
-        $height = $scale[5];
0
+      if (preg_match("/width(=\"|='|:\s*)([0-9]+)/", $post->embed, $width)) {
0
+        $sep_w = $width[1];
0
+        $original_width = $width[2];
0
+      } else
0
+        return $post->embed;
0
 
0
-        $new_height = (int) (($max_width / $width) * $height);
0
+      if (preg_match("/height(=\"|='|:\s*)([0-9]+)/", $post->embed, $height)) {
0
+        $sep_h  = $height[1];
0
+        $original_height = $height[2];
0
 
0
-        return str_replace($match, 'width="'.$max_width.'" height="'.$new_height.'"', $post->embed);
0
+        $new_height = (int) (($max_width / $original_width) * $original_height);
0
       }
0
 
0
-      if (preg_match("/width:([0-9]+)(px)?;(\s*)height:([0-9]+)(px)?;?/", $post->embed, $scale)) {
0
-        $match  = $scale[0];
0
-        $width  = $scale[1];
0
-        $height = $scale[4];
0
-        $px     = $scale[2];
0
-        $space  = $scape[3];
0
-
0
-        $new_height = (int) (($max_width / $width) * $height);
0
-
0
-        return str_replace($match, 'width:'.$max_width.$px.';'.$space.'height:'.$new_height.$px.';', $post->embed);
0
-      }
0
+      $post->embed = str_replace(array($width[0], $height[0]), array("width".$sep_w.$max_width, "height".$sep_h.$new_height), $post->embed);
0
 
0
       return $post->embed;
0
     }

Comments