Skip to content

Commit

Permalink
Added media files for entries
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jun 4, 2011
1 parent ce41ecb commit 926a872
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 71 deletions.
1 change: 1 addition & 0 deletions admin/tpl/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
))
Expand Down
23 changes: 2 additions & 21 deletions inc/definition/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Definition extends Entity {
private $modifier;
private $pronunciation;
private $comment;
private $media;
private $unverified;

// Lazy loaded properties
Expand All @@ -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;
Expand All @@ -98,7 +96,6 @@ public function __construct(
$this->modifier = $modifier;
$this->pronunciation = $pronunciation;
$this->comment = $comment;
$this->media = (int)$media;
$this->unverified = (bool)$unverified;
}

Expand All @@ -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']);
}

/**
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions inc/definition/DefinitionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,22 @@ 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)
return FALSE;
$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;
}
Expand All @@ -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);
Expand All @@ -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();

Expand Down
44 changes: 42 additions & 2 deletions inc/definition/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,36 @@
*
* 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;

/**
* 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;
}

/**
Expand All @@ -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);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions inc/definition/Meaning.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions inc/kumva.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
15 changes: 11 additions & 4 deletions inc/theme/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' (<span class="modifier">'.$definition->getModifier().'</span>)';
echo ' (<span class="modifier">'.$definition->getModifier().'</span>) ';

// Display pronunciation
if ($definition->getPronunciation())
echo ' /<span class="pronunciation">'.$definition->getPronunciation().'</span>/';
echo ' /<span class="pronunciation">'.$definition->getPronunciation().'</span>/ ';

// Display sound widget
if ($entry->hasMedia(Media::AUDIO)) {
Widgets::sound($entry->getId());
echo '&nbsp;';
}

// Display word class
$wordClass = $definition->getWordClass();
Expand Down
9 changes: 6 additions & 3 deletions inc/theme/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<a href="'.$sound.'" class="sm2_button">X</a>';
public static function sound($sound) {
if (is_int($sound))
$sound = KUMVA_URL_MEDIA.'/audio/'.$sound.'.mp3';

echo '<a href="'.$sound.'" class="sm2_button">&gt;</a>';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<?php
foreach ($search->getResults() as $def) {
echo '<li class="definition">';
Templates::entry($def);
Templates::entry($def->getEntry(), $def);
echo '</li>';
}
?>
Expand Down
6 changes: 6 additions & 0 deletions lang/en/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
6 changes: 6 additions & 0 deletions lang/rw/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
Loading

0 comments on commit 926a872

Please sign in to comment.