PageRenderTime 36ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/extensions.ext/plugins/PluginsController.php

https://bitbucket.org/udfr/uc3-udfr-ontowiki
PHP | 2188 lines | 1784 code | 141 blank | 263 comment | 227 complexity | 744d66d8c069aada55ec866291ac7b9c MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. require_once 'OntoWiki/Controller/Component.php';
  3. require_once 'OntoWiki/Toolbar.php';
  4. require_once 'Erfurt/Sparql/SimpleQuery.php';
  5. require_once 'Zend/Http/Client.php';
  6. /**
  7. * Controller for the OntoWiki Plugin Manager
  8. *
  9. * @category OntoWiki
  10. * @package OntoWiki_extensions_components_plugins
  11. * @author Qiu Feng <qiu_feng39@hotmail.com>
  12. * @copyright Copyright (c) 2008, {@link http://aksw.org AKSW}
  13. * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
  14. * @version $$
  15. */
  16. class PluginsController extends OntoWiki_Controller_Component
  17. {
  18. public function init()
  19. {
  20. parent::init();
  21. require_once('Zend/Paginator.php');
  22. require_once('Zend/Paginator/Adapter/Array.php');
  23. // Action Based Access Control for the Plugin Manager
  24. $owApp = OntoWiki::getInstance();
  25. if (!$this->_erfurt->isActionAllowed('PluginManagement')){
  26. //TODO uncomment after changes
  27. //require_once 'Erfurt/Ac/Exception.php';
  28. //throw new Erfurt_Ac_Exception('You are not allowed to use the Plugin Manager.');
  29. }
  30. OntoWiki_Navigation::reset();
  31. OntoWiki_Navigation::register('categories', array(
  32. 'controller' => 'plugins',
  33. 'action' => 'categories',
  34. 'name' => 'Search',
  35. 'position' => 0,
  36. 'active' => false
  37. ));
  38. OntoWiki_Navigation::register('new', array(
  39. 'controller' => 'plugins',
  40. 'action' => 'new-plugins',
  41. 'name' => 'What\'s new',
  42. 'position' => 1,
  43. 'active' => false
  44. ));
  45. OntoWiki_Navigation::register('installed', array(
  46. 'controller' => 'plugins',
  47. 'action' => 'installed',
  48. 'name' => 'Installed',
  49. 'position' => 2,
  50. 'active' => false
  51. ));
  52. }
  53. /**
  54. *
  55. *
  56. *
  57. */
  58. public function pluglistAction()
  59. {
  60. $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
  61. $u_query = 'PREFIX type: <'.$this->_privateConfig->p_type_base.'>
  62. PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
  63. PREFIX name: <'.$this->_privateConfig->p_name_base.'>
  64. PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
  65. PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
  66. PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  67. PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
  68. SELECT ?node ?name ?description ?developer ?url
  69. WHERE {?node type: plugin:.
  70. ?node name: ?name.
  71. ?node description: ?description.
  72. ?node developer: ?developer.
  73. ?node release: ?version.
  74. ?version url: ?url.}';
  75. $client->setParameterPost('query', $u_query);
  76. $client->setHeaders('Accept', 'application/sparql-results+json');
  77. $response = $client->request('POST');
  78. $sparl_results = Zend_Json::decode($response->getBody());
  79. $results = array();
  80. $wrong_response = false;
  81. if (!strstr($response->getBody(),'bindings')) {
  82. $wrong_response = true;
  83. $this->_owApp->appendMessage(
  84. new OntoWiki_Message('Plugin Repository not reachable', OntoWiki_Message::ERROR )
  85. );
  86. }
  87. if (count($sparl_results['results']['bindings']) != 0 && !$wrong_response) {
  88. $i = 0;
  89. foreach ($sparl_results['results']['bindings'] as $a_sparal_result) {
  90. $plugin_name = $a_sparal_result['name']['value'];
  91. $plugin_developer = $a_sparal_result['developer']['value'];
  92. $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, '', $plugin_developer);
  93. $plugin_desciption = $a_sparal_result['description']['value'];
  94. $results[$i] = array(
  95. 'name' => $plugin_name,
  96. 'developer' => $plugin_developer,
  97. 'description' => $plugin_desciption,
  98. );
  99. $i++;
  100. }
  101. }
  102. $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/plugin.css');
  103. $this->view->plugins = $results;
  104. //return 'plugins list';
  105. }
  106. /**
  107. * categorieAction
  108. *
  109. * This action can let the user to choose the category
  110. * of plungin that they want to search
  111. */
  112. public function categoriesAction()
  113. {
  114. //Rights check
  115. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Plugin Categories'));
  116. OntoWiki_Navigation::setActive('categories',true);
  117. require_once 'OntoWiki/Message.php';
  118. //End Rights check
  119. //Javascript for the plugintemplates
  120. $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/plugin.css');
  121. $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/pluginselect.js');
  122. $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/tagcloud.css');
  123. $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/createtagcloud.js');
  124. $pluginurl = $this->_componentUrlBase;
  125. $this->view->pluginurl = $pluginurl;
  126. //End Javascript
  127. /*Query to the Repository*/
  128. $from = "categories";
  129. $search_keyword = $this->_request->getPost('search_keyword', '');
  130. if ($this->_request->isPost()) {
  131. $categorie_select = $this->_request->getPost('categorie_select');
  132. $sort_kind = $this->_request->getPost('sort_kind', 'name');
  133. $sort_priority = $this->_request->getPost('sort_priority', 'ASC');
  134. $this->_session->plugins_per_page = $this->_request->getPost('plugins_per_page', 3);
  135. $this->_session->sort_priority = $sort_priority;
  136. $this->_session->sort_kind = $sort_kind;
  137. //echo $categorie_select." ".$sort_kind." ".$sort_priority." ".$this->_session->plugins_per_page;
  138. }
  139. else {
  140. $sort_kind = "name";
  141. $sort_priority = "ASC";
  142. $selected_tag = $this->getParam('tag');
  143. if ($selected_tag != ''){
  144. $from = "tag";
  145. }
  146. }
  147. //Information for sorting
  148. if (isset($this->_session->sort_kind)) {
  149. $sort_kind = $this->_session->sort_kind;
  150. }
  151. else {
  152. $sort_kind = 'name';
  153. }
  154. if (isset($this->_session->sort_priority)) {
  155. $sort_priority = $this->_session->sort_priority;
  156. }
  157. else {
  158. $sort_priority = 'ASC';
  159. }
  160. $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
  161. //$client = Erfurt_App::getInstance()->getHttpClient($this->_config->urlBase . 'sparql/');
  162. //echo $this->_config->urlBase . 'sparql/';
  163. //$u_query = 'SELECT * WHERE {?s ?p ?o} limit 100';
  164. $wrong_response = false;
  165. // if there is no search
  166. if ($search_keyword == '') {
  167. if ($from == 'categories' && $search_keyword == '') {
  168. $u_query = 'PREFIX type: <'.$this->_privateConfig->p_type_base.'>
  169. PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
  170. PREFIX name: <'.$this->_privateConfig->p_name_base.'>
  171. PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
  172. PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
  173. PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  174. PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
  175. SELECT ?node ?name ?description ?developer ?url
  176. WHERE {?node type: plugin:.
  177. ?node name: ?name.
  178. ?node description: ?description.
  179. ?node developer: ?developer.
  180. ?node release: ?version.
  181. ?version url: ?url.}';
  182. }
  183. // User search for somthing
  184. /*elseif ($from == 'categories' && $search_keyword != '') {
  185. $search_keyword = trim($search_keyword);
  186. $this->searchForUrl($search_keyword, $client);
  187. $search_keyword = trim($search_keyword);
  188. $first_letter = strtoupper(substr($search_keyword, 0, 1));
  189. $search_keyword = $first_letter . substr($search_keyword, 1);
  190. $u_query = " PREFIX type: <'.$this->_privateConfig->p_type_base.'>
  191. PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
  192. PREFIX name: <'.$this->_privateConfig->p_name_base.'>
  193. PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
  194. PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
  195. PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  196. PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
  197. PREFIX tag: <'.$this->_privateConfig->p_tag_base.'>
  198. SELECT ?node ?name ?description ?developer ?url
  199. WHERE { ?node type: plugin:.
  200. ?node name: ?name.
  201. ?node description: ?description.
  202. ?node developer: ?developer.
  203. ?node release: ?version.
  204. ?version url: ?url.
  205. ?version tag: \"$search_keyword\"^^xsd:string.}";
  206. }*/
  207. elseif ($from == 'tag') {
  208. $u_query = " PREFIX type: <".$this->_privateConfig->p_type_base.">
  209. PREFIX plugin: <".$this->_privateConfig->plugin_base.">
  210. PREFIX name: <".$this->_privateConfig->p_name_base.">
  211. PREFIX description: <".$this->_privateConfig->p_desc_base.">
  212. PREFIX developer: <".$this->_privateConfig->p_dev_base.">
  213. PREFIX release: <".$this->_privateConfig->p_release_base.">
  214. PREFIX url: <".$this->_privateConfig->filerelease_base.">
  215. PREFIX tag: <".$this->_privateConfig->p_tag_base.">
  216. SELECT ?node ?name ?description ?developer ?url
  217. WHERE { ?node type: plugin:.
  218. ?node name: ?name.
  219. ?node description: ?description.
  220. ?node developer: ?developer.
  221. ?node release: ?version.
  222. ?version url: ?url.
  223. ?version tag: \"$selected_tag\"^^xsd:string.}";
  224. }
  225. $u_query = $u_query . "ORDER BY " . $sort_priority . "(?" . $sort_kind . ")";
  226. //$u_query = $u_query." ORDER BY DESC(?name)";
  227. //echo "query: ".$u_query."<br/>";
  228. $client->setParameterPost('query', $u_query);
  229. $client->setHeaders('Accept', 'application/sparql-results+json');
  230. $response = $client->request('POST');
  231. //print_r($response);
  232. //print_r($response->getBody());
  233. //echo"<br/><br/>";
  234. /*End*/
  235. /*Change the results in an array*/
  236. $sparl_results = Zend_Json::decode($response->getBody());
  237. //print_r($sparl_results['bindings'][0]);
  238. $results = array();
  239. if (!strstr($response->getBody(),'bindings')) {
  240. $wrong_response = true;
  241. $this->_owApp->appendMessage(
  242. new OntoWiki_Message('Plugin Repository not reachable', OntoWiki_Message::ERROR )
  243. );
  244. }
  245. if (count($sparl_results['results']['bindings']) != 0 && !$wrong_response) {
  246. $i = 0;
  247. foreach ($sparl_results['results']['bindings'] as $a_sparal_result) {
  248. $plugin_name = $a_sparal_result['name']['value'];
  249. $plugin_developer = $a_sparal_result['developer']['value'];
  250. $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, '', $plugin_developer);
  251. $plugin_desciption = $a_sparal_result['description']['value'];
  252. $plugin_install_url = $a_sparal_result['url']['value'];
  253. $results[$i] = array(
  254. 'name' => $plugin_name,
  255. 'developer' => $plugin_developer,
  256. 'description' => $plugin_desciption,
  257. 'install_url' => $plugin_install_url
  258. );
  259. $i++;
  260. }
  261. }
  262. } // end if there is no search
  263. // if user wants to search
  264. else {
  265. $results = $this->searchForPlugins($search_keyword, $client, $wrong_response, $sort_kind, $sort_priority);
  266. }
  267. $count = count($results);
  268. if (!$wrong_response) {
  269. if (!isset($results)|| $count == 0) {
  270. $this->_owApp->appendMessage(
  271. new OntoWiki_Message('No Matching!', OntoWiki_Message::WARNING )
  272. );
  273. }
  274. else {
  275. $message = $count.' plugin(s) found!';
  276. $this->_owApp->appendMessage(
  277. new OntoWiki_Message($message, OntoWiki_Message::INFO )
  278. );
  279. }
  280. }
  281. /* Get Tags */
  282. if ($from == 'tag') {
  283. $tags_results = $this->getTags($selected_tag);
  284. }
  285. else {
  286. $tags_results = $this->getTags(null);
  287. }
  288. $this->view->tags = $tags_results;
  289. //echo "<br/><br/>TAGS_DECODE: ".print_r($tags_results)."<br/>";
  290. //echo"<br/><br/>";
  291. //Check the ftp-configuation in component.ini
  292. if (isset($this->_privateConfig->ftp->username) && isset($this->_privateConfig->ftp->password) && isset($this->_privateConfig->ftp->hostname)) {
  293. $ftp_config = true; // true or false didn't work?!
  294. }
  295. else {
  296. $ftp_config = false;
  297. }
  298. //Start use a Zend_paginator;
  299. $page =1;
  300. $numPerPage = 3;
  301. if (isset($this->_session->plugins_per_page)) {
  302. $numPerPage = $this->_session->plugins_per_page;
  303. }
  304. $this->view->plugins_per_page = $numPerPage;
  305. if (isset($_GET['page']) && is_numeric($_GET['page'])){
  306. $page = $_GET['page'];
  307. }
  308. $offset = $numPerPage*$page;
  309. $this->count = $count;
  310. $this->view->results = $results;
  311. $this->view->to_translate = $this->getFrontController()->getBaseUrl() . '/plugins/categories';
  312. $this->view->toinstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/getinfo';
  313. $this->view->ftp_config = $ftp_config;
  314. $this->view->plugin_outlook = $this->_privateConfig->client->plugin_outlook;
  315. $this->view->sort_priority = $sort_priority;
  316. $this->view->sort_kind = $sort_kind;
  317. $this->page($page, $numPerPage, $results);
  318. $this->render();
  319. //End
  320. //End
  321. }
  322. /**
  323. * newPluginsAction
  324. *
  325. * Show the new Plugins
  326. */
  327. public function newPluginsAction()
  328. {
  329. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('The plugins, new or just updatet'));
  330. OntoWiki_Navigation::setActive('new',true);
  331. require_once 'OntoWiki/Message.php';
  332. //Javascript for the plugintemplates
  333. $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/plugin.css');
  334. $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/pluginselect.js');
  335. $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/tagcloud.css');
  336. $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/createtagcloud.js');
  337. $pluginurl = $this->_componentUrlBase;
  338. $this->view->pluginurl = $pluginurl;
  339. //End
  340. /*Query to the Repository*/
  341. $from = "newPlugins";
  342. if ($this->_request->isPost()) {
  343. $sort_kind = $this->_request->getPost('sort_kind');
  344. $sort_priority = $this->_request->getPost('sort_priority');
  345. $this->_session->plugins_per_page = $this->_request->getPost('plugins_per_page');
  346. $newplugins_in_days = $this->_request->getPost('newplugins_in_days');
  347. $this->_session->newplugins_in_days = $newplugins_in_days;
  348. $this->_session->sort_priority = $sort_priority;
  349. $this->_session->sort_kind = $sort_kind;
  350. }
  351. else {
  352. if (isset($this->_session->newplugins_in_days)) {
  353. $newplugins_in_days = $this->_session->newplugins_in_days;
  354. }
  355. else {
  356. $newplugins_in_days = 0;
  357. }
  358. if (isset($this->_session->sort_priority)) {
  359. $sort_priority = $this->_session->sort_priority;
  360. }
  361. else {
  362. $sort_priority = "ASC";
  363. }
  364. if (isset($this->_session->sort_kind)) {
  365. $sort_kind = $this->_session->sort_kind;
  366. }
  367. else {
  368. $sort_kind = "name";
  369. }
  370. $selected_tag = $this->getParam('tag');
  371. if ($selected_tag != ''){
  372. $from = "tag";
  373. }
  374. }
  375. $daysago_in_seconds = $newplugins_in_days*60*60*24;
  376. $deadline = date('Y-m-d', time() - $daysago_in_seconds) . 'T00:00:00.000';
  377. //echo "<br/>$deadline<br/>";
  378. $this->view->deadline = $deadline;
  379. $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
  380. $u_query = 'PREFIX type: <'.$this->_privateConfig->p_type_base.'>
  381. PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
  382. PREFIX name: <'.$this->_privateConfig->p_name_base.'>
  383. PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
  384. PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
  385. PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  386. PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
  387. PREFIX modified: <'.$this->_privateConfig->p_modified_base.'>
  388. SELECT ?node ?name ?description ?developer ?url ?modified
  389. WHERE {?node type: plugin:.
  390. ?node name: ?name.
  391. ?node description: ?description.
  392. ?node developer: ?developer.
  393. ?node release: ?version.
  394. ?node modified: ?modified.
  395. ?version url: ?url.';
  396. $u_query = $u_query . ' FILTER (xsd:dateTime(?modified)>="' . $deadline . '"^^xsd:dateTime) }';
  397. //echo "<br/>u_query: $u_query<br/>";
  398. $u_query = $u_query . "ORDER BY " . $sort_priority . "(?" . $sort_kind . ")";
  399. $client->setParameterPost('query',$u_query);
  400. $client->setHeaders('Accept', 'application/sparql-results+json');
  401. $response = $client->request('POST');
  402. $sparl_results = Zend_Json::decode($response->getBody());
  403. //print_r($sparl_results['bindings'][0]);
  404. $results = array();
  405. if (count($sparl_results['results']['bindings']) != 0) {
  406. $i = 0;
  407. foreach ($sparl_results['results']['bindings'] as $a_sparal_result){
  408. $plugin_name = $a_sparal_result['name']['value'];
  409. $plugin_developer = $a_sparal_result['developer']['value'];
  410. $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, "", $plugin_developer);
  411. $plugin_desciption = $a_sparal_result['description']['value'];
  412. $plugin_install_url = $a_sparal_result['url']['value'];
  413. $results[$i] = array(
  414. 'name' => $plugin_name,
  415. 'developer' => $plugin_developer,
  416. 'description' => $plugin_desciption,
  417. 'install_url' => $plugin_install_url
  418. );
  419. $i++;
  420. }
  421. }
  422. $count = count($results);
  423. if (!isset($results)|| $count == 0) {
  424. $this->_owApp->appendMessage(
  425. new OntoWiki_Message('No Matching!', OntoWiki_Message::WARNING )
  426. );
  427. }
  428. else {
  429. $message = $count.' plugin(s) found!';
  430. $this->_owApp->appendMessage(
  431. new OntoWiki_Message($message, OntoWiki_Message::INFO )
  432. );
  433. }
  434. /* Get Tags */
  435. if ($from == 'tag') {
  436. $tags_results = $this->getTags($selected_tag);
  437. }
  438. else {
  439. $tags_results = $this->getTags(null);
  440. }
  441. $this->view->tags = $tags_results;
  442. //Start use a Zend_paginator;
  443. $page =1;
  444. $numPerPage = 3;
  445. if (isset($this->_session->plugins_per_page)){
  446. $numPerPage = $this->_session->plugins_per_page;
  447. }
  448. $this->view->plugins_per_page = $numPerPage;
  449. if (isset($_GET['page']) && is_numeric($_GET['page'])){
  450. $page = $_GET['page'];
  451. }
  452. $offset = $numPerPage*$page;
  453. $this->count = $count;
  454. $this->view->results = $results;
  455. $this->view->new_plugins = $this->getFrontController()->getBaseUrl().'/plugins/new-plugins';
  456. $this->view->toinstall_url = $this->getFrontController()->getBaseUrl().'/plugins/toinstall';
  457. $this->view->plugin_outlook = $this->_privateConfig->client->plugin_outlook;
  458. $this->view->newplugins_in_days = $newplugins_in_days;
  459. $this->view->sort_priority = $sort_priority;
  460. $this->view->sort_kind = $sort_kind;
  461. $this->page($page, $numPerPage, $results);
  462. $this->render();
  463. }
  464. /**
  465. * installedAction
  466. *
  467. * The functions for a plugin-developer
  468. */
  469. public function installedAction()
  470. {
  471. $selected_categorie = 'all'; // this function can have more uses
  472. if ($this->_request->isPost()) {
  473. $selected_categorie = $this->_request->getPost('categorie_select');
  474. $_SESSION['qiufeng']['plugins_per_page'] = $this->_request->getPost('plugins_per_page');
  475. }
  476. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Installed Plugins'));
  477. $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/makesure.js');
  478. OntoWiki_Navigation::setActive('installed', true);
  479. /* Ready from SystemConfig */
  480. $results = $this->readFromSysConfig('all');
  481. //print_r($results);
  482. $this->view->installedaction_url = $this->getFrontController()->getBaseUrl() . '/plugins/installed';
  483. $this->view->toinstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/toinstall';
  484. $this->view->touninstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/touninstall';
  485. $this->view->install_from_file_url = $this->getFrontController()->getBaseUrl() . '/plugins/install-From-File';
  486. if ($results === null) {
  487. $this->_owApp->appendMessage(
  488. new OntoWiki_Message('No plugin is installed!', OntoWiki_Message::WARNING )
  489. );
  490. $this->view->results = null;
  491. $numPerPage = 3;
  492. $this->view->plugins_per_page = $numPerPage;
  493. if (isset($_SESSION['qiufeng']['plugins_per_page'])) {
  494. $numPerPage = $_SESSION['qiufeng']['plugins_per_page'];
  495. }
  496. $this->view->plugins_per_page = $numPerPage;
  497. $this->page(1, $numPerPage, array());
  498. $this->render();
  499. }
  500. else {
  501. $results_without_upgrade = $results;
  502. $results = $this->searchupgrade($results_without_upgrade);
  503. $count = count($results);
  504. $message = "$count plugin(s) installed!";
  505. $this->_owApp->appendMessage(
  506. new OntoWiki_Message($message, OntoWiki_Message::INFO )
  507. );
  508. //Start use a Zend_pageinator;
  509. $page =1;
  510. $numPerPage = 3;
  511. $this->view->plugins_per_page = $numPerPage;
  512. if (isset($_SESSION['qiufeng']['plugins_per_page'])) {
  513. $numPerPage = $_SESSION['qiufeng']['plugins_per_page'];
  514. }
  515. $this->view->plugins_per_page = $numPerPage;
  516. if (isset($_GET['page']) && is_numeric($_GET['page'])) {
  517. $page = $_GET['page'];
  518. }
  519. $offset = $numPerPage*$page;
  520. $this->count = $count;
  521. $this->view->results = $results;
  522. $this->view->to_translate = $this->getFrontController()->getBaseUrl() . '/plugins/installed';
  523. $this->page($page,$numPerPage,$results);
  524. $this->render();
  525. //End
  526. }
  527. }
  528. /**
  529. * installfromFileAction
  530. *
  531. * Action for installation from a file
  532. */
  533. public function installFromFileAction()
  534. {
  535. $this->getFrontController()->setParam('noViewRenderer', true);
  536. if ($_FILES['install_from_file']['error'] == UPLOAD_ERR_OK) {
  537. // upload ok, move file
  538. //$fileUri = $this->_request->getPost('file_uri');
  539. $fileName = $_FILES['install_from_file']['name'];
  540. $tmpName = $_FILES['install_from_file']['tmp_name'];
  541. $mimeType = $_FILES['install_from_file']['type'];
  542. //echo"<br/>fileName: $fileName tempName:$tmpName mimeType:$mimeType<br/>";
  543. if (substr(trim($fileName),-4) == '.zip') {
  544. $install_with_ftp = false;
  545. try {
  546. if (!move_uploaded_file($_FILES['install_from_file']['tmp_name'],$this->_componentRoot . '/temp/installfromfile.zip')) {
  547. $install_with_ftp = true;
  548. rename($_FILES['install_from_file']['tmp_name'], $_FILES['install_from_file']['tmp_name'] . '.zip');
  549. $tmp_file = $_FILES['install_from_file']['tmp_name'] . '.zip';
  550. $fp = fopen($tmp_file, 'r');
  551. echo "<br/>tmp_file:$tmp_file<br/>";
  552. if ($fp) {
  553. $data = '';
  554. while(!feof($fp)) {
  555. $data .= fread($fp, 1024);
  556. }
  557. fclose($fp);
  558. $fp = fopen($_FILES['install_from_file']['tmp_name'] . '_tmp.zip', "w+");
  559. if ($fp) {
  560. fwrite($fp,$data);
  561. fclose($fp);
  562. }
  563. $sftp = null;
  564. $connection = null;
  565. $this->ftpConnect($sftp, $connection);
  566. if (!$sftp) {
  567. $this->_redirect('plugins/errors/error/noftp');
  568. }
  569. else{
  570. $from_file = $_FILES['install_from_file']['tmp_name'] . '_tmp.zip';
  571. $to_file = $this->_componentRoot . '/temp/installfromfile.zip';
  572. $copy = ssh2_exec($connection, "cp $from_file $to_file");
  573. $chmod = ssh2_exec($connection, "chmod 0777 $to_file");
  574. unlink($from_file);
  575. unlink($_FILES['install_from_file']['tmp_name'] . '.zip');
  576. if( $copy && $chmod ){
  577. //do nothing
  578. }
  579. else {
  580. $this->_redirect('plugins/errors/error/exec');
  581. }
  582. }
  583. }
  584. }
  585. }
  586. catch (Exception $e) {
  587. }
  588. $this->_redirect('plugins/install-choice/from/installfromfile/name/' . str_replace('.zip','',$fileName));
  589. }
  590. else {
  591. $this->_redirect('plugins/errors/error/zip');
  592. }
  593. }
  594. else {
  595. $this->_redirect('plugins/errors/error/filenotfound');
  596. }
  597. }
  598. /**
  599. * Action to show the errormessage
  600. * if for example the rdf-file is
  601. * not correct
  602. *
  603. */
  604. public function errorsAction()
  605. {
  606. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Error!'));
  607. $error = $this->_getParam('error');
  608. if ($error == 'rdf') {
  609. $this->_owApp->appendMessage(
  610. new OntoWiki_Message('Error in RDF-file, installtion canceled!', OntoWiki_Message::ERROR)
  611. );
  612. }
  613. elseif ($error == 'zip') {
  614. $this->_owApp->appendMessage(
  615. new OntoWiki_Message('You can only upload an ZIP file!', OntoWiki_Message::ERROR)
  616. );
  617. }
  618. elseif ($error == 'filenotfound') {
  619. $this->_owApp->appendMessage(
  620. new OntoWiki_Message('File not found!', OntoWiki_Message::ERROR)
  621. );
  622. }
  623. elseif ($error == 'moveinstallfile') {
  624. $this->_owApp->appendMessage(
  625. new OntoWiki_Message('Could not move uploaded file!', OntoWiki_Message::ERROR)
  626. );
  627. }
  628. elseif ($error == 'noftp') {
  629. $this->_owApp->appendMessage(
  630. new OntoWiki_Message('Apache has no write right and could not build an ftp-connection!', OntoWiki_Message::ERROR)
  631. );
  632. }
  633. elseif ($error == 'exec') {
  634. $this->_owApp->appendMessage(
  635. new OntoWiki_Message('SSH2_EXEC ERROR!', OntoWiki_Message::ERROR)
  636. );
  637. }
  638. elseif ($error == 'installnoftp') {
  639. $this->_owApp->appendMessage(
  640. new OntoWiki_Message('Install: No FTP-connection!', OntoWiki_Message::ERROR)
  641. );
  642. }
  643. }
  644. /**
  645. * Action for Zen_paginator
  646. *
  647. * @param int $page
  648. * @param int $numPerPage
  649. * @param array $results
  650. */
  651. public function page($page, $numPerPage, $results)
  652. {
  653. $paginator = Zend_Paginator::factory($results);
  654. $paginator->setCurrentPageNumber($page)->setItemCountPerPage($numPerPage);
  655. $this->view->paginator = $paginator;
  656. }
  657. /**
  658. * Action for Zend_paginator
  659. *
  660. */
  661. public function pagelistAction(){
  662. Zend_Paginator::setDefaultScrollingStyle('Elastic');
  663. Zend_View_Helper_PaginationControl::setDefaultViewPartial('../pagelist/categoriepagelist.phtml');
  664. $paginator->setView($view);
  665. }
  666. /**
  667. * Function to install a plugin
  668. *
  669. */
  670. public function toinstallAction()
  671. {
  672. require_once("Erfurt/Syntax/RdfParser.php");
  673. /* maybe will be used */
  674. if ($this->_request->isPost()) {
  675. // do nothing
  676. }
  677. /* really installation*/
  678. else {
  679. $from = $this->_getParam('from');
  680. if ($from =='installfromfile' || $from == 'upgrade' || $from == 'reinstall' || $from = 'categoriepage') {
  681. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Installing...'));
  682. $p_name = $this->_getParam('name');
  683. if ($from == 'categoriepage') {
  684. $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
  685. }
  686. elseif ($from == 'installfromfile') {
  687. $url = $this->_componentRoot.'/temp/installfromfile.zip';
  688. }
  689. elseif ($from == 'upgrade') {
  690. $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
  691. }
  692. elseif ($from == 'reinstall') {
  693. $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
  694. }
  695. $this->view->install_png_url = $this->_componentUrlBase . 'img/download.png';
  696. //echo "<h3>categorie:".$p_categorie."</h3>";
  697. //echo '<h3 style="color:#FF0000">Plugin:'.$p_name."from: ".$url." is installed!</h3>";
  698. $fp = fopen($url, 'r');
  699. if ($fp) {
  700. $data = '';
  701. while(!feof($fp)) {
  702. $data .= fread($fp, 1024);
  703. }
  704. fclose($fp);
  705. $filename = 'extensions/components/plugins/' . $p_name. '.zip';
  706. $fp = fopen($filename, "w+");
  707. if ($fp && is_writable('extensions/components/plugins/')) {
  708. clearstatcache();
  709. fwrite($fp,$data);
  710. fclose($fp);
  711. $filepath = $filename;
  712. if (file_exists($filepath)) {
  713. $zip = new ZipArchive();
  714. $rs = $zip->open($filepath);
  715. if ($rs) {
  716. $fd = explode(".",basename($filepath));
  717. $zip->extractTo(dirname($filepath) . '/' . $fd[0]);
  718. $zip->close();
  719. unlink($filepath);
  720. /* check the rdf-file */
  721. $rdf_file_path = 'extensions/components/plugins/' . $p_name . '/package.rdf';
  722. $fpt = fopen($url, 'r');
  723. if ($fpt) {
  724. /*Parse the rdf-file in an array*/
  725. $rdf_parser = Erfurt_Syntax_RdfParser::rdfParserWithFormat('rdf');
  726. $rdf_result = $rdf_parser->parse($rdf_file_path, 20);
  727. //print_r($rdf_result);
  728. $rdf_format = true;
  729. $config_info = $this->checkAndRead($rdf_format,$rdf_result);
  730. //print_r($config_info);
  731. /* Check the directories */
  732. if ($rdf_format && $config_info != null) {
  733. $extension_dir = $config_info['extension_dir'];
  734. $extension_file = $config_info['extension_file'];
  735. $error_message = '';
  736. if ($this->checkDir($extension_dir,$extension_file,$error_message)){
  737. /* Copy the directories */
  738. $extension_path = $this->_componentRoot;
  739. $extension_path = str_replace('\\', '/', $extension_path);
  740. $extension_path = str_replace('/components/plugins','',$extension_path);
  741. $correct_installed = true;
  742. $component_root = str_replace('\\', '/', $this->_componentRoot);
  743. for ($i=0; $i<count($extension_dir); $i++) {
  744. $a_dir = $extension_dir[$i];
  745. try {
  746. $from_dir = $component_root . '/' . $p_name. '/' . $a_dir;
  747. $to_dir = $extension_path . '/' . $a_dir;
  748. //echo "from_dir: ".$from_dir."<br/>"."to_dir".$to_dir."<br/>";
  749. rename($from_dir,$to_dir);
  750. $correct_installed = file_exists($to_dir);
  751. }
  752. catch (Exception $e) {
  753. $this->_owApp->appendMessage(
  754. new OntoWiki_Message("Can't copy directory to $to_dir", OntoWiki_Message::ERROR)
  755. );
  756. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  757. }
  758. }
  759. for ($i=0; $i<count($extension_file); $i++) {
  760. $a_file = $extension_file[$i];
  761. try {
  762. $from_dir = $component_root.'/' . $p_name. '/' . $a_file;
  763. $to_dir = $extension_path . '/' . $a_file;
  764. //echo "from_dir: ".$from_dir."<br/>"."to_dir".$to_dir."<br/>";
  765. rename($from_dir,$to_dir);
  766. $correct_installed = file_exists($to_dir);
  767. }
  768. catch (Exception $e) {
  769. $this->_owApp->appendMessage(
  770. new OntoWiki_Message("Can't copy file to $to_dir", OntoWiki_Message::ERROR)
  771. );
  772. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  773. }
  774. }
  775. /* delete the unzipped file in a directory!!*/
  776. $this->delDirAndFile($this->_componentRoot . '/' . $p_name);
  777. $correct_deleted = file_exists($this->_componentRoot . '/' . $p_name);
  778. if ($correct_installed && !$correct_deleted) {
  779. if ($from == 'installfromfile') {
  780. /* delete the template sourcefile */
  781. unlink($this->_componentRoot.'temp/installfromfile.zip');
  782. }
  783. $this->_owApp->appendMessage(
  784. new OntoWiki_Message("New Plugin: $p_name is installed successfully!", OntoWiki_Message::SUCCESS)
  785. );
  786. $this->view->install_info_png = $this->_componentUrlBase . 'img/true.png';
  787. }
  788. else {
  789. $this->_owApp->appendMessage(
  790. new OntoWiki_Message('Unknow error', OntoWiki_Message::ERROR)
  791. );
  792. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  793. }
  794. /* write into SysConfig */
  795. $this->insertIntoSysConfig($config_info);
  796. if (!$this->_privateConfig->client->debug) {
  797. $this->_redirect('plugins/categories');
  798. }
  799. }
  800. else {
  801. /* Possible that the extension schould be upgraded, test if they have the same Base-URL */
  802. echo"<br>$error_message<br/>";
  803. if ($this->isinstalled($config_info)) {
  804. $dirs = $config_info['extension_dir'];
  805. $files = $config_info['extension_file'];
  806. $plugin_baseurl = $config_info['plugin_baseurl'];
  807. $dir_serialized = $this->seriation($dirs);
  808. $file_serialized = $this->seriation($files);
  809. /*Take care of '/' because of Zend_framwork */
  810. $dir_serialized = str_replace('/','@slash@',$dir_serialized);
  811. $file_serialized = str_replace('/','@slash@',$file_serialized);
  812. $plugin_baseurl = str_replace('/','@slash@',$plugin_baseurl);
  813. $reinstall_url = 'plugins/trytoreinstall/dirs/' . $dir_serialized . '/files/' . $file_serialized . '/p_name/' . $p_name . '/extension_url/' . $plugin_baseurl;
  814. if ($from == 'installfromfile') {
  815. $url_zip_file = $this->_componentRoot . '/temp/installfromfile.zip';
  816. $url_zip_file = str_replace('\\', '/', $url_zip_file);
  817. $reinstall_url = $reinstall_url . '/reinstall_from/file/file_url/' . $this->codeSparqlQuery($url_zip_file);
  818. }
  819. elseif ($from == 'upgrade') {
  820. $upgrade_file_url = $this->_getParam('file_url');
  821. $reinstall_url = $reinstall_url . '/reinstall_from/upgrade/file_url/' . $upgrade_file_url; //$upgrade_file_url is already coded
  822. }
  823. elseif ($from == 'categoriepage') {
  824. $upgrade_file_url = $this->_getParam('file_url');
  825. $reinstall_url = $reinstall_url . '/reinstall_from/upgrade/file_url/' . $upgrade_file_url; //$upgrade_file_url is already coded
  826. }
  827. $this->_redirect($reinstall_url);
  828. }
  829. else {
  830. $this->_owApp->appendMessage(
  831. new OntoWiki_Message($error_message, OntoWiki_Message::ERROR)
  832. );
  833. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  834. }
  835. }
  836. }
  837. else {
  838. $this->_owApp->appendMessage(
  839. new OntoWiki_Message("Wrong RDf-format!", OntoWiki_Message::ERROR)
  840. );
  841. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  842. }
  843. }
  844. else {
  845. $this->_owApp->appendMessage(
  846. new OntoWiki_Message('RDF-file not found!: '.$filename, OntoWiki_Message::ERROR)
  847. );
  848. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  849. }
  850. }
  851. }
  852. else {
  853. $this->_owApp->appendMessage(
  854. new OntoWiki_Message("Copyed zip-file not found!: $filename", OntoWiki_Message::ERROR)
  855. );
  856. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  857. }
  858. }
  859. else {
  860. $this->_owApp->appendMessage(
  861. new OntoWiki_Message("Can't wirite file to: $filename", OntoWiki_Message::ERROR)
  862. );
  863. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  864. }
  865. }
  866. else {
  867. $this->_owApp->appendMessage(
  868. new OntoWiki_Message("Can't open file from: $url", OntoWiki_Message::ERROR)
  869. );
  870. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  871. }
  872. }
  873. }
  874. }
  875. /**
  876. * Intall the plugins with FTP
  877. *
  878. */
  879. public function toInstallWithFtpAction()
  880. {
  881. $sftp = null;
  882. $connection = null;
  883. $this->ftpConnect($sftp, $connection);
  884. if (!$sftp) {
  885. $this->_redirect('plugins/errors/error/installnoftp');
  886. }
  887. require_once("Erfurt/Syntax/RdfParser.php");
  888. /* maybe will be used */
  889. if ($this->_request->isPost()) {
  890. // do nothing
  891. }
  892. /* really installation*/
  893. else {
  894. $from = $this->_getParam('from');
  895. if ($from =='installfromfile' || $from == 'upgrade' || $from == 'reinstall' || $from = 'categoriepage') {
  896. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Installing...'));
  897. $p_name = $this->_getParam('name');
  898. if ($from == 'categoriepage') {
  899. $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
  900. }
  901. elseif ($from == 'installfromfile') {
  902. $url = $this->_componentRoot.'/temp/installfromfile.zip';
  903. }
  904. elseif ($from == 'upgrade') {
  905. $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
  906. }
  907. elseif ($from == 'reinstall') {
  908. $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
  909. }
  910. $this->view->install_png_url = $this->_componentUrlBase . 'img/download.png';
  911. $sftp = null;
  912. $connection = null;
  913. $this->ftpConnect($sftp, $connection);
  914. $componentRoot = $this->_componentRoot;
  915. if ($sftp) {
  916. /* Copy zip-file to the plugins-directory */
  917. $getfile = ssh2_exec($connection, "wget -O $componentRoot/$p_name.zip $url");
  918. $copy = ssh2_exec($connection, "cp $url $componentRoot/$p_name.zip");
  919. /* Unzip the zip-file */
  920. if (file_exists("$componentRoot/$p_name.zip")) {
  921. $unzip = ssh2_exec($connection, "unzip $componentRoot/$p_name.zip -d $componentRoot/$p_name");
  922. $del = ssh2_exec($connection, "rm $componentRoot/$p_name.zip");
  923. /* try to read from rdf-file */
  924. if (file_exists("$componentRoot/$p_name")) {
  925. ssh2_exec($connection, "chmod 777 $componentRoot/$p_name");
  926. $rdf_file_path = "extensions/components/plugins/$p_name/package.rdf";
  927. /* Parse the rdf-file in an array */
  928. $rdf_parser = Erfurt_Syntax_RdfParser::rdfParserWithFormat('rdf');
  929. $rdf_result = $rdf_parser->parse($rdf_file_path, 20);
  930. //print_r($rdf_result);
  931. $rdf_format = true;
  932. $config_info = $this->checkAndRead($rdf_format,$rdf_result);
  933. //print_r($config_info);
  934. // Check the directories
  935. if ($rdf_format && $config_info != null) {
  936. $extension_dir = $config_info['extension_dir'];
  937. $extension_file = $config_info['extension_file'];
  938. $error_message = '';
  939. if ($this->checkDir($extension_dir, $extension_file, $error_message)){
  940. $extension_path = $this->_componentRoot;
  941. $extension_path = str_replace('\\', '/', $extension_path);
  942. $extension_path = str_replace('/components/plugins','',$extension_path);
  943. $correct_installed = true;
  944. $component_root = str_replace('\\', '/', $this->_componentRoot);
  945. for ($i=0; $i<count($extension_dir); $i++) {
  946. $a_dir = $extension_dir[$i];
  947. $from_dir = $component_root . '/' . $p_name. '/' . $a_dir;
  948. $to_dir = $extension_path . '/' . $a_dir;
  949. //echo "from_dir: ".$from_dir."<br/>"."to_dir".$to_dir."<br/>";
  950. ssh2_exec($connection, "mv $from_dir $to_dir");
  951. if (!file_exists($to_dir)) {
  952. $correct_installed = file_exists($to_dir);
  953. $this->_owApp->appendMessage(
  954. new OntoWiki_Message("Can't copy directory to $to_dir FTP", OntoWiki_Message::ERROR)
  955. );
  956. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  957. }
  958. }
  959. for ($i=0; $i<count($extension_file); $i++) {
  960. $a_file = $extension_file[$i];
  961. try {
  962. $from_dir = $component_root.'/' . $p_name. '/' . $a_file;
  963. $to_dir = $extension_path . '/' . $a_file;
  964. //echo "from_file: ".$from_dir."<br/>"."to_file: ".$to_dir."<br/>";
  965. ssh2_exec($connection, "mv $from_dir $to_dir");
  966. if (!file_exists($to_dir)) {
  967. $correct_installed = file_exists($to_dir);
  968. $this->_owApp->appendMessage(
  969. new OntoWiki_Message("Can't copy file to $to_dir FTP", OntoWiki_Message::ERROR)
  970. );
  971. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  972. }
  973. }
  974. catch (Exception $e) {
  975. $this->_owApp->appendMessage(
  976. new OntoWiki_Message("Can't copy file to $to_dir with FTP", OntoWiki_Message::ERROR)
  977. );
  978. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  979. }
  980. }
  981. /* delete the unzipped file in a directory!! */
  982. ssh2_exec($connection, "rm -rf $componentRoot/$p_name");
  983. //echo "<br/> rm: rm -rf $componentRoot/$p_name <br/>";
  984. $correct_deleted = file_exists("$componentRoot/$p_name");
  985. if ($correct_installed && !$correct_deleted) {
  986. if ($from == 'installfromfile') {
  987. // delete the template sourcefile
  988. ssh2_exec($connection, "rm $componentRoot/temp/installfromfile.zip");
  989. }
  990. $this->_owApp->appendMessage(
  991. new OntoWiki_Message("New Plugin: $p_name is installed successfully!", OntoWiki_Message::SUCCESS)
  992. );
  993. $this->view->install_info_png = $this->_componentUrlBase . 'img/true.png';
  994. }
  995. else {
  996. $this->_owApp->appendMessage(
  997. new OntoWiki_Message('Unknow error', OntoWiki_Message::ERROR)
  998. );
  999. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  1000. }
  1001. /* write into SysConfig */
  1002. $this->insertIntoSysConfig($config_info);
  1003. if (!$this->_privateConfig->client->debug) {
  1004. $this->_redirect('plugins/categories');
  1005. }
  1006. }
  1007. else {
  1008. /* Possible that the extension schould be upgraded, test if they have the same Base-URL */
  1009. echo"<br>$error_message<br/>";
  1010. if ($this->isinstalled($config_info)) {
  1011. $dirs = $config_info['extension_dir'];
  1012. $files = $config_info['extension_file'];
  1013. $plugin_baseurl = $config_info['plugin_baseurl'];
  1014. $dir_serialized = $this->seriation($dirs);
  1015. $file_serialized = $this->seriation($files);
  1016. /*Take care of '/' because of Zend_framwork */
  1017. $dir_serialized = str_replace('/','@slash@',$dir_serialized);
  1018. $file_serialized = str_replace('/','@slash@',$file_serialized);
  1019. $plugin_baseurl = str_replace('/','@slash@',$plugin_baseurl);
  1020. $reinstall_url = 'plugins/trytoreinstall/dirs/' . $dir_serialized . '/files/' . $file_serialized . '/p_name/' . $p_name . '/extension_url/' . $plugin_baseurl . '/ftp/1';
  1021. if ($from == 'installfromfile') {
  1022. $url_zip_file = $this->_componentRoot . '/temp/installfromfile.zip';
  1023. $url_zip_file = str_replace('\\', '/', $url_zip_file);
  1024. $reinstall_url = $reinstall_url . '/reinstall_from/file/file_url/' . $this->codeSparqlQuery($url_zip_file);
  1025. }
  1026. elseif ($from == 'upgrade') {
  1027. $upgrade_file_url = $this->_getParam('file_url');
  1028. $reinstall_url = $reinstall_url . '/reinstall_from/upgrade/file_url/' . $upgrade_file_url; //$upgrade_file_url is already coded
  1029. }
  1030. elseif ($from == 'categoriepage') {
  1031. $upgrade_file_url = $this->_getParam('file_url');
  1032. $reinstall_url = $reinstall_url . '/reinstall_from/upgrade/file_url/' . $upgrade_file_url; //$upgrade_file_url is already coded
  1033. }
  1034. $this->_redirect($reinstall_url);
  1035. }
  1036. else {
  1037. $this->_owApp->appendMessage(
  1038. new OntoWiki_Message($error_message, OntoWiki_Message::ERROR)
  1039. );
  1040. $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
  1041. }
  1042. }
  1043. }
  1044. else {
  1045. $this->_owApp->appendMessage(
  1046. new OntoWiki_Message("RDF-file not readable with FTP", OntoWiki_Message::ERROR)
  1047. );
  1048. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  1049. }
  1050. }
  1051. else {
  1052. $this->_owApp->appendMessage(
  1053. new OntoWiki_Message("Failed to unzip file", OntoWiki_Message::ERROR)
  1054. );
  1055. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  1056. }
  1057. }
  1058. else {
  1059. $this->_owApp->appendMessage(
  1060. new OntoWiki_Message("File not found with FTP", OntoWiki_Message::ERROR)
  1061. );
  1062. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  1063. }
  1064. }
  1065. else {
  1066. $this->_owApp->appendMessage(
  1067. new OntoWiki_Message("Can't copy directory to $to_dir with FTP", OntoWiki_Message::ERROR)
  1068. );
  1069. $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
  1070. }
  1071. }
  1072. }
  1073. }
  1074. /**
  1075. * Function to uninstall a plugin
  1076. *
  1077. */
  1078. public function touninstallAction()
  1079. {
  1080. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Uninstalling...'));
  1081. $this->view->del_png_url = $this->_componentUrlBase . 'img/remove.png';
  1082. $error = false;
  1083. $reinstall = false;
  1084. /* The user wants to uninstall it, not because of reinstall */
  1085. if ($this->_request->isPost()) {
  1086. $p_name = $this->_request->getPost('uninstall_name');
  1087. //echo "<h1>Try to unstall extension: $p_name </h1><br/>";
  1088. $dirs =$_POST['uninstall_dir'];
  1089. $files = $_POST['uninstall_file'];
  1090. $extension_url = $_POST['extension_url'];
  1091. }
  1092. else {
  1093. if ($this->_getParam('from') == 'reinstall') {
  1094. $p_name = $this->_getParam('p_name');
  1095. $dirs = $this->_getParam('dirs');
  1096. $files = $this->_getParam('files');
  1097. $extension_url = $this->_getParam('plugin_baseurl');
  1098. $reinstall_from = $this->_getParam('reinstall_from');
  1099. $dirs = str_replace('@slash@', '/', $dirs);
  1100. $files = str_replace('@slash@', '/', $files);
  1101. $extension_url = str_replace('@slash@', '/', $extension_url);
  1102. //echo "<br/> p_name: $p_name <br/> dirs: $dirs <br/> files: $files <br/> baseurl: $extension_url <br/>";
  1103. $reinstall = true;
  1104. }
  1105. }
  1106. $extension_dir = array();
  1107. $extension_file = array();
  1108. $extension_dir = explode("@trennung@",$dirs);
  1109. $extension_file = explode("@trennung@",$files);
  1110. //print_r($extension_dir);
  1111. //print_r($extension_file);
  1112. $del_with_ftp = false;
  1113. if ($extension_dir[0]!='') {
  1114. foreach ($extension_dir as $p_dir) {
  1115. $p_dir = str_replace ('/components/plugins', '', ($this->_componentRoot)) . $p_dir;
  1116. //echo"<br/>p_dir: $p_dir<br/>";
  1117. if (file_exists($p_dir) && !$error) {
  1118. if (!$this->delDirAndFile($p_dir)) {
  1119. $del_with_ftp = true;
  1120. $sftp = null;
  1121. $connection = null;
  1122. $this->ftpConnect($sftp, $connection);
  1123. $this->_owApp->appendMessage(
  1124. new OntoWiki_Message("Dirctory :$p_dir could not be deleted! Try to use FTP! ", OntoWiki_Message::ERROR)
  1125. );
  1126. if (!$sftp) {
  1127. $error = true;
  1128. $this->_owApp->appendMessage(
  1129. new OntoWiki_Message("Dirctory :$p_dir could not be deleted! Either with PHP or with FTP (No Connection)! ", OntoWiki_Message::ERROR)
  1130. );
  1131. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1132. break;
  1133. }
  1134. else {
  1135. ssh2_exec($connection, "rm -rf $p_dir");
  1136. if (file_exists($p_dir)) {
  1137. $error = true;
  1138. $this->_owApp->appendMessage(
  1139. new OntoWiki_Message("Dirctory :$p_dir could not be deleted! Either with PHP or with FTP!", OntoWiki_Message::ERROR)
  1140. );
  1141. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1142. break;
  1143. }
  1144. else {
  1145. if ($this->_privateConfig->client->debug) {
  1146. echo "<h2> Directory: $p_dir is deleted with FTP!";
  1147. }
  1148. }
  1149. }
  1150. }
  1151. else {
  1152. if ($this->_privateConfig->client->debug) {
  1153. echo "<h2> Directory: $p_dir is deleted!";
  1154. }
  1155. }
  1156. }
  1157. else {
  1158. $error = true;
  1159. $this->_owApp->appendMessage(
  1160. new OntoWiki_Message("Dirctory :$p_dir not found!", OntoWiki_Message::ERROR)
  1161. );
  1162. $this->view->del_info_png = $this->_componentUrlBase . 'img/false.png';
  1163. break;
  1164. }
  1165. }
  1166. }
  1167. if ($extension_file[0]!= '' && !$error) {
  1168. foreach ($extension_file as $p_file) {
  1169. $p_file = str_replace ('/components/plugins', '', ($this->_componentRoot)).$p_file;
  1170. if (file_exists($p_file)) {
  1171. if (unlink($p_file)) {
  1172. if ($this->_privateConfig->client->debug) {
  1173. echo "<h2>File: $p_file is deleted!</h2>";
  1174. }
  1175. }
  1176. else {
  1177. $del_with_ftp = true;
  1178. $sftp = null;
  1179. $connection = null;
  1180. $this->ftpConnect($sftp, $connection);
  1181. $this->_owApp->appendMessage(
  1182. new OntoWiki_Message("File :$p_file could not be deleted! Try to use FTP! ", OntoWiki_Message::ERROR)
  1183. );
  1184. if (!$sftp) {
  1185. $error = true;
  1186. $this->_owApp->appendMessage(
  1187. new OntoWiki_Message("File :$p_file could not be deleted! Either with PHP or with FTP (No Connection)! ", OntoWiki_Message::ERROR)
  1188. );
  1189. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1190. break;
  1191. }
  1192. else {
  1193. ssh2_exec($connection, "rm $p_file");
  1194. if (!file_exists($p_file)) {
  1195. if ($this->_privateConfig->client->debug) {
  1196. echo "<h2>File: $p_file is deleted with FTP!</h2>";
  1197. }
  1198. }
  1199. else {
  1200. $error = true;
  1201. $this->_owApp->appendMessage(
  1202. new OntoWiki_Message("File : $p_file could not be deleted! Either with PHP or with FTP ", OntoWiki_Message::ERROR)
  1203. );
  1204. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. }
  1210. else {
  1211. $this->_owApp->appendMessage(
  1212. new OntoWiki_Message("File : $p_file is not found!", OntoWiki_Message::ERROR)
  1213. );
  1214. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1215. break;
  1216. }
  1217. }
  1218. }
  1219. if (!$error) {
  1220. $this->delFromSysConfig($extension_url);
  1221. if (!$del_with_ftp) {
  1222. $this->_owApp->appendMessage(
  1223. new OntoWiki_Message("Extension : $p_name is uninstalled successfully! ", OntoWiki_Message::SUCCESS)
  1224. );
  1225. }
  1226. else {
  1227. $this->_owApp->appendMessage(
  1228. new OntoWiki_Message("Extension : $p_name is uninstalled with FTP successfully! ", OntoWiki_Message::SUCCESS)
  1229. );
  1230. }
  1231. $this->view->del_info_png = $this->_componentUrlBase . 'img/true.png';
  1232. /* if the extension should be upgraded or reinstalled */
  1233. if ($reinstall) {
  1234. $url_toinstall = '';
  1235. if (!$del_with_ftp) {
  1236. $url_toinstall = $this->getFrontController()->getBaseUrl() . '/plugins/toinstall/from/reinstall/name/' . $p_name;
  1237. }
  1238. else {
  1239. $url_toinstall = $this->getFrontController()->getBaseUrl() . '/plugins/to-install-with-ftp/from/reinstall/name/' . $p_name;
  1240. }
  1241. $upgrade_file_url = $this->getParam('file_url');
  1242. $url_toinstall = $url_toinstall . '/file_url/' . $upgrade_file_url;
  1243. //$this->_redirect('http://localhost/ontowiki/index.php');
  1244. //echo"<br/> to_install_url: $url_toinstall <br/>";
  1245. //echo "<h2>Now you can reinstall:</h2> <a href=\'".$url_toinstall."\'>Reinstall!</a>";
  1246. $this->view->to_install_url = $url_toinstall;
  1247. }
  1248. else {
  1249. if (!$this->_privateConfig->client->debug) {
  1250. $this->_redirect("plugins/installed");
  1251. }
  1252. }
  1253. }
  1254. }
  1255. /**
  1256. * To uninstall a plugin with FTP
  1257. *
  1258. */
  1259. public function toUninstallFtpAction()
  1260. {
  1261. $sftp = null;
  1262. $connection = null;
  1263. $this->ftpConnect($sftp, $connection);
  1264. if (!$sftp) {
  1265. $this->_redirect('plugins/errors/error/installnoftp');
  1266. }
  1267. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Uninstalling...'));
  1268. $this->view->del_png_url = $this->_componentUrlBase . 'img/remove.png';
  1269. $error = false;
  1270. $reinstall = false;
  1271. /* The user wants to uninstall it, not because of reinstall */
  1272. if ($this->_request->isPost()) {
  1273. $p_name = $this->_request->getPost('uninstall_name');
  1274. //echo "<h1>Try to unstall extension: $p_name </h1><br/>";
  1275. $dirs = $this->_request->getPost('uninstall_dir');
  1276. $files = $this->_request->getPost('uninstall_file');
  1277. $extension_url = $this->_request->getPost('extension_url');
  1278. }
  1279. else {
  1280. if ($this->_getParam('from') == 'reinstall') {
  1281. $p_name = $this->_getParam('p_name');
  1282. $dirs = $this->_getParam('dirs');
  1283. $files = $this->_getParam('files');
  1284. $extension_url = $this->_getParam('plugin_baseurl');
  1285. $reinstall_from = $this->_getParam('reinstall_from');
  1286. $dirs = str_replace('@slash@', '/', $dirs);
  1287. $files = str_replace('@slash@', '/', $files);
  1288. $extension_url = str_replace('@slash@', '/', $extension_url);
  1289. //echo "<br/> p_name: $p_name <br/> dirs: $dirs <br/> files: $files <br/> baseurl: $extension_url <br/>";
  1290. $reinstall = true;
  1291. }
  1292. }
  1293. $extension_dir = array();
  1294. $extension_file = array();
  1295. $extension_dir = explode("@trennung@",$dirs);
  1296. $extension_file = explode("@trennung@",$files);
  1297. //print_r($extension_dir);
  1298. //print_r($extension_file);
  1299. if ($extension_dir[0] != '') {
  1300. foreach ($extension_dir as $p_dir) {
  1301. $p_dir = str_replace ('/components/plugins', '', ($this->_componentRoot)) . $p_dir;
  1302. //echo"<br/>p_dir: $p_dir<br/>";
  1303. if (file_exists($p_dir) && !$error) {
  1304. ssh2_exec($connection, "rm -rf $p_dir");
  1305. if (file_exists($p_dir)) {
  1306. $error = true;
  1307. $this->_owApp->appendMessage(
  1308. new OntoWiki_Message("Dirctory :$p_dir could not be deleted! ", OntoWiki_Message::ERROR)
  1309. );
  1310. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1311. break;
  1312. }
  1313. else {
  1314. if ($this->_privateConfig->client->debug) {
  1315. echo "<h2> Directory: $p_dir is deleted!";
  1316. }
  1317. }
  1318. }
  1319. else {
  1320. $error = true;
  1321. $this->_owApp->appendMessage(
  1322. new OntoWiki_Message("Dirctory :$p_dir not found!", OntoWiki_Message::ERROR)
  1323. );
  1324. $this->view->del_info_png = $this->_componentUrlBase . 'img/false.png';
  1325. break;
  1326. }
  1327. }
  1328. }
  1329. if ($extension_file[0]!= '' && !$error) {
  1330. foreach ($extension_file as $p_file) {
  1331. $p_file = str_replace ('/components/plugins', '', ($this->_componentRoot)).$p_file;
  1332. //echo"<br/>p_file: $p_file<br/>";
  1333. ssh2_exec($connection, "rm $p_file");
  1334. if (!file_exists($p_file)) {
  1335. if ($this->_privateConfig->client->debug) {
  1336. echo "<h2>File: $p_file is deleted!</h2>";
  1337. }
  1338. }
  1339. else {
  1340. $error = true;
  1341. $this->_owApp->appendMessage(
  1342. new OntoWiki_Message("File : $p_file could not be deleted! ", OntoWiki_Message::ERROR)
  1343. );
  1344. $this->view->del_info_png = $this->_componentUrlBase.'img/false.png';
  1345. break;
  1346. }
  1347. }
  1348. }
  1349. if (!$error) {
  1350. $this->delFromSysConfig($extension_url);
  1351. $this->_owApp->appendMessage(
  1352. new OntoWiki_Message("Extension : $p_name is uninstalled successfully! ", OntoWiki_Message::SUCCESS)
  1353. );
  1354. $this->view->del_info_png = $this->_componentUrlBase . 'img/true.png';
  1355. /* if the extension should be upgraded or reinstalled */
  1356. if ($reinstall) {
  1357. $url_toinstall = '';
  1358. $url_toinstall = $this->getFrontController()->getBaseUrl() . '/plugins/to-install-with-ftp/from/reinstall/name/' . $p_name;
  1359. $upgrade_file_url = $this->getParam('file_url');
  1360. $url_toinstall = $url_toinstall . '/file_url/' . $upgrade_file_url;
  1361. $this->view->to_install_url = $url_toinstall;
  1362. }
  1363. }
  1364. }
  1365. /**
  1366. * Choice if man wants to install the extesion again (reinstall)
  1367. *
  1368. */
  1369. function trytoreinstallAction()
  1370. {
  1371. $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Do you want to reinsatll?'));
  1372. $this->_owApp->appendMessage(
  1373. new OntoWiki_Message('This extension is alreadly installed, you must uninstall it, if you want to reinstall it.', OntoWiki_Message::WARNING )
  1374. );
  1375. $p_name = $this->_getParam('p_name');
  1376. $dirs = $this->_getParam('dirs');
  1377. $files = $this->_getParam('files');
  1378. $extension_url = $this->_getParam('extension_url');
  1379. $reinstall_from = $this->_getParam('reinstall_from');
  1380. $file_url = $this->_getParam('file_url');
  1381. $withFtp = $this->_getParam('ftp', 0);
  1382. //echo "<br/> dirs: $dirs <br/> files: $files <br/>";
  1383. //echo "<br/> reinstall_from: $reinstall_from <br/> file_url: $file_url <br/>";
  1384. if ($withFtp > 0) {
  1385. $reinstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/to-uninstall-ftp/from/reinstall/p_name/' . $p_name.'/dirs/' . $dirs . '/files/' . $files . '/plugin_baseurl/' . $extension_url;
  1386. }
  1387. else {
  1388. $reinstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/touninstall/from/reinstall/p_name/' . $p_name.'/dirs/' . $dirs . '/files/' . $files . '/plugin_baseurl/' . $extension_url;
  1389. }
  1390. $reinstall_url = $reinstall_url . '/reinstall_from/' . $reinstall_from . '/file_url/' . $file_url;
  1391. $this->view->reinstall = $reinstall_url;
  1392. $this->view->notreinstall = $this->getFrontController()->getBaseUrl() . '/plugins/installed';
  1393. }
  1394. /**
  1395. * Function to delete the directory
  1396. *
  1397. * @param string $dirName
  1398. * @return bool
  1399. */
  1400. function delDirAndFile($dirName)
  1401. {
  1402. $succ = true;
  1403. if ($handle = opendir("$dirName")) {
  1404. while (false !== ($item = readdir($handle))) {
  1405. if ($item != "." && $item != ".." ) {
  1406. if ( is_dir( "$dirName/$item" )) {
  1407. $this->delDirAndFile("$dirName/$item");
  1408. }
  1409. else {
  1410. if (!unlink("$dirName/$item")) {
  1411. $succ = false;
  1412. echo '<h3 style="color:#FF0000">Error: Can\'t delete file: '.$dirName/$item.'</h3>';
  1413. }
  1414. }
  1415. }
  1416. }
  1417. closedir($handle);
  1418. if (!rmdir($dirName)) {
  1419. $succ = false;
  1420. '<h3 style="color:#FF0000">Error: Can\'t delete directory: '.$dirName.'</h3>';
  1421. }
  1422. }
  1423. return $succ;
  1424. }
  1425. /**
  1426. * Get the information from a
  1427. * categroie.phtml
  1428. *
  1429. */
  1430. function getinfoAction()
  1431. {
  1432. $this->getFrontController()->setParam('noViewRenderer', true);
  1433. if ($this->_request->isPost()) {
  1434. $url = $this->_request->getPost('install_url');
  1435. $p_name = $this->_request->getPost('t_p_name');
  1436. $ftp_config = $this->_request->getPost('ftp_config');
  1437. if (!$ftp_config) {
  1438. $change_url = "plugins/toinstall/from/categoriepage/name/$p_name";
  1439. }
  1440. else {
  1441. $change_url = "plugins/install-choice/from/categoriepage/name/$p_name";
  1442. }
  1443. $change_url = $change_url . '/file_url/' . $this->codeSparqlQuery($url);
  1444. $this->_redirect($change_url);
  1445. }
  1446. }
  1447. /**
  1448. * Insert the parsed information about
  1449. * installed plugins into SystemConfigation
  1450. *
  1451. * @param array $config_info
  1452. */
  1453. function insertIntoSysConfig($config_info)
  1454. {
  1455. //print_r($config_info);
  1456. $a_plugin = $config_info['plugin_baseurl'];
  1457. $des = $config_info['description'];
  1458. /*prepare for the query, because of the spaces, point and so on */
  1459. $des = $this->codeSparqlQuery($des);
  1460. $this->_owApp->configModel->addStatement($a_plugin, self::P_TYPE_BASE,$config_info['type'], array());
  1461. $this->_owApp->configModel->addStatement($a_plugin, self::P_LABEL_BASE,$config_info['label'], array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1462. $this->_owApp->configModel->addStatement($a_plugin, self::P_DESC_BASE,$des, array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1463. $this->_owApp->configModel->addStatement($a_plugin, self::P_RELEASE_BASE,$config_info['release'], array());
  1464. $this->_owApp->configModel->addStatement($config_info['release'], self::FILERELEASE_BASE,$config_info['file_release'], array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1465. $this->_owApp->configModel->addStatement($config_info['release'], self::REVISION_BASE,$config_info['revision'], array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1466. $this->_owApp->configModel->addStatement($config_info['release'], self::CREATED_BASE,$config_info['created'], array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1467. $extension_dirs = $config_info['extension_dir'];
  1468. if (sizeof($extension_dirs) != 0) {
  1469. foreach ($extension_dirs as $a_extension_dir) {
  1470. $this->_owApp->configModel->addStatement($config_info['release'], self::EXTENSION_DIR_BASE, $a_extension_dir, array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1471. }
  1472. }
  1473. $extension_files = $config_info['extension_file'];
  1474. if (sizeof($extension_files) != 0) {
  1475. foreach ($extension_files as $a_extension_file) {
  1476. $this->_owApp->configModel->addStatement($config_info['release'], self::EXTENSION_FILE_BASE, $a_extension_file, array('object_type' => Erfurt_Store::TYPE_LITERAL));
  1477. }
  1478. }
  1479. }
  1480. /**
  1481. * Delete all the information about
  1482. * installed plugins from SystemConfigation
  1483. *
  1484. * @param string $extension_url
  1485. */
  1486. function delFromSysConfig($extension_url)
  1487. {
  1488. $query = ' PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  1489. PREFIX node: <' . $extension_url . '>
  1490. SELECT ?p_release
  1491. WHERE { node: release: ?p_release.}';
  1492. $release = array();
  1493. $release = $this->_owApp->configModel->sparqlQuery($query);
  1494. $release_url = $release[0]['p_release'];
  1495. $this->_owApp->configModel->deleteMatchingStatements($release_url, null, null, array());
  1496. $this->_owApp->configModel->deleteMatchingStatements($extension_url, null, null, array());
  1497. }
  1498. /**
  1499. * Read all the information about
  1500. * installed plugins from SystemConfigation
  1501. *
  1502. * @param string $categorie
  1503. * @return array
  1504. */
  1505. function readFromSysConfig($categorie)
  1506. {
  1507. $query = ' PREFIX type: <'.$this->_privateConfig->p_type_base.'>
  1508. PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
  1509. PREFIX label: <'.$this->_privateConfig->p_label_base.'>
  1510. PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
  1511. PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  1512. PREFIX revision: <'.$this->_privateConfig->p_revision_base.'>
  1513. PREFIX file_release: <'.$this->_privateConfig->filerelease_base.'>
  1514. PREFIX created: <'.$this->_privateConfig->p_created_base.'>
  1515. SELECT ?node ?p_name ?p_desc ?p_release ?p_revision ?p_f_release ?p_created
  1516. WHERE {?node type: plugin:.
  1517. ?node label: ?p_name.
  1518. ?node description: ?p_desc.
  1519. ?node release: ?p_release.
  1520. ?p_release revision: ?p_revision.
  1521. ?p_release file_release: ?p_f_release.
  1522. ?p_release created: ?p_created.
  1523. }';
  1524. $results_without_dirs = array();
  1525. $results_without_dirs = $this->_owApp->configModel->sparqlQuery($query);
  1526. /* Read the extensionDir and extensionFiles from SystemConfig */
  1527. $results = array();
  1528. if (count($results_without_dirs)!=0) {
  1529. foreach ($results_without_dirs as $a_plugin) {
  1530. $a_plugin['p_desc'] = $this->decodeSparqlQuery($a_plugin['p_desc']);
  1531. $node = $a_plugin['p_release'];
  1532. $query_dir = ' PREFIX node: <' . $node . '>
  1533. PREFIX extension_dir: <'.$this->_privateConfig->extension_dir.'>
  1534. SELECT ?extension_dir
  1535. WHERE {node: extension_dir: ?extension_dir.}';
  1536. $a_plugin['extension_dir'] = array();
  1537. $extension_dirs = $this->_owApp->configModel->sparqlQuery($query_dir);
  1538. //echo ("<br/>extension_dirs:<br/>");
  1539. //print_r($extension_dirs);
  1540. //echo ("<br/>END<br/>");
  1541. if (count($extension_dirs)!=0) {
  1542. foreach ($extension_dirs as $a_dir) {
  1543. $a_plugin['extension_dir'][] = $a_dir['extension_dir'];
  1544. }
  1545. }
  1546. $query_files = 'PREFIX node: <' . $node . '>
  1547. PREFIX extension_file: <'.$this->_privateConfig->extension_file.'>
  1548. SELECT ?extension_file
  1549. WHERE {node: extension_file: ?extension_file.}';
  1550. $a_plugin['extension_file'] = array();
  1551. $extension_files = $this->_owApp->configModel->sparqlQuery($query_files);
  1552. //echo ("<br/>extension_files:<br/>");
  1553. //print_r($extension_files);
  1554. //echo ("<br/>END<br/>");
  1555. if (count($extension_files)!=0) {
  1556. foreach ($extension_files as $a_file) {
  1557. $a_plugin['extension_file'][] = $a_file['extension_file'];
  1558. }
  1559. }
  1560. $results[] = $a_plugin;
  1561. }
  1562. }
  1563. //print_r($results);
  1564. if (count($results)!=0) {
  1565. return $results;
  1566. }
  1567. else {
  1568. return null;
  1569. }
  1570. }
  1571. /**
  1572. * Prepare for Sparql-Query because
  1573. * of the spaces, points and so on
  1574. * in the context
  1575. *
  1576. * @param string $text
  1577. * @return string
  1578. */
  1579. function codeSparqlQuery($text)
  1580. {
  1581. $text = trim($text);
  1582. $text = htmlspecialchars($text,ENT_QUOTES,"ISO-8859-15");
  1583. $text = str_replace(" ", "&nbsp;", $text);
  1584. $text = str_replace(".", "&pnt;", $text);
  1585. $text = str_replace("-", "&slsh;", $text);
  1586. $text = str_replace("/", "&slash;", $text);
  1587. return $text;
  1588. }
  1589. /**
  1590. * Decode the for Sparql coded String back
  1591. *
  1592. * @param string $text
  1593. * @return string
  1594. */
  1595. function decodeSparqlQuery($text)
  1596. {
  1597. $text = trim($text);
  1598. $text = htmlspecialchars_decode($text,ENT_QUOTES);
  1599. $text = str_replace("&nbsp;", " ", $text);
  1600. $text = str_replace("&pnt;", ".", $text);
  1601. $text = str_replace("&slsh;", "-", $text);
  1602. $text = str_replace("&slash;", "/", $text);
  1603. return $text;
  1604. }
  1605. /**
  1606. * Check and read
  1607. * Check the format of the RDF-file, if correct,
  1608. * read the information from the RDF-file
  1609. *
  1610. * @param bool $rdf_format
  1611. * @param array $rdf_result
  1612. * @return array
  1613. */
  1614. function checkAndRead(&$rdf_format, $rdf_result)
  1615. {
  1616. try {
  1617. $plugin_baseurl = key($rdf_result);
  1618. //echo "<br/>plugin_baseurl:".$plugin_baseurl."<br/>";
  1619. $a_plugin = $rdf_result[$plugin_baseurl];
  1620. //print_r($a_plugin);
  1621. $type = $a_plugin[self::P_TYPE_BASE][0]['value'];
  1622. $label = $a_plugin[self::P_LABEL_BASE][0]['value'];
  1623. $description = $a_plugin[self::P_DESC_BASE][0]['value'];
  1624. $release = $a_plugin[self::P_RELEASE_BASE][0]['value'];
  1625. $a_release = $rdf_result[$release];
  1626. $file_release = $a_release[self::FILERELEASE_BASE][0]['value'];
  1627. $revision = $a_release[self::REVISION_BASE][0]['value'];
  1628. $created = $a_release[self::CREATED_BASE][0]['value'];
  1629. $extension_dir = array();
  1630. if (array_key_exists(self::EXTENSION_DIR_BASE,$a_release)) {
  1631. foreach ($a_release[self::EXTENSION_DIR_BASE] as $a_extension_dir) {
  1632. $extension_dir[] = $a_extension_dir['value'];
  1633. }
  1634. }
  1635. $extension_file = array();
  1636. if (array_key_exists(self::EXTENSION_FILE_BASE,$a_release)) {
  1637. foreach ($a_release[self::EXTENSION_FILE_BASE] as $a_extension_file) {
  1638. $extension_file[] = $a_extension_file['value'];
  1639. }
  1640. }
  1641. if (isset($type) && isset($label) && isset($description) && isset($release) && isset($file_release) && isset($revision) && isset($created)){
  1642. $config_info = array(
  1643. "plugin_baseurl" => $plugin_baseurl,
  1644. "type" => $type,
  1645. "label" => $label,
  1646. "description" => $description,
  1647. "release" => $release,
  1648. "file_release" => $file_release,
  1649. "revision" => $revision,
  1650. "created" => $created,
  1651. "extension_dir" => $extension_dir,
  1652. "extension_file" => $extension_file
  1653. );
  1654. return $config_info;
  1655. }
  1656. else {
  1657. $rdf_format = false;
  1658. return null;
  1659. }
  1660. }
  1661. catch (Exception $e) {
  1662. $rdf_format = false;
  1663. return null;
  1664. }
  1665. }
  1666. /**
  1667. * checkDir
  1668. * Check the directories, if all the needed directories
  1669. * are there
  1670. *
  1671. * @param string $extension_dir
  1672. * @param string $extension_file
  1673. * @param string $message
  1674. * @return bool
  1675. */
  1676. public function checkDir($extension_dir, $extension_file, &$message)
  1677. {
  1678. if (count($extension_dir) != 0) {
  1679. foreach ($extension_dir as $a_dir){
  1680. $to_check = explode('/', $a_dir);
  1681. $path = $this->_componentRoot;
  1682. $path = str_replace('\\', '/', $path);
  1683. $path = str_replace('/components/plugins', '', $path);
  1684. for ($i=0; $i!=count($to_check)-1; $i++) {
  1685. $path = $path . '/' . $to_check[$i];
  1686. if (!file_exists($path)) {
  1687. $message = "Directory: $path is not found!";
  1688. return false;
  1689. }
  1690. }
  1691. $path = $path . '/' . $to_check[count($to_check)-1];
  1692. if (file_exists($path)) {
  1693. $message = "Directory: $path already exists!";
  1694. return false;
  1695. }
  1696. }
  1697. }
  1698. if (count($extension_file) != 0) {
  1699. foreach ($extension_file as $a_file) {
  1700. $to_check = explode("/",$a_file);
  1701. $path = $this->_componentRoot;
  1702. $path = str_replace("\\","/", $path);
  1703. $path = str_replace("/components/plugins","",$path);
  1704. for ($i=0; $i!=count($to_check)-1; $i++) {
  1705. $path = $path."/".$to_check[$i];
  1706. if (!file_exists($path)) {
  1707. $message = "Directory: $path is not found!";
  1708. return false;
  1709. }
  1710. }
  1711. $path = $path."/".$to_check[count($to_check)-1];
  1712. if (file_exists($path)) {
  1713. $message = "File: $path already exists!";
  1714. return false;
  1715. }
  1716. }
  1717. }
  1718. //echo "<br/>Dirs are ok! <br/>";
  1719. return true;
  1720. }
  1721. /**
  1722. * The function to test, if the extension is installed,
  1723. * but with another version.
  1724. *
  1725. * @param array $config_info
  1726. * @return bool
  1727. */
  1728. public function isinstalled($config_info)
  1729. {
  1730. $plugin_baseurl = $config_info['plugin_baseurl'];
  1731. $query = ' PREFIX node: <' . $plugin_baseurl . '>
  1732. SELECT ?x ?y
  1733. WHERE {node: ?x ?y.}';
  1734. $a_extension = $this->_owApp->configModel->sparqlQuery($query);
  1735. if (count($a_extension)<2) {
  1736. return false;
  1737. }
  1738. else {
  1739. return true;
  1740. }
  1741. }
  1742. /**
  1743. * Seriation an Array into a String
  1744. *
  1745. * @param array $extension_dir
  1746. * @return string
  1747. */
  1748. public function seriation($extension_dir)
  1749. {
  1750. $extension_dir_serialized = '';
  1751. for ($i = 0; $i<count($extension_dir); $i++){
  1752. if ($i == count($extension_dir)-1){
  1753. $extension_dir_serialized = $extension_dir_serialized.$extension_dir[$i];
  1754. }
  1755. else {
  1756. $extension_dir_serialized = $extension_dir_serialized.$extension_dir[$i]."@trennung@";
  1757. }
  1758. }
  1759. return $extension_dir_serialized;
  1760. }
  1761. /**
  1762. * Search for upgrades
  1763. *
  1764. * @param array $results_without_upgrade
  1765. * @return array
  1766. */
  1767. public function searchupgrade($results_without_upgrade)
  1768. {
  1769. $results = array();
  1770. foreach ($results_without_upgrade as $a_result) {
  1771. $plugin_url = $a_result['node'];
  1772. $p_created = $a_result['p_created'];
  1773. $query = ' PREFIX modified: <'.$this->_privateConfig->p_modified_base.'>
  1774. PREFIX release: <'.$this->_privateConfig->p_release_base.'>
  1775. PREFIX file_release: <'.$this->_privateConfig->filerelease_base.'>
  1776. PREFIX node: <' . $plugin_url . '>
  1777. SELECT ?new_created ?p_f_release
  1778. WHERE { node: modified: ?new_created.
  1779. node: release: ?p_release.
  1780. ?p_release file_release: ?p_f_release.}';
  1781. $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
  1782. $client->setParameterPost('query', $query);
  1783. $client->setHeaders('Accept', 'application/sparql-results+json');
  1784. $response = $client->request('POST');
  1785. $sparl_results = Zend_Json::decode($response->getBody());
  1786. //echo "<br/> An_upgrade: "; print_r($sparl_results); echo "<br/>";
  1787. if (strstr($response->getBody(),"new_created") && strstr($response->getBody(), "p_f_release")) {
  1788. $new_created = $sparl_results['results']['bindings'][0]['new_created']['value'];
  1789. $file_url = $sparl_results['results']['bindings'][0]['p_f_release']['value'];
  1790. }
  1791. if (!isset($new_created) || $new_created === null) {
  1792. $a_result['upgrade'] = '';
  1793. }
  1794. else {
  1795. $new_created = substr(trim($new_created),0,10);
  1796. $new_created = strtotime($new_created);
  1797. $p_created = strtotime($p_created);
  1798. if ($new_created > $p_created) {
  1799. $a_result['upgrade'] = $file_url;
  1800. }
  1801. else {
  1802. $a_result['upgrade'] = '';
  1803. }
  1804. }
  1805. $results[] = $a_result;
  1806. }
  1807. return $results;
  1808. }
  1809. /**
  1810. * Generate an array for the tags
  1811. *
  1812. * @param array $tags
  1813. * @param array $categorie_url
  1814. * @return array
  1815. */
  1816. public function createtags($tags,$categorie_url)
  1817. {
  1818. $tags_with_url = array();
  1819. if (count($tags)>0 && $tags!=null) {
  1820. foreach ($tags as $a_tag) {
  1821. $tags_with_url[] = array(
  1822. 'tag' => $a_tag['tag'],
  1823. 'url' => $categorie_url.'tag/' . $a_tag['tag'],
  1824. 'weight' => $a_tag['weight']
  1825. );
  1826. }
  1827. return $tags_with_url;
  1828. }
  1829. else {
  1830. return array();
  1831. }
  1832. }
  1833. /**
  1834. * Get the tags from repository
  1835. *
  1836. * @param array $tag
  1837. * @return array
  1838. */
  1839. public function getTags($tag)
  1840. {
  1841. $num_tags = $this->_privateConfig->client->tags_num;
  1842. $tags_client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->tags_url);
  1843. $tags_client->setHeaders('Accept', 'application/json');
  1844. $tags_client->setParameterPost('count', $num_tags);
  1845. if ($tag!=null) {
  1846. $tags_client->setParameterPost('tags', Zend_Json::encode(array($tag)));
  1847. }
  1848. $tags_response = $tags_client->request('POST');
  1849. $tags_results = Zend_Json::decode($tags_response->getBody());
  1850. //print_r($tags_response);
  1851. //echo "<br/>TAGS_RESPONSE: ".print_r($tags_response->getBody())."<br/>";
  1852. $tags_results = $this->createtags($tags_results, $this->getFrontController()->getBaseUrl() . '/plugins/categories/');
  1853. return $tags_results;
  1854. }
  1855. /**
  1856. * Get the connection to ftp-server
  1857. *
  1858. * @param unknown_type $sftp
  1859. * @param unknown_type $connection
  1860. */
  1861. public function ftpConnect(&$sftp, &$connection){
  1862. $username = $this->_privateConfig->ftp->username;
  1863. $password = $this->_privateConfig->ftp->password;
  1864. $hostname = $this->_privateConfig->ftp->hostname;
  1865. $ssh2 = "ssh2.sftp://$username:$password@$hostname:22";
  1866. $connection = ssh2_connect("$hostname", 22);
  1867. ssh2_auth_password($connection, $username, $password);
  1868. $sftp = ssh2_sftp($connection);
  1869. }
  1870. /**
  1871. * Choose the way of installation, weather
  1872. * with FTP or PHP
  1873. *
  1874. */
  1875. public function installChoiceAction()
  1876. {
  1877. $from = $this->getParam('from');
  1878. $name = $this->getParam('name');
  1879. if ($from == 'file_url') {
  1880. $file_url = '';
  1881. }
  1882. else {
  1883. $file_url = $this->getParam('file_url');
  1884. }
  1885. $this->view->with_ftp = $this->getFrontController()->getBaseUrl() . "/plugins/to-install-with-ftp/from/$from/name/$name/file_url/$file_url";
  1886. $this->view->no_ftp = $this->getFrontController()->getBaseUrl() . "/plugins/toinstall/from/$from/name/$name/file_url/$file_url";
  1887. }
  1888. public function successAction()
  1889. {
  1890. $from = $this->getParam('from');
  1891. if ($from == 'uninstall') {
  1892. $p_name = $this->getParam('p_name');
  1893. $this->_owApp->appendMessage(
  1894. new OntoWiki_Message("Extension : $p_name is uninstalled successfully! ", OntoWiki_Message::SUCCESS)
  1895. );
  1896. }
  1897. }
  1898. /**
  1899. * Search for plugins according to the information,
  1900. * the user entered in searchbox.
  1901. *
  1902. * @param string_type $search_keyword
  1903. * @param object $client
  1904. * @param bool $wrong_response
  1905. * @param string $sort_kind
  1906. * @param string $sort_priority
  1907. * @return array
  1908. */
  1909. public function searchForPlugins($search_keyword, $client, &$wrong_response, $sort_kind, $sort_priority)
  1910. {
  1911. $query = "PREFIX type: <".$this->_privateConfig->p_type_base.">
  1912. PREFIX plugin: <".$this->_privateConfig->plugin_base.">
  1913. SELECT DISTINCT ?packageUri
  1914. WHERE {
  1915. ?packageUri type: plugin:.
  1916. ?packageUri ?prop ?FilteredLiteral.
  1917. FILTER regex(?FilteredLiteral, \"$search_keyword\", \"i\")
  1918. }";
  1919. $client->setParameterPost('query',$query);
  1920. $client->setHeaders('Accept', 'application/sparql-results+json');
  1921. $response = $client->request('POST');
  1922. $sparl_results = Zend_Json::decode($response->getBody());
  1923. //print_r($sparl_results);
  1924. // if there is no error in reponse
  1925. if (strstr($response->getBody(),'bindings')) {
  1926. $url_results = array();
  1927. $bindings = $sparl_results['results']['bindings'];
  1928. foreach ($bindings as $a_binding) {
  1929. $url_results[] = $a_binding['packageUri']['value'];
  1930. }
  1931. $plugin_results = array();
  1932. if (count($url_results) != 0) {
  1933. $this->searchForUrl($url_results, $client, $plugin_results, $sort_kind, $sort_priority);
  1934. }
  1935. return $plugin_results;
  1936. }
  1937. else {
  1938. $this->_owApp->appendMessage(
  1939. new OntoWiki_Message('Plugin Repository not reachable', OntoWiki_Message::ERROR )
  1940. );
  1941. $wrong_response = true;
  1942. return null;
  1943. }
  1944. }
  1945. /**
  1946. * Search for the plugins according to the information
  1947. * from the function searchForPlugins
  1948. *
  1949. * @param array $url_results
  1950. * @param object $client
  1951. * @param array $results
  1952. * @param string $sort_kind
  1953. * @param string $sort_priority
  1954. */
  1955. public function searchForUrl($url_results, $client, &$results, $sort_kind, $sort_priority)
  1956. {
  1957. foreach ($url_results as $a_url_result) {
  1958. $u_query = "PREFIX type: <".$this->_privateConfig->p_type_base.">
  1959. PREFIX plugin: <".$this->_privateConfig->plugin_base.">
  1960. PREFIX name: <".$this->_privateConfig->p_name_base.">
  1961. PREFIX description: <".$this->_privateConfig->p_desc_base.">
  1962. PREFIX developer: <".$this->_privateConfig->p_dev_base.">
  1963. PREFIX release: <".$this->_privateConfig->p_release_base.">
  1964. PREFIX url: <".$this->_privateConfig->filerelease_base.">
  1965. PREFIX node: <$a_url_result>
  1966. SELECT ?name ?description ?developer ?url
  1967. WHERE {node: name: ?name.
  1968. node: description: ?description.
  1969. node: developer: ?developer.
  1970. node: release: ?version.
  1971. ?version url: ?url.
  1972. }";
  1973. $u_query = $u_query . "ORDER BY " . $sort_priority . "(?" . $sort_kind . ")";
  1974. $client->setParameterPost('query',$u_query);
  1975. $client->setHeaders('Accept', 'application/sparql-results+json');
  1976. $response = $client->request('POST');
  1977. $sparl_results = Zend_Json::decode($response->getBody());
  1978. //print_r($sparl_results);
  1979. foreach ($sparl_results['results']['bindings'] as $a_sparal_result) {
  1980. $plugin_name = $a_sparal_result['name']['value'];
  1981. $plugin_developer = $a_sparal_result['developer']['value'];
  1982. $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, '', $plugin_developer);
  1983. $plugin_desciption = $a_sparal_result['description']['value'];
  1984. $plugin_install_url = $a_sparal_result['url']['value'];
  1985. $results[] = array(
  1986. 'name' => $plugin_name,
  1987. 'developer' => $plugin_developer,
  1988. 'description' => $plugin_desciption,
  1989. 'install_url' => $plugin_install_url
  1990. );
  1991. }
  1992. }
  1993. }
  1994. }
  1995. ?>