. .
pragmaMx Support Forum 25 Mai 2012, 14:04:21 *
Willkommen Gast. Bitte einloggen oder registrieren.


Einloggen mit Benutzername und Passwort
News:
Brauchen Sie Hilfe? Bitte nutzen Sie unsere Suchfunktion bevor Sie Beiträge oder Fragen ins Board schreiben! Viele Fragen wurden bereits gestellt und beantwortet. Danke!
 
Übersicht Hilfe Forenregeln / Boardrules
 
Suche
Seiten: [1]   Nach unten
Drucken
Autor Thema: Videos von YouTube in der Coppermine Galerie anzeigen  (Gelesen 5728 mal)
0 Mitglieder und 1 Gast betrachten dieses Thema.
Sitki
Administrator
******
Offline Offline

Geschlecht: Männlich
Beiträge: 3.530

Sitki


WWW
« am: 19 September 2007, 08:28:38 »

Hallo Smiley,
auf der Suche nach einer Möglichkeit zum Einbinden von YouTube Videos in die Coppermine Galerie bin ich auf diesen Post gestoßen: Displaying videos from Youtube in Coppermine . Die hierin beschriebene Modifikation habe ich nach geringfügiger Anpassung an pragmaMx erfolgreich auf meiner Testseite eingespielt.

Demo auf meiner Testseite.

Meine Daten:
CMS-Version: pragmaMx 0.1.9, 1.30/2007-04-05
PHP-Version: 5.2.3
MySQL-Version: 5.0.37-max-log
Coppermine Photo Gallery 1.4.10 (stable)
Coppermine Theme: mx-port

Nachfolgend habe ich die obig genannte Modifikationsbeschreibung ins Deutsche übersetzt und die vorzunehmenden Codeänderungen an pragmaMX angepasst (lediglich die Themeanpassung in der themes.inc.php anstatt theme.php). Irrtümer und Auslassungen vorbehalten, ohne jegliche Gewähr! Es kann, aber muss nicht funktionieren!

Unbedingt beachten! DB und die zu ändernden Dateien vorher sichern bzw. Komplettsicherung vornehmen!



Diese Modifikation erlaubt dir Videos von YouTube in deine Coppermine Galerie einzubinden. Es erscheint auf der Upload Seite ein neuer Bereich, wo du die URL der Videos dann eingeben kannst. Die Coppermine Galerie wird automatisch das Thumbnail vom Video nutzen, wenn du das Video eingebunden hast.

