php – In which layer should I load views on a Clean(ish) architecture?

I am trying to organize my architecture following the clean architecture while using some commom practices/frameworks. I’m writing in PHP, but have no problem with other languages. The flow of my app is somewhat like this:

1 – I got a front controller/bootstrapper which instantiates an App object.

2 – Inside de App I’ve got a router,which instantiates a Controller and then it calls an Action method.

3 – Controller Action gets a Use Case object as parameter using DI and returns raw data: boolean, string, array or whatever.

My doubt is: Where should I go from here? I have to build a (Psr) Reponse (loading views, redirecting or whatever) and send it to browser. Where this kind of logic should reside? Let’s say I have a common User Crud: A list of users is shown on screen and there’s a “Create User” Button, which links to a Create User form. If validation fails on this form, the form is shown again showing why it was rejected. If everything is ok, then the user is redirected to the “Users list” again. After I execute the Use Case on controller, should I test the return and build the Response(render views and/or call redirect to other screen or print a json if it’s an api method) right in the Controller Action? It just seems wrong. I have read a lot of stuff about SOLID, Clean Architecture, Separation of Concerns and good practices and I truly could not find anything addressing this kind of thing. I appreciate if someone can shed some light on my thoughts. I also apologize for this long post and for possible grammar errors, because English is not my native language.

php – register_setting & add_settings_error validation issues with multiple fields

I’ve been trying to use the Settings API for the first time. I managed to piece together a working example but I’m stuck on how to make multiple input fields required. Right now I have an admin notice displaying but it displays for each field, so if I have 3 fields it displays 3 times. How do I make this work with multiple fields?

Register the fields…

function my_settings_init() {
    
    add_settings_section(
        'my_custom_setting_section',
        'Text for the page',
        'my_custom_setting_section_callback',
        'my-settings'
    );

        add_settings_field(
            'field-1',
            'Field 1',
            'my_settings_step1_markup',
            'my-settings',
            'my_custom_setting_section'
        );

        register_setting('my-settings', 'field-1', 'my_settings_settings_validation');
    
        add_settings_field(
            'field-2',
            '<span class="my-settings-step">Step 2</span>',
            'my_settings_step2_markup',
            'my-settings',
            'my_custom_setting_section'
        );

        register_setting('my-settings', 'field-2', 'my_settings_settings_validation');
    
        ... More fields below
}

add_action('admin_init', 'my_settings_init');

My validation callback so far…

function my_settings_settings_validation($input){
    
    $message = null;
    $type = null;
    
    if (null != $input) {
        if (false === get_option('my-settings')) {
            add_option('my-settings', $input);
            $message = __('Option added!');
            $type = 'updated';
        } else {
            update_option('my-settings', $input);
            $message = __('Option updated!');
            $type = 'updated';
        }
    }else{
        $message = __('There was a problem.');
        $type = 'error';
    }
    
    add_settings_error('my_option_notice', 'my_option_notice', $message, $type);
    
    return $input;
}

Any help would be great as I am clearly missing something!

php – Open image in its full size

I have this code and I’m trying to make the existing image (300×300) to open in full size when clicking it. Can you please point me to the right direction please?

Thanks in advance!

<?php
defined( 'ABSPATH' ) || exit;

$style = $el_class = $items = $heading = '';

$atts   = vc_map_get_attributes( $this->getShortcode(), $atts );
$css_id = uniqid( 'tm-restaurant-menu-' );
$this->get_inline_css( "https://wordpress.stackexchange.com/#" . $css_id, $atts );
extract( $atts );

$items = (array) vc_param_group_parse_atts( $items );
if ( count( $items ) < 1 ) {
    return;
}

$el_class  = $this->getExtraClass( $el_class );
$css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'tm-restaurant-menu ' . $el_class, $this->settings('base'), $atts );
$css_class .= " style-$style";
?>

<div class="<?php echo esc_attr( trim( $css_class ) ); ?>" id="<?php echo esc_attr( $css_id ); ?>">
    <ul class="menu-list">
        <?php
        foreach ( $items as $item ) {
            ?>
            <li class="menu-item">
                <?php if ( isset( $item('image') ) ) : ?>
                    <div class="image">
                        <?php
                        Retrolie_Image::the_attachment_by_id( array(
                            'id'     => $item('image'),
                            'size'   => 'custom',
                            'width'  => 300,
                            'height' => 300,
                        ) );
                        ?>
                    </div>
                <?php endif; ?>

                <div class="menu-info">
                    <div class="menu-header">
                        <?php if ( isset( $item('title') ) ) : ?>
                            <h5 class="menu-title"><?php echo esc_html( $item('title') ); ?></h5>
                        <?php endif; ?>

                        <?php if ( isset( $item('badge') ) && $item('badge') !== '' ): ?>
                            <div
                                class="menu-badge <?php echo esc_attr( $item('badge') ); ?>"><?php esc_html_e( 'New', 'retrolie' ); ?></div>
                        <?php endif; ?>
                    </div>

                    <?php if ( isset( $item('text') ) ) : ?>
                        <div class="menu-text"><?php echo esc_html( $item('text') ); ?></div>
                    <?php endif; ?>

                    <?php if ( isset( $item('price') ) ) : ?>
                        <div class="menu-price"><?php echo esc_html( $item('price') ); ?></div>
                    <?php endif; ?>
                </div>
            </li>
        <?php } ?>
    </ul>
