<p> var MF = acre.require("MANIFEST");
var MQL = acre.require(MF.libBase+"MQL");
var NS = MF.NS;
var ITEM_TYPE = MF.NS + '/scheme/item';
function getItemById(id,qExt)
{
var e = MQL.read({"type": ITEM_TYPE ,id:MF.TOPIC+'/'+id,"*": null
,item_type:{id:null,key:null}
,city_sector:{id:null,key:null}
,
"resource": [{
"kind": {
"id": null, key:{value:null}
},
"url": null,
"icon": null,
"optional": "optional"
}]
,"z:state":"normal"
,"limit":1}
,qExt);
if (!e){
e = {item_id:id,name:"#"+id,state:'not_found'};
}
e.images = Array.scan(e.resource,[],function(i,v){if (v.kind.key.value=="picture")this.push(v)},[null,null]);
//Array.scan(e.cost,[],function(i,v){v.kind=v.kind.key;},[null,null]);
console.log('e='+id,e);
return e ;
}
// writes result object in common way
function writeResultObject(obj)
{
var json = JSON.stringify(obj,null,5);
var callback= acre.request.params["callback"];
acre.write(callback?(callback+'('+json+')'):json);
}
function getLocationUrl(lat, lng)
{
return "http://maps.google.com/maps?f=q&hl=en&ie=UTF8&z=14&spn=0.052278,0.070982&output=embed"
+"&q="+lat+","+lng
+"&ll="+lat+","+lng
+"&sll="+lat+","+lng
}
function getLastTimestamp(lag1)
{
var lag = acre.keystore.get('timestamp.com')[0];
var q = MQL.read({"id": NS,"lastTimestamp": null,type:MF.NS + '/scheme/app'});
var ts = q && q["lastTimestamp"];
var d1 = ts ? Date.shifted(Date.parse(ts,"yyyy-MM-ddTHH:mm:ss"),lag) : (new Date());
var p1 = d1.format("yyyy_MM_dd_HH_mm");
console.log('getLastTimestamp:',p1, ts);
return p1;
}
function fetchFacebookApplicationAccessToken()
{
//MQL.checkAuthorized();
var cred = acre.keystore.get('graph.facebook.com');
var access_token = acre.urlfetch('https://graph.facebook.com/oauth/access_token?type=client_cred'
+'&client_id='+cred[0]
+'&client_secret='+cred[1]);
access_token = String.after(access_token.body,'access_token=')
console.log('access_token=',access_token);
return access_token;
}
function postToFacebook(e, access_token)
{
var cred = acre.keystore.get('ga.page.fb.com');
var result = acre.urlfetch('https://graph.facebook.com/feed?access_token=' +encodeURIComponent(cred[1])
,{method:"POST",content:'message='+encodeURIComponent(e.title)
+'&id='+encodeURIComponent('129253963800913')
+'&link='+encodeURIComponent(e.link)
+'&picture='+encodeURIComponent(e.image)
+'&description='+encodeURIComponent(e.description||'')
+'&caption='+encodeURIComponent(e.caption||'')});
console.log('result=',result.body);
var body = JSON.parse(result.body);
return body && body.id;
}
function postToMongoLab(e)
{
var cred = acre.keystore.get('ga.mongolab.com');
var name = {"ru":e.title_ru,"en": e.title,"cn":"魅力公寓" + e.title}
var VIDEO = { source: [{type: 'mp4',src: 'http://video-js.zencoder.com/oceans-clip.mp4'}],poster: {src:e.icon, size:{width:100, height:100}}}
var PANO_URL ='/html/js/libs/krpano/krpano.swf'
var item = {
id:e.item_id,
active: (e.state_id!='1'),
created: e.updated,
modified: e.updated,
num:e.item_num,
type:e.item_type,
name:name ,
descriptions:[],
icon: e.icon,
url: e.url,
,
// private
private: {
meta: {
// title
title: name,
// keywords
keywords: {"ru":"глазированая квартира","en": "Glamour apartment","cn":"魅力公寓"} , //TODO
description: {"ru":e.description_ru,"en": e.description,"cn":"魅力公寓" + e.description},
canonical_url: e.url,
shared_image: {src:e.icon, size:{width:100, height:100}}
}
}
,
// apartment capacity:
capacity: {
guests: e.capacityMax, // sleeps
living_space: e.squire,
rooms:e.room_count,
bedrooms: e.bedroom_count,
bathrooms: e.bathroomCount,
single_beds: e.singleBedCount,
double_beds: e.doubleBedCount,
child_beds: e.childBedCount
}
,
// ranking
category: 'standard', //TODO
glamourity: e.rank,
rating : { would_stay_again:7, reviews:e.reviews, rate1:2, rate2:5, rate3:8, rate4:9, rate5:8 } //TODO
,
// locality
location: {
country: 'FR',
city: 'paris',
district: e.area.id,
etage:2, //TODO
rank: e.address_rank,
metro: ['station1'], //TODO
geo: { lat:e.latitude ,lng:e.longitude}
}
,
// media resources
media:{
images: []
,
video: {
low: VIDEO ,
sd: VIDEO ,
hd: VIDEO
},
pano: {
url: PANO_URL
}
}
,
amenities: []
,
// commerce
availability: [
periods:[{start:'20120420', end:'20120426', state:'busy_by_owner'}, {start:'20120520', end:'20120526', state:'busy_by_ga'}]
expired : '20120930', // comment
minimal_stay_period: {date_period:'week',amount:1},//TODO
rent_type: "any",//TODO |short|long
}
,
price:{
amount_per_night: e.price
, amount_per_week: e.price*7
, amount_per_month: e.price*30
, is_best_offer: e.rank>3
,//TODO
rates : []
,
extras: {"ru":"глазум ипсум квартираниум на неделю вперёд и с вас плюс пицот за пылесос каждый день","en": "In all cases we have a 4 day minimum stay expect over the Christmas holidays where we have a one week minimum.","cn":"魅力公寓"}
}
other: {
"calendar": e.url
}
}
for (var i=0;i</p>