From f43b6081c1d81977e80f917a1cc5ec19f03519d8 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Sun, 13 Jul 2025 11:05:09 +0200 Subject: [PATCH] =?UTF-8?q?Dodaj=20funkcje=20do=20czyszczenia=20tekstu=20o?= =?UTF-8?q?g=C5=82osze=C5=84=20oraz=20aktualizuj=20wywo=C5=82ania=20w=20sz?= =?UTF-8?q?ablonach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/class.S.php | 62 +++++++++++++++++++ .../front/factory/class.GlobelusFirms.php | 4 +- .../globelus/adverts/advert-details.php | 3 +- .../globelus/adverts/last-adverts.php | 4 +- .../globelus/adverts/main-page-adverts.php | 2 +- .../globelus/candidates/adverts-list.php | 2 +- templates_user/globelus/cv/cv-list.php | 2 +- .../globelus/firms/firm-profile.php | 2 +- .../globelus/firms/followed-candidates.php | 2 +- .../globelus/firms/proposed-candidates.php | 2 +- 10 files changed, 74 insertions(+), 11 deletions(-) diff --git a/autoload/class.S.php b/autoload/class.S.php index 38927e0..6ee55f3 100644 --- a/autoload/class.S.php +++ b/autoload/class.S.php @@ -1,6 +1,68 @@ ]*)>/i', + function ($matches) { + $tag = $matches[1]; + $attrs = $matches[2]; + + // Znajdź tylko atrybut "style" + preg_match('/\sstyle\s*=\s*("[^"]*"|\'[^\']*\'|[^"\'>\s]+)/i', $attrs, $styleMatch); + $style = isset($styleMatch[0]) ? ' ' . $styleMatch[0] : ''; + + return "<$tag$style>"; + }, + $html + ); + } + + static public function strip_attributes_except_style_and_clean_font($html) { + return preg_replace_callback( + '/<([a-z0-9]+)([^>]*)>/i', + function ($matches) { + $tag = $matches[1]; + $attrs = $matches[2]; + + // Wyciągnij styl + preg_match('/\sstyle\s*=\s*("[^"]*"|\'[^\']*\'|[^"\'>\s]+)/i', $attrs, $styleMatch); + $style = ''; + + if (isset($styleMatch[1])) { + $rawStyle = trim($styleMatch[1], '\'"'); // bez cudzysłowów + + // usuń font-family (również z fallbackami np. Arial, sans-serif) + $filtered = []; + foreach (explode(';', $rawStyle) as $rule) { + if (stripos(trim($rule), 'font-family') !== 0) { + $filtered[] = trim($rule); + } + } + + if (!empty($filtered)) { + $style = ' style="' . implode('; ', $filtered) . '"'; + } + } + + return "<$tag$style>"; + }, + $html + ); + } + + static public function clear_advert_text( $text ) + { + $text = preg_replace('#]*>.*?#is', '', $text); + $text = preg_replace('#]*>.*?#is', '', $text); + $text = preg_replace('/on\w+="[^"]*"/i', '', $text); + $text = preg_replace("/on\w+='[^']*'/i", '', $text); + $text = preg_replace('/(href|src)\s*=\s*["\']\s*javascript:[^"\']*["\']/i', '', $text); + $text = self::strip_attributes_except_style($text); + $text = self::strip_attributes_except_style_and_clean_font($text); + return $text; + } + static public function strpos_arr( $haystack, $needle ) { if (!is_array($needle)) $needle = array($needle); diff --git a/autoload/front/factory/class.GlobelusFirms.php b/autoload/front/factory/class.GlobelusFirms.php index 35eea18..a22e3a1 100644 --- a/autoload/front/factory/class.GlobelusFirms.php +++ b/autoload/front/factory/class.GlobelusFirms.php @@ -1067,7 +1067,7 @@ class GlobelusFirms 'id_position' => $id_position ? $id_position : null, 'city' => $values['city'], 'region' => $values['region'], - 'text' => $values['text'], + 'text' => \S::clear_advert_text( $values['text'] ), 'contact_person' => $values['contact_person'], 'email' => $values['email'], 'phone' => $values['phone'], @@ -1104,7 +1104,7 @@ class GlobelusFirms 'id_position' => $id_position ? $id_position : null, 'city' => $values['city'], 'region' => $values['region'], - 'text' => $values['text'], + 'text' => \S::clear_advert_text( $values['text'] ), 'contact_person' => $values['contact_person'], 'email' => $values['email'], 'phone' => $values['phone'], diff --git a/templates_user/globelus/adverts/advert-details.php b/templates_user/globelus/adverts/advert-details.php index 4c7273e..24d1a15 100644 --- a/templates_user/globelus/adverts/advert-details.php +++ b/templates_user/globelus/adverts/advert-details.php @@ -169,7 +169,7 @@ ?>
advert['text']; + $text = $this -> advert['text']; if (!$this->g_user) : $text = preg_replace('/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i', ' Zaloguj się aby zobaczyć adres email ', $text); $text = preg_replace( @@ -178,6 +178,7 @@ $text ); endif; + $text = \S::clear_advert_text( $text ); echo $text; ?>
diff --git a/templates_user/globelus/adverts/last-adverts.php b/templates_user/globelus/adverts/last-adverts.php index 9568239..0bd1125 100644 --- a/templates_user/globelus/adverts/last-adverts.php +++ b/templates_user/globelus/adverts/last-adverts.php @@ -40,9 +40,9 @@ -
+
- ... + ...
diff --git a/templates_user/globelus/adverts/main-page-adverts.php b/templates_user/globelus/adverts/main-page-adverts.php index b0ae503..0bd1125 100644 --- a/templates_user/globelus/adverts/main-page-adverts.php +++ b/templates_user/globelus/adverts/main-page-adverts.php @@ -42,7 +42,7 @@
- ... + ...
diff --git a/templates_user/globelus/candidates/adverts-list.php b/templates_user/globelus/candidates/adverts-list.php index b499bab..7da40c6 100644 --- a/templates_user/globelus/candidates/adverts-list.php +++ b/templates_user/globelus/candidates/adverts-list.php @@ -55,7 +55,7 @@ - | |
- ... + ...
diff --git a/templates_user/globelus/cv/cv-list.php b/templates_user/globelus/cv/cv-list.php index bfb7524..855acc3 100644 --- a/templates_user/globelus/cv/cv-list.php +++ b/templates_user/globelus/cv/cv-list.php @@ -143,7 +143,7 @@ :
- +
diff --git a/templates_user/globelus/firms/firm-profile.php b/templates_user/globelus/firms/firm-profile.php index ce48731..26c9d42 100644 --- a/templates_user/globelus/firms/firm-profile.php +++ b/templates_user/globelus/firms/firm-profile.php @@ -182,7 +182,7 @@ - | |
- ... + ...
diff --git a/templates_user/globelus/firms/followed-candidates.php b/templates_user/globelus/firms/followed-candidates.php index 0c7b71d..e004253 100644 --- a/templates_user/globelus/firms/followed-candidates.php +++ b/templates_user/globelus/firms/followed-candidates.php @@ -43,7 +43,7 @@ | :
- +
diff --git a/templates_user/globelus/firms/proposed-candidates.php b/templates_user/globelus/firms/proposed-candidates.php index 9924790..18d34a2 100644 --- a/templates_user/globelus/firms/proposed-candidates.php +++ b/templates_user/globelus/firms/proposed-candidates.php @@ -69,7 +69,7 @@ :
- +