PHP Warning: Attempt to read property "SONGTITLE" on bool in - php

PHP Warning: Attempt to read property "SONGTITLE" on bool in
PHP Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home2/radiosound/public_html/80s/assets/php/config.php on line 31
`function Streaming(){
global $radio;
$shoutcast = #simplexml_load_file("http://live.radiosoundfm.com.br:8398/stats?sid=1");
$music = htmlspecialchars(addslashes($shoutcast->SONGTITLE));
$singer = ''; $name = $music;
if(strpos($music, '-') !== false && substr_count($music, '-') == 1){
$data = explode('-', $music);
$singer = trim($data[0]) != '' ? trim($data[0]) : '';
$name = trim($data[1]) != '' ? trim($data[1]) : '';
}
$data = array(
'music' => $music,
'name' => $name,
'singer' => $singer
);
return $data;
}`

Related

Unable to get dynamic Meta tags in codeigniter

I am working on codeigniter and i am trying to use dynamic meta tag but meta tags not working for me, Here is my code in controller
$id = $this->uri->segment(2);
$data['id'] = $id;
$data['metas'] = array(
array('name'=>'description', 'content'=>'A short but sweet DEFAULT description of this fine site'),
array('name' =>'keywords', 'content'=>'some awesome DEFAULT keywords for those rascally web crawlers')
);
Here is my view
<?php
foreach($metas as $meta)
{?>
<meta name="<?=$meta['name']?>" content="<?=$meta['content']?>" />
<?php }?>
Just go inside codeigniter 3 system/helpers/html_helper.php and copy the function and put it in your own libraries
function meta($name = '', $content = '', $type = 'name', $newline = "\n")
{
// Since we allow the data to be passes as a string, a simple array
// or a multidimensional one, we need to do a little prepping.
if ( ! is_array($name))
{
$name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
}
elseif (isset($name['name']))
{
// Turn single array into multidimensional
$name = array($name);
}
$str = '';
foreach ($name as $meta)
{
$type = (isset($meta['type']) && $meta['type'] !== 'name') ? 'http-equiv' : 'name';
$name = isset($meta['name']) ? $meta['name'] : '';
$content = isset($meta['content']) ? $meta['content'] : '';
$newline = isset($meta['newline']) ? $meta['newline'] : "\n";
$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
}
return $str;
}

How to get thumbnailPhoto from Active Directory ? php

I have this code :
if (TRUE === ldap_bind($ldap_connection, $ldap_username, $ldap_password)){
$ldap_base_dn = 'DC=xx,dc=xx,dc=xx';
$search_filter = '(&(objectCategory=person)(samaccountname=*))';
$attributes = array();
$attributes[] = 'givenname';
$attributes[] = 'mail';
$attributes[] = 'samaccountname';
$attributes[] = 'ipphone';
$attributes[] = 'thumbnailPhoto';
$result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter, $attributes);
if (FALSE !== $result){
$entries = ldap_get_entries($ldap_connection, $result);
for ($x=0; $x<$entries['count']; $x++){
if (!empty($entries[$x]['givenname'][0]) &&
!empty($entries[$x]['mail'][0]) &&
!empty($entries[$x]['samaccountname'][0]) &&
!empty($entries[$x]['ipphone'][0]) &&
'Shop' !== $entries[$x]['ipphone'][0] &&
'Account' !== $entries[$x]['ipphone'][0]){
$ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'phone' => trim($entries[$x]['ipphone'][0]), 'photo' => trim ($entries[$x]['thumbnailPhoto'][0]));
}
}
}
ldap_unbind($ldap_connection);
}
echo json_encode($ad_users);
I get only null for thumbnailPhoto .
How to handle this kind of data ? Can I get the url of this photo ?
I'm developing iOS app and sending employee data using json in php but how can I send this thumbnailPhoto also with each employee in json?
You have to use the attribute 'thumbnailphoto' and not 'thumbnailPhoto' (without capital letter).
Then in your $ad_users array you have to convert to base64 insted of trim :
'photo' => base64_encode ($entries[$x]['thumbnailPhoto'][0])

declare form variables and arrays

