Thanks Bob for your help,
Is there any official documentation which can help me about finding these informations ?
It’s working perfectly !!
<?php
/* Retrieve properties from DB */
$Bitly_KEY = $modx->getOption('Bitly_KEY', $scriptProperties, '');
$Bitly_LOGIN = $modx->getOption('Bitly_LOGIN', $scriptProperties, '');
$siteURL = $modx->getOption('site_url');
$docInfo = $modx->getObject('modResource',18);
$docname = $docInfo->get('alias');
$resource = $modx->getObject('modResource',18);
$contentType = $resource->getOne('ContentType');
$description = $contentType->get('description');
$extension = $contentType->get('file_extensions');
/* Check if it is in folder */
$parent = $docInfo->get('parent');
$path='';
/* Checks if everything is correct */
if (empty($Bitly_KEY)){
$output="-No Bit.ly key, please create an account @ bit.ly website";
return $output;
die();}
else{
$output=$Bitly_KEY;
}
if (empty($Bitly_LOGIN)){
$output="-No Bit.ly key, please create an account @ bit.ly website";
return $output;
die();}
else{
$output=$Bitly_LOGIN;
}
while ($parent != 0) {
$docInfo = $modx->getObject('modResource',$parent);
$alias = $docInfo->get('alias');
$path = $alias . '/' . $path;
$parent = $docInfo->get('parent');
}
$longurl = $siteURL . $path . $docname . $extension;
$bitly = 'http://api.bit.ly/shorten?version=2.0.1&longUrl='.urlencode($longurl).'&login='.$Bitly_LOGIN.'&apiKey='.$Bitly_KEY.'&format=xml';
$response = file_get_contents($bitly);
//credits to davidwalsh.name
//parse depending on desired format
if(strtolower('xml') == 'json')
{
$json = @json_decode($response,true);
return $json['results'][$longurl]['shortUrl'];
}
else //xml
{
$xml = simplexml_load_string($response);
return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
}
Frost
Configuration Apache + Modx + MSSQL 2008
===============================
Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.8
OS : Windows 2008 R2
SGBDR : Microsoft SQL Server 2008 (express)
I couldn’t find it (except in the DB), but I did find this, which should be a better method:
$extension = $contentType->getExtension();
Found it here: