From 299c7571fa6b114c63805a319780d53b3274b850 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 18 Aug 2014 18:25:47 +0200 Subject: [PATCH] Introduced common_get_temp_dir() which wraps getting temporary path. Signed-off-by: Roland Haeder --- classes/User_group.php | 15 +++++++++++- lib/framework.php | 23 +++++++++++++++++++ lib/imagefile.php | 13 +++++------ .../Tests/Phergie/Plugin/HandlerTest.php | 2 +- .../extlib/minify/min/lib/Solar/Dir.php | 4 ++-- plugins/OStatus/classes/FeedSub.php | 2 +- plugins/OStatus/classes/Ostatus_profile.php | 5 ++-- .../scripts/update_ostatus_profiles.php | 4 ++-- .../lib/offlinebackupqueuehandler.php | 2 +- .../VideoThumbnails/VideoThumbnailsPlugin.php | 2 +- .../WikiHowProfile/WikiHowProfilePlugin.php | 2 +- plugins/YammerImport/lib/yammerimporter.php | 2 +- scripts/docgen.php | 2 +- 13 files changed, 57 insertions(+), 21 deletions(-) diff --git a/classes/User_group.php b/classes/User_group.php index aad38b6358..89731ee264 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -85,9 +85,22 @@ class User_group extends Managed_DataObject { if (!isset($this->_profile[$this->profile_id])) { $profile = Profile::getKV('id', $this->profile_id); + if (!$profile instanceof Profile) { - throw new GroupNoProfileException($this); + + $profile = new Profile(); + $profile->nickname = $this->nickname; + $profile->fullname = $this->fullname; + $profile->profileurl = $this->mainpage; + $profile->homepage = $this->homepage; + $profile->bio = $this->description; + $profile->location = $this->location; + $profile->created = common_sql_now(); + $this->profile_id = $profile->insert(); + + //throw new GroupNoProfileException($this); } + $this->_profile[$this->profile_id] = $profile; } return $this->_profile[$this->profile_id]; diff --git a/lib/framework.php b/lib/framework.php index cc716cbdb5..b92ea088b6 100644 --- a/lib/framework.php +++ b/lib/framework.php @@ -105,6 +105,28 @@ function _have_config() return StatusNet::haveConfig(); } +function common_get_temp_dir() +{ + // Try to get it from php.ini first + $temp_path = trim(ini_get('upload_tmp_dir')); + + // Is it empty? + if (strlen($temp_path) == 0) { + // Then try sys_get_temp_dir() + $temp_path = trim(sys_get_temp_dir()); + + // Still empty? + if (strlen($temp_path) == 0) { + // Then set it to /tmp (ugly) + // @TODO Hard-coded non-Windows stuff! + $temp_path = '/tmp'; + } + } + + // Return found path + return $temp_path; +} + function GNUsocial_class_autoload($cls) { if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) { @@ -121,6 +143,7 @@ function GNUsocial_class_autoload($cls) } } + // Autoload function queue, starting with our own discovery method spl_autoload_register('GNUsocial_class_autoload'); diff --git a/lib/imagefile.php b/lib/imagefile.php index 8a0f652327..733a4bbc9c 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -61,13 +61,12 @@ class ImageFile $info = @getimagesize($this->filepath); - if (!( - ($info[2] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) || - ($info[2] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) || - $info[2] == IMAGETYPE_BMP || - ($info[2] == IMAGETYPE_WBMP && function_exists('imagecreatefromwbmp')) || - ($info[2] == IMAGETYPE_XBM && function_exists('imagecreatefromxbm')) || - ($info[2] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')))) { + if ( + ($info[2] == IMAGETYPE_GIF && !function_exists('imagecreatefromgif')) || + ($info[2] == IMAGETYPE_JPEG && !function_exists('imagecreatefromjpeg')) || + ($info[2] == IMAGETYPE_WBMP && !function_exists('imagecreatefromwbmp')) || + ($info[2] == IMAGETYPE_XBM && !function_exists('imagecreatefromxbm')) || + ($info[2] == IMAGETYPE_PNG && !function_exists('imagecreatefrompng'))) { // TRANS: Exception thrown when trying to upload an unsupported image file format. throw new UnsupportedMediaException(_('Unsupported image format.'), $this->filepath); diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php index 9ecdd327ae..98c70dfcee 100644 --- a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php +++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php @@ -493,7 +493,7 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase */ public function testAddPluginThrowsExceptionWhenPluginClassNotFound() { - $path = sys_get_temp_dir() . '/Phergie/Plugin'; + $path = common_get_temp_dir() . '/Phergie/Plugin'; $this->removeDirectory(dirname($path)); mkdir($path, 0777, true); touch($path . '/TestPlugin.php'); diff --git a/plugins/Minify/extlib/minify/min/lib/Solar/Dir.php b/plugins/Minify/extlib/minify/min/lib/Solar/Dir.php index 37f7169624..0d1555c947 100644 --- a/plugins/Minify/extlib/minify/min/lib/Solar/Dir.php +++ b/plugins/Minify/extlib/minify/min/lib/Solar/Dir.php @@ -134,8 +134,8 @@ class Solar_Dir { if (! Solar_Dir::$_tmp) { // use the system if we can - if (function_exists('sys_get_temp_dir')) { - $tmp = sys_get_temp_dir(); + if (function_exists('common_get_temp_dir')) { + $tmp = common_get_temp_dir(); } else { $tmp = Solar_Dir::_tmp(); } diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php index 338c2f5144..419f416484 100644 --- a/plugins/OStatus/classes/FeedSub.php +++ b/plugins/OStatus/classes/FeedSub.php @@ -487,7 +487,7 @@ class FeedSub extends Managed_DataObject return true; } if (common_config('feedsub', 'debug')) { - $tempfile = tempnam(sys_get_temp_dir(), 'feedsub-receive'); + $tempfile = tempnam(common_get_temp_dir(), 'feedsub-receive'); if ($tempfile) { file_put_contents($tempfile, $post); } diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index adc3326336..2f008962fa 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -1243,11 +1243,12 @@ class Ostatus_profile extends Managed_DataObject // @todo FIXME: This should be better encapsulated // ripped from oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); + $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar'); + die('temp_filename='.$temp_filename); try { if (!copy($url, $temp_filename)) { // TRANS: Server exception. %s is a URL. - throw new ServerException(sprintf(_m('Unable to fetch avatar from %s.'), $url)); + throw new ServerException(sprintf(_m('Unable to fetch avatar from %s to %s.'), $url, $temp_filename)); } if ($this->isGroup()) { diff --git a/plugins/OStatus/scripts/update_ostatus_profiles.php b/plugins/OStatus/scripts/update_ostatus_profiles.php index b4191e9eb5..01116bb6f4 100644 --- a/plugins/OStatus/scripts/update_ostatus_profiles.php +++ b/plugins/OStatus/scripts/update_ostatus_profiles.php @@ -70,11 +70,11 @@ class LooseOstatusProfile extends Ostatus_profile // @fixme this should be better encapsulated // ripped from oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); + $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar'); try { if (!copy($url, $temp_filename)) { // TRANS: Server exception. %s is a URL. - throw new ServerException(sprintf(_m('Unable to fetch avatar from %s.'), $url)); + throw new ServerException(sprintf(_m('Unable to fetch avatar from %s to %s.'), $url, $temp_filename)); } if ($this->isGroup()) { diff --git a/plugins/OfflineBackup/lib/offlinebackupqueuehandler.php b/plugins/OfflineBackup/lib/offlinebackupqueuehandler.php index 9f96193d95..82384f60bc 100644 --- a/plugins/OfflineBackup/lib/offlinebackupqueuehandler.php +++ b/plugins/OfflineBackup/lib/offlinebackupqueuehandler.php @@ -73,7 +73,7 @@ class OfflineBackupQueueHandler extends QueueHandler { // XXX: this is pretty lose-y; try another way - $tmpdir = sys_get_temp_dir() . '/offline-backup/' . $user->nickname . '/' . common_date_iso8601(common_sql_now()); + $tmpdir = common_get_temp_dir() . '/offline-backup/' . $user->nickname . '/' . common_date_iso8601(common_sql_now()); common_log(LOG_INFO, 'Writing backup data to ' . $tmpdir . ' for ' . $user->nickname); diff --git a/plugins/VideoThumbnails/VideoThumbnailsPlugin.php b/plugins/VideoThumbnails/VideoThumbnailsPlugin.php index 254931e5fb..9023c3edec 100644 --- a/plugins/VideoThumbnails/VideoThumbnailsPlugin.php +++ b/plugins/VideoThumbnails/VideoThumbnailsPlugin.php @@ -67,7 +67,7 @@ class VideoThumbnailsPlugin extends Plugin } // Let's save our frame to a temporary file. If we fail, remove it. - $imgPath = tempnam(sys_get_temp_dir(), 'socialthumb'); + $imgPath = tempnam(common_get_temp_dir(), 'socialthumb'); if (!imagejpeg($frame->toGDImage(), $imgPath)) { @unlink($imgPath); return true; diff --git a/plugins/WikiHowProfile/WikiHowProfilePlugin.php b/plugins/WikiHowProfile/WikiHowProfilePlugin.php index 6f45da6a70..567e195177 100644 --- a/plugins/WikiHowProfile/WikiHowProfilePlugin.php +++ b/plugins/WikiHowProfile/WikiHowProfilePlugin.php @@ -178,7 +178,7 @@ class WikiHowProfilePlugin extends Plugin // @todo FIXME: This should be better encapsulated // ripped from OStatus via oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); + $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar'); try { if (!copy($url, $temp_filename)) { // TRANS: Exception thrown when fetching an avatar from a URL fails. diff --git a/plugins/YammerImport/lib/yammerimporter.php b/plugins/YammerImport/lib/yammerimporter.php index 4cc5cb2d4a..54b273a8a1 100644 --- a/plugins/YammerImport/lib/yammerimporter.php +++ b/plugins/YammerImport/lib/yammerimporter.php @@ -442,7 +442,7 @@ class YammerImporter // @fixme this should be better encapsulated // ripped from oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); + $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar'); try { if (!copy($url, $temp_filename)) { // TRANS: Server exception thrown when an avatar could not be fetched. diff --git a/scripts/docgen.php b/scripts/docgen.php index 6341b72706..9ca4d9dad5 100755 --- a/scripts/docgen.php +++ b/scripts/docgen.php @@ -95,7 +95,7 @@ var_dump($replacements); $template = file_get_contents(dirname(__FILE__) . '/doxygen.tmpl'); $template = strtr($template, $replacements); -$templateFile = tempnam(sys_get_temp_dir(), 'statusnet-doxygen'); +$templateFile = tempnam(common_get_temp_dir(), 'statusnet-doxygen'); file_put_contents($templateFile, $template); $cmd = "doxygen " . escapeshellarg($templateFile); -- 2.39.5