Archiv der Kategorie ‘Programmierung‘

 
 

Send XML files modified with AS3 to password protected PHP-file and save them

Now that was one ride… took the whole night figuring it out, and so I will share it, of course. :D

I coded some flex-apps in the past, and I’m still working on it. Normally I use simple XML files to store configuration data, as they are so wonderfully easy to read with AS3.

But till now, changing these options meant opening on the local computer and editing them, or writing some (PHP4) compatible code with PHP, that was far from being readable.

So I decided to design a simple flash-configuration gui (only basic stuff here), but to prevent “funny people” from opening it and changing the options all the time, it had to come with some user-authentication system.

This part wasn’t that hard either, there are tons of tutorials out there how you can send (even MD5 protected) login data to a server side script like php, so I skip that.

But, and that wasn’t easy (at least for me), how to send the XML-data AND the login data together so a PHP-file can handle it.

Basically you do the following.

  1. Put the username/password/any other parameter directly into the URL you open and catch the with PHP’s $_GET[”…”] command
  2. Put the updated XML into the raw data post object, you can access via file_get_contents(”php://input”);

1. Login form with Flex/AS3

This is the first part. You have to collect username/password before doing anything else. Create some login form

<mx:Form id=“login_form”>
   <mx:FormItem label=“Username”>
	<mx:TextInput id=“username”/>
   </mx:FormItem>
   <mx:FormItem label=“password”>
         <mx:TextInput id=“password” displayAsPassword=“true”/>
   </mx:FormItem>
   <mx:FormItem>
	<mx:Button label=“submit” id=“submit_login” click=“login_user.send();”/>
   </mx:FormItem>
</mx:Form>

and a corresponding HTTPService

<mx:HTTPService
	id=“login_user”
	result=“checkLogin(event)”
	method=“POST”
	url=“any.php”
	useProxy=“false”>
		<mx:request xmlns=“”>
			<username>{MD5.hash(username.text)}</username>
			<password>{MD5.hash(password.text)}</password>
		</mx:request>
</mx:HTTPService>

This Service (login_user) opens any.php and sends the under <mx:request>… defined parameters (username,password) to it. The parameters are encrypted, visible passwords are something I don’t like that much ;). Visit the as3corelib  site to use these functions.

The any.php is straightforward than.

Define a user and password (this example is for one user without any fancy MySQL connection or anything)

$user = "admin";
$pass = "admin";
and than check the passed variables (from flex) for their correctness. 
if (isset($_POST["username"]) && isset($_POST["password"]) && $_POST["saveXML"]!="yes")
{
	$output = "<loginsuccess>“;
	if($_POST[”username”]==md5($user) && $_POST[”password”]==md5($pass))
		{
			$output .= “yes”;
		}else{
			$output .= “no”;
		}
	$output .= “</loginsuccess>“;
//output all the XML
print ($output);
}

If the submitted login data is correct, <loginsuccess>yes</loginsuccess>  will be returned. Otherwise it’s <loginsuccess>no</loginsuccess>.
If any.php finished, the Flex HTTPService calls the checkLogin function. It checks if the login data was correct and you can do what you want ;)

private function checkLogin(evt:ResultEvent):void
{
	if(evt.result.loginsuccess == “yes“)
	{
	//do something
	}
	if(evt.result.loginsuccess == “no“)
	{
	mx.controls.Alert.show(”Invalid username/password“);
	}
}

 

2. Send XML and credentials to PHP

So now you have a login form, checking if you are allowed to do something with a php-script. But what if you have to save something into a file (Flex/AS3 can’t do this), you’ll have to pass the new content to a server side script like php and let it do the work.

If, at this part, no credential-checking takes place, anyone knowing this script can use it so we have to combine send the XML-content via POST and the credentials via GET to php.

First, you need a HTTPService again

<mx:HTTPService
	id=“save_xml”
	result=“submitXML(event)”
	contentType=“application/xml”
	method=“POST”
	url=“any.php”
	useProxy=“false”>
</mx:HTTPService>

It’s important to define the content type (application/xml) here, and add NO <mx:request> to the HTTPService. Instead the url of save_xml is defined dynamically inside the AS3 code, when you want to save the xml to a file.

save_xml.url = "maximeeLite.php?password=“+MD5.hash(password.text)
               +”&username=“+MD5.hash(username.text)
               +”&saveXML=yes“;
save_xml.send(newXML);

As you see, password and username are passed as parameters within the url, the save_xml.send(newXML) passes the XML-Object newXML to any.php.

