]> git.mxchange.org Git - friendica.git/commitdiff
Move Global Functions - Part 3
authorPhilipp Holzer <admin@philipp.info>
Sat, 20 Oct 2018 16:19:55 +0000 (18:19 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sat, 20 Oct 2018 16:19:55 +0000 (18:19 +0200)
- Replaced every CACHE definition
- Moved check_url to App->checkURL()
- Removed unused definition "ZCURL_TIMEOUT"

16 files changed:
boot.php
index.php
mod/ping.php
mod/search.php
src/App.php
src/Content/OEmbed.php
src/Model/GContact.php
src/Model/Photo.php
src/Model/Profile.php
src/Network/Probe.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Diaspora.php
src/Protocol/OStatus.php
src/Util/JsonLD.php
src/Worker/DiscoverPoCo.php
src/Worker/Queue.php

index 5d4b7c147ee6890741ceeb17d46154eb2f281427..d55f4b7bc979f23bda425417172f329b50949c1b 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -121,24 +121,6 @@ define('LOGGER_DATA',            4);
 define('LOGGER_ALL',             5);
 /* @}*/
 
-/**
- * @name Cache
- * @deprecated since version 3.6
- * @see Cache
- *
- * Cache levels
- * @{
- */
-define('CACHE_MONTH',            Cache::MONTH);
-define('CACHE_WEEK',             Cache::WEEK);
-define('CACHE_DAY',              Cache::DAY);
-define('CACHE_HOUR',             Cache::HOUR);
-define('CACHE_HALF_HOUR',        Cache::HALF_HOUR);
-define('CACHE_QUARTER_HOUR',     Cache::QUARTER_HOUR);
-define('CACHE_FIVE_MINUTES',     Cache::FIVE_MINUTES);
-define('CACHE_MINUTE',           Cache::MINUTE);
-/* @}*/
-
 /**
  * @name Register
  *
@@ -212,11 +194,6 @@ $netgroup_ids = [
  */
 define('MAX_LIKERS',    75);
 
-/**
- * Communication timeout
- */
-define('ZCURL_TIMEOUT', (-1));
-
 /**
  * @name Notify
  *
@@ -502,29 +479,6 @@ function check_db($via_worker)
        }
 }
 
-/**
- * Sets the base url for use in cmdline programs which don't have
- * $_SERVER variables
- *
- * @param object $a App
- */
-function check_url(App $a)
-{
-       $url = Config::get('system', 'url');
-
-       // if the url isn't set or the stored url is radically different
-       // than the currently visited url, store the current value accordingly.
-       // "Radically different" ignores common variations such as http vs https
-       // and www.example.com vs example.com.
-       // We will only change the url to an ip address if there is no existing setting
-
-       if (empty($url) || (!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->getHostName()))) {
-               Config::set('system', 'url', System::baseUrl());
-       }
-
-       return;
-}
-
 /**
  * @brief Automatic database updates
  * @param object $a App
index 6ab405c632a3f092db5914db9f146f6f457b7ab1..884b067325d6e88744f2f4b1ad1d97b600f0fb40 100644 (file)
--- a/index.php
+++ b/index.php
@@ -172,7 +172,7 @@ if ($a->getMode()->isInstall() && $a->module != 'view') {
 } elseif (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $a->module != 'view') {
        $a->module = 'maintenance';
 } else {
-       check_url($a);
+       $a->checkURL();
        check_db(false);
        Addon::check();
 }
index 5ea75727a1152d6d3f12943dcb7b5b9eb684fcbc..6f5b5b4a9828aeed4a79c628f6e0213f2cafb3ec 100644 (file)
@@ -221,7 +221,7 @@ function ping_init(App $a)
                                DBA::escape(DateTimeFormat::utcNow())
                        );
                        if (DBA::isResult($ev)) {
-                               Cache::set($cachekey, $ev, CACHE_HOUR);
+                               Cache::set($cachekey, $ev, Cache::HOUR);
                        }
                }
 
index b6e1a7e7f2cf4be8cb0f59553bf24493de7ecd41..80b1c184ff9e1b6129c2ecf524fe6180dcd4a31a 100644 (file)
@@ -136,9 +136,9 @@ function search_content(App $a) {
                                                        "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]);
                                killme();
                        }
-                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), CACHE_HOUR);
+                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), Cache::HOUR);
                } else
-                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), CACHE_HOUR);
+                       Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), Cache::HOUR);
        }
 
        Nav::setSelected('search');
index 97c193b3b7f4937ec68fe62fc390dd1787ba04d2..ddffa867ab0432914d11a9c85495304aeaeb3b1c 100644 (file)
@@ -1607,4 +1607,23 @@ class App
 
                return $default;
        }
+
+       /**
+        * Sets the base url for use in cmdline programs which don't have
+        * $_SERVER variables
+        */
+       public function checkURL()
+       {
+               $url = Config::get('system', 'url');
+
+               // if the url isn't set or the stored url is radically different
+               // than the currently visited url, store the current value accordingly.
+               // "Radically different" ignores common variations such as http vs https
+               // and www.example.com vs example.com.
+               // We will only change the url to an ip address if there is no existing setting
+
+               if (empty($url) || (!link_compare($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) {
+                       Config::set('system', 'url', $this->getBaseURL());
+               }
+       }
 }
index 116120ab552474c4dfe3e8132ea995bb76716293..cfe9468ad57a58a0f893b0fb9d16522aa59e60fc 100644 (file)
@@ -120,9 +120,9 @@ class OEmbed
                                        'content' => $json_string,
                                        'created' => DateTimeFormat::utcNow()
                                ], true);