Um diese Modifikation nutzen zu können, werden einige Extras benötigt:
·   YouTube dev API USER-ID (http://www.youtube.com/my_profile_dev) (du musst dir bei YouTube vorher einen Account einrichten)
·   PHP URL “fopen“ muss eingeschaltet sein (kann unter phpinfo nachgeprüft werden)
·   PHP 5 (4.xx, siehe Codeanpassung*. Kann, aber muss nicht funktionieren!)
·   Reguläre URI Uploads müssen korrekt arbeiten, richtige Benutzerrechte etc.

Zu ändernde Dateien: upload.php, themes.inc.php

1. upload.php, füge diesen Code in die Nähe des Anfangs von der Datei nach den Kommentaren ein (dieser Schritt kann ausgelassen werden, wenn du PHP5 hast)

*
Code: [Select]  
if (!function_exists('file_put_contents')) {
function file_put_contents($n,$d) {
$f=@fopen($n,"w");
if (!$f) {
return false;
} else {
fwrite($f,$d);
fclose($f);
return true;
}
}
}

dann finde
Code: [Select]  
// Add the control device.
            $form_array[] = array('control', 'phase_1', 4);

füge davor ein
Code: [Select]  
// Youtube
           if (USER_ID) {
            $form_array[] = 'Youtube uploads';
              $form_array[] = array('', 'YT_array[]', 0, 256, 3);
              $form_array[] = 'Note: YouTube videos must be added in the form http://www.youtube.com/watch?v=xxxxxxxxxxx';
}

finde
Code: [Select]  
//Now we must prepare the inital form for adding the pictures to the database, and we must move them to their final location.

füge davor ein
Code: [Select]  
// youtube
   
   $YT_array = count($_POST['YT_array']);

if ($YT_array) {
$YT_failure_array = array();

for ($counter = 0; $counter < $YT_array; $counter++) {

// Create the failure ordinal for ordering the report of failed uploads.

$failure_cardinal = $counter + 1;

$failure_ordinal = ''.$failure_cardinal.'. ';
           
$YT_URI = $_POST['YT_array'][$counter];

if (!$YT_URI) continue;


if (preg_match('/youtube\.com\/watch\?v=(.*)/', $YT_URI, $matches)){

$vid = $matches[1];
                     
$xurl = "http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=xxxxxxxxxxx&video_id=$vid";
                     
$xdata = file_get_contents($xurl);

file_put_contents($CONFIG['fullpath'] . "edit/yt_$vid.xml", $xdata);

// todo: parse the xml properly
if (preg_match('/<thumbnail_url>(.*)<\/thumbnail_url>/', $xdata, $xmatches)){

$thumbnail = $xmatches[1];

$rh = fopen($thumbnail, 'rb');
$wh = fopen($CONFIG['fullpath'] . "edit/yt_$vid.jpg", 'wb');


        while (!feof($rh)) fwrite($wh, fread($rh, 1024));

fclose($rh);
fclose($wh);
     
$escrow_array[] = array('actual_name'=>"youtube_$vid.jpg", 'temporary_name'=> "yt_$vid.jpg");

} else {
$YT_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $YT_URI, 'error_code'=> $xdata);
}
             
             } else {
                 $YT_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $YT_URI, 'error_code'=> 'Failed to find video');
             }
         }
     }


Im obigen Codeblock, musst du xxxxxxxxxxx mit deiner YouTube Entwickler (developer) ID ersetzen.

finde
Code: [Select]  
$zip_error_count = count($zip_failure_array);

füge danach ein
Code: [Select]  
$YT_error_count = count($YT_failure_array);

finde
Code: [Select]  
// Create error report if we have errors.
    if (($file_error_count + $URI_error_count + $zip_error_count) > 0) {

ändere in
Code: [Select]  
// Create error report if we have errors.
    if (($file_error_count + $URI_error_count + $zip_error_count + $YT_error_count) > 0) {

finde
Code: [Select]  
// Close the error report table.
        endtable()

füge davor ein
Code: [Select]  
     
                // Look for YT upload errors.
        if ($YT_error_count > 0) {

            // There are URI upload errors. Generate the section label.
            form_label("YT errors:");
            echo "<tr><td>URI</td><td>Error message</td></tr>";

            // Cycle through the file upload errors.
            for ($i=0; $i < $YT_error_count; $i++) {

                // Print the error ordinal, file name, and error code.
                echo "<tr><td>{$YT_failure_array[$i]['failure_ordinal']} {$YT_failure_array[$i]['URI_name']}</td><td>{$YT_failure_array[$i]['error_code']}</td></tr>";

            }

        }

finde
Code: [Select]  
    $form_array = array(
        sprintf($lang_upload_php['max_fsize'], $CONFIG['max_upl_size']),
        array($lang_upload_php['album'], 'album', 2),
        array('MAX_FILE_SIZE', $max_file_size, 4),
        array($lang_upload_php['picture'], 'userpicture', 1, 1),
        array($lang_upload_php['pic_title'], 'title', 0, 255, 1),
        array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length']),
        array($lang_upload_php['keywords'], 'keywords', 0, 255, 1),
        array('event', 'picture', 4)
        );

ändere in
Code: [Select]  
     
        if (preg_match('/^youtube_(.*)\.jpg$/', $file_set[0], $ytmatches)){

         $vid = $ytmatches[1];

$xdata = file_get_contents($CONFIG['fullpath'] . "edit/yt_$vid.xml");


// todo: parse the xml properly
preg_match('/<description>(.*)<\/description>/', $xdata, $xmatches);
$description = substr($xmatches[1], 0, $CONFIG['max_img_desc_length']);

// todo: parse the xml properly
preg_match('/<tags>(.*)<\/tags>/', $xdata, $xmatches);
$keywords = $xmatches[1];

// todo: parse the xml properly
preg_match('/<title>(.*)<\/title>/', $xdata, $xmatches);
$title = substr($xmatches[1], 0, 255);


                $form_array = array(
        array($lang_upload_php['album'], 'album', 2),
        array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title),
        array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], $description),
        array($lang_upload_php['keywords'], 'keywords', 0, 255, 1, $keywords),
    array('control', 'phase_2', 4),
    array('unique_ID', $_POST['unique_ID'], 4),
        );
       
   
    } else {

                $form_array = array(
        sprintf($lang_upload_php['max_fsize'], $CONFIG['max_upl_size']),
        array($lang_upload_php['album'], 'album', 2),
        array('MAX_FILE_SIZE', $max_file_size, 4),
        array($lang_upload_php['picture'], 'userpicture', 1, 1),
        array($lang_upload_php['pic_title'], 'title', 0, 255, 1),
        array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length']),
        array($lang_upload_php['keywords'], 'keywords', 0, 255, 1),
        array('event', 'picture', 4)
        );

}

