- 1
if (substr(json_encode($row['list']), 0, 1) == '[') {
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+166
if (substr(json_encode($row['list']), 0, 1) == '[') {
Такой вот аналог is_array()
+149
if ($result->fetch()) {
return $result->get('num_flags');
}
else {
return 666;
}
Верующий программист :)
+161
//надо показать элемент каталога во всей красе
$_CENTER="show_category_item(".$newParts[0].");";
eval($_CENTER);
// ...
$_LEFT='get_main_category($cat_id, $new_path);';
$_CENTER="show_category_item_list($".'newParts'.");";
Вот с таким адом мне приходится работать.
+164
if($_POST['Selling_property_1']!=NULL):update_field('field_51db015800526', $_POST['Selling_property_1'], $_POST['pid']); endif;
if($_POST['Relocation_budget_1']!=NULL):update_field('field_51db018100527', $_POST['Relocation_budget_1'], $_POST['pid']); endif;
if($_POST['Selling_property_2']!=NULL):update_field('field_51db01ac00528', $_POST['Selling_property_2'], $_POST['pid']); endif;
if($_POST['School_1']!=NULL):update_field('field_51db01b900529', $_POST['School_1'], $_POST['pid']);endif;
if($_POST['homestyling_1']!=NULL):update_field('field_51db01c60052a', $_POST['homestyling_1'], $_POST['pid']);endif;
if($_POST['Telephony_1']!=NULL):update_field('field_51db02090052b', $_POST['Telephony_1'], $_POST['pid']);endif;
if($_POST['Broadband_1']!=NULL):update_field('field_51db02130052c', $_POST['Broadband_1'], $_POST['pid']);endif;
if($_POST['TV_1']!=NULL):update_field('field_51db021c0052d', $_POST['TV_1'], $_POST['pid']);endif;
if($_POST['Home_alarm_1']!=NULL):update_field('field_51db02280052e', $_POST['Home_alarm_1'], $_POST['pid']);endif;
if($_POST['Craftsmen_1']!=NULL):update_field('field_51db023a0052f', $_POST['Craftsmen_1'], $_POST['pid']);endif;
if($_POST['Home_decor_1']!=NULL):update_field('field_51db023e00530', $_POST['Home_decor_1'], $_POST['pid']);endif;
if($_POST['Bank_1']!=NULL):update_field('field_51db024900531', $_POST['Bank_1'], $_POST['pid']);endif;
if($_POST['Moving_cmp_1']!=NULL):update_field('field_51db025400532', $_POST['Moving_cmp_1'], $_POST['pid']);endif;
if($_POST['homestyling_2']!=NULL):update_field('field_51db025f00533', $_POST['homestyling_2'], $_POST['pid']);endif;
if($_POST['change_1']!=NULL):update_field('field_51db026900534', $_POST['change_1'], $_POST['pid']);endif;
if($_POST['moving_cmp_2']!=NULL):update_field('field_51db027200535', $_POST['moving_cmp_2'], $_POST['pid']);endif;
if($_POST['moving_truck_1']!=NULL):update_field('field_51db027e00536', $_POST['moving_truck_1'], $_POST['pid']);endif;
if($_POST['household_cleaning_1']!=NULL):update_field('field_51db028800537', $_POST['household_cleaning_1'], $_POST['pid']);endif;
if($_POST['insurance_1']!=NULL):update_field('field_51db029200538', $_POST['insurance_1'], $_POST['pid']);endif;
if($_POST['cleaning_1']!=NULL):update_field('field_51db029c00539', $_POST['cleaning_1'], $_POST['pid']);endif;
if($_POST['Home_alarm_1']!=NULL):update_field('field_51db02a70053a', $_POST['home_alarm_2'], $_POST['pid']);endif;
if($_POST['select_2']!=NULL):update_field('field_51db02b10053b', $_POST['select_2'], $_POST['pid']);endif;
if($_POST['insurance_2']!=NULL):update_field('field_51db02ca0053c', $_POST['insurance_2'], $_POST['pid']);endif;
if($_POST['school_2']!=NULL):update_field('field_51db02d40053d', $_POST['school_2'], $_POST['pid']);endif;
if($_POST['Telephony_2']!=NULL):update_field('field_51db02e10053e', $_POST['Telephony_2'], $_POST['pid']);endif;
if($_POST['Broadband_2']!=NULL):update_field('field_51db02e50053f', $_POST['Broadband_2'], $_POST['pid']);endif;
if($_POST['TV_2']!=NULL):update_field('field_51db02f100540', $_POST['TV_2'], $_POST['pid']);endif;
if($_POST['gasket_1']!=NULL):update_field('field_51db02fc00541', $_POST['gasket_1'], $_POST['pid']);endif;
if($_POST['electricity_2']!=NULL):update_field('field_51db030400542', $_POST['electricity_2'], $_POST['pid']);endif;
if($_POST['storage_1']!=NULL):update_field('field_51db031600543', $_POST['storage_1'], $_POST['pid']);endif;
if($_POST['electricity_1']!=NULL):update_field('field_51db031c00544', $_POST['electricity_1'], $_POST['pid']);endif;
if($_POST['change_2']!=NULL):update_field('field_51db032700545', $_POST['change_2'], $_POST['pid']);endif;
if($_POST['garbage_1']!=NULL):update_field('field_51db033100546', $_POST['garbage_1'], $_POST['pid']);endif;
if($_POST['garbage_2']!=NULL):update_field('field_51db033c00547', $_POST['garbage_2'], $_POST['pid']);endif;
if($_POST['gasket_2']!=NULL):update_field('field_51db034400548', $_POST['gasket_2'], $_POST['pid']);endif;
if($_POST['storage_2']!=NULL):update_field('field_51db034e00549', $_POST['storage_2'], $_POST['pid']);endif;
if($_POST['cleaning_2']!=NULL):update_field('field_51db03570054a', $_POST['cleaning_2'], $_POST['pid']);endif;
if($_POST['moving_truck_2']!=NULL):update_field('field_51db035f0054b', $_POST['moving_truck_2'], $_POST['pid']);endif;
if($_POST['inspection_1']!=NULL):update_field('field_51db03690054c', $_POST['inspection_1'], $_POST['pid']);endif;
if($_POST['craftsmen_2']!=NULL):update_field('field_51db03750054d', $_POST['craftsmen_2'], $_POST['pid']);endif;
if($_POST['household_cleaning_2']!=NULL):update_field('field_51db037e0054e', $_POST['household_cleaning_2'], $_POST['pid']);endif;
Обработка формы румынскими колегами.
+148
<?php
/* Почему статические методы — говно */
abstract class BaseNewsPeer {
…
/**
* Method to select one object from the DB.
*
* @param Criteria $criteria object used to create the SELECT statement.
* @param PropelPDO $con
* @return News
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
{
$critcopy = clone $criteria;
$critcopy->setLimit(1);
$objects = NewsPeer::doSelect($critcopy, $con);
if ($objects) {
return $objects[0];
}
return null;
}
…
class NewsPeer extends BaseNewsPeer
{
…
}
+153
<?php
sfConfig::set('show_counters', true);
/**
* Lite
*
* @category Symfony
* @package Plugins
* @subpackage liteSearchsite
* @author
* @since 12.11.2008
* @version $Id: actions.class.php 28664 2011-03-15 13:14:49Z ringtail $
*/
/**
* class liteSearchsiteActions. Функции для работы с поиском
*
* @category Symfony
* @package Plugins
* @subpackage liteSearchsite
* @author Tretyakov Ilya <[email protected]>
* @version $Id: actions.class.php 28664 2011-03-15 13:14:49Z ringtail $
*/
class liteSearchsiteActions extends sfActions
{
protected $searchsite;
protected $search_server = 'http://217.148.52.134:17000/';
/**
* конструктор
*
* @see sfComponent
*/
public function __construct($context, $moduleName, $actionName)
{
$this->searchsite = new liteSearchsite();
parent::__construct($context, $moduleName, $actionName);
}
/**
* Поиск. главная
*
* @param unknown_type $request
*/
public function executeIndex($request)
{
if ($request) {
$page = $request->getParameter('id');
$this->text = htmlspecialchars($request->getParameter('search_text'));
$reqid = $request->getParameter('reqid');
$page = $request->getParameter('p');
$numdoc = $request->getParameter('numdoc');
}
if (!$page) $page = 0;
if (!$this->searchsite->checkServer($this->search_server)) { throw new sfException('Ахтунг!'); }
if (!1) {
$this->search_work = 0;
} else
if ($this->searchsite->uploadXml($this->search_server, $this->text, $reqid, $page, $numdoc)) {
$this->pages_found = $this->searchsite->getCountItem();
$this->start_page = $this->searchsite->getStartPage();
$this->pages_found_word = $this->searchsite->getWordLinks();
$this->reqid = $this->searchsite->getRegId();
$this->pages = $this->searchsite->getPages();
$this->count_results = $this->searchsite->getDifPages();
if ($this->pages) {
$this->nextpagelink = $this->searchsite->getLinkNextPage();
$this->prepagelink = $this->searchsite->getLinkPrePage();
}
$this->search_work = 1;
if (!$this->pages_found) {
$this->no_result = 1;
$this->pages_found = 0;
} else {
$this->no_result = 0;
$this->list = $this->searchsite->getList($page);
//пересчитаем
//$this->pages_found = $this->searchsite->getCountItem();
//$this->searchsite->setCountPages();
//$this->pages_found_word = $this->searchsite->getWordLinks();
//$this->pages = $this->searchsite->getPages();
//$this->count_results = $this->searchsite->getDifPages();
if ($this->pages) {
$this->nextpagelink = $this->searchsite->getLinkNextPage();
$this->prepagelink = $this->searchsite->getLinkPrePage();
}
}
} else {
$this->search_work = 0;
}
}
+154
if (!empty($_GET[ret])) $_SESSION[ret] = $_GET[ret];
else if (!empty($_SESSION[ret])) $_GET[ret] = $_SESSION[ret];
Из разряда черной магии
+153
php_sapi_name() === 'cli' or exit('Only CLI mode allowed');
getenv('API_HOST') or exit(<<<EOT
To run tests you should setup "API_HOST" environment variable.
Try follow in bash command line:
$ export API_HOST=<api_host>
cd path/to/tests
php direct_report_problem.php
EOT
);
defined('API_ENDPOINT') || define('API_ENDPOINT', getenv('API_HOST') . '/webservice/index.php');
$method = API_ENDPOINT . '?op=...';
$describe = function ($msg, $test) {
printf("\n\n[%s]\n\n%s\n\n", $msg, shell_exec($test()));
sleep(2);
};
$describe('Cannot upload empty report', function() use ($method) {
return 'curl'
. ' -F user_id=61'
. ' ' . $method;
});
$describe('Can upload only direct report note', function() use ($method) {
return 'curl'
. ' -F user_id=61'
. ' -F problem_note=NOTE'
. ' ' . $method;
});
$describe('Can upload only direct report sound', function() use ($method) {
return 'curl'
. ' -F user_id=61'
. ' -F [email protected]'
. ' ' . $method;
});
$describe('Can upload only direct report image', function() use ($method) {
return 'curl'
. ' -F user_id=61'
. ' -F [email protected]'
. ' ' . $method;
});
$describe('Can upload all data direct report note, image, sound', function() use ($method) {
return 'curl'
. ' -F user_id=61'
. ' -F problem_note=NOTE'
. ' -F [email protected]'
. ' -F [email protected]'
. ' ' . $method;
});
+155
function lastDay($month, $year) {
if ($month != 12) {
$m = $month + 1;
$y = $year;
} else {
$m = 1;
$y = $year + 1;
}
return strftime("%d", mktime(0, 0, 0, $m, 0, $y));
}
Оригинальный и дофига понятный способ получить последний день текущего месяца.
+154
$date = date("Y-m-01", strtotime("-1 month"));
$like = substr($date, 0, 8) . "%";
а потом $like вставляется в sql-код