All you have to do now is some PHP again.

elseif ($_GET["saveXML"]=="yes")
{
	$output = "<savesuccess>“;
	if($_GET[”username”]==md5($mmConfig_user) && $_GET[”password”]==md5($mmConfig_pass))
	{
		$xml = file_get_contents(”php://input”);
	    	$file = fopen(”your.xml”,”wb”);
    		fwrite($file, $xml);
	    	fclose($file);
		$output .= “yes”;
	}
	else
	{
		$output .= “no”;
	}
	$output .= “</savesuccess>“;
//output all the XML
print ($output);
}

Check 1. if saveXML is yes (otherwise no XML-storing is wanted), than 2. check username/password and 3. get the new XML content with

$xml = file_get_contents("php://input"); 

and write it to the file (your.xml).

As with the login-script, here a <savesuccess>-field is returned, and can be checked by AS3 than.

private function submitXML(evt:ResultEvent):void
{
	if(evt.result.savesuccess == “yes“)
	{
	//file saved successfully
	}
	if(evt.result.savesuccess == “no“)
	{
	//file not saved
	}
}

 

That’s it. Perhaps I helped you somehow…

 

Wordpress als CMS - current-page-item und blogs

Soderle,

während ich so, immer wenn Zeit ist, an der Seite für mein Programm maxiMEE rumbastel, bin ich auf das Problem gestoßen, in der Seitenliste current-page-item als CSS-Klasse übergeben zu bekommen, wenn ich einen entsprechenden Link in der Seitenliste habe.

Folgender Aufbau:

Unter Einstellungen->Lesen->Startseite wird eine Seite als Startseite definiert, und eine weitere als "Blog-Seite".

Klickt man nun auf die Blogseite wird das Klassenattribut current-page-item nicht übergeben, sprich, der aktuelle Menüpunkt nicht hervorgehoben.

 

Zum Glück gibt es natürlich immer jemanden, der das gleiche Problem hatte, und eventuell sogar eine Lösung bereitstellt. In diesem Fall Umai, der in diesem Eintrag beschreibt, wie sich das Problem lösen lässt.

Danke also dafür! Thanks Umai… :)

sort multidimensional arrays with PHP and usort

  • German

Was?

Das hat mich schon lange gewurmt…

Wie sortiere ich ein multidimensionales Array nach Unterpunkten.

