本文整理汇总了PHP中common函数的典型用法代码示例。如果您正苦于以下问题:PHP common函数的具体用法?PHP common怎么用?PHP common使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了common函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _get_select_attributes
function _get_select_attributes($atts = [])
{
if (empty($atts)) {
return [];
}
// Group by attribute name
$_atts_by_name = [];
foreach ((array) $atts as $_info) {
$_atts_products_ids[$_info["name"]] = $_info["product_id"];
$_price_text = " (" . ($_info["price"] < 0 ? "-" : "+") . module("shop")->_format_price(abs($_info["price"])) . ")";
$_atts_by_name[$_info["name"]][$_info["value"]] = $_info["value"] . ($_info["price"] ? $_price_text : "");
}
$result = [];
foreach ((array) $_atts_by_name as $_name => $_info) {
$_product_id = $_atts_products_ids[$_name];
$_box = "";
$_box_name = "atts[" . intval($_product_id) . "][" . $_name . "]";
if (count($_info) > 1) {
$_box = common()->select_box($_box_name, $_info, $selected, false, 2, "", false);
} else {
$_box = current($_info) . "\n<input type=\"hidden\" name=\"" . $_box_name . "\" value=\"" . _prepare_html(current($_info)) . "\" />";
}
$result[$_name] = ["name" => _prepare_html($_name), "box" => $_box];
}
return $result;
}
示例2: _display_preview
/**
* Display preview method
*
* NOTE : parent_object & parent_action are used to determine
*/
function _display_preview($params = [], $template = "")
{
$replace = $params['replace'];
$PARENT_OBJECT = $_REQUEST["parent_object"];
$PARENT_ACTION = $_REQUEST["parent_action"];
// If no custom replace given, try to make own
if (empty($replace)) {
foreach ((array) $_POST as $k => $v) {
if (in_array($v, $this->skip_fields)) {
continue;
}
if ($k != 'category_id') {
$replace[$k] = $this->_format_text($v);
} else {
// Try to get category_id based on parent object
$categories = cache_get($PARENT_OBJECT . "_categories");
$replace['category_id'] = $categories[$v];
}
}
}
// Try to get template
if (false !== strpos($_POST['preview_form_action'], "add_comment")) {
$body = tpl()->parse("comments/preview", $replace);
} else {
$stpl_name = $PARENT_OBJECT . "/" . $PARENT_ACTION . "_preview";
$body = tpl()->_stpl_exists($stpl_name) ? tpl()->parse($stpl_name, $replace) : "";
}
// Default body
if (empty($body)) {
$body = tpl()->parse(__CLASS__ . "/default", $replace);
}
// Process template
$replace2 = ["template" => $body];
return common()->show_empty_page(tpl()->parse("preview/main", $replace2), ["title" => t("Preview")]);
}
示例3: pics_browser
function pics_browser()
{
if (isset($_GET['active']) && $_GET['active'] == 1) {
$active = ' AND p.active = \'1\' ';
} elseif (isset($_GET['active']) && $_GET['active'] == 0) {
$active = ' AND p.active = \'\' ';
} else {
$active = '';
}
if (main()->is_post()) {
foreach ($_POST['delete'] as $k => $v) {
list($id, $product_id) = explode("_", $k);
module('manage_shop')->_product_image_delete($id, $product_id);
}
}
$cats_list = _class('_shop_categories', 'modules/shop/')->recursive_get_child_ids(62521);
$sql = "SELECT `i`.`product_id`,`i`.`id` FROM `" . db('shop_products') . "` AS `p`, `" . db('shop_product_images') . "` AS `i` WHERE `p`.`id`=`i`.`product_id` AND `p`.`cat_id` IN ('" . implode("','", $cats_list) . "')" . $active;
list($add_sql, $pages, $total_records, $page_current, $pages_total, $pages_limited) = common()->divide_pages($sql);
$R = db()->query($sql . $add_sql);
$items = [];
while ($A = db()->fetch_assoc($R)) {
$_cls_products = _class('_shop_products', 'modules/shop/');
$image = $_cls_products->_product_image($A['product_id'], true);
$items[] = ['id' => $A['product_id'], 'image_id' => $A['id'], 'image' => $image['big']];
}
$replace = ['items' => $items, 'total' => $total_records, 'pages' => $pages];
$tpl_name = 'manage_shop/pics_browser';
return tpl()->parse($tpl_name, $replace);
}
示例4: _manufacturer_show
function _manufacturer_show()
{
// Prepare manufacturer
$replace = ["brand" => module("shop")->_manufacturer, "manufacturer_box" => common()->select_box("manufacturer", module("shop")->_man_for_select, $_SESSION['man_id'], false, 2), "url_manufacturer" => process_url("./?object=shop&action=products_show")];
unset($_SESSION["man_id"]);
return tpl()->parse("shop/manufacturer", $replace);
}
示例5: _track_error
/**
* Track user error message
*
* @param string
* @return void
*/
function _track_error($error_message = "")
{
if (empty($error_message)) {
return false;
}
// Try to get user error message source
$backtrace = debug_backtrace();
$cur_trace = $backtrace[1];
$next_trace = $backtrace[2];
// Prepare log text
$text = "## LOG STARTS AT " . date("Y-m-d H:i:s") . "; QUERY_STRING: " . $_SERVER["QUERY_STRING"] . "; REFERER: " . $_SERVER["HTTP_REFERER"] . "; USER_ID: " . main()->USER_ID . "; USER_GROUP: " . main()->USER_GROUP . "; SITE_ID: " . SITE_ID . "; USER_AGENT: " . $_SERVER["HTTP_USER_AGENT"] . " ##\r\n";
$text .= "URL: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\r\n";
$text .= "SOURCE FILE: \"" . $cur_trace["file"] . "\" at LINE " . $cur_trace["line"] . "; " . (!empty($next_trace["class"]) ? "METHOD: " . $next_trace["class"] . "->" . $next_trace["function"] : "FUNCTION: " . $next_trace["function"]) . ";\r\n";
$text .= "MESSAGE: " . $error_message . "\r\n";
$text .= "## LOG ENDS ##\r\n";
// Do add current error info to the log file
$h = fopen(INCLUDE_PATH . $this->LOG_USER_ERRORS_FILE_NAME, "a");
fwrite($h, $text);
fclose($h);
// Do store message into database (also check if that possible)
if ($this->LOG_INTO_DB && is_object(db())) {
$error_type = 0;
db()->insert_safe('log_user_errors', ['error_level' => intval($error_type), 'error_text' => $error_message, 'source_file' => $cur_trace['file'], 'source_line' => intval($cur_trace['line']), 'date' => time(), 'site_id' => (int) conf('SITE_ID'), 'user_id' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_id' : 'user_id']), 'user_group' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_group' : 'user_group']), 'is_admin' => MAIN_TYPE_ADMIN ? 1 : 0, 'ip' => common()->get_ip(), 'query_string' => WEB_PATH . '?' . $_SERVER['QUERY_STRING'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referer' => $_SERVER['HTTP_REFERER'], 'request_uri' => $_SERVER['REQUEST_URI'], 'env_data' => $this->DB_LOG_ENV ? $this->_prepare_env() : '', 'object' => $_GET['object'], 'action' => $_GET['action']]);
}
}
示例6: add
/**
*/
function add()
{
return form($a)->validate(['name' => 'trim|required'])->db_insert_if_ok(self::table, ['name', 'web_path', 'real_path'], [])->on_after_update(function () {
cache_del([self::table]);
common()->admin_wall_add(['site added: ' . $_POST['name'] . '', db()->insert_id()]);
})->text('name')->text('web_path')->text('real_path')->active_box()->save_and_back();
}
示例7: get_user_info
/**
*/
function get_user_info()
{
$access_token = $this->_storage_get('access_token');
if (!$access_token) {
$access_token = $this->get_access_token();
if (!$access_token) {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
}
}
if (!$this->_storage_get('user')) {
$url = $this->url_user . '?' . http_build_query(['access_token' => $access_token]);
$result = common()->get_remote_page($url, $cache = false, $opts, $response);
$result = $this->_decode_result($result, $response, __FUNCTION__);
if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
} else {
$this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]);
$user = $result;
// Emails
$url_emails = $this->url_user_emails . '?' . http_build_query(['access_token' => $access_token]);
$result = common()->get_remote_page($url_emails, $cache = false, $opts = [], $response);
$result = $this->_decode_result($result, $response, __FUNCTION__);
$user['emails'] = $result;
$this->_storage_set('user', $user);
}
}
return $this->_storage_get('user');
}
示例8: get_user_info
/**
*/
function get_user_info()
{
$access_token = $this->_storage_get('access_token');
if (!$access_token) {
$access_token = $this->get_access_token();
if (!$access_token) {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
}
}
if (!$this->_storage_get('user')) {
$url = $this->url_user . '?' . http_build_query(['oauth2_access_token' => $access_token]);
$opts['custom_header'][] = 'x-li-format: json';
$result = common()->get_remote_page($url, $cache = false, $opts, $response);
$result = $this->_decode_result($result, $response, __FUNCTION__);
if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
} else {
$this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]);
$this->_storage_set('user', $result);
}
}
return $this->_storage_get('user');
}
示例9: test
function test()
{
$time_start = microtime(true);
require_once YF_PATH . 'libs/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = module('test')->SMTP_OPTIONS['smtp_host'];
$mail->SMTPAuth = true;
$mail->Username = module('test')->SMTP_OPTIONS['smtp_user_name'];
$mail->Password = module('test')->SMTP_OPTIONS['smtp_password'];
if (module('test')->SMTP_OPTIONS['smtp_secure']) {
$mail->SMTPSecure = module('test')->SMTP_OPTIONS['smtp_secure'];
}
$mail->From = module('test')->TEST_MAIL['email_from'];
if (module('test')->TEST_MAIL['name_from']) {
$mail->FromName = module('test')->TEST_MAIL['name_from'];
}
$mail->AddAddress(module('test')->TEST_MAIL['email_to'], module('test')->TEST_MAIL['name_to']);
$mail->IsHTML(true);
$mail->Subject = module('test')->TEST_MAIL['subject'];
$mail->Body = module('test')->TEST_MAIL['html'];
$mail->AltBody = module('test')->TEST_MAIL['text'];
$result = $mail->Send();
$error_message .= $mail->ErrorInfo;
$body .= $result ? '<b style="color:green;">Send successful</b>' : '<b style="color:red;">Send failed</b>';
$body .= !$result ? '<br /><b>Reason:</b><br /> ' . $error_message . implode('<br />\\n', (array) main()->_all_core_error_msgs) . '<br />' : '';
$body .= '<br />Spent time: ' . common()->_format_time_value(microtime(true) - $time_start) . ' sec.<br />';
return $body;
}
示例10: get_user_info
/**
*/
function get_user_info()
{
$access_token = $this->_storage_get('access_token');
if (!$access_token) {
$access_token = $this->get_access_token();
if (!$access_token) {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
}
}
if (!$this->_storage_get('user')) {
$method = 'users.getInfo';
$sign = md5('app_id=' . $this->client_id . 'method=' . $method . 'secure=1' . 'session_key=' . $access_token . $this->client_public);
$url = $this->url_user . '?' . http_build_query(['session_key' => $access_token, 'secure' => 1, 'app_id' => $this->client_id, 'method' => $method, 'sig' => $sign]);
$result = common()->get_remote_page($url, $cache = false, $opts, $response);
$result = $this->_decode_result($result, $response, __FUNCTION__);
if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
} else {
$this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]);
$this->_storage_set('user', $result);
}
}
return $this->_storage_get('user');
}
示例11: _order_validate_delivery
/**
* Order validation
*/
function _order_validate_delivery()
{
$_POST['exp_date'] = $_POST['exp_date_mm'] . $_POST['exp_date_yy'];
$force_ship_type = module('shop')->FORCE_GROUP_SHIP[module('shop')->USER_GROUP];
if ($force_ship_type) {
$_POST["ship_type"] = $force_ship_type;
}
if (!strlen($_POST["ship_type"]) || !isset(module('shop')->_ship_types[$_POST["ship_type"]])) {
_re("Shipping type required");
}
foreach ((array) module('shop')->_b_fields as $_field) {
if (!strlen($_POST[$_field]) && in_array($_field, module('shop')->_required_fields)) {
_re(t(str_replace("b_", "Billing ", $_field)) . " " . t("is required"));
}
}
if ($_POST["email"] != "" && !common()->email_verify($_POST["email"])) {
_re("email not valid.");
}
/* foreach ((array)module('shop')->_s_fields as $_field) {
if (!strlen($_POST[$_field]) && in_array($_field, module('shop')->_required_fields)) {
_re(t(str_replace("s_", "Shipping ", $_field))." ".t("is required"));
}
}
if (!common()->email_verify($_POST["s_email"])) {
_re("Shipping email not valid.");
} */
}
示例12: _order_step_do_payment
/**
* Order step
*/
function _order_step_do_payment($FORCE_DISPLAY_FORM = false)
{
$basket_contents = module('shop')->_basket_api()->get_all();
if (module('shop')->FORCE_PAY_METHOD) {
$_POST["pay_type"] = module('shop')->FORCE_PAY_METHOD;
}
// Show previous form if needed
if (common()->_error_exists() || empty($_POST)) {
return module('shop')->_order_step_select_payment();
}
$ORDER_ID = intval($_POST["order_id"] ? $_POST["order_id"] : module('shop')->_CUR_ORDER_ID);
if (empty($ORDER_ID)) {
_re("Missing order ID");
}
// Get order info
$order_info = db()->query_fetch("SELECT * FROM " . db('shop_orders') . " WHERE id=" . intval($ORDER_ID) . " AND user_id=" . intval(main()->USER_ID) . " AND status='pending'");
if (empty($order_info["id"])) {
_re("Missing order record");
}
// Payment by courier, skip next step
if (!common()->_error_exists() && $_POST["pay_type"] == 1 or $_POST["pay_type"] == 3 or $_POST["pay_type"] == 4) {
module('shop')->_basket_api()->clean();
return js_redirect("./?object=shop&action=" . $_GET["action"] . "&id=finish&page=" . intval($ORDER_ID));
}
// Authorize.net payment type
if ($_POST["pay_type"] == 2) {
module('shop')->_basket_api()->clean();
return module('shop')->_order_pay_authorize_net($order_info);
}
}
示例13: _order_step_delivery
/**
* Order step
*/
function _order_step_delivery($FORCE_DISPLAY_FORM = false)
{
// Validate previous form
if (main()->is_post() && !$FORCE_DISPLAY_FORM) {
module('shop')->_order_validate_delivery();
// Display next form if we have no errors
if (!common()->_error_exists()) {
return module('shop')->_order_step_select_payment(true);
}
}
if (main()->USER_ID) {
$order_info = module('shop')->_user_info;
}
// Fill fields
foreach ((array) module('shop')->_b_fields as $_field) {
$replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[substr($_field, 2)]);
}
// Fill shipping from billing
foreach ((array) module('shop')->_s_fields as $_field) {
if (module('shop')->_user_info["shipping_same"] && !isset($_POST[$_field])) {
$s_field = "b_" . substr($_field, 2);
$replace[$_field] = _prepare_html(isset($_POST[$s_field]) ? $_POST[$s_field] : module('shop')->_user_info[$s_field]);
} else {
$replace[$_field] = _prepare_html(isset($_POST[$_field]) ? $_POST[$_field] : module('shop')->_user_info[$_field]);
}
}
$force_ship_type = module('shop')->FORCE_GROUP_SHIP[module('shop')->USER_GROUP];
$SELF_METHOD_ID = substr(__FUNCTION__, strlen("_order_step_"));
$replace = my_array_merge((array) $replace, ["form_action" => "./?object=shop&action=" . $_GET["action"] . "&id=" . $SELF_METHOD_ID, "error_message" => _e(), "ship_type_box" => module('shop')->_box("ship_type", $force_ship_type ? $force_ship_type : $_POST["ship_type"]), "back_link" => "./?object=shop&action=order", "cats_block" => module('shop')->_categories_show()]);
return tpl()->parse("shop/order_delivery", $replace);
}
示例14: coupon_edit
/**
*/
function coupon_edit()
{
$_GET['id'] = intval($_GET['id']);
if (empty($_GET['id'])) {
return _e('Empty ID!');
}
$coupon_info = db()->query_fetch('SELECT * FROM ' . db('shop_coupons') . ' WHERE id=' . $_GET['id']);
if (main()->is_post()) {
if (!$_POST['code']) {
_re('Code must be entered');
} else {
$_POST['code'] = $this->_cleanup_code($_POST['code']);
$cnt = db()->get_one("SELECT COUNT(`id`) AS `cnt` FROM `" . db('shop_coupons') . "` WHERE `code`='" . $_POST['code'] . "' AND `id`!=" . $_GET['id']);
if ($cnt != 0) {
_re('Code already exists');
}
}
if (!common()->_error_exists()) {
$sql_array = ['code' => $this->_cleanup_code($_POST['code']), 'user_id' => intval($_POST['user_id']), 'sum' => intval($_POST['sum']), 'status' => intval($_POST['status']), 'cat_id' => intval($_POST['cat_id']), 'order_id' => intval($_POST['order_id']), 'time_start' => strtotime($_POST['time_start']), 'time_end' => strtotime($_POST['time_end'])];
db()->update('shop_coupons', db()->es($sql_array), 'id=' . $_GET['id']);
common()->admin_wall_add(['shop coupon updated: ' . $this->_cleanup_code($_POST['code']), $_GET['id']]);
return js_redirect('./?object=' . main()->_get('object') . '&action=coupons');
}
}
$replace = ['code' => $coupon_info['code'], 'user_id' => $coupon_info['user_id'], 'sum' => $coupon_info['sum'], 'status' => $coupon_info['status'], 'cat_id' => $coupon_info['cat_id'], 'order_id' => $coupon_info['order_id'], 'time_start' => date('d.m.Y I:s', $coupon_info['time_start']), 'time_end' => date('d.m.Y I:s', $coupon_info['time_end']), 'form_action' => './?object=' . main()->_get('object') . '&action=coupon_edit&id=' . $coupon_info['id'], 'back_url' => './?object=' . main()->_get('object') . '&action=coupons'];
return form($replace)->text('code')->integer('user_id')->integer('sum')->select_box('status', $this->_statuses)->select_box('cat_id', module('manage_shop')->_cats_for_select, ['desc' => 'Main category', 'edit_link' => './?object=category_editor&action=show_items&id=shop_cats', 'translate' => 0])->integer('order_id')->datetime_select('time_start', null, ['with_time' => 1])->datetime_select('time_end', null, ['with_time' => 1])->save_and_back();
}
示例15: get_user_info
/**
*/
function get_user_info()
{
$access_token = $this->_storage_get('access_token');
if (!$access_token) {
$access_token = $this->get_access_token();
if (!$access_token) {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
}
}
if (!$this->_storage_get('user')) {
$access_token_request = $this->_storage_get('access_token_request');
$user_id = $access_token_request['result']['user_id'];
$url = $this->url_user . '?' . http_build_query($this->url_params + ['access_token' => $access_token, 'user_id' => $user_id]);
$result = common()->get_remote_page($url, $cache = false, $opts, $response);
$result = $this->_decode_result($result, $response);
if (isset($result['error']) || substr($response['http_code'], 0, 1) == '4') {
$this->_storage_clean();
js_redirect($this->redirect_uri, $url_rewrite = false);
return false;
} else {
$this->_storage_set('user_info_request', ['result' => $result, 'response' => $response]);
$this->_storage_set('user', $result);
}
}
return $this->_storage_get('user');
}