/** * @author goFrendiAsgard * @param parent_id, max_menu_depth * @desc return navigation child if parent_id specified, else it will return root navigation */ public final function cms_widgets() { $user_name = $this->cms_username(); $user_id = $this->cms_userid(); $not_login = !$user_name ? "TRUE" : "FALSE"; $login = $user_name ? "TRUE" : "FALSE"; $super_user = $user_id == 1 ? "TRUE" : "FALSE"; $query = $this->db->query("SELECT \n \t\t\twidget_id, widget_name, is_static, title, \n \t\t\tdescription, url, slug, static_content \n FROM cms_widget AS w WHERE\n ( \n (authorization_id = 1) OR\n (authorization_id = 2 AND {$not_login}) OR\n (authorization_id = 3 AND {$login}) OR\n (\n (authorization_id = 4 AND {$login}) AND \n (\n (SELECT COUNT(*) FROM cms_group_user AS gu WHERE gu.group_id=1 AND gu.user_id ='" . addslashes($user_id) . "')>0\n OR {$super_user} OR\n (SELECT COUNT(*) FROM cms_group_widget AS gw\n WHERE \n gw.widget_id=w.widget_id AND\n gw.group_id IN \n (SELECT group_id FROM cms_group_user WHERE user_id = '" . addslashes($user_id) . "')\n )>0\n )\n )\n ) AND active=1"); $result = array(); foreach ($query->result() as $row) { // generate widget content $content = ''; if ($row->is_static == 1) { $content = $this->cms_parse_keyword($row->static_content); } else { // url $url = $row->url; if (!strpos(strtolower($url), 'http')) { $url = base_url($url); } // script $script = '$.ajax({'; $script .= 'url:"' . $url . '",'; $script .= 'data:{_only_content:true},'; $script .= 'success:function(response){'; $script .= '$("div#_cms_widget_' . $row->widget_id . '").html(response);'; $script .= '}'; $script .= '});'; // asset $asset = new CMS_Asset(); $asset->add_cms_js('nocms/js/jquery.js'); $asset->add_string_js($script); // content $content .= '<div id="_cms_widget_' . $row->widget_id . '">'; $content .= $asset->compile_js(true); $content .= '</div>'; } // make widget based on slug if (!isset($result[$row->slug])) { $result[$row->slug] = array(); } $result[$row->slug][] = array("widget_id" => $row->widget_id, "widget_name" => $row->widget_name, "title" => $this->cms_lang($row->title), "description" => $row->description, "content" => $content); } return $result; }