]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Moved url parse functions to a library.
authorSem <sembrestels@riseup.net>
Thu, 3 Nov 2011 21:23:57 +0000 (22:23 +0100)
committerSem <sembrestels@riseup.net>
Thu, 3 Nov 2011 21:23:57 +0000 (22:23 +0100)
lib/videolist.php [new file with mode: 0644]
start.php
views/default/forms/videolist/add.php
views/default/forms/videolist/edit.php

diff --git a/lib/videolist.php b/lib/videolist.php
new file mode 100644 (file)
index 0000000..50f83c9
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+function video_youtube_parse_url($url) {
+       if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(youtube\.com\/)(.*)/', $url, $matches)) {
+       return false;
+       }
+
+       $domain = $matches[2] . $matches[3];
+       $path = $matches[4];
+
+       if (!preg_match('/^(watch\?v=)([a-zA-Z0-9_-]*)(&.*)?$/',$path, $matches)) {
+       return false;
+       }
+
+       $hash = $matches[2];
+       return $domain . 'v/' . $hash;
+}
+
+function video_vimeo_parse_url($url) {
+       if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(vimeo\.com\/)(.*)/', $url, $matches)) {
+               return false;
+       }
+
+       $domain = $matches[2] . $matches[3];
+       $path = $matches[4];
+
+       $hash = $matches[2];
+
+       return $domain . '/' . $hash;
+}
+
+function video_metacafe_parse_url($url) {
+       if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(metacafe\.com\/)(.*)/', $url, $matches)) {
+               return false;
+       }
+
+       $domain = $matches[2] . $matches[3];
+       $path = $matches[4];
+
+       $hash = $matches[2];
+
+       return $domain . '/' . $hash;
+}
+
+if(isset($confirm_action) && ($confirm_action == 'add_video')) {
+       if(isset($title_videourl) && ($title_videourl != '')) {
+               if($Pagecontainer != "youtube" || $Pagecontainer != "vimeo" || $Pagecontainer != "metacafe"){
+                       if(preg_match("/youtube/i", $title_videourl)) {
+                               $Pagecontainer = "youtube";
+                       }
+
+                       if(preg_match("/vimeo/i", $title_videourl)) {
+                               $Pagecontainer = "vimeo";
+                       }
+
+                       if(preg_match("/metacafe/i", $title_videourl)) {
+                               $Pagecontainer = "metacafe";
+                       }
+               }
+               if($Pagecontainer == "youtube") {
+                       $is_valid_video = video_youtube_parse_url($title_videourl);
+               } else if($Pagecontainer == "vimeo") {
+                       $is_valid_video = video_vimeo_parse_url($title_videourl);
+                       $is_valid_video = $get_addvideourl;
+               } else if($Pagecontainer == "metacafe"){
+                       $is_valid_video = video_metacafe_parse_url($title_videourl);
+                       $is_valid_video = $get_addvideourl;
+               }
+
+               if($is_valid_video) {
+                       $error['no-video'] = 1;
+                       $_SESSION['candidate_profile_video'] = $is_valid_video;
+                       $_SESSION['candidate_profile_video_access_id'] = $access_id;
+                       $_SESSION['videolisttags'] = $tags;
+                       $_SESSION['Pagecontainer'] = $Pagecontainer;
+                       $_SESSION['container_guid'] = $container_guid;
+                       $url = "action/videolist/add?__elgg_ts={$timestamp}&__elgg_token={$token}";
+                       forward($url);
+               }
+               else
+                       $error['no-video'] = 0;
+       }
+       else {
+               $error['no-video'] = 0;
+       }
+}
index 724aad61d02056a6018e3a7328a19d203046385b..ff0182c3bcc20867f5fd9d0cee9f364f84eff0ab 100644 (file)
--- a/start.php
+++ b/start.php
@@ -12,6 +12,8 @@
 elgg_register_event_handler('init', 'system', 'videolist_init');
 
 function videolist_init() {
+       
+       elgg_register_library('elgg:videolist', elgg_get_plugins_path() . 'videolist/lib/videolist.php');
 
        // add a site navigation item
        $item = new ElggMenuItem('videolist', elgg_echo('videolist'), 'videolist/all');
index 2ee5d9c2e1c248c07f633e3c966747d597040b60..b03c1834167d403be24530a06d5ea292a8a1e343 100644 (file)
@@ -53,90 +53,6 @@ if (!empty($get_addvideourl) && ($Pagecontainer == "youtube")) {
 
 $tags = get_input('videolisttags');
 
-function video_youtube_parse_url($url) {
-       if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(youtube\.com\/)(.*)/', $url, $matches)) {
-       return false;
-       }
-
-       $domain = $matches[2] . $matches[3];
-       $path = $matches[4];
-
-       if (!preg_match('/^(watch\?v=)([a-zA-Z0-9_-]*)(&.*)?$/',$path, $matches)) {
-       return false;
-       }
-
-       $hash = $matches[2];
-       return $domain . 'v/' . $hash;
-}
-
-function video_vimeo_parse_url($url) {
-       if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(vimeo\.com\/)(.*)/', $url, $matches)) {
-               return false;
-       }
-
-       $domain = $matches[2] . $matches[3];
-       $path = $matches[4];
-
-       $hash = $matches[2];
-
-       return $domain . '/' . $hash;
-}
-
-function video_metacafe_parse_url($url) {
-       if (!preg_match('/(http:\/\/)([a-zA-Z]{2,3}\.)(metacafe\.com\/)(.*)/', $url, $matches)) {
-               return false;
-       }
-
-       $domain = $matches[2] . $matches[3];
-       $path = $matches[4];
-
-       $hash = $matches[2];
-
-       return $domain . '/' . $hash;
-}
-
-if(isset($confirm_action) && ($confirm_action == 'add_video')) {
-       if(isset($title_videourl) && ($title_videourl != '')) {
-               if($Pagecontainer != "youtube" || $Pagecontainer != "vimeo" || $Pagecontainer != "metacafe"){
-                       if(preg_match("/youtube/i", $title_videourl)) {
-                               $Pagecontainer = "youtube";
-                       }
-
-                       if(preg_match("/vimeo/i", $title_videourl)) {
-                               $Pagecontainer = "vimeo";
-                       }
-
-                       if(preg_match("/metacafe/i", $title_videourl)) {
-                               $Pagecontainer = "metacafe";
-                       }
-               }
-               if($Pagecontainer == "youtube") {
-                       $is_valid_video = video_youtube_parse_url($title_videourl);
-               } else if($Pagecontainer == "vimeo") {
-                       $is_valid_video = video_vimeo_parse_url($title_videourl);
-                       $is_valid_video = $get_addvideourl;
-               } else if($Pagecontainer == "metacafe"){
-                       $is_valid_video = video_metacafe_parse_url($title_videourl);
-                       $is_valid_video = $get_addvideourl;
-               }
-
-               if($is_valid_video) {
-                       $error['no-video'] = 1;
-                       $_SESSION['candidate_profile_video'] = $is_valid_video;
-                       $_SESSION['candidate_profile_video_access_id'] = $access_id;
-                       $_SESSION['videolisttags'] = $tags;
-                       $_SESSION['Pagecontainer'] = $Pagecontainer;
-                       $_SESSION['container_guid'] = $container_guid;
-                       $url = "action/videolist/add?__elgg_ts={$timestamp}&__elgg_token={$token}";
-                       forward($url);
-               }
-               else
-                       $error['no-video'] = 0;
-       }
-       else {
-               $error['no-video'] = 0;
-       }
-}
 
 $body = '<form action="'.$_SERVER['php_self'].'" method="post" id="add_video_form">';
 $body .= elgg_view('input/hidden',array('internalname'=>'video_action', 'value'=>'add_video'));
index 7d7901bcdd84488ad816c61bf8a69d4446ff5434..9bcc64a7ae73b15626353b984d52c7cdf943062c 100644 (file)
@@ -2,6 +2,9 @@
 /**
 * Elgg Video Plugin > Edit view
 */
+
+elgg_load_library('elgg:videolist');
+
 // Make sure we're logged in (send us to the front page if not)
 gatekeeper();
 $page_owner = page_owner_entity();
@@ -40,4 +43,4 @@ if($owner instanceof ElggGroup){
                <input type="submit" value="<?php echo elgg_echo("save"); ?>" />
        </p>
 
-</form>
\ No newline at end of file
+</form>