upgrade on toolbox
This commit is contained in:
@@ -92,7 +92,7 @@ class Feed extends PhpObject {
|
||||
$sRssItem .= self::getHtml(self::cleanRss($asItem['author']), 'author');
|
||||
$sRssItem .= self::getHtml($asItem['link'], 'link');
|
||||
$sRssItem .= self::getHtml($asItem['category'], 'category');
|
||||
$sRssItem .= self::getHtml(self::cleanRss($asItem['description'].'.'), 'description');
|
||||
$sRssItem .= self::getHtml(self::cleanRss($asItem['description']), 'description');
|
||||
$sRssItem .= self::getHtml(self::getDate($asItem['pub_date']), 'pubDate');
|
||||
$sRssItem .= self::getHtml($asItem['guid'], 'guid', '', '', array('isPermaLink'=>'true'));
|
||||
return self::getHtml($sRssItem, 'item');
|
||||
|
||||
199
inc/toolbox.php
199
inc/toolbox.php
@@ -37,6 +37,7 @@ class ToolBox
|
||||
{
|
||||
//Add CLI arguments
|
||||
if(defined('STDIN')) mb_parse_str(implode('&', array_slice($argv, 1)), $_GET);
|
||||
$_REQUEST = array_merge($_GET, $_REQUEST);
|
||||
|
||||
//Add Server Name
|
||||
$sServerName = array_key_exists('SERVER_NAME', $_SERVER)?$_SERVER['SERVER_NAME']:$_SERVER['PWD'];
|
||||
@@ -129,52 +130,141 @@ class ToolBox
|
||||
return json_encode($asData);
|
||||
}
|
||||
|
||||
public static function createThumbnail($sInPath, $iMaxWidth, $iMaxHeight, $sOutPath='', $bDeleteIn=false, $asImageExts=array('jpg', 'jpeg', 'gif', 'png'))
|
||||
public static function getMimeType($sPath, $bSubTypeOnly=false)
|
||||
{
|
||||
//Retrieving file Content Type
|
||||
if(file_exists($sPath)) //Local
|
||||
{
|
||||
$oFileInfo = new finfo(FILEINFO_MIME);
|
||||
$sMimetype = $oFileInfo->file($sPath);
|
||||
}
|
||||
else //Remote
|
||||
{
|
||||
//get_headers($sUrl, 1)
|
||||
$oCurl = curl_init($sPath);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($oCurl, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($oCurl, CURLOPT_HEADER, true);
|
||||
//curl_setopt($oCurl, CURLOPT_NOBODY, true);
|
||||
curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
||||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_exec($oCurl);
|
||||
$sMimetype = curl_getinfo($oCurl, CURLINFO_CONTENT_TYPE);
|
||||
curl_close($oCurl);
|
||||
}
|
||||
|
||||
//Only sub type (after /)
|
||||
if($bSubTypeOnly)
|
||||
{
|
||||
preg_match('`\/(?P<type>\w+)(\;|$)`ui', mb_strtolower($sMimetype), $asMatch);
|
||||
$sMimetype = $asMatch['type'];
|
||||
}
|
||||
return $sMimetype;
|
||||
}
|
||||
|
||||
public static function isAnimatedGif($sFilePath)
|
||||
{
|
||||
if(!($oFile = @fopen($sFilePath, 'rb'))) return false;
|
||||
|
||||
$iCount = 0;
|
||||
while (!feof($oFile) && $iCount < 2)
|
||||
{
|
||||
|
||||
$sChunk = fread($oFile, 1024 * 100); //read 100kb at a time
|
||||
$iCount += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $sChunk, $asMatches);
|
||||
}
|
||||
fclose($oFile);
|
||||
|
||||
return $iCount > 1;
|
||||
}
|
||||
|
||||
public static function createThumbnail($sInPath, $iMaxWidth, $iMaxHeight, $sOutPath='', $bDeleteIn=false, $asImageExts=array('jpg', 'jpeg', 'gif', 'png'), $bCrop=false)
|
||||
{
|
||||
$asResult = array('error'=>'');
|
||||
|
||||
//Look up the extension to choose the image creator
|
||||
//TODO use MIME types
|
||||
$sInInfo = pathinfo($sInPath);
|
||||
$sInName = mb_strtolower($sInInfo['basename']);
|
||||
$sImageExt = mb_strtolower($sInInfo['extension']);
|
||||
//Look up the file type to choose the image creator
|
||||
$sImageExt = self::getMimeType($sInPath, true);
|
||||
$sImageExt = ($sImageExt=='jpg')?'jpeg':$sImageExt;
|
||||
|
||||
//New Destination folder
|
||||
$asInInfo = pathinfo($sInPath);
|
||||
$asOutInfo = pathinfo($sOutPath);
|
||||
if($sOutPath=='') $sOutPath = $sInPath;
|
||||
elseif(mb_substr($sOutPath, -1)=='/') $sOutPath .= $sInName;
|
||||
elseif(mb_substr($sOutPath, -1)=='/') $sOutPath .= mb_strtolower($asInInfo['basename']); //folder only, keep original name
|
||||
elseif(!array_key_exists('extension', $asOutInfo)) $sOutPath .= '.'.$sImageExt; //folder + filename, but getting ext from file info
|
||||
|
||||
//New sizes
|
||||
if(in_array($sImageExt, $asImageExts))
|
||||
if(!in_array($sImageExt, $asImageExts) && !empty($asImageExts)) $asResult['error'] = 'Wrong file type: '.$sImageExt;
|
||||
else
|
||||
{
|
||||
list($iWidth, $iHeight) = getimagesize($sInPath);
|
||||
if($iWidth > $iMaxWidth || $iHeight > $iMaxHeight)
|
||||
{
|
||||
$dResizeDeltaWidth = $iWidth - $iMaxWidth;
|
||||
$dResizeDeltaHeight = $iHeight - $iMaxHeight;
|
||||
if($dResizeDeltaWidth > $dResizeDeltaHeight)
|
||||
$iPosLeft = $iPosTop = 0;
|
||||
$iThumbWidth = $iMaxWidth;
|
||||
$iThumbHeight = $iMaxHeight;
|
||||
|
||||
//Max up the lowest value between height and width and crop the other
|
||||
if($bCrop)
|
||||
{
|
||||
$iResizedWidth = $iMaxWidth;
|
||||
$iResizedHeight = ($iResizedWidth / $iWidth) * $iHeight;
|
||||
if($dResizeDeltaWidth > $dResizeDeltaHeight) //Crop width
|
||||
{
|
||||
$iResizedHeight = $iMaxHeight;
|
||||
$iResizedWidth = ($iResizedHeight / $iHeight) * $iWidth;
|
||||
$iPosLeft = ($iResizedWidth - $iMaxWidth)/2*(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$iResizedWidth = $iMaxWidth;
|
||||
$iResizedHeight = ($iResizedWidth / $iWidth) * $iHeight;
|
||||
$iPosTop = ($iResizedHeight - $iMaxHeight)/2*(-1);
|
||||
}
|
||||
}
|
||||
else //Just resize
|
||||
{
|
||||
if($dResizeDeltaWidth > $dResizeDeltaHeight)
|
||||
{
|
||||
$iResizedWidth = $iMaxWidth;
|
||||
$iResizedHeight = ($iResizedWidth / $iWidth) * $iHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
$iResizedHeight = $iMaxHeight;
|
||||
$iResizedWidth = ($iResizedHeight / $iHeight) * $iWidth;
|
||||
}
|
||||
$iThumbWidth = $iResizedWidth;
|
||||
$iThumbHeight = $iResizedHeight;
|
||||
}
|
||||
|
||||
if($sImageExt=='gif' && self::isAnimatedGif($sInPath))
|
||||
{
|
||||
$sContent = file_get_contents($sInPath);
|
||||
$sBigGifPath = Databap::DOC_TMP_FOLDER.uniqid();
|
||||
$sCoalescePath = Databap::DOC_TMP_FOLDER.uniqid();
|
||||
|
||||
file_put_contents($sBigGifPath, $sContent);
|
||||
system('convert '.$sBigGifPath.' -coalesce '.$sCoalescePath);
|
||||
system('convert -size '.$iWidth.'x'.$iHeight.' '.$sCoalescePath.' -resize '.$iResizedWidth.'x'.$iResizedHeight.' '.$sOutPath);
|
||||
unlink($sBigGifPath);
|
||||
unlink($sCoalescePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
$iResizedHeight = $iMaxHeight;
|
||||
$iResizedWidth = ($iResizedHeight / $iHeight) * $iWidth;
|
||||
}
|
||||
//create image from source
|
||||
$oSource = call_user_func('imagecreatefrom'.$sImageExt, $sInPath);
|
||||
|
||||
//create image from source
|
||||
$oSource = call_user_func('imagecreatefrom'.$sImageExt, $sInPath);
|
||||
//Resize
|
||||
$oThumb = imagecreatetruecolor($iThumbWidth, $iThumbHeight);
|
||||
imagecopyresampled($oThumb, $oSource, $iPosLeft, $iPosTop, 0, 0, $iResizedWidth, $iResizedHeight, $iWidth, $iHeight);
|
||||
|
||||
//Resize
|
||||
$oThumb = imagecreatetruecolor($iResizedWidth, $iResizedHeight);
|
||||
imagecopyresized($oThumb, $oSource, 0, 0, 0, 0, $iResizedWidth, $iResizedHeight, $iWidth, $iHeight);
|
||||
|
||||
//Save
|
||||
if(file_exists($sOutPath)) unlink($sOutPath);
|
||||
if(!call_user_func_array('image'.$sImageExt, array($oThumb, $sOutPath)))
|
||||
{
|
||||
$asResult['error'] = 'Unable to create thumbnail : '.$sOutPath;
|
||||
//Save
|
||||
if(file_exists($sOutPath)) unlink($sOutPath);
|
||||
if(!call_user_func_array('image'.$sImageExt, array($oThumb, $sOutPath)))
|
||||
{
|
||||
$asResult['error'] = 'Unable to create thumbnail : '.$sOutPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($sInPath != $sOutPath)
|
||||
@@ -187,7 +277,6 @@ class ToolBox
|
||||
$asResult['height'] = $iResizedHeight;
|
||||
$asResult['out'] = $sOutPath;
|
||||
}
|
||||
else $asResult['error'] = 'Wrong file type';
|
||||
|
||||
if($bDeleteIn && $asResult['error']=='' && $sInPath != $sOutPath) unlink($sInPath);
|
||||
|
||||
@@ -205,6 +294,14 @@ class ToolBox
|
||||
return mb_convert_case($sText, MB_CASE_TITLE, "UTF-8");
|
||||
}
|
||||
|
||||
public static function mb_ucfirst($sText)
|
||||
{
|
||||
$sLength = mb_strlen($sText);
|
||||
$sFirstChar = mb_substr($sText, 0, 1);
|
||||
$sThen = mb_substr($sText, 1, $sLength - 1);
|
||||
return mb_strtoupper($sFirstChar).$sThen;
|
||||
}
|
||||
|
||||
public static function file_get_contents_utf8($oFile)
|
||||
{
|
||||
$sContent = file_get_contents($oFile);
|
||||
@@ -230,6 +327,56 @@ class ToolBox
|
||||
$iTimeLimit = time()+60*60*24*$iDays;
|
||||
setcookie($sCookieName, $sCookieValue, $iTimeLimit);
|
||||
}
|
||||
|
||||
public static function fixEOL($sText)
|
||||
{
|
||||
//Normalize line endings
|
||||
//Convert all line-endings to UNIX format
|
||||
$sText = str_replace("\r\n", "\n", $sText); //Windows
|
||||
$sText = str_replace("\r", "\n", $sText); //Mac
|
||||
|
||||
// Don't allow out-of-control blank lines
|
||||
$sText = preg_replace("/\n{2,}/", "\n\n", $sText);
|
||||
return $sText;
|
||||
}
|
||||
|
||||
public static function getDateTimeDesc($oTime)
|
||||
{
|
||||
$iTimeStamp = is_numeric($oTime)?$oTime:strtotime($oTime);
|
||||
$sCurTimeStamp = time();
|
||||
|
||||
$asWeekDays = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
|
||||
$asMonths = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre');
|
||||
$sSep = '|';
|
||||
$sFormat = 'Y'.$sSep.'n'.$sSep.'W'.$sSep.'N'.$sSep.'j'.$sSep.'G';
|
||||
list($sYear, $sMonth, $sWeek, $sWeekDay, $sDay, $sHour) = explode($sSep, date($sFormat, $iTimeStamp));
|
||||
list($sCurYear, $sCurMonth, $sCurWeek, $sCurWeekDay, $sCurDay, $sCurHour) = explode($sSep, date($sFormat, $sCurTimeStamp));
|
||||
|
||||
$sDesc = '';
|
||||
if($iTimeStamp>$sCurTimeStamp) $sDesc = 'dans le futur';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60) $sDesc = 'il y a quelques secondes';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*10) $sDesc = 'il y a quelques minutes';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*20) $sDesc = 'il y a un quart d\'heure';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*50) $sDesc = 'il y a une demi-heure';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*2) $sDesc = 'il y a une heure';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24 && $sDay==$sCurDay) $sDesc = 'à '.$sHour.'h';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24) $sDesc = 'hier';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*7 && $sWeek==$sCurWeek) $sDesc = $asWeekDays[$sWeekDay-1];
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*7) $sDesc = $asWeekDays[$sWeekDay-1].' dernier';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*9) $sDesc = 'il y a une semaine';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*12) $sDesc = 'il y a 10 jours';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*16) $sDesc = 'il y a 2 semaines';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*23) $sDesc = 'il y a 3 semaines';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*31 && $sMonth==$sCurMonth) $sDesc = 'le '.$sDay.' '.$asMonths[$sMonth-1];
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*30*2 && $sMonth==($sCurMonth-1)) $sDesc = 'le mois dernier';
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*365 && $sYear==$sCurYear) $sDesc = 'en '.$asMonths[$sMonth-1];
|
||||
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*365) $sDesc = 'en '.$asMonths[$sMonth-1].' '.$sYear;
|
||||
elseif($sYear==($sCurYear-1)) $sDesc = 'l\'année dernière';
|
||||
else $sDesc = 'en '.$sYear;
|
||||
|
||||
//return self::mb_ucfirst($sDesc);
|
||||
return $sDesc;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
8
script/jquery.js
vendored
8
script/jquery.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user