how to change the local directory from htdocs to my project folder XAmmp

I am currently setting up wordpress applications of my client in my local. Client is using Mammp paid version on a mac, and I am using Xammp on my pc. He is unable to guide me on how to do it. What I have is the code base repo of my php application, a .sql data dump file which the client wants me to import into mysql using command line. I did this using command line and I can see the db under databases in php my admin.
How do I proceed from here, how do i let “wordpress connect to the db”?
I followed the installation process for wordpress and unzipped the entire content of wordpress zip to my project folder which i placed inside htdocs folder.
Client said i have to change the root folder from htdocs in xammp to my project location.
I tried this for changing root folder:

Go to C:xamppapacheconfhttpd.conf.
Open httpd.conf.
Find tag : DocumentRoot “C:/xampp/htdocs”
Edit tag to : DocumentRoot “C:/xampp/htdocs/myproject/web”
Now find tag and change it to < Directory “C:/xampp/htdocs/myproject/web” >
Restart Your Apache.

It didn’t work.

SAML private key leak

I have encountered a data leak recently and it turns out source code got leaked.
I’m analysing everything that might come back to bite me and of the things is SAML private key.

Could a private key be used with malicious intent? I understand it gives the ability to decrypt SAML requests and the possibility to create some aswell, but I am far from knowledgable on the subject.

Thanks!

Z

How to calculate and update sales price in woocommerce product page

I inserted two radio buttons as product add ons by using the following to calculate extra packaging cost. But I have two problems.

First instead of getting the value of my custom field eg 4.35 it gets a value of 4.00.

Second how can I update the sales price in my product page when I choose an option

function add_custom_fees_before_add_to_cart() {
    global $product;

    $myfee = floatval(get_post_meta(get_the_ID(), '_skrprom', TRUE)) + floatval(0.90);

    $args = array(
        'type' => 'radio',
        'class' => array( 'form-row-wide' ),
        'options' => array(
        '' => 'Τηλεφωνική Παραγγελία',
        $myfee => 'Έξοδα Συσκευασίας '.$myfee.'€',
    ),
    'default' => ''
);
?>
<div class="custom-fees-wrap">
    <label for="iconic-engraving"><?php _e( 'Customize Your Order!', 'textdomain' ); ?></label>
    <?php woocommerce_form_field( 'custom_fees', $args, '' ); ?>
</div>
<?php
}

add_action( 'woocommerce_before_add_to_cart_button', 'add_custom_fees_before_add_to_cart', 99 );


function save_value_add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
$custom_fees = filter_input( INPUT_POST, 'custom_fees' );

if ( empty( $custom_fees ) ) {
    return $cart_item_data;
}

$cart_item_data['custom_fees'] = $custom_fees;

return $cart_item_data;
}

add_filter( 'woocommerce_add_cart_item_data', 'save_value_add_cart_item_data', 99, 3 );

