From 6eebd8c90941ddfe8eeca1961f7a7a493e227687 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 20 Aug 2015 20:10:32 +0200 Subject: [PATCH] Remove unsed things --- .../Controller/StaticController.php | 8 -- src/Wallabag/CoreBundle/Entity/Entry.php | 4 +- src/Wallabag/CoreBundle/Helper/Entry.php | 7 - src/Wallabag/CoreBundle/Helper/Tools.php | 133 ------------------ .../CoreBundle/Resources/config/routing.yml | 7 - src/Wallabag/CoreBundle/Tools/Utils.php | 13 ++ 6 files changed, 15 insertions(+), 157 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Helper/Entry.php delete mode 100755 src/Wallabag/CoreBundle/Helper/Tools.php diff --git a/src/Wallabag/CoreBundle/Controller/StaticController.php b/src/Wallabag/CoreBundle/Controller/StaticController.php index 3b844b44c..64875a665 100644 --- a/src/Wallabag/CoreBundle/Controller/StaticController.php +++ b/src/Wallabag/CoreBundle/Controller/StaticController.php @@ -28,12 +28,4 @@ class StaticController extends Controller array() ); } - - /** - * @Route("/", name="homepage") - */ - public function apiAction() - { - return $this->redirect($this->generateUrl('nelmio_api_doc_index')); - } } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 7d2d2027f..f88d189d3 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Hateoas\Configuration\Annotation as Hateoas; use JMS\Serializer\Annotation\XmlRoot; -use Wallabag\CoreBundle\Helper\Tools; +use Wallabag\CoreBundle\Tools\Utils; /** * Entry. @@ -265,7 +265,7 @@ class Entry public function setContent($content) { $this->content = $content; - $this->readingTime = Tools::getReadingTime($content); + $this->readingTime = Utils::getReadingTime($content); $this->domainName = parse_url($this->url, PHP_URL_HOST); return $this; diff --git a/src/Wallabag/CoreBundle/Helper/Entry.php b/src/Wallabag/CoreBundle/Helper/Entry.php deleted file mode 100644 index 219711b3d..000000000 --- a/src/Wallabag/CoreBundle/Helper/Entry.php +++ /dev/null @@ -1,7 +0,0 @@ - array( - 'timeout' => $timeout, - 'header' => 'User-Agent: '.$useragent, - 'follow_location' => true, - ), - 'ssl' => array( - 'verify_peer' => false, - 'allow_self_signed' => true, - ), - ) - ); - - # only download page lesser than 4MB - $data = @file_get_contents($url, false, $context, -1, 4000000); - - if (isset($http_response_header) and isset($http_response_header[0])) { - $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== false) or (strpos($http_response_header[0], '301 Moved Permanently') !== false)); - } - } - - # if response is not empty and response is OK - if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { - # take charset of page and get it - preg_match('##Usi', $data, $meta); - - # if meta tag is found - if (!empty($meta[0])) { - preg_match('#charset="?(.*)"#si', $meta[0], $encoding); - # if charset is found set it otherwise, set it to utf-8 - $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; - if (empty($encoding[1])) { - $encoding[1] = 'utf-8'; - } - } else { - $html_charset = 'utf-8'; - $encoding[1] = ''; - } - - # replace charset of url to charset of page - $data = str_replace('charset='.$encoding[1], 'charset='.$html_charset, $data); - - return $data; - } else { - return false; - } - } - - /** - * Encode a URL by using a salt. - * - * @param $string - * - * @return string - */ - public static function encodeString($string) - { - return sha1($string.SALT); - } - - public static function generateToken() - { - if (ini_get('open_basedir') === '') { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - // alternative to /dev/urandom for Windows - $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); - } else { - $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); - } - } else { - $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); - } - - return str_replace('+', '', $token); - } - - /** - * For a given text, we calculate reading time for an article. - * - * @param $text - * - * @return float - */ - public static function getReadingTime($text) - { - return floor(str_word_count(strip_tags($text)) / 200); - } -} diff --git a/src/Wallabag/CoreBundle/Resources/config/routing.yml b/src/Wallabag/CoreBundle/Resources/config/routing.yml index f3502e156..e69de29bb 100644 --- a/src/Wallabag/CoreBundle/Resources/config/routing.yml +++ b/src/Wallabag/CoreBundle/Resources/config/routing.yml @@ -1,7 +0,0 @@ -entry: - resource: "@WallabagCoreBundle/Controller/EntryController.php" - type: annotation - -config: - resource: "@WallabagCoreBundle/Controller/ConfigController.php" - type: annotation diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index 7e2968e77..a4fbcffda 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php @@ -25,4 +25,17 @@ class Utils // remove character which can broken the url return str_replace(array('+', '/'), '', $token); } + + /** + * For a given text, we calculate reading time for an article + * based on 200 words per minute + * + * @param $text + * + * @return float + */ + public static function getReadingTime($text) + { + return floor(str_word_count(strip_tags($text)) / 200); + } }