I'm trying to declare variables and arrays from a form (post) but it seems the arrays are not being processed:
// is this a better practise than directly pass the entire $_POST?
$list = array('use', 'type', 'status', 'bhk', 'baths', 'size', 'location', 'price', 'description');
foreach($list as $name) {
if ($name != 'description')
$var = "\$" . $name . "=filter_input(INPUT_POST, '" . $name . "', FILTER_SANITIZE_NUMBER_INT);";
else if ($name == 'description')
$var = "\$" . $name . "=filter_input(INPUT_POST, '" . $name . "', FILTER_SANITIZE_STRING);";
}
$area_1 = $size['area1'] != '' ? $size['area1'] : 0;
$area_2 = $size['area2'] != '' ? $size['area2'] : 0;
$city = $location['city'];
$zone = $location['zone'];
$sale = $price['sale'] != '' ? $price['sale'] : 0;
$rent = $price['rent'] != '' ? $price['rent'] : 0;
Could be that some of those inputs are long numbers? Like $price['sale'] (up to 999999) or $size['area1'] (up to 999). Since they don't need any unit type I prefer storing them as integers rather than strings. But tell me if the length is a problem.
EDIT: (FIX by #swidmann in comments)
$$name = filter_input(INPUT_POST, $name, FILTER_SANITIZE_NUMBER_INT);
Solution: (by #swidmann in comments)
$$name = filter_input(INPUT_POST, $name, FILTER_DEFAULT , FILTER_REQUIRE_ARRAY)
To create variables from your array you should use $$ instead of concatenating a string an run eval(), because eval() is evil.
You can make variables like this:
$$name = filter_input( INPUT_POST , $name, FILTER_SANITIZE_NUMBER_INT ); with $$name you can define a variable with the name of the string content $name
If your input can be an array, please take a look at filter_input_array() or filter_input() with the option FILTER_REQUIRE_ARRAY, depends on what you need.
Here is an approach:
// is this a better practise than directly pass the entire $_POST?
$list = array( 'use', 'type', 'status', 'bhk', 'baths', 'size', 'location', 'price', 'description' );
foreach ( $list as $name ) {
if ( $name != 'description' ) {
if( is_array( $_POST[$name] ) ) {
// I think you should also check for other types if needed (i.e. string)
$$name = filter_input( INPUT_POST , $name, FILTER_SANITIZE_NUMBER_INT , FILTER_REQUIRE_ARRAY );
} else {
$$name = filter_input( INPUT_POST , $name, FILTER_SANITIZE_NUMBER_INT );
}
} else if ( $name == 'description' ) {
$$name = filter_input( INPUT_POST , $name, FILTER_SANITIZE_STRING );
}
}
$area_1 = $size['area1'] != '' ? $size['area1'] : 0;
$area_2 = $size['area2'] != '' ? $size['area2'] : 0;
$city = $location['city'];
$zone = $location['zone'];
$sale = $price['sale'] != '' ? $price['sale'] : 0;
$rent = $price['rent'] != '' ? $price['rent'] : 0;
if you are not sure about the input, you can try the option FILTER_DEFAULT:
$$name = filter_input(INPUT_POST, $name, FILTER_DEFAULT , FILTER_REQUIRE_ARRAY)

Imploding Delimiters True Position (PHP)?

It's a function in my class. I have no idea for imploding $newConditions with ( OR ) ( AND ).
Anybody have an idea ?
// #GETSSQ = Get Secured Select Query
function getSSQ($query) {
$conDelimiters = array(' OR ',' AND '); // Condition Delimiters
$fivaDelimiters = array('LIKE','<=>','<>','=>','<=','!=','=','<','>'); // Field & Value delimiters {Operators}
$conditions = preg_split("/(".implode('|',$conDelimiters).")/", $query);
$newConditions = array();
$operator = array("operator" => null);
foreach ($conditions as $idx => $cond) {
$operator["index"] = strlen($cond);
foreach ($fivaDelimiters as $sym) {
$pos = strpos($cond,$sym);
if ($pos === false)
continue;
else {
if ($pos < $operator['index']) {
$operator['index'] = $pos;
$operator['operator'] = $sym;
}
}
}
// Operatör bölme işlemine devam et...
$parts = array();
if ($operator['operator'] === null) {
$error = array(
"error" => "Koşullar arası yazım hatası tespit edildi. [".$this->options['connectionType'].":".$query."]",
"code" => "008"
);
$this->showError($error);
continue;
} else {
$condParts = explode($operator['operator'],$cond);
foreach ($condParts as $idx => $val) {
$condParts[$idx] = trim($val);
}
$parts['field'] = $this->__getSSQ_editFields($condParts[0]);
$parts['operator'] = $this->__getSSQ_editOperators($operator['operator']);
$newValue = $condParts[1];
if (count($condParts) > 2) { // If condition value has an operator character set
unset($condParts[0]);
$newValue = implode($operator['operator'],$condParts);
}
if (preg_match("/^['|\"](.*?)['|\"]$/", $newValue)) { // If value has {'} or {"} character begin & end , remove it
$newValue = substr($newValue, 1, (strlen($newValue)-2));
}
$newValue = $this->__getSSQ_editValues($newValue);
$parts['value'] = $newValue;
} #ENDIF OPERATOR === NULL
$newConditions[] = $parts['field'].' '.$parts['operator'].' '.$parts['value'];
} #END FOREACH CONDITIONS
var_dump($newConditions);
}
For Example My Function :
$condition = "id=5 AND parentCategory=2 AND firstName LIKE 'B%' AND usingMobile = 'true'";
$db = new XXClass();
$db->getSSQ($condition);
This output =>
array (size=4)
0 => string 'id = '5'' (length=8)
1 => string 'parentCategory = '2'' (length=20)
2 => string 'firstName LIKE 'B%'' (length=19)
3 => string 'usingMobile = 'true'' (length=20)
I can reach Fields , Operators , Values with __getSSQ_editXXXXX functions

Warning: Creating default object from empty value error messages after upgrading PHP to 5.4 [duplicate]

This question already has answers here:
PHP 5.4: disable warning "Creating default object from empty value"
(4 answers)
Closed 9 years ago.
After I upgraded our Joomla site to the latest version of Xampp 1.8.2 and upgrading to PHP 5.4, I am now getting these error messages on the front end of the site. I tried Google and could not fix this issue. Can someone help me please! Code is below
Warning: Creating default object from empty value in C:\xampp\htdocs\modules\mod_wf_department\helper.php on line 71
<?php
/**
* #version 2.0 2012-04-17
* #package Joomla
* #subpackage Work Force
* #copyright (C) 2012 the Thinkery
* #license GNU/GPL see LICENSE.php
*/
defined('_JEXEC') or die('Restricted access');
require_once(JPATH_SITE.DS.'components'.DS.'com_workforce'.DS.'helpers'.DS.'employee.php');
require_once(JPATH_SITE.DS.'components'.DS.'com_workforce'.DS.'helpers'.DS.'html.helper.php');
require_once(JPATH_SITE.DS.'components'.DS.'com_workforce'.DS.'helpers'.DS.'query.php');
require_once(JPATH_SITE.DS.'components'.DS.'com_workforce'.DS.'helpers'.DS.'route.php');
require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_workforce'.DS.'classes'.DS.'admin.class.php');
jimport('joomla.utilities.date');
class modWFDepartmentHelper
{
function prepareContent( $text, $length=300 )
{
// strips tags won't remove the actual jscript
$text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text );
$text = preg_replace( '/{.+?}/', '', $text);
// replace line breaking tags with whitespace
$text = preg_replace( "'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", ' ', $text );
$text = strip_tags( $text );
if (strlen($text) > $length) $text = substr($text, 0, $length) . "...";
return $text;
}
function getEmployeesList( $where, $limitstart = 0, $limit = 9999, $sort = 'e.ordering', $order = 'ASC' )
{
$db = &JFactory::getDBO();
$department = new workforceHelperEmployee($db);
$department->setType('employees');
$department->setWhere( $where );
$department->setOrderBy( $sort, $order );
$employees = $department->getEmployee($limitstart,$limit);
return $employees;
}
function getList(&$params)
{
$count = (int) $params->get('count', 5);
$text_length = intval($params->get( 'preview_count', 75) );
$dept = (int) $params->get('department', 0);
$featured = (bool) $params->get('featured', 0);
if($params->get('random', 1)){
$sort = 'RAND()';
$order = '';
}else{
$sort = 'ordering';
$order = 'ASC';
}
$where = array();
if( $dept ) $where[] = 'e.department = '.$dept;
if( $featured) $where[] = 'e.featured = 1';
$rows = modWFDepartmentHelper::getEmployeesList($where,0,$count, $sort, $order);
$i = 0;
$lists = array();
if( $rows ){
foreach ( $rows as $row )
{
$lists[$i]->link = JRoute::_(WorkforceHelperRoute::getEmployeeRoute($row->id, $row->departmentid));
$lists[$i]->name = $row->name;
$lists[$i]->title = $row->position;
$lists[$i]->address = $row->street_address;
$lists[$i]->departmentname = $row->departmentname;
$lists[$i]->mainimage = $row->icon;
$prepared_text = modWFDepartmentHelper::prepareContent($row->bio, $text_length);
if($params->get('clean_desc', 0)){
$lists[$i]->introtext = modWFDepartmentHelper::sentence_case($prepared_text);
}else{
$lists[$i]->introtext = $prepared_text;
}
$i++;
$prepared_text = '';
}
}
return $lists;
}
function sentence_case($string)
{
$sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string .= ($key & 1) == 0?
ucfirst(strtolower(trim($sentence))) :
$sentence.' ';
}
return trim($new_string);
}
}
I don't believe you properly researched this error before asking your question (see here), but to fix it you need to initialise $lists[$i] to an object before assigning to its properties - change
foreach ($rows as $row) {
$lists[$i]->link = JRoute::_(WorkforceHelperRoute::getEmployeeRoute($row->id, $row->departmentid));
to
foreach ($rows as $row) {
$lists[$i] = new stdClass(); // initialise $lists[$i] to a new object
$lists[$i]->link = JRoute::_(WorkforceHelperRoute::getEmployeeRoute($row->id, $row->departmentid));
PHP allows you to create properties on the fly like this, but only if the variable ($lists[$i] in this case) is already an object.

Categories