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 !
Added Vimeo support to the Video feather, and now it resizes videos similar to 
the Photo feather.
vito (author)
Thu Jul 24 07:39:22 -0700 2008
commit  5d0346555f81f526a535c3c70f8ca4553502aa3c
tree    06dbe32f94dbfbcdb05e2566cb45be788cd1279e
parent  b27ffecdb8416c07b44e120ccd4ae5bf12f12ea2
...
5
6
7
8
9
10
 
11
12
13
...
18
19
20
21
22
23
 
24
25
26
...
55
56
57
 
 
 
 
 
 
58
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
...
5
6
7
 
 
 
8
9
10
11
...
16
17
18
 
 
 
19
20
21
22
...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
0
@@ -5,9 +5,7 @@
0
                             "type" => "text_block",
0
                             "rows" => 4,
0
                             "label" => __("Video", "video"),
0
-                            "bookmarklet" => (isset($_GET['url']) and
0
-                                              preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/",
0
-                                                         $_GET['url'])) ?
0
+                            "bookmarklet" => $this->isVideo() ?
0
                                               "url" :
0
                                               ""));
0
       $this->setField(array("attr" => "caption",
0
@@ -18,9 +16,7 @@
0
                             "preview" => true,
0
                             "bookmarklet" => "selection"));
0
 
0
-      $this->bookmarkletSelected(isset($_GET['url']) and
0
-                                 preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/",
0
-                                            $_GET['url']));
0
+      $this->bookmarkletSelected($this->isVideo());
0
 
0
       $this->setFilter("caption", "markup_post_text");
0
     }
0
@@ -55,8 +51,39 @@
0
     public function embed_tag($video) {
0
       if (preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/", $video, $matches)) {
0
         return '<object type="application/x-shockwave-flash" class="object-youtube" data="http://'.$matches[1].'youtube.com/v/'.$matches[2].'" width="468" height="391"><param name="movie" value="http://'.$matches[1].'youtube.com/v/'.$matches[2].'" /><param name="FlashVars" value="playerMode=embedded" /></object>';
0
+      } else if (preg_match("/http:\/\/(www\.)?vimeo.com\/([0-9]+)/", $video, $matches)) {
0
+        $site = get_remote($video);
0
+        preg_match('/<div id="vimeo_player_1397502" class="player" style="width:([0-9]+)px;height:([0-9]+)px;">/',
0
+                   $site,
0
+                   $scale);
0
+        return '<object type="application/x-shockwave-flash" class="object-vimeo" width="'.$scale[1].'" height="'.$scale[2].'" data="http://www.vimeo.com/moogaloop.swf?clip_id='.$matches[2].'&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id='.$matches[2].'&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /></object>';
0
       } else {
0
         return $video;
0
       }
0
     }
0
+    public function embed_tag_for($post, $max_width = 500) {
0
+      preg_match('/width=("|\')([0-9]+)("|\') height=("|\')([0-9]+)("|\')/', $post->embed, $scale);
0
+      $match  = $scale[0];
0
+      $width  = $scale[2];
0
+      $height = $scale[5];
0
+
0
+      if ($width < $max_width)
0
+        return $post->embed;
0
+
0
+      $height = ($max_width / $width) * $height;
0
+
0
+      return str_replace($match, 'width="'.$max_width.'" height="'.$height.'"', $post->embed);
0
+    }
0
+    public function isVideo() {
0
+      if (!isset($_GET['url']))
0
+        return false;
0
+
0
+      if (preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/", $_GET['url']))
0
+        return true;
0
+
0
+      if (preg_match("/http:\/\/(www\.)?vimeo.com\/([0-9]+)/", $_GET['url']))
0
+        return true;
0
+
0
+      return false;
0
+    }
0
   }
...
1
2
3
4
 
5
6
7
8
...
1
2
3
 
4
5
6
7
8
0
@@ -1,7 +1,7 @@
0
 {% extends "content/post.twig" %}
0
 
0
 {% block content %}
0
-            ${ feathers.photo.image_tag_for(post, 434) }
0
+            ${ feathers['photo'].image_tag_for(post, 434) }
0
             <div class="clear"></div>
0
             ${ post.caption | read_more }
0
 {% endblock %}
0
\ No newline at end of file
...
1
2
3
4
 
5
6
7
8
...
1
2
3
 
4
5
6
7
8
0
@@ -1,7 +1,7 @@
0
 {% extends "content/post.twig" %}
0
 
0
 {% block content %}
0
-            $post.embed
0
+            ${ feathers['video'].embed_tag_for(post, 434) }
0
             <br />
0
             ${ post.caption | read_more }
0
 {% endblock %}
0
\ No newline at end of file

Comments