diff options
Diffstat (limited to 'app')
-rwxr-xr-x | app/app.php | 3 | ||||
-rw-r--r-- | app/classes/Cache.php | 360 | ||||
-rw-r--r-- | app/classes/Opml.php | 42 | ||||
-rw-r--r-- | app/classes/OpmlManager.php | 6 | ||||
-rw-r--r-- | app/classes/Planet.php | 25 | ||||
-rw-r--r-- | app/classes/PlanetConfig.php | 4 | ||||
-rwxr-xr-x | app/classes/Simplel10n.php | 30 | ||||
-rw-r--r-- | app/helpers.php | 7 | ||||
-rwxr-xr-x | app/l10n/extract.php | 78 |
9 files changed, 283 insertions, 272 deletions
diff --git a/app/app.php b/app/app.php index f82b262..4ae1947 100755 --- a/app/app.php +++ b/app/app.php @@ -13,7 +13,7 @@ if (is_installed()) { $conf = Spyc::YAMLLoad($savedConfig); // this is a check to upgrade older config file without l10n - if(!isset($conf['locale'])) { + if (!isset($conf['locale'])) { $resetPlanetConfig = new PlanetConfig($conf); file_put_contents($savedConfig, $resetPlanetConfig->toYaml()); $conf = Spyc::YAMLLoad($savedConfig); @@ -25,7 +25,6 @@ if (is_installed()) { if ($conf['debug']) { error_reporting(E_ALL); } - } $l10n = new Simplel10n($conf['locale']); diff --git a/app/classes/Cache.php b/app/classes/Cache.php index b73182e..f4b2dcf 100644 --- a/app/classes/Cache.php +++ b/app/classes/Cache.php @@ -13,242 +13,238 @@ * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* +* * © Copyright 2005 Richard Heyes */ /** * Caching Libraries for PHP5 -* +* * Handles data and output caching. Defaults to /dev/shm * (shared memory). All methods are static. -* +* * Eg: (output caching) -* +* * if (!OutputCache::Start('group', 'unique id', 600)) { -* +* * // ... Output -* +* * OutputCache::End(); * } -* +* * Eg: (data caching) -* +* * if (!$data = DataCache::Get('group', 'unique id')) { -* +* * $data = time(); -* +* * DataCache::Put('group', 'unique id', 10, $data); * } -* +* * echo $data; */ - class Cache - { - /** - * Whether caching is enabled - * @var bool - */ - public static $enabled = true; +class Cache +{ + /** + * Whether caching is enabled + * @var bool + */ + public static $enabled = true; - /** - * Place to store the cache files - * @var string - */ - protected static $store = '/dev/shm/'; + /** + * Place to store the cache files + * @var string + */ + protected static $store = '/dev/shm/'; - /** - * Prefix to use on cache files - * @var string - */ - protected static $prefix = 'cache_'; + /** + * Prefix to use on cache files + * @var string + */ + protected static $prefix = 'cache_'; - /** - * Stores data - * - * @param string $group Group to store data under - * @param string $id Unique ID of this data - * @param int $ttl How long to cache for (in seconds) - */ - protected static function write($group, $id, $ttl, $data) - { - $filename = self::getFilename($group, $id); - - if (self::$enabled && $fp = fopen($filename, 'xb')) { + /** + * Stores data + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + * @param int $ttl How long to cache for (in seconds) + */ + protected static function write($group, $id, $ttl, $data) + { + $filename = self::getFilename($group, $id); - if (flock($fp, LOCK_EX)) { - fwrite($fp, $data); - } - fclose($fp); - - // Set filemtime - touch($filename, time() + $ttl); + if (self::$enabled && $fp = fopen($filename, 'xb')) { + if (flock($fp, LOCK_EX)) { + fwrite($fp, $data); } + fclose($fp); + + // Set filemtime + touch($filename, time() + $ttl); } + } - /** - * Reads data - * - * @param string $group Group to store data under - * @param string $id Unique ID of this data - */ - protected static function read($group, $id) - { - $filename = self::getFilename($group, $id); + /** + * Reads data + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + */ + protected static function read($group, $id) + { + $filename = self::getFilename($group, $id); - return file_get_contents($filename); - } + return file_get_contents($filename); + } - /** - * Determines if an entry is cached - * - * @param string $group Group to store data under - * @param string $id Unique ID of this data - */ - protected static function isCached($group, $id) - { - $filename = self::getFilename($group, $id); + /** + * Determines if an entry is cached + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + */ + protected static function isCached($group, $id) + { + $filename = self::getFilename($group, $id); - if (self::$enabled && file_exists($filename) && filemtime($filename) > time()) { - return true; - } + if (self::$enabled && file_exists($filename) && filemtime($filename) > time()) { + return true; + } - @unlink($filename); + @unlink($filename); - return false; - } + return false; + } - /** - * Builds a filename/path from group, id and - * store. - * - * @param string $group Group to store data under - * @param string $id Unique ID of this data - */ - protected static function getFilename($group, $id) - { - $id = md5($id); + /** + * Builds a filename/path from group, id and + * store. + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + */ + protected static function getFilename($group, $id) + { + $id = md5($id); - return self::$store . self::$prefix . "{$group}_{$id}"; - } + return self::$store . self::$prefix . "{$group}_{$id}"; + } - /** - * Sets the filename prefix to use - * - * @param string $prefix Filename Prefix to use - */ - public static function setPrefix($prefix) - { - self::$prefix = $prefix; - } + /** + * Sets the filename prefix to use + * + * @param string $prefix Filename Prefix to use + */ + public static function setPrefix($prefix) + { + self::$prefix = $prefix; + } - /** - * Sets the store for cache files. Defaults to - * /dev/shm. Must have trailing slash. - * - * @param string $store The dir to store the cache data in - */ - public static function setStore($store) - { - self::$store = $store; - } + /** + * Sets the store for cache files. Defaults to + * /dev/shm. Must have trailing slash. + * + * @param string $store The dir to store the cache data in + */ + public static function setStore($store) + { + self::$store = $store; } +} /** * Output Cache extension of base caching class */ - class OutputCache extends Cache - { - /** - * Group of currently being recorded data - * @var string - */ - private static $group; +class OutputCache extends Cache +{ + /** + * Group of currently being recorded data + * @var string + */ + private static $group; - /** - * ID of currently being recorded data - * @var string - */ - private static $id; + /** + * ID of currently being recorded data + * @var string + */ + private static $id; - /** - * Ttl of currently being recorded data - * @var int - */ - private static $ttl; + /** + * Ttl of currently being recorded data + * @var int + */ + private static $ttl; - /** - * Starts caching off. Returns true if cached, and dumps - * the output. False if not cached and start output buffering. - * - * @param string $group Group to store data under - * @param string $id Unique ID of this data - * @param int $ttl How long to cache for (in seconds) - * @return bool True if cached, false if not - */ - public static function Start($group, $id, $ttl) - { - if (self::isCached($group, $id)) { - echo self::read($group, $id); - return true; - - } else { - - ob_start(); + /** + * Starts caching off. Returns true if cached, and dumps + * the output. False if not cached and start output buffering. + * + * @param string $group Group to store data under + * @param string $id Unique ID of this data + * @param int $ttl How long to cache for (in seconds) + * @return bool True if cached, false if not + */ + public static function Start($group, $id, $ttl) + { + if (self::isCached($group, $id)) { + echo self::read($group, $id); + return true; + } else { + ob_start(); - self::$group = $group; - self::$id = $id; - self::$ttl = $ttl; + self::$group = $group; + self::$id = $id; + self::$ttl = $ttl; - return false; - } + return false; } + } - /** - * Ends caching. Writes data to disk. - */ - public static function End() - { - $data = ob_get_contents(); - ob_end_flush(); + /** + * Ends caching. Writes data to disk. + */ + public static function End() + { + $data = ob_get_contents(); + ob_end_flush(); - self::write(self::$group, self::$id, self::$ttl, $data); - } + self::write(self::$group, self::$id, self::$ttl, $data); } +} /** * Data cache extension of base caching class */ - class DataCache extends Cache - { +class DataCache extends Cache +{ - /** - * Retrieves data from the cache - * - * @param string $group Group this data belongs to - * @param string $id Unique ID of the data - * @return mixed Either the resulting data, or null - */ - public static function Get($group, $id) - { - if (self::isCached($group, $id)) { - return unserialize(self::read($group, $id)); - } - - return null; + /** + * Retrieves data from the cache + * + * @param string $group Group this data belongs to + * @param string $id Unique ID of the data + * @return mixed Either the resulting data, or null + */ + public static function Get($group, $id) + { + if (self::isCached($group, $id)) { + return unserialize(self::read($group, $id)); } + + return null; + } - /** - * Stores data in the cache - * - * @param string $group Group this data belongs to - * @param string $id Unique ID of the data - * @param int $ttl How long to cache for (in seconds) - * @param mixed $data The data to store - */ - public static function Put($group, $id, $ttl, $data) - { - self::write($group, $id, $ttl, serialize($data)); - } + /** + * Stores data in the cache + * + * @param string $group Group this data belongs to + * @param string $id Unique ID of the data + * @param int $ttl How long to cache for (in seconds) + * @param mixed $data The data to store + */ + public static function Put($group, $id, $ttl, $data) + { + self::write($group, $id, $ttl, serialize($data)); } -?>
\ No newline at end of file +} diff --git a/app/classes/Opml.php b/app/classes/Opml.php index ae9e8b1..a9de2b0 100644 --- a/app/classes/Opml.php +++ b/app/classes/Opml.php @@ -2,12 +2,12 @@ class Opml { - var $_xml = null; - var $_currentTag = ''; + private $_xml = null; + private $_currentTag = ''; - var $title = ''; - var $entries = array(); - var $map = + public $title = ''; + public $entries = array(); + private $map = array( 'URL' => 'website', 'HTMLURL' => 'website', @@ -19,30 +19,28 @@ class Opml ); - function parse($data) + public function parse($data) { $this->_xml = xml_parser_create('UTF-8'); //xml_parser_set_option($this->_xml, XML_OPTION_CASE_FOLDING, false); //xml_parser_set_option($this->_xml, XML_OPTION_SKIP_WHITE, true); xml_set_object($this->_xml, $this); - xml_set_element_handler($this->_xml,'_openTag','_closeTag'); - xml_set_character_data_handler ($this->_xml, '_cData'); + xml_set_element_handler($this->_xml, '_openTag', '_closeTag'); + xml_set_character_data_handler($this->_xml, '_cData'); - xml_parse($this->_xml,$data); + xml_parse($this->_xml, $data); xml_parser_free($this->_xml); return $this->entries; } - function _openTag($p,$tag,$attrs) + private function _openTag($p, $tag, $attrs) { $this->_currentTag = $tag; - if ($tag == 'OUTLINE') - { + if ($tag == 'OUTLINE') { $i = count($this->entries); - foreach (array_keys($this->map) as $key) - { + foreach (array_keys($this->map) as $key) { if (isset($attrs[$key])) { $this->entries[$i][$this->map[$key]] = $attrs[$key]; } @@ -50,21 +48,25 @@ class Opml } } - function _closeTag($p, $tag){ + private function _closeTag($p, $tag) + { $this->_currentTag = ''; } - function _cData($p, $cdata){ - if ($this->_currentTag == 'TITLE'){ + private function _cData($p, $cdata) + { + if ($this->_currentTag == 'TITLE') { $this->title = $cdata; } } - function getTitle(){ + public function getTitle() + { return $this->title; } - function getPeople(){ + public function getPeople() + { return $this->entries; } -}
\ No newline at end of file +} diff --git a/app/classes/OpmlManager.php b/app/classes/OpmlManager.php index d3940b2..66de7c9 100644 --- a/app/classes/OpmlManager.php +++ b/app/classes/OpmlManager.php @@ -26,7 +26,8 @@ class OpmlManager * @param Opml $opml * @param string $file */ - public static function save($opml, $file){ + public static function save($opml, $file) + { $out = '<?xml version="1.0"?>'."\n"; $out.= '<opml version="1.1">'."\n"; $out.= '<head>'."\n"; @@ -44,7 +45,8 @@ class OpmlManager file_put_contents($file, $out); } - public static function backup($file){ + public static function backup($file) + { copy($file, $file.'.bak'); } } diff --git a/app/classes/Planet.php b/app/classes/Planet.php index d6007e5..898126f 100644 --- a/app/classes/Planet.php +++ b/app/classes/Planet.php @@ -51,7 +51,7 @@ class Planet * * @param PlanetConfig $config */ - public function __construct($config=null) + public function __construct($config = null) { $this->config = $config === null ? new PlanetConfig() : $config; @@ -87,7 +87,8 @@ class Planet { $this->items = $this->_filterItemsByCategory( $this->items, - $this->config->getCategories()); + $this->config->getCategories() + ); return $this->items; } @@ -122,7 +123,7 @@ class Planet $opml = OpmlManager::load($file); $opml_people = $opml->getPeople(); - foreach ($opml_people as $opml_person){ + foreach ($opml_people as $opml_person) { $person = new PlanetFeed( $opml_person['name'], $opml_person['feed'], @@ -146,7 +147,6 @@ class Planet $feed->init(); $this->items = array_merge($this->items, $feed->get_items()); } - } $this->sort(); } @@ -156,7 +156,7 @@ class Planet * * @param float $max_load Percentage of feeds to load */ - public function download($max_load=0.1) + public function download($max_load = 0.1) { $max_load_feeds = ceil(count($this->people) * $max_load); $opml = OpmlManager::load(__DIR__.'/../../custom/people.opml'); @@ -184,7 +184,7 @@ class Planet $isDown = ''; // http://simplepie.org/wiki/reference/simplepie/merge_items ? - if (($feed->data) && ($feed->get_item_quantity() > 0)){ + if (($feed->data) && ($feed->get_item_quantity() > 0)) { $items = $feed->get_items(); $this->items = array_merge($this->items, $items); } else { @@ -221,20 +221,21 @@ class Planet */ public function _filterItemsByCategory($items, $categories = null) { - if (is_null($categories) or empty(trim($categories))) - { + if (is_null($categories) or empty(trim($categories))) { return $items; } $categories = array_map('trim', explode(',', strtolower($categories))); $cb_category_filter = - function ($item) use ($categories) - { - if (!is_array($item_categories = $item->get_categories())) + function ($item) use ($categories) { + if (!is_array($item_categories = $item->get_categories())) { return false; + } $item_categories = array_map( - function ($i) { return strtolower($i->get_label()); }, + function ($i) { + return strtolower($i->get_label()); + }, $item_categories ); diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php index f3928bc..257d1b9 100644 --- a/app/classes/PlanetConfig.php +++ b/app/classes/PlanetConfig.php @@ -52,7 +52,8 @@ class PlanetConfig return $this->conf['url']; } - public function getName(){ + public function getName() + { return $this->conf['name']; } @@ -190,5 +191,4 @@ class PlanetConfig $this->conf[$key] = $value; } - } diff --git a/app/classes/Simplel10n.php b/app/classes/Simplel10n.php index 79313b3..f84ef5c 100755 --- a/app/classes/Simplel10n.php +++ b/app/classes/Simplel10n.php @@ -1,24 +1,28 @@ <?php -class Simplel10n { +class Simplel10n +{ public $locale; public $l10nFolder; - public function __construct($locale='en') { + public function __construct($locale = 'en') + { $GLOBALS['locale'] = array(); $this->locale = $locale; $this->l10nFolder = __DIR__ . '/../l10n/'; $this->load($this->l10nFolder . $this->locale); } - public function setL1OnFolder($path) { + public function setL1OnFolder($path) + { $this->l10nFolder = $path; } - static function getString($str, $comment='') { - if(array_key_exists($str, $GLOBALS['locale'])) { + public static function getString($str, $comment = '') + { + if (array_key_exists($str, $GLOBALS['locale'])) { return trim(str_replace('{ok}', '', $GLOBALS['locale'][$str])); } else { return $str; @@ -29,23 +33,27 @@ class Simplel10n { * This is the same as getString except that we don't remove the {ok} string * This is needed only for the extraction script */ - static function extractString($str, $comment='') { - if(array_key_exists($str, $GLOBALS['locale'])) { + public static function extractString($str, $comment = '') + { + if (array_key_exists($str, $GLOBALS['locale'])) { return $GLOBALS['locale'][$str]; } else { return $str; } } - static function load($pathToFile) { + public static function load($pathToFile) + { - if (!file_exists($pathToFile . '.lang')) return false; + if (!file_exists($pathToFile . '.lang')) { + return false; + } $file = file($pathToFile . '.lang'); foreach ($file as $k => $v) { - if (substr($v,0,1) == ';' && !empty($file[$k+1])) { - $GLOBALS['locale'][trim(substr($v,1))] = trim($file[$k+1]); + if (substr($v, 0, 1) == ';' && !empty($file[$k+1])) { + $GLOBALS['locale'][trim(substr($v, 1))] = trim($file[$k+1]); } } } diff --git a/app/helpers.php b/app/helpers.php index 5f251e4..f3a9dfa 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -2,9 +2,9 @@ /** * Register polyfills for old PHP versions. - * + * * This way, the real function will only be called if it - * is available, and we won't force the use of our own + * is available, and we won't force the use of our own * implementation. */ function register_polyfills() @@ -63,7 +63,7 @@ function is_installed() * @param string $comment * @return string */ -function _g($str, $comment='') +function _g($str, $comment = '') { return Simplel10n::getString($str, $comment); } @@ -86,4 +86,3 @@ function removeCustomFiles() } } } - diff --git a/app/l10n/extract.php b/app/l10n/extract.php index 1384827..ef44912 100755 --- a/app/l10n/extract.php +++ b/app/l10n/extract.php @@ -29,41 +29,44 @@ $GLOBALS['english'] = array(); * */ -function extract_l10n_strings($file) { +function extract_l10n_strings($file) +{ $lines = file($file); $patterns = array('/_g\([\'"](.*?)[\'"]\)/', '/getString\([\'"](.*?)[\'"]\)/',); foreach ($lines as $line) { - // Skip comments - if($line[0] == '#' || $line[0] == '/') continue; + if ($line[0] == '#' || $line[0] == '/') { + continue; + } // parsing logic - foreach($patterns as $pattern) { - if(preg_match_all($pattern, $line, $matches, PREG_PATTERN_ORDER)) { - foreach($matches[1] as $val) { - + foreach ($patterns as $pattern) { + if (preg_match_all($pattern, $line, $matches, PREG_PATTERN_ORDER)) { + foreach ($matches[1] as $val) { // Do not extract php variables calls or empty strings - if($val[0] == '$' || $val == '') continue; + if ($val[0] == '$' || $val == '') { + continue; + } // Is there a localization comment ? $l10n_note = explode("',", $val); // Also test strings in double quotes - if(count($l10n_note) == 1) { + if (count($l10n_note) == 1) { $l10n_note = explode('",', $val); } // Extract cleaned up strings - if(count($l10n_note) == 2) { + if (count($l10n_note) == 2) { $l10n_str = trim($l10n_note[0]); - $l10n_note = trim(substr(trim($l10n_note[1]),1)); # Remove quote at begining of string + $l10n_note = trim(substr(trim($l10n_note[1]), 1)); # Remove quote at begining of string } else { $l10n_str = trim($val); $l10n_note = ''; } - if(!array_key_exists($l10n_str, $GLOBALS['english'])) { + if (!array_key_exists($l10n_str, $GLOBALS['english'])) { $GLOBALS['english'][$l10n_str] = array($l10n_str, $l10n_note); } } @@ -80,12 +83,13 @@ function extract_l10n_strings($file) { * show_l10n_strings() ; */ -function show_l10n_strings() { +function show_l10n_strings() +{ header('Content-Type:text/plain'); - foreach($GLOBALS['english'] as $val) { - if($val[1]) { + foreach ($GLOBALS['english'] as $val) { + if ($val[1]) { echo '# ' . $val[1] . "\n"; } echo ";$val[0]\n"; @@ -98,28 +102,28 @@ function show_l10n_strings() { * returns an array of file paths */ -function find_all_files($dir) { +function find_all_files($dir) +{ $result = array(); $root = scandir($dir); $ignore = array('.', '..', '.git', '.svn', '.hg', 'cache', '.gitignore', 'lib'); - foreach($root as $value) { - - if(in_array($value, $ignore)) { + foreach ($root as $value) { + if (in_array($value, $ignore)) { continue; } - if(is_file("$dir/$value")) { + if (is_file("$dir/$value")) { $split = explode('.', $value); - if(end($split) == 'php'){ + if (end($split) == 'php') { $result[] = "$dir/$value"; } continue; } - foreach(find_all_files("$dir/$value") as $value) { + foreach (find_all_files("$dir/$value") as $value) { $result[]=$value; } } @@ -127,11 +131,12 @@ function find_all_files($dir) { return $result; } -function update_lang_files($source, $dest) { +function update_lang_files($source, $dest) +{ $files = find_all_files($source); - foreach($files as $file) { + foreach ($files as $file) { extract_l10n_strings($file); } @@ -142,39 +147,38 @@ function update_lang_files($source, $dest) { // list locales $locales = array(); - foreach($files as $file) { - - if(in_array($file, $ignore)) { + foreach ($files as $file) { + if (in_array($file, $ignore)) { continue; } $split = explode('.', $file); - if($split[1] == 'lang') { + if ($split[1] == 'lang') { $locales[] = $split[0]; } - } + } - foreach($locales as $locale) { + foreach ($locales as $locale) { $status[$locale] = 0; $lang_file_path = $dest . '/' . $locale; Simplel10n::load($lang_file_path); ob_start(); - foreach($GLOBALS['english'] as $key => $val) { + foreach ($GLOBALS['english'] as $key => $val) { $warning = ''; $value = @Simplel10n::extractString($key); - if($value == $val[0]) { + if ($value == $val[0]) { $status[$locale]++; $warning = ' ** String needs translation **'; } - if($val[1]) { + if ($val[1]) { echo '# Translation note: ' . $val[1] . $warning . "\n"; - } elseif($warning != '') { + } elseif ($warning != '') { echo '# Translation note: ' . $warning . "\n"; } @@ -187,16 +191,16 @@ function update_lang_files($source, $dest) { file_put_contents($lang_file_path. '.lang', $content); unset($GLOBALS['locale']); - } + } // Display a short status report header('Content-Type:text/plain'); echo "Number of English strings: " . count($GLOBALS['english']) . "\n"; echo "Your installation has these languages installed: " . implode(', ', $locales) . "\n"; - foreach($locales as $val) { + foreach ($locales as $val) { echo $val . " has " . $status[$val] . " untranslated strings.\n"; - } + } } update_lang_files($root, $root . 'app/l10n'); |