- 1
- 2
- 3
- 4
if( !$this->dirsmodel->isExist(array('alias' => $_POST['alias']))) {
$this->messages[] = 'Такой алиас уже существует';
return $this->redirect("admin/dirs/#" . $cat_id);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+148
if( !$this->dirsmodel->isExist(array('alias' => $_POST['alias']))) {
$this->messages[] = 'Такой алиас уже существует';
return $this->redirect("admin/dirs/#" . $cat_id);
}
Говнокод тонкий особый. Кто найдёт получит пиченьку
+159
while ($CORE_PATH[strlen($CORE_PATH)-1]=='\\' || $CORE_PATH[strlen($CORE_PATH)-1]=='/')
{
if (($CORE_PATH[strlen($CORE_PATH)-1]=='\\' || $CORE_PATH[strlen($CORE_PATH)-1]=='/') && strlen($CORE_PATH)>1)
{
$CORE_PATH = substr($CORE_PATH, 0, strlen($CORE_PATH)-1);
}
elseif (($CORE_PATH[strlen($CORE_PATH)-1]=='\\' || $CORE_PATH[strlen($CORE_PATH)-1]=='/') && strlen($CORE_PATH)==1)
{
$CORE_PATH = "";
}
}
+160
<?php
define ('SENGINES',serialize(
array(
'yandex',
'google',
// ... тут их еще несколько
)));
class <засекречено> {
/**
* engines
*
* @var array
*/
private $_engines = unserialize(SENGINES);
// ...
}
+144
<?php
define('PARAM_INT','i');
define('PARAM_INTEGER','i');
define('PARAM_FLOAT','f');
define('PARAM_DOUBLE','f');
define('PARAM_STRING','s');
define('PARAM_ID','id');
define('PARAM_ANY','*');
define('PARAM_RAW','raw');
define('PARAM_OBJECT','o');
define('PARAM_URL','u');
define('PARAM_EMAIL','e');
define('SOURCE_INPUT','$_GET');
define('SOURCE_FORM','$_POST');
define('SOURCE_COOKIE','$_COOKIE');
define('SOURCE_REQUEST','$_REQUEST');
define('SOURCE_PATH','$this->params');
define('SOURCE_ANY','');
class Request implements {
const PARAM_INT=PARAM_INT;
const PARAM_INTEGER=PARAM_INTEGER;
const PARAM_FLOAT=PARAM_FLOAT;
const PARAM_DOUBLE=PARAM_DOUBLE;
const PARAM_STRING=PARAM_STRING;
const PARAM_ID=PARAM_ID;
const PARAM_ANY=PARAM_ANY;
const PARAM_RAW=PARAM_RAW;
const PARAM_OBJECT=PARAM_OBJECT;
const PARAM_URL=PARAM_URL;
const PARAM_EMAIL=PARAM_EMAIL;
const SOURCE_INPUT=SOURCE_INPUT;
const SOURCE_FORM=SOURCE_FORM;
const SOURCE_COOKIE=SOURCE_COOKIE;
const SOURCE_REQUEST=SOURCE_REQUEST;
const SOURCE_PATH=SOURCE_PATH;
const SOURCE_ANY=SOURCE_ANY;
.....
}
цель: пользоваться как и в стиле ООП, как и сделать запись короче, без указания Request::
некоторые значения синомизированы для менее мучительного процесса вспоминания имен констант.
говно, но что делать....
может, у кого-то мозги работают лучше, чем у меня, и предложат другой выход?
зы: кто согласен, что так и нужно делать, минусуйте и топите, не буду в обиде
+150
/* That revolting regular expression explained
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
\---/ \---/\-------------/ \-------/
| | | |
| | | The value
| | ~,|,^,$,* or =
| Attribute
Tag
*/
Это НЕ говонокод, просто коммент к регулярке, просто очень понравился и хотел показать...
Иногда регулярки очен запутанами бывает, и редактировать их турдно без нормальной комментов.
Нашел в shop-script
+154
// $curr_page - старница, на который сейчас находимся
// $n_page - число страниц
// $count - обще число записей
// $param - site - страницы на сайте
// - adm - в админке
function genNumPage($curr_page, $n_page, $count, $param=null) {
$string = parse_url($_SERVER['REQUEST_URI']);
$query = '?'.$string['query'];
$num_page = ceil($count / $n_page);
if (isset($param)) $table = new my_Page("site/site_interface.html", "num_page");
else $table = new my_Page("interface/interface.html", "num_page");
if ($num_page < 2) return null;
for ($i = 1; $i <= $num_page; $i++) {
if ($i != $curr_page) {
if (preg_match('/\?p\=[0-9]{1,3}/', $query)) $href = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.$i, $query);
elseif (preg_match('/\&p\=[0-9]{1,3}/', $query)) $href = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.$i, $query);
elseif ($string['query'] != '') $href = '?'.$string['query'].'&p='.$i;
else $href = '?p='.$i;
if ((!$param) || ($param == 'adm')) $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> ";
else $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> | ";
}
elseif ((!$param) || ($param == 'adm')) $str .= "<span>".$i."</span>";
else $str .= "<span>".$i."</span> | ";
}
if ($curr_page > 1) {
if (preg_match('/\?p\=[0-9]{1,3}/', $query)) $prev = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page - 1), $query);
elseif (preg_match('/\&p\=[0-9]{1,3}/', $query)) $prev = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page - 1), $query);
elseif ($string['query'] != '') $prev = '?'.$string['query'].'&p='.($curr_page - 1);
else $prev = '?p='.($curr_page - 1);;
if ((!$param) || ($param == 'adm')) $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">←</a> ";
else $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">Предыдущая</a> ";
}
if ($curr_page < $num_page) {
if (preg_match('/\?p\=[0-9]{1,3}/', $query)) $next = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page + 1), $query);
elseif (preg_match('/\&p\=[0-9]{1,3}/', $query)) $next = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page + 1), $query);
elseif ($string['query'] != '') $next = '?'.$string['query'].'&p='.($curr_page + 1);
else $next = '?p='.($curr_page + 1);;
if ((!$param) || ($param == 'adm')) $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">→</a> ";
else $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">Следующая</a> ";
}
$table->addValueArray(array(
"NUM" => $str,
"PREV" => $prev,
"NEXT" => $next
));
return $table->myReplace();
}
Генерирует номера страниц. Из одной CMS'ки.
+161
function ss ($id){ // получить дату рождения по ИНН для украины
$result = array();
//sex
$result['sex'] = (substr($id,8,1) % 2) ? 'M' : 'F';
//birthdate
$days = substr($id,0,5);
$year = 1900; $day = 01; $month = 01;
while ($days > 0)
{
$daysInYear = (checkdate (02, 29, $year)) ? 366 : 365;
if ($days > $daysInYear)
{
$days -= $daysInYear;
$year ++;
}
else{
for ($daysInMonth = 31; !checkdate($month, $daysInMonth, $year); $daysInMonth–) ;
if ($days > $daysInMonth)
{
$days -= $daysInMonth;
$month ++;
}
else{
$day = $days;
$days = 0;
}
}
}
$result['year'] = $year;
$result['month'] = $month;
$result['day'] = $day;
return $result;
}
обходить каждый день начиная с 1900 это сила
быстрее было бы
$inn = '2322222222';
$inn = substr($inn,0,5);
$normal_date = date("d.m.Y", strtotime('01/01/1900 + ' . $inn . ' days - 1 days'));
+144
// Строк 50 кода
<style>
switch ($view_mod)
{
default :
echo ('
// Здесь для элементов разметки стили выводятся
');
break;
2 :
echo ('
// Соответственно здесь
');
break;
3 :
echo ('
// И здесь
');
break;
}
</style>
// Еще строк 250 кода
if (!isset ($color_theme)) then
{
$color_theme=$def_color_theme;
}
В универе учат в основном Delphi, решил, что надо самостоятельно хорошо изучить что-нить еще. Решил попробовать PHP и непривычно постоянно с одного языка на другой перескакивать. Блин, eб@нулся, пока нашел ошибки on lines: 18, 26 и 44...
+158
<?php
class WikiParser{
private $p;
function __construct($p){
$this->p=$p;
}
function parse(){
$this->p = preg_replace('/\[\[([^\/"?[=|]+?)\]\]/siu', '<a href="link.php?sea=$1">$1</a>', $this->p);
$this->p = preg_replace('/\[\[([^\/"?[=|]+?)\|(.+?)\]\]/siu', '<a href="link.php?sea=$1">$2</a>', $this->p);
$this->p = preg_replace('/\[\[([a-z]+?:\/\/[^"|]*?)\|([^"?[=|]+?)\]\]/siu', '<a href="$1">$2</a>', $this->p);
$this->p = preg_replace('/\[\[([a-z]+?:\/\/[^"|]*?)\]\]/siu', '<a href="$1">$1</a>', $this->p);
$this->p = preg_replace('/<<([^\/"?[=|]+?)>>/siu', '<a href="link.php?sea=$1">$1</a>', $this->p);
$this->p = preg_replace('/<<([^\/"?[=|]+?)\|(.+?)>>/siu', '<a href="link.php?sea=$1">$2</a>', $this->p);
$this->p = preg_replace('/<<([a-z]+?:\/\/[^"|]*?)\|([^"?[=|]+?)>>/siu', '<a href="$1">$2</a>', $this->p);
$this->p = preg_replace('/<<([a-z]+?:\/\/[^"|]*?)>>/siu', '<a href="$1">$1</a>', $this->p);
$this->p = preg_replace('/\*\*\*?([^"?=#%]+?)\*\*\*?/siu', '<b>$1</b>', $this->p);
$this->p = preg_replace('/\-\-\-?([^"?=#%]+?)\-\-\-?/siu', '<s>$1</s>', $this->p);
$this->p = preg_replace('/\/\/\/?([^"?=#%]+?)\/\/\/?/siu', '<i>$1</i>', $this->p);
$this->p = preg_replace('/\r?\n\r?\n/', '</p><p>', $this->p);
$this->p = preg_replace('/\n/', '<br/>', $this->p);
$this->p = preg_replace('/\{\{locked\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Статья огорожена от <a href="link.php?sea=вапераст">ваперастов</a></td></tr></table>', $this->p);
$this->p = preg_replace('/\{\{locked\|(.*?)\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Статья огорожена от $1</td></tr></table>', $this->p);
$this->p = preg_replace('/\{\{недопись\}\}/siu', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle"><b>Недопись</b><br>Ваша статья - Гавно. Короткая, тупая и малоинформативная</td></tr></table>', $this->p);
$this->p = preg_replace('/\{\{недопись\|([^|]*?)\}\}/siu', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle">Недопись<br>Ваша статья - $1</td></tr></table>', $this->p);
$this->p = preg_replace('/\{\{moved\|(.*?)\}\}/', '<table style="clear: both; width: 90%; border-color:#333333; border-style: solid; border-width: 1px 1px 1px 2px; padding: 2px; margin: 1px auto 1px auto; vertical-align: center; background-color: #fefefe; text-align: left;"><tr><td style="vertical-align: middle"><b>Статья перемещена</b><br>-->$1</td></tr></table>', $this->p);
$this->p = preg_replace('/[[<]#[]>]/', '', $this->p);
if(!preg_match('#^<p>.*</p>$#siu', $this->p)) $this->p='<p>'.$this->p.'</p>';
$this->p = preg_replace('/<p><\/p>/siu', '', $this->p);
}
function get(){return $this->p;}
}
?>
Без комментариев
+161
function renameimage($dir,$file)
{
$words=array('fuck','blia','fuck_you_spilberg','mazfaka','simpsons');
$rand=array_rand($words);
$type_foto=end(explode(".", $file));
$new_name_of_foto=md5($rand[$words].$file).'.'.$type_foto;
$ren=rename($dir.$file,$dir.$new_name_of_foto);
if($ren)
{
return $new_name_of_foto;
}
else
{
echo 'не получилось...<br>';
}
}
пыщ-пыщ