Im konkreten Fall ist es ein Array, das von CpmFetch (Thumbnail via WebSnapr: http://cpmfetch.fistfullofcode.com/) zurückgegeben wird (für maxiMEE).

Alle meine kläglichen Versuche mit array_multisort sind gescheitert, usort ist des Rätsels Lösung.

 

Wie?

Von CpmFetch erhält man etwas in der Art:

Array
(
    [0] => Array
        (
            [pFilepath] => userpics/10001/
            [pFilename] => Andreas_Wehr_Leinwand.jpg
            [pAid] => 2
            [pFilesize] => 1070798
            [pTitle] => Andreas Wehr Leinwand
            [pCaption] =>
            [pOwner_name] => admin
            [pOwnerId] => 1
            [pCtime] => 1190127402
            [pHits] => 13
            [pPid] => 141
            [pPic_Rating] => 0
            [pVotes] => 0
            [pWidth] => 1038
            [pHeight] => 1528
            [pUser1] =>
            [pUser2] =>
            [pUser3] =>
            [pUser4] =>
            [cCid] => 2
            [cName] => Testbilder
            [cDescription] =>
            [cPos] => 0
            [cParent] => 0
            [cThumb] => 5
            [uUser_lastvisit] => 2008-02-25 21:44:37
            [uUser_regdate] => 2006-12-04 10:29:48
            [uUser_email] =>
            [uUser_profile1] =>
            [uUser_profile2] =>
            [uUser_profile3] =>
            [uUser_profile4] =>
            [uUser_profile5] =>
            [uUser_profile6] =>
            [aAid] => 2
            [aTitle] => Test
            [aDescription] =>
            [aVisibility] => 0
            [aPos] => 100
            [aCategory] => 2
            [aThumb] => 0
            [aKeyword] =>
            [fullPathToThumb] => albums/userpics/10001/thumb_Andreas_Wehr_Leinwand.jpg
            [fullPathToNormal] => albums/userpics/10001/normal_Andreas_Wehr_Leinwand.jpg
            [fullPathToFull] => albums/userpics/10001/Andreas_Wehr_Leinwand.jpg
        )

    [1] => Array
        (
            [pFilepath] => userpics/10001/
            [pFilename] => muschelsuppe_suf_framed.jpg
            [pAid] => 2
            [pFilesize] => 287347
            [pTitle] =>
            [pCaption] =>
            [pOwner_name] => admin
            [pOwnerId] => 1
            [pCtime] => 1190046369
            [pHits] => 8
            [pPid] => 11
            [pPic_Rating] => 0
            [pVotes] => 0
            [pWidth] => 1000
            [pHeight] => 1000
            [pUser1] =>
            [pUser2] =>
            [pUser3] =>
            [pUser4] =>
            [cCid] => 2
            [cName] => Testbilder
            [cDescription] =>
            [cPos] => 0
            [cParent] => 0
            [cThumb] => 5
            [uUser_lastvisit] => 2008-02-25 21:44:37
            [uUser_regdate] => 2006-12-04 10:29:48
            [uUser_email] =>
            [uUser_profile1] =>
            [uUser_profile2] =>
            [uUser_profile3] =>
            [uUser_profile4] =>
            [uUser_profile5] =>
            [uUser_profile6] =>
            [aAid] => 2
            [aTitle] => Test
            [aDescription] =>
            [aVisibility] => 0
            [aPos] => 100
            [aCategory] => 2
            [aThumb] => 0
            [aKeyword] =>
            [fullPathToThumb] => albums/userpics/10001/thumb_muschelsuppe_suf_framed.jpg
            [fullPathToNormal] => albums/userpics/10001/normal_muschelsuppe_suf_framed.jpg
            [fullPathToFull] => albums/userpics/10001/muschelsuppe_suf_framed.jpg
        )

    )

Sortiert werden sollen jetzt die Bilder entweder nach Einstellungsdatum in die Galerie, oder nachh Titel. Jeweils aufsteigend und absteigend.

$sort_type definiert dabei die Art zu sortieren.

$sort_type = 2;

	//sort the array
	usort($images,sortImages);
	//the sort-function
	function sortImages($a,$b)
	{
		global $sort_type;

				switch ($sort_type) {
				case 1:
						if ($a[pCtime] == $b[pCtime]) {
				  		     return 0;
				 			   }
				    return ($a[pCtime] < $b[pCtime]) ? -1 : 1;
						break;
				case 2:
						if ($a[pCtime] == $b[pCtime]) {
				  		     return 0;
				 			   }
				    return ($a[pCtime] > $b[pCtime]) ? -1 : 1;
						break;
				case 3:
						if ($a[pTitle] == $b[pTitle]) {
				  		     return 0;
				 			   }
				    return strcmp($a[pTitle],$b[pTitle]);
						break;
				case 4:
						if ($a[pTitle] == $b[pTitle]) {
				  		     return 0;
				 			   }
				    return -strcmp($a[pTitle],$b[pTitle]);
						break;
				default:

						break;
				}

}

Mit

usort($images,sortImages); 

wird der Sortiervorgang angestoßen.

usort ruft dann jeweils die Funktion sortImages auf, um die beiden Array-Elemente zu vergleichen.

Es wird als Rückgabe eine Zahl kleiner, gleich oder größer 0 erwartet.

(siehe auch PHP-Manual Thumbnail via WebSnapr: http://us2.php.net/manual/en/function.usort.php)

Wird nach Datum sortiert, wird entsprechend die pCtime verglichen.

Bei der Sortierung nach Titel hilft strcmp.

 

Jetzt bin ich erleichtert, das maxiMEE Coppermine Plugin ist damit fast fertig :)

maxi.MEE - coming soooooon

  • English
  • German

maxi.MEE is coming. My Coppermine fullscreen-plugin does have a name now ;)

http://maximee.com

maxi.MEE Logo

FSlideS 0.5

So,

das Plugin kann jetzt innerhalb von Coppermine konfiguriert werden.

Cool

Ein ausführliche Anleitung folgt später eventuell noch.

Hier geht es zum Download


Bugfixes

  • Diaschau arbeitet jetzt zuverlässig
  • Zufallsbilder sollten richtig angezeigt werden

Features

  • Konfiguration des Plugins über die Coppermine-Gallerie
    • Sprache
    • Standart-Hintergrundfarbe
    • Diaschau-Intervall
  • Auslagerung der Einstellungen in XML-Datei
    • Sprachen
    • Diaschau-Intervall
    • Hintergrundfarbe
  • Unterstützung mehrerer Sprachen
    • Deutsch
    • Englisch

