The PHP framework behind SitioYa

Koshkil documentation

Services

Utilities

The utilities live in core/tools/ and core/network/. Most are classes with static methods, included with Koshkil::Uses().

Koshkil::Uses('sys.tools.utils.stringUtils');
echo stringUtils::makeURL('Winter Sale 2026');   // winter-sale-2026

Strings: stringUtils

Method Purpose
makeURL($text) URL-friendly text (slug).
makeExcerpt($text, $length = 200, $end = '...') Excerpt without breaking words.
makePlainText($text) / removeTags($html) / strip_tags_attributes($html) HTML clean-up.
makeClickableLinks($text) Turns URLs into links.
safeName($name, $path = null) Safe, unique file name.
isEmail($text) Validates an email address.
countWords($text), stringOccurrence($needle, $haystack) Counting.
getMonthName($month, $short = true) Month name in Spanish.
padString($text, $pad, $times, $side = 'left') Padding.
number_unformat($number, $decimals, $thousands, $decimal) Turns "1.234,50" into a number.
replace_all($search, $replacement, $text) Repeats the replacement until there are no matches left.

Dates: datesUtils

Koshkil::Uses('sys.tools.utils.datesUtils');

datesUtils::formatDateTime('22/09/2026', 'dd/mm/yy', 'yyyy-mm-dd');  // '2026-09-22'
datesUtils::elapsed('2026-09-22 10:00:00');                           // elapsed time, in Spanish
datesUtils::timeLeft('2026-12-31 23:59:59');

$date = new datesUtils('22/09/2026 10:00:00');
$date = $date->addDays(7)->addHours(2);   // each operation returns a new date
echo $date->format('Y-m-d H:i:s');
$date->dayOfWeek(); $date->month(); $date->year();

Files: fileUtils

Method Purpose
mkdir($folder) / createDirectory($path) Creates folders (recursively).
deleteFiles($folder, '*.cache') / removeFolder($path) Deleting.
getTempDir() The project's temporary folder.
processSingleUpload($field, $record, $group, $type, $usage) Stores an upload in the gallery, attached to a record.
processMultipleUpload($field, $record, $group) Several uploads.
uploadedFileIsValid($field, $requirements) Validates type and size.
getFileIcon($file, $fontawesome = false) Icon for the file extension.
rotateFile($file, $maxHistory) Rotation (used by the logs).

Images: imagesUtils

Koshkil::Uses('sys.tools.utils.imagesUtils');

imagesUtils::resizePicture($source, $target, 1200, 800);   // keeps the aspect ratio
imagesUtils::loadAndLimitDiskSize($path, 300 * 1024);       // recompresses to about 300 KB
imagesUtils::getRemoteImage($url, $localFile, 800, 600);

Other utilities

Class Main methods
arrayUtils deepMerge($a, $b), sanitizeStrings($array), buildQueryForCurl($array)
numberUtils stringToNumber('1M') → 1048576, numberToString($n, $factor)
encodingUtils UTF-8 / ISO-8859-1 conversion (utf8_encode, utf8_decode)
htmlUtils parseTag($html), getTagParameters($attributes)
passwordUtils createHash($password, $storedHash = null)
totpUtils One-time codes (TOTP) for a second factor: secretKey(), verifyKey()
Inflector camelize(), deCamelize(), pluralize(), singularize()
Sanitize mask($data, $options) masks passwords and card numbers (used by the logs)
TCollection Iterable collection (see Models)

Email

emailUtils wraps PHPMailer and takes the SMTP settings from config/email.php:

<?php
$CONFIG = [
    'Email' => [
        'Smtp' => ['host' => 'smtp.mysite.com', 'port' => 587, 'secure' => true, 'username' => '…', 'password' => '…'],
        'Options' => [
            'Sender' => ['name' => 'My site', 'address' => 'no-reply@mysite.com'],
            'useRealAddress' => true,   // false: everything goes to sendTo (useful in development)
            'sendTo' => ['name' => 'Testing', 'address' => 'testing@mysite.com'],
        ],
    ],
];
Koshkil::Uses('sys.tools.utils.emailUtils');

$mail = new emailUtils();
$mail->sendTextMailByAddress('customer@mail.com', 'Your order', '<p>Thanks for your purchase!</p>');
$mail->sendTextMailByAddresses(['a@mail.com', 'b@mail.com'], 'Notice', $html, [$attachmentPath]);

The sendMailByAddress(), sendMailByUser() and sendMailByRules() methods use templates stored in the database (email_template model: tmp_nombre, tmp_titulo, tmp_contenido) and replace [variable] with the values given to setVariable(). sendMailByRules('noticias') writes to every user who has that rule.

Network

Koshkil::Uses('sys.network.clients.curl');

$http = new curl('https://api.example.com/v1/prices');
$http->setOptions([CURLOPT_TIMEOUT => 10]);
$json = $http->post(['product' => 15], ['Accept: application/json']);
Koshkil::Uses('sys.network.clients.ftp');

$ftp = new FTPClient('ftp.mysite.com', 'user', 'password', '/public_html');
$ftp->connect();
$ftp->login();
$ftp->put($localFile, 'images/photo.jpg');
$ftp->close();

Extensions.Ftp.PassiveMode (in config/extensions.php) enables passive mode. Gallery uploads can be mirrored over FTP using the user's usr_ftp_* settings.