Encryption with Eval on PHP - decode

need help all,
now I have code like
function encode64($text){
$text_encode = base64_encode($text);
$text_encode = str_replace("=","_",$text_encode);
if(strlen($text_encode)%2==1) $text_encode=$text_encode."*";
for($i=0;$i<strlen($text_encode)/2;$i++){
$result = $result.substr($text_encode,$i,1);
$result = $result.substr($text_encode,strlen($text_encode)-$i-1,1);
}
return strrev($result);
}
function decode64($text){
$text_decode = strrev($text);
for($i=0;$i<strlen($text_decode)/2;$i++){
$raw_result = $raw_result.substr($text_decode,$i*2,1);
}
for($i=strlen($text_decode)/2;$i>0;$i--){
$raw_result = $raw_result.substr($text_decode,$i*2-1,1);
}
if(substr($raw_result,strlen($raw_result)-1,1)=="*"){
for($i=0;$i<strlen($text_decode)-1;$i++){
$result = $result.substr($text_decode,$i,1);
}
return base64_decode($result);
}else return base64_decode($raw_result);
}
this is using encode64 : LnCQd3ybbv2J930JJsyckC7dbzX9lGzagasuiUIHUIYIUYUISydiuahsdoijpojOIJIOIoiewSJIODcsWFx2fYcv2xV2sJZoWQN30YXl25RmibKvCNd23XasXFJ3hcX531NG5Ic93ARilbbvSNcGsJI7CkRyjJbh2R4npcbh3tIWgYZKG9lSlYKpGN1X5Qcn3gFCsdXl2NV3yXclm592ybK6CVkWpbOp3RJ3lXd0HxVWydbhiZAWkZYk299VuZO0wF_G_Z
and who can give me result
why can't read full code, I just can read like below:
http://i60.tinypic.com/2euomzq.png
can give me any solution because I need full code.

Related

Fatal error: Uncaught Error: Cannot use object of type WP_Error as array

Am trying to fetch user data from wordpress table. When I put the data into an array it shows me an fatal error.
This is my php code:
$getuser_data = $wpdb->get_results($user_query);
$userdata = array();
foreach($getuser_data as $data)
{
$userfeed['username'] = $data->user_login;
$userfeed['name'] = $data->user_email;
$userfeed['email'] = $data->display_name;
$userfeed['user_id'] = $data->ID;
$userfeed['profile_pic'] = get_wp_user_avatar_src($data->ID);
$usercount = count($getuser_data);
}
$userdata[] = $userfeed;
Its showing the fatal error Cannot use object of type WP_Error as array in last line $userdata[].
Any help would be appreciated.
Thanks in advance.
There might be something wrong with the $user_query and as a result $wpdb->get_results($user_query) is returning WP_Error object instead of the query result. Wrap the code inside the following block and check what's the error.
if( !is_wp_error( $getuser_data ) ) {
$userdata = array();
foreach($getuser_data as $data)
{
$userfeed['username'] = $data->user_login;
$userfeed['name'] = $data->user_email;
$userfeed['email'] = $data->display_name;
$userfeed['user_id'] = $data->ID;
$userfeed['profile_pic'] = get_wp_user_avatar_src($data->ID);
$usercount = count($getuser_data);
$userdata[] = $userfeed;
}
} else {
echo $getuser_data->get_error_message();
}

PHPexcel - getOldCalculatedValue and rangeToArray

