#StackBounty: #php #javascript #theme-customizer #settings WordPress customizer: load controls in a custom div

Bounty: 100

I have a custom div (holder for extra settings) which I need to load some specific controls from a specific section in there. I can get the controls in JavaScript but I can’t generate the necessary HTML as WordPress do in sections.

wp.customize.section( 'custom_div_1' ).controls();

It gives an array of controls but how to generate the HTML like Site title or Tagline controls in default WordPress section.

This custom div will toggle by the left button Open extra settings.

Screenshot for easier understanding:screenshot

Any help is appreciated.


Get this bounty!!!

#StackBounty: #php #image #math #imagemagick #sequence Determine tile size sequnce

Bounty: 50

please help, i am stuck very seriously, i have following tile values:

$tileheight = "58"; // 100x100  104px   560x560
$tileheight = "36"; // 200x200  104px   560x560
$tileheight = "32"; // 300x300  104px   560х560
$tileheight = "30"; // 400x400  104px   560х560

100×100…400×400 – height and width of generated image inside tile

104px – height of tile

560×560 – height and width that will always outputs (fits in image)

What would be the value – “?” for dimension 500×500? What formula could i use?

$tileheight = "?"; // 500x500 104px   560х560

Here for what result will outputs for 400×400:
400x400

UPDATE:

Here what code i use for conversion:

exec("convert '$image' -resize ".$imgw."x".$imgh."! -quality 100 'proc/res$session.jpg'");

exec("convert '$tile' -resize x".$tileheight." -quality 100 'proc/til$session.jpg'");

