db=& $db;
}
function processOviList ($polist,$device,$itype=""){
// Loop through the list.
$c= "0";
while (isset ($polist['oid'][$c])){
echo "
Processing ".$polist['title'][$c]." [".$polist['oid'][$c]."]";
// Check if already exists - based on OviStore ID
// 0 does not exist at all
// 1 is exists with parse list
// 2 is exists with parse item
// 3 parsed both
$exist = $this->entryExist ($polist['oid'][$c]);
if ($exist['rmsg'] =="1"){
// already parsed with list
if (in_array($device,$exist['devices'])){
$this->msg.="
Device already added";
} else {
$this->addDevice($device,$exist['entry_id'],$polist['oid'][$c]);
}
// Get an item, parse and process
// This should not occur
} elseif ($exist['rmsg'] =="3"){
// Item has already been parsed, but we may need to add new info
$this->msg.="
Item already fully parsed [".$polist['oid'][$c]."]";
// Checks and adds devices if necessary
if (in_array($device,$exist['devices'])){
$this->msg.="
Device already added";
} else {
$this->addDevice($device,$exist['entry_id'],$polist['oid'][$c]);
}
// Check for pricing info - add price if necessary
// For UK
if ($exist['ovi_UK']=="0" && $polist['geo'][$c]=="UK" ){
$iprice = $this->formatPrice($polist['price'][$c]);
$this->writePrice ($iprice,"UK",$exist['entry_id']);
// For US
} elseif ($exist['ovi_US']=="0" && $polist['geo'][$c]=="US" ){
$iprice = $this->formatPrice($polist['price'][$c]);
$this->writePrice ($iprice,"US",$exist['entry_id']);
}
} elseif ($exist['rmsg'] =="0"){
// Completey new Add to database
$igeo = $polist['geo'][$c];
// Clean up price string
$iprice = $this->formatPrice($polist['price'][$c]);
// Set pricing field for database
if ($igeo == "US"){
$iusprice = $iprice;
$iUS = "2";
$iukprice = "";
$iUK = "0";
} elseif($igeo == "UK"){
$iukprice = $iprice;
$iUK = "2";
$iusprice = "";
$iUS = "0";
}
// author furl
$authorfurl = str_replace("http://store.ovi.com/publisher/",'',$polist['authorurl'][$c]);
$authorfurl = str_replace('/','',$authorfurl);
// Image copy / pocess
$poiconurl = $this->copyImg($polist['iconurl'][$c], $polist['oid'][$c], "icon");
if ($poiconurl == "0"){
// Image copy failed
// Flag for attention.
$iconcopy = "0";
// Set icon to Ovi server
$poiconurl = $polist['iconurl'][$c];
} else {
$iconcopy = "1";
}
// echo "

";
// Set the pase as complete for list pasrse - differentiates from an item parse/
$oilparse ="1";
// Put things into an array
$dentry = array ('oid'=>$polist['oid'][$c],
'title'=>$polist['title'][$c],
'furl'=>$this->furl($polist['title'][$c]),
'desc'=>$polist['description'][$c],
'author'=>$polist['author'][$c],
'authorurl'=>$polist['authorurl'][$c],
'authorfurl'=>$authorfurl,
'cat'=>$polist['cat'][$c],
'type'=>$itype,
'isUK'=>$iUK,
'priceUK'=>$iukprice,
'isUS'=>$iUS,
'priceUS'=>$iusprice,
'icon'=>$poiconurl,
'icon_c'=>$iconcopy,
'parse_l'=>$oilparse
);
// Add to database
$addid= $this->entryAdd($dentry);
// Device
$this->addDevice($device,$addid,$polist['oid'][$c]);
// Item Parse
$piurl = "http://store.ovi.com/content/".$polist['oid'][$c]."?terminalId=".$device."";
$ipres = $this->parseOviItemShort ($piurl,$polist['geo'][$c]);
// Item Process (size and images)
$this->processOviItemShort ($ipres,$polist['oid'][$c]);
// Checking if its OAW, if it is set type and validate automatically
if ($ipres['ovi_osaw'] =="1"){
$this->msg.="
Auto-detected and validated OAW";
// Identifies platfrom and then adds as appropriate
$pres = $this->identifyPlatform($addid);
if ($this->isplatform['s603']=="1"){
foreach ($this->oawcs603 as $device_to_add){
$this->addDevice($device_to_add,$addid,$polist['oid'][$c]);
}
}
if ($this->isplatform['s605']=="1"){
foreach ($this->oawcs605 as $device_to_add){
$this->addDevice($device_to_add,$addid,$polist['oid'][$c]);
}
foreach ($this->oawcsy3 as $device_to_add){
$this->addDevice($device_to_add,$addid,$polist['oid'][$c]);
}
}
if ($this->isplatform['sy3']=="1"){
// Do nothing for now pending new OAW X7 etc.
}
// Set aa_type as 2
$amsg = $this->aatypeUpdate("2",$addid);
// Set entry as validated
$vmsg = $this->validatedUpdate ("1",$addid);
} else {
// Do a validation baed on title
// Only do this wehn everything else has been added
$aValid = array('-', ' ',':','(',')','.','<','>','^','/');
if(ctype_alnum(str_replace($aValid, '', $polist['title'][$c]))) {
$vmsg = $this->validatedUpdate ("1",$addid);
}
}
sleep(1);
}
// end add to database
echo $this->msg;
$this->msg="";
flush();
// slight pause
$timenow = time();
echo "
Time: ".$timenow."
";
$c = $c + 1;
}
sleep (2);
}
function iconUpdate ($niconurl,$noid){
if ($noid !=""){
$sql="UPDATE entries
SET icon_c='1', ovi_icon='".$niconurl."'
WHERE ovi_id='".$noid."'";
$result=$this->db->query($sql);
echo "Updated DB";
} else {
echo "No ID specified";
}
}
function aatypeUpdate ($aatype,$eid){
if ($eid !=""){
$sql="UPDATE entries
SET aa_type='".$aatype."'
WHERE entry_id='".$eid."'";
$result=$this->db->query($sql);
return "aa_type Set to ".$aatype." for Entry ID: ".$eid;
} else {
return "No Entry ID specified or other error";
}
}
function validatedUpdate ($validated,$eid){
if ($validated !="" && $eid !=""){
$sql="UPDATE entries
SET validated='".$validated."'
WHERE entry_id='".$eid."'";
$result=$this->db->query($sql);
return "validated set to ".$validated." for Entry ID: ".$eid;
} else {
return "No Entry ID specified or other error";
}
}
function featuredUpdate ($featured,$eid){
if ($featured !="" && $eid !=""){
$sql="UPDATE entries
SET featured='".$featured."'
WHERE entry_id='".$eid."'";
$result=$this->db->query($sql);
return "featured set to ".$featured." for Entry ID: ".$eid;
} else {
return "No Entry ID specified or other error";
}
}
function formatPrice($fprice){
// remove currency symbol and price extras
$curr = array("£ ","$ "," (incl. taxes)"); // Get rid of $ and £
$iprice = str_replace($curr,'',$fprice);
// Change Free to 0
if ($iprice == "Free"){
$iprice = "0";
}
return $iprice;
}
function writePrice ($wprice,$geo,$eid){
$wprice = number_format ($wprice,2);
if ($eid !=""){
if ($geo=="UK"){
$sql="UPDATE entries SET ovi_UK='2', ovi_price_UK='".$wprice."' WHERE entry_id='".$eid."'";
$result=$this->db->query($sql);
$this->msg.="
UK Price Added - £".$wprice;
} elseif ($geo="US"){
$sql="UPDATE entries SET ovi_US='2', ovi_price_US='".$wprice."' WHERE entry_id='".$eid."'";
$result=$this->db->query($sql);
$this->msg.="
US Price Added - $".$wprice;
}
}
}
function entryAdd($d){
$time = time();
$sql="INSERT INTO
entries
SET
ovi_id='".$d['oid']."',
ovi_title='".$d['title']."',
ovi_furl='".$d['furl']."',
ovi_desc='".$d['desc']."',
ovi_author='".$d['author']."',
ovi_authorurl='".$d['authorurl']."',
ovi_author_furl='".$d['authorfurl']."',
ovi_cat='".$d['cat']."',
ovi_type='".$d['type']."',
ovi_UK='".$d['isUK']."',
ovi_price_UK='".$d['priceUK']."',
ovi_US='".$d['isUS']."',
ovi_price_US='".$d['priceUS']."',
ovi_icon='".$d['icon']."',
icon_c='".$d['icon_c']."',
parse_l='".$d['parse_l']."',
ovi_time='".$time."'";
$result=$this->db->query($sql);
$jid = mysql_insert_id();
$this->msg.="
Added to Entry DB Sucessfully [".$jid."]";
// If this is a news item adds the itemid to the furl so it can be crawled by Google news.
return $jid;
}
function entryExist ($eoid){
$ildevices = array();
$eovi_UK = "";
$eovi_US = "";
$sql="SELECT entry_id, ovi_id, parse_l, parse_i, ovi_UK, ovi_US
FROM entries
WHERE ovi_id='".$eoid."'";
$result=$this->db->query($sql);
if ($result->size() < 1){
$this->msg.="
Does not exist at all";
$rmsg = "0";
$entry_id = "";
} else {
$row=$result->fetch();
$eovi_UK = $row['ovi_UK'];
$eovi_US = $row['ovi_US'];
if($row['parse_i']=="1" && $row['parse_l']=="1"){
$this->msg.="
Exists both parsed";
$rmsg = "3";
$entry_id = $row['entry_id'];
} elseif($row['parse_i']=="1"){
$this->msg.="
Exists parse item";
$rmsg = "2";
$entry_id = $row['entry_id'];
}elseif ($row['parse_l']=="1"){
$this->msg.="
Exists parse list";
$rmsg = "1";
$entry_id = $row['entry_id'];
}
$sql2="SELECT dev_name
FROM 2devices
WHERE ovi_id='".$eoid."'";
$result2=$this->db->query($sql2);
while ($row2=$result2->fetch()) {
$ildevices[]=$row2['dev_name'];
}
}
$exist_result = array ('rmsg'=>$rmsg,'entry_id'=>$entry_id,'devices'=>$ildevices, 'ovi_UK'=>$eovi_UK,'ovi_US'=>$eovi_US,);
return $exist_result;
}
function addDevice($devicetoadd, $entryid, $dovi_id,$dtime="0") {
if ($dtime=="0"){
$dtime = time();
}
if ($devicetoadd !="" && $entryid !="" && $dovi_id !="" && $dtime !="0"){
$sql="INSERT IGNORE INTO
2devices
SET
entry_id='".$entryid."',
ovi_id='".$dovi_id."',
dev_name='".$devicetoadd."',
dev_time='".$dtime."'";
$result=$this->db->query($sql);
$this->msg.="
Added device [".$devicetoadd."]";
} else {
$this->msg.="
Did not add - missing variable.";
}
}
function parseOviList($url,$geo="US"){
echo "Parsing: ".$url."
";
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11 GTB7.0 (.NET CLR 3.5.30729)";
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_COOKIE, "view=List; JNPRSESSID=b551l8ta7k1of87r9cfd9sb381;");
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Put through proxy if applicable
if ($geo=="UK"){
echo "
UK Proxy";
curl_setopt($ch, CURLOPT_PROXY, '95.154.211.201');
curl_setopt($ch, CURLOPT_PROXYPORT, '31013');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'pp-qadallak:jehuelso');
}
$output = curl_exec ($ch);
// create HTML DOM
$html = str_get_html($output);
// Get List HTML
$relatedItems = $html->find('ol.entityList',0);
// Go through items
if (!empty($relatedItems)){
$hdlo="";
$ovilist = array();
foreach ($relatedItems->find('li.entity') as $rli)
{
// echo $rli;
$ritemurl = trim($rli->find('a', 0)->href);
$ritemurl = $this->deQueryURL($ritemurl);
// Ovi Item ID
$ritemoid = strrchr($ritemurl,'/');
$ritemoid = str_replace('/','',$ritemoid);
$riconurl = trim($rli->find('img', 0)->src);
$riconurl = $this->deQueryURL($riconurl);
$rtitle = trim($rli->find('a', 1)->innertext);
$rdescription = trim($rli->find('.summary', 0)->innertext);
$rauthor = trim($rli->find('.publisher', 0)->innertext);
$rauthorurl = trim($rli->find('.publisher', 0)->href);
$rauthorurl = $this->deQueryURL($rauthorurl);
$rcat2 = trim($rli->find('.entityType', 0)->innertext);
$rprice = trim($rli->find('.price', 0)->innertext);
//Short write out
echo $rtitle." (".$ritemoid.")
";
//Long write out
// echo "".$rtitle." - ".$rauthor." - ".$rcat2." - ".$rprice." - ".$ritemoid."
".$rdescription."
".$rauthorurl."
".$ritemurl."
".$riconurl."
";
// array builder for item list
$ovilist['oid'][] = $ritemoid;
$ovilist['title'][] = $rtitle;
$ovilist['description'][] = $rdescription;
$ovilist['author'][] = $rauthor;
$ovilist['authorurl'][] = $rauthorurl;
$ovilist['cat'][] = $rcat2;
$ovilist['price'][] = $rprice;
$ovilist['itemurl'][] = $ritemurl;
$ovilist['iconurl'][] = $riconurl;
$ovilist['geo'][] = $geo;
$hdlo="1";
}
if ($hdlo !="1"){
$ovilist ="e";
}
} else {
$ovilist ="e";
}
// clean up memory
$html->clear();
unset($html);
// print_r($ovilist);
return $ovilist;
}
function parseOviItem($url,$geo="US",$doRelated="0"){
echo "Parsing Item: ".$url."
";
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11 GTB7.0 (.NET CLR 3.5.30729)";
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_COOKIE, "view=List; JNPRSESSID=b551l8ta7k1of87r9cfd9sb381;");
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
// create HTML DOM
$html = str_get_html($output);
//echo $html;
//Check warning
$owarning = trim ($html->find('.warning',0)->innertext);
//echo $owarning;
// Country warning
if (strpos($owarning,"country")!== FALSE){
echo "Country warning
";
$ovierror = "c";
$oviitem = array ('error'=>$ovierror);
// Device warning
} elseif (strpos($owarning,"not available")!== FALSE){
echo "Device warning
";
$ovierror = "d";
$oviitem = array ('error'=>$ovierror);
// Its OK Get Information
} else {
//Get Item HTML
$sectionItem = $html->find('.sectionContent',0);
// Category
if (!empty($sectionItem)){
$oscat1 = trim($sectionItem->find('a', 1)->innertext);
$oscat2 = trim($sectionItem->find('a', 2)->innertext);
$oscaturl = trim($sectionItem->find('a', 2)->href);
$catcut = strripos($oscaturl,"Id=")+3;
$oscatid = substr($oscaturl,$catcut);
}
// Images
$contentItem = $html->find('.contentItem',0);
if (!empty($contentItem)){
$osimg1 = trim($contentItem->find('img', 0)->src);
@$osimg2 = trim($contentItem->find('a', 1)->href);
@$osimg3 = trim($contentItem->find('a', 2)->href);
$osimg1 = $this->deQueryURL($osimg1);
$osimg2 = $this->deQueryURL($osimg2);
$osimg3 = $this->deQueryURL($osimg3);
}
// Secription
$contentDesc = $html->find('.contentDescription',0);
if (!empty($contentDesc)){
$ostitle = trim($contentDesc->find('h1', 0)->innertext);
$ossize = trim($contentDesc->find('p', 1)->innertext);
$osdescription = trim($contentDesc->find('p', 2)->innertext);
$osprice = trim($html->find('.price', 0)->innertext);
$ossize = strstr($ossize,' - ');
$ossize = str_replace(' - ','',$ossize);
$ossize = str_replace(' MB','',$ossize);
}
// Publisher
$authorDesc = $html->find('.createdBy',0);
if (!empty($authorDesc)){
$osauthorname = trim($authorDesc->find('a', 0)->innertext);
$osauthorurl = trim($authorDesc->find('a', 0)->href);
}
// Print out Item
echo "General
".$ostitle."
".$ossize."
".$osdescription."
".$osprice."
";
echo "Author
".$osauthorname."
".$osauthorurl."
";
echo "Category
".$oscat1."
".$oscat2."
".$oscaturl."
";
echo "Images
".$osimg1."
".$osimg2."
".$osimg3."
";
}
$ovilist = array();
if ($doRelated == "1"){
echo "Parsing Related: ".$url."
";
// Get related
$relatedItems = $html->find('ol.entityList',0);
// echo $relatedItems;
// Loop through related one by one
foreach ($relatedItems->find('li.entity') as $rli)
{
// echo $rli;
$ritemurl = trim($rli->find('a', 0)->href);
$ritemurl = $this->deQueryURL($ritemurl);
// Ovi Item ID
$ritemoid = strrchr($ritemurl,'/');
$ritemoid = str_replace('/','',$ritemoid);
$riconurl = trim($rli->find('img', 0)->src);
$riconurl = $this->deQueryURL($riconurl);
$rtitle = trim($rli->find('a', 1)->innertext);
$rdescription = trim($rli->find('.summary', 0)->innertext);
$rauthor = trim($rli->find('.publisher', 0)->innertext);
$rauthorurl = trim($rli->find('.publisher', 0)->href);
$rauthorurl = $this->deQueryURL($rauthorurl);
$rcat2 = trim($rli->find('.entityType', 0)->innertext);
$rprice = trim($rli->find('.price', 0)->innertext);
// short ouput
echo $rtitle." (".$ritemoid.")
";
// Long from ouput
// echo "".$rtitle." - ".$rauthor." - ".$rcat2." - ".$rprice." - ".$ritemoid."
".$rdescription."
".$rauthorurl."
".$ritemurl."
".$riconurl."
";
// array builder for item list
$ovilist['oid'][] = $ritemoid;
$ovilist['title'][] = $rtitle;
$ovilist['description'][] = $rdescription;
$ovilist['author'][] = $rauthor;
$ovilist['authorurl'][] = $rauthorurl;
$ovilist['cat'][] = $rcat2;
$ovilist['price'][] = $rprice;
$ovilist['itemurl'][] = $ritemurl;
$ovilist['iconurl'][] = $riconurl;
$ovilist['geo'][] = $geo;
}
}
// Put things into an array
$oviitem = array ('title'=>$ostitle,
'description'=>$osdescription,
'oviitme'=>$ossize,
'price'=>$osprice,
'type'=>$oscat1,
'category'=>$oscat2,
'category_url'=>$oscaturl,
'category_id'=>$oscatid,
'img1'=>$osimg1,
'img2'=>$osimg2,
'img3'=>$osimg3,
'geo'=>$geo,
'related'=>$ovilist
);
// clean up memory
$html->clear();
unset($html);
// print_r($oviitem);
return $oviitem;
}
function parseOviItemShort($url,$geo="US"){ // Short version
$this->msg .= "
Parsing Item: ".$url."";
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11 GTB7.0 (.NET CLR 3.5.30729)";
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_COOKIE, "view=List; JNPRSESSID=b551l8ta7k1of87r9cfd9sb381;");
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
// create HTML DOM
$html = str_get_html($output);
// echo $html;
//Check warning
$owarning = trim ($html->find('.warning',0)->innertext);
// echo $owarning;
// Country warning
if (strpos($owarning,"country")!== FALSE){
$ovierrmsg = "Country warning (not available)";
$ovierror = "c";
$oviitem = array ('error'=>$ovierror, 'errormsg'=>$ovierrmsg);
// Device warning
} elseif (strpos($owarning,"not available")!== FALSE){
$ovierrmsg = "Device warning (not compatible)";
$ovierror = "d";
$oviitem = array ('error'=>$ovierror, 'errormsg'=>$ovierrmsg);
// Its OK Get Information
} else {
//Get Item HTML
$sectionItem = $html->find('.sectionContent',0);
// Category
if (!empty($sectionItem)){
$oscat1 = trim($sectionItem->find('a', 1)->innertext);
$oscat2 = trim($sectionItem->find('a', 2)->innertext);
$oscaturl = trim($sectionItem->find('a', 2)->href);
$catcut = strripos($oscaturl,"Id=")+3;
$oscatid = substr($oscaturl,$catcut);
}
// Images
$contentItem = $html->find('.contentItem',0);
if (!empty($contentItem)){
$osimg1 = trim($contentItem->find('img', 0)->src);
@$osimg2 = trim($contentItem->find('a', 1)->href);
@$osimg3 = trim($contentItem->find('a', 2)->href);
$osimg1 = $this->deQueryURL($osimg1);
$osimg2 = $this->deQueryURL($osimg2);
$osimg3 = $this->deQueryURL($osimg3);
}
// Size and Qt
$contentDesc = $html->find('.contentDescription',0);
// echo $contentDesc;
if (!empty($contentDesc)){
// Qt potential
$p1info = trim($contentDesc->find('p', 0)->innertext);
//echo $p1info;
$p1pos = strpos($p1info,"large one-time update");
if($p1pos) {
$qtflag="1";
} else {
$qtflag="0";
}
// Size
$ossize = trim($contentDesc->find('p', 1)->innertext);
$cpos = strpos($ossize," MB");
// This checks whether size in this para, sometimes not because of Qt warning message.
$parapos = "1";
if($cpos === false) {
// string needle NOT found in haystack so set to para 2
$ossize = trim($contentDesc->find('p', 2)->innertext);
$parapos = "2";
}
$ossize = strstr($ossize,' - ');
$ossize = str_replace(' - ','',$ossize);
$ossize = str_replace(' MB','',$ossize);
// title
$ostitle = trim($contentDesc->find('h1', 0)->innertext);
// Description
$osdescription = trim($contentDesc->find('p', $parapos+3)->innertext);
$osratnum = trim($contentDesc->find('p', $parapos+1)->innertext);
$osratscore = trim($contentDesc->find('p', $parapos+2)->innertext);
// Price
$osprice = trim($html->find('.price', 0)->innertext);
}
// Publisher support
$pubContact = $html->find('.publisherContactTop',0);
// Assumed to not be OAW
$osaw = "0";
if (!empty($pubContact)){
$ossuppet = trim($pubContact->find('a', 1)->href);
$ossuppet = str_replace('mailto:','',$ossuppet);
$ossuppe = $ossuppet;
$ossuppw = trim($pubContact->find('a', 0)->href);
if ($ossuppw == "http://www.ovi.com/appwizard"){
$osaw = "1";
}
} else {
// Allow for pages without the support details
$ossuppe="";
$ossuppw="";
}
/* Print out Item
echo "General
".$ostitle."
".$ossize."
".$osdescription."
".$osprice."
";
echo "Author
".$osauthorname."
".$osauthorurl."
";
echo "Category
".$oscat1."
".$oscat2."
".$oscaturl."
";
echo "Images
".$osimg1."
".$osimg2."
".$osimg3."
";
*/
// Put things into an array
$oviitem = array ('size'=>$ossize,
'ovi_type'=>$oscat1,
'category_url'=>$oscaturl,
'category_id'=>$oscatid,
'img1'=>$osimg1,
'img2'=>$osimg2,
'img3'=>$osimg3,
'ovi_support_w'=>$ossuppw,
'ovi_support_e'=>$ossuppe,
'ovi_osaw'=>$osaw,
'ovi_tech'=>$qtflag,
'ovi_title'=>$ostitle,
'ovi_rate_num'=>$osratnum,
'ovi_rate_score'=>$osratscore,
'ovi_description'=>$osdescription,
'ovi_price'=>$osprice
);
}
// clean up memory
$html->clear();
unset($html);
// print_r($oviitem);
return $oviitem;
}
function processOviItemShort ($ipres,$roid){
//print_r($ipres);
if (isset ($ipres['error'])){
//echo "error";
$this->msg.="
ERROR: ".$ipres['errormsg']." [".$roid."]";
} else {
// Image copy / pocess
$i_img_1 = $ipres['img1'];
$i_img_2 = $ipres['img2'];
$i_img_3 = $ipres['img3'];
$imgcpy = "0";
/*
// IMAGE 1
$i_img_1 = $this->copyImg($ipres['img1'], $roid, "screen-1");
if ($i_img_1 == "0"){
// Image copy failed
// Flag for attention.
$imgcpy = "0";
// Set icon to Ovi server
$i_img_1 = $ipres['img1'];
} else {
$imgcpy = "1";
}
// IMAGE 2
if ($ipres['img2'] !=""){
$i_img_2 = $this->copyImg($ipres['img2'], $roid, "screen-2");
if ($i_img_2 == "0"){
// Image copy failed
// Flag for attention.
$imgcpy = "0";
// Set icon to Ovi server
$i_img_2 = $ipres['img2'];
} else {
$imgcpy = "1";
}
} else {
$i_img_2 = "";
}
// IMAGE 3
if ($ipres['img3'] !=""){
$i_img_3 = $this->copyImg($ipres['img2'], $roid, "screen-3");
if ($i_img_3 == "0"){
// Image copy failed
// Flag for attention.
$imgcpy = "0";
// Set icon to Ovi server
$i_img_3 = $ipres['img3'];
} else {
$imgcpy = "1";
}
} else {
$i_img_3 = "";
}
*/
// Database update
$oiaa_type = "0";
if ($ipres['ovi_type']=="Applications"){
$oiaa_type = "1";
} elseif ($ipres['ovi_type']=="Games"){
$oiaa_type = "4";
} elseif ($ipres['ovi_type']=="Personalisation"){
$oiaa_type = "5";
} elseif ($ipres['ovi_type']=="Audio & video"){
$oiaa_type = "6";
}
$sql="UPDATE
entries
SET
ovi_size='".$ipres['size']."',
ovi_type='".$ipres['ovi_type']."',
aa_type='".$oiaa_type."',
ovi_cat_url='".$ipres['category_url']."',
ovi_cat_id='".$ipres['category_id']."',
ovi_img_1='".$i_img_1."',
ovi_img_2='".$i_img_2."',
ovi_img_3='".$i_img_3."',
img_c='".$imgcpy."',
ovi_support_w='".$ipres['ovi_support_w']."',
ovi_support_e='".$ipres['ovi_support_e']."',
ovi_tech='".$ipres['ovi_tech']."',
ovi_rate_num='".$ipres['ovi_rate_num']."',
ovi_rate_score='".$ipres['ovi_rate_score']."',
parse_i='1'
WHERE
ovi_id='".$roid."'";
$result=$this->db->query($sql);
//echo "added item parse info";
$this->msg.="
Added item information [".$roid."]";
}
echo $this->msg;
$this->msg="";
}
// Updates Item with Qt, Rating and and support info only
// This is a fix for older content
function updateOviItemBits ($ipres,$roid){
if (isset ($ipres['error'])){
//echo "error";
$this->msg.="
ERROR: ".$ipres['errormsg']." [".$roid."]";
} else {
$sql="UPDATE
entries
SET
ovi_support_w='".$ipres['ovi_support_w']."',
ovi_support_e='".$ipres['ovi_support_e']."',
ovi_tech='".$ipres['ovi_tech']."',
ovi_rate_num='".$ipres['ovi_rate_num']."',
ovi_rate_score='".$ipres['ovi_rate_score']."'
WHERE
ovi_id='".$roid."'";
//echo $sql;
$result=$this->db->query($sql);
//echo "added item parse info";
$this->msg.="
Updated Qt, Contact and rating item information [".$roid."]";
}
echo $this->msg;
$this->msg="";
}
function deQueryURL($dqurl){
$sc = strpos ($dqurl,'?');
return substr($dqurl,0,$sc);
}
function copyImg ($weburl,$oid="misc",$itype=""){
// Allow for query strongs on URLs
$pos1 = stripos($weburl, "?");
if ($pos1 !=""){
$weburl = substr($weburl,0,$pos1);
}
// Folder handling
$oifolder = "/home/allabout/public_html/images/oimg2/".$oid."/";
if (file_exists($oifolder)){
//Folder already exists
} else {
mkdir ($oifolder,0777);
}
// Image info
$pos2 = strripos($weburl, ".");
if ($pos2 !=""){
$oiformat = substr($weburl,$pos2);
}
// Copy to local
// Returns filename or FALSE
$fn = $oifolder.$itype."-".$oid;
$cf = copy ($weburl, $fn.$oiformat);
// echo "
".$weburl."
";
// echo "
http://www.allaboutsymbian.com/images/oimg/".$oid."/".$itype."-".$oid.$oiformat."
";
if (filesize ($fn.$oiformat) < 100){
$this->msg.="
Error: File copy failed. Trying alt method.";
//original image
//$qdata = file_get_contents($weburl);
//$qfile = fopen($fn.$oiformat, "w+");
//fputs($qfile, $qdata);
//fclose($qfile);
// sleep(1);
$lfile = fopen($fn.$oiformat, "w");
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $weburl);
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
curl_setopt($ch2, CURLOPT_FILE, $lfile);
// curl_exec($ch2);
// print_r(curl_getinfo($ch2));
fclose($lfile);
curl_close($ch2);
if (filesize ($fn.$oiformat) < 100){
$this->msg.=" Alt method failed too. Original URL applied.";
$cf=0;
}
}
// echo "File OK";
if ($cf == TRUE){
$this->msg.="
Image copied sucessfully [".$itype."][".$oid."]";
// do resizing if its an icon.
if ($itype == "icon"){
// Begin
$img = new imagingresize;
$img->set_img($fn.$oiformat);
$img->set_quality(80);
// Small thumbnail
$img->set_size(64);
$img->save_img($fn."-64x64".$oiformat);
// Baby thumbnail
$img->set_size(32);
$img->save_img($fn."-32x32".$oiformat);
// Finalize
$img->clear_cache();
}
$retimg = "http://www.allaboutsymbian.com/images/oimg2/".$oid."/".$itype."-".$oid.$oiformat;
return $retimg;
} else {
return $cf;
}
}
function furl($title) {
$furl = ereg_replace("[^[:space:]a-zA-Z0-9-]", "", $title);
$furl = str_replace(" - ", "-", $furl);
$furl = str_replace(" ", "_", $furl);
// Check for duplicate FURLs
$repeat = "1";
$furlr = $furl;
// This loop checks to see if the furl already exists if it does it add n and checks again. Ensure no repeated FURLs
while ($repeat !="") {
$sql="SELECT ovi_id
FROM entries
WHERE ovi_furl='".$furl."'";
$result=$this->db->query($sql);
if ($result->size() < 1){
$repeat = "";
} else {
$furl = $furlr;
$furl .= "_".$repeat;
$repeat = $repeat +1;
}
}
return $furl;
}
function checkDeviceCompat ($oviid, $entryid, $device, $geo="US"){
$exist = $this->entryExist ($oviid);
if ($exist['rmsg'] =="3"){
// already fully
if (in_array($device,$exist['devices'])){
$dmsg = "Device already added [".$device."]";
} else {
// Check for device compatibility
// Build URL to check and parse page
$piurl = "http://store.ovi.com/content/".$oviid."?terminalId=".$device."";
// echo "Checking";
$dresult = $this->parseOviItemDevice ($piurl,$geo);
// print_r($dresult);
// Deal with result
if ($dresult[result]=="1"){
// Yes
$this->addDevice($device,$entryid,$oviid);
$dmsg = "Result: Added [".$device."]";
} else {
$dmsg = "Result: (".$dresult[result].") ".$dresult[errormsg] ." [".$device."]";
}
}
} else {
$dmsg = "Item does not exist in AAS Entry DB";
}
return $dmsg;
}
function parseOviItemDevice($url,$geo){ // Short version
// "
Parsing Item: ".$url."";
// Get the page in question
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11 GTB7.0 (.NET CLR 3.5.30729)";
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_COOKIE, "view=List; JNPRSESSID=b551l8ta7k1of87r9cfd9sb381;");
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
// create HTML DOM
$html = str_get_html($output);
// echo $html;
//Check warning
$owarning = trim ($html->find('.warning',0)->innertext);
//echo $owarning;
// Country warning
if (strpos($owarning,"country")!== FALSE){
$ovierrmsg = "Country warning (not available)";
$ovierror = "c";
$dresult = array ('result'=>$ovierror, 'errormsg'=>$ovierrmsg);
// Device warning
} elseif (strpos($owarning,"not available")!== FALSE){
$ovierrmsg = "Device not compatible / available:";
$ovierror = "d";
$dresult = array ('result'=>$ovierror, 'errormsg'=>$ovierrmsg);
// Its OK Get Information
} else {
//Get Item HTML
$sectionItem = $html->find('.sectionContent',0);
// Category
if (!empty($sectionItem)){
// Is available, there means we should add device as compatible.
$dresult = array ('result'=>"1");
} else {
$dresult = array ('result'=>"0", 'errormsg'=>"Unknown Error");
}
}
// clean up memory
$html->clear();
unset($html);
// print_r($oviitem);
return $dresult;
}
function checkSymb3($oviid, $entryid){
$device = "N8-00";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg = $deviceresult."
";
$device = "C7-00";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
$device = "C6-01";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
sleep(1);
$device = "E7-00";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
$device = "X7-00";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
return $rmsg;
}
function checkS605($oviid, $entryid){
// $device = "5250";
// $deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
// $rmsg .= $deviceresult."
";
//$device = "5530xm";
//$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
//$rmsg .= $deviceresult."
";
$device = "C6-00";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
sleep(1);
$device = "N97";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
$device = "N97_mini";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
$device = "5230";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
sleep(1);
$device = "X6";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
$device = "C5-03";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
$device = "5800";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, $device);
$rmsg .= $deviceresult."
";
return $rmsg;
}
function checkS603($oviid, $entryid){
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "E71");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "E72");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "E63");
$rmsg .= $deviceresult."
";
sleep(1);
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "C5-00");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "E5-00");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "N86_8MP");
$rmsg .= $deviceresult."
";
sleep(1);
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "N82");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "N95");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "N73");
$rmsg .= $deviceresult."
";
$deviceresult = $this->checkDeviceCompat($oviid, $entryid, "N79");
$rmsg .= $deviceresult."
";
return $rmsg;
}
function identifyPlatform($entryid){
// Works out what platfrom(s) an entry has
$darr = $this->getDevices($entryid);
$this->isplatform = "";
// S60 3rd Edition
if (array_intersect($this->cs603,$darr)){
$this->isplatform['s603']="1";
} else {
$this->isplatform['s603']="0";
}
// S60 5th Edition
if (array_intersect($this->cs605,$darr)){
$this->isplatform['s605']="1";
} else {
$this->isplatform['s605']="0";
}
//Symbian^3
if (array_intersect($this->csy3,$darr)){
$this->isplatform['sy3']="1";
} else {
$this->isplatform['sy3']="0";
}
return $this->isplatform;
}
function getDevices($entryid){
// This function gets the compatible devices for a specific entryid
if ($entryid !=""){
$sql="SELECT d.dev_name
FROM 2devices AS d
WHERE d.entry_id ='".$entryid."'";
$result=$this->db->query($sql);
while ( $row=$result->fetch() ) {
$lod[]=$row['dev_name'];
}
return $lod;
}
}
function RankExist ($rank_type_id,$rank_time,$rank_geo="US") {
// Set rank time information
$rank_week = date ("W",$rank_time);
$rank_year = date ("Y",$rank_time);
// Check if this ranking has already been stored
$sql="SELECT rank_id
FROM rankings
WHERE rank_type_id ='".$rank_type_id."' AND rank_geo ='".$rank_geo."' AND rank_week ='".$rank_week."' AND rank_year ='".$rank_year."'";
$result=$this->db->query($sql);
if ($result->size() >= "1"){
$this->msg = "
Rank Data already exists and is stored for this combination. Rank Type: ".$rank_type_id." Geo: ".$rank_geo."";
return "1";
} else {
return "0";
}
}
function addRankData ($data_id, $data_title, $rank_device, $rank_type, $rank_type_id, $rank_geo, $rank_time){
// Set rank time information
$rank_week = date ("W",$rank_time);
$rank_year = date ("Y",$rank_time);
// Counter for array index and ranking
$i = "0";
$this->msg = "
".$rank_device." - ".$rank_type." W".$rank_week." Y".$rank_year."
";
foreach ($data_id as $rank_id){
// Get rank information
$rank_title = $data_title[$i];
$i=$i+1;
$rank_ranking = $i;
// Add to database
// echo "".$rank_ranking." ".$rank_title." [".$rank_id."] - W".$rank_week." Y".$rank_year." (".$rank_time.")
";
if ($rank_id !=""){
$sql="INSERT INTO
rankings
SET
rank_type='".$rank_type."',
rank_type_id='".$rank_type_id."',
rank_device='".$rank_device."',
ranking='".$rank_ranking."',
ovi_id='".$rank_id."',
ovi_title='".$rank_title."',
rank_geo='".$rank_geo."',
rank_time='".$rank_time."',
rank_week='".$rank_week."',
rank_year='".$rank_year."'";
$result=$this->db->query($sql);
$this->msg.="
".$rank_ranking.". ".$rank_title." [".$rank_id."]";
} else {
$this->msg.="
Error.";
}
}
}
function getRankData ($rank_url,$rank_device,$rank_geo="US"){
$rank_url = $rank_url."&terminalId=".$rank_device;
set_time_limit (60);
$url=$rank_url;
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array();
$topdata = $oil;
set_time_limit (60);
$url = $rank_url."&page=2";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=3";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=4";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=5";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=6";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=7";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=8";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
set_time_limit (60);
$url = $rank_url."&page=9";
$oil = $this->parseOviList ($url,$rank_geo);
$topdata = array_merge_recursive($topdata,$oil);
return $topdata;
}
}
?>