public static function print_processing_script($order) { echo html('p', __('Your Order is strill being processed. Please wait a few seconds...', 'colabsthemes')); echo html('p', sprintf(__('If your Order does not complete soon, please contact us and refer to your Order ID - #%d.', 'colabsthemes'), $order->get_id())); $page = $_SERVER['REQUEST_URI']; header("Refresh:5; url={$page}"); }
/** * Mark the field as editable * * @param string $content Filtered content * @param mixed $data Additional data like an object id etc. * * @return string Wrapped content */ public function wrap($content, $data) { if (!$this->allow($data)) { return $content; } $data = wp_parse_args($data, array('type' => $this->input_type)); if ('rich' == $data['type'] && !FEE_Core::$options->rich) { $data['type'] = 'textarea'; } self::$wrapped[$data['type']] = true; if (is_null($content)) { $content = ''; } if (!is_scalar($content)) { trigger_error("scalar expected. " . gettype($content) . " given", E_USER_WARNING); } $data = apply_filters('front_end_editor_wrap', $data, $this->filter); $data['filter'] = $this->filter; $data_attr = array(); foreach ($data as $key => $value) { if (!is_scalar($value)) { $value = json_encode($value); } $data_attr["data-{$key}"] = $value; } $data_attr['class'] = 'fee-field'; if ($this->was_placeholded) { $data_attr['title'] = FEE_Core::get_title($this->filter); } $wrap_tag = in_array($data['type'], array('textarea', 'rich', 'widget')) ? 'div' : 'span'; if ('div' == $wrap_tag) { $data_attr['class'] .= ' fee-clearfix'; } return html($wrap_tag, $data_attr, $content); }
function show() { $docs = _class('docs'); $dir = $docs->docs_dir; $dir_len = strlen($dir); $ext = '.stpl'; $ext_len = strlen($ext); $name = preg_replace('~[^a-z0-9/_-]+~ims', '', $_GET['id']); if (strlen($name)) { $dev_path = YF_PATH . '.dev/samples/classes/'; $dev_class_path = $dev_path . $name . '.class.php'; if (file_exists($dev_class_path)) { return _class($name, $dev_path)->show(); } $f = $dir . $name . '.stpl'; if (!file_exists($f)) { return _404('Not found'); } return '<section class="page-contents">' . tpl()->parse_string(file_get_contents($f), $replace, 'doc_' . $name) . '</section>'; } $url = rtrim(url('/@object/@action/')) . '/'; $data = []; foreach ((array) $this->_get_misc_docs($dir) as $name) { $data[$name] = ['name' => $name, 'link' => $url . urlencode($name)]; } ksort($data); return html()->li($data); }
/** * * @since 2.0.0 * * @return string */ public function render() { $introduction = html('div class="intro-text"', html('h2', __('Send Posts to Subscribers', 'Postmatic')), html('p', __('Posts are sent as soon as you hit publish.<br /> Comments can be sent with a simple reply.', 'Postmatic'))); $table_entries = array(array('title' => __('Author Subscriptions', 'Postmatic'), 'type' => 'checkbox', 'name' => 'auto_subscribe_authors', 'desc' => __('Subscribe authors to comments on their own posts.<small>(Recommended)</small>', 'Postmatic') . html('p', __('This will automatically subscribe post authors to new comment notifications on their posts. This works well to keep the author up to date with the latest comments and discussion.', 'Postmatic'))), array('title' => __('User Accounts', 'Postmatic'), 'type' => 'checkbox', 'name' => 'send_login_info', 'desc' => __('Email subscribers WordPress account credentials when they subscribe.', 'Postmatic') . html('p', __('Only necessary in some situations as all user commands are otherwise possible via email. If enabled we recommend using a good front end login plugin.', 'Postmatic'))), array('title' => __('Choose Posts to Deliver', 'Postmatic'), 'type' => 'checkbox', 'name' => 'no_post_email_default', 'desc' => __('Do not send new posts unless I choose to.', 'Postmatic') . html('p', __('Uncheck the "Do not deliver this post via email" checkbox before publishing to deliver a specific post.', 'Postmatic'))), array('title' => __('Default sending mode', 'Postmatic'), 'type' => 'checkbox', 'name' => 'excerpt_default', 'desc' => __('Send only the excerpt instead of the full post content.', 'Postmatic') . html('p', __('Enable this setting to only send excerpts with a button to read more online. You can override this on a per-post basis when drafting a new post. Note that the user will not be able to reply to the email to leave a comment because... well... who can comment on an excerpt?', 'Postmatic')))); $this->override_entries($table_entries); return $introduction . $this->form_table($table_entries); }
function document() { set("title", "Documents"); set("data", Document::getAll()); set("promos", Promo::getAll()); return html("list.html.php", "layout.html.php"); }
public function input() { $input = parent::input(); if (isset($this->data)) { $input->data('url', html(json_encode($this->data), false)); } else { if ($page = $this->page()) { foreach ($page->files() as $file) { if ($file->type() == 'image') { $media[$file->name()]['orientation'] = (string) $file->orientation(); $media[$file->name()]['thumbnail'] = (string) $file->url(); $media[$file->name()]['width'] = (string) $file->width(); $media[$file->name()]['height'] = (string) $file->height(); } if ($media[$file->name()]['type'] != 'video') { $media[$file->name()]['type'] = (string) $file->type(); } $media[$file->name()][$file->extension()] = (string) $file->url(); $media[$file->name()]['url'] = (string) $file->url(); $media[$file->name()]['name'] = (string) $file->name(); } $mediajson = html(json_encode($media)); $input->data(array('media' => $mediajson, 'field' => 'gallery')); } } //$input->tag('div'); //$input->removeAttr('type'); //$input->removeAttr('value'); return $input; }
public function indexAction() { // Display the send_us_a_file.html page if the "Send us a file" feature is on and the user is not logged in. if (fz_config_get('app', 'send_us_a_file_feature') && false == $this->getUser()) { set('start_from', Zend_Date::now()->get(Zend_Date::DATE_SHORT)); $maxUploadSize = min(Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('upload_max_filesize')), Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('post_max_size'))); set('max_upload_size', $maxUploadSize); return html('send_us_a_file.html'); } $this->secure(); $user = $this->getUser(); $freeSpaceLeft = max(0, Fz_Db::getTable('File')->getRemainingSpaceForUser($user)); $maxUploadSize = min(Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('upload_max_filesize')), Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('post_max_size')), $freeSpaceLeft); $progressMonitor = fz_config_get('app', 'progress_monitor'); $progressMonitor = new $progressMonitor(); set('upload_id', md5(uniqid(mt_rand(), true))); set('start_from', Zend_Date::now()->get(Zend_Date::DATE_SHORT)); set('refresh_rate', 1200); set('files', Fz_Db::getTable('File')->findByOwnerOrderByUploadDateDesc($user)); set('use_progress_bar', $progressMonitor->isInstalled()); set('upload_id_name', $progressMonitor->getUploadIdName()); set('free_space_left', $freeSpaceLeft); set('max_upload_size', $maxUploadSize); set('sharing_destinations', fz_config_get('app', 'sharing_destinations', array())); set('disk_usage', array('space' => '<b id="disk-usage-value">' . bytesToShorthand(Fz_Db::getTable('File')->getTotalDiskSpaceByUser($user)) . '</b>', 'quota' => fz_config_get('app', 'user_quota'))); return html('main/index.php'); }
/** * Render a modal * * @param \FrenchFrogs\Polliwog\Modal\Modal\Bootstrap $modal * @return string */ public function _modal(Modal\Bootstrap $modal) { $html = ''; // header if ($modal->hasCloseButton()) { $html .= html('button', ['type' => 'button', 'class' => 'close', 'data-dismiss' => 'modal', 'aria-label' => $modal->getCloseButtonLabel()], '<span aria-hidden="true">×</span>'); } if ($modal->hasTitle()) { $html .= html('h4', ['class' => static::MODAL_HEADER_TITLE_CLASS], $modal->getTitle()); } $html = html('div', ['class' => static::MODAL_HEADER_CLASS], $html); // body $html .= html('div', ['class' => static::MODAL_BODY_CLASS], $modal->getBody()); // footer if ($modal->hasActions()) { $actions = ''; if ($modal->hasCloseButton()) { $actions .= html('button', ['type' => 'button', 'class' => 'btn btn-default', 'data-dismiss' => 'modal'], $modal->getCloseButtonLabel()); } foreach ($modal->getActions() as $action) { /** @var Element\Button $action */ $actions .= html('button', $action->getAttributes(), $action->getLabel()); } $html .= html('div', ['class' => static::MODAL_FOOTER_CLASS], $actions); } // container if (!$modal->isOnlyContent()) { $html = html('div', ['class' => static::MODAL_CONTENT_CLASS, 'role' => 'document'], $html); $html = html('div', ['class' => static::MODAL_CLASS, 'role' => 'dialog'], $html); } return $html; }
public function mark_automatically($student_answer, &$log) { $this->msg->set_root('/auto-marking'); $log = array(); if (!$this->auto_marking_method) { throw new Exception($this->msg->_('cannot-mark-type-none')); } if (!is_string($student_answer)) { throw new Exception($this->msg->_('invalid-format')); } $clean_answer = Util::remove_useless_whitespaces($student_answer); $log[] = ['sa-running', []]; $log[] = ['sa-pattern', [html($this->raw_answer)]]; $log[] = ['sa-given-answer', [html($student_answer)]]; $log[] = ['sa-given-answer-clean', [html($clean_answer)]]; if (preg_match($this->answer, $student_answer) || preg_match($this->answer, $clean_answer)) { $log[] = ['sa-result-correct', []]; $mark = 1; } else { $log[] = ['sa-result-incorrect', []]; $mark = 0; } $log[] = ['mark', array('mark' => $mark)]; return $mark; }
/** */ public function show() { css(' #faq-search { padding-top: 20px; } #faq-items { padding-top: 20px; padding-bottom: 20px; } #faq-items li.li-header { list-style: none; display:none; } #faq-items li.li-level-0 { display: block; font-size: 15px; } #faq-items li.li-level-1 { padding-top: 10px; font-size: 13px; } span.highlight { background-color: #ff0; } '); asset('jquery-highlight'); jquery(' var url_hash = window.location.hash.replace("/", ""); if (url_hash) { $("li.li-level-0" + url_hash + " .li-level-1", "#faq-items").show(); } $(".li-level-0", "#faq-items").click(function(){ $(".li-level-1", this).toggle() }) $("input#search", "#faq-search").on("change keyup", function(){ var words = $(this).val(); $("#faq-items").unhighlight(); $("#faq-items").highlight(words); $(".li-level-1").hide().filter(":has(\'span.highlight\')").show(); }) '); $items = []; foreach ((array) db()->from(self::table)->where('active', 1)->where('locale', conf('language'))->get_all() as $a) { $items[$a['id']] = ['parent_id' => $a['parent_id'], 'name' => _truncate(trim($a['title']), 60, true, '...'), 'link' => url('/@object/#/faq' . $a['id']), 'id' => 'faq' . $a['id']]; if ($a['text']) { $items['1111' . $a['id']] = ['parent_id' => $a['id'], 'body' => trim($a['text'])]; } } return tpl()->parse_string($this->_tpl, ['items' => html()->li_tree($items)]); }
function show(&$smarty, $tmp, $setting, &$html, $lv = 0, &$limit) { if ($setting['shownode'] && $lv != 0) { if (is_object($smarty) && method_exists($smarty, 'gen_url')) { $url = $smarty->gen_url(array('app' => 'content', 'ctl' => 'site_article', 'act' => 'lists', 'arg0' => $tmp['info']['node_id'])); } $html .= html($lv, $url, $tmp['info']['node_name']); } if (!$setting['shownode']) { if ($limit <= 0) { return; } #$tmp['article'] = array_slice( $tmp['article'], 0, $setting['limit'] ); } if ($tmp['article']) { if ($setting['styleart']) { $tmp_lv = $setting['shownode'] ? $setting['lv'] + 1 : 2; } else { $tmp_lv = $lv + 1; } foreach ($tmp['article'] as $row) { if (is_object($smarty) && method_exists($smarty, 'gen_url')) { $url = $smarty->gen_url(array('app' => 'content', 'ctl' => 'site_article', 'act' => 'index', 'arg0' => $row['article_id'])); } $html .= html($tmp_lv, $url, $row['title']); $limit--; } } if ($tmp['child']) { foreach ($tmp['child'] as $row) { show($smarty, $row, $setting, $html, $lv + 1, $limit); } } }
function markdown2html($text) { $text = html($text); //bold text $text = preg_replace('/__(.+?)__/s', '<strong>$1</strong>', $text); $text = preg_replace('/\\*\\*(.+?)\\*\\*/s', '<strong>$1</strong>', $text); //italic text $text = preg_replace('/_([^_]+)_/', '<em>$1</em>', $text); $text = preg_replace('/\\*([^\\*]+)\\*/', '<em>$1</em>', $text); //преобразование стиля Windows (\r\n) в стиль Unix (\n) $text = preg_replace('/\\r\\n/', "\n", $text); //преобразуем стиль MacOS (\r) в Unix (\n) $text = preg_replace('/\\r/', "\n", $text); //Абзацы. Изначальный вид >>> $text = '<p>' . preg_replace('/\n\n/', '<p></p>', $text) . '</p>'; <<< но получается слишком большое расстояние, видимо из-за двойных <p> $text = preg_replace('/\\n\\n/', '<p></p>', $text); //разрывы строки $text = preg_replace('/\\n/', '<br>', $text); // [linked text](link URL) $text = preg_replace('/\\[([^\\]]+)]\\(([-a-z0-9._~:\\/?#@!$&\'()*+,;=%]+)\\)/i', '<a href="$2">$1</a>', $text); // // Преобразуем стиль Windows (\r\n) в Unix (\n). Иногда вместо preg_replace можно и нужно использовать str_replace // $text = str_replace("\r\n", "\n", $text); // // Преобразуем стиль Macintosh (\r) в Unix (\n). // $text = str_replace("\r", "\n", $text); // // Абзацы // $text = '<p>' . str_replace("\n\n", '</p><p>'# $text) . '</p>'; // // Разрывы строк // $text = str_replace("\n", 1<br>1, $text); return $text; }
protected function ready_content() { $content = ''; $content .= $this->send_login_warning_content(); $content .= html('input', array('name' => $this->import_type_name, 'type' => 'hidden', 'value' => $this->import_type)); return $this->form_wrap($content, array('value' => __('Import from Subscribe To Comments Reloaded', 'Postmatic'))); }
/** */ function show() { $deepness = 3; $ext = '.stpl'; $ext_len = strlen($ext); foreach ((array) $this->_dir_array as $gname => $glob) { foreach (range(1, $deepness) as $deep) { $glob_pattern = $glob . '*' . str_repeat('/*', $deep) . $ext; foreach (glob($glob_pattern) as $path) { $name = substr(implode('/', array_reverse(array_slice(array_reverse(explode('/', $path)), 0, $deep))), 0, -$ext_len); $names[$name][$path] = $path; $theme = implode(array_slice(array_reverse(explode('/', $path)), $deep, 1)); $found_in[$path] = $gname . ' | ' . $theme; } } } ksort($names); foreach ((array) $names as $name => $paths) { $links = []; foreach ($paths as $path) { $links[] = a('/file_manager/edit/' . urlencode($path), 'Edit ' . $path, 'fa fa-edit', $found_in[$path]); } $body['<b>' . $name . '</b>'] = implode(' ', $links); } return html()->simple_table($body, ['condensed' => 1]); }
public static function niceClass($tag = "test") { if (substr($tag, 0, 1) + 0 > 0) { $tag = "_number_" . $tag; } return html(str_replace(array(" ", "&"), array("_", "_-amp-_"), $tag)); }
protected function render() { $prop = $this->props; $this->beginContent(); $xi = $prop->expandIcon; if ($prop->menu instanceof NavigationLinkInterface) { $links = $prop->excludeRoot ? $prop->menu : [$prop->menu]; } else { $links = $prop->menu; } if (!$links) { return; } echo html(map($links, function ($link) use($xi) { /** @var NavigationLinkInterface $link */ if (!$link) { return ''; } if (is_array($link)) { $link = $link[0]; } // Exclude hidden links and menu separators. if (!$link->isActuallyVisible() || $link->isGroup() && $link->title() == '-') { return null; } $children = $link->getMenu(); $children->rewind(); $active = $link->isActive() ? '.active' : ''; $sub = $children->valid() ? '.sub' : ''; $current = $link->isSelected() ? '.current' : ''; $url = $link->isGroup() && !isset($link->defaultURI) ? null : $link->url(); $header = $link->isGroup() && $link->title() != '-' ? '.header' : ''; return [h("li{$active}{$sub}{$current}{$header}", [h("a{$active}", ['href' => $url], [when($link->icon(), h('i', ['class' => $link->icon()])), $link->title(), when(isset($xi) && $sub, h("span.{$xi}"))]), when($sub, $this->renderMenuItem($children, $xi, false))])]; })); }
public static function print_processing_script($order) { echo html('p', __('Your Order is strill being processed. Please wait a few seconds...', APP_TD)); echo html('p', sprintf(__('If your Order does not complete soon, please contact us and refer to your Order ID - #%d.', APP_TD), $order->get_id())); $page = $_SERVER['REQUEST_URI']; echo html('script', 'setTimeout( function(){ location.href="' . $page . '"; }, 5000 );'); }
function show() { $id = preg_replace('~[^a-z0-9_-]+~ims', '', $_GET['id']); if (strlen($id)) { if (substr($id, 0, strlen('table2_')) === 'table2_') { return _class($id, YF_PATH . '.dev/samples/table2/')->show(); } else { return _class('docs')->_show_for($this); } } $ext = '.class.php'; $ext_len = strlen($ext); $globs = ['yf_dev' => YF_PATH . '.dev/samples/table2/*' . $ext]; $names = []; foreach ($globs as $glob) { foreach (glob($glob) as $cls) { $cls = basename($cls); if ($cls == __CLASS__ || false === strpos($cls, __FUNCTION__)) { # continue; } $name = substr($cls, 0, -$ext_len); $names[$name] = $name; } } $links = []; foreach ($names as $name) { $data[$name] = ['name' => $name, 'link' => url('/@object/@action/' . $name)]; } return html()->li($data); }
function page_add_bookmark() { $form = new Zebra_Form('form'); $form->clientside_validation(array('close_tips' => true, 'on_ready' => false, 'disable_upload_validation' => true, 'scroll_to_error' => false, 'tips_position' => 'right', 'validate_on_the_fly' => true, 'validate_all' => true)); $form->add('label', 'label_url', 'url', 'URL'); $url = $form->add('text', 'url', 'http://'); $url->set_rule(array('required' => array('url_error', 'URL musí být vyplněno.'), 'url' => array(true, 'url_error', 'Pole musí obsahovat platné URL (včetně protokolu).'))); $form->add('label', 'label_title', 'title', 'Název stránky'); $title = $form->add('text', 'title', ''); $title->set_rule(array('required' => array('title_error', 'Název musí být vyplněn.'))); $form->add('submit', 'submitbtn', 'Přidat'); if ($form->validate()) { $ok = model_add($_POST['url'], $_POST['title'], array()); if ($ok) { flash('info', 'Záložka byla vytvořena'); } else { flash('error', 'Záložku se nepodařilo vytvořit.'); } redirect_to('/'); } // set('form', $form->render('views/add_form.php', true)); set('form', $form->render('', true)); set('title', 'Nová záložka'); return html('add.html.php'); }
public function login($welcome = null) { if ($user = panel()->site()->user()) { go(panel()->urls()->index()); } $message = l('login.error'); $error = false; $form = panel()->form('login'); $form->cancel = false; $form->save = l('login.button'); $form->centered = true; if (r::is('post') and get('_csfr') and csfr(get('_csfr'))) { $data = $form->serialize(); $user = site()->user(str::lower($data['username'])); if (!$user) { $error = true; } else { if (!$user->hasPanelAccess()) { $error = true; } else { if (!$user->login(get('password'))) { $error = true; } else { go(panel()->urls()->index()); } } } } if ($username = s::get('username')) { $form->fields->username->value = html($username, false); } return layout('login', array('meta' => new Snippet('meta'), 'welcome' => $welcome ? l('login.welcome') : '', 'form' => $form, 'error' => $error ? $message : false)); }
function wlist() { $lines = null; $args = func_get_args(); switch ($args[0]) { case 'scan': if ($elements = scan_dir($args[2]['path'], 'DIR')) { foreach ($elements as $value) { if (is_file($args[2]['path'] . $value . $args[2]['find'])) { $about = @parse_ini_file($args[2]['path'] . $value . '/protocol/about.gl.php'); $name = $about['product'] ? $about['product'] : $value; $lines[$name] = $args[3] ? href(THIS, $args[3], $value) : href($value); unset($about); } } } break; default: if (is_array($args[2])) { foreach ($args[2] as $link => $name) { $lines[$link] = href(THIS, $args[3], $name); } } break; } //Выводим массив ссылок ;) if ($lines) { foreach ($lines as $name => $link) { form("label", icon($args[1]) . '<a href="' . $link . '">' . $name . '</a>'); } } else { html('<br> Wlist lib. (C) Kazin Fedor, 2010'); } }
function show() { if ($_GET['id']) { return _class('docs')->_show_for($this); } $docs = _class('docs'); asset('font-awesome4'); foreach ($this->_get_assets() as $a) { $name = $a['name']; $sub = []; $sub[] = $docs->_github_link($a['path']); $content = $a['content']; $info = is_array($content) ? $content['info'] : []; if ($info['name']) { $sub[] = '<b>' . t('name') . '</b>: ' . $info['name']; } if ($info['desc']) { $sub[] = '<b>' . t('desc') . '</b>: ' . $info['desc']; } if ($info['url']) { $sub[] = '<b>' . t('url') . '</b>: <a href="' . _prepare_html($info['url']) . '">' . _prepare_html($info['url']) . '</a>'; } if ($info['git']) { $sub[] = '<b>' . t('git') . '</b>: <a href="' . $info['git'] . '">' . $info['git'] . '</a>'; } $data[$name] = ['name' => $name, 'link' => url('/@object/@action/#' . $name), 'sub' => $sub, 'id' => $name]; } return html()->li($data); }
function error($msg) { global $title, $header; html($title, $header, "<h2>Erro</h2>{$msg}"); disconnect(); exit(1); }
protected function send_login_warning_content() { if (!Prompt_Core::$options->get('send_login_info')) { return ''; } return html('p class="send-login-warning"', html('strong', __('Important:', 'Postmatic')), ' ', __('You have User Account notifications enabled in the Options tab, which means that each new subscriber imported will receive an email with their credentials. It is not necessary to send these credentials to Postmatic subscribers as all subscriber functions can be done directly via email. If you would like to disable these notifications please do so in the Options tab above.', 'Postmatic')); }
function ucd_list_shortcode() { ob_start(); get_data(); html(); return ob_get_clean(); }
private function wrap_upload($field_name, $desc) { $upload_button = html('input', array('class' => 'upload_button button', 'rel' => $field_name, 'type' => 'button', 'value' => __('Upload Image', APP_TD))); $clear_button = html('input', array('class' => 'delete_button button', 'rel' => $field_name, 'type' => 'button', 'value' => __('Clear Image', APP_TD))); $preview = html('div', array('id' => $field_name . '_image', 'class' => 'upload_image_preview'), html('img', array('src' => scbForms::get_value($field_name, $this->options->get())))); return $upload_button . ' ' . $clear_button . $desc . $preview; }
function form(Form\Form\Form $form) { $html = ''; $form->addAttribute('role', 'form'); $form->addClass('form-horizontal'); // Elements if ($form->hasCsrfToken()) { $html .= csrf_field(); } if ($form->hasLegend()) { $html .= html('h4', ['class' => Style::MODAL_HEADER_TITLE_CLASS], $form->getLegend()); } $html = html('div', ['class' => Style::MODAL_HEADER_CLASS], $html); $body = ''; foreach ($form->getElements() as $e) { /** @var $e \FrenchFrogs\Form\Element\Element */ $body .= $e->render(); } // body $html .= html('div', ['class' => Style::MODAL_BODY_CLASS . ' form-body'], $body); // Actions if ($form->hasActions()) { $actions = ''; foreach ($form->getActions() as $e) { $actions .= $e->render(); } $html .= html('div', ['class' => Style::MODAL_FOOTER_CLASS], $actions); } if ($form->isRemote()) { $form->addClass('form-remote'); } $html = html('form', $form->getAttributes(), $html); return $html; }
public function mark_automatically($student_answer, &$log) { $this->msg->set_root('/auto-marking'); $log = array(); if (!$this->auto_marking_method) { throw new Exception($this->msg->_('cannot-mark-type-none')); } if (!is_array($student_answer) || count($student_answer) != $this->n_answers) { throw new Exception($this->msg->_('invalid-format')); } $log[] = ['ft-running', []]; $correct = 0; for ($i = 0; $i < $this->n_answers; $i++) { $log[] = ['ft-nth-field', [$i + 1]]; $raw_answer = $student_answer[$i]; $clean_answer = Util::remove_useless_whitespaces($raw_answer); $log[] = ['ft-pattern', [html($this->raw_answers[$i])]]; $log[] = ['ft-given-answer', [html($raw_answer)]]; $log[] = ['ft-given-answer-clean', [html($clean_answer)]]; if (preg_match($this->answers[$i], $raw_answer) || preg_match($this->answers[$i], $clean_answer)) { $log[] = ['ft-result-correct', []]; $correct++; } else { $log[] = ['ft-result-incorrect', []]; } } if ($this->auto_marking_method == 'binary') { $mark = (int) ($correct == $this->n_answers); $log[] = ['mark', array('mark' => $mark)]; } else { $mark = (double) $correct / $this->n_answers; $log[] = ['mark-with-fraction', array('numerator' => $correct, 'denominator' => $this->n_answers, 'mark' => $mark)]; } return $mark; }
function books_new() { $book_data = book_data_from_form(); set('book', make_book_obj($book_data)); set('authors', find_authors()); return html('books/new.html.php'); }
function authorize() { global $api; $story_app = NULL; // Successful authorization. Store the access token in the session if (!isset($_GET['error'])) { try { $api->authenticate('authorization_code', array('code' => $_GET['code'], 'redirect_uri' => option('OAUTH_REDIRECT_URI'))); $_SESSION['access_token'] = $api->oauth->access_token; $_SESSION['refresh_token'] = $api->oauth->refresh_token; $story_app = $api->app->get(STORY_APP_ID); } catch (PodioError $e) { die("There was an error. The API responded with the error type <b>{$e->body['error']}</b> and the message <b>{$e->body['error_description']}</b><br><a href='" . url_for('/') . "'>Go back</a>"); } } if ($story_app) { $_SESSION['story_app'] = $story_app; $_SESSION['space'] = $api->space->get($_SESSION['story_app']['space_id']); redirect_to(''); } else { // Something went wrong. Display appropriate error message. unset($_SESSION['access_token']); unset($_SESSION['refresh_token']); $error_description = !empty($_GET['error_description']) ? htmlentities($_GET['error_description']) : 'You do not have access to the ScrumIO apps. Try logging in as a different user.'; return html('login.html.php', NULL, array('oauth_url' => option('OAUTH_URL'), 'error_description' => $error_description)); } }