Friday 28 February 2014

Function to add the Error Log into Custom Log File in Joomla 3.0

Function to add the Error Log into Custom Log File in Joomla 3.0
function addErrorToLog($message='')
{
 $data = date('Y-m-d H.i.s'). "\t INFO \t\t ".$_SERVER['REMOTE_ADDR']." \t\t Message: ".$message;
 
 $log_path = JFactory::getApplication()->getCfg('log_path');
 $logfile_path = $log_path . '\com_locator.formbridge.log.php';
 
 if ( !file_exists($logfile_path) )  // if file is not exist.
 {
  $ini_data = "#\n" .
     "#\n" .
     "#Date: 28.02.2014 13:46:29 UTC\n" .
     "#WebApp: Form Bridge (Joomla Platform) 1.0 Stable [ IRC Adhikari ] 28.02.2014 00:00 GMT\n\n".
     "#Fields: date time \t priority \t clientip \t category : message\n";
  $error =  file_put_contents($logfile_path, (PHP_EOL . $ini_data . $data) );
 } else // If file already exist, add the data into existing file.
 {
  $error = file_put_contents($logfile_path, (PHP_EOL . $data), FILE_APPEND | LOCK_EX);
 }

 return true;
}
$this->addErrorToLog($message=' This is test message ');

Function to update the DB Table Record in Joomla 3.0+

// Function to update the DB Table Records in Joomla 3.0+ by passing the data in arrays
protected function updateTableRecordByClauses($fields, $table, $where=array())
{
 $this->db = JFactory::getDBO();
 
 $query = "UPDATE ".$table." SET %s WHERE %s";
 
 $fields = array();
 foreach ($fields as $key => $val ) :
  $fields[] = $this->db->quoteName($key) . '=\''.$val.'\'';
 endforeach;
 
 // Conditions for which records should be updated.
 $conditions = array();
 foreach ($where as $key => $val ) :
  $conditions[] = $this->db->quoteName($key) . '=\''.$val.'\'';
 endforeach;
 
 $this->db->setQuery( $query = sprintf($query, implode(",", $fields), implode(" AND ", $conditions)) );
 $result = $this->db->execute();

 return $result;
}
// To call the function 
 $fields = array('Status'=>'Approved');
 $whereClause = array('SubmissionId' => 12 'FieldName' => 'Membership', 'FieldValue' => 'Pending');
 $this->updateTableRecordByClauses($fields, '#__users_submission', $whereClause);


// Function to update the Single Where Clause.
protected function updateTableRecord($locationObj, $table)
{
 $this->db = JFactory::getDBO();
 // Update a new query object.
 $result = $this->db->updateObject($table, $locationObj, 'id');
 // $id = (int)$this->db->insertid();
 
 return $result;
}
 // Update the user record into '__users' table.
 $dataObj = new stdClass();
 $dataObj->id = $myfields['UserId'];
 $dataObj->lastResetTime = $location_id;
 $dataObj->block = $myfields['Country'];
 $dataObj->updated = date('Y-m-d H:i:s');
 $this->updateTableRecord($dataObj, '#__users');

Wednesday 26 February 2014

Get Geocodes Latitude and Longitude using PHP (via Google API)

The below function pulls the Geocode Location Latitude and Longitude values using PHP. It uses the Google API to pull those Geo co-ordinates.
 function getLatLogOfAddress($address='')
 {
  $address = urlencode($address);
  
  //here is the google api url
  $url = "http://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false";
  
  //get the content from the api using file_get_contents
  $getmap = file_get_contents($url);
  
  //the result is in json format. To decode it use json_decode
  $googlemap = json_decode($getmap);

  $data = array();
  //get the latitute, longitude, address from google api's json result 
  $googlemap = isset($googlemap->results[0]) ? $googlemap->results[0] : '';
  $data['lat'] = isset($googlemap->geometry->location->lat) ? $googlemap->geometry->location->lat : '';
  $data['lng'] = isset($googlemap->geometry->location->lng) ? $googlemap->geometry->location->lng : ''; 
  $data['address'] = isset($googlemap->formatted_address) ? $googlemap->formatted_address : $address;
  
  return $data;
 }

// Call the function as below;
 $address = "Apollo Victoria Theatre, 17 Wilton Road, Westminster, London, SW1V 1LG, UK";
 $geocodes = $this->getLatLogOfAddress($address);
 print_r($geocodes);
 
// The Result would be...
 Array
 (
     [lat] => 51.4957746
     [lng] => 51.4957746
     [address] => London SW1V 1LG, UK
 ) 

Monday 24 February 2014

How the HTTP Live Streaming works: The Basics of HTTP Live Streaming

The research for this article started when some of my subscription users started complaining that they could only see a few minutes of one of my longer webinars before they needed to reset their browser. At first, I thought this was caused by bad programming on our part. But, further research made me realize that iOS devices only stream about 10 minutes of continuous video content when they are connected to a cellular data network, then they stop.
Period.
This article explains why. (If you want a more technical explanation, read this Apple Support Note.)
NOTE: If any of the following conditions are true, you can ignore this article:
  • You stream all your videos off YouTube, Vimeo, or other commercial streaming service
  • Your videos run less than 10 minutes
  • No one watches your videos on an iOS mobile device (apparently, Android devices don’t have this limitation).
Understanding Live Streaming isn’t easy, but it isn’t impossible, and this article provides a cookbook you can follow which makes a lot of it fairly simple.
SOME BACKGROUND
There are two types of web video:
  • Progressive downloads
  • Streaming video

Find more on below link:

Referred: The Basics of HTTP Live Streaming