[qo-modules-dev] [14] php

[ Thread Index | Date Index | More lists.tuxfamily.org/qo-modules-dev Archives ]


Revision: 14
Author:   ytorres
Date:     2008-11-11 22:37:06 +0100 (Tue, 11 Nov 2008)

Log Message:
-----------
php

Added Paths:
-----------
    yannick/php/lib.php
    yannick/php/shortcuts.php

Removed Paths:
-------------
    yannick/php/get-desktop.php
    yannick/php/get-state.php
    yannick/php/move-to.php
    yannick/php/update-filename.php


Deleted: yannick/php/get-desktop.php
===================================================================
--- yannick/php/get-desktop.php	2008-11-11 21:35:33 UTC (rev 13)
+++ yannick/php/get-desktop.php	2008-11-11 21:37:06 UTC (rev 14)
@@ -1,74 +0,0 @@
-<?php
-$dir = "../desktop/";
-$dirP = "desktop/";
-$img = "img/";
-$items = array();
-$d = dir($dir);
-
-$i = 0;
-
-while($name = $d->read()){
-
-    // Skip this for Linux's users
-    if( $name == '..' || $name == '.' ) { continue; }
-
-    // Skip hidden files/folders
-    if( substr($name, 0, 1) == '.' ) { continue; }
-
-    // Files
-    if( is_file($dir.$name) ) {
-
-      // Images ?
-      if(preg_match('/\.(jpg|gif|png)$/', $name)) {
-
-	$size = filesize($dir.$name);
-	$lastmod = filemtime($dir.$name)*1000;
-	$items[] = array(
-		    'id'=>$i,
-		    'type'=>'file',
-		    'originName'=>$name,
-		    'name'=>$name,
-		    'size'=>$size,
-		    'lastmod'=>$lastmod,
-		    'url'=>$dirP.$name
-	);
-
-      } else {
-      // Common files
-	$size = filesize($dir.$name);
-	$lastmod = filemtime($dir.$name)*1000;
-	$items[] = array(
-		    'id'=>$i,
-		    'type'=>'file',
-		    'originName'=>$name,
-		    'name'=>$name,
-		    'size'=>$size,
-		    'lastmod'=>$lastmod,
-		    'url'=>$img.'text.png'
-	);
-
-      }
-    } else if( is_dir($dir.$name) ) {
-
-    // Folders
-      $size = disk_total_space($dir.$name);
-      $lastmod = filemtime($dir.$name)*1000;
-      $items[] = array(
-		  'id'=>$i,
-		  'type'=>'folder',
-		  'originName'=>$name,
-		  'name'=>$name,
-		  'size'=>$size,
-		  'lastmod'=>$lastmod,
-		  'url'=>$img.'folder'
-    );
-
-    }
-$i ++;
-}
-$d->close();
-
-
-$o = array('items'=>$items);
-echo json_encode($o);
-?>
\ No newline at end of file

Deleted: yannick/php/get-state.php
===================================================================
--- yannick/php/get-state.php	2008-11-11 21:35:33 UTC (rev 13)
+++ yannick/php/get-state.php	2008-11-11 21:37:06 UTC (rev 14)
@@ -1,22 +0,0 @@
-<?php
-
-$stateFile = "../desktop/.shortcutState";
-
-$state = Array("success" => true);
-
-if( !is_file($stateFile) ) { echo "{success:false}"; exit; }
-
-$content = file_get_contents($stateFile);
-
-$xml = new SimpleXMLElement($content);
-
-foreach ($xml->element as $item) {
-   $state[(string)$item->filename] = Array(
-	'name' => (string)$item->filename,
-	'posX' => (int)$item->posx,
-	'posY' => (int)$item->posy
-	);
-}
-
-echo json_encode($state);
-?>
\ No newline at end of file