2. modules/Gallery/include/themes.inc.php führe die nachfolgende Änderung durch

finde
Code: [Select]  
if (isset($image_size['reduced'])) {

ändere in
Code: [Select]  
if (preg_match('/^youtube_(.*)\.jpg$/', $CURRENT_PIC_DATA['filename'], $ytmatches)){
   
    $vid = $ytmatches[1];
      $pic_html = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'. $vid . '"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'. $vid . '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object><br />';
   
    } elseif (isset($image_size['reduced'])) {


Wenn du diese Nachricht beim Upload erhältst:

  1YouTube internal error. Please report this issue -- including the exact method of producing this error -- to YouTube.

Dann ist deine dev_id vermutlich falsch.
Gespeichert

Grüsse & Esenlikler
Wurde dein Problem gelöst? Dann bitte markiere den Thread entsprechend.
Kein Support per PM - Nutzt bitte das Forum!
Destek için forumu kullanın. Özel mesaj atmayın..
Helmuth von Moltke
Sitki
Administrator
******
Offline Offline

Geschlecht: Männlich
Beiträge: 3.530

Sitki


WWW
« Antworten #1 am: 20 September 2007, 13:16:40 »

Hallo Smiley,

noch eine zusätzliche Information.

Wenn nicht die Standart-Theme von der pragmaMx-Coppermine verwendet werden sollte, dann ist die oben unter theme.inc.php beschriebene Änderung in der theme.php des verwendeten Theme vorzunehmen, sofern die theme.php die Funktion
Code: [Select]  
if (isset($image_size['reduced'])) {
beinhaltet. Wenn diese Funktion nicht in der verwendeten theme.php enthalten ist, dann ist die Änderung auch in diesem Fall wie oben beschrieben in der theme.inc.php vorzunehmen.
Gespeichert

Grüsse & Esenlikler
Wurde dein Problem gelöst? Dann bitte markiere den Thread entsprechend.
Kein Support per PM - Nutzt bitte das Forum!
Destek için forumu kullanın. Özel mesaj atmayın..
Helmuth von Moltke
breakdancer
Gast
« Antworten #2 am: 03 April 2009, 11:05:29 »

Moin,

bitte diesen Beitrag am Besten an diesen http://www.pragmamx.org/Forum-topic-22661.html hier dranhängen oder das Original Post von Sitki abändern, es hat sich nämlich einiges geändert...

Seit einiger Zeit läuft alles über die neue Google API. Wer einen neuen Developer-Account anlegt, bekommt zwar eine Client-ID und einen x-stelligen Developer Key, beides aber nicht für diese Modifikation nutzbar.

Nibbler, der die Modifikation online gestellt hat, hat auch ein entsprechendes Update released. Hier ist es nun.

Alle Änderungen in der upload.php !

1. suche

Code: [Select]  
if (preg_match('/youtube\.com\/watch\?v=(.*)/', $YT_URI, $matches)){

$vid = $matches[1];
                     
$xurl = "http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=xxxxxxxxxxx&video_id=$vid";
                     
$xdata = file_get_contents($xurl);

file_put_contents($CONFIG['fullpath'] . "edit/yt_$vid.xml", $xdata);

// todo: parse the xml properly
if (preg_match('/<thumbnail_url>(.*)<\/thumbnail_url>/', $xdata, $xmatches)){

$thumbnail = $xmatches[1];

$rh = fopen($thumbnail, 'rb');
$wh = fopen($CONFIG['fullpath'] . "edit/yt_$vid.jpg", 'wb');


        while (!feof($rh)) fwrite($wh, fread($rh, 1024));

fclose($rh);
fclose($wh);
     
$escrow_array[] = array('actual_name'=>"youtube_$vid.jpg", 'temporary_name'=> "yt_$vid.jpg");

} else {
$YT_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $YT_URI, 'error_code'=> $xdata);
}

und ersetze es durch

Code: [Select]  
if (preg_match('/youtube\.com\/watch\?v=(.*)/', $YT_URI, $matches)){

$vid = $matches[1];
                     
$xurl = "http://gdata.youtube.com/feeds/api/videos/$vid";
                     
$xdata = file_get_contents($xurl);

file_put_contents($CONFIG['fullpath'] . "edit/yt_$vid.xml", $xdata);

// todo: parse the xml properly
//if (preg_match('/<thumbnail_url>(.*)<\/thumbnail_url>/', $xdata, $xmatches)){

$thumbnail = "http://img.youtube.com/vi/$vid/0.jpg";

$rh = fopen($thumbnail, 'rb');
$wh = fopen($CONFIG['fullpath'] . "edit/yt_$vid.jpg", 'wb');


        while (!feof($rh)) fwrite($wh, fread($rh, 1024));

fclose($rh);
fclose($wh);
     
$escrow_array[] = array('actual_name'=>"youtube_$vid.jpg", 'temporary_name'=> "yt_$vid.jpg");

//} else {
// $YT_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $YT_URI, 'error_code'=> $xdata);
//}


2. suche

Code: [Select]  
// todo: parse the xml properly
preg_match('/<description>(.*)<\/description>/', $xdata, $xmatches);
$description = substr($xmatches[1], 0, $CONFIG['max_img_desc_length']);

// todo: parse the xml properly
preg_match('/<tags>(.*)<\/tags>/', $xdata, $xmatches);
$keywords = $xmatches[1];

// todo: parse the xml properly
preg_match('/<title>(.*)<\/title>/', $xdata, $xmatches);
$title = substr($xmatches[1], 0, 255);

und ersetze es durch

Code: [Select]  
// todo: parse the xml properly
preg_match("/<media:description type='plain'>(.*)<\/media:description>/s", $xdata, $xmatches);
$description = substr($xmatches[1], 0, $CONFIG['max_img_desc_length']);

// todo: parse the xml properly
preg_match('/<media:keywords>(.*)<\/media:keywords>/s', $xdata, $xmatches);
$keywords = $xmatches[1];

// todo: parse the xml properly
preg_match("/<media:title type='plain'>(.*)<\/media:title>/s", $xdata, $xmatches);
$title = substr($xmatches[1], 0, 255);

Das wars schon, läuft prima.

Ihr benötigt für die Modifikation keine Dev_Id mehr.

Viele Grüße

Markus

P. S. Quelle: http://forum.coppermine-gallery.net/index.php/topic,37962.280.html - Seite 15 !
Gespeichert
Seiten: [1]   Nach oben
Drucken
 
Gehe zu:  

Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
design by hENNE, layout based on YAML