public function testCanGetEntitiesByAnnotationCreationTime() { $prefix = elgg_get_config('dbprefix'); $users = elgg_get_entities(array('type' => 'user', 'limit' => 1)); // create some test annotations $subtypes = $this->getRandomValidSubtypes(array('object'), 1); $subtype = $subtypes[0]; $annotation_name = 'test_annotation_name_' . rand(); // our targets $valid1 = new \ElggObject(); $valid1->subtype = $subtype; $valid1->save(); $id1 = $valid1->annotate($annotation_name, 1, ACCESS_PUBLIC, $users[0]->guid); // this one earlier $yesterday = time() - 86400; update_data("\n\t\t\tUPDATE {$prefix}annotations\n\t\t\tSET time_created = {$yesterday}\n\t\t\tWHERE id = {$id1}\n\t\t"); $valid2 = new \ElggObject(); $valid2->subtype = $subtype; $valid2->save(); $valid2->annotate($annotation_name, 1, ACCESS_PUBLIC, $users[0]->guid); $options = array('annotation_owner_guid' => $users[0]->guid, 'annotation_created_time_lower' => time() - 3600, 'annotation_name' => $annotation_name); $entities = elgg_get_entities_from_annotations($options); $this->assertEqual(1, count($entities)); $this->assertEqual($valid2->guid, $entities[0]->guid); $options = array('annotation_owner_guid' => $users[0]->guid, 'annotation_created_time_upper' => time() - 3600, 'annotation_name' => $annotation_name); $entities = elgg_get_entities_from_annotations($options); $this->assertEqual(1, count($entities)); $this->assertEqual($valid1->guid, $entities[0]->guid); $valid1->delete(); $valid2->delete(); }
/** * Create or update the extras table for a given object. * Call create_entity first. * * @param int $guid The guid of the entity you're creating (as obtained by create_entity) * @param string $title The title of the object * @param string $description The object's description * * @return bool */ function create_object_entity($guid, $title, $description) { global $CONFIG; $guid = (int) $guid; $title = sanitise_string($title); $description = sanitise_string($description); $row = get_entity_as_row($guid); if ($row) { // Core entities row exists and we have access to it $query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}"; if ($exists = get_data_row($query)) { $query = "UPDATE {$CONFIG->dbprefix}objects_entity\n\t\t\t\tset title='{$title}', description='{$description}' where guid={$guid}"; $result = update_data($query); if ($result != false) { // Update succeeded, continue $entity = get_entity($guid); elgg_trigger_event('update', $entity->type, $entity); return $guid; } } else { // Update failed, attempt an insert. $query = "INSERT into {$CONFIG->dbprefix}objects_entity\n\t\t\t\t(guid, title, description) values ({$guid}, '{$title}','{$description}')"; $result = insert_data($query); if ($result !== false) { $entity = get_entity($guid); if (elgg_trigger_event('create', $entity->type, $entity)) { return $guid; } else { $entity->delete(); } } } } return false; }
function upgrade_20141130() { $upgrade_version = get_upgrade_version(); if ($upgrade_version >= UPGRADE_VERSION) { return true; } $site = elgg_get_site_entity(); $dbprefix = elgg_get_config('dbprefix'); // move ip tracking from heavy object entities to lighter-weight annotations $options = array("type" => "object", "subtype" => "spam_login_filter_ip", 'limit' => false); $batch = new ElggBatch('elgg_get_entities', $options, null, 50, false); $week_ago = time() - 604800; // just delete anything over a week old foreach ($batch as $e) { // create a new record as an annotation and delete the entity if ($e->time_created > $week_ago) { $id = $site->annotate('spam_login_filter_ip', $e->ip_address, ACCESS_PUBLIC); if ($id) { $sql = "UPDATE {$dbprefix}annotations SET time_created = {$e->time_created} WHERE id = {$id}"; update_data($sql); } } $e->delete(); } set_upgrade_version(20141130); }
function dbvalidate_fix_bad_entities() { $db_prefix = elgg_get_config('dbprefix'); $guid = elgg_get_logged_in_user_guid(); $query = "UPDATE {$db_prefix}entities e LEFT JOIN {$db_prefix}entities o ON e.owner_guid = o.guid" . " SET e.owner_guid = {$guid}" . " WHERE (e.type = 'object' OR e.type='group') AND (o.guid IS NULL OR o.guid = 0)"; update_data($query); }
function upgrade_1395099219() { // updating river entries $dbprefix = elgg_get_config('dbprefix'); $query = "UPDATE {$dbprefix}river r\n\t\tSET r.view = 'framework/mechanics/river/claim'\n\t\tWHERE r.view = 'river/object/hjformsubmission/create' AND r.action_type = 'claim'"; update_data($query); }
/** *用户修改昵称 * 用户在个人中心可以修改自己的昵称 *流程分析 * 判断用户新昵称和旧昵称是否一致 * 将新昵称写入数据库 **/ public function index() { $home_member_id = session('home_member_id'); $member_info = get_info($this->table, array('id' => $home_member_id)); if (IS_POST) { $nickname = I('nickname'); if ($member_info['nickname'] == $nickname) { $this->error('您的昵称未作修改!'); } unset($_POST); $_POST['id'] = session('home_member_id'); $_POST['nickname'] = $nickname; $result = update_data($this->table); if (is_numeric($result)) { session('nickname', $_POST['nickname']); //更新缓存 $this->success('修改成功!', U('User/UpdateName/index'), $ajax); } else { $this->error('修改失败,请联系客服!', U('User/UpdateName/index'), $ajax); } } else { $data['member_info'] = $member_info; $this->assign($data); $this->display(); } }
function profile_manager_run_once() { global $CONFIG; // upgrade $profile_field_class_name = "ProfileManagerCustomProfileField"; $group_field_class_name = "ProfileManagerCustomGroupField"; $field_type_class_name = "ProfileManagerCustomProfileType"; $field_category_class_name = "ProfileManagerCustomFieldCategory"; if ($id = get_subtype_id('object', ProfileManagerCustomProfileField::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$profile_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileField::SUBTYPE, $profile_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomGroupField::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$group_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomGroupField::SUBTYPE, $group_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomProfileType::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$field_type_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileType::SUBTYPE, $field_type_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomFieldCategory::SUBTYPE)) { update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes set class='{$field_category_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomFieldCategory::SUBTYPE, $field_category_class_name); } }
public function testCanUpdateData() { _elgg_services()->db->addQuerySpec(['sql' => 'UPDATE A SET b = :b WHERE c = :c', 'params' => [':b' => 'b', ':c' => 'c'], 'row_count' => 20]); _elgg_services()->db->addQuerySpec(['sql' => 'UPDATE A SET b = :b WHERE d = :d', 'params' => [':b' => 'b', ':d' => 'd'], 'row_count' => 0]); $this->assertTrue(update_data('UPDATE A SET b = :b WHERE c = :c', [':b' => 'b', ':c' => 'c'])); $this->assertEquals(20, update_data('UPDATE A SET b = :b WHERE c = :c', [':b' => 'b', ':c' => 'c'], true)); $this->assertTrue(update_data('UPDATE A SET b = :b WHERE d = :d', [':b' => 'b', ':d' => 'd'])); $this->assertEquals(0, update_data('UPDATE A SET b = :b WHERE d = :d', [':b' => 'b', ':d' => 'd'], true)); }
/** * Update subtype * * @param ElggObject $page */ function pages_2012061800($page) { $dbprefix = elgg_get_config('dbprefix'); $subtype_id = (int) get_subtype_id('object', 'page_top'); $page_guid = (int) $page->guid; update_data("UPDATE {$dbprefix}entities\n\t\tSET subtype = {$subtype_id} WHERE guid = {$page_guid}"); error_log("called"); return true; }
function setStatus($field = "status") { $ids = I('ids'); if (!$ids) { return array('status' => '0', 'msg' => '请选择要修改的数据'); // $this->error('请选择要修改的数据'); } $field_val = intval(I('get.' . $field)); if (is_array($ids)) { $_POST = array($field => $field_val); $map['id'] = array('in', $ids); //$result=update_data($this->table,array(),$map); $Model = M($this->table); // 实例化User对象 $Model->where($map)->save($_POST); // 根据条件更新记录 $ids_str = implode(',', $ids); /*如果该表数据有缓存,那么删除缓存*/ if ($this->cache_data != '') { F($this->cache_data, NULL); } if ($this->session_cache_name != '') { session($this->session_cache_name, NULL); } if ($this->has_parent) { $this->parent_operate(); } return array('status' => '1', 'msg' => '操作成功'); // $this->success('操作成功'); } else { $ids = intval($ids); if (!$ids) { return array('status' => '0', 'msg' => '请选择要修改的数据'); // $this->error('请选择要操作的数据'); } $_POST = array('id' => $ids, $field => $field_val); $result = update_data($this->table); if (is_numeric($result)) { /*如果该表数据有缓存,那么删除缓存*/ if ($this->cache_data != '') { F($this->cache_data, NULL); } if ($this->session_cache_name != '') { session($this->session_cache_name, NULL); } if ($this->has_parent) { $this->parent_operate(); } return array('status' => '1', 'msg' => '操作成功'); // $this->success('操作成功'); } else { return array('status' => '0', 'msg' => $result); // $this->error($result); } } }
function upgrade_izap_videos_to($version) { global $CONFIG; $update_entity_subtype = "UPDATE {$CONFIG->dbprefix}entity_subtypes SET class = 'IzapVideos' WHERE subtype = 'izap_videos'"; $del_entity_query = "DELETE FROM {$CONFIG->dbprefix}entities\n WHERE subtype IN (SELECT id FROM {$CONFIG->dbprefix}entity_subtypes\n WHERE subtype='izapVideoQueue')"; $del_queue_object_query = "DELETE FROM {$CONFIG->dbprefix}entity_subtypes where subtype='izapVideoQueue'"; if (update_data($update_entity_subtype) || (delete_data($del_entity_query) || delete_data($del_queue_object_query))) { datalist_set('izap_videos_version', $version); } }
/** *用户修改头像 * 用户在个人中心可以修改自己的头像 *流程分析 * 1、接收用户的号码和验证码 * 2、验证验证码 * 验证码要和提交的手机一致 * 3、修改用户的手机号码 **/ public function index() { //手机app参数 $apptype = (!empty(I('post.apptype')) and I('post.apptype') == C('APP_KEY')) ? true : false; //手机app接口密钥 //手机app与电脑客户端参数区分 if ($apptype) { $app_key = trim(I("post.key")); //md5加密的登录时间 $home_member_id = I("post.home_member_id"); $this->isLoginExpire($app_key, $member_id); //判断登录过期 $ajax = true; $update_phone = trim(I('update_phone')); $update_code = trim(I('update_code')); } else { $ajax = false; $home_member_id = session('home_member_id'); $update_phone = session('update_phone'); $update_code = session('update_code'); } //获取用户信息 $member_info = get_info($this->table, array('id' => $home_member_id)); if (!$member_info) { $this->error("未获取到您的信息", '', $ajax); } if (IS_POST) { //接收用户的手机号码 $member_telephone = trim(I('newPhone')); $code = trim(I('code')); //验证号码是否做了修改 if ($member_info['telephone'] == $member_telephone) { $this->error('您的手机未作修改!!', '', $ajax); } //验证验证码的正确性 if ($member_telephone != $update_phone || $code != $update_code) { $this->error('您的验证码有误!', '', $ajax); } unset($_POST); ///dump($code); $_POST['id'] = intval($home_member_id); $_POST['telephone'] = $member_telephone; $result = update_data($this->table); if (is_numeric($result)) { $this->success('修改成功!', U('User/UpdatePhone/index'), $ajax); } else { $this->error('修改失败,请联系客服!', U('User/UpdatePhone/index'), $ajax); } } else { $data['member_info'] = $member_info; $this->assign($data); $this->display(); } }
function update_page() { global $user, $sql_updates; if (isset($_POST['edit'])) { $edit = $_POST['edit']; } if (isset($_POST['op'])) { $op = $_POST['op']; } switch ($op) { case "Update": // make sure we have updates to run. print update_page_header("Drupal database update"); $links[] = "<a href=\"index.php\">main page</a>"; $links[] = "<a href=\"index.php?q=admin\">administration pages</a>"; print theme("item_list", $links); // NOTE: we can't use l() here because the URL would point to 'update.php?q=admin'. if ($edit["start"] == -1) { print "No updates to perform."; } else { update_data($edit["start"]); } print "<br />Updates were attempted. If you see no failures above, you may proceed happily to the <a href=\"index.php?q=admin\">administration pages</a>."; print " Otherwise, you may need to update your database manually."; print update_page_footer(); break; default: // NOTE: We need the following five lines in order to fix a bug with // database.mysql (issue #15337). We should be able to remove // this work around in the future. $result = db_query("SELECT * FROM {variable} WHERE name = 'update_start' AND value LIKE '%;\"'"); if ($variable = db_fetch_object($result)) { $variable->value = unserialize(substr($variable->value, 0, -2) . '";'); variable_set('update_start', $variable->value); } $start = variable_get("update_start", 0); $dates[] = "All"; $i = 1; foreach ($sql_updates as $date => $sql) { $dates[$i++] = $date; if ($date == $start) { $selected = $i; } } $dates[$i] = "No updates available"; // make update form and output it. $form = form_select("Perform updates from", "start", isset($selected) ? $selected : -1, $dates, "This defaults to the first available update since the last update you performed."); $form .= form_submit("Update"); print update_page_header("Drupal database update"); print form($form); print update_page_footer(); break; } }
function action_log($table_name, $table_id = 0, $action_filed = 'id,title') { $url = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME); if (is_numeric($table_id)) { $map['id'] = $table_id; } else { $map['id'] = array('in', $table_id); } $result = get_result($table_name, $map, $action_filed); $_POST = array('member_id' => session('member_id'), 'username' => session('username'), 'url' => $url, 'table_name' => $table_name, 'table_id' => $table_id, 'description' => json_encode($result), 'ip' => get_client_ip()); update_data('action_log'); }
protected function update() { $rules = array(array('title', 'require', '标题必须!', 1), array('content', 'require', '内容必须!', 1)); $_POST['content'] = replaceStrImg($_POST['content'], "replace"); $_POST['type'] = $this->type; $result = update_data($this->table, $rules); if (is_numeric($result)) { $this->success('操作成功!', U('index')); } else { $this->error($result); } }
/** * Make sure river items have targets * @return void */ function interactions_20150106a() { $dbprefix = elgg_get_config('dbprefix'); $river = new \ElggBatch('elgg_get_river', array('action_type' => 'stream:comment', 'limit' => 0, 'callback' => false)); foreach ($river as $r) { $id = $r->id; $comment = get_entity($r->object_guid); $target_guid = 0; if ($comment) { $target_guid = (int) $comment->container_guid; } $query = "UPDATE {$dbprefix}river SET target_guid={$target_guid} WHERE id={$id}"; update_data($query); } }
public function update() { if (IS_POST) { $id = intval(I('post.id')); $rules = array(array('title', 'require', '请填写配置标题'), array('name', 'require', '请填写配置标识'), array('name', '/^[a-zA-Z_]{4,15}+$/', '配置标识只允许使用字母和下划线'), array('name', '', '配置标识已存在,请更换其它标识', 1, 'unique'), array('group', 'require', '请填写分组'), array('group', '/^[\\x{4e00}-\\x{9fa5}A-Za-z0-9_]+$/u', '分组只允许使用中文、字母和下划线'), array('type', 'require', '请选择配置类型')); $result = update_data($this->table, $rules); if (is_numeric($result)) { F('config', null); $this->success('操作成功', U('index')); } else { $this->error($result); } } else { $this->success('违法操作', U('index')); } }
public function ajax_update() { $resource_id = I('id'); $title = I('title'); //淇敼瀵瑰簲鐨刬d鐨則itle unset($_POST); $_POST['id'] = $resource_id; $_POST['title'] = $title; $result = update_data($this->table); $this->ajaxReturn(session('sql')); if (is_numeric($result)) { $this->ajaxReturn(array('status' => 1, 'msg' => '淇敼鎴愬姛锛侊紒')); } else { $this->ajaxReturn(array('status' => 0, 'mag' => '淇敼澶辫触锛侊紒')); } }
public function testCanUpdate() { add_entity_relationship($this->user->guid, 'test_self1', $this->user->guid); $rel = check_entity_relationship($this->user->guid, 'test_self1', $this->user->guid); $res = update_data("\n\t\t\tUPDATE {$this->prefix}entity_relationships\n\t\t\tSET relationship = 'test_self2'\n\t\t\tWHERE id = {$rel->id}\n\t\t"); $rel = get_relationship($rel->id); $this->assertIdentical($res, true); $this->assertEqual($rel->relationship, 'test_self2'); $num_rows = update_data("\n\t\t\tUPDATE {$this->prefix}entity_relationships\n\t\t\tSET relationship = 'test_self3'\n\t\t\tWHERE id = {$rel->id}\n\t\t", [], true); $rel = get_relationship($rel->id); $this->assertIdentical($num_rows, 1); $this->assertEqual($rel->relationship, 'test_self3'); $num_rows = update_data("\n\t\t\tUPDATE {$this->prefix}entity_relationships\n\t\t\tSET relationship = :rel\n\t\t\tWHERE id = :id\n\t\t", [':rel' => 'test_self4', ':id' => $rel->id], true); $rel = get_relationship($rel->id); $this->assertIdentical($num_rows, 1); $this->assertEqual($rel->relationship, 'test_self4'); $rel->delete(); }
/** * {@inheritdoc} */ public function handle(ElggEntity $entity) { $value = get_input($this->getShortname()); $value = strip_tags($value); // update access collection name if group name changes if ($entity->guid && $value != $entity->name) { $entity_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $entity_name); $acl = get_access_collection($entity->group_acl); if ($acl) { $db_prefix = elgg_get_config('dbprefix'); $query = "UPDATE {$db_prefix}access_collections SET name = '{$ac_name}'\n\t\t\t\tWHERE id = {$entity->group_acl}"; update_data($query); } } $entity->name = $value; return $entity; }
public function del() { //1、根据点击删除传递过来的ID获取相关数据 $ids = I('ids'); $map['id'] = array("in", $ids); $result = get_result($this->table, $map); //2、获取评论内容中的图片并删除 foreach ($result as $key => $value) { //删除内容中的图片 delStrImgs($value['content']); //3、统计评论删除后新闻的评论数量 $_POST['id'] = $value['product_id']; $_POST['comment'] = count_data($this->table, array("product_id" => $value['product_id'])); update_data("article"); } //4、删除数据表中的数据 delete_data($this->table, $map); $this->success("删除成功"); }
/** * Create or update the entities table for a given site. * Call create_entity first. * * @param int $guid Site GUID * @param string $name Site name * @param string $description Site Description * @param string $url URL of the site * * @return bool * @access private */ function create_site_entity($guid, $name, $description, $url) { global $CONFIG; $guid = (int) $guid; $name = sanitise_string($name); $description = sanitise_string($description); $url = sanitise_string($url); $row = get_entity_as_row($guid); if ($row) { // Exists and you have access to it $query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}"; if ($exists = get_data_row($query)) { $query = "UPDATE {$CONFIG->dbprefix}sites_entity\n\t\t\t\tset name='{$name}', description='{$description}', url='{$url}' where guid={$guid}"; $result = update_data($query); if ($result != false) { // Update succeeded, continue $entity = get_entity($guid); if (elgg_trigger_event('update', $entity->type, $entity)) { return $guid; } else { $entity->delete(); //delete_entity($guid); } } } else { // Update failed, attempt an insert. $query = "INSERT into {$CONFIG->dbprefix}sites_entity\n\t\t\t\t(guid, name, description, url) values ({$guid}, '{$name}', '{$description}', '{$url}')"; $result = insert_data($query); if ($result !== false) { $entity = get_entity($guid); if (elgg_trigger_event('create', $entity->type, $entity)) { return $guid; } else { $entity->delete(); //delete_entity($guid); } } } } return false; }
public function update() { if (IS_POST) { $id = intval(I('post.id')); $url = I('post.url'); $rules = array(array('title', 'require', '导航名称必须!')); $_POST['type'] = 'bottom'; $pid = intval(I('post.pid')); $result = update_data($this->table, $rules); if (is_numeric($result)) { //获取修改的特殊状态,更新 F($this->cache_data, null); action_log($this->table, $result, $this->action_filed); $this->success('操作成功', U('index', array('pid' => intval(I('post.pid'))))); } else { $this->error($result); } } else { $this->success('违法操作', U('index')); } }
/** *新闻详情页面 * 需求分析 * 将对应的新闻显示到页面中 * 流程分析 * 1、接收用户传过来的id * 2、查询相关数据 × 3、将页面中的其他数据显示 **/ public function detail() { //接收新闻信息 $news_id = I('id'); $map['id'] = $news_id; $news_info = get_info($this->table, $map); $data['news_detail'] = $news_info; //将推荐的公告查询出来 $map_notice['status'] = array('GT', 0); $map_notice['type'] = 'notice'; $map_notice['recommend'] = 1; //被推荐的公告 //查询出来 $notice_result = get_result($this->table, $map_notice); //增加阅读次数 $_POST = array('id' => $news_info['id'], 'view' => $news_info['view'] + 1); update_data($this->table); $data['notice'] = $notice_result; $this->assign($data); $this->display(); }
/** * Run once function * * @return void */ function profiles_go_run_once() { $dbprefix = elgg_get_config("dbprefix"); // upgrade class names for subtypes $profile_field_class_name = "ProfileManagerCustomProfileField"; $trip_field_class_name = "ProfileManagerCustomTripField"; $field_type_class_name = "ProfileManagerCustomProfileType"; $field_category_class_name = "ProfileManagerCustomFieldCategory"; if ($id = get_subtype_id('object', ProfileManagerCustomProfileField::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$profile_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileField::SUBTYPE, $profile_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomTripField::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$trip_field_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomTripField::SUBTYPE, $trip_field_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomProfileType::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$field_type_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomProfileType::SUBTYPE, $field_type_class_name); } if ($id = get_subtype_id('object', ProfileManagerCustomFieldCategory::SUBTYPE)) { update_data("UPDATE {$dbprefix}entity_subtypes set class='{$field_category_class_name}' WHERE id={$id}"); } else { add_subtype('object', ProfileManagerCustomFieldCategory::SUBTYPE, $field_category_class_name); } // update ownerships of profile manager field configuration // owner should be site instead of a user (prevents problems when upgrading) // Added in Profile Manager v5.6 $options = array("type" => "object", "subtypes" => array(ProfileManagerCustomProfileField::SUBTYPE, ProfileManagerCustomTripField::SUBTYPE, ProfileManagerCustomProfileType::SUBTYPE, ProfileManagerCustomFieldCategory::SUBTYPE), "limit" => false); $entities = elgg_get_entities($options); foreach ($entities as $entity) { $entity->owner_guid = $entity->site_guid; $entity->container_guid = $entity->site_guid; $entity->save(); } }
public function ajaxDelete_config() { $posts = I("post."); $info = get_info($this->table, array("id" => $posts['id'])); $path = $info['value']; $_POST = null; if (file_exists($path)) { if (@unlink($path)) { $_POST['id'] = $posts['id']; $_POST['value'] = ''; update_data($this->table, array("id" => $posts['id'])); $this->success("删除成功"); } else { $this->error("删除失败"); } } else { $_POST['id'] = $posts['id']; $_POST['value'] = ''; update_data($this->table, array("id" => $posts['id'])); $this->success("文件不存在,删除失败,数据被删除"); } }
public function update() { if (IS_POST) { $id = intval(I('post.id')); $rules = array(array('title', 'require', '标题不能为空!'), array('description', 'require', '描述必须填写!')); /*刘巧*/ $_POST['is_admin'] = 0; //if($id==0){//如果是添加 //}else{//如果是修改 // if(I('post.password')){ // $_POST['password']=md5(md5(I('post.password'))); //}else{ // unset($_POST['password']); //} //} $result = update_data($this->table, $rules); if (is_numeric($result)) { F($this->cache_data, null); $this->success('操作成功', U('index')); } else { $this->error($result); } } else { $this->success('违法操作', U('index')); } }
/** * Runs a full database script from disk. * * The file specified should be a standard SQL file as created by * mysqldump or similar. Statements must be terminated with ; * and a newline character (\n or \r\n) with only one statement per line. * * The special string 'prefix_' is replaced with the database prefix * as defined in {@link $CONFIG->dbprefix}. * * @warning Errors do not halt execution of the script. If a line * generates an error, the error message is saved and the * next line is executed. After the file is run, any errors * are displayed as a {@link DatabaseException} * * @param string $scriptlocation The full path to the script * * @return void * @throws DatabaseException * @access private */ function run_sql_script($scriptlocation) { if ($script = file_get_contents($scriptlocation)) { global $CONFIG; $errors = array(); // Remove MySQL -- style comments $script = preg_replace('/\\-\\-.*\\n/', '', $script); // Statements must end with ; and a newline $sql_statements = preg_split('/;[\\n\\r]+/', $script); foreach ($sql_statements as $statement) { $statement = trim($statement); $statement = str_replace("prefix_", $CONFIG->dbprefix, $statement); if (!empty($statement)) { try { $result = update_data($statement); } catch (DatabaseException $e) { $errors[] = $e->getMessage(); } } } if (!empty($errors)) { $errortxt = ""; foreach ($errors as $error) { $errortxt .= " {$error};"; } $msg = elgg_echo('DatabaseException:DBSetupIssues') . $errortxt; throw new DatabaseException($msg); } } else { $msg = elgg_echo('DatabaseException:ScriptNotFound', array($scriptlocation)); throw new DatabaseException($msg); } }
/** * when duplicate access is detected we'll transfer all content assigned to * one and assign it to the other * All content from $access1 will now be under $access2 * * @param type $access1 * @param type $access2 */ function merge_access($access1, $access2) { if (!elgg_instanceof($access1, 'object', 'granular_access') || !$access1->acl_id) { return false; } if (!elgg_instanceof($access2, 'object', 'granular_access') || !$access2->acl_id) { return false; } $dbprefix = elgg_get_config('dbprefix'); $sql = "UPDATE {$dbprefix}entities SET access_id = {$access2->acl_id} WHERE access_id = {$access1->acl_id}"; update_data($sql); $sql = "UPDATE {$dbprefix}metadata SET access_id = {$access2->acl_id} WHERE access_id = {$access1->acl_id}"; update_data($sql); $sql = "UPDATE {$dbprefix}annotations SET access_id = {$access2->acl_id} WHERE access_id = {$access1->acl_id}"; update_data($sql); return true; }
/** * OhYesChat Page Setup; * URLs take the form of * Boot: ohyeschat/boot/ohyeschat.boot.js * Notifications: ohyeschat/notif * Freinds: ohyeschat/friends * New tab : ohyeschat/newtab * actions: { * Send Message: oyeschat/action/send * Refresh the tab: ohyeschat/action/refresh * Remove the tab : ohyeschat/action/removetab/<id of tab> * * Title is ignored * * * @param array $page * @return bool */ function ohyeschat_page_handler($page) { $plugin = elgg_get_plugins_path() . 'OhYesChat/'; if (!isset($page[0])) { if (elgg_is_admin_logged_in()) { $page[0] = 'admin'; } else { forward(); } } $user = elgg_get_logged_in_user_entity(); if (empty($user->username)) { return false; } switch ($page[0]) { case 'admin': if (elgg_is_admin_logged_in()) { if (empty($page[1])) { include_once "{$plugin}pages/admin/dashboard.php"; } else { if ($page[1] == 'track') { include_once "{$plugin}pages/admin/trackuser.php"; } if ($page[1] == 'getuser') { include_once "{$plugin}pages/admin/getuser.php"; } } } break; case 'smilies': echo elgg_view('ohyes/chat/smiles/similes', array('tab' => get_input('uid'))); break; case 'messages': $user = $page[1]; if (!empty($user)) { $var['user'] = get_user_by_username($user); $var['owner'] = elgg_get_logged_in_user_entity()->guid; $var['messages'] = array_reverse(OhYesChat::getMessages($var['user']->guid, $var['owner'])); $params['content'] = elgg_view('ohyes/chat/expend', $var); $body = elgg_view_layout('one_sidebar', $params); echo elgg_view_page($params['title'], $body); } break; case 'boot': if ($page[1] == 'ohyeschat.boot.js') { header('Content-Type: text/javascript'); echo elgg_view('js/ohyes/chat'); } break; case 'notif': header('Content-Type: application/json'); $messages = elgg_view('ohyes/chat/messages'); if (empty($messages)) { $messages = '<p style="padding:10px;">' . elgg_echo('ohyes:chat:no:message') . '</p>'; } echo json_encode(array('messages' => $messages, 'count' => '')); break; case 'friends': header('Content-Type: application/json'); echo json_encode(array('friends' => elgg_view('ohyes/chat/friends', array('entity' => elgg_get_logged_in_user_entity())))); break; case 'newtab': header('Content-Type: application/json'); if (empty($page[1])) { exit; } else { if (!in_array($page[1], $_SESSION['ohyes_chat'])) { $_SESSION['ohyes_chat'][] = $page[1]; } } $login = elgg_get_logged_in_user_entity()->guid; $friend = get_user($page[1]); $messages = OhYesChat::getMessages($login, $page[1]); foreach (array_reverse($messages) as $umessages) { $icon = elgg_view("icon/default", array('entity' => get_user($umessages->sender), 'size' => 'small')); $user_msgs[] = elgg_view('ohyes/chat/message-item', array('icon' => $icon, 'message' => OhYesChat::replaceIcon($umessages->message), 'sender' => $umessages->sender)); } $tab = elgg_view('ohyes/chat/selectfriend', array('friend' => $friend)); $messages = implode('', $user_msgs); echo json_encode(array('tab' => $tab, 'messages' => $messages)); global $CONFIG; update_data("UPDATE {$CONFIG->dbprefix}ohyes_chat \n\t\t\t\t\t\t SET view='1' WHERE(sender='{$page['1']}' \n\t\t\t AND reciever='{$login}');"); break; case 'action': if (empty($page[1]) || !in_array($page[1], OhYesChat::actions())) { exit; } if ($page[1] == 'send') { require_once "{$plugin}actions/send.php"; } if ($page[1] == 'refresh') { exit; //removed in 1.1 release; $arsalanshah; } if ($page[1] == 'removetab') { $uid = array_search($page[2], $_SESSION['ohyes_chat']); unset($_SESSION['ohyes_chat'][$uid]); echo 'removed'; } break; case 'mobile': if (elgg_is_active_plugin('OhYesChat_Mobile') && OhYesChat::FromMobile()) { elgg_trigger_plugin_hook('ohyeschat', 'mobile', $page); } else { forward(); } break; default: return false; } return true; }