Google Books Preview Woocommerce snippet

I am trying to insert a Google Books Preview pop-up on Woocommerce product pages. The code Google provide is:

<script type="text/javascript" src="//books.google.com/books/previewlib.js"></script>
<script type="text/javascript">
GBS_insertPreviewButtonPopup('ISBN:XXXXXXXXXXX');
</script>

This code embeds a button which when clicked will open a pop-up preview of the relevant book. XXXXXXXXXXX has to be replaced with the product SKU, all of which are book ISBN numbers on this site. The placement would use a hook such as woocommerce_product_meta_end or woocommerce_after_single_product_summary.

I’ve tried creating a Code Snippet by adapting answers given in previous requests, but none of them seem to aim to just embed this button (there is one request for a shortcode – that is not what I need). And my attempts to use php to echo the sku in place of XXXXXXXXXXX have failed as my coding ability is limited.

Can anybody suggest how to achieve what I want?

How to create a mondial relay label with symfony 5?

I need help pls!!

I would like to set up the relay point delivery service with Mondial Relay.

Only in the documentation there are no code elements to make the API call to implement label creation.

Has anyone any idea of how to implement it with php symfony 5??

Managing timeouts for Nginx and PHP

I would like the default timeout for my API to be 60 seconds. But for some endpoints I would like the flexibility to add a few seconds to the timeout duration.

I can do this in PHP like so – ini_set('max_execution_time', '120');.

So to achieve this I want to set Nginx timeout to 300 seconds (5 minutes) and as mentioned the default timeout for PHP to 60 seconds.

I was just wondering whether there are any dangerous downsides to this approach.

WordPress Custom Theme nth Post

I am just learning custom WordPress theme creation and I can’t find answers to some questions.

— I want to create a blog theme. There will be a carousel. How can I choose (for example) the first 4 posts for this carousel? And after them, the “latest posts” loop will start after 4th post.

I’ve found only the loop which is shown next;

<?php 
   if ( have_posts() ) : 
   while ( have_posts() ) : the_post(); 
    // Display post content
   endwhile; endif; 
?>

After selecting one person, selected person must dissappear from options

In the group table I select a person from the list, but after selecting one name, his name should not appear in other select options, it must show ‘selected’ or just disappear, so names in groups cant duplicate, 1name=1slot.

In the students list below, there must be a group’s name assigned to a person if he/she is selected.
View for a better understanding

My groups dropdown blade:

<div class="row">
@for ($groupName = 1; $groupName <= $project->amount; $groupName++)
<div class="col-3">
<table class="table table-bordered table-sm table-hover text-center my-3">
<tr class="table-light">
    <th> Group #{{ $groupName }} </th>
</tr>
<tr>
    <td>
    @for ($j = 0; $j < $project->studentsPerGroup; $j++)
    <select class="form-select form-select-sm" style="overflow:auto; max-height:260;">
        <option selected>Assign Student</option>
        @foreach ($students as $student)
        <option value="{{ $groupName }}">{{ ucwords($student->name) }} {{ $loop->iteration . '/' . $loop->count }}</option>
        @endforeach
    </select>
    @endfor
    </td>
</tr>
</table>
</div>
@endfor
</div>

And persons list table:

enter code her<table class="table table-bordered table-sm table-hover text-center my-3">
<tr class="table-light">
    <th>Student</th>
    <th>Group Name</th>
    <th width="220px">Action</th>
</tr>
    @foreach ($students as $student)
<tr class="align-middle">
    <td class="text-left">{{ ucwords($student->name) }}</td>
    <td>Group#</td>
    <td>
        <form action="{{ route('students.destroy', $student->id) }}" method="POST">
            @csrf
            @method('DELETE')
            <button type="submit" title="delete" class="btn btn-danger btn-sm" onclick="return confirm('Please Confirm')">
                Remove
            </button>
        </form>
    </td>
</tr>
@endforeach
</table>

It’s a school project and I really tried hard. Any help is appreciated.

Prohibiting the output of certain IDs Laravel

When I create a post, the user selects a server(guild), and I need to prohibit the selection of a server that was previously created

I tried via @if($server->title != $guild->id) But it doesn’t work

I also do @if(Auth::user()->id === $user->id) to check the output to a specific user of his server,Maybe it gets in the way

@foreach($users as $user)
                    @foreach($user->guilds as $guild)
                        @if(Auth::user()->id === $user->id)
                            @foreach($servers as $server)
                                @if($server->title != $guild->id)
                                        <option value="{{$guild->id}}">{{$guild->name}}</option>
                                @endif
                            @endforeach
                        @endif
                    @endforeach
                @endforeach

Multilines message into WhatsApp API Using Textarea, POST and json playload with PHP

i am using WhatsAPP API of One of Facebook Partner.

I have a form with text area , Message content of textarea is POSTed to sendWhatsApp.php
and inside of sendWhatsApp.php i pasted following API code.

<?php
if(isset($_POST["textareacontent"])){
$message = $_POST["textareacontent"];

$url = "https://my-api-vender.com/api/send";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Content-Type: application/jsonrn",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = '
{
 "app": {
"id": "79912580897",
"time": "1651738553",
"data": {
  "recipient": {
    "id": "923336458112"
  },
  "message": [
    {
      "time": "1651738553",
      "type": "text",
      "value": "'.$message.'"
    }
  ]
}
  }
}
';

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
}

This code is workin fine with single line message.
but web i enter special charachters , Unicode carachters or ani emoji its shwoing erro.
So please help me how can i send multiline message also how can i use special charaehters, unicode and emojis.

Add Slider using Bootstrap Carousel with PHP code