</div>

php – Creating multiple tables with Plugin

I opened a new question, just to be sure. The former request has partly been resolved.
I got another question regarding creating tables for wordpress: Only one table is created (The first one), but the others not. Does somebody know why?

My Code now looks like this:

function artok_activate(){
    global $wpdb;
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    $charset_collate                = $wpdb->get_charset_collate();
    $table_Veranstaltung            = $wpdb->prefix . 'Veranstaltung';
    $table_Personen                 = $wpdb->prefix . 'Personen';
    $table_Sponsor                  = $wpdb->prefix . 'Sponsor';
    $table_SponKunde                = $wpdb->prefix . 'SponKunde';
    
    if( $wpdb->get_var( "SHOW TABLES LIKE '$table_Veranstaltung'" ) != $table_Veranstaltung ) {
        $tableVer_Crea = 'CREATE TABLE ' . $table_Veranstaltung . '(
        ver_id int(11) NOT NULL AUTO_INCREMENT, 
        VeranstaltungName varchar(255), 
        PRIMARY KEY  (ver_id)
        )' . $charset_collate . ';';
        dbDelta( $tableVer_Crea );
        $success = empty($wpdb->last_error);
        
        return $success;
    }
    
    if( $wpdb->get_var( "SHOW TABLES LIKE '$table_Personen'" ) != $table_Personen ) {
        $tablePers_Crea = "CREATE TABLE " . $table_Personen . "(
        pers_id int(11) NOT NULL AUTO_INCREMENT, 
        Datum DATE, 
        Passwort varchar(255) UNIQUE, 
        Vorname varchar(255), 
        Nachname varchar(255), 
        Anrede varchar(255), 
        LoeschDatum DATE, 
        fkVer_id int(11), 
        FOREIGN KEY(fkVer_id) REFERENCES wp_Veranstaltung(Ver_id), 
        PRIMARY KEY  (pers_id)
        )" . $charset_collate . ";";
        
        dbDelta($tablePers_Crea);
        
        $success = empty($wpdb->last_error);
        
        return $success;
    }
    
    if( $wpdb->get_var( "SHOW TABLES LIKE '$table_Sponsor'" ) != $table_Sponsor) {
        $tableSp_Crea = "CREATE TABLE " . $table_Sponsor . "(
        sp_id int(11) NOT NULL AUTO_INCREMENT, 
        Code varchar(255), 
        Name varchar(255), 
        PRIMARY KEY  (sp_id)
        )" . $charset_collate . ";";
        dbDelta( $tableSp_Crea );
        $success = empty($wpdb->last_error);
        
        return $success;
    }
    
    if( $wpdb->get_var( "SHOW TABLES LIKE '$table_SponKunde'" ) != $table_SponKunde ) {
        $tableSpKu_Crea = "CREATE TABLE " . $table_SponKunde . "(
        fkPers_id int(11), 
        fkSp_id int(11), 
        FOREIGN KEY(fkPers_id) REFERENCES wp_Personen(pers_id), 
        FOREIGN KEY(fkSp_id) REFERENCES wp_Sponsor(sp_id)
        )" . $charset_collate . ";";
        dbDelta( $tableSpKu_Crea );
        $success = empty($wpdb->last_error);
        
        return $success;
    }
}   
    register_activation_hook( __FILE__, 'artok_activate' );

Where to add my PHP codes for AJAX Jquery to work?

I am trying to display state’s names responsively based on what country is selected from a list (via a library).

I reckon I needed to use WP AJAX and Jquery to achieve this goal. I am totally new to WP AJAX and Jquery. For the past two days, I have been reading blogs and forums to achieve the responsiveness. Here I came across two files to add my PHP code snippets which are functions.php AND plugin files.

Question: Should I add the PHP code snippets in themes/functions.php OR plugins/MYPLUGIN/myplugin.php or either one? Why?

Two instances of the blogs I’ve read:

php – Hide out of stock only from shop page, not single product variations

So I currently have a shop that uses different variations of products as the sizes.

I have added some code that “greys out” any variations that are out of stock in the drop down on my single products page, as I’d like people to be able to see what sizes may be back in stock soon etc.

There are some single products completely out of stock so I’d like these to be hidden on the shop page, there is an option in WooCommerce but enabling this also hides the out of stock variations on the single product page, which I don’t want to do.

Any ideas how this can be achieved?

Como reproduzir método de criptografia em C# em PHP?