-                               $cache_ttl = CACHE_DAY;
+                               $cache_ttl = Cache::DAY;
                        } else {
-                               $cache_ttl = CACHE_FIVE_MINUTES;
+                               $cache_ttl = Cache::FIVE_MINUTES;
                        }
 
                        Cache::set($cache_key, $json_string, $cache_ttl);
index 26cb11175c5b48573f638ec1d7e3eec9bb8a2e42..681c1c37096473fa96679edbb402086591222a67 100644 (file)
@@ -468,7 +468,7 @@ class GContact
                        * Uncommented because the result of the queries are to big to store it in the cache.
                        * We need to decide if we want to change the db column type or if we want to delete it.
                        */
-                       //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES);
+                       //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, Cache::FIVE_MINUTES);
 
                        return $r;
                }
@@ -509,7 +509,7 @@ class GContact
                * Uncommented because the result of the queries are to big to store it in the cache.
                * We need to decide if we want to change the db column type or if we want to delete it.
                */
-               //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, CACHE_FIVE_MINUTES);
+               //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, Cache::FIVE_MINUTES);
                return $list;
        }
 
index 372e875ea7b587e5f4dcd35802fa68d834c72976..6b094ded6ca5aea0b0b09cb442bc19ca8252f068 100644 (file)
@@ -253,7 +253,7 @@ class Photo
                                        DBA::escape(L10n::t('Contact Photos'))
                                );
                        }
-                       Cache::set($key, $albums, CACHE_DAY);
+                       Cache::set($key, $albums, Cache::DAY);
                }
                return $albums;
        }
