I just updated my Customizr child theme and I'm getting the following error on my dashboard:
Warning: Invalid argument supplied for foreach() in /home/beaufort/public_html/wp-content/themes/customizr/inc/class-fire-utils.php on line 653
This is what is on line 653:
foreach ( $_font_groups as $_group_slug => $_font_list ) {
and this is what follows:
if ( 'list' == $_what ) {
$_to_return[$_group_slug] = array();
$_to_return[$_group_slug]['list'] = array();
$_to_return[$_group_slug]['name'] = $_font_list['name'];
}
I am clueless when it comes to php so your help would be much appreicated!
Many thanks
/**
* #return an array of font name / code OR a string of the font css code
* #parameter string name or google compliant suffix for href link
*
* #package Customizr
* #since Customizr 3.2.9
*/
function tc_get_font( $_what = 'list' , $_requested = null ) {
$_to_return = ( 'list' == $_what ) ? array() : false;
$_font_groups = apply_filters(
'tc_font_pairs',
TC_init::$instance -> font_pairs
);
foreach ( $_font_groups as $_group_slug => $_font_list ) {
if ( 'list' == $_what ) {
$_to_return[$_group_slug] = array();
$_to_return[$_group_slug]['list'] = array();
$_to_return[$_group_slug]['name'] = $_font_list['name'];
}
foreach ( $_font_list['list'] as $slug => $data ) {
switch ($_requested) {
case 'name':
if ( 'list' == $_what )
$_to_return[$_group_slug]['list'][$slug] = $data[0];
break;
case 'code':
if ( 'list' == $_what )
$_to_return[$_group_slug]['list'][$slug] = $data[1];
break;
default:
if ( 'list' == $_what )
$_to_return[$_group_slug]['list'][$slug] = $data;
else if ( $slug == $_requested ) {
return $data[1];
}
break;
}
}
}
return $_to_return;
}
Before line 653 add if (is_array($_font_groups)) {
Then, add a closing bracket } above return $_to_return;
Related
I Got error in the datatable in mongodb please give solution...
If Anyone have reference source code send me it will helpful for me....................................................................................................................................................................................
Notice: Undefined index: iColumns in D:\xampp\htdocs\mongo\test3.php on line 47
Notice: Undefined index: sEcho in D:\xampp\htdocs\mongo\test3.php on line 129
{"sEcho":0,"iTotalRecords":9,"iTotalDisplayRecords":9,"aaData":[{"_id":
{"$id":"5936e5e783b236680c00002a"},"name":"Mitra","age":21,"gender":"M","course":"BTECH","marks":77}
Source Code:
<?php
mb_internal_encoding('UTF-8');
$database = 'university';
$collection = 'students';
/**
* MongoDB connection
*/
try{
// Connecting to server
$m = new MongoClient( );
}catch(MongoConnectionException $connectionException){
print $connectionException;
exit;
}
$m_collection = $m->$database->$collection;
/**
* Define the document fields to return to DataTables (as in http://us.php.net/manual/en/mongocollection.find.php).
* If empty, the whole document will be returned.
*/
$fields = array();
// Input method (use $_GET, $_POST or $_REQUEST)
$input = & $_REQUEST;
/**
* Handle requested DataProps
*/
// Number of columns being displayed (useful for getting individual column search info)
$iColumns = $input['iColumns'];
// Get mDataProp values assigned for each table column
$dataProps = array();
for ($i = 0; $i < $iColumns; $i++) {
$var = 'mDataProp_'.$i;
if (!empty($input[$var]) && $input[$var] != 'null') {
$dataProps[$i] = $input[$var];
}
}
/**
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large collections.
*/
$searchTermsAny = array();
$searchTermsAll = array();
if ( !empty($input['sSearch']) ) {
$sSearch = $input['sSearch'];
for ( $i=0 ; $i < $iColumns ; $i++ ) {
if ($input['bSearchable_'.$i] == 'true') {
if ($input['bRegex'] == 'true') {
$sRegex = str_replace('/', '\/', $sSearch);
} else {
$sRegex = preg_quote($sSearch, '/');
}
$searchTermsAny[] = array(
$dataProps[$i] => new MongoRegex( '/'.$sRegex.'/i' )
);
}
}
}
// Individual column filtering
for ( $i=0 ; $i < $iColumns ; $i++ ) {
if ( $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
if ($input['bRegex_'.$i] == 'true') {
$sRegex = str_replace('/', '\/', $input['sSearch_'.$i]);
} else {
$sRegex = preg_quote($input['sSearch_'.$i], '/');
}
$searchTermsAll[ $dataProps[$i] ] = new MongoRegex( '/'.$sRegex.'/i' );
}
}
$searchTerms = $searchTermsAll;
if (!empty($searchTermsAny)) {
$searchTerms['$or'] = $searchTermsAny;
}
$cursor = $m_collection->find($searchTerms, $fields);
/**
* Paging
*/
if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
$cursor->limit( $input['iDisplayLength'] )->skip( $input['iDisplayStart'] );
}
/**
* Ordering
*/
if ( isset($input['iSortCol_0']) ) {
$sort_fields = array();
for ( $i=0 ; $i<intval( $input['iSortingCols'] ) ; $i++ ) {
if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
$field = $dataProps[ intval( $input['iSortCol_'.$i] ) ];
$order = ( $input['sSortDir_'.$i]=='desc' ? -1 : 1 );
$sort_fields[$field] = $order;
}
}
$cursor->sort($sort_fields);
}
/**
* Output
*/
$output = array(
"sEcho" => intval($input['sEcho']),
"iTotalRecords" => $m_collection->count(),
"iTotalDisplayRecords" => $cursor->count(),
"aaData" => array(),
);
foreach ( $cursor as $doc ) {
$output['aaData'][] = $doc;
}
echo json_encode( $output );
Those are not errors, are Notices:
$iColumns = $input['iColumns'];
$input has no key named iColumns.
"sEcho" => intval($input['sEcho']),
Same thing here: $input has no key named sEcho
Make sure that $_REQUEST contains both keys.
Or you could disable Error Reporting for notices.
EDIT:
You use:
$input = & $_REQUEST;
you should provably use $_GET or $_POST depending how you send the date to the server and ensure iColumns and sEcho are sent.
If your frontend has a form and you are posting the data, you could validate the input fields so those two variables are required OR give them a default value.
If you want to default it (for example) to 10:
$iColumns = isset($input['iColumns']) ? isset($input['iColumns']) : 10;
and (not sure what sEcho index is used for:
$sEcho = isset($input['sEcho'] ? intval($input['sEcho']) : 10;
$output = array(
"sEcho" => $sEcho,
"iTotalRecords" => $m_collection->count(),
"iTotalDisplayRecords" => $cursor->count(),
"aaData" => array(),
);
That should not give you any notices.
Other Option, disable reporting of notices:
[root#server ]$ vi /etc/php.ini
error_reporting = E_ALL & ~E_NOTICE
Or, in the top of your php file:
error_reporting(E_ALL & ~E_NOTICE);
I try to make query in Codeigniter via Active Records:
if (isset($data['where']['and'])) {
$this->db->where($data['where']['and']);
}
if (isset($data['where']['or'])) {
$this->db->or_where_in('idSpec', $data['where']['or']);
}
I want to get:
WHERE name = 1 AND (idSpec = 2 OR idSpec = 3 OR idSpec = 4);
But now I get:
WHERE name = 1 OR idSpec = 2 OR idSpec = 3 OR idSpec = 4;
Use below code.
if (isset($data['where']['and'])) {
$this->db->where($data['where']['and']);
}
if (isset($data['where']['or'])) {
$this->db->where("(idSpec = 2 OR idSpec = 3 OR idSpec = 4;)", NULL, FALSE);
}
I assume your $data['where']['or'] contains some ids.
This may help you.
if (isset($data['where']['or']))
{
$or_conditions='(idSpec ='.implode(' OR idSpec = ',$data['where']['or']).')';
$this->db->where($or_conditions);//if this produce error use bellow one
//$this->db->where($or_conditions,'',false);
}
This is the basic method to select data from database I'm using well for a long time..
/**
* Le wild function to make a life better.
* Doing abrakadabra
*
* #param $table
* #param bool $selector
* #param string $order
* #param bool $start
* #param bool $limit
* #param $return
*
* #return mixed
*/
public function _getCustomTableData($table, $selector = FALSE, $order = 'id DESC', $start = FALSE, $limit = FALSE, $return = FALSE, $group_by = FALSE)
{
$query = $return ? $this->db->select($return) : $this->db->select('*');
if ( $selector ) {
if ( isset($selector['mixed_selection']) && $selector['mixed_selection'] == TRUE ) {
$query = $this->db->where($selector['mixed_selection']);
} else {
foreach ( $selector as $select_array ):
$query = $this->db->where($select_array);
endforeach;
}
}
if ( $group_by ) {
$query = $this->db->group_by($group_by);
}
$query = $this->db->order_by($order);
if ( $start && $limit ) {
$query = $this->db->limit($limit, $start);
}
if ( ! $start && $limit ) {
$query = $this->db->limit($limit);
}
// proceed
$query = $this->db->get($table);
if ( $limit == TRUE && $limit == 1 ) {
$query = $query->row_array();
if ( $return ) {
return $query[$return];
} else {
return $query;
}
} else {
$query = $query->result_array();
return $query;
}
}
and query looks like:
$this->_getCustomTableData('table', array(array('selector' => '1', 'time >=' => time())), 'id DESC', FALSE, 1, 'id');
it's like:
SELECT 'id' FROM `table` WHERE `selector` = 1 AND `time` >= 1472582... ORDER BY id DESC LIMIT 1
or you can use "mixed selection"
$this->_getCustomTableData('table', array('mixed_selection' => 'selector = 1 AND time >= 1472582...'), 'id DESC', FALSE, 1, 'id');
and the result will be the same. I have wrote this method when I was beginner with CI and it helped me a lot :)
I got strange error suddenly and my website is down. Even i cant login to wordpress admin account ...
here is error :
Parse error: syntax error, unexpected end of file, expecting function (T_FUNCTION) in /home/Myid/public_html/Mywebsite/wp-includes/class-oembed.php on line 191
I logged in to my host account filemanager to edit file and only i found on line 191 is this :
"* #param string $provider The URL"
Please help how to fix this.
Few line up coding as follows :
// Fetch URL content
if ( $html = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ) ) {
/**
* Filter the link types that contain oEmbed provider URLs.
*
* #since 2.9.0
*
* #param array $format Array of oEmbed link types. Accepts 'application/json+oembed',
* 'text/xml+oembed', and 'application/xml+oembed' (incorrect,
* used by at least Vimeo).
*/
$linktypes = apply_filters( 'oembed_linktypes', array(
'application/json+oembed' => 'json',
'text/xml+oembed' => 'xml',
'application/xml+oembed' => 'xml',
) );
// Strip <body>
$html = substr( $html, 0, stripos( $html, '</head>' ) );
// Do a quick check
$tagfound = false;
foreach ( $linktypes as $linktype => $format ) {
if ( stripos($html, $linktype) ) {
$tagfound = true;
break;
}
}
if ( $tagfound && preg_match_all( '/<link([^<>]+)>/i', $html, $links ) ) {
foreach ( $links[1] as $link ) {
$atts = shortcode_parse_atts( $link );
if ( !empty($atts['type']) && !empty($linktypes[$atts['type']]) && !empty($atts['href']) ) {
$providers[$linktypes[$atts['type']]] = $atts['href'];
// Stop here if it's JSON (that's all we need)
if ( 'json' == $linktypes[$atts['type']] )
break;
}
}
}
}
// JSON is preferred to XML
if ( !empty($providers['json']) )
return $providers['json'];
elseif ( !empty($providers['xml']) )
return $providers['xml'];
else
return false;
}
/**
* Connects to a oEmbed provider and returns the result.
*
* #param string $provider The URL
cant get a clue whats going wrong ..please let me know how to fix this.
thanks a lot
There are 6 { for 7 }, I'm pretty sure there is one too many after the break;
Your last closing brace is the one that's causing the error }
The one right above * Connects to a oEmbed provider and returns the result.
// Fetch URL content
...
// JSON is preferred to XML
if ( !empty($providers['json']) )
return $providers['json'];
elseif ( !empty($providers['xml']) )
return $providers['xml'];
else
return false;
}
^--- That ONE right there.
/**
* Connects to a oEmbed provider and returns the result.
*
* #param string $provider The URL
Rewrite
// Fetch URL content
if ( $html = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ) ) {
/**
* Filter the link types that contain oEmbed provider URLs.
*
* #since 2.9.0
*
* #param array $format Array of oEmbed link types. Accepts 'application/json+oembed',
* 'text/xml+oembed', and 'application/xml+oembed' (incorrect,
* used by at least Vimeo).
*/
$linktypes = apply_filters( 'oembed_linktypes', array(
'application/json+oembed' => 'json',
'text/xml+oembed' => 'xml',
'application/xml+oembed' => 'xml',
) );
// Strip <body>
$html = substr( $html, 0, stripos( $html, '</head>' ) );
// Do a quick check
$tagfound = false;
foreach ( $linktypes as $linktype => $format ) {
if ( stripos($html, $linktype) ) {
$tagfound = true;
break;
}
}
if ( $tagfound && preg_match_all( '/<link([^<>]+)>/i', $html, $links ) ) {
foreach ( $links[1] as $link ) {
$atts = shortcode_parse_atts( $link );
if ( !empty($atts['type']) && !empty($linktypes[$atts['type']]) && !empty($atts['href']) ) {
$providers[$linktypes[$atts['type']]] = $atts['href'];
// Stop here if it's JSON (that's all we need)
if ( 'json' == $linktypes[$atts['type']] )
break;
}
}
}
}
// JSON is preferred to XML
if ( !empty($providers['json']) )
return $providers['json'];
elseif ( !empty($providers['xml']) )
return $providers['xml'];
else
return false;
/**
* Connects to a oEmbed provider and returns the result.
*
* #param string $provider The URL
*/
i can resolve this error in my wordpress by checking error_log file in root folder of my WP
in the last line of this file you can seek and find the error (filename and line)
and if you have backup of your WP ftp files you can replace them with a correct version
so finally it may need to delete some plugins of needed
I'm trying to get variables from several interrelated functions during XML parsing and put them into arrays. The code is:
function readChapters($reader) {
while($reader->read()) {
if( /* condition here */ ) {
$chapter = readValue($reader);
}
if( /* condition here */ ) {
readModules($reader);
}
if( /* condition here */ ) {
return;
}
}
}
function readModules($reader) {
while($reader->read()) {
if( /* condition here */ ) {
readModule($reader);
}
if( /* condition here */ ) {
return($reader);
}
}
}
function readModule($reader) {
while($reader->read()) {
if( /* condition here */ ) {
$topic = readValue($reader);
}
if( /* condition here */ ) {
$description = readValue($reader);
}
}
}
function readValue($reader) {
while($reader->read()) {
if( /* condition here */ ) {
return $reader->readInnerXML();
}
}
}
$reader = new XMLReader();
$reader->open('example.xml');
$current = 0;
$topics_list = array();
$chapterName = ""; // want to add $chapter
$topicName = ""; // want to add $topic
$descriptionText = ""; // want to add $description
while($reader->read()) {
if(// condition here) {
readChapters($reader);
}
$topics_list[$current] = array();
$topics_list[$current]['chapter'] = $chapterName;
$topics_list[$current]['topic'] = $topicName;
$topics_list[$current]['description'] = $descriptionText;
}
$reader->close();
print_r($topics_list);
Problem: How to get $chapter, $topic, $description variables from outside of these functions in order to put them into arrays? Thanks in advance.
Update: The XML document structure is here, and the expected structure of Array():
Array (
[0] => Array (
[chapter] => Chapter_name1
[topic] => Topic_name1
[description] => Content_of_the_topic1
)
[1] => Array (
[chapter] => Chapter_name1
[topic] => Topic_name2
[description] => Content_of_the_topic2
)
[2] => Array (
[chapter] => Chapter_name2
[topic] => Topic_name2
[description] => Content_of_the_topic2
)
.....
)
You're essentially using a set of function to build a data structure using data from an XML object. That means that each function should return the data structure it's named for: readChapters() should return a chapter structure (and should probably be named readChapter(), since I think it's only reading one chapter, correct?), and so on. I don't know what your XML looks like or what your desired data structure looks like, but you'll want something like this:
function readChapter($reader) {
$chapter = array();
while (// condition) {
if (// something)
$chapter['chapter'] = readValue($reader);
elseif (// something else)
$chapter['topic'] = readValue($reader);
// etc
}
return $chapter;
}
Then in your main loop below, you can have this:
while ($reader->read()) {
if (// condition here) {
$topics_list[] = readChapter($reader);
}
}
Hope that gets you closer to something you can build!
I have a PHP application that takes a CSV in input; in the first column I have both category and subcategory splitted by a '|'. I have to put this stuff in a Open Cart DB, which has the same table for Category and Subcategory (a column "parent_id" indicates the category_id of the Category).
I thought to build a class with all the fields needed as follows:
class Categorie {
public $category_id;
public $parent_id;
public $image;
public $top;
public $column;
public $sort_order;
public $status;
public $date_modified;
public $date_added;
public $language_id;
public $name;
public $description;
public $meta_description;
public $meta_keywords;
}
Then I analyze the data:
$categorie = array();
while ( ( $riga_file = fgetcsv( $file, 100000, "\t" ) ) !== false )
{
$array_el = count( $riga_file );
for( $el_cur = 0; $el_cur < $array_el; $el_cur++ )
{
switch ( $el_cur )
{
case 0:
$colonne = explode( "|", $riga_file[$el_corr] );
$categoria = new Categorie();
$categoria->image = "";
$categoria->top = 1;
$categoria->column = 1;
// ... bla adding description data
if( $categorie[$colonne[0]] == NULL ) // (1)
{
$categoria->name = $colonne[0];
$categoria->category_id = $id_categoria;
$categoria->parent_id = 0;
$categorie[$colonne[0]] = $categoria;
$id_categoria++;
}
if( $colonne[1] != NULL ) // (2)
{
$categoria->name = $colonne[1];
if( $categorie[$colonne[1]] == NULL )
{
$categoria->category_id = $id_categoria;
$categoria->parent_id = $categorie[$colonne[0]]->category_id;
$categorie[$colonne[1]] = $categorie;
$id_categoria++;
}
}
break;
}
I should have an array filled with a collection of unique objects like:
// OUT(3)
Category 1
Subcategory 1
Category 2
Subcategory 2...
If I put echoes of $categoria (not $categorie) inside (1) and (2), I see exactly what I wrote down in OUT(3), which leads me to think that my "engine" is correct. The problems come when I try to search into the array:
echo "<table border='1'>";
foreach( $categorie as $value )
{
echo "<tr>
<td>$value->category_id</td>
<td>$value->parent_id</td>
<td>$value->name</td>
</tr>";
}
echo "</table>";
because I don't get Categories at all, and most but not all Subcategories.
Am I doing something wrong with "search engine" or I misunderstood something with PHP Arrays (probably because I come from C++ and this php is f**king my mind)?
I solved the problem, or better: problems.
1) I mispelled a variable: in (2) I wrote:
$categorie[$colonne[1]] = $categorie;
The correct writing is:
$categorie[$colonne[1]] = $categoria;
2) The bigger problem was from my "unknowing" of PHP, in fact, fixed the problem 1, I got an output like:
subcategory1
subcategory1
subcategory2
subcategory2
and so on. This lead me to guess that when I do:
$categorie[$colonne[1]] = $categoria;
PHP doesn't copy the values inside, but uses addresses instead. Follows the right code:
switch ( $el_corr )
{
case 0: // Categorie e sottocategorie
$colonne = explode( "|", $riga_file[$el_corr] );
$categoria = new Categorie();
$categoria->image = "";
$categoria->top = 1;
$categoria->column = 1;
$categoria->sort_order = 0;
$categoria->status = 1;
// Category_Description Campi
$categoria->language_id = 1;
$categoria->name = $colonne[0];
$categoria->description = "";
$categoria->meta_description = "";
$categoria->meta_keywords = "";
////////////////////////
if( $categorie[$colonne[0]] == NULL )
//if( !trova_categorie( $colonne[0], $categorie ) )
{
$categoria->name = $colonne[0];
$categoria->category_id = $id_categoria;
$categoria->parent_id = 0;
$categorie[$colonne[0]] = $categoria;
$id_categoria++;
}
$categoria = new Categorie();
$categoria->image = "";
$categoria->top = 1;
$categoria->column = 1;
$categoria->sort_order = 0;
$categoria->status = 1;
// Category_Description Campi
$categoria->language_id = 1;
$categoria->name = $colonne[0];
$categoria->description = "";
$categoria->meta_description = "";
$categoria->meta_keywords = "";
if( $colonne[1] != NULL )
{
$categoria->name = $colonne[1];
if( $categorie[$colonne[1]] == NULL )
//if( !trova_categorie( $colonne[1], $categorie ) )
{
$categoria->category_id = $id_categoria;
$categoria->parent_id = $categorie[$colonne[0]]->category_id;
$categorie[$colonne[1]] = $categoria;
$id_categoria++;
}
}
break;
}