tenho esse método em C# que é usado para criptografar senhas. Preciso passar ele para PHP pra conseguir usar no meu sistema. Será que consigo fazer isso? Desde já obrigado.

    public static string HashPassword(string password)
    {
        byte() salt;
        byte() buffer2;
        if (password == null)
        {
            throw new ArgumentNullException("password");
        }
        using (Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(password, 0x10, 0x3e8))
        {
            salt = bytes.Salt;
            buffer2 = bytes.GetBytes(0x20);
        }
        byte() dst = new byte(0x31);
        Buffer.BlockCopy(salt, 0, dst, 1, 0x10);
        Buffer.BlockCopy(buffer2, 0, dst, 0x11, 0x20);
        return Convert.ToBase64String(dst);
    }

decimales en php mysql html

hola buenos días estoy desarrollando un sistema y tengo un problema ala hora de querer ingresar una cantidad no detecta los decimales en el código y no multiplica con un precio llamado desde otra tabla.
les agradecería mucho su ayuda.

les comparto mi codigo:

function listarDetalles(){

$('#listMpriDproducto').html('');



var filas = "";

var subtotal = 0;

var total = 0;

var subtotalFinal = 0;

var totalFinal = 0;






  

 for(var i=0; i<detalles.length; i++) {
if( detalles(i).estado == 1 ) {

  var importe = detalles(i).importe = detalles(i).cantidad * detalles(i).precio;
    
    importe = detalles(i).importe = detalles(i).importe ;
  var filas = filas + 
  "<tr><td>"+(i+1)+"</td> <td name='materiales()'>"+detalles(i).materiales+
  "</td>  <td name='unidadm()'>"+detalles(i).unidadm+
  "</td> <td name='precio()' id='precio()'>"+detalles(i).moneda+" "+detalles(i).precio+
  "</td> <td>"+detalles(i).stock+
  "</td> <td><input type='float' name='cantidad()' id='cantidad()'  onClick='setCantidad(event, this, "+(i)+");' onKeyUp='setCantidad(event, this, "+(i)+");' value='"+detalles(i).cantidad+
  "'></td><td> <span name='importe()' id='importe"+i+"'>"+detalles(i).moneda+" "+detalles(i).importe+
  "</span> </td> <td>  <button href="https://stackoverflow.com/#" class='btn btn-danger btn-lg' role='button' onClick='eliminarMpri(event, "+(i)+");' aria-pressed='true'><span class='glyphicon glyphicon-trash'></span> </button></td> </tr>";
  subtotal = subtotal + importe;


    //concatenar para poner la moneda con el subtotal
        subtotalFinal = detalles(i).moneda+" "+subtotal;

  var su = subtotal;
        var or=parseFloat(su);
        var total= Math.round(or+subtotal);


        //concatenar para poner la moneda con el total
        totalFinal = detalles(i).moneda+" "+total;

      

}

}

Buying – UK based php programmer

Hi,
SEMrush

I am looking for a UK based programmer to come in with me on a business idea. There is some money to put into this, but having been over promised and under delivered by a few people in the past on different projects I want someone who is prepared to work with me on this.

I do not want to go in to details at this stage, but I want to create a website that is ultimately a form that cross references with a database to provide a list of products in the financial services industry – there is obviously more to it than that (registrations, API integrations in time, payment processing down the line), but it gives a very broad outline of what is needed.

I have worked in financial services for about 15 years, I run my own business which has been trading since 2013 as a sole trader and then 2016 as a limited company – in essence you can vet my business and credentials on companies house and the FCA register.

I have everything in place to get the venture earning money once this is done, we have insurance we are regulated by the FCA, we have the agreements with the banks etc. But it must be someone in the UK.

Thank you.

 

php – Notice: unserialize error

I am using an old unsupported module which gives an error since update to magento 2.2.11.

Notice: unserialize error at offset 0 of 3150 bytes on line 81.

    protected function getUserExtra()
    {
        if (!$this->_adminSession->getUser())
            return ();
        $extra = $this->_adminSession->getUser()->getExtra();
        if (is_string($extra))
            **$extra = unserialize($extra);**
        if (!is_array($extra))
            $extra = ();
        if (!isset($extra('barcodeinventory')))
            $extra('barcodeinventory') = ();
        return $extra;
    }

I have changed it to new json way of unserializing but that also gives an error.

        protected $serialize;
    
    public function __construct(
        MagentoFrameworkSerializeSerializerJson $serialize,
    ) {
        $this->serialize = $serialize;
    }

protected function getUserExtra()
    {
        if (!$this->_adminSession->getUser())
            return ();
        $extra = $this->_adminSession->getUser()->getExtra();
        if (is_string($extra))
            $extra = $this->serialize->unserialize($extra);
        if (!is_array($extra))
            $extra = ();
        if (!isset($extra('barcodeinventory')))
            $extra('barcodeinventory') = ();
        return $extra;
    }

New error: Fatal error: Uncaught TypeError: Argument 4 passed to ModelRegistry::__construct() must implement interface MagentoFrameworkSerializeSerializerInterface