-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Looks like stable release
- Loading branch information
0 parents
commit bda4c35
Showing
14 changed files
with
1,188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
* text=auto | ||
* eol=lf | ||
|
||
.git export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
vendor export-ignore | ||
makefile export-ignore | ||
phpunit.xml export-ignore | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "ajur-media/fsnews.media", | ||
"description": "FSNews Engine Media common class", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"AJUR\\FSNews\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Karel Wintersky", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"ext-json": "*", | ||
"ext-fileinfo": "*", | ||
"psr/log": "^1.1", | ||
"karelwintersky/arris": "^2.4", | ||
"karelwintersky/arris.toolkit.mimetypes": "^1.0", | ||
"ajur-media/php_gdwrapper": "^1.2" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/make | ||
|
||
help: | ||
@perl -e '$(HELP_ACTION)' $(MAKEFILE_LIST) | ||
|
||
test: ##@test PHPUnit tests | ||
@php ./vendor/bin/phpunit --bootstrap vendor/autoload.php --testdox tests | ||
|
||
# ------------------------------------------------ | ||
# Add the following 'help' target to your makefile, add help text after each target name starting with '\#\#' | ||
# A category can be added with @category | ||
GREEN := $(shell tput -Txterm setaf 2) | ||
YELLOW := $(shell tput -Txterm setaf 3) | ||
WHITE := $(shell tput -Txterm setaf 7) | ||
RESET := $(shell tput -Txterm sgr0) | ||
HELP_ACTION = \ | ||
%help; while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-_]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \ | ||
print "usage: make [target]\n\n"; for (sort keys %help) { print "${WHITE}$$_:${RESET}\n"; \ | ||
for (@{$$help{$$_}}) { $$sep = " " x (32 - length $$_->[0]); print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; }; \ | ||
print "\n"; } | ||
|
||
# -eof- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<phpunit | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true"> | ||
|
||
<testsuite name=""> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace AJUR\FSNews\Constants; | ||
|
||
trait AllowedMimeTypes | ||
{ | ||
/** | ||
* Доступные для аплоада майм-типы | ||
* | ||
* @var string[] | ||
*/ | ||
public static $allowed_mime_types = [ | ||
'audio/', | ||
'image/', | ||
'video/', | ||
'application/pdf', | ||
'application/msword', | ||
'application/vnd.ms-powerpoint', | ||
'application/rtf', | ||
'application/vnd.ms-excel', | ||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | ||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace AJUR\FSNews\Constants; | ||
|
||
trait ContentDirs | ||
{ | ||
/** | ||
* Mapping: тип контента - каталог хранения | ||
* | ||
* Используется в методе getRelResourcePath() | ||
* | ||
* @var string[] | ||
*/ | ||
public static $content_dirs = [ | ||
"title" => "titles", | ||
"titles" => "titles", | ||
"photos" => "photos", | ||
"videos" => "videos", | ||
"audios" => "audios", | ||
"youtube" => "youtube", | ||
"files" => "files", | ||
"_" => "" | ||
]; | ||
|
||
public static function getContentDir($type = 'photos'):string | ||
{ | ||
return array_key_exists($type, self::$content_dirs) | ||
? self::$content_dirs[$type] | ||
: self::$content_dirs['_']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?php | ||
|
||
namespace AJUR\FSNews\Constants; | ||
|
||
trait ConvertSizes | ||
{ | ||
/** | ||
* Все возможные размеры превьюшек/картинок ко всем типам медиа - с размерами, функцией-обработчиком, файлом вотермарки, отступом вотермарки | ||
* | ||
* Внимание: префиксы уже содержат `_` и приклеиваются к корню имени без добавочных знаков. Ну, должны. | ||
* | ||
* @var array | ||
*/ | ||
public static $convert_sizes = [ | ||
/* | ||
* Используются размеры: 100x100, 440x300, 630x465, 1280x1024 | ||
*/ | ||
"photos" => [ | ||
/* | ||
* Иконка превью в списке фотографий, входящих в фоторепортаж (десктоп и мобильный) | ||
*/ | ||
"100x100" => [ | ||
'maxWidth' => 100, | ||
'maxHeight' => 100, | ||
'method' => "getfixedpicture", | ||
'prefix' => '100x100_', | ||
'quality' => 80, | ||
], | ||
/* | ||
* sizes_full - для десктопного фоторепортажа в RSS-лентах | ||
* базовый размер для фото, вставляемого в МОБИЛЬНУЮ статью через [media id=] -- (считается, что 440 - это базовая ширина мобилки) | ||
*/ | ||
"440x300" => [ | ||
'maxWidth' => 440, | ||
'maxHeight' => 999, | ||
'method' => "resizepictureaspect", | ||
'wmFile' => "l.png", | ||
'wmMargin' => 10, | ||
'prefix' => '440x300_', | ||
'quality' => 80, | ||
], | ||
/* | ||
* базовый размер для фото в фоторепортаже (десктоп и мобильный) | ||
* базовый размер для фото, вставляемого в десктопную статью через [media id=] | ||
*/ | ||
"630x465" => [ | ||
'maxWidth' => 630, | ||
'maxHeight' => 465, | ||
'method' => "resizepictureaspect", | ||
'wmFile' => "l.png", | ||
'wmMargin' => 30, | ||
'prefix' => '630x465_', | ||
'quality' => 80, | ||
], | ||
/* | ||
* sizes_full - полноразмерная картинка, всплывающая при клике на вставленную в статью/страницу фото размера 'sizes' (630x465) | ||
* sizes_full для репортажей на мобиле | ||
* sizes_large для всех фото | ||
* + упоминается в шаблоне site/reports/reports_list.tpl | ||
*/ | ||
"1280x1024" => [ | ||
'maxWidth' => 1280, | ||
'maxHeight' => 1024, | ||
'method' => "resizeimageaspect", | ||
'wmFile' => "l.png", | ||
'wmMargin' => 30, | ||
'prefix' => '1280x1024_', | ||
'quality' => 90, | ||
], | ||
], | ||
"videos" => [ | ||
"100x100" => [ | ||
/* | ||
* Превью-иконка видео в админке | ||
*/ | ||
'maxWidth' => 100, | ||
'maxHeight' => 100, | ||
'method' => "getfixedpicture", | ||
'prefix' => '100x100_', | ||
'quality' => 80, | ||
], | ||
/* | ||
* Превью видео, используется | ||
*/ | ||
"640x352" => [ | ||
'maxWidth' => 640, | ||
'maxHeight' => 360, | ||
'method' => "getfixedpicture", | ||
'prefix' => '640x352_', | ||
'quality' => 80, | ||
], | ||
], | ||
|
||
"audios" => [ | ||
"_" => [ | ||
'prefix' => '', | ||
], | ||
], | ||
|
||
"files" => [ | ||
"_" => [ | ||
'prefix' => '', | ||
], | ||
], | ||
|
||
"youtube" => [ | ||
/* | ||
* Превью в админке | ||
*/ | ||
"100x100" => [ | ||
'maxWidth' => 100, | ||
'maxHeight' => 100, | ||
'method' => "getfixedpicture", | ||
'prefix' => '100x100_', | ||
'quality' => 80 | ||
], | ||
/* | ||
* Превью видео, используется | ||
*/ | ||
"640x352" => [ | ||
'maxWidth' => 640, | ||
'maxHeight' => 360, | ||
'method' => "getfixedpicture", | ||
'prefix' => '640x325_', | ||
'quality' => 80 | ||
], | ||
], | ||
|
||
"titles" => [ | ||
/* | ||
* основное title изображение, (article.tpl) | ||
* Еще оно используется в админке, в редакторе статей | ||
* Нехай качество будет 92, разница между 90 и 92 по размеру около 2%, а качество должно различаться заметно | ||
*/ | ||
'608x406' => [ | ||
'maxWidth' => 608, | ||
'maxHeight' => 406, | ||
'method' => '', | ||
'prefix' => '', | ||
'quality' => 92 | ||
], | ||
/* | ||
* "квадратные" превью тайтлов статей на главной (widget.tpl, index_tres.tpl) | ||
*/ | ||
'300x266' => [ | ||
'maxWidth' => 300, | ||
'maxHeight' => 266, | ||
'method' => 'getFixedPicture', | ||
'prefix' => 'resize_', | ||
'quality' => 80 | ||
], | ||
/* | ||
* маленькие превью тайтлов статей на главной (3 в топе) | ||
* картинки в фиде "авторский материал" на главной | ||
*/ | ||
'205x150' => [ | ||
'maxWidth' => 205, | ||
'maxHeight' => 150, | ||
'method' => 'getFixedPicture', | ||
'prefix' => 'small_', | ||
'quality' => 70 | ||
], | ||
] | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace AJUR\FSNews\Helpers; | ||
|
||
class DTHelper | ||
{ | ||
const ruMonths = array( | ||
1 => 'января', 2 => 'февраля', | ||
3 => 'марта', 4 => 'апреля', 5 => 'мая', | ||
6 => 'июня', 7 => 'июля', 8 => 'августа', | ||
9 => 'сентября', 10 => 'октября', 11 => 'ноября', | ||
12 => 'декабря' | ||
); | ||
|
||
const yearSuffux = 'г.'; | ||
|
||
/** | ||
* Преобразует переданную дату в русифицированную дату | ||
* | ||
* @param string $datetime - заполненную нулями возвращает как "-", "today"|"NOW()" | ||
* @param bool $is_show_time | ||
* @param null $year_suffix - можно передать пустую строчку, чтобы подавить вывод годового суффикса | ||
* @return string | ||
*/ | ||
public static function convertDate(string $datetime, bool $is_show_time = false, $year_suffix = null):string | ||
{ | ||
$datetime = strtoupper($datetime); | ||
if ($datetime === "0000-00-00 00:00:00" || $datetime === "0000-00-00") { | ||
return "-"; | ||
} | ||
|
||
if ($datetime === 'TODAY' || $datetime === 'NOW()') { | ||
$datetime = date("Y-m-d H:i:s"); | ||
} | ||
|
||
if (is_null($year_suffix)) { | ||
$year_suffix = self::yearSuffux; | ||
} | ||
|
||
list( $y, $m, $d, $h, $i, $s ) = sscanf( $datetime, "%d-%d-%d %d:%d:%d" ); | ||
|
||
$rusdate = sprintf("%s %s %s", $d, self::ruMonths[$m], $y ? "{$y} {$year_suffix}" : ""); | ||
|
||
if ($is_show_time) { | ||
$rusdate .= sprintf(" %02d:%02d", $h, $i); | ||
} | ||
return $rusdate; | ||
} | ||
|
||
} |
Oops, something went wrong.