Loading


Advertisement:

Author Topic: [SOLVED]I am not able to apply a regex item title  (Read 412 times)

herculesnetwork

  • Newbie
  • *
  • Posts: 17
[SOLVED]I am not able to apply a regex item title
« on: March 19, 2017, 02:32:07 pm »
I've tried it in a lot of different ways:

$item['s_title'] = preg_replace('/my regex', '', $item['s_title']);

$title['s_title'] = preg_replace('/my regex/', '', $title['s_title']);

$title = preg_replace('/my regex/', '', $title);

in public_html/oc-includes/osclass/frm/Item.form.class.php
Code: [Select]
in public_html/oc-includes/osclass/frm/Item.form.class.php
echo '<div class="title">';
                echo '<div><label for="title">' . __('Title') . ' *</label></div>';
                $title = (isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_title'])) ? $item['locale'][$locale['pk_c_code']]['s_title'] : '';
                 $title['s_title'] = preg_replace('/my regex/', ' ',  $title['s_title']);
                if( Session::newInstance()->_getForm('title') != "" ) {
                    $title_ = Session::newInstance()->_getForm('title');
                    if( $title_[$locale['pk_c_code']] != "" ){
                        $title = $title_[$locale['pk_c_code']];

or

Code: [Select]
--------------
or
      if( $title_[$locale['pk_c_code']] != "" ){
                        $title = $title_[$locale['pk_c_code']];
                    }
                }
                self::title_input('title', $locale['pk_c_code'], $title);
                 $title = preg_replace('/my regex/', ' ',  $title);
               
                echo '</div>';

Can someone help me? Thanks all.
« Last Edit: March 20, 2017, 10:07:40 am by herculesnetwork »

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: I am not able to apply a regex item title
« Reply #1 on: March 19, 2017, 03:47:29 pm »
Hi,

In any case, you must work over $title there:

Code: [Select]
$title = (isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_title'])) ? $item['locale'][$locale['pk_c_code']]['s_title'] : '';
$title = preg_replace('/my regex/', ' ', $title);

Have you checked that your regex expression is correct? You can test it here: https://regex101.com/

Regards

herculesnetwork

  • Newbie
  • *
  • Posts: 17
Re: I am not able to apply a regex item title
« Reply #2 on: March 19, 2017, 06:04:00 pm »
Hi Teseo, Thanks very much by reply..
Yes of course, and I have my own regex tester, where I have always done my regex creations, through this, and even because, this code (expression) regex works in other cms of blogs and other non cms sites.

Hi,

In any case, you must work over $title there:

Code: [Select]
$title = (isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_title'])) ? $item['locale'][$locale['pk_c_code']]['s_title'] : '';
$title = preg_replace('/my regex/', ' ', $title);

Have you checked that your regex expression is correct? You can test it here: https://regex101.com/

Regards

herculesnetwork

  • Newbie
  • *
  • Posts: 17
Re: I am not able to apply a regex item title
« Reply #3 on: March 19, 2017, 06:49:09 pm »
This regex I have been using for a long time, on several websites, but I do not know why, I created a php page in the subdirectory of this osclass installation, and I created a text field and subjugated it with all the values that this regex should match, Inside the some vhost of that osclass installation, that is, it is not in that place, in that variable that I must do this.

Hi,

In any case, you must work over $title there:

Code: [Select]
$title = (isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_title'])) ? $item['locale'][$locale['pk_c_code']]['s_title'] : '';
$title = preg_replace('/my regex/', ' ', $title);

Have you checked that your regex expression is correct? You can test it here: https://regex101.com/

Regards
« Last Edit: March 19, 2017, 06:50:43 pm by herculesnetwork »

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: I am not able to apply a regex item title
« Reply #4 on: March 19, 2017, 07:03:13 pm »
???

After this line:

Quote
$title = (isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_title'])) ? $item['locale'][$locale['pk_c_code']]['s_title'] : '';

Before the regex being applied, do you have the title string stored in $title?

herculesnetwork

  • Newbie
  • *
  • Posts: 17
Re: I am not able to apply a regex item title
« Reply #5 on: March 19, 2017, 07:42:06 pm »
Sorry Teseo, But I don't undestand you ask!  do you have the title string stored in $title?
Because this string I hope people insert in $ title at the time of making the srsrsr publications
The people at the time of creating the publications will create these strings.

this variab├žel $tite in /oc-includes/osclass/frm/Item.form.class.php

$title Is not it the one that stores the fields that people fill in when they post ads?!!!!!! :-)

this is my code in attachment

« Last Edit: March 19, 2017, 07:48:44 pm by herculesnetwork »

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: I am not able to apply a regex item title
« Reply #6 on: March 19, 2017, 08:09:27 pm »
$title Is not it the one that stores the fields that people fill in when they post ads?!!!!!! :-)

Yes, but that's the form step (function multilanguage_title_description). On Publish Ad $title will be blank, it will have a value only on Edit Ad. If your goal is to check for forbidden words or something like that, that's not the place to do it.

herculesnetwork

  • Newbie
  • *
  • Posts: 17
Re: I am not able to apply a regex item title
« Reply #7 on: March 19, 2017, 09:42:18 pm »
It was what the US said, this regex is right, we are moving in the wrong variable :-) , and or in the wrong place, so where is the right place?

$title Is not it the one that stores the fields that people fill in when they post ads?!!!!!! :-)

Yes, but that's the form step (function multilanguage_title_description). On Publish Ad $title will be blank, it will have a value only on Edit Ad. If your goal is to check for forbidden words or something like that, that's not the place to do it.

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: I am not able to apply a regex item title
« Reply #8 on: March 19, 2017, 11:04:17 pm »
It should be done once the ad is submitted and about to be stored in the database. Here's a way to do it with no Osclass core modification.

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_filter_title_description($aItem) {
    
$disallow "/myregexexpression/";
    
    foreach(@
$aItem['title'] as $key => $value) {
        
$aItem['title'][$key] = preg_replace($disallow' ',  $value);
    }

    foreach(@
$aItem['description'] as $key => $value) {
        
$aItem['description'][$key] = preg_replace($disallow' ',  $value);
    }
    
    return 
$aItem;
}

osc_add_filter('item_add_prepare_data''cust_filter_title_description');
osc_add_filter('item_edit_prepare_data''cust_filter_title_description');
?>


Regards
« Last Edit: March 19, 2017, 11:06:46 pm by teseo »

herculesnetwork

  • Newbie
  • *
  • Posts: 17
Re: I am not able to apply a regex item title
« Reply #9 on: March 20, 2017, 10:06:22 am »
I'm sorry, I fell asleep..  :-[
Now yes; Worked perfectly; ... That deadpool 2 what, noooo... Teseo - The Hero :-)   :P :D ;D
I always make a separate file with the name of the action, and use include in these cases, I do not know, do you think this is a good practice?
ThankSsss Teseo :-)

It should be done once the ad is submitted and about to be stored in the database. Here's a way to do it with no Osclass core modification.

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_filter_title_description($aItem) {
    
$disallow "/myregexexpression/";
    
    foreach(@
$aItem['title'] as $key => $value) {
        
$aItem['title'][$key] = preg_replace($disallow' ',  $value);
    }

    foreach(@
$aItem['description'] as $key => $value) {
        
$aItem['description'][$key] = preg_replace($disallow' ',  $value);
    }
    
    return 
$aItem;
}

osc_add_filter('item_add_prepare_data''cust_filter_title_description');
osc_add_filter('item_edit_prepare_data''cust_filter_title_description');
?>


Regards
« Last Edit: March 20, 2017, 10:42:27 am by herculesnetwork »

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: I am not able to apply a regex item title
« Reply #10 on: March 20, 2017, 12:44:54 pm »
You're welcome. :)

I always make a separate file with the name of the action, and use include in these cases, I do not know, do you think this is a good practice?

Well, that adds a bit of overhead because possibly a number of additional files must be loaded every time. Another alternative would be to create a custom_functions.php, then it's just a single include if you upgrade the theme.

Regards

herculesnetwork

  • Newbie
  • *
  • Posts: 17
Re: I am not able to apply a regex item title
« Reply #11 on: March 20, 2017, 02:19:48 pm »
Yes I create a file with this exact name to be able to apply security and personalization of logins in WP themes, as well as preset things of the footer and icon so that I do not have to start from scratch every new theme I use, as well as apply any changes, Yes, I do not really repeat this include action :-)
   Thank you so much :-)
You're welcome. :)

I always make a separate file with the name of the action, and use include in these cases, I do not know, do you think this is a good practice?

Well, that adds a bit of overhead because possibly a number of additional files must be loaded every time. Another alternative would be to create a custom_functions.php, then it's just a single include if you upgrade the theme.

Regards