Skip to content
Snippets Groups Projects
Commit b8be00fd authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #79082 : fix rt comments

parent 2457b325
Branches
Tags
6 merge requests!2890Master,!2889Master,!2888Master,!2887Master,!2878Dev#79082 explo amelioration du force https,!2873Dev#79082 explo amelioration du force https
Pipeline #5257 failed with stage
in 28 minutes and 38 seconds
......@@ -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
......@@ -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
<?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
));
?>
<?
echo 'toto';
?>
<?php
$articles = Class_Article::findAllBy(['where' => 'concat(description,contenu) like "%'. $this->search .'%"']);
foreach ($articles as $article)
var_dump($article->getContenu());
?>
<?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
......@@ -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 '#';
......
......@@ -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()]);
}
}
......@@ -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
......@@ -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());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment