1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7use Tiki\FileGallery\File; 8 9/** 10 * Class Services_Diagram_Controller 11 * 12 * Controller for diagram related operations 13 * 14 */ 15class Services_Diagram_Controller 16{ 17 /** 18 * Controller setup function. Runs before any action 19 * @throws Services_Exception_Disabled 20 */ 21 public function setUp() 22 { 23 Services_Exception_Disabled::check('wikiplugin_diagram'); 24 } 25 26 /** 27 * Function used to cache a diagram. 28 * If the diagram is represented inline in a page, the cache file name result will be the md5 of the content 29 * @param $input 30 * @return array 31 * @throws Exception 32 */ 33 public function action_image($input) 34 { 35 global $prefs; 36 37 $payload = []; 38 39 if ($prefs['fgal_export_diagram_on_image_save'] !== 'y' || ! function_exists('simplexml_load_string')) { 40 return false; 41 } 42 43 $cacheLib = TikiLib::lib('cache'); 44 $fileId = $input->fileId->int(); 45 $data = $input->data->value(); 46 $rawXml = $input->content->value(); 47 48 if (! is_null($fileId) && $fileId !== 0) { 49 $file = File::id($fileId); 50 51 if (empty($file)) { 52 return false; 53 } 54 55 $rawXml = $file->data(); 56 } 57 58 $diagramRoot = simplexml_load_string($rawXml); 59 60 foreach ($diagramRoot->diagram as $diagram) { 61 $diagramId = (string) $diagram->attributes()->id; 62 $cacheLib->cacheItem(md5($diagram->asXML()), $data[$diagramId], 'diagram'); 63 } 64 65 if (! empty($input->ticketsAmount->int())) { 66 $payload['new_tickets'] = []; 67 $accesslib = TikiLib::lib('access'); 68 69 for ($i = 0; $i < $input->ticketsAmount->int(); $i++) { 70 $accesslib->setTicket(); 71 $payload['new_tickets'][] = $accesslib->getTicket(); 72 } 73 } 74 75 return $payload; 76 } 77} 78