From 926a872aab1d105640039c5ec44693a8f56cee95 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Sat, 4 Jun 2011 17:32:21 +0200 Subject: [PATCH] Added media files for entries --- admin/tpl/header.php | 1 + inc/definition/Definition.php | 23 +--------- inc/definition/DefinitionService.php | 15 ++++--- inc/definition/Entry.php | 44 +++++++++++++++++- inc/definition/Meaning.php | 9 +--- inc/kumva.php | 1 + inc/theme/Templates.php | 15 +++++-- inc/theme/Widgets.php | 9 ++-- index.php | 2 +- lang/en/site.php | 6 +++ lang/rw/site.php | 6 +++ lib/akabanga/utils.php | 25 +++++++++++ themes/kinyarwanda/pages/pronunciation.php | 52 +++++++++++----------- 13 files changed, 137 insertions(+), 71 deletions(-) diff --git a/admin/tpl/header.php b/admin/tpl/header.php index 2b26f7a..f4eb165 100644 --- a/admin/tpl/header.php +++ b/admin/tpl/header.php @@ -35,6 +35,7 @@ )), array('pages.php', KU_STR_SITE, 'site', NULL, array( array('pages.php', KU_STR_PAGES, 'pages', NULL), + array('media.php', KU_STR_MEDIA, 'media', NULL), array('languages.php', KU_STR_LANGUAGES, 'languages', NULL), array('settings.php', KU_STR_SETTINGS, 'settings', Role::ADMINISTRATOR) )) diff --git a/inc/definition/Definition.php b/inc/definition/Definition.php index d9d0f48..613285f 100755 --- a/inc/definition/Definition.php +++ b/inc/definition/Definition.php @@ -56,7 +56,6 @@ class Definition extends Entity { private $modifier; private $pronunciation; private $comment; - private $media; private $unverified; // Lazy loaded properties @@ -80,12 +79,11 @@ class Definition extends Entity { * @param string modifier the modifier, e.g. 'aba-' * @param string pronunciation the pronunciation, e.g. 'umugabo' * @param string comment the comment - * @param int media the media flags * @param bool unverified TRUE if definition is unverified */ public function __construct( $id = 0, $entryId = 0, $revision = 0, $revisionStatus = 0, $changeId = 0, - $wordClass = '', $prefix = '', $lemma = '', $modifier = '', $pronunciation = '', $comment = '', $media = 0, $unverified = FALSE) + $wordClass = '', $prefix = '', $lemma = '', $modifier = '', $pronunciation = '', $comment = '', $unverified = FALSE) { $this->id = (int)$id; $this->entryId = (int)$entryId; @@ -98,7 +96,6 @@ public function __construct( $this->modifier = $modifier; $this->pronunciation = $pronunciation; $this->comment = $comment; - $this->media = (int)$media; $this->unverified = (bool)$unverified; } @@ -108,7 +105,7 @@ public function __construct( * @return Definition the definition */ public static function fromRow(&$row) { - return new Definition($row['definition_id'], $row['entry_id'], $row['revision'], $row['revisionstatus'], $row['change_id'], $row['wordclass'], $row['prefix'], $row['lemma'], $row['modifier'], $row['pronunciation'], $row['comment'], $row['media'], $row['unverified']); + return new Definition($row['definition_id'], $row['entry_id'], $row['revision'], $row['revisionstatus'], $row['change_id'], $row['wordclass'], $row['prefix'], $row['lemma'], $row['modifier'], $row['pronunciation'], $row['comment'], $row['unverified']); } /** @@ -298,22 +295,6 @@ public function setComment($comment) { $this->comment = $comment; } - /** - * Gets the media flags - * @return int the media flags - */ - public function getMedia() { - return $this->media; - } - - /** - * Sets the media flags - * @param int media the media flags - */ - public function setMedia($media) { - $this->media = $media; - } - /** * Gets if this is unverified * @return bool TRUE if unverified diff --git a/inc/definition/DefinitionService.php b/inc/definition/DefinitionService.php index 331b0a3..73fccab 100644 --- a/inc/definition/DefinitionService.php +++ b/inc/definition/DefinitionService.php @@ -196,7 +196,9 @@ public function getDefinitionExamples($definition) { */ public function saveEntry($entry) { if ($entry->isNew()) { - $sql = 'INSERT INTO `'.KUMVA_DB_PREFIX.'entry` VALUES(NULL)'; + $sql = 'INSERT INTO `'.KUMVA_DB_PREFIX.'entry` VALUES(' + .'NULL,' + .aka_prepsqlval($entry->getMedia()).')'; $res = $this->database->insert($sql); if ($res === FALSE) @@ -204,11 +206,12 @@ public function saveEntry($entry) { $entry->setId($res); } else { - //$sql = 'UPDATE `'.KUMVA_DB_PREFIX.'entry` SET ' - //.'WHERE entry_id = '.$entry->getId(); + $sql = 'UPDATE `'.KUMVA_DB_PREFIX.'entry` SET ' + .'media = '.aka_prepsqlval($entry->getMedia()).' ' + .'WHERE entry_id = '.$entry->getId(); - //if ($this->database->query($sql) === FALSE) - //return FALSE; + if ($this->database->query($sql) === FALSE) + return FALSE; } return TRUE; } @@ -232,7 +235,6 @@ public function saveDefinition($definition) { .aka_prepsqlval($definition->getModifier()).',' .aka_prepsqlval($definition->getPronunciation()).',' .aka_prepsqlval($definition->getComment()).',' - .aka_prepsqlval($definition->getMedia()).',' .aka_prepsqlval($definition->isUnverified()).')'; $res = $this->database->insert($sql); @@ -252,7 +254,6 @@ public function saveDefinition($definition) { .'modifier = '.aka_prepsqlval($definition->getModifier()).',' .'pronunciation = '.aka_prepsqlval($definition->getPronunciation()).',' .'comment = '.aka_prepsqlval($definition->getComment()).',' - .'media = '.aka_prepsqlval($definition->getMedia()).',' .'unverified = '.aka_prepsqlval($definition->isUnverified()).' ' .'WHERE definition_id = '.$definition->getId(); diff --git a/inc/definition/Entry.php b/inc/definition/Entry.php index af8227c..ec6b5b9 100644 --- a/inc/definition/Entry.php +++ b/inc/definition/Entry.php @@ -19,11 +19,24 @@ * * Purpose: Entry class */ + +/** + * Media type flags + */ +class Media extends Enum { + const AUDIO = 0; + const IMAGE = 1; + + protected static $strings = array('audio', 'image'); + protected static $localized = array(KU_STR_AUDIO, KU_STR_IMAGE); +} /** * Dictionary entry class */ class Entry extends Entity { + private $media; + // Lazy loaded properties private $head; private $revisions; @@ -31,9 +44,11 @@ class Entry extends Entity { /** * Constructs an entry * @param int id the id + * @param int media the media flags */ - public function __construct($id = 0) { + public function __construct($id = 0, $media = 0) { $this->id = (int)$id; + $this->media = (int)$media; } /** @@ -42,7 +57,32 @@ public function __construct($id = 0) { * @return Entry the entry */ public static function fromRow(&$row) { - return new Entry($row['entry_id']); + return new Entry($row['entry_id'], $row['media']); + } + + /** + * Gets the media flags + * @return int the media flags + */ + public function getMedia() { + return $this->media; + } + + /** + * Sets the media flags + * @param int media the media flags + */ + public function setMedia($media) { + $this->media = $media; + } + + /** + * Gets if the media type exists for this entry + * @param int type the media type + * @return bool true if media type exists + */ + public function hasMedia($type) { + return aka_getbit($this->media, $type); } /** diff --git a/inc/definition/Meaning.php b/inc/definition/Meaning.php index b2778cc..603bf1f 100755 --- a/inc/definition/Meaning.php +++ b/inc/definition/Meaning.php @@ -75,8 +75,7 @@ public function getMeaning() { * @return bool TRUE if flag is set, else FALSE */ public function getFlag($flag) { - $mask = pow(2, $flag); - return $this->flags & $mask; + return aka_getbit($this->flags, $flag); } /** @@ -93,11 +92,7 @@ public function getFlags() { * @param bool state TRUE to set flag, else FALSE */ public function setFlag($flag, $state) { - $mask = pow(2, $flag); - if ($state) - $this->flags |= $mask; - else - $this->flags &= ~$mask; + $this->flags = aka_setbit($this->flags, $flag, $state); } /** diff --git a/inc/kumva.php b/inc/kumva.php index 8c84d91..964e3b1 100755 --- a/inc/kumva.php +++ b/inc/kumva.php @@ -48,6 +48,7 @@ // Get current absolute URL and login URL define('KUMVA_URL_CURRENT', 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); define('KUMVA_URL_LOGIN', KUMVA_URL_ROOT.'/admin/login.php'); +define('KUMVA_URL_MEDIA', KUMVA_URL_ROOT.'/media'); // Project URLs define('KUMVA_URL_PROJECT', 'https://github.com/ijuru/kumva'); diff --git a/inc/theme/Templates.php b/inc/theme/Templates.php index cbe55d3..9268a3f 100755 --- a/inc/theme/Templates.php +++ b/inc/theme/Templates.php @@ -54,20 +54,27 @@ public static function definitionLink($definition, $edit = FALSE) { } /** - * Displays a definition as full dictionary entry with examples etc + * Displays a definition as full dictionary entry with examples etc + * @param Entry entry the entry * @param Definition definition the definition */ - public static function entry($definition) { + public static function entry($entry, $definition) { // Display prefix+lemma self::definition($definition); // Display modifier if ($definition->getModifier()) - echo ' ('.$definition->getModifier().')'; + echo ' ('.$definition->getModifier().') '; // Display pronunciation if ($definition->getPronunciation()) - echo ' /'.$definition->getPronunciation().'/'; + echo ' /'.$definition->getPronunciation().'/ '; + + // Display sound widget + if ($entry->hasMedia(Media::AUDIO)) { + Widgets::sound($entry->getId()); + echo ' '; + } // Display word class $wordClass = $definition->getWordClass(); diff --git a/inc/theme/Widgets.php b/inc/theme/Widgets.php index 2aeb9ce..a32519e 100755 --- a/inc/theme/Widgets.php +++ b/inc/theme/Widgets.php @@ -212,10 +212,13 @@ public static function facebookLikeButton() { /** * Creates a small flash button to play the given sound file - * @param string sound the url of the sound file + * @param mixed sound the url of the sound file or id of an entry */ - public static function soundPlayButton($sound) { - echo 'X'; + public static function sound($sound) { + if (is_int($sound)) + $sound = KUMVA_URL_MEDIA.'/audio/'.$sound.'.mp3'; + + echo '>'; } /** diff --git a/index.php b/index.php index c61d418..175a7cc 100755 --- a/index.php +++ b/index.php @@ -52,7 +52,7 @@ getResults() as $def) { echo '
  • '; - Templates::entry($def); + Templates::entry($def->getEntry(), $def); echo '
  • '; } ?> diff --git a/lang/en/site.php b/lang/en/site.php index fbc9007..7789366 100644 --- a/lang/en/site.php +++ b/lang/en/site.php @@ -41,6 +41,7 @@ ku_sitetrans('KU_STR_ANSWERS', 'Answers'); ku_sitetrans('KU_STR_ANY', 'Any'); ku_sitetrans('KU_STR_APPROVE', 'Approve'); +ku_sitetrans('KU_STR_AUDIO', 'Audio'); ku_sitetrans('KU_STR_AUTO', 'Auto'); ku_sitetrans('KU_STR_BACK', 'Back'); ku_sitetrans('KU_STR_BASIC', 'Basic'); @@ -89,6 +90,7 @@ ku_sitetrans('KU_STR_HIDE', 'Hide'); ku_sitetrans('KU_STR_HISTORY', 'History'); ku_sitetrans('KU_STR_HOME', 'Home'); +ku_sitetrans('KU_STR_IMAGE', 'Image'); ku_sitetrans('KU_STR_IMPORT', 'Import'); ku_sitetrans('KU_STR_INSTALL', 'Install'); ku_sitetrans('KU_STR_INTERJECTION', 'Interjection'); @@ -105,6 +107,7 @@ ku_sitetrans('KU_STR_LOGOUT', 'Logout'); ku_sitetrans('KU_STR_MATCHBYDEFAULT', 'Match by default'); ku_sitetrans('KU_STR_MEANINGS', 'Meanings'); +ku_sitetrans('KU_STR_MEDIA', 'Media'); ku_sitetrans('KU_STR_MOBILESITE', 'Mobile site'); ku_sitetrans('KU_STR_MODE', 'Mode'); ku_sitetrans('KU_STR_MODIFIER', 'Modifier'); @@ -126,6 +129,7 @@ ku_sitetrans('KU_STR_PAGE', 'Page'); ku_sitetrans('KU_STR_PAGES', 'Pages'); ku_sitetrans('KU_STR_PASSWORD', 'Password'); +ku_sitetrans('KU_STR_PATH', 'Path'); ku_sitetrans('KU_STR_PENDING', 'Pending'); ku_sitetrans('KU_STR_PHPVERSION', 'PHP version'); ku_sitetrans('KU_STR_PHRASE', 'Phrase'); @@ -168,6 +172,7 @@ ku_sitetrans('KU_STR_ROOT', 'Root'); ku_sitetrans('KU_STR_RUDE', 'Rude'); ku_sitetrans('KU_STR_SAVE', 'Save'); +ku_sitetrans('KU_STR_SCAN', 'Scan'); ku_sitetrans('KU_STR_SEARCH', 'Search'); ku_sitetrans('KU_STR_SEARCHES', 'Searches'); ku_sitetrans('KU_STR_SEARCHHISTORY', 'Search history'); @@ -198,6 +203,7 @@ ku_sitetrans('KU_STR_TITLE', 'Title'); ku_sitetrans('KU_STR_TOTAL', 'Total'); ku_sitetrans('KU_STR_TOTALENTRIES', 'Total entries'); +ku_sitetrans('KU_STR_TYPE', 'Type'); ku_sitetrans('KU_STR_UNVERIFIED', 'Unverified'); ku_sitetrans('KU_STR_UNWATCH', 'Unwatch'); ku_sitetrans('KU_STR_USAGEEXAMPLES', 'Usage examples'); diff --git a/lang/rw/site.php b/lang/rw/site.php index d4e9fa0..0aa5668 100644 --- a/lang/rw/site.php +++ b/lang/rw/site.php @@ -41,6 +41,7 @@ ku_sitetrans('KU_STR_ANSWERS', 'Ibisubizo'); ku_sitetrans('KU_STR_ANY', 'Zose'); ku_sitetrans('KU_STR_APPROVE', 'Approve'); +ku_sitetrans('KU_STR_AUDIO', 'Audio'); ku_sitetrans('KU_STR_AUTO', 'Auto'); ku_sitetrans('KU_STR_BACK', 'Subira'); ku_sitetrans('KU_STR_BASIC', 'Basic'); @@ -89,6 +90,7 @@ ku_sitetrans('KU_STR_HIDE', 'Hide'); ku_sitetrans('KU_STR_HISTORY', 'Amateka'); ku_sitetrans('KU_STR_HOME', 'Urugo'); +ku_sitetrans('KU_STR_IMAGE', 'Image'); ku_sitetrans('KU_STR_IMPORT', 'Import'); ku_sitetrans('KU_STR_INSTALL', 'Install'); ku_sitetrans('KU_STR_INTERJECTION', 'Irangamutima'); @@ -105,6 +107,7 @@ ku_sitetrans('KU_STR_LOGOUT', 'Gufunga'); ku_sitetrans('KU_STR_MATCHBYDEFAULT', 'Match by default'); ku_sitetrans('KU_STR_MEANINGS', 'Ibisobanuro'); +ku_sitetrans('KU_STR_MEDIA', 'Media'); ku_sitetrans('KU_STR_MOBILESITE', 'Site ya telefone'); ku_sitetrans('KU_STR_MODE', 'Mode'); ku_sitetrans('KU_STR_MODIFIER', 'Modifier'); @@ -126,6 +129,7 @@ ku_sitetrans('KU_STR_PAGE', 'Ipaje'); ku_sitetrans('KU_STR_PAGES', 'Ipaje'); ku_sitetrans('KU_STR_PASSWORD', 'Password'); +ku_sitetrans('KU_STR_PATH', 'Path'); ku_sitetrans('KU_STR_PENDING', 'Pending'); ku_sitetrans('KU_STR_PHPVERSION', 'PHP version'); ku_sitetrans('KU_STR_PHRASE', 'Phrase'); @@ -168,6 +172,7 @@ ku_sitetrans('KU_STR_ROOT', 'Umuzi'); ku_sitetrans('KU_STR_RUDE', 'Rude'); ku_sitetrans('KU_STR_SAVE', 'Bika'); +ku_sitetrans('KU_STR_SCAN', 'Scan'); ku_sitetrans('KU_STR_SEARCH', 'Shakisha'); ku_sitetrans('KU_STR_SEARCHES', 'Searches'); ku_sitetrans('KU_STR_SEARCHHISTORY', 'Amateka yo gushakisha'); @@ -198,6 +203,7 @@ ku_sitetrans('KU_STR_TITLE', 'Title'); ku_sitetrans('KU_STR_TOTAL', 'Igiteranyo'); ku_sitetrans('KU_STR_TOTALENTRIES', 'Total entries'); +ku_sitetrans('KU_STR_TYPE', 'Type'); ku_sitetrans('KU_STR_UNVERIFIED', 'Unverified'); ku_sitetrans('KU_STR_UNWATCH', 'Unwatch'); ku_sitetrans('KU_STR_USAGEEXAMPLES', 'Ingero zo gukoresha'); diff --git a/lib/akabanga/utils.php b/lib/akabanga/utils.php index 38581cf..9c56e48 100755 --- a/lib/akabanga/utils.php +++ b/lib/akabanga/utils.php @@ -167,5 +167,30 @@ function aka_includejs($path) { global $AKABANGA_JSINCLUDES; $AKABANGA_JSINCLUDES[] = $path; } + +/** + * Gets the specified bit of a value + * @param int val the value + * @param int bit the bit number + * @return bool the bit state + */ +function aka_getbit($val, $bit) { + $mask = pow(2, $bit); + return (bool)($val & $mask); +} + +/** + * Sets the specified bit of a value to true or false + * @param int val the value to modify + * @param int bit the bit number + * @param bool state the bit state (defaults to TRUE) + */ +function aka_setbit($val, $bit, $state = true) { + $mask = pow(2, $bit); + if ($state) + return $val | $mask; + else + return $val & ~$mask; +} ?> diff --git a/themes/kinyarwanda/pages/pronunciation.php b/themes/kinyarwanda/pages/pronunciation.php index 41eb85e..a8a4d89 100644 --- a/themes/kinyarwanda/pages/pronunciation.php +++ b/themes/kinyarwanda/pages/pronunciation.php @@ -34,27 +34,27 @@ a broad as in 'far' - a-ma-ta + a-ma-ta e long like 'a' in 'hay' or short like 'e' in 'bet' - ay-joh + ay-joh i long like 'ee' in 'bee' or short like 'i' in 'bit' - ee-ji-tee + ee-ji-tee o long like 'o' in 'tone' or short like 'o' in 'lot' - a-ma-haw-ro + a-ma-haw-ro u like 'oo' in 'food' - oo-moon-hoo + oo-moon-hoo Consonants () @@ -67,37 +67,37 @@ b softer than in English with the lips barely touching - i-bi-ba-bi + i-bi-ba-bi c like 'ch' in 'church' - i-choo-pah + i-choo-pah j soft like 'z' in 'azure' - i-joo-roo + i-joo-roo l almost like 'r' - lay-tah + lay-tah r as in English but with slight trill sound - a-ma-ree-rah + a-ma-ree-rah y like 'y' in 'you' and never a vowel like 'sky' - ee-chee-yee-koh + ee-chee-yee-koh z like 'z' in 'zone' - ee-zoo-bah + ee-zoo-bah Consonant combinations () @@ -105,64 +105,64 @@ bw as 'bg' (even written 'bg' in some older books) - oob-go-bah + oob-go-bah jy hard 'j' like in 'jam' - koo-jah + koo-jah mp as 'mh' - eem-hang-gah + eem-hang-gah nn as if there was a slight 'i' between them - oo-boo-voo-n-in-yee + oo-boo-voo-n-in-yee nk as 'ngh' - eeng-ha + eeng-ha nt as 'nh' - oo-moon-hoo + oo-moon-hoo rw as if there were a 'g' between them - oor-gwan-dah + oor-gwan-dah ry as 'rdj' or 'dy' - oo-moord-jang-goh + oo-moord-jang-goh sw as if there was a slight 'k' between them - oo-moos-kwa + oo-moos-kwa tw as if there was a slight 'g' between them - oo-goot-gwi + oo-goot-gwi

    Word interactions

    Words in a Kinyarwanda sentence interact with each other to allow the words to flow into each other. The most common interaction occurs when a word begins with a vowel and causes the preceding word to drop its final vowel. In some cases this interaction is written explicitly, like in the case of (e.g. na umugabo should be written n'umugabo), but in other cases the final vowel is retained in the spelling even though it is not pronounced. For example:

    Regional variation