function calculate_add_cart_fee() {
   global $woocommerce;
   $cart_items = $woocommerce->cart->get_cart();
   foreach( $cart_items as $key => $item ) { 
      if( !isset( $item['custom_fees'] ) && empty( $item['custom_fees'] ) ) continue;
    $woocommerce->cart->add_fee( __('Έξοδα Συσκευασίας', 'textdomain'), $item['custom_fees'] );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'calculate_add_cart_fee', 99 );

Rewrite rule in plugin for permalink

I have plugin which is active on de page (permalink):
site.com/plugininfo/?item_id=100

I want to add in plugin rewrite rule for this url’s:
site.com/items/blabla/100/

“blabla” will be each time different.

I have tried different solutions but without success.

function when_rewrite_rules( $wp_rewrite ) {
  $new_rules = array();
  $new_rules['items/([^/]+)/([^/]+)/?$'] = 'plugininfo/?item_id=$matches[2]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules','when_rewrite_rules');

seems that you can not rewrite url to direct to the permalink?

if I change code to

$new_rules['items/([^/]+)/([^/]+)/?$'] = 'index.php?p=500&item_id=$matches[2]';

500 is id of page, then is working but visitor get redirected from site.com/items/blabla/100/ to site.com/plugininfo/?item_id=100

Of course i want that visitor stay at url site.com/items/blabla/100/

Any solutions?
Thanks

Pedja

Can I collect explode then explode again? – Laravel 8

I’m trying to create data save variable using a text file. I read that the collect function in laravel is the right choice for managing the data.

Here is the data saved after I exploded with PHP_EOL : dd output: exploded variable

What I want to do is explode once more per array with “|”, so my code is like this but it can’t.

$temps=explode(PHP_EOL,$note);
$isi=collect([
                explode('|',$temps)
            ]);

This code can only be applied if it is accompanied by a manual array like this :

$isi=collect([
                explode('|',$temps[0]),
                explode('|',$temps[2])
            ]);

The dd output : dd output: manual array

Please help.

Cakephp 4 not running on Ubuntu 20.3

After installing and creating a new CakePHP app using composer, I am trying to run the app on my browser using bin/cake server.

I get these errors:

Warning: cake_core cache was unable to write ‘cake_dev_eng’ to File cache in /usr/share/php/Cake/Cache/Cache.php on line 327

PHP Warning: /usr/share/php/Cake/Console/Templates/skel/tmp/cache/persistent/ is not writable in /usr/share/php/Cake/Cache/Engine/FileEngine.php on line 389

Please can anyone help me with resolving these issues? I am new to Linux.

Thanks in advance.

WordPress does not detect bootstrap and Jquery

I have an application that I’m trying to include in a wordpress page, I passed it the include of the index.php file and everything is displayed but when it looks for the JQuery and Bootstrap files for the style these are not detected.
The style files are located in the same folder as the index file and I pass them as follows (they are just examples):

    <link rel="stylesheet" href="include/bootstrap4/css/bootstrap-select.min.css">
    <link rel="stylesheet" href="include/bootstrap4/css/bootstrap.min.css">
    <link rel="stylesheet" href="include/bootstrap4/other/jquery-ui.css">
    <script src="include/bootstrap4/other/jquery-3.3.1.min.js"></script>

Also I tried to include Bootstrap with cnd and the style is detected but with Jqueys still nothing.
The application without the jquery files does not work, can anyone tell me how I can include bootstrap and Jquery in the page?

Creating Dynamic Input fields with json data

I am creating dynamic multi fields with PHP and JSON data. I am facing issues like 1st the foreach is not showing the data with the same keys like “text” field it is showing the one only in foreach loop. it should show.

1: input field with data (type text)
2: Textarea field with data
3: inputfield with data (type text)

but it is only showing 2 fields when I am running the code. Where I am mistaking?
And how to show the fields with types if the type is text then show the <input type="text" with data> and if it is textarea then show <textarea with data></textarea> please some one can help me out with this?

$json_test_data = '
                {
                    "section_1":
                    [
                        {
                            "text":{"class":"mb-20","name":"text","value":"value 1","placeholder":"Section placeholder"}
                        },
                        {
                            "textarea":{"class":"mb-20","name":"section_content","value":"Section content 1","placeholder":"Section Content"}
                        },
                        {
                            "text":{"class":"mb-20","name":"value_2","value":"value 2 value","placeholder":"value 2 placeholder"}
                        }
                    ]
                }';
                $json_test = json_decode($json_test_data, true);
                $input = '';
                if(is_array($json_test))
                {
                    foreach ($json_test as $section => $section_data)
                    {
                        echo '<div class="model">';
                        echo '<div class="model-header d-flex"><h4>'.$section.' Data</h4></div>';
                        foreach($section_data as $section_fields => $fields_data)
                        {
                            foreach($fields_data as $field_key => $field_value)
                            {
                                if($field_key == 'text')
                                {
                                    foreach($field_value as $field_keyy => $field_valuee)
                                    {   
                                        $input .= $field_keyy.'="'.$field_valuee.'" ';
                                    }
                                    echo '<input '.$input.'>';
                                }
                                
                            }
                        }
                        echo '</div>';
                    }
                }

I tried to input data based on the selected checkbox but an error occurred when selecting the second data if the first data was not selected too

<td>
    <input type="number" name="qty_masuk[]" id="qty_masuk" class="form-control" placeholder="QTY">
</td>
<td>
    <div class="form-control">
        <input type="checkbox" id="id_barang" name="id_barang[]" value="<?php echo $st['id_barang']; ?>">
    </div>
</td>

code html view

public function add_selected_barang()
{
    if (isset($_POST['submit'])) {
        $id_barang = $_POST['id_barang'];
        $qty_masuk = $_POST['qty_masuk'];

        for ($i = 0; $i < count($id_barang); $i++) {
            if ($qty_masuk != NULL) {
                $category_id = $id_barang[$i];
                $category_qty = $qty_masuk[$i];
                $this->Po_model->multisave($category_id, $category_qty);
            }
            // 
            $this->session->set_flashdata('flash', 'Item baru berhasil ditambahkan');
            redirect('daftarproduk');
        }
    }
}

in this controller I try to get 2 or more data when the checkbox is selected, when all the data is checked there is no problem at all the data entered is correct according to the selected data, which becomes a problem when I try to input the 2nd data without checking the first data, qty_masuk the value becomes 0 which should follow the data entered by the user, the problem that occurs is in qty_masuk.

function multisave($id_barang, $qty_masuk)
{
    $query = "INSERT INTO `barang_masuk`( `id_barang`, `qty_masuk`) 
    VALUES ('$id_barang','$qty_masuk')";
    $this->db->query($query);
}

Model

what should be added to solve this problem?

Magento 2: Cannot getData from different controller

I have this class

class Api extends MagentoFrameworkModelAbstractModel
{
 public function __construct(
        MagentoFrameworkMessageManagerInterface $messageManager,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoStoreModelStoreManagerInterface $storeManager,
        MyModulePaymentHelperData $helper
    ) {
        $this->messageManager = $messageManager;
        $this->scopeConfig = $scopeConfig;
        $this->storeManager = $storeManager;
        $this->helper = $helper;
        $this->contentType = $this->helper->getConfigData('content_type');
    }
    .
    .
    .
    function createOnlinePurchase($authToken, $lastOrder)
    {
        .
        .
        .
        //here I pass lastOrder's increment id to my payment gateway
        $lastOrder->setData('test','test data');
        $lastOrder->save();
        
        //make payment gateway api call, get payment url
        return url;
    }

}

this class is then used by a custom controller:

class Index extends MagentoFrameworkAppActionAction
{
    public function __construct(
        MagentoFrameworkAppActionContext $context,
        MyModulePaymentModelApi $moduleApi,
        MagentoCheckoutModelSession $session
    ) {
        parent::__construct($context);

        $this->moduleApi = $moduleApi;
        $this->session = $session;
    }
   
 public function execute() {
       $token = $this->moduleApi->requestAuthToken();

       if ($this->session->getLastRealOrder() && $token !== null) {
            $url = $this->moduleApi->createOnlinePurchase($token, $this->session->getLastRealOrder());

            if ($url !== null && substr($url, 0, 4) == 'http') {
               $this->session->clearStorage();     
               return $this->resultRedirectFactory->create()->setUrl($url);
            } 
            else {
                $this->messageManager->addError(__("Url invalid: ".$url));
                return $this->resultRedirectFactory->create()->setPath('checkout/onepage/failure');
            }
       }
}

on a SECOND custom controller Callback, which is triggered by my payment gateway, I retrieved the order object using $order = $this->getOrderFactory->create()->loadByIncrementId($incrementId)

where $this->getOrderFactory is an instance of MagentoSalesModelOrderFactory I injected.

I got the increment id back from my payment gateway.

Somehow within this Callback class, when I use $order->getData('test'), I get nothing

My question is

Is there some core magento concept I’m missing here?

Or is there any other way I can retrieve this test data in Callback which only have the information of increment Id (because at the point of Callback, user have already left magento and come back)

It’s weird to me beause I can edit and save the order from Callback but my extra data is not saved/associated with the order object itself

Thanks in advance!

Play Sound when value matched

Hello I have a simple script below where the value if MATCHED will echo message, but I want to create a script from this that instead of message it will sound or play audio file when the value is matched here below is the script sorry if I put the script sample inappropriate TY

<?php
// weather disturbance checker script
$imagesDir = './ajax-images/';  // directory for ajax-images with trailing slash
$MayBagyo = file_get_contents('./cache/typhoonsector3.txt');
$products = str_word_count($MayBagyo, 1);

$bagyostatus = 'wp9'; // when matched

$cyclonefound = false;
foreach ($products as $product)

{
    if (strpos($bagyostatus,$product) !== false) {
        $cyclonefound = true;
        break;
    }
}

if ($cyclonefound) {
    //echo 'A Low Pressure Area is Detected';
   echo "sound will play"/>";
}
else {
    echo '"message will post';

}
// end of weather disturbance checker script
?>

php script generating new pw to PlayFab

This is my first php script ever and I have googled a lot to try to get the script to work.

I am working on this tutorial: https://docs.microsoft.com/en-us/gaming/playfab/features/engagement/emails/using-email-templates-to-send-an-account-recovery-email

<!DOCTYPE HTML>  
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>  

<?php
// define variables and set to empty values
$emailErr = $pw1Err = $pw2Err = "";
$email = $pw1 = $pw2 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

  if (empty($_POST["email"])) 
  {
    $emailErr = "Email is required";
  } 
  else 
  {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
    }
  }

  if (empty($_POST["pw1"])) 
  {
    $pw1Err = "Password is required";
  }

  if (empty($_POST["pw2"])) {
    $pw2Err = "Confirm Password is required";
  }


//$str1 = "Hello";
//$str2 = "Hello World";
//echo strcasecmp($pw11, $pw2); // Outputs: -6


//$check = strcasecmp($pw11, $pw2)

$check = strcasecmp($pw1, $pw2); // Outputs: -6

/*
  if ($check == 0)
  {
      <br><br>
      echo Passwords are the same!;
      <br><br>
  }
  else
  {
      <br><br>
      echo Passwords are NOT the same!;
      <br><br>
  }
  */

}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>Password Recovery</h2>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo     htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  E-mail: <input type="text" name="email" value="<?php echo   $email;?>">
  <span class="error">* <?php echo $emailErr;?></span>
  <br><br>
  New Password: <input type="test_input" name=pw1 valur="<?php echo $pw1;?>">
  <span class="error">* <?php echo $pw1Err;?></span>
  <br><br>
  Confirm Password: <input type="test_input" name=pw2 valur="<?  php echo $pw2;?>">
  <span class="error">* <?php echo $pw2Err;?></span>
  <br><br><br>
  <input type="submit" name="submit" value="Submit">  
</form>

<?php
echo "<br>";
echo "<h3>Your Input:</h3>";
echo $email;
echo "<br>";
echo $check;
?>

</body>
</html>

What I am trying to accomplish is the callback URL. I first tried to create it in WordPress, which was also a first, and now try with php code.

Here is what I try to accomplish:

A form with the following fields:

  1. email
  2. New pasword (currently a text_input during test but will be real pw)
  3. Confirm password (currently a text_input during test but will be real pw)
  4. Submit button

Currently I am focus on trying to echo the result but I just can’t get this to work.

The ultimate target is to send back a confirmation with this API including the new checked password and the token.

https://docs.microsoft.com/en-us/rest/api/playfab/admin/account-management/reset-password?view=playfab-rest

I have been trying for quite a long time now so I reach out for help.

Call to a member function forceFill() on null, PersonalAccessTokenFactory.php

When I tried to use oauth laravel authentication, it produces the following error.I tried restarting redis and laravel server.Kindly help me to fix this issue.

  {
    "status": "error",
    "message": "{"status":"error","type":"exception","message":"Call to a member function forceFill() on null","file":"\/srv\/vendor\/laravel\/passport\/src\/PersonalAccessTokenFactory.php","line":78}"
}

Laravel model with multiple where condition getting unclear data

