*
* @param mysqli $db
*/
- public function __construct($db) {
+ public function __construct(mysqli $db) {
$this->_DB = $db;
}
* @param string $data
* @return mixed
*/
- public function create($data) {
+ public function create(string $data): bool {
$ret = false;
$_words = implode(' ', $this->_words($data));
* @param string $m Month m
* @param string $d Day d
* @param string $id Id of the entry
- * @return array|null
+ * @return array
*/
- public function load($y, $m, $d, $id) {
+ public function load(string $y, string $m, string $d, string $id): array {
$ret = array();
if(!empty($id) && !empty($y) && !empty($m) && !empty($d)) {
*
* @param array $data
* @param string $id
- * @return mixed
+ * @return int
*/
- public function update($data,$id) {
- $ret = false;
+ public function update(array $data, string $id) {
+ $ret = 0;
if(!empty($data) && !empty($id)) {
$_words = implode(' ', $this->_words($data));
/**
* Create unique words from the given data
*
+ * @param $data string
+ * @return array
* @todo ignores
*
- * @param $data
- * @return array
*/
- private function _words($data) {
+ private function _words(string $data): array {
preg_match_all('/\w{3,}+/',$data,$matches);
return array_unique($matches[0]);
}
* A static helper class
*/
class Summoner {
- /**
- * validate the given string with the given type. Optional check the string
- * length
- *
- * @param string $input The string to check
- * @param string $mode How the string should be checked
- * @param mixed $limit If int given the string is checked for length
- *
- * @return bool
- *
- * @see http://de.php.net/manual/en/regexp.reference.unicode.php
- * http://www.sql-und-xml.de/unicode-database/#pc
- *
- * the pattern replaces all that is allowed. the correct result after
- * the replace should be empty, otherwise are there chars which are not
- * allowed
- */
- static function validate($input,$mode='text',$limit=false) {
+ /**
+ * validate the given string with the given type. Optional check the string
+ * length
+ *
+ * @param string $input The string to check
+ * @param string $mode How the string should be checked
+ * @param mixed $limit If int given the string is checked for length
+ *
+ * @return bool
+ *
+ * @see http://de.php.net/manual/en/regexp.reference.unicode.php
+ * http://www.sql-und-xml.de/unicode-database/#pc
+ *
+ * the pattern replaces all that is allowed. the correct result after
+ * the replace should be empty, otherwise are there chars which are not
+ * allowed
+ */
+ static function validate(string $input, $mode='text', $limit=false): bool {
// check if we have input
$input = trim($input);
return $ret;
}
- /**
- * check if a string starts with a given string
- *
- * @param string $haystack
- * @param string $needle
- * @return boolean
- */
- static function startsWith($haystack, $needle) {
+ /**
+ * check if a string starts with a given string
+ *
+ * @param string $haystack
+ * @param string $needle
+ * @return boolean
+ */
+ static function startsWith(string $haystack, string $needle): bool {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
- /**
- * check if a string ends with a given string
- *
- * @param string $haystack
- * @param string $needle
- * @return boolean
- */
- static function endsWith($haystack, $needle) {
+ /**
+ * check if a string ends with a given string
+ *
+ * @param string $haystack
+ * @param string $needle
+ * @return boolean
+ */
+ static function endsWith(string $haystack, string $needle): bool {
$length = strlen($needle);
if ($length == 0) {
return true;
* @param int $id
* @return string
*/
- static function b64sl_pack_id($id) {
+ static function b64sl_pack_id(int $id): string {
error_log($id);
$id = intval($id);
$ida = ($id > 0xFFFFFFFF ? $id >> 32 : 0); // 32 bit big endian, top
return $id;
}
- /**
- * Decode a base64-encoded big-endian integer of up to 64 bits.
- *
- * @see https://www.jwz.org/base64-shortlinks/
- * @param int $id
- * @return false|int|string|string[]
- */
- static function b64sl_unpack_id($id) {
+ /**
+ * Decode a base64-encoded big-endian integer of up to 64 bits.
+ *
+ * @see https://www.jwz.org/base64-shortlinks/
+ * @param int $id
+ * @return false|int|string|string[]
+ */
+ static function b64sl_unpack_id(int $id) {
$id = str_replace ('-', '+', $id); // decode URL-unsafe "+" "/"
$id = str_replace ('_', '/', $id);
$id = base64_decode ($id);
*
* http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
*
- * @param $array
- * @param $key
+ * @param $array array
+ * @param $key string
* @return bool|mixed
*/
- static function ifset($array,$key) {
+ static function ifset(array $array, string $key): bool {
return isset($array[$key]) ? $array[$key] : false;
}
<?php
+/**
+ * scientia
+ *
+ * Copyright 2021 Johannes Keßler
+ *
+ * https://www.bananas-playground.net/projekt/scientia/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
require_once 'lib/entry.class.php';
$Entry = new Entry($DB);
<?php
+/**
+ * scientia
+ *
+ * Copyright 2021 Johannes Keßler
+ *
+ * https://www.bananas-playground.net/projekt/scientia/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
$TemplateData['entries'] = array();
$queryStr = "SELECT `e`.`ident`, `e`.`date`, SUBSTRING(`e`.`body`,1,100) AS body FROM `".DB_PREFIX."_entry` AS e";