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$ 7 8use Symfony\Component\Yaml\Yaml; 9 10class Services_Export_Controller 11{ 12 /** 13 * Get all content that could be synced with remote Tiki. 14 * @return array 15 */ 16 function action_sync_content($input) 17 { 18 global $user; 19 20 $userlib = TikiLib::lib('user'); 21 list($isvalid, $user) = $userlib->validate_user($input->user->text(), $input->password->text()); 22 23 if (! $isvalid) { 24 return [ 25 'error' => 'Specified user credentials are invalid.' 26 ]; 27 } 28 29 // enforce permissions of the incoming user and their groups 30 $_permissionContext = new Perms_Context($user); 31 32 $perms = Perms::get(); 33 if (! $perms->admin) { 34 return [ 35 'error' => 'Specified user is not an administrator.' 36 ]; 37 } 38 39 return [ 40 'data' => $this->dumpContent(), 41 'status' => 'ok' 42 ]; 43 } 44 45 /** 46 * Currently available: wiki pages and tracker definitions + preferences/configuration. 47 * @return string 48 */ 49 function dumpContent() { 50 global $prefs; 51 52 $data = "Preferences:\n"; 53 $data .= Yaml::dump($prefs, 20, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); 54 55 $writer = new \Tiki_Profile_Writer("profiles", "temporary_export"); 56 \Tiki_Profile_InstallHandler_WikiPage::export($writer, '', true); 57 \Tiki_Profile_InstallHandler_Tracker::export($writer, '', true); 58 59 $data .= $writer->dump(); 60 61 foreach ($writer->getExternalWriter()->getFiles() as $file => $content) { 62 $data .= "\n\n$file\n$content"; 63 } 64 65 return $data; 66 } 67} 68