Hello everyone i want to ask about my problem. I want to get which data if column a is b or column b is a for a messaging app. I think you will understand when you see the code. And I also think I did nothing wrong in writing the code. this is my code and the response

Variable for this test

var uid: "QqAIR5Qwd6erFQIgSG"
var friend_uid: "Pk6R56XmWMywcObV3a"

Test 1

Chat::where(['sender'=>$request->uid, 'receiver'=>$request->friend_uid])->get();

Response

"data": [
    {
        "id": 4,
        "sender": "QqAIR5Qwd6erFQIgSG",
        "receiver": "Pk6R56XmWMywcObV3a",
        "message": "eyJpdiI6Ik8xSld4QlQ3bmMxaWxBMVlua3B0WXc9PSIsInZhbHVlIjoidGMvNGpXVmowVDczRUhSdGM0UkFQNHNjSVVZcFEyeFJlRThWNGdhMWZQMUFodkIwNWJtNmg4cmg1T2NOTm5ZdXBkdzdWWWhUY3hDQUtnVFBGcHllMkE9PSIsIm1hYyI6IjRkYTI5OTk3ZTRhMDAwZTdkYzgwODVmOTgyYzdlYTY2NDg0ZGM2YmExMDVkYzdiMzRhOTliYjA2MjU1ZTc3ZTkiLCJ0YWciOiIifQ==",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    }
]

