/extensions.ext/plugins/PluginsController.php
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
- <?php
- require_once 'OntoWiki/Controller/Component.php';
- require_once 'OntoWiki/Toolbar.php';
- require_once 'Erfurt/Sparql/SimpleQuery.php';
- require_once 'Zend/Http/Client.php';
- /**
- * Controller for the OntoWiki Plugin Manager
- *
- * @category OntoWiki
- * @package OntoWiki_extensions_components_plugins
- * @author Qiu Feng <qiu_feng39@hotmail.com>
- * @copyright Copyright (c) 2008, {@link http://aksw.org AKSW}
- * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
- * @version $$
- */
- class PluginsController extends OntoWiki_Controller_Component
- {
- public function init()
- {
- parent::init();
- require_once('Zend/Paginator.php');
- require_once('Zend/Paginator/Adapter/Array.php');
-
- // Action Based Access Control for the Plugin Manager
- $owApp = OntoWiki::getInstance();
- if (!$this->_erfurt->isActionAllowed('PluginManagement')){
- //TODO uncomment after changes
- //require_once 'Erfurt/Ac/Exception.php';
- //throw new Erfurt_Ac_Exception('You are not allowed to use the Plugin Manager.');
- }
- OntoWiki_Navigation::reset();
- OntoWiki_Navigation::register('categories', array(
- 'controller' => 'plugins',
- 'action' => 'categories',
- 'name' => 'Search',
- 'position' => 0,
- 'active' => false
- ));
- OntoWiki_Navigation::register('new', array(
- 'controller' => 'plugins',
- 'action' => 'new-plugins',
- 'name' => 'What\'s new',
- 'position' => 1,
- 'active' => false
- ));
- OntoWiki_Navigation::register('installed', array(
- 'controller' => 'plugins',
- 'action' => 'installed',
- 'name' => 'Installed',
- 'position' => 2,
- 'active' => false
- ));
- }
-
- /**
- *
- *
- *
- */
- public function pluglistAction()
- {
- $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
-
- $u_query = 'PREFIX type: <'.$this->_privateConfig->p_type_base.'>
- PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
- PREFIX name: <'.$this->_privateConfig->p_name_base.'>
- PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
- PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
- PREFIX release: <'.$this->_privateConfig->p_release_base.'>
- PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
-
- SELECT ?node ?name ?description ?developer ?url
- WHERE {?node type: plugin:.
- ?node name: ?name.
- ?node description: ?description.
- ?node developer: ?developer.
- ?node release: ?version.
- ?version url: ?url.}';
-
- $client->setParameterPost('query', $u_query);
- $client->setHeaders('Accept', 'application/sparql-results+json');
- $response = $client->request('POST');
- $sparl_results = Zend_Json::decode($response->getBody());
- $results = array();
- $wrong_response = false;
-
- if (!strstr($response->getBody(),'bindings')) {
- $wrong_response = true;
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Plugin Repository not reachable', OntoWiki_Message::ERROR )
- );
- }
-
- if (count($sparl_results['results']['bindings']) != 0 && !$wrong_response) {
- $i = 0;
- foreach ($sparl_results['results']['bindings'] as $a_sparal_result) {
- $plugin_name = $a_sparal_result['name']['value'];
- $plugin_developer = $a_sparal_result['developer']['value'];
- $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, '', $plugin_developer);
- $plugin_desciption = $a_sparal_result['description']['value'];
- $results[$i] = array(
- 'name' => $plugin_name,
- 'developer' => $plugin_developer,
- 'description' => $plugin_desciption,
- );
- $i++;
- }
- }
-
- $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/plugin.css');
- $this->view->plugins = $results;
- //return 'plugins list';
- }
-
-
-
- /**
- * categorieAction
- *
- * This action can let the user to choose the category
- * of plungin that they want to search
- */
- public function categoriesAction()
- {
- //Rights check
- $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Plugin Categories'));
- OntoWiki_Navigation::setActive('categories',true);
- require_once 'OntoWiki/Message.php';
- //End Rights check
- //Javascript for the plugintemplates
- $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/plugin.css');
- $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/pluginselect.js');
- $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/tagcloud.css');
- $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/createtagcloud.js');
- $pluginurl = $this->_componentUrlBase;
- $this->view->pluginurl = $pluginurl;
- //End Javascript
- /*Query to the Repository*/
- $from = "categories";
- $search_keyword = $this->_request->getPost('search_keyword', '');
- if ($this->_request->isPost()) {
- $categorie_select = $this->_request->getPost('categorie_select');
- $sort_kind = $this->_request->getPost('sort_kind', 'name');
- $sort_priority = $this->_request->getPost('sort_priority', 'ASC');
- $this->_session->plugins_per_page = $this->_request->getPost('plugins_per_page', 3);
- $this->_session->sort_priority = $sort_priority;
- $this->_session->sort_kind = $sort_kind;
- //echo $categorie_select." ".$sort_kind." ".$sort_priority." ".$this->_session->plugins_per_page;
- }
- else {
- $sort_kind = "name";
- $sort_priority = "ASC";
- $selected_tag = $this->getParam('tag');
- if ($selected_tag != ''){
- $from = "tag";
- }
- }
-
- //Information for sorting
- if (isset($this->_session->sort_kind)) {
- $sort_kind = $this->_session->sort_kind;
- }
- else {
- $sort_kind = 'name';
- }
- if (isset($this->_session->sort_priority)) {
- $sort_priority = $this->_session->sort_priority;
- }
- else {
- $sort_priority = 'ASC';
- }
-
-
- $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
-
-
-
- //$client = Erfurt_App::getInstance()->getHttpClient($this->_config->urlBase . 'sparql/');
- //echo $this->_config->urlBase . 'sparql/';
- //$u_query = 'SELECT * WHERE {?s ?p ?o} limit 100';
- $wrong_response = false;
- // if there is no search
- if ($search_keyword == '') {
- if ($from == 'categories' && $search_keyword == '') {
- $u_query = 'PREFIX type: <'.$this->_privateConfig->p_type_base.'>
- PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
- PREFIX name: <'.$this->_privateConfig->p_name_base.'>
- PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
- PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
- PREFIX release: <'.$this->_privateConfig->p_release_base.'>
- PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
-
- SELECT ?node ?name ?description ?developer ?url
- WHERE {?node type: plugin:.
- ?node name: ?name.
- ?node description: ?description.
- ?node developer: ?developer.
- ?node release: ?version.
- ?version url: ?url.}';
- }
- // User search for somthing
- /*elseif ($from == 'categories' && $search_keyword != '') {
- $search_keyword = trim($search_keyword);
- $this->searchForUrl($search_keyword, $client);
-
-
- $search_keyword = trim($search_keyword);
- $first_letter = strtoupper(substr($search_keyword, 0, 1));
- $search_keyword = $first_letter . substr($search_keyword, 1);
- $u_query = " PREFIX type: <'.$this->_privateConfig->p_type_base.'>
- PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
- PREFIX name: <'.$this->_privateConfig->p_name_base.'>
- PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
- PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
- PREFIX release: <'.$this->_privateConfig->p_release_base.'>
- PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
- PREFIX tag: <'.$this->_privateConfig->p_tag_base.'>
-
- SELECT ?node ?name ?description ?developer ?url
- WHERE { ?node type: plugin:.
- ?node name: ?name.
- ?node description: ?description.
- ?node developer: ?developer.
- ?node release: ?version.
- ?version url: ?url.
- ?version tag: \"$search_keyword\"^^xsd:string.}";
- }*/
-
- elseif ($from == 'tag') {
- $u_query = " PREFIX type: <".$this->_privateConfig->p_type_base.">
- PREFIX plugin: <".$this->_privateConfig->plugin_base.">
- PREFIX name: <".$this->_privateConfig->p_name_base.">
- PREFIX description: <".$this->_privateConfig->p_desc_base.">
- PREFIX developer: <".$this->_privateConfig->p_dev_base.">
- PREFIX release: <".$this->_privateConfig->p_release_base.">
- PREFIX url: <".$this->_privateConfig->filerelease_base.">
- PREFIX tag: <".$this->_privateConfig->p_tag_base.">
-
- SELECT ?node ?name ?description ?developer ?url
- WHERE { ?node type: plugin:.
- ?node name: ?name.
- ?node description: ?description.
- ?node developer: ?developer.
- ?node release: ?version.
- ?version url: ?url.
- ?version tag: \"$selected_tag\"^^xsd:string.}";
- }
-
-
- $u_query = $u_query . "ORDER BY " . $sort_priority . "(?" . $sort_kind . ")";
- //$u_query = $u_query." ORDER BY DESC(?name)";
- //echo "query: ".$u_query."<br/>";
- $client->setParameterPost('query', $u_query);
- $client->setHeaders('Accept', 'application/sparql-results+json');
- $response = $client->request('POST');
- //print_r($response);
- //print_r($response->getBody());
- //echo"<br/><br/>";
- /*End*/
-
- /*Change the results in an array*/
- $sparl_results = Zend_Json::decode($response->getBody());
- //print_r($sparl_results['bindings'][0]);
- $results = array();
-
-
- if (!strstr($response->getBody(),'bindings')) {
- $wrong_response = true;
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Plugin Repository not reachable', OntoWiki_Message::ERROR )
- );
- }
-
-
- if (count($sparl_results['results']['bindings']) != 0 && !$wrong_response) {
- $i = 0;
- foreach ($sparl_results['results']['bindings'] as $a_sparal_result) {
- $plugin_name = $a_sparal_result['name']['value'];
- $plugin_developer = $a_sparal_result['developer']['value'];
- $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, '', $plugin_developer);
- $plugin_desciption = $a_sparal_result['description']['value'];
- $plugin_install_url = $a_sparal_result['url']['value'];
- $results[$i] = array(
- 'name' => $plugin_name,
- 'developer' => $plugin_developer,
- 'description' => $plugin_desciption,
- 'install_url' => $plugin_install_url
- );
- $i++;
- }
- }
- } // end if there is no search
- // if user wants to search
- else {
- $results = $this->searchForPlugins($search_keyword, $client, $wrong_response, $sort_kind, $sort_priority);
- }
-
- $count = count($results);
- if (!$wrong_response) {
- if (!isset($results)|| $count == 0) {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('No Matching!', OntoWiki_Message::WARNING )
- );
- }
- else {
- $message = $count.' plugin(s) found!';
- $this->_owApp->appendMessage(
- new OntoWiki_Message($message, OntoWiki_Message::INFO )
- );
- }
- }
-
- /* Get Tags */
- if ($from == 'tag') {
- $tags_results = $this->getTags($selected_tag);
- }
- else {
- $tags_results = $this->getTags(null);
- }
- $this->view->tags = $tags_results;
- //echo "<br/><br/>TAGS_DECODE: ".print_r($tags_results)."<br/>";
- //echo"<br/><br/>";
-
- //Check the ftp-configuation in component.ini
- if (isset($this->_privateConfig->ftp->username) && isset($this->_privateConfig->ftp->password) && isset($this->_privateConfig->ftp->hostname)) {
- $ftp_config = true; // true or false didn't work?!
- }
- else {
- $ftp_config = false;
- }
-
- //Start use a Zend_paginator;
- $page =1;
- $numPerPage = 3;
- if (isset($this->_session->plugins_per_page)) {
- $numPerPage = $this->_session->plugins_per_page;
- }
- $this->view->plugins_per_page = $numPerPage;
- if (isset($_GET['page']) && is_numeric($_GET['page'])){
- $page = $_GET['page'];
- }
- $offset = $numPerPage*$page;
- $this->count = $count;
- $this->view->results = $results;
- $this->view->to_translate = $this->getFrontController()->getBaseUrl() . '/plugins/categories';
- $this->view->toinstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/getinfo';
- $this->view->ftp_config = $ftp_config;
- $this->view->plugin_outlook = $this->_privateConfig->client->plugin_outlook;
- $this->view->sort_priority = $sort_priority;
- $this->view->sort_kind = $sort_kind;
- $this->page($page, $numPerPage, $results);
- $this->render();
- //End
- //End
- }
-
- /**
- * newPluginsAction
- *
- * Show the new Plugins
- */
- public function newPluginsAction()
- {
- $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('The plugins, new or just updatet'));
- OntoWiki_Navigation::setActive('new',true);
- require_once 'OntoWiki/Message.php';
- //Javascript for the plugintemplates
- $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/plugin.css');
- $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/pluginselect.js');
- $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'templates/plugins/css/tagcloud.css');
- $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/createtagcloud.js');
- $pluginurl = $this->_componentUrlBase;
- $this->view->pluginurl = $pluginurl;
- //End
- /*Query to the Repository*/
- $from = "newPlugins";
- if ($this->_request->isPost()) {
- $sort_kind = $this->_request->getPost('sort_kind');
- $sort_priority = $this->_request->getPost('sort_priority');
- $this->_session->plugins_per_page = $this->_request->getPost('plugins_per_page');
- $newplugins_in_days = $this->_request->getPost('newplugins_in_days');
- $this->_session->newplugins_in_days = $newplugins_in_days;
- $this->_session->sort_priority = $sort_priority;
- $this->_session->sort_kind = $sort_kind;
- }
- else {
- if (isset($this->_session->newplugins_in_days)) {
- $newplugins_in_days = $this->_session->newplugins_in_days;
- }
- else {
- $newplugins_in_days = 0;
- }
- if (isset($this->_session->sort_priority)) {
- $sort_priority = $this->_session->sort_priority;
- }
- else {
- $sort_priority = "ASC";
- }
- if (isset($this->_session->sort_kind)) {
- $sort_kind = $this->_session->sort_kind;
- }
- else {
- $sort_kind = "name";
- }
-
- $selected_tag = $this->getParam('tag');
- if ($selected_tag != ''){
- $from = "tag";
- }
- }
- $daysago_in_seconds = $newplugins_in_days*60*60*24;
- $deadline = date('Y-m-d', time() - $daysago_in_seconds) . 'T00:00:00.000';
- //echo "<br/>$deadline<br/>";
- $this->view->deadline = $deadline;
- $client = Erfurt_App::getInstance()->getHttpClient($this->_privateConfig->repository->r_url);
- $u_query = 'PREFIX type: <'.$this->_privateConfig->p_type_base.'>
- PREFIX plugin: <'.$this->_privateConfig->plugin_base.'>
- PREFIX name: <'.$this->_privateConfig->p_name_base.'>
- PREFIX description: <'.$this->_privateConfig->p_desc_base.'>
- PREFIX developer: <'.$this->_privateConfig->p_dev_base.'>
- PREFIX release: <'.$this->_privateConfig->p_release_base.'>
- PREFIX url: <'.$this->_privateConfig->filerelease_base.'>
- PREFIX modified: <'.$this->_privateConfig->p_modified_base.'>
-
- SELECT ?node ?name ?description ?developer ?url ?modified
- WHERE {?node type: plugin:.
- ?node name: ?name.
- ?node description: ?description.
- ?node developer: ?developer.
- ?node release: ?version.
- ?node modified: ?modified.
- ?version url: ?url.';
- $u_query = $u_query . ' FILTER (xsd:dateTime(?modified)>="' . $deadline . '"^^xsd:dateTime) }';
- //echo "<br/>u_query: $u_query<br/>";
- $u_query = $u_query . "ORDER BY " . $sort_priority . "(?" . $sort_kind . ")";
- $client->setParameterPost('query',$u_query);
- $client->setHeaders('Accept', 'application/sparql-results+json');
- $response = $client->request('POST');
- $sparl_results = Zend_Json::decode($response->getBody());
- //print_r($sparl_results['bindings'][0]);
- $results = array();
-
-
- if (count($sparl_results['results']['bindings']) != 0) {
- $i = 0;
- foreach ($sparl_results['results']['bindings'] as $a_sparal_result){
- $plugin_name = $a_sparal_result['name']['value'];
- $plugin_developer = $a_sparal_result['developer']['value'];
- $plugin_developer = str_replace($this->_privateConfig->rdf_base_url, "", $plugin_developer);
- $plugin_desciption = $a_sparal_result['description']['value'];
- $plugin_install_url = $a_sparal_result['url']['value'];
- $results[$i] = array(
- 'name' => $plugin_name,
- 'developer' => $plugin_developer,
- 'description' => $plugin_desciption,
- 'install_url' => $plugin_install_url
- );
- $i++;
- }
- }
- $count = count($results);
- if (!isset($results)|| $count == 0) {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('No Matching!', OntoWiki_Message::WARNING )
- );
- }
- else {
- $message = $count.' plugin(s) found!';
- $this->_owApp->appendMessage(
- new OntoWiki_Message($message, OntoWiki_Message::INFO )
- );
- }
-
- /* Get Tags */
- if ($from == 'tag') {
- $tags_results = $this->getTags($selected_tag);
- }
- else {
- $tags_results = $this->getTags(null);
- }
- $this->view->tags = $tags_results;
-
- //Start use a Zend_paginator;
- $page =1;
- $numPerPage = 3;
- if (isset($this->_session->plugins_per_page)){
- $numPerPage = $this->_session->plugins_per_page;
- }
- $this->view->plugins_per_page = $numPerPage;
- if (isset($_GET['page']) && is_numeric($_GET['page'])){
- $page = $_GET['page'];
- }
- $offset = $numPerPage*$page;
- $this->count = $count;
- $this->view->results = $results;
- $this->view->new_plugins = $this->getFrontController()->getBaseUrl().'/plugins/new-plugins';
- $this->view->toinstall_url = $this->getFrontController()->getBaseUrl().'/plugins/toinstall';
- $this->view->plugin_outlook = $this->_privateConfig->client->plugin_outlook;
- $this->view->newplugins_in_days = $newplugins_in_days;
- $this->view->sort_priority = $sort_priority;
- $this->view->sort_kind = $sort_kind;
- $this->page($page, $numPerPage, $results);
- $this->render();
- }
- /**
- * installedAction
- *
- * The functions for a plugin-developer
- */
- public function installedAction()
- {
- $selected_categorie = 'all'; // this function can have more uses
- if ($this->_request->isPost()) {
- $selected_categorie = $this->_request->getPost('categorie_select');
- $_SESSION['qiufeng']['plugins_per_page'] = $this->_request->getPost('plugins_per_page');
- }
- $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Installed Plugins'));
- $this->view->headScript()->appendFile($this->_componentUrlBase . 'templates/resources/makesure.js');
- OntoWiki_Navigation::setActive('installed', true);
- /* Ready from SystemConfig */
- $results = $this->readFromSysConfig('all');
- //print_r($results);
- $this->view->installedaction_url = $this->getFrontController()->getBaseUrl() . '/plugins/installed';
- $this->view->toinstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/toinstall';
- $this->view->touninstall_url = $this->getFrontController()->getBaseUrl() . '/plugins/touninstall';
- $this->view->install_from_file_url = $this->getFrontController()->getBaseUrl() . '/plugins/install-From-File';
- if ($results === null) {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('No plugin is installed!', OntoWiki_Message::WARNING )
- );
- $this->view->results = null;
- $numPerPage = 3;
- $this->view->plugins_per_page = $numPerPage;
- if (isset($_SESSION['qiufeng']['plugins_per_page'])) {
- $numPerPage = $_SESSION['qiufeng']['plugins_per_page'];
- }
- $this->view->plugins_per_page = $numPerPage;
- $this->page(1, $numPerPage, array());
- $this->render();
- }
- else {
- $results_without_upgrade = $results;
- $results = $this->searchupgrade($results_without_upgrade);
- $count = count($results);
- $message = "$count plugin(s) installed!";
- $this->_owApp->appendMessage(
- new OntoWiki_Message($message, OntoWiki_Message::INFO )
- );
- //Start use a Zend_pageinator;
- $page =1;
- $numPerPage = 3;
- $this->view->plugins_per_page = $numPerPage;
- if (isset($_SESSION['qiufeng']['plugins_per_page'])) {
- $numPerPage = $_SESSION['qiufeng']['plugins_per_page'];
- }
- $this->view->plugins_per_page = $numPerPage;
- if (isset($_GET['page']) && is_numeric($_GET['page'])) {
- $page = $_GET['page'];
- }
- $offset = $numPerPage*$page;
- $this->count = $count;
- $this->view->results = $results;
- $this->view->to_translate = $this->getFrontController()->getBaseUrl() . '/plugins/installed';
- $this->page($page,$numPerPage,$results);
- $this->render();
- //End
- }
- }
-
- /**
- * installfromFileAction
- *
- * Action for installation from a file
- */
- public function installFromFileAction()
- {
- $this->getFrontController()->setParam('noViewRenderer', true);
- if ($_FILES['install_from_file']['error'] == UPLOAD_ERR_OK) {
- // upload ok, move file
- //$fileUri = $this->_request->getPost('file_uri');
- $fileName = $_FILES['install_from_file']['name'];
- $tmpName = $_FILES['install_from_file']['tmp_name'];
- $mimeType = $_FILES['install_from_file']['type'];
- //echo"<br/>fileName: $fileName tempName:$tmpName mimeType:$mimeType<br/>";
- if (substr(trim($fileName),-4) == '.zip') {
- $install_with_ftp = false;
- try {
- if (!move_uploaded_file($_FILES['install_from_file']['tmp_name'],$this->_componentRoot . '/temp/installfromfile.zip')) {
- $install_with_ftp = true;
- rename($_FILES['install_from_file']['tmp_name'], $_FILES['install_from_file']['tmp_name'] . '.zip');
- $tmp_file = $_FILES['install_from_file']['tmp_name'] . '.zip';
- $fp = fopen($tmp_file, 'r');
- echo "<br/>tmp_file:$tmp_file<br/>";
- if ($fp) {
- $data = '';
- while(!feof($fp)) {
- $data .= fread($fp, 1024);
- }
- fclose($fp);
- $fp = fopen($_FILES['install_from_file']['tmp_name'] . '_tmp.zip', "w+");
-
- if ($fp) {
- fwrite($fp,$data);
- fclose($fp);
- }
- $sftp = null;
- $connection = null;
- $this->ftpConnect($sftp, $connection);
- if (!$sftp) {
- $this->_redirect('plugins/errors/error/noftp');
- }
- else{
- $from_file = $_FILES['install_from_file']['tmp_name'] . '_tmp.zip';
- $to_file = $this->_componentRoot . '/temp/installfromfile.zip';
- $copy = ssh2_exec($connection, "cp $from_file $to_file");
- $chmod = ssh2_exec($connection, "chmod 0777 $to_file");
- unlink($from_file);
- unlink($_FILES['install_from_file']['tmp_name'] . '.zip');
- if( $copy && $chmod ){
- //do nothing
- }
- else {
- $this->_redirect('plugins/errors/error/exec');
- }
- }
-
- }
- }
- }
- catch (Exception $e) {
- }
-
- $this->_redirect('plugins/install-choice/from/installfromfile/name/' . str_replace('.zip','',$fileName));
-
- }
- else {
- $this->_redirect('plugins/errors/error/zip');
- }
- }
- else {
- $this->_redirect('plugins/errors/error/filenotfound');
- }
- }
- /**
- * Action to show the errormessage
- * if for example the rdf-file is
- * not correct
- *
- */
- public function errorsAction()
- {
- $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Error!'));
- $error = $this->_getParam('error');
- if ($error == 'rdf') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Error in RDF-file, installtion canceled!', OntoWiki_Message::ERROR)
- );
- }
- elseif ($error == 'zip') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('You can only upload an ZIP file!', OntoWiki_Message::ERROR)
- );
- }
- elseif ($error == 'filenotfound') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('File not found!', OntoWiki_Message::ERROR)
- );
- }
- elseif ($error == 'moveinstallfile') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Could not move uploaded file!', OntoWiki_Message::ERROR)
- );
- }
- elseif ($error == 'noftp') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Apache has no write right and could not build an ftp-connection!', OntoWiki_Message::ERROR)
- );
- }
- elseif ($error == 'exec') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('SSH2_EXEC ERROR!', OntoWiki_Message::ERROR)
- );
- }
- elseif ($error == 'installnoftp') {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Install: No FTP-connection!', OntoWiki_Message::ERROR)
- );
- }
- }
-
- /**
- * Action for Zen_paginator
- *
- * @param int $page
- * @param int $numPerPage
- * @param array $results
- */
- public function page($page, $numPerPage, $results)
- {
- $paginator = Zend_Paginator::factory($results);
- $paginator->setCurrentPageNumber($page)->setItemCountPerPage($numPerPage);
- $this->view->paginator = $paginator;
- }
- /**
- * Action for Zend_paginator
- *
- */
- public function pagelistAction(){
- Zend_Paginator::setDefaultScrollingStyle('Elastic');
- Zend_View_Helper_PaginationControl::setDefaultViewPartial('../pagelist/categoriepagelist.phtml');
- $paginator->setView($view);
- }
-
- /**
- * Function to install a plugin
- *
- */
- public function toinstallAction()
- {
- require_once("Erfurt/Syntax/RdfParser.php");
- /* maybe will be used */
- if ($this->_request->isPost()) {
- // do nothing
- }
- /* really installation*/
- else {
- $from = $this->_getParam('from');
- if ($from =='installfromfile' || $from == 'upgrade' || $from == 'reinstall' || $from = 'categoriepage') {
- $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Installing...'));
- $p_name = $this->_getParam('name');
- if ($from == 'categoriepage') {
- $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
- }
- elseif ($from == 'installfromfile') {
- $url = $this->_componentRoot.'/temp/installfromfile.zip';
- }
- elseif ($from == 'upgrade') {
- $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
- }
- elseif ($from == 'reinstall') {
- $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
- }
-
- $this->view->install_png_url = $this->_componentUrlBase . 'img/download.png';
- //echo "<h3>categorie:".$p_categorie."</h3>";
- //echo '<h3 style="color:#FF0000">Plugin:'.$p_name."from: ".$url." is installed!</h3>";
- $fp = fopen($url, 'r');
- if ($fp) {
- $data = '';
- while(!feof($fp)) {
- $data .= fread($fp, 1024);
- }
- fclose($fp);
- $filename = 'extensions/components/plugins/' . $p_name. '.zip';
-
- $fp = fopen($filename, "w+");
-
- if ($fp && is_writable('extensions/components/plugins/')) {
- clearstatcache();
- fwrite($fp,$data);
- fclose($fp);
- $filepath = $filename;
- if (file_exists($filepath)) {
- $zip = new ZipArchive();
- $rs = $zip->open($filepath);
- if ($rs) {
- $fd = explode(".",basename($filepath));
- $zip->extractTo(dirname($filepath) . '/' . $fd[0]);
- $zip->close();
- unlink($filepath);
- /* check the rdf-file */
- $rdf_file_path = 'extensions/components/plugins/' . $p_name . '/package.rdf';
- $fpt = fopen($url, 'r');
- if ($fpt) {
- /*Parse the rdf-file in an array*/
- $rdf_parser = Erfurt_Syntax_RdfParser::rdfParserWithFormat('rdf');
- $rdf_result = $rdf_parser->parse($rdf_file_path, 20);
- //print_r($rdf_result);
- $rdf_format = true;
- $config_info = $this->checkAndRead($rdf_format,$rdf_result);
- //print_r($config_info);
- /* Check the directories */
- if ($rdf_format && $config_info != null) {
- $extension_dir = $config_info['extension_dir'];
- $extension_file = $config_info['extension_file'];
- $error_message = '';
- if ($this->checkDir($extension_dir,$extension_file,$error_message)){
- /* Copy the directories */
- $extension_path = $this->_componentRoot;
- $extension_path = str_replace('\\', '/', $extension_path);
- $extension_path = str_replace('/components/plugins','',$extension_path);
- $correct_installed = true;
- $component_root = str_replace('\\', '/', $this->_componentRoot);
- for ($i=0; $i<count($extension_dir); $i++) {
- $a_dir = $extension_dir[$i];
- try {
- $from_dir = $component_root . '/' . $p_name. '/' . $a_dir;
- $to_dir = $extension_path . '/' . $a_dir;
- //echo "from_dir: ".$from_dir."<br/>"."to_dir".$to_dir."<br/>";
- rename($from_dir,$to_dir);
- $correct_installed = file_exists($to_dir);
- }
- catch (Exception $e) {
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Can't copy directory to $to_dir", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- for ($i=0; $i<count($extension_file); $i++) {
- $a_file = $extension_file[$i];
- try {
- $from_dir = $component_root.'/' . $p_name. '/' . $a_file;
- $to_dir = $extension_path . '/' . $a_file;
- //echo "from_dir: ".$from_dir."<br/>"."to_dir".$to_dir."<br/>";
- rename($from_dir,$to_dir);
- $correct_installed = file_exists($to_dir);
- }
- catch (Exception $e) {
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Can't copy file to $to_dir", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- /* delete the unzipped file in a directory!!*/
- $this->delDirAndFile($this->_componentRoot . '/' . $p_name);
- $correct_deleted = file_exists($this->_componentRoot . '/' . $p_name);
- if ($correct_installed && !$correct_deleted) {
- if ($from == 'installfromfile') {
- /* delete the template sourcefile */
- unlink($this->_componentRoot.'temp/installfromfile.zip');
- }
- $this->_owApp->appendMessage(
- new OntoWiki_Message("New Plugin: $p_name is installed successfully!", OntoWiki_Message::SUCCESS)
- );
- $this->view->install_info_png = $this->_componentUrlBase . 'img/true.png';
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('Unknow error', OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- /* write into SysConfig */
- $this->insertIntoSysConfig($config_info);
- if (!$this->_privateConfig->client->debug) {
- $this->_redirect('plugins/categories');
- }
- }
- else {
- /* Possible that the extension schould be upgraded, test if they have the same Base-URL */
- echo"<br>$error_message<br/>";
- if ($this->isinstalled($config_info)) {
- $dirs = $config_info['extension_dir'];
- $files = $config_info['extension_file'];
- $plugin_baseurl = $config_info['plugin_baseurl'];
- $dir_serialized = $this->seriation($dirs);
- $file_serialized = $this->seriation($files);
- /*Take care of '/' because of Zend_framwork */
- $dir_serialized = str_replace('/','@slash@',$dir_serialized);
- $file_serialized = str_replace('/','@slash@',$file_serialized);
- $plugin_baseurl = str_replace('/','@slash@',$plugin_baseurl);
- $reinstall_url = 'plugins/trytoreinstall/dirs/' . $dir_serialized . '/files/' . $file_serialized . '/p_name/' . $p_name . '/extension_url/' . $plugin_baseurl;
- if ($from == 'installfromfile') {
- $url_zip_file = $this->_componentRoot . '/temp/installfromfile.zip';
- $url_zip_file = str_replace('\\', '/', $url_zip_file);
- $reinstall_url = $reinstall_url . '/reinstall_from/file/file_url/' . $this->codeSparqlQuery($url_zip_file);
- }
- elseif ($from == 'upgrade') {
- $upgrade_file_url = $this->_getParam('file_url');
- $reinstall_url = $reinstall_url . '/reinstall_from/upgrade/file_url/' . $upgrade_file_url; //$upgrade_file_url is already coded
- }
- elseif ($from == 'categoriepage') {
- $upgrade_file_url = $this->_getParam('file_url');
- $reinstall_url = $reinstall_url . '/reinstall_from/upgrade/file_url/' . $upgrade_file_url; //$upgrade_file_url is already coded
- }
- $this->_redirect($reinstall_url);
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message($error_message, OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Wrong RDf-format!", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
- }
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message('RDF-file not found!: '.$filename, OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Copyed zip-file not found!: $filename", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Can't wirite file to: $filename", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- else {
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Can't open file from: $url", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase.'img/false.png';
- }
- }
- }
- }
-
- /**
- * Intall the plugins with FTP
- *
- */
- public function toInstallWithFtpAction()
- {
- $sftp = null;
- $connection = null;
- $this->ftpConnect($sftp, $connection);
- if (!$sftp) {
- $this->_redirect('plugins/errors/error/installnoftp');
- }
-
- require_once("Erfurt/Syntax/RdfParser.php");
- /* maybe will be used */
- if ($this->_request->isPost()) {
- // do nothing
- }
- /* really installation*/
- else {
- $from = $this->_getParam('from');
- if ($from =='installfromfile' || $from == 'upgrade' || $from == 'reinstall' || $from = 'categoriepage') {
- $this->view->placeholder('main.window.title')->set($this->_owApp->translate->_('Installing...'));
- $p_name = $this->_getParam('name');
- if ($from == 'categoriepage') {
- $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
- }
- elseif ($from == 'installfromfile') {
- $url = $this->_componentRoot.'/temp/installfromfile.zip';
- }
- elseif ($from == 'upgrade') {
- $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
- }
- elseif ($from == 'reinstall') {
- $url = $this->decodeSparqlQuery($this->_getParam('file_url'));
- }
-
- $this->view->install_png_url = $this->_componentUrlBase . 'img/download.png';
-
- $sftp = null;
- $connection = null;
- $this->ftpConnect($sftp, $connection);
- $componentRoot = $this->_componentRoot;
- if ($sftp) {
- /* Copy zip-file to the plugins-directory */
- $getfile = ssh2_exec($connection, "wget -O $componentRoot/$p_name.zip $url");
- $copy = ssh2_exec($connection, "cp $url $componentRoot/$p_name.zip");
-
- /* Unzip the zip-file */
- if (file_exists("$componentRoot/$p_name.zip")) {
- $unzip = ssh2_exec($connection, "unzip $componentRoot/$p_name.zip -d $componentRoot/$p_name");
- $del = ssh2_exec($connection, "rm $componentRoot/$p_name.zip");
- /* try to read from rdf-file */
- if (file_exists("$componentRoot/$p_name")) {
- ssh2_exec($connection, "chmod 777 $componentRoot/$p_name");
- $rdf_file_path = "extensions/components/plugins/$p_name/package.rdf";
- /* Parse the rdf-file in an array */
- $rdf_parser = Erfurt_Syntax_RdfParser::rdfParserWithFormat('rdf');
- $rdf_result = $rdf_parser->parse($rdf_file_path, 20);
- //print_r($rdf_result);
- $rdf_format = true;
- $config_info = $this->checkAndRead($rdf_format,$rdf_result);
- //print_r($config_info);
-
- // Check the directories
- if ($rdf_format && $config_info != null) {
- $extension_dir = $config_info['extension_dir'];
- $extension_file = $config_info['extension_file'];
- $error_message = '';
- if ($this->checkDir($extension_dir, $extension_file, $error_message)){
- $extension_path = $this->_componentRoot;
- $extension_path = str_replace('\\', '/', $extension_path);
- $extension_path = str_replace('/components/plugins','',$extension_path);
- $correct_installed = true;
- $component_root = str_replace('\\', '/', $this->_componentRoot);
- for ($i=0; $i<count($extension_dir); $i++) {
- $a_dir = $extension_dir[$i];
- $from_dir = $component_root . '/' . $p_name. '/' . $a_dir;
- $to_dir = $extension_path . '/' . $a_dir;
- //echo "from_dir: ".$from_dir."<br/>"."to_dir".$to_dir."<br/>";
- ssh2_exec($connection, "mv $from_dir $to_dir");
- if (!file_exists($to_dir)) {
- $correct_installed = file_exists($to_dir);
- $this->_owApp->appendMessage(
- new OntoWiki_Message("Can't copy directory to $to_dir FTP", OntoWiki_Message::ERROR)
- );
- $this->view->install_info_png = $this->_componentUrlBase . 'img/false.png';
- }
- }
- for ($i=0; $i<count($extension_file); $i++) {
- $a_file = $extension_file[$i];
- try {
- $from_dir = $component_root.'/' . $p_name. '/' . $a_file;
- $to_dir = $extension_path . '/' . $a_file;
- //echo "from_file: ".$from_dir."<br/>"."to_file: ".$to_dir."<br/>";
- ssh2_exec($connection, "mv $from_dir $to_dir");
- if (!file_exists($to_dir)) {
- …
Large files files are truncated, but you can click here to view the full file