-
Лучший говнокод
- В номинации:
-
- За время:
-
-
+156
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
$this->_html .= '<script type="text/javascript">id_language = ' . intval($this->defaultLanguage) . ';</script>';
if ($ObjAdvancedTopMenuClass)
$haveDepend = AdvancedTopMenuClass::menuHaveDepend($ObjAdvancedTopMenuClass->id);
$this->_html .= '<form action="' . $this->base_config_url . '" method="post" id="menuform_' . $this->name . '" name="menuform_' . $this->name . '" method="post" enctype="multipart/form-data" class="width3">
<div id="blocMenuForm">
' . ($ObjAdvancedTopMenuClass ? '<input type="hidden" name="id_menu" value="' . intval($ObjAdvancedTopMenuClass->id) . '" /><br /><a href="' . $this->base_config_url . '"><img src="../img/admin/arrow2.gif" />' . $this->l('Back') . '</a><br class="clear" /><br />' : '');
$this->_html .= '<label>' . $this->l('Tab type') . '</label>
<div class="margin-form"><select name="type" id="type_menu">
<option value="">' . $this->l('Choose') . '</option>
<option value="1" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 1 ? 'selected="selected"' : '') . '>' . $this->l('CMS') . '</option>
<option value="2" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 2 ? 'selected="selected"' : '') . '>' . $this->l('Link') . '</option>
<option value="3" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 3 ? 'selected="selected"' : '') . '>' . $this->l('Category') . '</option>
<option value="4" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 4 ? 'selected="selected"' : '') . '>' . $this->l('Manufacturer') . '</option>
<option value="5" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 5 ? 'selected="selected"' : '') . '>' . $this->l('Supplier') . '</option>
<option value="6" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 6 ? 'selected="selected"' : '') . '>' . $this->l('Search') . '</option>
<option value="7" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 7 ? 'selected="selected"' : '') . '>' . $this->l('Only image or icon') . '</option>
</select></div>';
$this->_html .= '<script type="text/javascript">$("#type_menu").change(function() {showMenuType($(this),"menu");});</script>';
$this->_html .= '<label>' . $this->l('Menu link not clickable') . '</label>
<div class="margin-form">
<input type="checkbox" name="clickable" id="menu_clickable" value="1" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->link [$this->defaultLanguage] == '#' ? ' checked=checked' : '') . ' />
<small>' . $this->l('Add a # in the link field. Do not remove.') . '</small>
</div>';
$this->_html .= '<script type="text/javascript">$("#menu_clickable").click(function() {setUnclickable($(this));});</script>';
if ($ObjAdvancedTopMenuClass && in_array($ObjAdvancedTopMenuClass->type, $this->rebuildable_type)) {
$this->_html .= '<label>' . $this->l('Rebuild tree') . '</label>
<div class="margin-form"><label class="t" for="rebuild_on"><img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /></label>
<input type="radio" name="rebuild" id="rebuild_on" value="1" />
<label class="t" for="rebuild_on"> ' . $this->l('Yes') . '</label>
<label class="t" for="rebuild_off"><img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /></label>
<input type="radio" name="rebuild" id="rebuild_off" value="0" checked=checked />
<label class="t" for="rebuild_off"> ' . $this->l('No') . '</label><br />' . $this->l('Caution, this may change the appearance of your menu !') . '</div>';
}
А Smarty стоит рядышком и тихо плачет вместе с программистом.
Модуль для PrestaShop стоимостью 50 евро.
in8finity,
19 Мая 2014
-
+133
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
public void ExtIdGen()
{
try
{
Random rnd = new Random();
string uin = "";
for (int i = 0; i < 20; i++)
{
uin += rnd.Next(10).ToString();
}
this.ExtId = uin;
GetError("0");
}
catch
{
GetError("-6");
}
}
private void GetError(string error_code)
{
switch (error_code)
{
case "0":
this.LastErrorCode = 0;
this.LastErrorDescription = "Нет ошибок";
break;
// -1 .. -5
case "-6":
this.LastErrorCode = -6;
this.LastErrorDescription = "Ошибка при получении идентификатора запроса";
break;
}
}
LastErrorCode, LastErrorDescription, ExtId - public поля.
Там весь класс написан в таком стиле, с вызовами GetError, принимающими номер ошибки в виде строки, молчаливым catch-ем всех исключений и т.п.
yamamoto,
17 Мая 2014
-
+155
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
{php}
$this->_tpl_vars['image_set'] = array();
$this->_tpl_vars['json_string'] = "";
{/php}
{if $pcollection}
{foreach name=pcollection key=picture_id item=picture from=$pcollection}
{php}
array_push($this->_tpl_vars['image_set'], "{$this->_tpl_vars['urlprefix']}/thumb.php?file=" . str_replace("thumbs","original","media/pictures/{$this->_tpl_vars['album']->getPath()}/{$this->_tpl_vars['picture']->getPath()}")."&size=245x143");
{/php}
{/foreach}
{/if}
{php}
$this->_tpl_vars['json_string'] = json_encode($this->_tpl_vars['image_set']);
{/php}
{$json_string}
получение объекта в smarty, потом пара фокусов, и вуаля, выплевываем json строку
expert,
15 Мая 2014
-
+152
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
function code_generator(){
$chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$code_name='';
for ($i=0;$i<5;$i++){
$code_name.=substr($chars, rand(1, strlen($chars))-1,1);
}
return $code_name;
}
function generate (){
$code_name=code_generator().'-'.code_generator().'-'.code_generator().'-'.code_generator().'-'.code_generator();
return $code_name;
}
Шедевральное решение задачи по генерированию ключа:)
PHPed,
09 Мая 2014
-
+156
- 1
- 2
- 3
- 4
- 5
- 6
function onFuncIsSome()
{
someFunc();
if( !state )
return;
}
я понимаю что после этого условия что-то когда то было, но выглядит прикольно )
Dart_Sergius,
06 Мая 2014
-
+151
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
if (!empty($_POST["favoriteColor"])) {
switch($_POST["favoriteColor"]) {
case "Lightred":
$strBackgroundColor = "#FFDAB9";
break;
case "Lightgreen":
$strBackgroundColor = "Lightgreen";
break;
case "Lightblue":
$strBackgroundColor = "Lightblue";
break;
case "Lightgray":
$strBackgroundColor = "Lightgray";
break;
default:
$strBackgroundColor = "Gray";
break;
}
} else {
$strBackgroundColor = "Gray";
}
arif,
05 Мая 2014
-
+126
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
private static void LoadSendMethodFromConfig()
{
if (!sendMethod.HasValue)
{
sendMethod = SendMethodTypes.Default;
try
{
// read SendKeys value from config file, not case sensitive
string value = System.Configuration.ConfigurationManager.AppSettings.Get("SendKeys");
if (string.IsNullOrEmpty(value))
return;
if (value.Equals("JournalHook", StringComparison.OrdinalIgnoreCase))
sendMethod = SendMethodTypes.JournalHook;
else if (value.Equals("SendInput", StringComparison.OrdinalIgnoreCase))
sendMethod = SendMethodTypes.SendInput;
}
catch { } // ignore any exceptions to keep existing SendKeys behavior
}
}
Сорцы дотнета. Игнорируем любые исключения. Возмущение компилятора отключаем атрибутом. Как мило!
Пруф: http://referencesource.microsoft.com/#System.Windows.Forms/ndp/fx/src/winforms/Managed/System/WinForms/SendKeys.cs#323f3884113aa0ae#references
Цимес ещё и в том, что раньше в коде не было строк:
if (string.IsNullOrEmpty(value))
return;
То есть NullReferenceException тоже глушилось.
ЗЫ: пришлось пароль вспоминать, чтобы запостить. А то лень было логиниться, из под геста изредка комментил.
koodeer,
28 Апреля 2014
-
+154
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
trait TPerson {
public $fname;
public $lname;
public $mname;
// ...
}
class BUser extends EMongoDocument {
public $first_name;
public $last_name;
public $middle_name;
// ...
}
class User extends BUser {
public $firstname;
public $lastname;
// ...
}
Попалось такое наследие на одном рабочем месте. Было два типа юзеров, каждый из них наследовал BUser, в одном из них были firstname и lastname, в другом не были. В монге документы юзера, у которого свои firstname и lastname были вида:
{
_id: ObjectId("..."),
...
first_name: '',
last_name: '',
middle_name: '',
fname: '',
lname: '',
mname: '',
firstname: '',
lastname: ''
}
LubarVV,
26 Апреля 2014
-
+72
- 1
- 2
- 3
- 4
- 5
if(error == CABtEngineErrors.K_ERR_BTENGINE_CANCEL) {
mObserver.btEngineEncryptError(CABtEngineErrors.K_ERR_BTENGINE_CANCEL);
} else {
mObserver.btEngineEncryptError(error);
}
busylee,
26 Апреля 2014
-
+154
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
$massiv = array(1,2,3,4,5,6,7,8);
$her = 0;
$idRazdelov = array();
$idRoditela = $idrazdelf;
foreach($massiv as $chislo){
$db_list = CIBlockSection::GetList(Array(SORT=>"ASC"), $arFilter = Array("IBLOCK_ID"=>"7", "ID"=>$idRoditela), true);
while($ar_result = $db_list->GetNext()){
if ($her == 0){
if ($ar_result["IBLOCK_SECTION_ID"]){
$idRazdelov[].= $ar_result["ID"];
$idRoditela = $ar_result["IBLOCK_SECTION_ID"];
}else{
$idRazdelov[].= $ar_result["ID"];
$her = 1;
}
}
}
}
Cotard,
25 Апреля 2014