PageRenderTime 70ms CodeModel.GetById 33ms 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

Large files files are truncated, but you can click here to view the full file

  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)) {

Large files files are truncated, but you can click here to view the full file