Merge pull request #1033 from annando/master

Temporary paths are now defined automatically
This commit is contained in:
Tobias Diekershoff 2014-06-24 06:29:35 +02:00
commit 3600ab1ffc
14 changed files with 653 additions and 485 deletions

View file

@ -693,6 +693,14 @@ if(! class_exists('App')) {
else
$stylesheet = '$stylesheet';
$shortcut_icon = get_config("system", "shortcut_icon");
if ($shortcut_icon == "")
$shortcut_icon = $this->get_baseurl()."/images/friendica-32.png";
$touch_icon = get_config("system", "touch_icon");
if ($touch_icon == "")
$touch_icon = $this->get_baseurl()."/images/friendica-128.png";
$tpl = get_markup_template('head.tpl');
$this->page['htmlhead'] = replace_macros($tpl,array(
'$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
@ -703,6 +711,8 @@ if(! class_exists('App')) {
'$showmore' => t('show more'),
'$showfewer' => t('show fewer'),
'$update_interval' => $interval,
'$shortcut_icon' => $shortcut_icon,
'$touch_icon' => $touch_icon,
'$stylesheet' => $stylesheet
)) . $this->page['htmlhead'];
}
@ -2150,7 +2160,7 @@ function random_digits($digits) {
}
function get_cachefile($file, $writemode = true) {
$cache = get_config("system","itemcache");
$cache = get_itemcachepath();
if ((! $cache) || (! is_dir($cache)))
return("");
@ -2171,7 +2181,7 @@ function get_cachefile($file, $writemode = true) {
function clear_cache($basepath = "", $path = "") {
if ($path == "") {
$basepath = get_config('system','itemcache');
$basepath = get_itemcachepath();
$path = $basepath;
}
@ -2199,6 +2209,63 @@ function clear_cache($basepath = "", $path = "") {
}
}
function get_itemcachepath() {
// Checking, if the cache is deactivated
$cachetime = (int)get_config('system','itemcache_duration');
if ($cachetime < 0)
return "";
$itemcache = get_config('system','itemcache');
if (($itemcache != "") AND is_dir($itemcache) AND is_writable($itemcache))
return($itemcache);
$temppath = get_temppath();
if ($temppath != "") {
$itemcache = $temppath."/itemcache";
mkdir($itemcache);
if (is_dir($itemcache) AND is_writable($itemcache)) {
set_config("system", "itemcache", $itemcache);
return($itemcache);
}
}
return "";
}
function get_lockpath() {
$lockpath = get_config('system','lockpath');
if (($lockpath != "") AND is_dir($lockpath) AND is_writable($lockpath))
return($lockpath);
$temppath = get_temppath();
if ($temppath != "") {
$lockpath = $temppath."/lock";
mkdir($lockpath);
if (is_dir($lockpath) AND is_writable($lockpath)) {
set_config("system", "lockpath", $lockpath);
return($lockpath);
}
}
return "";
}
function get_temppath() {
$temppath = get_config("system","temppath");
if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath))
return($temppath);
$temppath = sys_get_temp_dir();
if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) {
set_config("system", "temppath", $temppath);
return($temppath);
}
return("");
}
function set_template_engine(&$a, $engine = 'internal') {
// This function is no longer necessary, but keep it as a wrapper to the class method
// to avoid breaking themes again unnecessarily

View file

@ -764,7 +764,7 @@ function get_photo_info($url) {
if (is_null($data)) {
$img_str = fetch_url($url, true, $redirects, 4);
$tempfile = tempnam(get_config("system","temppath"), "cache");
$tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str);
$data = getimagesize($tempfile);
unlink($tempfile);
@ -775,3 +775,52 @@ function get_photo_info($url) {
return $data;
}
function scale_image($width, $height, $max) {
$dest_width = $dest_height = 0;
if((!$width) || (!$height))
return FALSE;
if($width > $max && $height > $max) {
// very tall image (greater than 16:9)
// constrain the width - let the height float.
if((($height * 9) / 16) > $width) {
$dest_width = $max;
$dest_height = intval(( $height * $max ) / $width);
} elseif($width > $height) {
// else constrain both dimensions
$dest_width = $max;
$dest_height = intval(( $height * $max ) / $width);
} else {
$dest_width = intval(( $width * $max ) / $height);
$dest_height = $max;
}
} else {
if( $width > $max ) {
$dest_width = $max;
$dest_height = intval(( $height * $max ) / $width);
} else {
if( $height > $max ) {
// very tall image (greater than 16:9)
// but width is OK - don't do anything
if((($height * 9) / 16) > $width) {
$dest_width = $width;
$dest_height = $height;
} else {
$dest_width = intval(( $width * $max ) / $height);
$dest_height = $max;
}
} else {
$dest_width = $width;
$dest_height = $height;
}
}
}
return array("width" => $dest_width, "height" => $dest_height);
}

View file

@ -710,6 +710,8 @@
if($parent)
$_REQUEST['type'] = 'net-comment';
else {
// logger("api_statuses_update: upload ".print_r($_FILES, true)." ".print_r($_POST, true)." ".print_r($_GET, true), LOGGER_DEBUG);
//die("blubb");
$_REQUEST['type'] = 'wall';
if(x($_FILES,'media')) {
// upload the image if we have one
@ -1617,18 +1619,32 @@
return $ret;
}
function api_get_entitities($text, $bbcode) {
function api_get_entitities(&$text, $bbcode) {
/*
To-Do:
* Links at the first character of the post
* different sizes of pictures
* caching picture data (using the id for that?) (See privacy_image_cache)
*/
$a = get_app();
$result = q("SELECT `installed` FROM `addon` WHERE `name` = 'privacy_image_cache' AND `installed`");
$image_cache = (count($result) > 0);
$include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
if ($include_entities != "true")
if ($include_entities != "true") {
if ($image_cache) {
require_once("addon/privacy_image_cache/privacy_image_cache.php");
preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
foreach ($images[1] AS $image) {
$replace = $a->get_baseurl()."/privacy_image_cache/".privacy_image_cache_cachename($image);
$text = str_replace($image, $replace, $text);
}
}
return array();
}
$bbcode = bb_CleanPictureLinks($bbcode);
@ -1717,24 +1733,47 @@
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
$redirects = 0;
$img_str = fetch_url($url,true, $redirects, 10);
$image = @imagecreatefromstring($img_str);
require_once("include/Photo.php");
$image = get_photo_info($url);
if ($image) {
// If privacy_image_cache is activated, then use the following sizes:
// thumb (150), small (340), medium (600) and large (1024)
if ($image_cache) {
require_once("addon/privacy_image_cache/privacy_image_cache.php");
$media_url = $a->get_baseurl()."/privacy_image_cache/".privacy_image_cache_cachename($url);
$sizes = array();
$scale = scale_image($image[0], $image[1], 150);
$sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
if (($image[0] > 150) OR ($image[1] > 150)) {
$scale = scale_image($image[0], $image[1], 340);
$sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
}
$scale = scale_image($image[0], $image[1], 600);
$sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
if (($image[0] > 600) OR ($image[1] > 600)) {
$scale = scale_image($image[0], $image[1], 1024);
$sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
}
} else {
$media_url = $url;
$sizes["medium"] = array("w" => $image[0], "h" => $image[1], "resize" => "fit");
}
$entities["media"][] = array(
"id" => $start+1,
"id_str" => (string)$start+1,
"indices" => array($start, $start+strlen($url)),
"media_url" => $url,
"media_url_https" => $url,
"media_url" => normalise_link($media_url),
"media_url_https" => $media_url,
"url" => $url,
"display_url" => $display_url,
"expanded_url" => $url,
"type" => "photo",
"sizes" => array("medium" => array(
"w" => imagesx($image),
"h" => imagesy($image),
"resize" => "fit")));
"sizes" => $sizes);
}
$offset = $start + 1;
}

View file

@ -78,7 +78,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
else {
$Text = bbcode($Text, $preserve_nl, false, 4);
// Libertree doesn't convert a harizontal rule if there isn't a linefeed
$Text = str_replace("<hr />", "\n<hr />", $Text);
$Text = str_replace("<hr />", "<br /><hr />", $Text);
}
// Now convert HTML to Markdown

View file

@ -424,7 +424,7 @@ function bb_ShareAttributes($match) {
$posted = "";
$itemcache = get_config("system","itemcache");
$itemcache = get_itemcachepath();
// relative dates only make sense when they aren't cached
if ($itemcache == "") {
@ -661,7 +661,7 @@ function bb_ShareAttributes($share, $simplehtml) {
$posted = "";
$itemcache = get_config("system","itemcache");
$itemcache = get_itemcachepath();
// relative dates only make sense when they aren't cached
if ($itemcache == "") {
@ -949,8 +949,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// removing multiplicated newlines
if (get_config("system", "remove_multiplicated_lines")) {
$search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n");
$replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]");
$search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share ");
$replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]", "\n[share ");
do {
$oldtext = $Text;
$Text = str_replace($search, $replace, $Text);

View file

@ -35,7 +35,7 @@ function cronhooks_run(&$argv, &$argc){
}
}
$lockpath = get_config('system','lockpath');
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'cronhooks');
if($pidfile->is_already_running()) {

View file

@ -354,7 +354,7 @@ function db_definition() {
),
"indexes" => array(
"PRIMARY" => array("id"),
"access" => array("cat","k"),
"access" => array("cat(30)","k(30)"),
)
);
$database["contact"] = array(
@ -638,7 +638,7 @@ function db_definition() {
),
"indexes" => array(
"PRIMARY" => array("id"),
"hook_file_function" => array("hook","file","function"),
"hook_file_function" => array("hook(30)","file(60)","function(30)"),
)
);
$database["intro"] = array(
@ -890,7 +890,7 @@ function db_definition() {
),
"indexes" => array(
"PRIMARY" => array("id"),
"access" => array("uid","cat","k"),
"access" => array("uid","cat(30)","k(30)"),
)
);
$database["photo"] = array(

View file

@ -58,7 +58,7 @@ function onepoll_run(&$argv, &$argc){
}
// Test
$lockpath = get_config('system','lockpath');
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
if($pidfile->is_already_running()) {

View file

@ -41,7 +41,7 @@ function poller_run(&$argv, &$argc){
}
}
$lockpath = get_config('system','lockpath');
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'poller');
if($pidfile->is_already_running()) {

View file

@ -84,7 +84,7 @@ function queue_run(&$argv, &$argc){
load_config('config');
load_config('system');
$lockpath = get_config('system','lockpath');
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'queue');
if($pidfile->is_already_running()) {

View file

@ -554,6 +554,11 @@ function admin_page_site(&$a) {
$info = get_config('config','info');
$info = htmlspecialchars($info);
// Automatically create temporary paths
get_temppath();
get_lockpath();
get_itemcachepath();
//echo "<pre>"; var_dump($lang_choices); die("</pre>");
/* Register policy */
@ -631,7 +636,7 @@ function admin_page_site(&$a) {
'$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")),
'$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system','suppress_language'), t("Suppress language information in meta information about a posting.")),
'$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), "The item caches buffers generated bbcode and external images."),
'$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day).")),
'$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")),
'$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")),
'$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."),
'$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."),

View file

@ -13,9 +13,13 @@
<link rel="stylesheet" type="text/css" href="{{$stylesheet}}" media="all" />
<!--
<link rel="shortcut icon" href="{{$baseurl}}/images/friendica-32.png" />
<link rel="apple-touch-icon" href="{{$baseurl}}/images/friendica-128.png"/>
-->
<link rel="shortcut icon" href="{{$shortcut_icon}}" />
<link rel="apple-touch-icon" href="{{$touch_icon}}"/>
<meta name="apple-mobile-web-app-capable" content="yes" />

View file

@ -19,6 +19,10 @@ img {
/* width: 80%;*/
}
#adminpage .screenshot img {
width: 640px;
}
#pending-update {
float:right;
color: #ffffff;

View file

@ -1,11 +1,11 @@
<?php
/**
* Name: Vier
* Version: 0.9
* Version: 1.1
* Author: Fabio <http://kirgroup.com/profile/fabrixxm>
* Author: Ike <http://pirati.ca/profile/heluecht>
* Maintainer: Ike <http://pirati.ca/profile/heluecht>
* Description: "Vier" uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
* Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
*/
function vier_init(&$a) {