This is valid response

Test 2

Chat::where(['sender'=>$request->friend_uid, 'receiver'=>$request->uid])->get();

Response

"data": []

This is valid because it doesn’t exist in the database, if there is then he will appear I’ve tried it.

Test 3 (i want to do this)

Chat::where(['sender'=>$request->uid, 'receiver'=>$request->friend_uid])->orWhere('sender'=>$request->friend_uid, 'receiver'=>$request->uid)->get();

Response

"data": [
    {
        "id": 2,
        "sender": "30B67S1tV7O7sJRG2l",
        "receiver": "QqAIR5Qwd6erFQIgSG",
        "message": "eyJpdiI6IkFDaFNMNjZESk96ZU5rSTQyMVhOUEE9PSIsInZhbHVlIjoiaDZyZU9TRSs2c0VTdkVlU2ZDd2JvZHpvQTh3KzZIYjk0NWJrbm90Tk9WREhBV2lrTS9xQW9KOXIza0MwaHUyMGUrTnlBS21aNXBRd1BweXJldlhiOWkzR0hqeHlFWERpdXczZ1E4NTJCSUU9IiwibWFjIjoiMzA3YmQwZmM4NjFlOTk3YmQwNzMwMzgxMTQ4ZmRhZDBhY2IzOWJkZWMzYWVhZmQyNjQ2NGI1MzM4NDQ2ZWY4YiIsInRhZyI6IiJ9",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    },
    {
        "id": 4,
        "sender": "QqAIR5Qwd6erFQIgSG",
        "receiver": "Pk6R56XmWMywcObV3a",
        "message": "eyJpdiI6Ik8xSld4QlQ3bmMxaWxBMVlua3B0WXc9PSIsInZhbHVlIjoidGMvNGpXVmowVDczRUhSdGM0UkFQNHNjSVVZcFEyeFJlRThWNGdhMWZQMUFodkIwNWJtNmg4cmg1T2NOTm5ZdXBkdzdWWWhUY3hDQUtnVFBGcHllMkE9PSIsIm1hYyI6IjRkYTI5OTk3ZTRhMDAwZTdkYzgwODVmOTgyYzdlYTY2NDg0ZGM2YmExMDVkYzdiMzRhOTliYjA2MjU1ZTc3ZTkiLCJ0YWciOiIifQ==",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    },
    {
        "id": 87,
        "sender": "chT9eSJ0N6HAXlkUUL",
        "receiver": "QqAIR5Qwd6erFQIgSG",
        "message": "eyJpdiI6Ikd4ZFZZTE1IVXRGQXNCVmUxUmJhcUE9PSIsInZhbHVlIjoiNWNUZE91Mk41K2o5Si9TSktOdEpNVSswYlVXZDlQd2hyTWY0d256cEJ4YkZKNVg0Y2hwbmNiUTJkZFhMSGxzVSIsIm1hYyI6IjA5ZDk2MDNkYzFhYzY0MTNlNTM3ODNmZDFiZDU3OTc2NThkODg4MGQzZGM5ZWQyYWRjM2Q1YzJmODkwNmUwOTYiLCJ0YWciOiIifQ==",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    }
]

why when I try with a query like this I get data which doesn’t match the uid or friend_uid? what happened and if where is the error in my program?, please help, thank you.