Added: yannick/php/lib.php
===================================================================
--- yannick/php/lib.php	                        (rev 0)
+++ yannick/php/lib.php	2008-11-11 21:37:06 UTC (rev 14)
@@ -0,0 +1,141 @@
+<?php
+
+// ShortCut class
+
+class shortcut {
+
+    var $desktop   = '../desktop/';
+    var $desktopJs = 'desktop/';
+    var $imgJs     = 'img/';
+    var $stateFile = '.shortcutState';
+
+    public function __construct() {
+
+    }
+
+    private function get_files() {
+
+    	$items = array();
+	$i = 0;
+	
+	$d = dir($this->desktop);
+	while($name = $d->read()){
+
+	    // Skip this for Linux's users
+	    if( $name == '..' || $name == '.' ) { continue; }
+
+	    // Skip hidden files/folders
+	    if( substr($name, 0, 1) == '.' ) { continue; }
+
+	    // Files
+	    if( is_file($this->desktop.$name) ) {
+
+	      // Images ?
+	      if(preg_match('/\.(jpg|gif|png)$/', $name)) {
+
+		$size = filesize($this->desktop.$name);
+		$lastmod = filemtime($this->desktop.$name)*1000;
+		$items[] = array(
+			    'id'=>$i,
+			    'type'=>'file',
+			    'originName'=>$name,
+			    'name'=>$name,
+			    'size'=>$size,
+			    'lastmod'=>$lastmod,
+			    'url'=>$this->desktopJs.$name
+		);
+
+	      } else {
+	      // Common files
+		$size = filesize($this->desktop.$name);
+		$lastmod = filemtime($this->desktop.$name)*1000;
+		$items[] = array(
+			    'id'=>$i,
+			    'type'=>'file',
+			    'originName'=>$name,
+			    'name'=>$name,
+			    'size'=>$size,
+			    'lastmod'=>$lastmod,
+			    'url'=>$this->imgJs.'text.png'
+		);
+
+	      }
+	    } else if( is_dir($this->desktop.$name) ) {
+
+	    // Folders
+	      $size = disk_total_space($this->desktop.$name);
+	      $lastmod = filemtime($this->desktop.$name)*1000;
+	      $items[] = array(
+			  'id'=>$i,
+			  'type'=>'folder',
+			  'originName'=>$name,
+			  'name'=>$name,
+			  'size'=>$size,
+			  'lastmod'=>$lastmod,
+			  'url'=>$this->imgJs.'folder'
+	    );
+
+	    }
+	$i ++;
+	}
+	$d->close();
+	
+	return $items;
+    
+    } //get_files
+
+    public function get_desktop_items() {
+
+	$o = array('items'=>$this->get_files());
+	echo json_encode($o);
+
+    } // get_desktop_items
+
+    public function get_state() {
+
+      $state = Array("success" => true);
+
+      if( !is_file($this->desktop.$this->stateFile) ) { echo "{success:false}"; }
+      else {
+	$content = file_get_contents($this->desktop.$this->stateFile);
+
+	$xml = new SimpleXMLElement($content);
+
+	foreach ($xml->element as $item) {
+	  $state[(string)$item->filename] = Array(
+		'name' => (string)$item->filename,
+		'posX' => (int)$item->posx,
+		'posY' => (int)$item->posy
+		);
+	}
+
+	echo json_encode($state);
+      }
+    }
+
+    public function fs_move_to($FileName, $to) {
+      rename($this->desktop.$FileName, $this->desktop.$to.'/'.$FileName);
+    }
+
+    public function fs_update_filename($originName, $newName) {
+
+      $o->success = false;
+
+      @rename($this->desktop.$originName, $this->desktop.$newName) or die(json_encode($o));
+
+      $o->success = true;
+      $o->newName = $newName;
+
+      echo json_encode($o);
+
+    }
+
+    public function __destruct() {
+    
+    }
+
+}
+
+
+
+?>
\ No newline at end of file

Deleted: yannick/php/move-to.php
===================================================================
--- yannick/php/move-to.php	2008-11-11 21:35:33 UTC (rev 13)
+++ yannick/php/move-to.php	2008-11-11 21:37:06 UTC (rev 14)
@@ -1,9 +0,0 @@
-<?php
-$dir = "../desktop/";
-
-$moveTo = $_POST['moveTo'];
-$name = $_POST['name'];
-
-rename($dir.$name, $dir.$moveTo.'/'.$name);
-
-?>
\ No newline at end of file

Added: yannick/php/shortcuts.php
===================================================================
--- yannick/php/shortcuts.php	                        (rev 0)
+++ yannick/php/shortcuts.php	2008-11-11 21:37:06 UTC (rev 14)
@@ -0,0 +1,30 @@
+<?php
+
+// Call the class
+include "lib.php";
+
+$o = new shortcut();
+
+$what = $_POST['what'];
+
+
+switch ($what) {
+
+  case 'get-desktop' :
+	$o->get_desktop_items();
+	break;
+
+  case 'get-state' :
+	$o->get_state();
+	break;
+
+  case 'move-to' :
+	$o->fs_move_to($_POST['name'], $_POST['moveTo']);
+	break;
+
+  case 'update-fileName' :
+	$o->fs_update_filename($_POST['originName'], $_POST['newName']);
+	break;
+}
+
+?>
\ No newline at end of file

Deleted: yannick/php/update-filename.php
===================================================================
--- yannick/php/update-filename.php	2008-11-11 21:35:33 UTC (rev 13)
+++ yannick/php/update-filename.php	2008-11-11 21:37:06 UTC (rev 14)
@@ -1,15 +0,0 @@
-<?php
-$dir = "../desktop/";
-
-$originName = $_POST['originName'];
-$NewValue = $_POST['NewValue'];
-
-$o->success = false;
-
-@rename($dir.$originName, $dir.$NewValue) or die(json_encode($o));
-
-$o->success = true;
-$o->newName = $NewValue;
-
-echo json_encode($o);
-?>
\ No newline at end of file


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/