Searched for quite a while now, but I'm stuck at the following problem.
I am using PHPexcel 1.8.0
The spreadsheet is read using the following code:
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, TRUE);
So far ok and it works well.
But some spreadsheets contain external referenced data.
And for that I want to use "getOldCalculatedValue".
How do I combine "getOldCalculatedValue" with "rangeToArray" ?
Or is "rangeToArray" inappropriate for this ?
Thanks for any help or hints !
Simple answer, you can't combine the two
rangeToArray() is a simple method for a simple purpose, it doesn't try to do anything clever, simply to return the data from the worksheet as efficiently and quickly as possible
getOldCalculatedValue() is used for a very specific circumstance, and isn't guaranteed to be correct even then, because it retrieves the last value calculated for the cell in MS EXcel itself, which ,ay not be correct if the external workbook wasn't available to MS Excel in that circumstance, or MS Excel formula evaluation was disable.
When calculating cells values from a formula, the PHPExcel calculation engine should use the getOldCalculatedValue() as a fallback if it finds an external reference, and rangeToArray() will try to use this method, but it isn't perfect, especially when that reference in nested deep inside other formulae referenced in other cells.
If you know that a formula in a cell contains an external reference, you should use getOldCalculatedValue() directly for that cell
I came up with the following solution.
Maybe not perfect, but it currently does the job. Thanks for any improvements!
With PHPExcel included and the excel file uploaded and ready, I continue with:
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
Create a new array to store the cell values of a row
$arr_row = array();
Loop through the rows
for ($rownumber = 2; $rownumber <= $highestRow; $rownumber++){
$row = $sheet->getRowIterator($rownumber)->current();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
Then loop through the cells of the current row
foreach ($cellIterator as $cell) {
Find cells with a formula
$cellcheck = substr($cell->getValue(),0,1);
if($cellcheck == '='){
$cell_content = $cell->getOldCalculatedValue();
}
else{
$cell_content = $cell->getValue();
}
Add the cell values to the array
array_push($arr_row,$cell_content);
Close cell loop
}
At this point I use the $arr_row to do further calculations and string formatting, before finally inserting it into a mysql table.
Close row loop
}
I made some changes in the function rangeToArray() inside Worksheet.php.
Worked fine!
public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
// Returnvalue
$returnValue = array();
// Identify the range that we need to extract from the worksheet
list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
$minCol = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] -1);
$minRow = $rangeStart[1];
$maxCol = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] -1);
$maxRow = $rangeEnd[1];
$maxCol++;
// Loop through rows
$r = -1;
for ($row = $minRow; $row <= $maxRow; ++$row) {
$rRef = ($returnCellRef) ? $row : ++$r;
$c = -1;
// Loop through columns in the current row
for ($col = $minCol; $col != $maxCol; ++$col) {
$cRef = ($returnCellRef) ? $col : ++$c;
// Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
// so we test and retrieve directly against _cellCollection
if ($this->_cellCollection->isDataSet($col.$row)) {
// Cell exists
$cell = $this->_cellCollection->getCacheData($col.$row);
if ($cell->getValue() !== null) {
if ($cell->getValue() instanceof PHPExcel_RichText) {
$returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText();
} else {
if ($calculateFormulas)
{ ##################################### CHANGED LINES
if(!preg_match('/^[=].*/', $cell->getValue()))
{
$returnValue[$rRef][$cRef] = $cell->getCalculatedValue(); # THE ORIGINAL CODE ONLY HAD THIS LINE
}
else
{
$returnValue[$rRef][$cRef] = $cell->getOldCalculatedValue();
}
} ##################################### CHANGED LINES
else
{
$returnValue[$rRef][$cRef] = $cell->getValue();
}
}
if ($formatData) {
$style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
$returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString(
$returnValue[$rRef][$cRef],
($style && $style->getNumberFormat()) ?
$style->getNumberFormat()->getFormatCode() :
PHPExcel_Style_NumberFormat::FORMAT_GENERAL
);
}
} else {
// Cell holds a NULL
$returnValue[$rRef][$cRef] = $nullValue;
}
} else {
// Cell doesn't exist
$returnValue[$rRef][$cRef] = $nullValue;
}
}
}
// Return
return $returnValue;
}

Drupal Views:Add condition in where clause where the value is a field in hook_alter_query

