- 1
- 2
- 3
// $r[2] = 1080;
$timeStart = (strlen(floor($r[2] / 60)) == 1 ? "0" . floor($r[2] / 60) : floor($r[2] /
60)) . ":" . (strlen($r[2] % 60) == 1 ? "0" . $r[2] % 60 : $r[2] % 60);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
// $r[2] = 1080;
$timeStart = (strlen(floor($r[2] / 60)) == 1 ? "0" . floor($r[2] / 60) : floor($r[2] /
60)) . ":" . (strlen($r[2] % 60) == 1 ? "0" . $r[2] % 60 : $r[2] % 60);
Превращаем минуты во время в формате H:i by ©senior shaurma developer
+1
<?
/*
Bitrix Cleaner v2.2 - https://github.com/creadome/bitrixcleaner
Быстрая очистка 1С-Битрикс
(c) 2015 Станислав Васильев - http://creado.me
[email protected]
*/
require $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_admin_before.php';
$trash = array(
'cache' => array(
'/bitrix/cache/' => 'Неуправляемый кеш',
'/bitrix/managed_cache/' => 'Управляемый кеш',
'/bitrix/html_pages/' => 'HTML кеш'
),
'files' => array(
'/upload/resize_cache/' => 'Кеш изображений'
)
);
if ($_GET['clean']) {
BXClearCache(true);
$GLOBALS['CACHE_MANAGER']->CleanAll();
$GLOBALS['stackCacheManager']->CleanAll();
$staticHtmlCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance();
$staticHtmlCache->deleteAll();
foreach ($trash['files'] as $files => $name) DeleteDirFilesEx($files);
}
function countsize($directory) {
$count = array('file' => 0, 'size' => 0);
foreach (scandir($directory) as $file) {
if ($file != '.' && $file != '..') {
if (is_dir($directory.$file)) {
$inner = countsize($directory.$file.'/');
$count['file'] += $inner['file'];
$count['size'] += $inner['size'];
} else {
$count['file'] ++;
$count['size'] += filesize($directory.$file);
}
}
}
return $count;
}
?>
<table>
<tr>
<th>Описание</th>
<th>Путь</th>
<th>Файлы</th>
<th>Размер</th>
</tr>
<?
foreach ($trash as $type) {
foreach ($type as $directory => $name) {
$count = countsize($_SERVER['DOCUMENT_ROOT'].$directory);
?>
<tr>
<td><?=$name?></td>
<td><a href="/bitrix/admin/fileman_admin.php?lang=ru&path=<?=$directory?>"><?=$directory?></a></td>
<td><?=$count['file']?></td>
<td><?=round($count['size'] / 1048576, 2)?> Мб</td>
</tr>
<?
}
}
?>
</table>
<input type="button" value="Очистить" class="adm-btn-save" data-action="clean">
Битрикс. порадовала строчка "'/bitrix/cache/' => 'Неуправляемый кеш'". Оказывается даже адептам битрикса не подвластно управление кешом самого битрикса :D
https://github.com/creadome/bitrixcleaner/blob/master/cleaner/cleaner.php
+1
if(!strpos($amount,'.')) {
$amount = $amount . '.00';
} else {
$strlength = strlen(explode('.',$amount)[1]);
if($strlength != 2) {
if($strlength == 1) {
$amount = $amount . '0';
}
if($strlength > 2) {
$amount = round($amount,2);
}
}
}
Получение дробного до сотых числа
+1
function toggleAdPanelMobile(e) {
if (mobilecheck()) {
if ($(e.target).parents('.catalog-container').length || $(e.target).hasClass('button')) {
if ($('#site-content').hasClass('open')) {
$siteAdv.show();
}
} else {
if (!$('#site-content').hasClass('open')) {
$siteAdv.show();
}
}
}
}
Главное, что работает
+1
<ul id="top_menu" alias="{$alias}" parentAlias="{$parentAlias}">
{foreach $items as $i}
{*{$i->parentId == null} :)*}
{if $i->parentId == null}
<li class="{if $alias === $i->alias || $parentAlias === $i->alias}active{/if}"><a href="{Yii::app()->params->languageUrl}/{$i->alias}" onclick="return false;">{$i->lang->name}</a>
<ul class="sub" style="display: none;">
{foreach $items as $ii}
{if $ii->parentId == $i->id}
<li class="{if $alias === $ii->alias || $parentAlias === $ii->alias}active{/if}">
{if $ii->hasAction > 0}
<a href="{if $ii->alias!==''}{Yii::app()->params->languageUrl}/{$ii->alias}{/if}">{$ii->lang->name}</a>
{else}
<a href="{Yii::app()->params->languageUrl}/{$i->alias}{if $ii->alias!==''}/{$ii->alias}{/if}">{$ii->lang->name}</a>
{/if}
</li>
{/if}
{/foreach}
</ul>
</li>
{/if}
{/foreach}
</ul>
Типичное меню на фреймворках.
В данном случае Yii
+1
<script type="text/javascript" src="{$assetsUrl}/js/controllers/news.js"></script>
<div class="breadcrumbs">
<span typeof="v:Breadcrumb" ><a href="/" style="color: #000000;">{Y::t('MainMenu', 'Главная')}</a></span> /
<span typeof="v:Breadcrumb" style="color: red;">{$this->title}</span>
</div>
<div class="news_sections">
<ul>
{assign comment ''}
{foreach from=Trololo::model()->newsTypes() key=k item=n}
{if Yii::app()->request->getParam('rubric')==$k}
{assign comment $n['comment']}
<li class="active"><span>{$n['label']}</span></li>
{else}
<li class=""><span><a href="{Yii::app()->params->languageUrl}/news/rubric/{$k}">{$n['label']}</a></span></li>
{/if}
{/foreach}
</ul>
</div>
<h1 class="page_title">{$comment}</h1>
Типичный шаблон на фреймворке.
В данном случае - Yii.
+1
<?
namespace components\max;
class articles_element
{
static function run($_arParams)
{
$arParams = &$_arParams['PARAMS'];
$tm = &$_arParams['tm'];
$user = &$tm->user;
$code = $arParams['CODE'];
$arCache = array(
'prefix' => 'show',
'sufix' => $code,
'time' => -1,
'lang' => LANGUAGE_ID,
);
$tm->loadLang('show');
$arSelect = array(
'E.id',
'E.active',
'rel',
'time',
'code',
'date_active_from',
'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
'content_'.LANGUAGE_ID.' AS content' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
'author_id',
'only_for_auth_users',
'source_url',
'source_author',
'source_date',
);
$arJoin = [];
if($tm->conf['show']['show_additional'])
{
$arSelect[] = 'GROUP_CONCAT(show2category.category_id) AS categories';
$arJoin[\CShow2Category::$table.' show2category ON E.id = show2category.show_id'] = 'LEFT';
}
$arFilter = array('E.code' => $code, 'E.site_id' => $tm->conf['site_id']);
$dbShow = \CShow::GetList(false, $arFilter, ['E.id'], array('nTopCount' => 1), $arSelect, $arJoin);
while($arShow = mysql_fetch_assoc($dbShow))
{
$arShow['title'] = htmlspecialchars($arShow['title']);
if(!empty($arShow['categories']))
{
$arShow['categories'] = explode(',', $arShow['categories']);
}
$arShow['time_write'] = date("d.m.Y", $arShow['date_active_from']);
$arShow['only_for_auth_users'] = $arResult['only_for_auth_users'] && empty($tm->user['id']);
$arResult = $arShow;
if($arResult['only_for_auth_users'])
{
$arResult['title'] = GetMessage('ERROR_ONLY_AUTH');
}
$tm->setLastModifiedTime($arShow['date_active_from']);
$tm->setBuffered('title', $arResult['title'].' | '.GetMessage('sitename'));
$tm->setBuffered('h1', $arResult['title']);
}
if(empty($arResult))
{
// Проверяем редиректы
$arParamsRedirects = array(
'code' => $arFilter['code'],
'module' => 'show',
);
$tm->redirects_modules($arParamsRedirects);
$tm->pagenotfound();
}
$arResult['user_status'] = $user['sts'];
if($tm->conf['show']['show_additional'] && !empty($arResult['categories']))
{
$arFilter = [
'active' => 1,
'show2category.category_id' => $arResult['categories'],
'!E.id' => $arResult['id'],
];
$arSelect = [
'E.id',
'code',
'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
Код от противника фреймворков (это контроллер). Цитата виновника торжества:
"У меня роутинга нету За роутинг отвечает nginx (ранее отвечал .htaccess)"
+1
<p class="name">
{% if (file.url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% } else { %}
<span>{%=file.name%}</span>
{% } %}
</p>
{% if (file.error!="SyntaxError: Unexpected token <") { %}
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
Шедевральный человек! Оригинал http://www.yiiframework.ru/forum/viewtopic.php?t=15956#p119944
+1
List<dynamic> reporting = item.company_profile_data?.AnnualFinancialStatementFiles ??
new List<dynamic>();
string annual = "";
foreach (var report in reporting)
{
if (report.File != null)
{
string name = report.File?.Info?.Name;
if (name != null) annual = annual + name.Substring(0, name.LastIndexOf('.')) + ", ";
}
}
item.Name = annual;
П - производительность.
+1
void CScene::IncludeObjects()
{
// Reset All.
ExcludeObjects();
// fill Vershiny of piramid...
point3d versh[4];
point3d eye = {IniSet.ptCamPos.x, IniSet.ptCamPos.y, IniSet.ptCamPos.z};
Screen2World(0, 0, versh[0]);
Screen2World(nScreenSzX, 0, versh[1]);
Screen2World(nScreenSzX, nScreenSzY, versh[2]);
Screen2World(0, nScreenSzY, versh[3]);
// Increase before OO...
int ix, sz = parrObjs.Size();
point3d vect;
for(ix = 0; ix < 4; ix++){
sub_vectors(&vect.x, &versh[ix].x, &eye.x);
norm_vect(&vect.x);
scale_vect(&vect.x, 200.f);
versh[ix] = vect;
}
// Create faces of piramid and search collision with it...
point3d Piramid[4][3];
Piramid[0][0] = eye;
Piramid[1][0] = eye;
Piramid[2][0] = eye;
Piramid[3][0] = eye;
Piramid[0][1] = versh[0];
Piramid[0][2] = versh[1];
Piramid[1][1] = versh[1];
Piramid[1][2] = versh[2];
Piramid[2][1] = versh[2];
Piramid[2][2] = versh[3];
Piramid[3][1] = versh[3];
Piramid[3][2] = versh[0];
// Dyadya WALERA!!!!
for(ix = nObjOff; ix < sz; ix++){
CObj3d *pObj = parrObjs.e(ix);
pObj->Transform(FALSE);
point3d ptPos = pObj->GetPosition();
if(IniSet.nIncludeObjectMode == WS_INCLUDE_BARYCENTER){
point3d ptCentr = IniSet.ptCamTarget;
point3d vtVect;
sub_vectors(&vtVect.x, &ptPos.x, &ptCentr.x);
plane plGran;
point3d ptCross;
for(int jx = 0; jx < 4; jx++){
comp_plane_eqn(&plGran.a, &Piramid[jx][0].x, &Piramid[jx][1].x, &Piramid[jx][2].x);
cross_line_plane(vtVect, &plGran.a, ptCentr, ptCross);
float f1, f2;
f1 = plGran.a * ptPos.x + plGran.b * ptPos.y + plGran.c * ptPos.z + plGran.d;
f2 = plGran.a * ptCentr.x + plGran.b * ptCentr.y + plGran.c * ptCentr.z + plGran.d;
if(f1 * f2 < 0.f){
if(point_in_triangle(Piramid[jx][0], Piramid[jx][1], Piramid[jx][2], ptCross)){
ptCross = ConvertPos3D(ptCross);
if(IniSet.bMirrorH){ ptCross.y = -ptCross.y; }
if(IniSet.bMirrorV){ ptCross.x = -ptCross.x; }
if(IniSet.bMirrorD){ ptCross.z = -ptCross.z; }
transform_back_point(&ptCross, &ptCross, &IniSet.mtMatr);
pObj->ptSavedPos = ptCross;
break;
}
}
}
}else{ // XYZ Axes.
point3d vtXYZ[3] = {{1.f, 0.f, 0.f},
{0.f, 1.f, 0.f},
{0.f, 0.f, 1.f}};
BOOL bFound = FALSE;
for(int ax = 0; ax < 3; ax++){
point3d vtVect;
transform_point(&vtVect, &vtXYZ[ax], &IniSet.mtMatr);
for(int jx = 0; jx < 4; jx++){
plane plGran;
comp_plane_eqn(&plGran.a, &Piramid[jx][0].x, &Piramid[jx][1].x, &Piramid[jx][2].x);
point3d ptCentr = IniSet.ptCamTarget;
point3d ptCross;
cross_line_plane(vtVect, &plGran.a, ptPos, ptCross);
float f1, f2;
f1 = plGran.a * ptPos.x + plGran.b * ptPos.y + plGran.c * ptPos.z + plGran.d;
f2 = plGran.a * ptCentr.x + plGran.b * ptCentr.y + plGran.c * ptCentr.z + plGran.d;
point3d vtDif;
sub_vectors(&vtDif.x, &ptCross.x, &IniSet.ptCamPos.x);
if(vec_length(&vtDif.x) < 0.01f){ continue; } // avoid crossing with eye.
Гавнокод: включить все 3Д объекты в экран.