FSslideS - Vollbild/Fullscreen Coppermine-Plugin

Finally, it’s done.
My little fullscreen-flash-app is available as a coppermine plugin.
It’s by far not final, but it works.

Click here for more information

Vollbild-Modus - Anleitung für Coppermine

So,
es gibt mal wieder was neues…

ich habe meinen Vollbildmodus für Coppermine mal hergerichtet und eine Anleitung dazu veröffentlicht.

Sollte relativ leicht nachzuvollziehen sein!

Hier geht es zur Anleitung

Viel Spass!

Flashs Vollbildmodus/Fullscreen Mode und WMODE

Da habe ich mir also meinen Flashbutton für eine Vollbild-Slideshow mühsam gebaut, wollte aber trotzdem gerne Lightbox zur Anzeige der Bilder weiterverwenden… nicht jeder verspürt schließlich das Bedürfnis alles im Vollbild zu betrachten!

Nur hat man dabei ein großes Problem, scheint der Vollbild-Button (bzw. jeder andere Flash-Inhalt), durch die Lightbox durch… und hübsch ist definitiv anders, wenn mitten in meinen Bilder der Flash-Button auftaucht :(

Durchscheinender Flash-Inhalt

Abhilfe habe ich im Netz nicht gefunden… der Parameter wmode mit den Optionen transparent und opaque von Flash (Informationen zu allen Parametern bei Adobe) schafft zwar Abhilfe, aber dann funktioniert der Vollbildmodus nicht mehr…

  • wmode - Possible values: window, opaque, transparent. Sets the Window Mode property of the Flash movie for transparency, layering, and positioning in the browser.
    • window - movie plays in its own rectangular window on a web page.
    • opaque - the movie hides everything on the page behind it.
    • transparent - the background of the HTML page shows through all transparent portions of the movie, this may slow animation performance. (Quelle)

Da das offensichtlich nicht geändert werden kann, öffnen sich meine Bilder vorerst wieder in einem Popup… wobei ich das verschmerzen kann, ihr sollt euch die ja eh im Vollbild-Modus ansehen und genießen ;)

Vollbild-Diaschau in Flash (Update)+Anleitung

So,

mal etwas Zeit genommen und es niedergeschrieben.

Es gibt jetzt eine Vollbild-Diaschau in Flash von mir, die auch fröhlich getestet werden kann.

LINK zur Seite (auch rechts im Menü zu finden ;))

Es geht jetzt fast alles, was ich mir so vorgestellt habe, nur die Integration in entsprechende Bildergalerien ist noch Handarbeit :)

Als Vorgeschmack ein paar Bildchen davon:

Screenshot1Screenshot2Screenshot3Screenshot4Screenshot5

SWFObject + Lightbox + Coppermine und der Internet Explorer

Während der Bastelei an meinem Vollbild-Bildbetrachter (bald gibt es Neuigkeiten), bin ich auf etwas wirklich nerviges gestoßen.

Das Nutzen von SWFObject zum Einbinden von Flash in die Seite innerhalb von meiner Coppermine-Galerie hat dazu geführt, dass mitunter der InternetExplorer ausgesperrt wurde. Der hat zwar die Seite geladen, aber dann eine Fehlermeldung ausgespuckt.

“Die Seite …. kann nicht geöffnet werden. Vorgang abgebrochen. ”

“Internet Explorer cannot open the Internet site … Operation Aborted”
Grund: unbekannt, jedenfalls für mich. Zumal in Firefox und Opera keine Probleme auftauchen.
Na ja, Google ist ja dein Freund… man ist nicht der einzige mit den Problemen:
Der Tipp auf http://aralbalkan.com/912 hat zwar etwas geholfen, aber nicht wirklich. Im Internet Explorer wurde danach nach der Flashplayer-Installation verlangt, bzw. dieser nicht erkannt.
Geholfen hat ein FAQ-Eintrag auf der Seite der SWFObject-Macher:








This text is replaced by the first Flash movie.
This text is replaced by the second Flash movie.
Man baut sich eine onload-Funktion ein, die das SWFObject erst einbettet, wenn die Seite fertig geladen ist. UND: TATAAA, alles läuft!

  • Stats

    Besucher online: 1
    Besucher heute: 8
    Besucher seit 29. März 2008: 5685
    78 Besucher haben sich diese Seite angesehen
  • Spam Blocked