public function init() { $me = User\User::get(); if (!$me) { session_destroy(); } $rids = $me->rids; self::$rids = $rids; $qry = 'SELECT plg_name,plg_type,plg_status,region,title,content,pages,visibility FROM ' . PREFIX . 'codo_plugins AS p' . ' LEFT JOIN ' . PREFIX . 'codo_blocks AS b ON p.plg_name=b.module ' . ' LEFT JOIN ' . PREFIX . 'codo_block_roles AS r ON b.id=r.bid ' . ' WHERE r.rid IN (' . implode(",", $rids) . ') OR r.rid IS NULL ORDER BY b.weight'; $result = $this->db->query($qry)->fetchAll(); foreach ($result as $res) { $path = PLUGIN_DIR . $res['plg_name'] . '/' . $res['plg_name'] . '.php'; if (file_exists($path) && $res['plg_status'] == 1) { $this->loadPlugin($res, $path); } self::$plugin[$res['plg_name']] = array("status" => $res['plg_status'], "block" => $res['region']); } $this->storeHtmlBlocks(); }
public static function set_promoted_or_demoted_rid() { $user = User\User::get(); $rids = \DB::table(PREFIX . 'codo_promotion_rules')->where(function ($query) use($user) { $query->where('reputation', '<=', $user->reputation)->where('type', '=', 1); })->orWhere(function ($query) use($user) { $query->where('posts', '<=', $user->no_posts)->where('type', '=', 1); })->orWhere(function ($query) use($user) { $query->where('reputation', '<=', $user->reputation)->where('posts', '<=', $user->no_posts)->where('type', '=', 0); })->lists('rid'); $current_roles = \DB::table(PREFIX . 'codo_user_roles')->select('rid', 'is_promoted')->where('uid', '=', $user->id)->get(); $deletions = array(); $additions = array(); $current_rids = array(); foreach ($current_roles as $role) { if ($role['is_promoted'] == '1' && !in_array($role['rid'], $rids)) { //the promoted roles is no longer applicable //demote him i.e remove this role for the user $deletions[] = $role['rid']; } $current_rids[] = $role['rid']; //used in next loop } foreach ($rids as $rid) { if (!in_array($rid, $current_rids)) { //the user has a promoted role which is not added, so add it $additions[] = $rid; } } if (!empty($additions)) { $new_roles = array(); foreach ($additions as $addition) { $new_roles[] = array('uid' => $user->id, 'rid' => $addition, 'is_primary' => 0, 'is_promoted' => 1); } \DB::table(PREFIX . 'codo_user_roles')->insert($new_roles); } if (!empty($deletions)) { \DB::table(PREFIX . 'codo_user_roles')->where('uid', '=', $user->id)->whereIn('rid', $deletions)->delete(); } }