I am trying to get all certificates from database to show on slider, My slide show only one image while it gets the count of images correct, this is the code I was trying to show images with.
using PHP and Bootstrap for carousel viewer.

<div class="row border rounded-lg" style="text-align: center; margin-right: 150px; margin-left: 180px;">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
     <ol class="carousel-indicators">
     <?php 
          $certificates = new Certificates();
          $a=0;
          if($certificates->getEmpCeretificate($_GET['id'])) {
             foreach($certificates->getEmpCeretificate($_GET['id']) as $certificate) {
                if($a==0){
                  echo '<li data-target="#carouselExampleIndicators" data-slide-to="'.$a.'" class="active"></li>';
                  }
                else{
                  echo '<li data-target="#carouselExampleIndicators" data-slide-to="'.$a.'"></li>';
                  }
                  $a = $a + 1 ;
                }
              }
              ?>
     </ol>
     <div class="carousel-inner">
         <?php 
         $b=0;
         if($certificates->getEmpCeretificate($_GET['id'])) {
            foreach($certificates->getEmpCeretificate($_GET['id']) as $certificate) {
              $image = base64_encode($certificate['certificate_image']); 
              echo '<p> '. $certificate['cnt'] . '</p>' ;
              if($b==0){
                  echo '<div class="carousel-item active" >'; 
              }
              else{
                 echo '<div class="carousel-item" >'; 
              }
                 echo '<img class="d-block w-100" src="data:image/jpg;charset=utf8;base64,'. $image .'"  style="width: 100%; height:300px;" />';
                 echo ' <div class="carousel-caption">';
                 echo ' <h3>'.  $certificate['name'] .'</h3>';
                 echo ' </div>';
                 echo '</div>';
                 $b = $b + 1 ;                 
                }
              }  

How to use php SCANDIR function to show directory listing that can interacted (e.g. if video then click to play)?

I have couple of html buttons in a .php page that are supposed to show files from directory containing .mp4/video files. I came across SCANDIR function which is working and shows the files in directory.

However, I need the listing to be interactive like click to play video (something like a href or hyperlink). Currently, the displayed list is just plain text.

I just need the listing to have a hyperlink to actual video files which I plan to play inside another html-div.

<button class="button-left" onclick="showLatestHits()"> Latest Hits</button>

<p id="song_genre">

function php_func_LatestHits()
    {
        $dir = 'music/Latest Hits';
        $files = scandir($dir);
        foreach ($files as $value) {
            if ('.' !== $value && '..' !== $value && '.DS_Store' !== $value) {
                echo "<br><br>" . $value;
            }
        }
    }

var result_LatestHits = "<?php php_func_LatestHits(); ?>"

function showLatestHits() {
    document.getElementById("song_genre").innerHTML = result_LatestHits;
}

Best practices for declaring class constants with PHP?

When I design classes in PHP and I need (or want) a constant I usually declare it as a class constant like this:

class MyClass {
    const FOO = 1;
}

Then I can use it like MyClass::FOO or self::FOO if using it inside a class method. Let’s add a class method so I can illustrate my question:

class MyClass {
    const FOO = 1;

    public static function add(int $a, int $b = self::FOO): int {
        return $a + $b;
    }
}

So far, so good. I can use my newly created method like $result = MyClass::add(5); or $result = MyClass::add(5, 7); and that’s about it. I always create interfaces for all my classes and that’s where my question falls into.

If my constants are declared within the class definition my IDE (PhpStorm in this case) complains about not having FOO declared although it is declared (but in the class and not in its interface). I can move the constant declaration to the class interface and everything is ok.

However, in other languages (like Java), declaring constants in interfaces (called the constant interface pattern) is considered bad practice. Being honest I have to say I’m ok with having my constants within their intended classes (it doesn’t really break the code, PhpStorm just complains about it but it’s not a real stopper…) but I would like to know what is the best approach to declare class constants.

Laravel relationship HasMany

I keep multiple address records belonging to a user. but when i write with dd i can’t access other table’s data.

Following my code:

user Table

id |    name       | country |
--- --------------  ----------   

7  | Mr. Lenny Bins| Belgium
2  | Dalton Miller | Swaziland

address Table

user_id | address         
-------- ---------
7       | 740 Brown Greens Suite  
7       | 9906 Cleora Wall Apt.      
2       | 53977 Kip Center Apt

UserModel

 public function getAddress()
    {
        return $this->hasMany(Address::class);
    }

UserController

$users = User::where('id' ,7)->with('getAddress')->get();

dd($users->toArray());
// The output of this is below

The output of this

dd($users->getAddress->toArray());

I get an error when I try like this.

Property [getAddress] does not exist on this collection instance.

Replacing characters in a returned Header Location in PHP

I’m trying to filter returned header location after POST using below PHP code. The returned header location is required for further processing of the payment status and saving the status in the db. The API provider seems not supportive since they don’t reply on time or fail to reply at all.

    $output = curl_exec($curl);
    $lines = explode("n",$output);
    $out = array();
    $headers = true;

    foreach ($lines as $l){
        $l = trim($l);
        if ($headers && !empty($l)){
           if (strpos($l,'location') !== false){
                $p = explode(' ',$l);
                $out['Headers']['location'] = trim($p[1]);
                $url = json_encode($out['Headers']['location']);
                echo json_encode($out['Headers']['location']);
            } 
        } 
    } 

The echo output is as below:- `"https://sandbox.kopokopo.com/api/v1/payments/c122c1d2-8e07-48d3-8c9d-597829447fda"`
How do I make the output to be a valid url without "" ? I'll really appreciate your valuable assistance.