function xt_cron_autoshare() { global $wpdb; if (!IS_CLOUD) { set_time_limit(0); } $date = gmdate('Y-m-d H', current_time('timestamp')); $shares = $wpdb->get_results('SELECT * FROM ' . XT_TABLE_SHARE_CRON . ' WHERE create_date<=\'' . $date . '\' LIMIT 200'); $deleteKeys = array(); if (!empty($shares)) { foreach ($shares as $share) { $share_key = $share->share_key; $user_id = $share->user_id; $user_name = $share->user_name; $album_id = $share->album_id; $data = array(); if (!empty($share->cache_data)) { $data = maybe_unserialize($share->cache_data); if (!empty($data)) { if (xt_check_share($data['share_key'], $user_id)) { $deleteKeys[] = $share_key; continue; } } } if (empty($data)) { $fetch = array(); if (startsWith($share_key, 'tb')) { //taobao $fetch = xt_share_fetch('http://item.taobao.com/item.htm?id=' . str_replace('tb_', '', $share_key)); } elseif (startWith($share_key, 'pp')) { //paipai $fetch = xt_share_fetch('http://auction1.paipai.com/' . str_replace('pp_', '', $share_key)); } if (!empty($fetch)) { $data = array('share_key' => $fetch['share_key'], 'title' => $fetch['title'], 'pic_url' => $fetch['pic_url'], 'price' => $fetch['price'], 'cid' => $fetch['cid'], 'cache_data' => $fetch['cache_data'], 'content' => '', 'from_type' => $fetch['from_type']); } } if (!empty($data)) { xt_share_share(array('share_key' => $data['share_key'], 'title' => $data['title'], 'pic_url' => $data['pic_url'], 'price' => $data['price'], 'cid' => (int) $data['cid'], 'user_id' => (int) $user_id, 'user_name' => $user_name, 'cache_data' => $data['cache_data'], 'from_type' => $data['from_type'], 'data_type' => 1, 'content' => isset($data['content']) ? trim(strip_tags($data['content'])) : null, 'album_id' => (int) $album_id)); } $deleteKeys[] = $share_key; } if (!empty($deleteKeys)) { $_keys = array(); foreach ($deleteKeys as $deleteKey) { $_keys[] = "'{$deleteKey}'"; } $wpdb->query('DELETE FROM ' . XT_TABLE_SHARE_CRON . ' WHERE share_key in (' . implode(',', $_keys) . ')'); } xt_catalogs_share(true); //reload catalogs and tags do_action('xt_page_updated', 'home'); //clear home cache } }
/** * check need login urls return ture if need check else return false * check by SERVER REQUEST_URI * @return bool */ public function checkNeedLogin() { if (isset($_GET['returnurl']) && !empty($_GET['returnurl'])) { return true; } if ($_SERVER['REQUEST_URI'] == '/index.php/login/index') { return true; } elseif (startWith($_SERVER['REQUEST_URI'], '/index.php/login/index')) { return true; } $requestUri = $_SERVER['REQUEST_URI']; $urlArr = explode('?', $requestUri); $url = isset($urlArr[0]) ? $urlArr[0] : ''; $noNeedLoginUrls[] = '/features'; $noNeedLoginUrls[] = '/features/'; if (!in_array($url, $noNeedLoginUrls)) { return false; } return true; }
public function fromFile($src, $target_quality = 90) { $imageFileName = strtok(str_replace(appHomeUrl() . '/storage/app/tmp/', '', $src), '?'); if (startWith($imageFileName, self::getPrefix())) { $file = new File(storage_path('app/tmp/' . $imageFileName)); if ($file) { $this->targetFileAsset = asset('storage/app/tmp/' . $imageFileName); $this->imageType = $file->getMimeType(); $this->imageFilePath = $file->getRealPath(); switch (strtolower($this->imageType)) { case 'image/png': $this->imageFileExt = 'png'; $this->image = imagecreatefrompng($this->imageFilePath); break; case 'image/gif': $this->imageFileExt = 'gif'; $this->image = imagecreatefromgif($this->imageFilePath); break; case 'image/jpeg': case 'image/pjpeg': $this->imageFileExt = 'jpg'; $this->image = imagecreatefromjpeg($this->imageFilePath); break; default: $this->saveResult(['success' => false, 'message' => 'Image type was not supported']); return false; } $this->imageFileSize = $file->getSize(); $this->targetQuality = $target_quality; list($imageWidth, $imageHeight) = getimagesize($this->imageFilePath); $this->imageWidth = $imageWidth; $this->imageHeight = $imageHeight; $this->targetFileName = $imageFileName; $this->targetFilePath = $this->imageFilePath; return true; } } $this->saveResult(['success' => false, 'message' => 'Image was not existed']); return false; }
public function redirect($url, $httpCode = 302) { if (startWith($url, 'http://') || startWith($url, 'https://')) { } else { $url = url_to($url); } if ($httpCode == 301) { header('HTTP/1.1 301 Moved Permanently'); } header("Location: {$url}"); die; }
function url_to($_url, $_params = NULL, $_type = false) { $app = strtolower(hmvc\Web\Application::app()->router()->getAppName()); $basePath = hmvc\Web\Application::basePath(); if (is_array($_url)) { if (isset($_url[1])) { $app = $_url[1]; } $_url = $_url[0]; $basePath = hmvc\Web\Application::request()->baseUrl(); } if ($app == hmvc\Web\Application::app()->router()->getAppName() || hmvc\Web\Application::app()->router()->getAppName() == \hmvc\Web\Config::get('router.app')) { $app = ''; } else { //Route Alias $alias = hmvc\Web\Config::get('alias'); $aliasName = array_search($app, $alias); if ($aliasName) { $app = $aliasName; } else { // $app = strtolower(h\Web\Application::app()->router()->getAppName()); } $app = '/' . $app; } if (startWith($_url, '/')) { $_url = ltrim($_url, '/'); $app = ''; } if (hmvc\Web\Config::get("router.uri_protocol") == "PATH_INFO") { $_type = true; } //index.php $showscriptname = hmvc\Web\Config::get('router.showscriptname', 'index.php'); //Query String $querystring = ""; if (is_array($_params) && $_type == false) { if ($showscriptname) { $querystring = http_build_query($_params); return sprintf("%s/%s?r=%s/%s%s&%s", $basePath, $showscriptname, $app, $_url, hmvc\Web\Config::get('router.suffix'), $querystring); } else { $querystring = '?' . http_build_query($_params); } } else { if (is_array($_params) && $_type == true) { foreach ($_params as $key => $value) { $querystring .= '/' . $key . "/" . $value; } if ($showscriptname) { return sprintf("%s/%s%s/%s%s%s", $basePath, $showscriptname, $app, $_url, $querystring, hmvc\Web\Config::get('router.suffix')); } else { return sprintf("%s%s/%s%s%s", $basePath, $app, $_url, $querystring, hmvc\Web\Config::get('router.suffix')); } } else { if ($showscriptname && $_type == false) { $showscriptname = '/' . $showscriptname . '?r='; } else { if ($showscriptname && $_type == true) { $showscriptname = '/' . $showscriptname; } } return sprintf("%s%s%s/%s%s%s", $basePath, $showscriptname, $app, $_url, hmvc\Web\Config::get('router.suffix'), $querystring); } } return sprintf("%s%s/%s%s%s", $basePath, $app, $_url, hmvc\Web\Config::get('router.suffix'), $querystring); }
function getUserDepartments() { global $mysql; $level = $_SESSION["level"]; if (startWith($level, '004-')) { $res[0] = array("department" => "006-001"); } else { $groups = $mysql->DBGetAsOneArray("select DISTINCT `level` from `user` where `isDeleted` = 'false'"); for ($i = 0; $i < count($groups); $i++) { $tmp = explode("-", $groups[$i]); $groups[$i] = $tmp[0]; } $groups = array_merge(array_unique($groups)); $res = array(); for ($i = 0; $i < count($groups); $i++) { $res[$i] = array("department" => $groups[$i] . '-001'); } } return $res; }
/** * @param string $url * @param string $extraClass * @return \Katniss\Models\Helpers\MenuItem */ public function matchUrl($match_url, $extraClass = 'active', $strict = false) { if ($this->href != null) { if (!$strict) { if ($this->url == $match_url || notRootUrl($this->url) && startWith($match_url, $this->url)) { $this->class .= ' ' . $extraClass; } } else { if ($this->url == $match_url) { $this->class .= ' ' . $extraClass; } } } return $this; }
<?php header("Content-type: text/html; charset=utf-8"); $form_id = $_GET['form_id']; $id_whitelist = array('8PN3GF', 'd7vq7C', 'tEZB6h', 'YOYOW3', 'NEXYZU', 'ZnX2GA'); $postFields = ''; foreach ($_GET as $key => $value) { if (startWith($key, 'field')) { $postFields .= "{$key}={$value}&"; } } if (!in_array($form_id, $id_whitelist)) { echo '{"error":"表格ID错误", "code":"401"}'; exit; } if (!$postFields) { echo '{"error":"推送数据为空", "code":"402"}'; exit; } $postFields = substr($postFields, 0, strlen($postFields) - 1); $url = "https://jinshuju.net/api/v1/forms/{$form_id}"; //认证 $auth_name = "HU8iFVwTDkBKGU1BK42Mfw"; $auth_pass = "******"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_USERPWD, $auth_name . ':' . $auth_pass); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch);
if (defined("SAE_MYSQL_HOST_M")) { $val = mysql_real_escape_string($val); } else { $val = mysqli_real_escape_string($mysql->DBGetConnection(), $val); } $arg[$key] = $val; } } else { //$arg = str_replace("%","%25",$arg); //$arg = str_replace("+","%2B",$arg); if (defined("SAE_MYSQL_HOST_M")) { $arg = mysql_real_escape_string($arg); } else { $val = mysqli_real_escape_string($mysql->DBGetConnection(), $arg); } } return $arg; } function ga($data) { global $mysql; $fields = array("userName", "interfaceName"); $obj = array("userName" => $data["userName"], "interfaceName" => $data["interfaceName"]); $mysql->DBInsertAsArray("`user_behavior`", $obj); $res = array('status' => 'successful', 'errMsg' => $data["interfaceName"]); echo json_encode($res); } $APPBASE = $_SERVER['DOCUMENT_ROOT']; if (startWith($_SERVER['PHP_SELF'], '/fd/')) { $APPBASE = $APPBASE . '/fd'; }
function getDbUsers() { global $db; if (!$db) { return array(); } //$db = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error()); $sql = "SELECT User FROM mysql.user WHERE Select_priv='N'"; $res = mysql_query($sql); $users = array(); $me = getmyname(); while ($user = mysql_fetch_object($res)) { if (!isadmin() && !startWith($user->User, $me)) { continue; } $users[] = $user->User; } //mysql_close($db); return $users; }
function fetchall2table(array $fetchall, array $fields) { $get = function ($data, $property) { if (is_array($data) && isset($data[$property])) { return $data[$property]; } elseif (is_object($data) && isset($data->{$property})) { return $data->{$property}; } return null; }; $contents = "<table><tbody><tr>"; foreach ($fields as $field) { if (is_string($field)) { $libelle = $field; } elseif (is_array($field)) { $libelle = $field[1]; } if (startWith($libelle, '!_')) { $content .= "<th>" . substr($libelle, 2) . "</th>"; } else { $content .= "<th>" . htmlentities($libelle, ENT_COMPAT | ENT_HTML401, 'cp1252') . "</th>"; } } $content .= "</tr>"; foreach ($fetchall as $row) { $content .= "<tr>"; foreach ($fields as $field) { $content .= "<td>"; if (is_string($field)) { $libelle = $get($row, $field); } elseif (is_array($field)) { $libelle = $get($row, $field[0]); } $content .= htmlentities($libelle, ENT_COMPAT | ENT_HTML401, 'cp1252'); $content .= "</td>"; } $content .= "</tr>"; } $content .= "</tbody></table>"; return $contents; }
/** * @param $start * @return \Closure */ function notStartWith($start) { return negate(startWith($start)); }