function upsert($collect, $doc) { global $db; $doc['_id'] = $id = $doc['id']; unset($doc['id']); $doc['fbbk_updated_time'] = date(DATE_ISO8601); $db->selectCollection($collect)->update(array('_id' => $id), array_remove_empty($doc), array('upsert' => true)); return $id; }
function array_remove_empty($array) { foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = array_remove_empty($array[$key]); } if (empty($array[$key])) { unset($array[$key]); } } return $array; }
function array_remove_empty($haystack) { foreach ($haystack as $key => $value) { if (is_array($value)) { $haystack[$key] = array_remove_empty($haystack[$key]); } if (empty($haystack[$key])) { unset($haystack[$key]); } } return $haystack; }
function array_remove_empty(&$arr, $trim = true) { foreach ($arr as $key => $value) { if (is_array($value)) { array_remove_empty($arr[$key]); } else { $value = trim($value); if ($value == '') { unset($arr[$key]); } elseif ($trim) { $arr[$key] = $value; } } } }
public static function process() { $q = array_key_exists('q', $_GET) ? $_GET['q'] : ""; $url_parts = explode("/", rtrim($q, "/") . "/"); ksort(self::$map); foreach (self::$map as $weight => $arr) { foreach ($arr as $url => $callback) { if ($url == "*") { call_user_func($callback, $q); return; } $parts = array_remove_empty(explode("/", ltrim($url, "/"))); preg_match_all("#:([a-zA-Z_]+)#", $url, $matches); $expecting = count($matches[1]); // if there is a blank at the end it will be one longer if (count($url_parts) == count($parts) || count($url_parts) - 1 == count($parts)) { foreach ($parts as $k => $v) { if ($v == "*") { $ret_vals[] = implode("/", array_slice($url_parts, $k)); } elseif (substr($v, 0, 1) == ":") { $ret_vals[substr($v, 1)] = $url_parts[$k]; } elseif ($url_parts[$k] == $v) { continue; } else { break; } } if (count($ret_vals) == $expecting) { call_user_func($callback, $ret_vals); return; } } else { continue; } } } }
public function __construct() { $this->_module_info['path'] = './app/modules/' . basename(__FILE__); $sql = new SQLObject(); session_start(); if (!isset($_SESSION['logged'])) { if (isset($_COOKIE['AUTHKEY'])) { if ($sql->query("SELECT user_id AS id,user_username AS username,user_password_hash AS password_hash,user_email AS email,user_groups AS groups FROM " . $sql->table('auth_users') . " WHERE (AUTHKEY = '" . $_COOKIE['AUTHKEY'] . "')") && $sql->num_rows()) { $user = $sql->fetch_one(); $_SESSION['logged'] = true; $_SESSION['user']['id'] = (int) $user->id; $_SESSION['user']['username'] = (string) $user->username; $_SESSION['user']['email'] = (string) $user->email; $_SESSION['groups'] = array_remove_empty(explode(';', $user->groups)); $this->setLoginTime(); } else { $this->logout(); } } else { $this->logout(); } } if ($_SESSION['logged']) { TPL::add(array('CURRENT_USER.ID' => $_SESSION['user']['id'], 'CURRENT_USER.USERNAME' => $_SESSION['user']['username'], 'CURRENT_USER.EMAIL' => $_SESSION['user']['email'])); TPL::cond('LOGGED', true); if ($sql->query("SELECT user_groups FROM " . $sql->table('auth_users') . " WHERE (user_id = " . $_SESSION['user']['id'] . ")") && $sql->num_rows()) { $user = $sql->fetch_one(); $_SESSION['groups'] = array_remove_empty(explode(';', $user->user_groups)); } } else { TPL::cond('LOGGED', false); } $this->setAuthkey(); $this->saveSessionTime(); $this->loadPermissions(); }
function modify() { if (jget('settingsubmit')) { $limit = jget('limit', 'int'); if ($limit < 1) { $limit = 15; } $time = jget('time', 'int'); if ($time < 1) { $time = 15; } $white_list = jget('white_list'); if ($white_list) { $white_list = explode("\n", $white_list); foreach ($white_list as $k => $v) { $white_list[$k] = trim($v); } $white_list = array_remove_empty(array_unique($white_list)); } $failedlogins = array('limit' => $limit, 'time' => $time, 'white_list' => $white_list); jconf::set('failedlogins', $failedlogins); } $this->Messager('设置成功', 'admin.php?mod=failedlogins&code=index'); }
function approveAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); debugMessage($formvalues); // exit; if (!isArrayKeyAnEmptyString('id', $formvalues)) { if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet = new Timesheet(); $timesheet->populate(decode($formvalues['id'])); $timesheet->setStatus($formvalues['status']); if (!isEmptyString($timesheet->getDateIn()) && !isEmptyString($timesheet->getDateOut())) { $timesheet->setHours($timesheet->getComputedHours()); } $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); if (!isArrayKeyAnEmptyString('reason', $formvalues)) { $timesheet->setComments("<br/>Rejected with remarks: " . $formvalues['reason']); } // debugMessage($timesheet->toArray()); try { if ($timesheet->save()) { $session->setVar(SUCCESS_MESSAGE, "Successfully Approved"); } $timesheet->afterApprove(); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } // exit; if (!isArrayKeyAnEmptyString('ids', $formvalues)) { $idsarray = array_remove_empty(explode(',', $formvalues['ids'])); // debugMessage($idsarray); if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet_collection = new Doctrine_Collection(Doctrine_Core::getTable("Timesheet")); if (count($idsarray) > 0) { $hrs = 0; foreach ($idsarray as $key => $id) { $timesheet = new Timesheet(); $timesheet->populate($id); $timesheet->setStatus($formvalues['status']); $timesheet->setHours($timesheet->getComputedHours()); // debugMessage($timesheet->getComputedHours()); $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); $timesheet_collection->add($timesheet); // debugMessage($timesheet->toArray()); } try { if ($timesheet_collection->save()) { $msg = "Successfully Approved"; if ($formvalues['status'] == 4) { $msg = "Successfully Rejected"; } $session->setVar(SUCCESS_MESSAGE, $msg); foreach ($timesheet_collection as $timesheet) { $timesheet->afterApprove(); } } } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } } $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); }
function posts_manage_do_search() { if ($_POST['categories']) { $togo_categories = "/categories:{$_POST['categories']}"; } else { $togo_categories = false; } if ($_POST['tags']) { $tags = explode(',', $_POST['tags']); $tags = trimArray($tags); $tags = array_unique_FULL($tags); asort($tags); $tags = array_remove_empty($tags); $tags = implode(',', $tags); $togo_tags = "/tags:{$tags}"; } else { $togo_tags = false; } $val = implode(',', $_POST['categories']); //setcookie ( "admin_content_posts_manage_selected_categories", $val, time () + 36000 ); $val = implode(',', $_POST['tags']); //setcookie ( "admin_content_posts_manage_selected_tags", $val, time () + 36000 ); $gogo = site_url('admin/content/posts_manage') . $togo_categories . $togo_tags; $gogo = reduce_double_slashes($gogo); header("Location: {$gogo} "); //var_dump ( $gogo ); exit; }
function web_invoice_fix_billing_meta_array($arr) { $narr = array(); $counter = 1; while (list($key, $val) = each($arr)) { if (is_array($val)) { $val = array_remove_empty($val); if (count($val) != 0) { $narr[$counter] = $val; $counter++; } } else { if (trim($val) != "") { $narr[$counter] = $val; $counter++; } } } unset($arr); return $narr; }
function woothemes_content_builder_array_remove_empty($arr) { $narr = array(); while (list($key, $val) = each($arr)) { if (is_array($val)) { $val = array_remove_empty($val); // does the result array contain anything? if (count($val) != 0) { // yes :-) $narr[$key] = $val; } } else { if (trim($val) != "") { $narr[$key] = $val; } } } unset($arr); return $narr; }
function DoModifyNormal() { if ('11111111' == $this->Post['config']['iphone_passphrase']) { $this->Post['config']['iphone_passphrase'] = $this->Config['iphone_passphrase']; } if (!($this->Post['config']['iphone_push_enable'] > 0 && $this->Post['config']['iphone_download_url'] && $this->Post['config']['iphone_passphrase'] && $this->Post['config']['iphone_pem_file'] && $this->_check_ipone_file($this->Post['config']['iphone_pem_file']) && is_file(ROOT_PATH . $this->Post['config']['iphone_pem_file']) && function_exists("openssl_open") && $this->_check_iphone_join($this->Post['config']['iphone_pem_file'], $this->Post['config']['iphone_passphrase']))) { $this->Post['config']['iphone_push_enable'] = 0; } if (isset($this->Post['config']['nickname_length'])) { $this->Post['config']['nickname_length'] = (int) $this->Post['config']['nickname_length']; if ($this->Config['ucenter_enable']) { $this->Post['config']['nickname_length'] = $this->Post['config']['nickname_length'] > 15 ? 15 : $this->Post['config']['nickname_length']; } elseif ($this->Post['config']['nickname_length'] > 50) { $this->Post['config']['nickname_length'] = 50; } } if (isset($this->Post['config']['website_home_page'])) { $website_home_page = explode('|', $this->Post['config']['website_home_page']); $this->Post['config']['default_module'] = $website_home_page[0]; $this->Post['config']['default_code'] = $website_home_page[1] ? $website_home_page[1] : $website_home_page[0]; unset($this->Post['config']['website_home_page']); } if (isset($this->Post['user_forbid'])) { if ($this->Post['user_forbid']) { $forbid_list = explode("\r\n", $this->Post['user_forbid']); $forbid_list = array_unique($forbid_list); $forbid = implode("\r\n", $forbid_list); jconf::set('user', array('forbid' => $forbid)); } unset($this->Post['user_forbid']); $this->Post['config']['regstatus'] = isset($this->Post['config']['regstatus']) ? $this->Post['config']['regstatus'] : array(); $this->Post['config']['third_party_regstatus'] = isset($this->Post['config']['third_party_regstatus']) ? $this->Post['config']['third_party_regstatus'] : array(); } isset($this->Post['config']['regiter_tuijian']) && ($this->Post['config']['regiter_tuijian'] = $this->Post['config']['regiter_tuijian'] ? $this->Post['config']['regiter_tuijian'] : array()); if (isset($this->Post['config']['watermark_contents_size'])) { $this->Post['config']['watermark_contents'] = isset($this->Post['config']['watermark_contents']) ? $this->Post['config']['watermark_contents'] : array(); } if (isset($this->Post['email_white_list'])) { if ($this->Post['email_white_list']) { $email_white_list = explode("\r\n", $this->Post['email_white_list']); $email_white_list = array_remove_empty(array_unique($email_white_list)); jconf::set('email_white_list', $email_white_list); } else { jconf::set('email_white_list', ''); } unset($this->Post['email_white_list']); } if (isset($this->Post['register']['ip'])) { $register = jconf::get('register'); $register['ip']['time_val'] = max(0, (int) $this->Post['register']['ip']['time_val']); $register['ip']['time_unit'] = $this->Post['register']['ip']['time_unit']; $register['ip']['limit'] = max(0, (int) $this->Post['register']['ip']['limit']); $time_unit_config = jconf::get('time_unit'); $register['ip']['time'] = (int) ($register['ip']['time_val'] * $time_unit_config[$register['ip']['time_unit']]['unit']); $register['ip']['time_html'] = $register['ip']['time_val'] . $time_unit_config[$register['ip']['time_unit']]['name']; $ip_white_list = ''; if ($this->Post['register']['ip']['white_list']) { $ip_white_list = explode("\n", $this->Post['register']['ip']['white_list']); foreach ($ip_white_list as $k => $v) { $ip_white_list[$k] = trim($v); } $ip_white_list = array_remove_empty(array_unique($ip_white_list)); } $register['ip']['white_list'] = $ip_white_list; jconf::set('register', $register); $this->Post['config']['register_check_ip_enable'] = $register['ip']['time'] > 0 && $register['ip']['limit'] > 0 ? 1 : 0; unset($this->Post['register']['ip']); } if (isset($this->Post['config']['site_name']) && empty($this->Post['config']['site_name'])) { $this->Messager("修改出现错误,站点名称不能为空"); } if (isset($this->Post['config']['normal_default_role_id']) && empty($this->Post['config']['normal_default_role_id'])) { $this->Messager("修改出现错误,请先选择一个角色"); } if (isset($this->Post['config']['thumbwidth'])) { $this->Post['config']['thumbwidth'] = min(300, max(30, (int) $this->Post['config']['thumbwidth'])); } if (isset($this->Post['config']['thumbheight'])) { $this->Post['config']['thumbheight'] = min(300, max(30, (int) $this->Post['config']['thumbheight'])); } if (isset($this->Post['config']['watermark_position'])) { $this->Post['config']['watermark_position'] = (int) $this->Post['config']['watermark_position']; } if (isset($this->Post['config']['image_size'])) { $this->Post['config']['image_size'] = max(10, min(51200, (int) $this->Post['config']['image_size'])); $this->Post['config']['image_size_limit'] = $this->Post['config']['image_size'] * 1024; } if (isset($this->Post['seccode_setting'])) { $this->Post['config']['seccode_login'] = $this->Post['config']['seccode_login'] ? 1 : 0; $this->Post['config']['seccode_register'] = $this->Post['config']['seccode_register'] ? 1 : 0; $this->Post['config']['seccode_password'] = $this->Post['config']['seccode_password'] ? 1 : 0; $this->Post['config']['seccode_publish'] = $this->Post['config']['seccode_publish'] ? 1 : 0; $this->Post['config']['seccode_comment'] = $this->Post['config']['seccode_comment'] ? 1 : 0; $this->Post['config']['seccode_forward'] = $this->Post['config']['seccode_forward'] ? 1 : 0; $this->Post['config']['seccode_sms'] = $this->Post['config']['seccode_sms'] ? 1 : 0; $this->Post['config']['seccode_no_email'] = $this->Post['config']['seccode_no_email'] ? 1 : 0; $this->Post['config']['seccode_no_photo'] = $this->Post['config']['seccode_no_photo'] ? 1 : 0; $this->Post['config']['seccode_no_vip'] = $this->Post['config']['seccode_no_vip'] ? 1 : 0; $this->Post['config']['seccode_purviews'] = array(); if (is_array($this->Post['config']['seccode_purview']) && count($this->Post['config']['seccode_purview'])) { foreach ($this->Post['config']['seccode_purview'] as $__spid) { $__spid = jfilter($__spid, 'int'); if ($__spid > 0) { $this->Post['config']['seccode_purviews'][$__spid] = $__spid; } } } $this->Post['config']['seccode_enable'] = $this->Post['seccode_enable'] ? (int) $this->Post['seccode_enable'] : 0; if ($this->Post['config']['seccode_enable'] == 1) { $this->Post['config']['seccode_login'] = $this->Post['config']['seccode_logins'] ? 1 : 0; $this->Post['config']['seccode_register'] = $this->Post['config']['seccode_registers'] ? 1 : 0; $this->Post['config']['seccode_password'] = $this->Post['config']['seccode_passwords'] ? 1 : 0; } $this->Post['config']['seccode_purview'] = is_array($this->Post['config']['seccode_purview']) ? implode(',', $this->Post['config']['seccode_purview']) : ''; $this->Post['config']['seccode_pri_key'] = $this->Post['config']['seccode_pri_key'] ? $this->Post['config']['seccode_pri_key'] : $this->yxm_pri_key; $this->Post['config']['seccode_pub_key'] = $this->Post['config']['seccode_pub_key'] ? $this->Post['config']['seccode_pub_key'] : $this->yxm_pub_key; unset($this->Post['seccode_setting']); } if (isset($this->Post['config']['is_qmd'])) { $this->Post['config']['is_qmd'] = $this->Post['config']['is_qmd'] ? 1 : 0; if ($this->Post['config']['is_qmd']) { if (!$this->Post['config']['qmd_file_url'] || !jmkdir($this->Post['config']['qmd_file_url'])) { $this->Post['config']['qmd_file_url'] = 'images/qmd/'; } if (!$this->Post['config']['qmd_fonts_url'] || !file_exists($this->Post['config']['qmd_fonts_url'])) { $this->Post['config']['is_qmd'] = 0; $this->Messager('请上传签名档必须的字体文件 ' . $this->Post['config']['qmd_fonts_url']); } } $this->Post['config']['qmd_link_display'] = $this->Post['config']['qmd_link_display'] ? 1 : 0; } if (isset($this->Post['config']['follow_limit'])) { $this->Post['config']['follow_limit'] = max(0, (int) $this->Post['config']['follow_limit']); } if (isset($this->Post['config']['topic_input_length'])) { $this->Post['config']['topic_input_length'] = max(0, (int) $this->Post['config']['topic_input_length']); } if (isset($this->Post['config']['gzip'])) { $this->Post['config']['gzip'] = $this->Post['config']['gzip'] && function_exists('ob_gzhandler') ? 1 : 0; } if (isset($this->Post['config']['reply_mode_normal'])) { $this->Post['config']['reply_mode_normal'] = $this->Post['config']['reply_mode_normal'] ? 1 : 0; } $new_config = $config = jconf::core_settings(); foreach ($this->Post['config'] as $k => $v) { if (isset($this->Post['config'][$k]) && !is_null($v)) { $new_config[$k] = $v; } } $new_config['topic_cut_length'] = (int) $new_config['topic_cut_length']; if ($new_config['topic_cut_length'] > 200 || $new_config['topic_cut_length'] < 10) { $new_config['topic_cut_length'] = 140; } if (!$new_config['wap_url']) { $new_config['wap_url'] = $new_config['site_url'] . '/wap'; } if (!$new_config['mobile_url']) { $new_config['mobile_url'] = $new_config['site_url'] . '/mobile'; } $new_config['extra_domains'] = array(); if ($new_config['extra_domain']) { $_arrs = explode("\n", $new_config['extra_domain']); foreach ($_arrs as $v) { $v = trim($v); $vl = strlen($v); if ($vl > 3 && $vl < 100) { $new_config['extra_domains'][] = strtolower($v); } } $new_config['extra_domain'] = implode("\n", $new_config['extra_domains']); } $new_config['copyright'] = jstripslashes($new_config['copyright']); $new_config['tongji'] = jstripslashes($new_config['tongji']); $new_config['topic_view_share_code'] = jstripslashes($new_config['topic_view_share_code']); $new_config['regclosemessage'] = jstripslashes($new_config['regclosemessage']); $result = jconf::set($new_config); if ($result != false) { $this->Messager("配置修改成功"); } else { $this->Messager("配置修改失败"); } }
function save($doc, $type, $ancestors) { global $db, $config; $doc['fbbk_updated_time'] = date(DATE_ISO8601); if (count($ancestors)) { $r = $ancestors[0]; $colName = "{$r['type']}_{$r['id']}_{$type}s"; if (count($ancestors) > 1) { $doc['fbbk_parent'] = end($ancestors); } } else { $colName = $type . 's'; } if ($config['enable_photo_download'] && $type == 'photo') { /// Download the photo. $p = end($ancestors); $source = $doc['images'][0]['source']; $dir = "{$config['data_storage']}/photos/{$p['type']}_{$p['id']}/"; $dest = $dir . $doc['id'] . '.' . pathinfo(parse_url($source, PHP_URL_PATH))['extension']; if (!file_exists($dest)) { if (!is_dir($dir)) { mkdir($dir, 0777, true); } if (copy($source, $dest)) { p("Successfully downloaded photo to {$dest}"); } else { p("Warning: Failed downloading {$source} to {$dest}"); } usleep(1000); } else { p("{$dest} already exists."); } unset($doc['images']); } $doc['_id'] = $doc['id']; unset($doc['id']); $ret = $db->selectCollection($colName)->update(array('_id' => $doc['_id']), array_remove_empty($doc), array('upsert' => true)); p("Updated {$type} with id {$doc['_id']}."); return $ret; }
/** * Removes any empty or NULL elements from an array * @param <array> $arr Array to remove empty values from * @return <array> Array without empty values * @category Arrays * <code> * $result = Arrays::removeEmpty(array('3', '2', NULL, '1', '3', '')); * </code> */ function removeEmpty($arr) { try { $narr = array(); while (list($key, $val) = each($arr)) { if (is_array($val)) { $val = array_remove_empty($val); // does the result array contain anything? if (count($val) != 0) { // yes :-) $narr[$key] = $val; } } else { if (trim($val) != "") { $narr[$key] = $val; } } } unset($arr); return $narr; } catch (Exception $err) { return $err->getMessage(); } }
public static function parseUrl($arg = false) { if ($arg === false) { $_GET['q'] = filter('content_parseurl', $_GET['q']); URLMap::from("*", "Content::parseURL", 1000); } else { $parts = array_remove_empty(explode('/', $_GET['q'])); if (count($parts) == 1) { if (self::isNode('/' . $parts[0])) { self::setCurrent(self::nameToId('/' . $parts[0])); } else { self::trigger404(); } } elseif (count($parts) > 1) { $page = '/' . implode('/', $parts); if (self::isNode($page)) { self::setCurrent(self::nameToId($page)); } else { self::trigger404(); } } else { self::setCurrent(Settings::get('site', 'homepage id', true)); } } }
public function newAction() { $this->_helper->redirector->gotoSimple(ACTION_INDEX, $this->getRequest()->getControllerName(), $this->getRequest()->getModuleName(), array_remove_empty(array_merge_maintain_keys($this->_getAllParams(), $this->getRequest()->getQuery()))); }
/** * Redirect list searches to maintain the urls as per zend format */ public function reportsearchAction() { // debugMessage($this->getRequest()->getQuery()); // debugMessage($this->_getAllParams()); $action = $this->_getParam('page'); if (!isEmptyString($this->_getParam('pageaction'))) { $action = $this->_getParam('pageaction'); } //exit(); if (!isEmptyString($action)) { $this->_helper->redirector->gotoSimple($action, $this->getRequest()->getControllerName(), $this->getRequest()->getModuleName(), array_remove_empty(array_merge_maintain_keys($this->_getAllParams(), $this->getRequest()->getQuery()))); } }
private function remove_alert($remove_alert_ID) { $skeleton = array('posts' => array(), 'taxonomies' => array(), 'post_types' => array(), 'alerts' => array()); $alerts = $orig_alerts = get_option('jc_active_alerts', $skeleton); // Reset this alert's settings if (!empty($alerts['alerts'][$remove_alert_ID])) { foreach ($alerts['alerts'][$remove_alert_ID] as $type => $type_IDs) { foreach ($type_IDs as $type_ID => $bool) { unset($alerts[$type][$type_ID][$remove_alert_ID]); } } // Clean empty values $alerts = wp_parse_args(array_remove_empty($alerts), $skeleton); $alerts['alerts'][$remove_alert_ID] = array(); } foreach ($alerts as $type => $_alerts) { if ($type == 'alerts') { continue; } if (isset($alerts[$type][$remove_alert_ID])) { unset($alerts[$type][$remove_alert_ID]); } } return $alerts; }
function add($param, $id = 0) { if (!$param) { return false; } if ($param['topic']) { if (!$param['tid']) { $topic = array('content' => $param['topic'], 'from' => 'reward', 'type' => 'first', 'item' => 'reward', 'item_id' => 0); $return = jlogic('topic')->Add($topic); } else { $return = jlogic('topic')->Modify($param['tid'], $param['topic']); } if (is_array($return) && $return['tid']) { $data['tid'] = $return['tid']; } else { if (is_string($return)) { return $return; } else { return '转发的微博发布失败...'; } } } $data['uid'] = MEMBER_ID; #标题 $data['title'] = $param['title']; #开始时间 $data['fromt'] = $param['fromt']; #结束时间 $data['tot'] = $param['tot']; #描述 $data['content'] = $param['content']; #活动图片 $data["event_image"] = $param["event_image"]; $i = 1; foreach ($param['prize_name'] as $key => $val) { $i++; if ((!$val || !$param['prize'][$key]) && $key < 6) { continue; } $prize[] = array('prize_name' => $val, 'prize' => $param['prize'][$key], 'prize_num' => (int) $param['prize_num'][$key], 'prize_image' => $param['prize_image'][$key]); if (!$data['image'] && $param['prize_image'][$key]) { $data['image'] = $param['prize_image'][$key]; } } #奖品 $data['prize'] = serialize($prize); #转发规则 $rules = array(); foreach ($param['rules'] as $key => $val) { if (!($val = trim($val))) { continue; } switch ($key) { case 'tag': $rules['tag'] = explode('|', $val); $rules['tag'] = array_remove_empty($rules['tag']); break; case 'user': $user = str_replace('|', "','", $val); $sql = "select `uid`,`nickname` from `" . TABLE_PREFIX . "members` where `nickname` in ('{$user}')"; $query = DB::query($sql); while ($rs = DB::fetch($query)) { $user_arr[$rs['uid']]['nickname'] = $rs['nickname']; } $rules['user'] = $user_arr; break; case 'at_num': $num = (int) $val; $num > 0 && ($rules['at_num'] = $num); default: break; } } $data['rules'] = serialize($rules); #发布时间 $data['posttime'] = TIMESTAMP; #发布IP $data['postip'] = ip2long($GLOBALS['_J']['client_ip']); if ($id) { $reward = $this->getRewardInfo($id); if (!$reward) { return '有奖转发不存在或已删除。'; } $where = " where `id` = '{$id}' "; $rid = $this->update($data, TABLE_PREFIX . 'reward', $where); if (!$rid) { return '更新失败'; } $rid = $id; } else { $rid = $this->insert($data, TABLE_PREFIX . 'reward'); } if ($rid > 0) { #给图片赋予ID $param['prize_image'] = array_remove_empty($param['prize_image']); if (!empty($param['prize_image'])) { $ids = implode(",", $param['prize_image']); if ($ids) { DB::query("update `" . TABLE_PREFIX . "reward_image` set `rid` = '{$rid}' where `id` in ({$ids})"); } } #将item_id赋给微博 DB::query("update `" . TABLE_PREFIX . "topic` set `item_id` = '{$rid}' where `tid` = '{$data['tid']}'"); } return $rid; }
protected function _fidsToDataArray($data) { $newData = array(); foreach ($data as $fid => $val) { if (substr($fid, 0, 5) == '000d0') { $iRecord = substr($fid, 6, 2); $iVal = substr($fid, 4, 2); // 4,2 or 5,1 ??? $iRecord = hexdec($iRecord); $iVal = hexdec($iVal); $newData['data'][$iRecord][$iVal] = $val; } else { $newData['fids'][$fid] = $val; } } //$newData['data'] = array_filter($newData['data']); $newData['data'] = array_remove_empty($newData['data']); return $newData; }
/** * Recursively Remove empty values from an array. If any of the keys contains an * array, the values are also removed. * * @param Array $input The array * @return Array with the specified values removed or the filtered values */ function array_remove_empty($arr) { $narr = array(); while (list($key, $val) = each($arr)) { if (is_array($val)) { $val = array_remove_empty($val); // does the result array contain anything? if (count($val) != 0) { // yes :-) $narr[$key] = $val; } } else { if (!isEmptyString($val)) { $narr[$key] = $val; } } } unset($arr); return $narr; }
function shiftslistsearchAction() { $this->_helper->redirector->gotoSimple("shifts", "config", $this->getRequest()->getModuleName(), array_remove_empty(array_merge_maintain_keys($this->_getAllParams(), $this->getRequest()->getQuery()))); }