<?php include 'shmctrl.php'; $q = shm_access(); $cmd = array(); $cmd['done'] = 'exit'; shm_put($q, $cmd);
function getWaveFiles() { global $queue; $cmd = array(); foreach ($this->cards as $card) { if (!file_exists(SFC_WAVE_PATH . $card->question . '.wav')) { $cmd[$card->question] = 'get'; } } shm_put($queue, $cmd); }
define('MW_STORAGE_ROOT', str_replace('\\', '/', dirname(__FILE__)) . '/'); define('MW_STORAGE_WAVE', MW_STORAGE_ROOT . 'wave/'); define('MW_LOOKUP_URL', 'http://www.m-w.com/dictionary/'); define('MW_SOUNDS_URL', 'http://www.m-w.com/cgi-bin/audio.pl?'); #------------------------------------------------------------------------- # Init the interprocess communication queue #------------------------------------------------------------------------- $working = true; $queue = shm_create(); shm_put($queue, array()); #------------------------------------------------------------------------- # Starting #------------------------------------------------------------------------- while ($working) { $cmd = shm_get($queue); shm_put($queue, array()); foreach ($cmd as $data => $id) { switch ($id) { case 'exit': $working = false; break; case 'get': # By pass if the file already exists if (file_exists(MW_STORAGE_WAVE . $data . '.wav')) { break; } # Get the word meaning from Mirriam-Webster $contents = file_get_contents(MW_LOOKUP_URL . rawurlencode($data)); # Detect audio URL in the contents if (preg_match_all("|javascript:popWin\\('/cgi-bin/audio.pl\\?([^)]+)'\\)|is", $contents, $m)) { $group = array();
# Starting point #------------------------------------------------------------------------- if (defined('WORDTEST')) { $word = strtolower(WORDTEST); } else { $word = strtolower(stripslashes($_POST['word'])); $word = preg_replace("/'.*\$/", '', $word); } #------------------------------------------------------------------------- # If sound file doesn't exist, # request the mwget to download it if (!file_exists('wave/' . $word . '.wav')) { $queue = shm_access(); $cmd = shm_get($queue); $cmd[$word] = 'get'; shm_put($queue, $cmd); echo '0'; } else { echo '1'; } #------------------------------------------------------------------------- # Open database and start looking up #------------------------------------------------------------------------- if ($db = vdict_open('./ev.db')) { mb_internal_encoding('UTF-8'); if (!show($db, $word)) { # Try to be smart ;-) $exts = array('ing' => '|e', 'ies' => 'y', 'ied' => 'y', 'ily' => 'y', 'es' => '', 'ed' => '|e', 'ly' => '|le', 's' => ''); $found = false; foreach ($exts as $e => $re) { foreach (explode('|', $re) as $r) {