exec("convert $image $pp -write mpr:image +delete 
proc/til$session.jpg -write mpr:edge_top +delete 
proc/til$session.jpg -write mpr:edge_btm +delete 

mpr:image -alpha set -bordercolor none 
-compose Dst -frame ".$tileheight."x".$tileheight."+".$tileheight." -compose over 

-transverse  -tile mpr:edge_btm 
-draw 'color 1,0 floodfill' -transpose -draw 'color 1,0 floodfill' 
-transverse  -tile mpr:edge_top 
-draw 'color 1,0 floodfill' -transpose -draw 'color 1,0 floodfill' 

mpr:image -gravity center -composite proc/ok$session.jpg");

$input = "proc/ok$session.jpg";
$toWidth  = "840";
$toHeight = "560";
$quality  = "100";
// -background white -gravity center -extent {$toWidth}x{$toHeight}
exec("convert $input -thumbnail {$toWidth}x{$toHeight} proc/ok$session.jpg");

Here what formula i use to make correct tile height:

$tiledata = getimagesize($tile);

$tilewidth = $tiledata[0];
$tileheight = $tiledata[1];

$math1 = ($tileheight+$tileheight)/($imgw+$imgh);
$tileheight = $tileheight * $math1;


Get this bounty!!!

#StackBounty: #php #wordpress #wpml Unable to translate one custom post type slug in WPML

Bounty: 50

I have raised this issue on the WPML forums, but hoping someone here will be able to assist.

I am trying to translate the slug for a custom post type

The English URL is http://brigade-electronics.com/nl/products/backeye360/

The translated URL should be http://brigade-electronics.com/nl/producten/backeye360/

Instead I get a 404 error when navigating to the URL after enabling the translate slug option

Steps to duplicate the issue:

  • Click On WPML -> Translation options
  • Enable the Translate custom posts slugs (via WPML String Translation).
  • Under the Custom posts settings (on the same page) Click the translate checkbox
  • Added the translated slug for each language
  • Hit save
  • Navigate to the front end and see a 404 error on the products section only.

I have run all options in the troubleshooting page, to clear up the database.

This only seems to apply to certain pages within the product section. The weirdest part of this is the Canadian section of the site, as the term ‘product’ is in English therefore the URLs remain the same with or without the translated slugs in place, however, I still get the 404 error on these pages.

It is also worth noting that all other custom post types work without issue.

The custom post types have been registered in the standard way

function register_products_post_type() {

    $labels = array(
        'name' => __( 'Products', '' ),
        'singular_name' => __( 'Product', '' )
    );

    $args = array(
        'label' => __( 'Products', '' ),
        'labels' => $labels,
        'description' => '',
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_rest' => false,
        'rest_base' => '',
        'has_archive' => false,
        'show_in_menu' => true,
        'exclude_from_search' => false,
        'capability_type' => 'post',
        'map_meta_cap' => true,
        'hierarchical' => true,
        'rewrite' => array( 'slug' => 'products', 'with_front' => false ),
        'query_var' => true,
        'menu_position' => 6,
        'menu_icon' => 'dashicons-cart',
        'supports' => array( 'title', 'thumbnail', 'page-attributes' )
    );

    register_post_type( 'products', $args );

}
add_action( 'init', 'register_products_post_type' );

Thanks


Get this bounty!!!

#StackBounty: #php #filter #laravel-4 #model How to filter all quires result in laravel 4.2 app by year

Bounty: 50

I want to add filter for all application quires to get result by specific year

I put current year on session

for example :

public function postLogin()
{
    Session::put('currentYear', date("Y"));
}

and I have many controllers on my app now I want any model query result filter by session year => Session::get(‘currentYear’)

I have a lot of models for example I have one route to view all users, teachers , students`

public function getList()
{
    $data['students'] = User::where('group_id', '=', 4)->get();

    return View::make('students.list', $data);
}

Can I put __construct in BaseControler to filter all app quires by Session::get(‘currentYear’)?


Get this bounty!!!

#StackBounty: #php #apache #caching #xampp How to disable Apache caching in Apache-XAMPP?

Bounty: 50

I am having this weird problem with my XAMPP-Apache.
I am making an log-in system where form is posted to redirect.php page.
I updated the redirect.php and but still it is showing me the same old result.
There is not even a single line to redirect(header fn call) it to another page but still it redirects to home.php page as it was doing in older script.
I tried clearing cache of my browser and changing the browser for testing but didn’t work…I even tried rebooting the server but no change.
Please help me through….


Get this bounty!!!

#StackBounty: #php #laravel #redis #laravel-5.4 #laravel-echo Laravel Echo never recieving event

Bounty: 50

For whatever reason, I cannot receive any data on my client side from laravel echo. I am using laravel-echo-server (socket.io), redis broadcaster, and redis queues. As far as I can tell, they are all functional. I’ll take you through how I set it up for testing. First I created a UserCreated event:

class UserCreated implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;

    public function __construct($user)
    {
        $this->user = $user;
    }

    public function broadcastOn()
    {
        return new Channel('user-created');
    }

    public function broadcastAs()
    {
        return 'user.created';
    }
}

Then, to test this event, I created a CreateUser command:

class CreateUser extends Command
{
    protected $signature = 'create:user {username}';

    protected $description = 'Create a new user!';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $user = ChatterUser::create([
            'name' => $this->argument('username'),
            'email' => uniqid() . '@gmail.com',
            'password' => bcrypt('secret')
        ]);
        event(new ChatterEventsUserCreated($user));
    }
}

Finally, here is my laravel-echo-server.json:

{
    "authEndpoint": "/broadcasting/auth",
    "authHost": "chatter.dev",
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": "6379",
            "host": "localhost"
        }
    },
    "port": 6001,
    "protocol": "http",
    "sslCertPath": "",
    "sslKeyPath": "",
    "socketio": {}
}

Next I ran php artisan queue:listen, and laravel-echo-server start. They both ran without error.
To make sure that the server worked, I did php artisan create:user Bob123.
It was successful. The queue returned this (in console):

[2017-06-01 01:28:27] Processing: ChatterEventsUserCreated
[2017-06-01 01:28:27] Processed:  ChatterEventsUserCreated

And the laravel-echo-server returned this (in console):

CHANNEL user-created

So, to get the data I sent with the user, I created a Vue component, with a echo listener in the mounted function. Here’s my component:

<template>
    
</div> </template> export default { mounted() { console.log('Component mounted.'); window.Echo.channel('user-created') .listen('.user.created', (data) => { console.log(data); }); }, data(){ return { messages: [] } } }

When I refreshed my webpage, Component mounted was logged to the console so I’m certain that it loaded. But, for whatever reason, when I send the CreateUser command, the data is not logged into the browsers console.

Here is everything that you might point out:

I changed my broadcast driver to redis in my .env

BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=redis

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

I also uncommented the BroadcastingServiceProvider in the app.php config.

I can’t think of anything else right now that you might point out that I have done, but if I remember any others I will update the question.

Thanks for any help.

Note: I’m not familiar with Redis, so currently I’m leaning towards that being my problem. Simply adding predispredis as a dependency simply doesn’t feel like that’s all I have to do. Hopefully this note helps.

Edit:

As suggested, I tried running redis-server before I ran laravel-echo-server. This is what was returned in the console:

vagrant@homestead:~/Code/Chatter$ redis-server
16342:C 01 Jun 05:45:38.066 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
16342:M 01 Jun 05:45:38.067 * Increased maximum number of open files to 10032 (it was originally set to 1024).
16342:M 01 Jun 05:45:38.067 # Creating Server TCP listening socket *:6379: bind: Address already in use

I assume this means that the redis server was running, so I guess homestead starts it automatically by default.


Get this bounty!!!

#StackBounty: #mysql #php #mariadb #deadlock Why are my deadlocks not shown by SHOW ENGINE INNODB STATUS;?

Bounty: 50

I have a MariaDB (5.5.41) cluster made of 2 nodes configured as master-slave. All reads and writes are sent to the same node.

I have been investigating some deadlock issues for a few weeks.

On a regular basis, my PHP application returns Message: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction.

I used to be able to run SHOW ENGINE INNODB STATUS; and would see that last deadlock, but for some reason, after a small irrelevant configuration change (changing innodb_buffer_pool_instances from 1 to 19), and a reboot of both nodes, doing a SHOW ENGINE INNODB STATUS; will not show any deadlock.

However, if I connect with my mysql client and manually create transactions resulting in a deadlock, the status command does show the deadlock.

I tried playing innodb_print_all_deadlocks ON and OFF. Nothing shows in the mysql-error.log, except for my manually triggered deadlock.

Why are the deadlocks created by my PHP application not showing anymore?


Get this bounty!!!

#StackBounty: #javascript #php #file-upload #dropzone.js Cannot send more than 4 files with dropzone

Bounty: 100

This is weird…

I can send 0, 1, 2, 3, 4 files with dropzone but cannot send 5 or more..

I suppose I am correctly defining the options here:

Dropzone.options.myDropzone = {
    url: "action.php",
    autoProcessQueue: false,
    uploadMultiple: true,
    parallelUploads: 6,
    maxFilesize: 5, 
    maxFiles: 6,
    addRemoveLinks: true,
    paramName: 'userfile',
    acceptedFiles: 'image/*',
    dictMaxFilesExceeded: 'Too many files! Maximum is {{maxFiles}}',

    // The setting up of the dropzone
    init: function() {
        dzClosure = this; // Makes sure that 'this' is understood inside the functions below.
        // for Dropzone to process the queue (instead of default form behavior):
        document.getElementById("submit-form").addEventListener("click", function(e) {
            e.preventDefault();
            e.stopPropagation();
            // Make sure that the form isn't actually being sent.
            // If the user has selected at least one file, AJAX them over.
            if (dzClosure.files.length !== 0) {
                // dzClosure.options.autoProcessQueue = true;
                dzClosure.processQueue();
            // Else just submit the form and move on.
            } else {
                $('#foorm').submit();
            }
        });
        // send all the form data along with the files:
        this.on("sendingmultiple", function(data, xhr, formData) {
            formData.append("name", $("#name").val());
            formData.append("email", $("#email").val());
        }); 
        this.on("sucessmultiple", function(files, response) {
            // dzClosure.options.autoProcessQueue = false;
            $(location).attr('href', 'message_sent.html')
        });
    }
}

I say correctly because when I drag more than 6 files I see the error message: Too many files! Maximum is 6

Does this boundary make any sense in the source code?

Some more details:
a simplified version of my form is as follows

<form id="foorm" method="post" action="action.php" enctype="multipart/form-data">
    <input type="text" id="name" name="name" required>
    <input type="email" id="email" name="email" required>
    <div class="dropzone" id="myDropzone">
    <button type="submit" name="submit-form" id="submit-form">Send!</button>
</form>

and my action.php starts with displaying json_encode($_FILES); and json_encode($_POST);

and they are as expected when sending less than 4 files and are [] when sending 5 or more

EDIT

It seems that I can upload 5 or more if they are smaller in size! Can this be anything else than a bug on dropzone? (honest question)


Get this bounty!!!

#StackBounty: #php #laravel #csrf Laravel enable csrf protection on api middleware

Bounty: 50

I’m on Laravel 5.4 and my routes are in the api middleware

I see that I need to transfer my routes to the web middleware, but I need them to be on the api middleware since I’m creating a restful api, any suggestions on how I could force csrf protection?


Get this bounty!!!

#StackBounty: #magento-1.9 #php #csv #inventory #import-script Multiple Inventory slots for Different warehouses

Bounty: 50

I have found a great script that allows for quick inventory updating via a php script, and it does work well. I am able to just go by SKU, quantity, and set each as is_in_stock.

My question then becomes, we have two main warehouses, call them Main and West, would it be possibly to add a secondary inventory slot to each product, and via the same script with few adjustments, be able to upload two different values for each warehouse?

Implementation of the display would be simple enough as currently it is just:

<?php 
$qty = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if ($qty<=0) { ?>

//Backordered

<?php } else { ?>    

//Echo Quantity
<?php echo $qty; } ?>

<?php endif; ?>

And adding another slot could turn into (what I assume) just $qty_secondary with similar loading format.


As a side note, I see the work it goes through with each product, is it as optimized as it could be? It was created back in 2010, and I imagine a lot of things have changed since then and it could be changed for the better I’m sure.


System: Magento 1.9.0.1 & PHP 5.6


Get this bounty!!!