- 1
print str_replace('collapsed', '', str_replace('expanded', '', str_replace('leaf', '', menu_tree($menu_name = 'menu-fabric'))))
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+157
print str_replace('collapsed', '', str_replace('expanded', '', str_replace('leaf', '', menu_tree($menu_name = 'menu-fabric'))))
Вывод меню через файл шаблона в Drupal…
+154
include "./include/db.conf.php";
$con = mysql_connect($DB["host"],$DB["user"],$DB["pass"]) or die ("could not connect:".mysql_error());
mysql_set_charset('utf8');
mysql_select_db($DB["dbName"]) or die ("could not connect:".mysql_error());
$hash = $_GET['hash'];
$login = $_GET['login'];
echo "SELECT id FROM reg WHERE log = '".$login."' AND hash = '".$hash."'";
$query = mysql_query("SELECT id FROM reg WHERE log = '".$login."' AND hash = '".$hash."'") or die ("MYSQL error".mysql_error());
if ($query) {
while($row = mysql_fetch_array($query)) {
echo row['id'];}
$query = mysql_query("UPDATE reg SET commit=1 WHERE id=".row['id'])
or die ("MYSQL error".mysql_error());}
Знакомая поделилась шедевром. Так, конечно, можно... но в общем комментарии излишни.
Да, форматирование оригинала сохранено.
+162
public function save() {
try {
try {
$this->create();
} catch (Exception $e) {
//probably dulplicate
$this->update();
}
} catch (Exception $e) {
logger::error($e);
}
}
try-catch много не бывает
+157
function date_preobr($date, $ind=0) {
$date1=substr($date, 8, 2); $date21=substr($date, 5, 2); $date3=substr($date, 0, 4);
if ($ind==0) $data=$date1.".".$date21.".".$date3;
elseif ($ind==1) $data=$date1.".".$date21.".".substr($date3, 2, strlen($date3)-2);
elseif ($ind==2) {switch ($date21) {case "01":$date21="января";break;case "02":$date21="февраля";break;
case "03":$date21="марта";break;case "04":$date21="апреля";break;case "05":$date21="мая";break;
case "06":$date21="июня";break;case "07":$date21="июля";break;case "08":$date21="августа";break;
case "09":$date21="сентября";break;case "10":$date21="октября";break;case "11":$date21="ноября";break;
case "12":$date21="декабря";break;} $data=$date1." ".$date21." ".$date3;}
return $data;}
Были даты, есть дата, будут даты.
Привожу в первозданном виде.
+154
public function setIndex() {
$lang = '';
switch($this->data['find_in']) {
case '1' :
$this->indexes = Indexes::COMPANIES.$lang;
break;
case '2' :
$this->indexes = Indexes::PRODUCTS.$lang;
break;
case '3' :
$this->indexes = Indexes::PROMOS.$lang;
break;
default:
$this->indexes = Indexes::COMPANIES.$lang;
break;
}
}
+148
<?php
class CodeCounter {
const MULTILINE_COMMENT = 0x01;
private $dir = null;
private $ext = null;
public function __construct($dir = '.', $ext = '*') {
$this->dir = $dir;
if($ext == '*') {
$this->ext = "/.*/si";
} else {
$e = explode('|', $ext);
foreach($e as &$ext) {
$ext = trim($ext);
if($ext == '')
unset($ext);
}
$r = implode('|', $e);
$this->ext = "/.*\.({$r})$/si";
}
}
public function calculate() {
$lines = 0;
$args = func_get_args();
if(count($args) == 0)
$dir = $this->dir;
else
$dir = $args[0];
if(file_exists($dir) && is_dir($dir)) {
$list = scandir($dir);
foreach($list as $item) {
if($item == '.' || $item == '..')
continue;
$fullItem = realpath($dir . DIRECTORY_SEPARATOR . $item);
if(is_dir($fullItem)) {
$lines += $this->calculate($fullItem);
} else {
if(preg_match($this->ext, $item)) {
echo "Calculating lines in {$fullItem}: ";
$_lines = self::count($fullItem);
echo "{$_lines}\n";
$lines += $_lines;
}
}
}
}
return $lines;
}
private static function count($file) {
$lines = 0;
$d = null;
if(file_exists($file) && ($file = file($file))) {
foreach($file as $line) {
$line = trim($line);
if($line == '')
continue;
if( substr($line, 0, 2) == '//' || //single line comment
substr($line, 0, 1) == '#' || //single line comment
substr($line, 0, 2) == '<?' || //php open tag
substr($line, 0, 2) == '?>' //php close tags
)
continue;
if(($pos = strpos('/*', $line)) !== false) {
if($pos == 0) {
if(strpos('*/', $line, $pos) === false) {
$d = self::MULTILINE_COMMENT;
}
} else {
$lines++;
}
continue;
}
if($d == self::MULTILINE_COMMENT) {
if(strpos('*/', $line) !== false) {
$d = null;
}
continue;
}
$lines++;
}
}
return $lines;
}
}
$counter = new CodeCounter('./amapys', 'php|js');
$lines = $counter->calculate();
echo "\nTotal: {$lines} lines\n";
Автор: POPSuL
Пхп-шники такие пхп-шники.
ООП во все поля. Им неведом sed и awk.
+154
foreach ($templatedata as $templatedataname=>$templatedatavalue)
$$templatedataname = $templatedatavalue;
include($templatesDir.'/'.$file.'.tpl.php');
Велошаблонизатор, превращающий пары ключ-значение из массива в локальные переменные шаблона.
Шаблон - простой php-файл, в нужных местах выводящий полученные значения (реже с какой-либо логикой вроде обработки массива).
+167
$r = $this->client->getBerechneteGrundversorgungsTarifebyPLZundVerbrauchKundenart($this->params);
По сути не говнокод, но нечитабельность налицо...
+164
foreach ($params as $k => $v) {
eval('$this->' . $k . ' = $v;');
}
+158
//Отображеие меню
$arr = get("select max(depth) as d from ".DP."docs");
$to = $arr[0]['d'];
$a = get("select * from ".DP."docs where depth='0' order by prior");
$arr = $a;
for($i=0;$i<=$to;$i++)
{
$a = get("select * from ".DP."docs where depth='".$i."' order by prior");
if(is_array($a))
foreach($a as $key=>$value)
{
$b = array();$af = array();$bf = array();
$b = get("select * from ".DP."docs where pid='".$a[$key]['id']."' order by prior");
if(!$b)$b = array();
$before = true;
//поиск в массиве
foreach($arr as $key2=>$value2)
{
if($arr[$key2]['id'] != $a[$key]['id'] and $before) $bf[] = $arr[$key2];
if($arr[$key2]['id'] == $a[$key]['id'] ){ $bf[] = $arr[$key2]; $before=false;}
if($arr[$key2]['id'] != $a[$key]['id'] and !$before) $af[] = $arr[$key2];
}
$arr = array_merge($bf,$b,$af);
}
}
построение дерева сайта. хотя может я не разобрался, весь код пестрит такими перлами.