From b8be00fdc23658fc94affd5d426d49e5bcd4001d Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Thu, 8 Nov 2018 10:26:55 +0100 Subject: [PATCH] dev #79082 : fix rt comments --- .../admin/controllers/AjaxController.php | 48 +----- .../controllers/UrlManagerController.php | 25 +-- .../admin/views/scripts/search/detail.phtml | 19 --- .../views/scripts/search/force-https.phtml | 3 - .../admin/views/scripts/urls/list.phtml | 7 - library/Class/ContentTextReplacement.php | 161 ------------------ library/Class/UrlManager/Article.php | 4 +- library/Class/UrlManager/Domain.php | 3 +- library/Class/UrlManager/Newsletter.php | 5 +- .../controllers/UrlManagerControllerTest.php | 54 +----- 10 files changed, 13 insertions(+), 316 deletions(-) delete mode 100644 application/modules/admin/views/scripts/search/detail.phtml delete mode 100644 application/modules/admin/views/scripts/search/force-https.phtml delete mode 100644 application/modules/admin/views/scripts/urls/list.phtml delete mode 100644 library/Class/ContentTextReplacement.php diff --git a/application/modules/admin/controllers/AjaxController.php b/application/modules/admin/controllers/AjaxController.php index a7db2083487..871f9690825 100644 --- a/application/modules/admin/controllers/AjaxController.php +++ b/application/modules/admin/controllers/AjaxController.php @@ -63,50 +63,4 @@ class Admin_AjaxController extends Zend_Controller_Action { if (isset($autohrities[$code])) return $authorities[$code]; } - - - public function testUrlAction() { - session_write_close(); - - if (!$url = $this->_getParam('url')) - return; - return $this->_checkUrl($url); - } - - - public function testUrlHttpsAction() { - session_write_close(); - - if (!$url = $this->_getParam('url')) - return; - str_replace('http://','https://',$url); - return $this->_checkUrl($url); - - } - - public function forceHttpsAction() { - session_write_close(); - - if (!($url = $this->_getParam('url')) && strlen($url) <10) - $this->redirect(); - - (new Class_ContentTextReplacement())->transformUrlToHttps(urldecode($url)); - return $url; - $this->_redirect($this->view->url(['module' => 'admin', - 'controller' => 'search', - 'action' => 'list'])); - } - - - protected function _checkUrl($url) { - $file_headers = @get_headers($url); - if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') { - $html= 'erreur'; - echo '<div class="error">ERREUR</div>'; - return ; - - } - echo '<div class="ok">OK</div>'; - } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/application/modules/admin/controllers/UrlManagerController.php b/application/modules/admin/controllers/UrlManagerController.php index d16b8f50a99..37153c718bd 100644 --- a/application/modules/admin/controllers/UrlManagerController.php +++ b/application/modules/admin/controllers/UrlManagerController.php @@ -125,25 +125,6 @@ class Admin_UrlManagerController extends ZendAfi_Controller_Action { } - public function httpAction() { - $this->view->search = $this->_getParam('http'); - $this->_redirect('admin/url-manager/list/term/http'); - } - - - public function findAction() { - if ($this->_request->isPost() - && ($term=$this->_getParam('term','http'))) - $this->_redirect('admin/url-manager/list/term/'.$term); - } - - - public function baseAction() { - $this->_redirect('admin/url-manager/list/term/http'); - } - - - protected function _searchForm() { return (new ZendAfi_Form()) ->setAction(Class_Url::absolute(['module' => 'admin', @@ -174,6 +155,7 @@ class Admin_UrlManagerController extends ZendAfi_Controller_Action { } + protected function _getEditUrlForm() { return (new ZendAfi_Form()) @@ -185,7 +167,4 @@ class Admin_UrlManagerController extends ZendAfi_Controller_Action { 'placeholder' => 'https']) ->addUniqDisplayGroup('change'); } - - -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/application/modules/admin/views/scripts/search/detail.phtml b/application/modules/admin/views/scripts/search/detail.phtml deleted file mode 100644 index 9078a854b7a..00000000000 --- a/application/modules/admin/views/scripts/search/detail.phtml +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -echo 'URL:'.$this->search.'<BR/>'; -$description = (new Class_TableDescription('articles')) -->addColumn($this->_('Titre'), function($article) - { return $this->tagAnchor($this->url(['module' => 'admin', - 'controller' => 'cms', - 'action' => 'edit', - 'id' => $article->getId()],null,true), - $article->getTitre()) - ;}); - -echo $this->tag('div', $this->renderTable($description, - $this->articles - )); - - - -?> diff --git a/application/modules/admin/views/scripts/search/force-https.phtml b/application/modules/admin/views/scripts/search/force-https.phtml deleted file mode 100644 index 97cb534dc8c..00000000000 --- a/application/modules/admin/views/scripts/search/force-https.phtml +++ /dev/null @@ -1,3 +0,0 @@ -<? -echo 'toto'; -?> diff --git a/application/modules/admin/views/scripts/urls/list.phtml b/application/modules/admin/views/scripts/urls/list.phtml deleted file mode 100644 index a6f1570991d..00000000000 --- a/application/modules/admin/views/scripts/urls/list.phtml +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -$articles = Class_Article::findAllBy(['where' => 'concat(description,contenu) like "%'. $this->search .'%"']); - -foreach ($articles as $article) -var_dump($article->getContenu()); -?> diff --git a/library/Class/ContentTextReplacement.php b/library/Class/ContentTextReplacement.php deleted file mode 100644 index 18799e87755..00000000000 --- a/library/Class/ContentTextReplacement.php +++ /dev/null @@ -1,161 +0,0 @@ -<?php -/** - * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. - * - * BOKEH is free software; you can redistribute it and/or modify - * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by - * the Free Software Foundation. - * - * There are special exceptions to the terms and conditions of the AGPL as it - * is applied to this software (see README file). - * - * BOKEH is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE - * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -class Class_ContentTextReplacement { - public function transformUrlToHttps($url) { - $this->replaceText($url,$this->_getHttps($url)); - } - - - public function replaceText($old_text,$new_text) { - (new Class_ArticleReplacement())->replaceTextTo($old_text,$new_text); - } - - - public function getArticles($text) { - return (new Class_ArticleReplacement())->findAll($text); - } - - - public function findAllUrls($http, $preg) { - $urls = []; - $urls = (new Class_ArticleReplacement())->mergeUrl($http, $preg, $urls); - $urls = (new Class_NewsletterReplacement())->mergeUrl($http, $preg, $urls); - $urls = (new Class_DomainsReplacement())->mergeUrl($http, $preg, $urls); - - return $urls; - } - - protected function mergeUrls($matches,$urls, $text) { - foreach($matches as $match) { - if (trim($match[0]) == ''|| (strpos($match[0], $text)===false)) - continue; - if (isset($urls[$match[0]])) - $urls[$match[0]]=$urls[$match[0]]+1; - else $urls[$match[0]]=1; - } - return $urls; - } - - protected function _getHttps($url) { - return str_replace('http://','https://', $url); - } -} - - - - -abstract class Class_ContentReplacement { - public function replaceTextTo($old_text,$new_text) { - foreach ($this->findAll($old_text) as $model) { - $this->_saveModel($model,$old_text,$new_text); - } - } - - protected function mergeUrls($matches,$urls, $text) { - foreach($matches as $match) { - if (trim($match[0]) == ''|| (strpos($match[0], $text)===false)) - continue; - if (isset($urls[$match[0]])) - $urls[$match[0]]=$urls[$match[0]]+1; - else $urls[$match[0]]=1; - } - return $urls; - } - - - abstract protected function _saveModel($model,$old_text,$new_text); -} - - - - -class Class_ArticleReplacement extends Class_ContentReplacement { - protected function _saveModel($article, $old_text,$new_text) { - $article->setContenu(str_ireplace($old_text,$new_text,$article->getContenu())); - $article->setDescription(str_ireplace($old_text,$new_text,$article->getDescription())); - $article->save(); - } - - - public function findAll($text) { - return Class_Article::findAllBy(['where' => 'concat(description,contenu) like "%'. $text .'%"']); - } - - - public function mergeUrl($http, $preg, $urls) { - foreach ( $this->findAll($http) as $article) { - preg_match_all($preg, $article->getContenu(), $matches, PREG_PATTERN_ORDER) ; - $urls =$this->mergeUrls($matches,$urls, $http); - preg_match_all($preg, $article->getDescription(), $matches, PREG_PATTERN_ORDER) ; - $urls =$this->mergeUrls($matches,$urls,$http); - } - return $urls; - } -} - - - - -class Class_NewsletterReplacement extends Class_ContentReplacement { - protected function _saveModel($model, $old_text,$new_text) { - $model->setContenu(str_ireplace($old_text,$new_text,$article->getContenu())); - $model->save(); - } - - public function findAll($text) { - return Class_Newsletter::findAllBy(['where' => 'contenu like "%' . $text . '%"']); - } - - public function mergeUrl($http, $preg, $urls) { - foreach ($this->findAll($http) as $model) { - preg_match_all($preg, $model->getContenu(), $matches, PREG_PATTERN_ORDER) ; - $urls =$this->mergeUrls($matches,$urls, $http); - } - return $urls; - } - -} - - - - -class Class_DomainsReplacement extends Class_ContentReplacement { - protected function _saveModel($model, $old_text,$new_text) { - $model->setUrlImg(str_ireplace($old_text,$new_text,$model->getUrlImg())); - $model->save(); - } - - public function findAll($text) { - return Class_Catalogue::findAllBy(['where' => 'url_img like "%' . $text . '%"']); - } - - public function mergeUrl($http, $preg, $urls) { - foreach ($this->findAll($http) as $model) { - preg_match_all($preg, $model->getUrlImg(), $matches, PREG_PATTERN_ORDER) ; - $urls =$this->mergeUrls($matches,$urls, $http); - - } - return $urls; - } -} -?> \ No newline at end of file diff --git a/library/Class/UrlManager/Article.php b/library/Class/UrlManager/Article.php index 387c2f1876e..8d1fb492341 100644 --- a/library/Class/UrlManager/Article.php +++ b/library/Class/UrlManager/Article.php @@ -21,6 +21,8 @@ class Class_UrlManager_Article extends Class_UrlManager_Abstract { + + public function getData() { if (!$model = $this->getModel()) return ''; @@ -31,7 +33,6 @@ class Class_UrlManager_Article extends Class_UrlManager_Abstract { } - public function replace($url, $by) { if (!$model = $this->getModel()) return false; @@ -42,6 +43,7 @@ class Class_UrlManager_Article extends Class_UrlManager_Abstract { ->save(); } + public function getAdminUrl() { if (!$model = $this->getModel()) return '#'; diff --git a/library/Class/UrlManager/Domain.php b/library/Class/UrlManager/Domain.php index 8ce9f44acbc..207728e654b 100644 --- a/library/Class/UrlManager/Domain.php +++ b/library/Class/UrlManager/Domain.php @@ -21,6 +21,8 @@ class Class_UrlManager_Domain extends Class_UrlManager_Abstract { + + public function getData() { return ($model = $this->getModel()) ? $model->getUrlImg() @@ -47,5 +49,4 @@ class Class_UrlManager_Domain extends Class_UrlManager_Abstract { 'action' => 'edit', 'id_catalogue' => $model->getId()]); } - } diff --git a/library/Class/UrlManager/Newsletter.php b/library/Class/UrlManager/Newsletter.php index 1d6587a9d39..1eacf75f2a5 100644 --- a/library/Class/UrlManager/Newsletter.php +++ b/library/Class/UrlManager/Newsletter.php @@ -21,6 +21,8 @@ class Class_UrlManager_Newsletter extends Class_UrlManager_Abstract { + + public function getData() { return ($model = $this->getModel()) ? $model->getContenu() @@ -47,5 +49,4 @@ class Class_UrlManager_Newsletter extends Class_UrlManager_Abstract { 'action' => 'edit', 'id' => $model->getId()]); } - -} +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/UrlManagerControllerTest.php b/tests/application/modules/admin/controllers/UrlManagerControllerTest.php index 1db4b22da9a..3c5da8aa1a2 100644 --- a/tests/application/modules/admin/controllers/UrlManagerControllerTest.php +++ b/tests/application/modules/admin/controllers/UrlManagerControllerTest.php @@ -251,63 +251,13 @@ class UrlManagerControllerTestUrlActionTest extends UrlManagerTestCase { /** @test */ public function dispatchTestUrlWithHttpMonDomainDotOrgShouldSuccess() { $this->dispatch('/admin/url-manager/test-url/url/' . urlencode('http://mon-domain.org'), true); - $this->assertXPathContentContains('//p', 'Ok'); + $this->assertXPathContentContains('//span', 'Oui'); } /** @test */ public function dispatchTestUrlWithHttpsMonDomainDotOrgShouldSuccess() { $this->dispatch('/admin/url-manager/test-url/url/' . urlencode('https://mon-domain.org'), true); - $this->assertXPathContentContains('//p', 'Ok'); + $this->assertXPathContentContains('//span', 'Oui'); } } - - - -class UrlManagerControllerForceHttpsPostTest extends Admin_AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - public function setUp() { - parent::setUp(); - - ZendAfi_Auth::getInstance() - ->logUser($this->fixture('Class_Users', - ['id' => 6, - 'login' => 'sysadm', - 'password' => 123, - 'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN])); - - $this->fixture('Class_Notice', - ['id' => 123910, - 'alpha_titre' => 'LANGUE NON SPECIFIEE', - 'type_doc' => Class_TypeDoc::ARTICLE]); - - - $this->onLoaderOfModel('Class_Article') - ->whenCalled('findAllBy') - ->answers([$this->fixture('Class_Article',['id' => 4, - 'id_notice' => 123910, - 'auteur' => null, - 'id_lieu' => 3, - 'domaine_ids' => ['11', '12'], - 'id_cat' => 23, - 'langue' => null, - 'titre' => 'Langue non spécifiée', - 'description' => '', - 'contenu' => 'test: http://monurl.fr.', - 'date_creation' => '2010-12-25'])]); - - - - $this->postDispatch('/admin/ajax/force-https/', ['url' => urlencode('http://monurl.fr') - ]); - } - - - /** @test */ - public function urlShouldBecomeHttps() { - $this->assertEquals('test: https://monurl.fr.',Class_Article::find(4)->getContenu()); - } - - -} -- GitLab