Browse Source

plugin fritzing (en construction)

idleman 6 years ago
parent
commit
8c43500568

+ 67 - 0
plugin/fritzing/Fritzing.class.php

@@ -0,0 +1,67 @@
+<?php
+class Fritzing {
+
+	public static function manifest(){
+		return array(
+			'uid' => 'fritzing',
+			'label' => 'Schéma fritzing',
+			'description' => 'Fichier pour le logiciel fritzing',
+			'fromExtension' => array('fzz'),
+			'toExtension' => 'fzz',
+			'upload' => array(
+				'url'     => 'action.php?action=upload_resource_file',
+				'element' => '#dropZoneFiles',
+				'callback' => "refresh_fritzing();",
+			)
+		);
+	}
+
+	//Import depuis un glisser déposé du fichier
+	public static function fromFile($resource){
+		$resource->save();
+		$ext = getExt($resource->label);
+		$name = $resource->id.'.'.$ext;
+		file_put_contents(SKETCH_PATH.$name,$resource->content);
+		$resource->content = $name;
+		return $resource;
+	}
+
+	//Import depuis un flux json compressé de la ressource
+	public static function fromJson($resource){
+		$resource->save();
+		$stream = base64_decode($resource->content);
+		$resource->content = $resource->id.'.png';
+		file_put_contents(SKETCH_PATH.$resource->content,$stream);
+		return $resource;
+	}
+	
+	//export en fichier JSON compressé de la ressource
+	public static function toJson($resource){
+		$resource = $resource->toArray();
+		$resource['content'] = base64_encode(file_get_contents(SKETCH_PATH.$resource['content']));
+		return $resource;
+	}
+
+	public static function toFile($resource){
+
+		$ext = getExt($resource->content);
+		$infos = self::manifest();
+		return array(
+			'name'=> slugify($resource->label).'.'.$ext,
+			'content' => file_exists(SKETCH_PATH.$resource->content) ? file_get_contents(SKETCH_PATH.$resource->content) : ''
+		);
+	}
+
+	public static function toHtml($resource,$sketch){
+		global $myUser;
+		$infos = self::manifest();
+
+		$content = $resource->content ==''?'Envoyer un fichier':'<a href="action.php?action=get_resource&id='.$resource->id.'">Télécharger</a>';
+		$response['content'] = '<div id="dropZoneFiles" style="width:100%;height:auto;" class="dropzone">'.$content.'</div>';
+		if($myUser->id == $sketch->owner)
+			$response['upload'] = $infos['upload'];
+		
+		return $response;
+	}
+}
+?>

+ 10 - 0
plugin/fritzing/action.php

@@ -0,0 +1,10 @@
+<?php
+
+global $_,$conf;
+switch($_['action']){
+	case 'test_load':
+
+	break;
+}
+
+?>

+ 9 - 0
plugin/fritzing/app.json

@@ -0,0 +1,9 @@
+{
+	"id": "fr.idleman.fritzing",
+	"name": "Fritzing",
+	"version": "1.0",
+	"url": "http://blog.idleman.fr",
+	"licence": {"name": "MIT","url" : "http://choosealicense.com/licenses/mit/"},
+	"description": "Ajout des types de ressources fritzing",
+	"require" : {}
+}

BIN
plugin/fritzing/example.fzz


+ 38 - 0
plugin/fritzing/fritzing.plugin.php

@@ -0,0 +1,38 @@
+<?php
+
+
+
+
+
+
+function fritzing_plugin_add_type(&$types){
+	$types['fritzing'] = __DIR__.SLASH.'Fritzing.class.php';
+}
+
+
+
+function fritzing_plugin_install($id){
+	if($id != 'fr.idleman.fritzing') return;
+	// en cas d'erreur : throw new Exception('Mon erreur');
+}
+function fritzing_plugin_uninstall($id){
+	if($id != 'fr.idleman.fritzing') return;
+	// en cas d'erreur : throw new Exception('Mon erreur');
+}
+
+
+//cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
+function fritzing_plugin_action(){
+	require_once('action.php');
+}
+
+
+Plugin::addCss("/main.css"); 
+Plugin::addJs("/main.js"); 
+
+Plugin::addHook("install", "fritzing_plugin_install");
+Plugin::addHook("uninstall", "fritzing_plugin_uninstall"); 
+Plugin::addHook("action", "fritzing_plugin_action");    
+Plugin::addHook("resource_type", "fritzing_plugin_add_type");    
+
+?>

+ 0 - 0
plugin/fritzing/main.css


+ 3 - 0
plugin/fritzing/main.js

@@ -0,0 +1,3 @@
+function refresh_fritzing(){
+	alert('Plugin en construction');
+}