I am trying to add a condition to a query like:
civicrm_contact_civicrm_relationship.id <> civicrm_contact_civicrm_relationship_1.id
but for the second field drupal takes it as a string so it always result into
civicrm_contact_civicrm_relationship.id <> 'civicrm_contact_civicrm_relationship_1.id'
I've tried to play with the numerical value with no success.
Any idea how can I do this? May be with another hook? any tip will be welcome!
My code:
$view->query->where[2]["conditions"][0]["field"] = "civicrm_contact_civicrm_relationship_1.id";
$view->query->where[2]["conditions"][0]["operator"] = "IS NULL";
$view->query->where[2]["conditions"][0]["value"] = "";
$view->query->where[2]["conditions"][1]["field"] = "civicrm_contact_civicrm_relationship.id";
$view->query->where[2]["conditions"][1]["operator"] = "IS NULL";
$view->query->where[2]["conditions"][1]["value"] = "";
$view->query->where[2]["conditions"][2]["field"] = "civicrm_contact_civicrm_relationship.id";
$view->query->where[2]["conditions"][2]["value"] ="civicrm_contact_civicrm_relationship_1.id";
$view->query->where[2]["conditions"][2]["numeric"] = "1";
$view->query->where[2]["conditions"][2]["operator"] = "<>";
$view->query->where[2]["type"] = "OR";
try something like
function my_hook_views_query_alter(&$view, &$query)
{
if ($view->name == 'my_hook') {
$alias = $query->add_table('civicrm_contact_civicrm_relationship','civicrm_contact_civicrm_relationship_1');
$query->add_where_expression(0,'civicrm_contact_civicrm_relationship.id <> civicrm_contact_civicrm_relationship_1.id');
dpm($query); //dumps object to admin with devel module
}
}

How to execute a php loop in an andWhere clause using QueryBuilder?

I would like to execute this type of query using QueryBuilder in my FakeRepository.php (it's for a search form where the user can check some boxes).
if (sizeof($p['types']) > 0) {
$qb->andWhere(
foreach ($p['types'] as $type_id)
{'type.id=' .$type_id.' OR ' }
'1=0');
}
But I have an error with my syntax but I don't know how to fix it :
Parse error: syntax error, unexpected T_FOREACH, expecting ')' in /MyBundle/Entity/FakeRepository.php
Thanks a lot for your help
You need to first construct your OR condition and then pass it to the query builder
$first = true;
$orQuery = '';
foreach ($p['types'] as $type_id)
if ($first) {
$first = false;
} else {
$orQuery .= ' OR ';
}
$orQuery .= 'type.id=' .$type_id;
}
$qb->andWhere($orQuery);
You can also resove this problem:
$arr = array();
foreach ($p['types'] as $type_id){
$arr[] = $qb->expr()->orX("type.id = $type_id");
}
$qb->andWhere(join(' OR ', $arr));
Another solution to keep QueryBuilder functionality
$orX = $qb->expr()->orX();
foreach ($types as $key => $type) {
$orX->add($qb->expr()->eq('types', ':types'.$key));
$qb->setParameter('types'.$key, $type->getId());
}
$qb->andWhere($orX);

drupal get list of terms of a node

How to get list of terms of a node ( by node id) belongs to a particular vocabulary. Is there any drupal function ?
taxonomy_node_get_terms function.
http://api.drupal.org/api/function/taxonomy_node_get_terms/6
Or also:
taxonomy_node_get_terms_by_vocabulary
http://api.drupal.org/api/function/taxonomy_node_get_terms_by_vocabulary/6
I know there is api for getting list of vocabularies But i am nto sure, one api exist for gettign list of terms of vocabularies.
However, you can try this function. It will work.
function myutils_get_terms_by_vocabulary($vname, $tname = "") {
$sql = "select td.*
from term_data td
inner join vocabulary v on td.vid = v.vid
where v.name = '%s'";
if($tname) {
$result = db_query($sql . " and td.name = '%s'", $vname, $tname);
return db_fetch_object($result);
} else {
$result = db_query($sql, $vname);
}
$terms = array();
while ($term = db_fetch_object($result)) {
$terms[$term->tid] = strtolower($term->name);
}
return $terms;
}
Basically i created a 'myutils' module for such common functions and added this function there. so that i can use them in all similar scenarios.

Resources