/** * * */ public function executeIndex($request) { list($year, $month) = phpToolkit::array_splice_values($request->getParameterHolder()->getAll(), array('year', 'month')); if (!$year) { $this->newsPosts = SitenewsPeer::getMostRecentPosts(); $this->title = 'News Archive <span>» Latest News</span>'; } else { if ($month >= 1 && $month <= 12) { $this->newsPosts = SitenewsPeer::getPostsByDate($year, $month); coreToolkit::loadHelpers('Date'); $this->selection = format_date(mktime(0, 0, 0, $month, 1, $year), "F Y"); $this->title = 'News for ' . $this->selection; } else { $this->forward404(); } } }
/** * Transform kanji in the input Japanese text into links to the Study area, * and add class for Javascript popup with the Heisig keywords. * * @param string $j_text Japanese text in utf-8 from validated post data. * @return string Japanese text as HTML code. */ protected function transformJapaneseText($j_text) { coreToolkit::loadHelpers('Tag'); $j_text = escape_once(trim($j_text)); // collect associative array of known kanji => kanji, framenum, keyword $kanjis = ReviewsPeer::getKnownKanji($this->getUser()->getUserId(), array('kanji', 'keyword')); $known = array(); foreach ($kanjis as $i => $kanjiData) { $known[$kanjiData['kanji']] = $kanjiData; } // wrap known kanji in text with links to Study area and hooks for javascript tooltip foreach ($known as $kanji => $info) { $url = '/study/?search=' . $info['framenum']; $rep = '<a href="' . $url . '" class="j" title="' . $info['keyword'] . '">' . $kanji . '</a>'; $j_text = str_replace($kanji, $rep, $j_text); } // assumes lines end with \r\n $j_text = preg_replace('/[\\r\\n]+/', '<br/>', $j_text); return $j_text; }
/** * Format data for the client-side javascript that builds a SVG chart. * */ protected function makeChartData($carddata) { $data = new stdClass(); $boxes = array(); for ($i = 0; $i < count($carddata); $i++) { $stacks = array(); // left stack $stacks[] = array('value' => $carddata[$i]['expired_cards'], 'type' => $i == 0 ? 'failed' : 'expired'); // right stack $stacks[] = array('value' => $carddata[$i]['fresh_cards'], 'type' => $i == 0 ? 'untested' : 'fresh'); $boxes[] = $stacks; } $data->boxes = $boxes; // links used in the chart coreToolkit::loadHelpers(array('Url')); $data->url_study = url_for('study/failedlist'); //.'?'.http_build_query(array()); $data->url_new = $this->getReviewUrl(array('type' => 'untested')); $data->url_review = $this->getReviewUrl(array('type' => 'expired')); return $data; }
/** * Load a custom helper file for use in the current template. * * The file should be in the /lib/helper/ directory and the filename is <helpername>Helper.php * * @param string One or multiple helpers to load. * @return */ function use_helper() { coreToolkit::loadHelpers(func_get_args()); }
/** * Render template file using PHP as the templating engine. * * @param string Filename * @return string A string representing the rendered presentation */ protected function renderFile($templateFile) { // load core and standard helpers $helpers = array_unique(array_merge(array('Core', 'Url', 'Asset', 'Tag'), coreConfig::get('standard_helpers'))); coreToolkit::loadHelpers($helpers); extract($this->parameterHolder->toArray(), EXTR_REFS); // template shortcuts $_context = coreContext::getInstance(); $_request = $_context->getRequest(); $_params = $_request->getParameterHolder(); $_user = $_context->getUser(); $_response = $_context->getResponse(); // render ob_start(); ob_implicit_flush(0); require $templateFile; return ob_get_clean(); }
/** * 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; }
/** * Return array of public stories for SharedStories component. * * Third parameter indicates which part of the shared stories selection to return: * - newest * - old (sorted by stars) * * @see study/SharedStoriesComponent * * @return array<array> */ public static function getPublicStories($framenum, $keyword, $bNewest) { coreToolkit::loadHelpers(array('Tag', 'Url', 'Links')); $select = self::getInstance()->select(array('stories.userid', 'username', 'stories.framenum', 'lastmodified' => 'DATE_FORMAT(updated_on,\'%e-%c-%Y\')', 'stories.text', 'stars', 'kicks'))->joinLeft('storiesscores', 'stories.framenum=storiesscores.framenum AND stories.userid=storiesscores.authorid')->join('users', 'users.userid=stories.userid')->where('stories.framenum=? AND public!=0', $framenum); if ($bNewest) { $select->where('updated_on >= DATE_ADD(CURDATE(),INTERVAL -1 MONTH)'); $select->order('updated_on DESC'); } else { $select->where('updated_on < DATE_ADD(CURDATE(),INTERVAL -1 MONTH)'); $select->order(array('stars DESC', 'updated_on DESC')); } //if (!$bNewest) { // echo $select;exit; //} $rows = self::$db->fetchAll($select); foreach ($rows as &$R) { // do not show 0's if (!$R['stars']) { $R['stars'] = ''; } if (!$R['kicks']) { $R['kicks'] = ''; } $R['text'] = StoriesPeer::getFormattedStory($R['text'], $keyword); $R['author'] = link_to_member($R['username']); } return $rows; }
/** * Returns the component rendered content. * * If the vars parameter is omitted, the action's internal variables * will be passed, just as it would to a normal template. * * If the vars parameter is set then only those values are * available in the component. * * @param string $moduleName module name * @param string $componentNae component name * @param array $vars vars * * @return string The component rendered content */ public function getComponent($moduleName, $componentName, $vars = null) { coreToolkit::loadHelpers('Partial'); $vars = !is_null($vars) ? $vars : $this->varHolder->getAll(); return get_component($moduleName, $componentName, $vars); }
/** * Returns flashcard data for the Kanji reviews. * This is a uiFlashcardReview callback, the data ($id) must be sanitized! * * @param * * @return mixed Object with flashcard data, or null */ public static function getFlashcardData($id) { $id = (int) $id; // note: zero is not a valid kanji id if ($id < 1 || $id > rtkBook::MAXKANJI_VOL3) { return null; } $cardData = self::getKanjiById($id); if (!$cardData) { return null; } // set properties for the flashcard $cardData->id = $cardData->framenum; coreToolkit::loadHelpers(array('Tag', 'Url', 'Links')); $cardData->keyword = link_to_keyword($cardData->keyword, $cardData->framenum, array('title' => 'Go to the Study page', 'target' => '_blank')); return $cardData; }
public function getConfig() { coreToolkit::loadHelpers(array('Date', 'CJK')); $this->_selection = uiSelectionState::getSelection(manageActions::REMOVE_FLASHCARDS); return <<<EOD { settings: { primaryKey: ['framenum'] }, columns: [ { caption: 'Index', width: 5, cssClass: 'center', colData: 'framenum' }, { caption: 'Kanji', width: 7, cssClass: 'kanji', colData: 'kanji', colDisplay: '_kanji' }, { caption: 'Keyword', width: 10, cssClass: 'keyword', colData: 'keyword'/*, colDisplay: '_keyword'*/ }, { caption: 'Pass', width: 1, cssClass: 'bold center', colData: 'successcount' }, { caption: 'Fail', width: 1, cssClass: 'center red', colData: 'failurecount', colDisplay: '_failurecount' }, { caption: 'Box', width: 8, cssClass: 'bold center', colData: 'leitnerbox' }, { caption: 'Last Review', width: 15, cssClass: 'center', colData: 'ts_lastreview', colDisplay: '_lastreview' }, { caption: '<input type="checkbox" name="chkAll" value="all" class="chkAll" />', width: 1, cssClass: 'center', colDisplay: '_checkbox' } ] } EOD; }
public function getConfig() { coreToolkit::loadHelpers(array('Date', 'CJK')); $this->_selection = uiSelectionState::getSelection(manageActions::REMOVE_FLASHCARDS); return <<<EOD \t\t{ \t\t\tsettings: { \t\t\t\tprimaryKey: ['framenum'] \t\t\t}, \t\t\tcolumns: [ \t\t\t\t{ \t\t\t\t\tcaption: \t'Index', \t\t\t\t\twidth: \t\t5, \t\t\t\t\tcssClass:\t'center', \t\t\t\t\tcolData:\t'framenum' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Kanji', \t\t\t\t\twidth: \t\t7, \t\t\t\t\tcssClass:\t'kanji', \t\t\t\t\tcolData:\t'kanji', \t\t\t\t\tcolDisplay:\t'_kanji' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Keyword', \t\t\t\t\twidth: \t\t10, \t\t\t\t\tcssClass:\t'keyword', \t\t\t\t\tcolData:\t'keyword'/*, \t\t\t\t\tcolDisplay:\t'_keyword'*/ \t\t\t\t}, \t\t\t\t \t\t\t\t{ \t\t\t\t\tcaption: \t'Pass', \t\t\t\t\twidth: \t\t1, \t\t\t\t\tcssClass:\t'bold center', \t\t\t\t\tcolData:\t'successcount' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Fail', \t\t\t\t\twidth: \t\t1, \t\t\t\t\tcssClass:\t'center red', \t\t\t\t\tcolData:\t'failurecount', \t\t\t\t\tcolDisplay: '_failurecount' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Box', \t\t\t\t\twidth: \t\t8, \t\t\t\t\tcssClass:\t'bold center', \t\t\t\t\tcolData:\t'leitnerbox' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Last Review', \t\t\t\t\twidth: \t\t15, \t\t\t\t\tcssClass:\t'center', \t\t\t\t\tcolData:\t'ts_lastreview', \t\t\t\t\tcolDisplay:\t'_lastreview' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'<input type="checkbox" name="chkAll" value="all" class="chkAll" />', \t\t\t\t\twidth: \t\t1, \t\t\t\t\tcssClass:\t'center', \t\t\t\t\tcolDisplay:\t'_checkbox' \t\t\t\t} \t\t\t] \t\t} EOD; }
/** * * * @param string $text Raw post text from database, with special markup * @param bool $brief Cut long post at the '<more>' mark and add a link to the full post * @param int $msg_id Id of the news post if $brief is True * @return string */ public static function formatPost($text, $brief = false, $msg_id = 0) { coreToolkit::loadHelpers(array('Tag', 'Url')); // brief mode if ($pos = strpos($text, '<more>')) { if ($brief) { $text = substr($text, 0, $pos); $text .= link_to('Continued...', 'news/detail?id=' . $msg_id, array('class' => 'readmore')); } else { $text = preg_replace('/(\\r\\n?)*<more>(\\r\\n?)*/', '<p>', $text); } } // replace linefeeds by XHTML <br /> $s = preg_replace('/(\\r\\n?)*(<\\/?\\w+>)(\\r\\n?)*/', '$2', $text); $s = preg_replace('/(\\r\\n?)+/', '<br /><br />', $s); return $s; }
public function getConfig() { coreToolkit::loadHelpers(array('CJK')); return <<<EOD \t\t{ \t\t\tsettings: { \t\t\t\tprimaryKey: ['userid', 'framenum'] \t\t\t}, \t\t\tcolumns: [ \t\t\t\t{ \t\t\t\t\tcaption: \t'Framenum', \t\t\t\t\twidth: \t\t5, \t\t\t\t\tcssClass:\t'center', \t\t\t\t\tcolData:\t'framenum' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Kanji', \t\t\t\t\twidth: \t\t7, \t\t\t\t\tcssClass:\t'kanji', \t\t\t\t\tcolData:\t'kanji', \t\t\t\t\tcolDisplay:\t'_kanji' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Keyword', \t\t\t\t\twidth: \t\t19, \t\t\t\t\tcssClass:\t'keyword', \t\t\t\t\tcolData:\t'keyword', \t\t\t\t\tcolDisplay:\t'_keyword' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'OnYomi', \t\t\t\t\twidth: \t\t15, \t\t\t\t\tcssClass:\t'nowrap', \t\t\t\t\tcolData:\t'onyomi' \t\t\t\t}, \t\t\t\t{ caption: 'StrokeCount', width: 15, cssClass: 'center', colData: 'strokecount' }, \t\t\t\t \t\t\t\t/* flashcard data */ \t\t\t\t{ \t\t\t\t\tcaption: \t'Pass', \t\t\t\t\twidth: \t\t8, \t\t\t\t\tcssClass:\t'bold center', \t\t\t\t\tcolData:\t'successcount' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Fail', \t\t\t\t\twidth: \t\t8, \t\t\t\t\tcssClass:\t'center red', \t\t\t\t\tcolData:\t'failurecount' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Box', \t\t\t\t\twidth: \t\t8, \t\t\t\t\tcssClass:\t'bold center', \t\t\t\t\tcolData:\t'leitnerbox' \t\t\t\t}, \t\t\t\t{ \t\t\t\t\tcaption: \t'Last Review', \t\t\t\t\twidth: \t\t15, \t\t\t\t\tcssClass:\t'center', \t\t\t\t\tcolData:\t'ts_lastreview', \t\t\t\t\tcolDisplay:'_lastreview' \t\t\t\t} \t\t\t] \t\t} EOD; }
public function getConfig() { coreToolkit::loadHelpers(array('CJK')); return <<<EOD { settings: { primaryKey: ['userid', 'framenum'] }, columns: [ { caption: 'Framenum', width: 5, cssClass: 'center', colData: 'framenum' }, { caption: 'Kanji', width: 7, cssClass: 'kanji', colData: 'kanji', colDisplay: '_kanji' }, { caption: 'Keyword', width: 19, cssClass: 'keyword', colData: 'keyword', colDisplay: '_keyword' }, { caption: 'OnYomi', width: 15, cssClass: 'nowrap', colData: 'onyomi' }, { caption: 'StrokeCount', width: 15, cssClass: 'center', colData: 'strokecount' }, /* flashcard data */ { caption: 'Pass', width: 8, cssClass: 'bold center', colData: 'successcount' }, { caption: 'Fail', width: 8, cssClass: 'center red', colData: 'failurecount' }, { caption: 'Box', width: 8, cssClass: 'bold center', colData: 'leitnerbox' }, { caption: 'Last Review', width: 15, cssClass: 'center', colData: 'ts_lastreview', colDisplay:'_lastreview' } ] } EOD; }
/** * 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; }