diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/avahi-export.php | 107 | ||||
-rw-r--r-- | scripts/compile-translation.php | 24 | ||||
-rw-r--r-- | scripts/create-testbookmarks.php | 24 | ||||
-rw-r--r-- | scripts/create-testuser.php | 10 | ||||
-rw-r--r-- | scripts/database-dump.php | 26 | ||||
-rw-r--r-- | scripts/database-restore.php | 37 | ||||
-rw-r--r-- | scripts/fix-unfiled-tags.php | 35 | ||||
-rw-r--r-- | scripts/update-translation-base.php | 19 | ||||
-rw-r--r-- | scripts/update-translation.php | 25 |
9 files changed, 307 insertions, 0 deletions
diff --git a/scripts/avahi-export.php b/scripts/avahi-export.php new file mode 100644 index 0000000..f609949 --- /dev/null +++ b/scripts/avahi-export.php @@ -0,0 +1,107 @@ +<?php +/** + * Exports bookmarks tagged with "zeroconf" + * as avahi service files. + * + * XML Documentation: "man 5 avahi.service" + * + * + * This file is part of + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; + +$fileprefix = $GLOBALS['avahiServiceFilePrefix']; +$filepath = $GLOBALS['avahiServiceFilePath']; + +$arSchemes = array( + 'ftp' => array(21, '_ftp._tcp'), + 'ssh' => array(22, '_ftp._tcp'), + 'sftp' => array(22, '_sftp-ssh._tcp'), + 'http' => array(80, '_http._tcp'), +); + +if (!is_writable($filepath)) { + echo "avahi service directory is not writable:\n"; + echo $filepath . "\n"; + exit(1); +} + +//clean out existing SemanticScuttle service files +$existing = glob($filepath . '/' . $fileprefix . '*'); +if (count($existing) > 0) { + foreach ($existing as $file) { + unlink($file); + } +} + +$bs = SemanticScuttle_Service_Factory::get('Bookmark'); +$bookmarks = $bs->getBookmarks(0, null, null, $GLOBALS['avahiTagName']); +$bookmarks = $bookmarks['bookmarks']; + +if (count($bookmarks) == 0) { + echo 'No "' . $GLOBALS['avahiTagName'] . '"-tagged bookmarks available.' . "\n"; + exit(0); +} + +$written = 0; +foreach ($bookmarks as $bm) { + $xTitle = htmlspecialchars($bm['bTitle']); + $parts = parse_url($bm['bAddress']); + + if (!isset($parts['host'])) { + echo 'No hostname in: ' . $bm['bAddress'] . "\n"; + exit(2); + } + + $xHostname = htmlspecialchars($parts['host']); + $xPath = isset($parts['path']) ? $parts['path'] : ''; + if (isset($parts['query'])) { + $xPath .= '?' . $parts['query']; + } + if (isset($parts['fragment'])) { + $xPath .= '#' . $parts['fragment']; + } + + $scheme = isset($parts['scheme']) ? $parts['scheme'] : 'http'; + if (!isset($arSchemes[$scheme])) { + //dying is hard, but at least the user knows + // that something is seriously wrong + echo "Unknown scheme: $scheme\n"; + exit(3); + } + list($xPort, $xType) = $arSchemes[$scheme]; + + if (isset($parts['port'])) { + $xPort = (int)$parts['port']; + } + + $xml = <<<XML +<?xml version="1.0" standalone='no'?> +<!DOCTYPE service-group SYSTEM "avahi-service.dtd"> +<service-group> + <name>{$xTitle}</name> + <service> + <type>{$xType}</type> + <host-name>{$xHostname}</host-name> + <port>{$xPort}</port> + <txt-record>path={$xPath}</txt-record> + </service> +</service-group> +XML; + + $file = $filepath . '/' . $fileprefix . $bm['bId'] . '.service'; + file_put_contents($file, $xml); + ++$written; +} + +echo $written . " service files created\n"; +?>
\ No newline at end of file diff --git a/scripts/compile-translation.php b/scripts/compile-translation.php new file mode 100644 index 0000000..9d48e69 --- /dev/null +++ b/scripts/compile-translation.php @@ -0,0 +1,24 @@ +<?php +/** + * Compile a translation file from .po to .mo + */ +chdir(dirname(dirname(__FILE__))); + +if ($argc < 2) { + die("pass language name to update, i.e 'de_DE'\n"); +} +$lang = $argv[1]; + +$langdir = 'data/locales/' . $lang; +if (!is_dir($langdir)) { + die('There is no language directory: ' . $langdir . "\n"); +} + + +passthru( + 'msgfmt --statistics' + . ' ' . $langdir . '/LC_MESSAGES/messages.po' + . ' -o ' . $langdir . '/LC_MESSAGES/messages.mo' +); + +?>
\ No newline at end of file diff --git a/scripts/create-testbookmarks.php b/scripts/create-testbookmarks.php new file mode 100644 index 0000000..cbacb85 --- /dev/null +++ b/scripts/create-testbookmarks.php @@ -0,0 +1,24 @@ +<?php +/** + * Simply create some test bookmarks + */ +require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; + +$us = SemanticScuttle_Service_Factory::get('User'); +$uid = $us->addUser('dummy', 'dummy', 'dummy@example.org'); + +$bs = SemanticScuttle_Service_Factory::get('Bookmark'); +for ($nA = 0; $nA < 10; $nA++) { + $rand = rand(); + $bid = $bs->addBookmark( + 'http://example.org/' . $rand, + 'unittest bookmark #' . $rand, + 'description', + null, + 0, + array('unittest'), + null, null, false, false, + $uid + ); +} +?>
\ No newline at end of file diff --git a/scripts/create-testuser.php b/scripts/create-testuser.php new file mode 100644 index 0000000..0a74f6c --- /dev/null +++ b/scripts/create-testuser.php @@ -0,0 +1,10 @@ +<?php +/** + * Simply create a test user in the database with "test" as password + */ +require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; + +$us = SemanticScuttle_Service_Factory::get('User'); +$us->addUser('test', 'test', 'test@example.org'); +$us->addUser('admin', 'admin', 'admin@example.org'); +?>
\ No newline at end of file diff --git a/scripts/database-dump.php b/scripts/database-dump.php new file mode 100644 index 0000000..f4f04ac --- /dev/null +++ b/scripts/database-dump.php @@ -0,0 +1,26 @@ +<?php +/** + * Dumps the semanticscuttle database into a file using mysqldump. + * + * This file is part of + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; + +passthru( + 'mysqldump' + . ' -h' . escapeshellarg($GLOBALS['dbhost']) + . ' -u' . escapeshellarg($GLOBALS['dbuser']) + . ' -p' . escapeshellarg($GLOBALS['dbpass']) + . ' ' . escapeshellarg($GLOBALS['dbname']) + . ' > semanticscuttle-dump.sql' +); +?>
\ No newline at end of file diff --git a/scripts/database-restore.php b/scripts/database-restore.php new file mode 100644 index 0000000..6516e71 --- /dev/null +++ b/scripts/database-restore.php @@ -0,0 +1,37 @@ +<?php +/** + * Restores the semanticscuttle database from a given file. + * + * This file is part of + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +if (!isset($argv[1])) { + echo "Please pass the sql file to restore\n"; + exit(1); +} +$file = $argv[1]; +if (!file_exists($file)) { + echo "The file does not exist\n"; + exit(2); +} + +require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; + +passthru( + 'mysql' + . ' -h' . escapeshellarg($GLOBALS['dbhost']) + . ' -u' . escapeshellarg($GLOBALS['dbuser']) + . ' -p' . escapeshellarg($GLOBALS['dbpass']) + . ' ' . escapeshellarg($GLOBALS['dbname']) + . ' < ' . escapeshellarg($file) +); +?>
\ No newline at end of file diff --git a/scripts/fix-unfiled-tags.php b/scripts/fix-unfiled-tags.php new file mode 100644 index 0000000..8a5238e --- /dev/null +++ b/scripts/fix-unfiled-tags.php @@ -0,0 +1,35 @@ +<?php +/** + * SemanticScuttle from approximately 0.94 up to 0.98.2, system:unfiled + * tags were not created when adding new bookmarks with the web interface. + * + * This script adds system:unfiled tags for all bookmarks that have no + * tags. + */ +require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; + +//needed to load the database object +$bt = SemanticScuttle_Service_Factory::get('Bookmark2Tag'); +$db = SemanticScuttle_Service_Factory::getDb(); + +$query = <<<SQL +SELECT b.bId +FROM sc_bookmarks AS b + LEFT JOIN sc_bookmarks2tags AS bt ON b.bId = bt.bId +WHERE bt.bId IS NULL +SQL; + +if (!($dbresult = $db->sql_query($query))) { + die('Strange SQL error'); +} +while ($row = $db->sql_fetchrow($dbresult)) { + $db->sql_query( + 'INSERT INTO ' . $bt->getTableName() . ' ' + . $db->sql_build_array( + 'INSERT', + array('bId' => $row['bId'], 'tag' => 'system:unfiled') + ) + ); +} +$db->sql_freeresult($dbresult); +?>
\ No newline at end of file diff --git a/scripts/update-translation-base.php b/scripts/update-translation-base.php new file mode 100644 index 0000000..8237510 --- /dev/null +++ b/scripts/update-translation-base.php @@ -0,0 +1,19 @@ +<?php +/** + * Update gettext translation base file + */ +chdir(dirname(dirname(__FILE__))); + +//do not include php-gettext or database layer +passthru( + 'xgettext -kT_ngettext:1,2 -kT_ -L PHP' + . ' -o data/locales/messages.po' + . ' src/SemanticScuttle/*.php' + . ' src/SemanticScuttle/Model/*.php' + . ' src/SemanticScuttle/Service/*.php' + . ' data/templates/default/*.php' + . ' www/*.php' + . ' www/*/*.php' +); + +?>
\ No newline at end of file diff --git a/scripts/update-translation.php b/scripts/update-translation.php new file mode 100644 index 0000000..4c950f1 --- /dev/null +++ b/scripts/update-translation.php @@ -0,0 +1,25 @@ +<?php +/** + * Update single gettext translation from + * gettext base file + */ +chdir(dirname(dirname(__FILE__))); + +if ($argc < 2) { + die("pass language name to update, i.e 'de_DE'\n"); +} +$lang = $argv[1]; + +$langdir = 'data/locales/' . $lang; +if (!is_dir($langdir)) { + die('There is no language directory: ' . $langdir . "\n"); +} + + +passthru( + 'msgmerge --update --backup=off' + . ' ' . $langdir . '/LC_MESSAGES/messages.po' + . ' data/locales/messages.po' +); + +?>
\ No newline at end of file |