/** * Метод редактирования уже существующего уведомления. Метод содержит все переменные, что и для создания уведомления, * но здесь некоторые параметры могут не указываться. Если ни один параметр не будет указан, то изменений в базу * внесено не будет * * @param int|array(int) $id идентификатор уведомления, может быть как числом, так и массивом чисел, в этом случае * изменятся все указанные уведомления * @param null|sting $msg * @param null|bool $confirm * @param null|string $start * @param null|string $end * * @return bool */ static function redactNotice($id, $msg = null, $confirm = null, $start = null, $end = null) { if (is_array($id)) { $id = array_map(function ($var) { return intval($var); }, $id); $id = implode(',', $id); } else { $id = intval($id); } $args = array(); if ($msg) { $args[] = '`msg` = \'' . MySQLi::checkString($msg) . '\''; } if ($start) { $args[] = '`startDate` = \'' . MySQLi::checkString($start) . '\''; } if ($end) { $args[] = '`stopDate` = \'' . MySQLi::checkString($end) . '\''; } if ($confirm) { $args[] = '`confirm` = \'' . intval($confirm) . '\''; } if ($args) { return MySQLi::query('UPDATE `' . Settings::$DB_PREFIX . '_notice` SET ' . implode(',', $args) . ' WHERE `id` IN (' . $id . ')'); } }
function wikipediaParse() { $result = MySQLi::query('SELECT * FROM `addr_countries`'); while ($row = $result->fetch_assoc()) { echo $row['name'] . '<br>'; $page = file_get_contents('https://ru.wikipedia.org/wiki/' . $row['name']); if ($page === false) { continue; } preg_match_all('/<img(?:\\s[^<>]*?)?\\bsrc\\s*=\\s*(?|"([^"]*)"|\'([^\']*)\'|([^<>\'"\\s]*))[^<>]*>/i', $page, $allTags); $i = 0; foreach ($allTags[0] as $val) { if (!empty($val) && strpos($val, 'Flag of')) { $begin = strpos($val, 'src="') + 5; $end = strpos($val, 'png"') + 3; $url = 'https:' . substr($val, $begin, $end - $begin); $img = './img/countriesFlags/' . $row['id'] . '.png'; file_put_contents($img, file_get_contents($url)); $i++; } else { if (!empty($val) && strpos($val, 'Coat of')) { $begin = strpos($val, 'src="') + 5; $end = strpos($val, 'png"') + 3; $url = 'https:' . substr($val, $begin, $end - $begin); $img = './img/countriesCoats/' . $row['id'] . '.png'; file_put_contents($img, file_get_contents($url)); $i++; } } if ($i == 2) { break; } } preg_match('/<td>[A-Z]{2}<\\/td>/', $page, $tmp); $iso = substr($tmp[0], 4, 2); preg_match('/<td>[A-Z]{3}<\\/td>/', $page, $tmp); $mok = substr($tmp[0], 4, 3); preg_match('/\\+[0-9]{1,5}</', $page, $tmp); $phone = substr($tmp[0], 1, strpos($tmp[0], '<') - 1); if (!$phone) { $phone = 0; } MySQLi::query('UPDATE `addr_countries` SET `iso` = \'' . MySQLi::checkString($iso) . '\', `mok` = \'' . MySQLi::checkString($mok) . '\', `flag` = \'' . $row['id'] . '.png\', `emplem` = \'' . $row['id'] . '.png\', `phone` = ' . $phone . ' WHERE `name` = \'' . MySQLi::checkString($row['name']) . '\''); } }
static function parseURI($word) { $result = MySQLi::query('SELECT A.`uri`, B.`' . Controller::$lang . '` AS `alias` FROM `engine_uri_mask` A, `engine_lang` B WHERE A.`alias` = B.`id` AND B.`' . Controller::$lang . '` LIKE \'' . MySQLi::checkString($word) . '\''); if ($result->num_rows == 0) { throw new Exception('Ошибка парсинга'); } return $result->fetch_assoc()['uri']; }
/** * Метод редактирования существующей записи. * Если параметры не указаны, то обновление не будет выполнено. * * @param int $id идентификатор записи в базе * @param null|string|int $theme номер или название темы * @param null|string $title заголовок * @param null|string $msg тело * @param null|string $date дата */ static function redactNews($id, $theme = null, $title = null, $msg = null, $date = null) { $arg = array(); if ($title) { $arg[] = '`title` = \'' . MySQLi::checkString($title) . '\''; } if ($msg) { $arg[] = '`msg` = \'' . MySQLi::checkString($msg) . '\''; } if ($date) { $arg[] = '`date` = \'' . MySQLi::checkString($date) . '\''; } if ($theme) { $arg[] = '`themeId` = ' . (is_numeric($theme) ? intval($theme) : '(SELECT `id` FROM `news_themes` WHERE `name` = \'' . MySQLi::checkString($theme) . '\')'); } if ($arg) { MySQLi::query('UPDATE `' . Settings::$DB_PREFIX . '_news` SET ' . implode(',', $arg) . ' WHERE `id` = ' . intval($id)); } }
static function parseURI($uri) { $uri = substr($uri, 1); $result = MySQLi::query('SELECT B.`published`, A.`link`, A.`groupId` FROM `' . self::menuItemsTableName() . '` A, `' . self::menuTableName() . '` B WHERE A.`menuId` = B.`id` AND A.`alias` LIKE \'' . MySQLi::checkString($uri) . '\''); $result = $result->fetch_assoc(); // if(!$result || !$result['published'] || $result['groupId'] != 0) // throw new Exception('permission denied'); return $result['link']; }