/** * Set array of flashcard ids, from a selection expressed as a string. * * Accepts: * Single cards 3 * Range of cards 4-25 * Kanji <single utf8 char> * * Delimiters: * All flashcard ids (numerical or kanji) must be separated by commas, * or spaces, or tabs. A range of cards can not have spaces around the dash. * Kanji characters do not need to be separated between them but must be separated * from the numerical indices eg: * * 3, 42 15, 10-13 一年生 * * @param string $selString Selection in string format * * @return int Number of cards in selection */ public function setFromString($selString) { $this->itemIds = array(); // split string on spaces, japanese space (0x3000) and comma $selparts = preg_split('/[,\\s\\x{3000}]+/u', $selString, -1, PREG_SPLIT_NO_EMPTY); if (!count($selparts)) { return false; } foreach ($selparts as &$part) { // numerical range if (preg_match('/^([0-9]+)-([0-9]+)$/', $part, $matches)) { $from = $matches[1]; $to = $matches[2]; if (!rtkBook::isValidRtkFrameNum($from) || !rtkBook::isValidRtkFrameNum($to)) { $this->request->setError('if', sprintf('Invalid framenumber: "%s"', $part)); return false; } elseif ($from > $to) { $this->request->setError('ir', sprintf('Invalid range: "%s"', $part)); return false; } for ($i = $from; $i <= $to; $i++) { $this->itemIds[] = $i; } } elseif (ctype_digit($part)) { $framenum = intval($part); if (!rtkBook::isValidRtkFrameNum($framenum)) { $this->request->setError('if', sprintf('Invalid framenumber: "%s"', $part)); return false; } $this->itemIds[] = $framenum; } elseif (CJK::hasKanji($part)) { $cjkChars = CJK::getKanji($part); if (!count($cjkChars)) { continue; } foreach ($cjkChars as $cjk) { $framenum = rtkBook::getIndexForKanji($cjk); if ($framenum) { $this->itemIds[] = $framenum; } else { $this->request->setError('if', sprintf('Cannot add non-Heisig character: "%s"', $part)); return false; } } } else { $this->request->setError('ip', sprintf('Invalid part: "%s"', $part)); return false; } } // remove duplicates $this->itemIds = array_unique($this->itemIds); return $this->getNumCards(); }
/** * Takes a string of Japanese text and returns the kanji with links to * the Study page, and the title attribute contains the RTK keyword. * * @param string $compound * * @return string Html markup */ public static function getKeywordizedCompound($compound) { $chars = CJK::splitU($compound); //DBG::out(print_r($chars, true)); $s = ''; coreToolkit::loadHelpers(array('Tag', 'Url')); foreach ($chars as $c) { if (false !== ($framenum = rtkBook::getIndexForKanji($c))) { $keyword = KanjisPeer::getKeyword($framenum); // FIXME - internal uri should be '@study_edit?id=' once it goes to production site.. $url = link_to($c, 'http://kanji.koohii.com/study/kanji/' . $c, array('title' => $keyword)); $s = $s . $url; } else { $s = $s . $c; } } //DBG::out($s);exit; return $s; }
/** * Takes a string of Japanese text and returns the kanji with links to * the Study page, and the title attribute contains the RTK keyword. * * @param string $compound * * @return string Html markup */ public static function getKeywordizedCompound($compound) { $chars = CJK::splitU($compound); //DBG::out(print_r($chars, true)); $s = ''; coreToolkit::loadHelpers(array('Tag', 'Url')); foreach ($chars as $c) { if (false !== ($framenum = rtkBook::getIndexForKanji($c))) { $keyword = KanjisPeer::getKeyword($framenum); $url = link_to($c, '@study_edit?id=' . $c, array('title' => $keyword)); $s = $s . $url; } else { $s = $s . $c; } } //DBG::out($s);exit; return $s; }