@@ -265,7 +265,7 @@ class Photo
        public static function clearAlbumCache($uid)
        {
                $key = "photo_albums:".$uid.":".local_user().":".remote_user();
-               Cache::set($key, null, CACHE_DAY);
+               Cache::set($key, null, Cache::DAY);
        }
 
        /**
index 1f0773cd18c5998d6aac26b945a98071d6826967..f6fb3167d775cbe33d23dee5dfe296c4e335acc0 100644 (file)
@@ -577,7 +577,7 @@ class Profile
                        );
                        if (DBA::isResult($s)) {
                                $r = DBA::toArray($s);
-                               Cache::set($cachekey, $r, CACHE_HOUR);
+                               Cache::set($cachekey, $r, Cache::HOUR);
                        }
                }
 
@@ -1037,7 +1037,7 @@ class Profile
                        logger('URL ' . $my_url . ' already tried to authenticate.', LOGGER_DEBUG);
                        return;
                } else {
-                       Cache::set($cachekey, true, CACHE_MINUTE);
+                       Cache::set($cachekey, true, Cache::MINUTE);
                }
 
                logger('Not authenticated. Invoking reverse magic-auth for ' . $my_url, LOGGER_DEBUG);
index 23b97a5cd060346da07652fc810e74d9cb9377fd..08ec4ae1c8863cab38f03ec14a2eb84bf946fa5b 100644 (file)
@@ -381,7 +381,7 @@ class Probe
 
                // Only store into the cache if the value seems to be valid
                if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
-                       Cache::set("Probe::uri:".$network.":".$uri, $data, CACHE_DAY);
+                       Cache::set("Probe::uri:".$network.":".$uri, $data, Cache::DAY);
 
                        /// @todo temporary fix - we need a real contact update function that updates only changing fields
                        /// The biggest problem is the avatar picture that could have a reduced image size.
index a94b7f59fde0c9b18aaaf50eec92b7860232531d..2291b68e9a2c9acc116ce0130813168938b72478 100644 (file)
@@ -545,7 +545,7 @@ class Transmitter
 
                $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
 
-               Cache::set($cachekey, $data, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $data, Cache::QUARTER_HOUR);
                return $data;
        }
 
index 5792d56b6eeef6cc0e28e6315cbb08f8ed939d6f..1a8054aad51757a0103d633a0b79b24c4596f3a4 100644 (file)
@@ -3205,7 +3205,7 @@ class Diaspora
                logger("Send participation for ".$item["guid"]." by ".$author, LOGGER_DEBUG);
 
                // It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
-               Cache::set($cachekey, $item["guid"], CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $item["guid"], Cache::QUARTER_HOUR);
 
                return self::buildAndTransmit($owner, $contact, "participation", $message);
        }
@@ -3575,7 +3575,7 @@ class Diaspora
 
                $msg = ["type" => $type, "message" => $message];
 
-               Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
 
                return $msg;
        }
@@ -3702,7 +3702,7 @@ class Diaspora
                        $comment['thread_parent_guid'] = self::getGuidFromUri($item['thr-parent'], $item['uid']);
                }
 
-               Cache::set($cachekey, $comment, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $comment, Cache::QUARTER_HOUR);
 
                return($comment);
        }
index f589d3827f0bbc5ad85cf699df7cdb5552fa29f5..0e3d5e6c0f0412e326f26bc8465029595fa09179 100644 (file)
@@ -2210,7 +2210,7 @@ class OStatus
                $feeddata = trim($doc->saveXML());
 
                $msg = ['feed' => $feeddata, 'last_update' => $last_update];
-               Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
+               Cache::set($cachekey, $msg, Cache::QUARTER_HOUR);
 
                logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
 
index 5380c3c542734bb613aa4238fc960d8a755ceb4a..6f4545565fa7e78ccc9ed1a519364e471681d0cf 100644 (file)
@@ -43,7 +43,7 @@ class JsonLD
                }
 
                $data = jsonld_default_document_loader($url);
-               Cache::set('documentLoader:' . $url, $data, CACHE_DAY);
+               Cache::set('documentLoader:' . $url, $data, Cache::DAY);
                return $data;
        }
 
index 497684497fbd4cc778558cc7627626a5bc5c1ce6..c1583888c72ecb8b3efb13725b323ab79fe867d6 100644 (file)
@@ -258,7 +258,7 @@ class DiscoverPoCo
                                }
                        }
                }
-               Cache::set("dirsearch:".$search, time(), CACHE_DAY);
+               Cache::set("dirsearch:".$search, time(), Cache::DAY);
        }
 
        /**
index b27a776c7a9e65b7a62a93208a2db98f52699ea9..6cad9ac53f8d8ecb00bcde5dbc2028da1bda3122 100644 (file)
@@ -87,7 +87,7 @@ class Queue
                                        logger("Check server " . $server . " (" . $contact["network"] . ")");
 
                                        $vital = PortableContact::checkServer($server, $contact["network"], true);
-                                       Cache::set($cachekey_server . $server, $vital, CACHE_MINUTE);
+                                       Cache::set($cachekey_server . $server, $vital, Cache::MINUTE);
                                }
 
                                if (!is_null($vital) && !$vital) {
@@ -119,7 +119,7 @@ class Queue
                                        QueueModel::removeItem($q_item['id']);
                                } else {
                                        QueueModel::updateTime($q_item['id']);
-                                       Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
+                                       Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
                                }
                                break;
 
@@ -129,7 +129,7 @@ class Queue
 
                                if ($deliver_status == -1) {
                                        QueueModel::updateTime($q_item['id']);
-                                       Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
+                                       Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
                                } else {
                                        QueueModel::removeItem($q_item['id']);
                                }
@@ -144,7 +144,7 @@ class Queue
                                        QueueModel::removeItem($q_item['id']);
                                } else {
                                        QueueModel::updateTime($q_item['id']);
-                                       Cache::set($cachekey_deadguy . $contact['notify'], true, CACHE_MINUTE);
+                                       Cache::set($cachekey_deadguy . $contact['notify'], true, Cache::MINUTE);
                                }
                                break;