public static function segment($options = []) { $value = $options['value'] ?? ''; // todo: proper type handling with global border $type = $options['type'] ?? ''; $header = $options['header'] ?? []; $footer = $options['footer'] ?? []; array_key_unset($options, ['value', 'type', 'header', 'footer']); // single segment if we do not have header nor footer if ($header == null && $footer == null) { $options['class'] = array_add_token($options['class'] ?? [], ['ui', 'segment', $type], ' '); return '<div ' . self::generate_attributes($options) . '>' . $value . '</div>'; } else { $options['class'] = array_add_token($options['class'] ?? [], ['ui', 'segments', $type], ' '); $result = '<div ' . self::generate_attributes($options) . '>'; if ($header != null) { if (!empty($type)) { $type .= ' message'; } $result .= '<div class="ui segment ' . $type . '">' . $header . '</div>'; } $result .= '<div class="ui segment">' . $value . '</div>'; if ($footer != null) { $result .= '<div class="ui segment secondary">' . $footer . '</div>'; } $result .= '</div>'; return $result; } }
/** * see tinyurl::set(); */ public static function set($url, $options = []) { // insert new row into the table $object = new numbers_backend_misc_tinyurl_db_model_tinyurls(); $result = $object->insert(['sm_tinyurl_inserted' => format::now('datetime'), 'sm_tinyurl_url' => $url . '', 'sm_tinyurl_expires' => $options['expires'] ?? null]); if ($result['success']) { $result['data']['id'] = $result['last_insert_id']; $result['data']['hash'] = base_convert($result['last_insert_id'] . '', 10, 36); } else { $result['data'] = []; } array_key_unset($result, ['success', 'error', 'data'], ['preserve' => true]); return $result; }
/** * Captcha * * @param array $options * @return string */ public static function captcha($options = []) { $captcha_link = $options['id'] ?? 'default'; // validation if (!empty($options['validate'])) { return self::validate($captcha_link, $options['password']); } // generating password $password = self::generate_password($captcha_link, $options['password_letters'] ?? null, $options['password_length'] ?? 5); array_key_unset($options, ['password_letters', 'password_length']); $image_options = ['src' => 'data:image/png;base64,' . base64_encode(self::draw($password, ['return_image' => true])), 'style' => $options['img_style'] ?? 'vertical-align: middle;']; if (!empty($options['only_image'])) { return html::img($image_options); } else { return '<table width="100%"><tr><td>' . html::input($options) . '</td><td width="1%"> </td><td width="1%">' . html::img($image_options) . '</td></tr></table>'; } }
/** * @see html::menu() */ public static function menu($options = []) { $items = $options['options'] ?? []; $items_right = $options['options_right'] ?? []; $brand = $options['brand'] ?? null; array_key_unset($options, ['options', 'brand']); $result = '<div class="navbar navbar-default" role="navigation">'; $result .= '<div class="container">'; $result .= '<div class="navbar-header">'; $result .= '<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">'; $result .= '<span class="sr-only">Toggle navigation</span>'; $result .= '<span class="icon-bar"></span>'; $result .= '<span class="icon-bar"></span>'; $result .= '<span class="icon-bar"></span>'; $result .= '</button>'; $result .= '<a class="navbar-brand" href="/">' . $brand . '</a>'; $result .= '</div>'; $result .= '<div class="collapse navbar-collapse navbar-nav-fix">'; $result .= '<ul class="nav navbar-nav">'; $index = 1; foreach ($items as $k => $v) { $result .= '<li class="navbar-nav-li-level1" search-id="' . $index . '">'; // if we have options if (!empty($v['options'])) { $result .= self::menu_submenu($v, 0); } else { // create name $name = i18n(null, $v['name']); if (!empty($v['icon'])) { $name = html::icon(['type' => $v['icon']]) . ' ' . $name; } if (!empty($v['url'])) { $result .= html::a(['href' => $v['url'], 'value' => $name]); } else { $result .= $name; } } $result .= '</li>'; $items[$k]['index'] = $index; $index++; } // and we need to add all tabs again into others tab $result .= '<li search-id="0" class="navbar-nav-others">'; $result .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">More <b class="caret"></b></a>'; $result .= '<ul class="dropdown-menu navbar-nav-others-ul">'; //multi-level foreach ($items as $k => $v) { $class = !empty($v['options']) ? ' dropdown-submenu' : ''; $result .= '<li class="navbar-nav-li-level1-others' . $class . '" search-id="' . $v['index'] . '">'; // if we have options if (!empty($v['options'])) { $result .= self::menu_submenu($v, 1); } else { // create name $name = i18n(null, $v['name']); if (!empty($v['icon'])) { $name = html::icon(['type' => $v['icon']]) . ' ' . $name; } if (!empty($v['url'])) { $result .= html::a(['href' => $v['url'], 'value' => $name]); } else { $result .= $name; } } $result .= '</li>'; } $result .= '</ul>'; $result .= '</li>'; $result .= '</ul>'; // right menu if (!empty($items_right)) { $result .= '<ul class="nav navbar-nav navbar-right">'; foreach ($items_right as $k => $v) { $result .= '<li class="navbar-nav-li-level1">'; // if we have options if (!empty($v['options'])) { $result .= self::menu_submenu($v, 0); } else { // create name $name = i18n(null, $v['name']); if (!empty($v['name_extension'])) { $name .= '<br/>' . $v['name_extension']; } if (!empty($v['icon'])) { $name = html::icon(['type' => $v['icon']]) . ' ' . $name; } if (!empty($v['url'])) { $result .= html::a(['href' => $v['url'], 'value' => $name]); } else { $result .= $name; } } $result .= '</li>'; } $result .= '</ul>'; } $result .= '</div>'; $result .= '</div>'; $result .= '</div>'; return $result; }
/** * @see html::icon() */ public static function icon($options = []) { // if we are rendering image if (isset($options['file'])) { $name = $options['file']; if (isset($options['path'])) { $path = $options['path']; } $options['src'] = $path . $name; if (!isset($options['style'])) { $options['style'] = 'vertical-align: middle;'; } array_key_unset($options, ['file', 'path']); // we need to get width and height of the image from the end of filename if (preg_match('/([0-9]+)(x([0-9]+))?./', $name, $matches)) { if (isset($matches[1])) { $options['width'] = $matches[1]; } if (isset($matches[3])) { $options['height'] = $matches[1]; } } return html::img($options); } else { if (isset($options['type'])) { $options['class'] = array_add_token($options['class'] ?? [], 'icon ' . $options['type'], ' '); $options['tag'] = $options['tag'] ?? 'i'; return html::tag($options); } } }