示例#1
1
 public function index($feedtype = 'rss2')
 {
     if (!Kohana::config('settings.allow_feed')) {
         throw new Kohana_404_Exception();
     }
     if ($feedtype != 'atom' and $feedtype != 'rss2') {
         throw new Kohana_404_Exception();
     }
     // How Many Items Should We Retrieve?
     $limit = (isset($_GET['l']) and !empty($_GET['l']) and (int) $_GET['l'] <= 200) ? (int) $_GET['l'] : 20;
     // Start at which page?
     $page = (isset($_GET['p']) and !empty($_GET['p']) and (int) $_GET['p'] >= 1) ? (int) $_GET['p'] : 1;
     $page_position = $page == 1 ? 0 : $page * $limit;
     // Query position
     $site_url = url::base();
     // Cache the Feed with subdomain in the cache name if mhi is set
     $subdomain = '';
     if (substr_count($_SERVER["HTTP_HOST"], '.') > 1 and Kohana::config('config.enable_mhi') == TRUE) {
         $subdomain = substr($_SERVER["HTTP_HOST"], 0, strpos($_SERVER["HTTP_HOST"], '.'));
     }
     $cache = Cache::instance();
     $feed_items = $cache->get($subdomain . '_feed_' . $limit . '_' . $page);
     if ($feed_items == NULL) {
         // Cache is Empty so Re-Cache
         $incidents = ORM::factory('incident')->where('incident_active', '1')->orderby('incident_date', 'desc')->limit($limit, $page_position)->find_all();
         $items = array();
         foreach ($incidents as $incident) {
             $categories = array();
             foreach ($incident->category as $category) {
                 $categories[] = (string) $category->category_title;
             }
             $item = array();
             $item['id'] = $incident->id;
             $item['title'] = $incident->incident_title;
             $item['link'] = $site_url . 'reports/view/' . $incident->id;
             $item['description'] = $incident->incident_description;
             $item['date'] = $incident->incident_date;
             $item['categories'] = $categories;
             if ($incident->location_id != 0 and $incident->location->longitude and $incident->location->latitude) {
                 $item['point'] = array($incident->location->latitude, $incident->location->longitude);
                 $items[] = $item;
             }
         }
         $cache->set($subdomain . '_feed_' . $limit . '_' . $page, $items, array('feed'), 3600);
         // 1 Hour
         $feed_items = $items;
     }
     $feedpath = $feedtype == 'atom' ? 'feed/atom/' : 'feed/';
     header('Content-Type: application/' . ($feedtype == 'atom' ? 'atom' : 'rss') . '+xml; charset=utf-8');
     $view = new View('feed/' . $feedtype);
     $view->feed_title = Kohana::config('settings.site_name');
     $view->site_url = $site_url;
     $view->georss = 1;
     // this adds georss namespace in the feed
     $view->feed_url = $site_url . $feedpath;
     $view->feed_date = gmdate("D, d M Y H:i:s T", time());
     $view->feed_description = Kohana::lang('ui_admin.incident_feed') . ' ' . Kohana::config('settings.site_name');
     $view->items = $feed_items;
     $view->render(TRUE);
 }
示例#2
0
 public function activate($validation_key)
 {
     if (!IN_PRODUCTION) {
         $profiler = new Profiler();
     }
     // TODO: Figure out where to store magic constants.
     if ($validation_key && strlen($validation_key) == 32) {
         $db = Database::instance();
         $email_users_set = $db->select('email_users.email', 'email_users.is_validated', 'user_details.public_api_key', 'user_details.private_api_key')->from('email_users')->join('user_details', array('email_users.user_id' => 'user_details.id'))->where('validation_key', $validation_key)->limit(1)->get();
         if (count($email_users_set)) {
             $email_user_row = null;
             foreach ($email_users_set as $row) {
                 $email_user_row = $row;
                 break;
             }
             if (!$email_user_row->is_validated) {
                 $db->from('email_users')->set('is_validated', '1')->set('validation_key', 'NULL', $disable_escaping = true)->where('email', $email_user_row->email)->update();
             }
             if ($email_user_row->public_api_key) {
                 $this->render_activation_succeeded_view(Kohana::lang('account_messages.activation.success_with_api_keys'));
             } else {
                 $this->render_activation_succeeded_view(Kohana::lang('account_messages.activation.success_without_api_keys'));
             }
         } else {
             $this->render_activation_failed_view(Kohana::lang('account_messages.activation.key_not_found'));
         }
     } else {
         $this->render_activation_failed_view(Kohana::lang('account_messages.activation.key_not_found'));
     }
 }
示例#3
0
 /**
  * 改变状态
  */
 function do_active($id)
 {
     //权限验证
     role::check('user_charge');
     if (!$id) {
         remind::set(Kohana::lang('o_global.bad_request'), 'user/user_charge');
     }
     $db = Database::instance();
     $data = array_shift($db->query('SELECT * FROM user_charge_order WHERE id=' . $id)->result_array(false));
     if ($data['id'] <= 0 || $data['status'] > 0) {
         remind::set(Kohana::lang('o_global.bad_request'), 'user/user_charge');
     }
     $logodata = array();
     $logodata['manager_id'] = $this->manager_id;
     $logodata['ip'] = tool::get_str_ip();
     $logodata['user_log_type'] = 27;
     $logodata['method'] = __CLASS__ . '::' . __METHOD__ . '()';
     $logodata['memo'] = "充值订单号:" . $data['order_num'] . ", 购买拍点数:" . $data['price'] . ", 充值金额:" . $data['money'];
     $sql = "UPDATE user_charge_order SET status=1 WHERE id='" . $id . "' ";
     if ($db->query($sql)) {
         //充值用户Money
         $sql_reward = "UPDATE users \r\n                            SET user_money = user_money+" . $data['price'] . "\r\n                            WHERE id='" . $data['user_id'] . "'\r\n                          ";
         $db->query($sql_reward);
         //操作log
         ulog::add($logodata);
         remind::set(Kohana::lang('o_global.update_success'), 'user/user_charge', 'success');
     } else {
         //操作log
         ulog::add($logodata, 1);
         remind::set(Kohana::lang('o_global.update_error'), 'user/user_charge', 'error');
     }
 }
示例#4
0
 public function index()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     // First is IMAP PHP Library Installed?
     $modules = new Modulecheck();
     if ($modules->isLoaded('imap')) {
         // If SSL Enabled
         $ssl = Kohana::config('settings.email_ssl') == true ? "/ssl" : "";
         // Do not validate certificates (TLS/SSL server)
         //$novalidate = strtolower(Kohana::config('settings.email_servertype')) == "imap" ? "/novalidate-cert" : "";
         $novalidate = "/novalidate-cert";
         // If POP3 Disable TLS
         $notls = strtolower(Kohana::config('settings.email_servertype')) == "pop3" ? "/notls" : "";
         $service = "{" . Kohana::config('settings.email_host') . ":" . Kohana::config('settings.email_port') . "/" . Kohana::config('settings.email_servertype') . $notls . $ssl . $novalidate . "}";
         // Connected!
         if (@imap_open($service, Kohana::config('settings.email_username'), Kohana::config('settings.email_password'), 0, 1)) {
             echo json_encode(array("status" => "success", "message" => Kohana::lang('ui_main.success')));
         } else {
             echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_main.error') . " - " . imap_last_error()));
         }
     } else {
         echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_main.error') . " - " . Kohana::lang('ui_admin.error_imap')));
     }
 }
示例#5
0
 function index()
 {
     $this->template->content = new View('members/dashboard');
     $this->template->content->title = Kohana::lang('ui_admin.dashboard');
     $this->template->this_page = 'dashboard';
     // User
     $this->template->content->user = $this->user;
     // User Reputation Score
     $this->template->content->reputation = reputation::calculate($this->user->id);
     // Get Badges
     $this->template->content->badges = Badge_Model::users_badges($this->user->id);
     // Retrieve Dashboard Counts...
     // Total Reports
     $this->template->content->reports_total = ORM::factory('incident')->where("user_id", $this->user->id)->count_all();
     // Total Unapproved Reports
     $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->where("user_id", $this->user->id)->count_all();
     // Total Checkins
     $this->template->content->checkins = ORM::factory('checkin')->where("user_id", $this->user->id)->count_all();
     // Total Alerts
     $this->template->content->alerts = ORM::factory('alert')->where("user_id", $this->user->id)->count_all();
     // Total Votes
     $this->template->content->votes = ORM::factory('rating')->where("user_id", $this->user->id)->count_all();
     // Total Votes Positive
     $this->template->content->votes_up = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "1")->count_all();
     // Total Votes Negative
     $this->template->content->votes_down = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "-1")->count_all();
     // Get reports for display
     $this->template->content->incidents = ORM::factory('incident')->where("user_id", $this->user->id)->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
     // To support the "welcome" or "not enough info on user" form
     if ($this->user->public_profile == 1) {
         $this->template->content->profile_public = TRUE;
         $this->template->content->profile_private = FALSE;
     } else {
         $this->template->content->profile_public = FALSE;
         $this->template->content->profile_private = TRUE;
     }
     $this->template->content->hidden_welcome_fields = array('email' => $this->user->email, 'notify' => $this->user->notify, 'color' => $this->user->color, 'password' => '', 'needinfo' => 0);
     /*
     // Javascript Header
     $this->template->flot_enabled = TRUE;
     $this->template->js = new View('admin/dashboard_js');
     // Graph
     $this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
     $this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
     */
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     $this->template->js = new View('admin/stats_js');
     $this->template->content->failure = '';
     // Build dashboard chart
     // Set the date range (how many days in the past from today?)
     // Default to one year if invalid or not set
     $range = (isset($_GET['range']) and preg_match('/^\\d+$/', $_GET['range']) > 0) ? (int) $_GET['range'] : 365;
     // Phase 3 - Invoke Kohana's XSS cleaning mechanism just incase an outlier wasn't caught
     $range = $this->input->xss_clean($range);
     $incident_data = Incident_Model::get_number_reports_by_date($range, $this->user->id);
     $data = array('Reports' => $incident_data);
     $options = array('xaxis' => array('mode' => '"time"'));
     $this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
 }
示例#6
0
 public function notify_admins($subject = NULL, $message = NULL)
 {
     // Don't show the exceptions for this operation to the user. Log them
     // instead
     try {
         if ($subject && $message) {
             $settings = kohana::config('settings');
             $from = array();
             $from[] = $settings['site_email'];
             $from[] = $settings['site_name'];
             $users = ORM::factory('user')->where('notify', 1)->find_all();
             foreach ($users as $user) {
                 if ($user->has(ORM::factory('role', 'admin'))) {
                     $address = $user->email;
                     $message .= "\n\n\n\n~~~~~~~~~~~~\n" . Kohana::lang('notifications.admin_footer') . "\n" . url::base() . "\n\n" . Kohana::lang('notifications.admin_login_url') . "\n" . url::base() . "admin";
                     if (!email::send($address, $from, $subject, $message, FALSE)) {
                         Kohana::log('error', "email to {$address} could not be sent");
                     }
                 }
             }
         } else {
             Kohana::log('error', "email to {$address} could not be sent\n\t\t\t\t - Missing Subject or Message");
         }
     } catch (Exception $e) {
         Kohana::log('error', "An exception occured " . $e->__toString());
     }
 }
示例#7
0
 /**
  * Displays all reports.
  */
 public function index()
 {
     $this->template->header->this_page = Kohana::lang('ui_admin.feeds');
     $this->template->content = new View('feeds');
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => ORM::factory('feed_item')->count_all()));
     $feeds = ORM::factory('feed_item')->orderby('item_date', 'desc')->find_all((int) Kohana::config('settings.items_per_page'), $pagination->sql_offset);
     $this->template->content->feeds = $feeds;
     //Set default as not showing pagination. Will change below if necessary.
     $this->template->content->pagination = '';
     // Pagination and Total Num of Report Stats
     if ($pagination->total_items == 1) {
         $plural = '';
     } else {
         $plural = 's';
     }
     if ($pagination->total_items > 0) {
         $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1;
         $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page'));
         if ($total_pages > 1) {
             // If we want to show pagination
             $this->template->content->pagination_stats = Kohana::lang('ui_admin.showing_page') . ' ' . $current_page . ' ' . Kohana::lang('ui_admin.of') . ' ' . $total_pages . ' ' . Kohana::lang('ui_admin.pages');
             $this->template->content->pagination = $pagination;
         } else {
             // If we don't want to show pagination
             $this->template->content->pagination_stats = $pagination->total_items . ' ' . Kohana::lang('ui_admin.feeds');
         }
     } else {
         $this->template->content->pagination_stats = $pagination->total_items . ' ' . Kohana::lang('ui_admin.feeds');
     }
     /*$icon_html = array();
     		$icon_html[1] = "<img src=\"".url::base()."media/img/image.png\">"; //image
     		$icon_html[2] = "<img src=\"".url::base()."media/img/video.png\">"; //video
     		$icon_html[3] = ""; //audio
     		$icon_html[4] = ""; //news
     		$icon_html[5] = ""; //podcast
     		
     		//Populate media icon array
     		$this->template->content->media_icons = array();
     		foreach($incidents as $incident)
     		{
     			$incident_id = $incident->id;
     			if(ORM::factory('media')
                    ->where('incident_id', $incident_id)->count_all() > 0)
     			{
     				$medias = ORM::factory('media')
                               ->where('incident_id', $incident_id)->find_all();
     				
     				//Modifying a tmp var prevents Kohona from throwing an error
     				$tmp = $this->template->content->media_icons;
     				$tmp[$incident_id] = '';
     				
     				foreach($medias as $media)
     				{
     					$tmp[$incident_id] .= $icon_html[$media->media_type];
     					$this->template->content->media_icons = $tmp;
     				}
     			}
     		}*/
 }
示例#8
0
 /**
  * Sends an email alert
  */
 public static function _send_email_alert($post)
 {
     // Email Alerts, Confirmation Code
     $alert_email = $post->alert_email;
     $alert_lon = $post->alert_lon;
     $alert_lat = $post->alert_lat;
     $alert_radius = $post->alert_radius;
     $alert_code = text::random('alnum', 20);
     $settings = kohana::config('settings');
     $to = $alert_email;
     $from = array();
     $from[] = $settings['alerts_email'] ? $settings['alerts_email'] : $settings['site_email'];
     $from[] = $settings['site_name'];
     $subject = $settings['site_name'] . " " . Kohana::lang('alerts.verification_email_subject');
     $message = Kohana::lang('alerts.confirm_request') . url::site() . 'alerts/verify?c=' . $alert_code . "&e=" . $alert_email;
     if (email::send($to, $from, $subject, $message, TRUE) == 1) {
         $alert = ORM::factory('alert');
         $alert->alert_type = self::EMAIL_ALERT;
         $alert->alert_recipient = $alert_email;
         $alert->alert_code = $alert_code;
         $alert->alert_lon = $alert_lon;
         $alert->alert_lat = $alert_lat;
         $alert->alert_radius = $alert_radius;
         if (isset($_SESSION['auth_user'])) {
             $alert->user_id = $_SESSION['auth_user']->id;
         }
         $alert->save();
         self::_add_categories($alert, $post);
         return TRUE;
     }
     return FALSE;
 }
示例#9
0
 public static function AvailLink($hostname, $servicedesc, $start, $end)
 {
     $config = new Config_Model();
     $config->read_config();
     $hostname = urlencode($hostname);
     $servicedesc = urlencode($servicedesc);
     $smon = date('m', $start);
     $sday = date('d', $start);
     $syear = date('Y', $start);
     $shour = date('G', $start);
     $smin = date('i', $start);
     $ssec = date('s', $start);
     $emon = date('m', $end);
     $eday = date('d', $end);
     $eyear = date('Y', $end);
     $ehour = date('G', $end);
     $emin = date('i', $end);
     $esec = date('s', $end);
     $nagios_base = $config->conf['nagios_base'];
     if ($servicedesc == "Host+Perfdata") {
         print "<a href=\"{$nagios_base}/avail.cgi?show_log_entries=&host={$hostname}&timeperiod=custom&smon={$smon}&sday={$sday}&syear={$syear}&shour={$shour}&smin={$smin}&ssec={$ssec}&emon={$emon}&eday={$eday}&eyear={$eyear}&ehour={$ehour}&emin={$emin}&esec={$esec}&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=yes&initialassumedservicestate=6&backtrack=4\"";
     } else {
         print "<a href=\"{$nagios_base}/avail.cgi?show_log_entries=&host={$hostname}&service={$servicedesc}&timeperiod=custom&smon={$smon}&sday={$sday}&syear={$syear}&shour={$shour}&smin={$smin}&ssec={$ssec}&emon={$emon}&eday={$eday}&eyear={$eyear}&ehour={$ehour}&emin={$emin}&esec={$esec}&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=yes&initialassumedservicestate=6&backtrack=4\"";
     }
     print " title=\"" . Kohana::lang('common.nagios-avail-link-title') . "\"><img src=\"" . url::base() . "media/images/trends.gif\" ></a>\n";
 }
示例#10
0
 function index()
 {
     $this->template->content = new View('admin/blocks');
     $this->template->content->title = Kohana::lang('ui_admin.blocks');
     // Get Registered Blocks
     if (!is_array($this->_registered_blocks)) {
         $this->_registered_blocks = array();
     }
     // Get Active Blocks
     $settings = ORM::factory('settings', 1);
     $active_blocks = $settings->blocks;
     $active_blocks = array_filter(explode("|", $active_blocks));
     // setup and initialize form field names
     $form = array('action' => '', 'block' => '');
     //	copy the form as errors, so the errors will be stored with keys corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     $form_action = "";
     if ($_POST) {
         $post = Validation::factory($_POST);
         //	 Add some filters
         $post->pre_filter('trim', TRUE);
         // Add some rules, the input field, followed by a list of checks, carried out in order
         $post->add_rules('action', 'required', 'alpha', 'length[1,1]');
         $post->add_rules('block', 'required', 'alpha_dash');
         if (!array_key_exists($post->block, $this->_registered_blocks)) {
             $post->add_error('block', 'exists');
         }
         if ($post->validate()) {
             // Activate a block
             if ($post->action == 'a') {
                 array_push($active_blocks, $post->block);
                 $settings->blocks = implode("|", $active_blocks);
                 $settings->save();
             } elseif ($post->action == 'd') {
                 $active_blocks = array_diff($active_blocks, array($post->block));
                 $settings->blocks = implode("|", $active_blocks);
                 $settings->save();
             }
         } else {
             $errors = arr::overwrite($errors, $post->errors('blocks'));
             $form_error = TRUE;
         }
     }
     // Sort the Blocks
     $sorted_blocks = blocks::sort($active_blocks, array_keys($this->_registered_blocks));
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     $this->template->content->total_items = count($this->_registered_blocks);
     $this->template->content->registered_blocks = $this->_registered_blocks;
     $this->template->content->active_blocks = $active_blocks;
     $this->template->content->sorted_blocks = $sorted_blocks;
     // Javascript Header
     $this->template->tablerowsort_enabled = TRUE;
     $this->template->js = new View('admin/blocks_js');
 }
示例#11
0
 public function index()
 {
     $route_data = Myroute::instance()->get();
     if ($_POST) {
         $site_next_flow = site::site_next_flow($this->current_flow);
         $submit_target = intval($this->input->post('submit_target'));
         if (Myroute::instance()->edit($_POST)) {
             //判断添加成功去向
             switch ($submit_target) {
                 case 2:
                     remind::set(Kohana::lang('o_global.update_success'), $site_next_flow['url'], 'success');
                 default:
                     remind::set(Kohana::lang('o_global.update_success'), 'site/route', 'success');
             }
         } else {
             remind::set(Kohana::lang('o_global.update_error'), 'site/route');
         }
     }
     $this->template->content = new View("site/route_edit");
     $this->template->content->is_modify = 0;
     if ($this->manager_is_admin == 1) {
         $this->template->content->is_modify = 1;
     }
     $this->template->content->data = $route_data;
     $this->template->content->site_id = $this->site_id;
 }
示例#12
0
 function index()
 {
     $this->template->content = new View('admin/dashboard');
     $this->template->content->title = Kohana::lang('ui_admin.dashboard');
     $this->template->this_page = 'dashboard';
     // Retrieve Dashboard Count...
     // Total Reports
     $this->template->content->reports_total = ORM::factory('incident')->count_all();
     // Total Unapproved Reports
     $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
     // Total Unverified Reports
     $this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
     // Total Categories
     $this->template->content->categories = ORM::factory('category')->count_all();
     // Total Locations
     $this->template->content->locations = ORM::factory('location')->count_all();
     // Total Incoming Media
     $this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
     // Messages By Service
     $total_message_count = 0;
     $message_services = array();
     $services = ORM::factory('service')->find_all();
     foreach ($services as $service) {
         $message_count = ORM::factory('message')->join('reporter', 'message.reporter_id', 'reporter.id')->where('service_id', $service->id)->where('message_type', '1')->count_all();
         $message_services[] = array('id' => $service->id, 'name' => $service->service_name, 'count' => $message_count);
         $total_message_count += $message_count;
     }
     $this->template->content->message_services = $message_services;
     // Total Messages
     $this->template->content->message_count = $total_message_count;
     // Get reports for display
     $incidents = ORM::factory('incident')->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
     $this->template->content->incidents = $incidents;
     // Get Incoming Media (We'll Use NewsFeeds for now)
     $this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
     /*
     // Javascript Header
     $this->template->flot_enabled = TRUE;
     $this->template->js = new View('admin/dashboard_js');
     // Graph
     $this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
     $this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
     */
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     $this->template->js = new View('admin/stats_js');
     $this->template->content->failure = '';
     // Build dashboard chart
     // Set the date range (how many days in the past from today?)
     //    default to one year
     $range = isset($_GET['range']) ? $_GET['range'] : 365;
     if (isset($_GET['range']) and $_GET['range'] == 0) {
         $range = NULL;
     }
     $this->template->content->range = $range;
     $incident_data = Incident_Model::get_number_reports_by_date($range);
     $data = array('Reports' => $incident_data);
     $options = array('xaxis' => array('mode' => '"time"'));
     $this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
 }
示例#13
0
 /**
  * Displays all feeds.
  */
 public function index()
 {
     $this->template->header->this_page = Kohana::lang('ui_admin.feeds');
     $this->template->content = new View('feed/feeds');
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => ORM::factory('feed_item')->count_all()));
     $feeds = ORM::factory('feed_item')->orderby('item_date', 'desc')->find_all((int) Kohana::config('settings.items_per_page'), $pagination->sql_offset);
     $this->template->content->feeds = $feeds;
     //Set default as not showing pagination. Will change below if necessary.
     $this->template->content->pagination = '';
     // Pagination and Total Num of Report Stats
     $plural = $pagination->total_items == 1 ? '' : 's';
     if ($pagination->total_items > 0) {
         $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1;
         $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page'));
         if ($total_pages > 1) {
             // Paginate results
             $pagination_stats = Kohana::lang('ui_admin.showing_page') . ' ' . $current_page . ' ' . Kohana::lang('ui_admin.of') . ' ' . $total_pages . ' ' . Kohana::lang('ui_admin.pages');
             $this->template->content->pagination_stats = $pagination_stats;
             $this->template->content->pagination = $pagination;
         } else {
             // No pagination
             $this->template->content->pagination_stats = $pagination->total_items . ' ' . Kohana::lang('ui_admin.feeds');
         }
     } else {
         $this->template->content->pagination_stats = $pagination->total_items . ' ' . Kohana::lang('ui_admin.feeds');
     }
 }
示例#14
0
 /**
  * Delete image
  * @return void
  * @param integer id of item
  * @param integer id of picture
  * @param string dir with images
  */
 public function delete_image($id, $image, $dir)
 {
     // Check for user permission
     if (user::is_got()) {
         // Page settings
         $this->set_title(Kohana::lang('gallery.delete_image'));
         $this->add_breadcrumb(Kohana::lang('gallery.delete_image'), url::current());
         // Set redirect URL
         if (isset($_POST['redirect'])) {
             $redirect = $_POST['redirect'];
         } else {
             $redirect = request::referrer();
         }
         $form = array('redirect' => $redirect);
         if ($_POST) {
             if (isset($_POST['yes'])) {
                 // Clicked on yes = delete image
                 unlink('./data/' . $dir . '/' . $id . '_' . $image . '.jpg');
                 unlink('./data/' . $dir . '/' . $id . '_' . $image . '_m.jpg');
                 url::redirect($form['redirect']);
             } else {
                 url::redirect($form['redirect']);
             }
         }
         // View
         $this->template->content = new View('admin/delete_image');
         $this->template->content->form = $form;
     }
 }
示例#15
0
 /**
  * 物流对应的地区列表
  */
 function index($id)
 {
     if (!$id) {
         remind::set(Kohana::lang('o_global.bad_request'), request::referrer(), 'error');
     }
     $deliverycn_service = DeliverycnService::get_instance();
     $deliverycn_region_service = Deliverycn_regionService::get_instance();
     //验证此条物流
     $data = $deliverycn_service->get($id);
     if (!$data['id']) {
         remind::set(Kohana::lang('o_global.access_denied'), request::referrer(), 'error');
     }
     //初始化请求结构体
     $query_struct = array('where' => array('deliverycn_id' => $id), 'like' => array(), 'orderby' => array('position' => 'ASC', 'id' => 'ASC'), 'limit' => array('per_page' => 2000, 'offset' => 0));
     // 每页条目数
     controller_tool::request_per_page($query_struct, $request_data);
     $count = $deliverycn_region_service->query_count($query_struct);
     // 模板输出 分页
     $this->pagination = new Pagination(array('total_items' => $count, 'items_per_page' => $query_struct['limit']['per_page']));
     $query_struct['limit']['offset'] = $this->pagination->sql_offset;
     $query_struct['limit']['page'] = $this->pagination->current_page;
     //调用列表
     $deliverycn_regions = $deliverycn_region_service->get_delivery_regions_by_position($query_struct);
     $this->template->content = new View("site/deliverycn/region");
     $this->template->content->deliverycn_regions = $deliverycn_regions;
     $this->template->content->data = $data;
     $this->template->content->regions = $deliverycn_region_service->get_regions();
 }
示例#16
0
 /**
  * Show latest PER_PAGE news on page
  * @return void
  */
 public function index($module = NULL, $page = 1)
 {
     $this->set_title(Kohana::lang('search.search'));
     if ($page == 1) {
         $this->add_breadcrumb(Kohana::lang('search.the_best_results'), url::current());
     } else {
         $this->add_breadcrumb(Kohana::lang('search.page_no') . ' ' . $page, url::current());
     }
     // Default values
     $form = array('value' => '');
     $errors = array();
     if ($_POST) {
         $post = new Validation($_POST);
         // Some filters
         $post->pre_filter('trim', TRUE);
         // Rules
         $post->add_rules('value', 'required');
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // Repopulate form with error and original values
             $form = arr::overwrite($form, $post->as_array());
             $errors = $post->errors('search_errors');
         }
     }
     $this->template->content = new View('search');
     $data = $this->products->search($post['value']);
     $data2 = $this->page->search($post['value']);
     $data3 = $this->news->search($post['value']);
     $this->template->content->data = $data;
     $this->template->content->data2 = $data2;
     $this->template->content->data3 = $data3;
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
 }
示例#17
0
 public static function is_allowed($permission = 'default', $site_id = 0, $type = NULL)
 {
     $verify = true;
     $site_ids = role::get_site_ids($type);
     //超级管理员root不需要检查权限 zhu modify
     if (role::is_root()) {
         $verify = true;
     } else {
         if ($site_id > 0 && !in_array($site_id, $site_ids)) {
             $verify = false;
         }
         $acl = Session::instance()->get(self::$acl_tag);
         if ($acl) {
             $acl = unserialize($acl);
         } else {
             $acl = self::acl_init();
         }
         $manager = role::get_manager();
         $verify = $acl->is_allowed($manager["username"], $permission);
     }
     //验证操作
     if ($verify) {
         return $site_ids;
     } else {
         if (request::is_ajax()) {
             $return_struct = array('status' => 0, 'code' => 501, 'msg' => Kohana::lang('o_global.access_denied'), 'content' => array());
             die(json_encode($return_struct));
         } else {
             $referrer = tool::referrer_url();
             remind::set('权限不足', $referrer, 'error');
         }
     }
 }
示例#18
0
 /**
  * Methode : page envoyer le mailing
  */
 public function envoyer()
 {
     if ($_POST) {
         $texte = $this->input->post('texte');
         $format = $this->input->post('format');
         $sujet = $this->input->post('sujet');
         $format = $format == 1 ? TRUE : FALSE;
         $users = $this->user->select();
         $nbr_envois = 0;
         foreach ($users as $user) {
             if ($format) {
                 $view = new View('mailing/template');
                 $view->name = ucfirst(mb_strtolower($user->username));
                 $view->content = $texte;
                 $message = $view->render();
             } else {
                 $message = $texte;
             }
             if (email::send($user->email, Kohana::config('email.from'), $sujet, $message, $format)) {
                 $nbr_envois++;
             }
         }
         return url::redirect('mailing?msg=' . urlencode(Kohana::lang('mailing.send_valide', number_format($nbr_envois))));
     } else {
         return parent::redirect_erreur('mailing');
     }
 }
示例#19
0
 public function basket()
 {
     $basket = $this->session->get("basket");
     if ($this->view == "") {
         $this->view = $this->config->conf['overview-range'];
     }
     if (is_array($basket) && sizeof($basket) > 0) {
         foreach ($basket as $item) {
             list($host, $service) = explode("::", $item);
             $this->data->buildDataStruct($host, $service, $this->view);
         }
         $this->template->page->basket_box = $this->add_view('basket_box');
         $this->template->page->header->title = Kohana::lang('common.page-basket');
         $this->url = "basket?";
         // Timerange Box Vars
         $this->template->page->timerange_box = $this->add_view('timerange_box');
         $this->template->page->timerange_box->timeranges = $this->data->TIMERANGE;
         // Pages Box
         $this->pages = $this->data->getPages();
         $this->template->page->pages_box = $this->add_view('pages_box');
         $this->template->page->pages_box->pages = $this->pages;
         // Icon Box
         $this->template->page->icon_box = $this->add_view('icon_box');
         $this->template->page->icon_box->position = "basket";
     } else {
         url::redirect("start", 302);
     }
 }
示例#20
0
 public function i18n_stuff()
 {
     $element = Event::$data;
     // skip the __form_object and already internationalized elements
     if ($element->name != '__form_object' and !in_array('i18nd', $element->attributes)) {
         // fetch label's i18n string, if not found use element's name
         if ($element->label and !in_array($element->type, array('button', 'submit'))) {
             if (Kohana::lang($this->i18n_labels . $element->name) == $this->i18n_labels . $element->name) {
                 $element->label = ucfirst($element->name);
             } else {
                 $element->label = Kohana::lang($this->i18n_labels . $element->name);
             }
         }
         // fetch button's i18n string, if not found use element's original value
         if (in_array($element->type, array('button', 'submit'))) {
             if (Kohana::lang($this->i18n_buttons . $element->name) == $this->i18n_buttons . $element->name) {
                 $element->value = ucfirst($element->value);
             } else {
                 $element->value = Kohana::lang($this->i18n_buttons . $element->name);
             }
         }
         // fetch error's i18n string, if not found use element's original error
         if ($element->error and $element->error_msg_class != 'comment') {
             if (Kohana::lang($this->i18n_errors . $element->error) == $this->i18n_errors . $element->error) {
                 $element->error = ucfirst($element->error);
             } else {
                 $element->error = Kohana::lang($this->i18n_errors . $element->error);
             }
         }
         // mark the element as internationalized
         $element->add_attribute('i18nd');
     }
 }
示例#21
0
文件: user.php 项目: momoim/momo-api
 /**
  * 用户登陆
  * @method POST
  */
 public function login()
 {
     $post = $this->get_data();
     $mobile = trim($post['mobile']);
     $zone_code = $post['zone_code'] ? trim($post['zone_code']) : ($post['zonecode'] ? trim($post['zonecode']) : '86');
     $zone_code = str_replace('+', '', $zone_code);
     $password = trim($post['password']);
     if (empty($mobile)) {
         $this->send_response(400, NULL, '40001:手机号为空');
     }
     if (!international::check_is_valid($zone_code, $mobile)) {
         $this->send_response(400, NULL, '40002:手机号码格式不对');
     }
     if ($password == "") {
         $this->send_response(400, NULL, '40003:密码为空');
     }
     $user = $this->model->get_user_by_mobile($zone_code, $mobile);
     if (!$user) {
         $this->send_response(400, NULL, Kohana::lang('user.mobile_not_register'));
     }
     if (!password_verify($password, $user['password'])) {
         $this->send_response(400, NULL, Kohana::lang('user.username_password_not_match'));
     }
     $token = $this->model->create_token(3600, TRUE, array('zone_code' => $user['zone_code'], 'mobile' => $user['mobile'], 'id' => (int) $user['id']));
     $this->send_response(200, array('id' => (int) $user['uid'], 'name' => $user['username'], 'avatar' => sns::getavatar($user['uid']), 'access_token' => $token['access_token'], 'refresh_token' => $token['refresh_token'], 'expires_in' => $token['expires_in']));
 }
示例#22
0
 /**
  * Permission denied page
  * @return void 
  */
 public function index()
 {
     // Page settings
     $this->add_breadcrumb(Kohana::lang('denied.denied'), url::current());
     $this->set_title(Kohana::lang('denied.denied'));
     // View
     $this->template->content = new View('denied');
 }
示例#23
0
 public static function add_to_basket_icon($host, $service, $source = FALSE)
 {
     if ($source === FALSE) {
         print "<span id=\"basket_action_add\"><a title=\"" . Kohana::lang('common.basket-add-service') . "\" id=\"" . $host . "::" . $service . "\"><img width=12px height=12px src=\"" . url::base() . "media/images/add.png\"></a></span>\n";
     } else {
         print "<span id=\"basket_action_add\"><a title=\"" . Kohana::lang('common.basket-add-item') . "\" id=\"" . $host . "::" . $service . "::" . $source . "\"><img width=16px height=16px src=\"" . url::base() . "media/images/add.png\"></a></span>\n";
     }
 }
示例#24
0
 /**
  * Render Custom 404 Error Page
  */
 public function error_404()
 {
     Header("HTTP/1.0 404 Not Found");
     $this->layout = new View('error');
     $this->layout->title = Kohana::lang('ui_admin.page_not_found');
     $this->layout->content = Kohana::lang('ui_admin.page_not_found_message');
     $this->layout->render(true);
 }
 /**
  * Demonstrates how to parse RSS feeds by using DOMDocument.
  */
 function rss()
 {
     // Parse an external atom feed
     $feed = feed::parse('http://trac.kohanaphp.com/timeline?changeset=on&format=rss');
     // Show debug info
     echo Kohana::debug($feed);
     echo Kohana::lang('core.stats_footer');
 }
示例#26
0
 /**
  * Demonstrates how to parse RSS feeds by using DOMDocument.
  */
 function rss()
 {
     // Parse an external atom feed
     $feed = feed::parse('http://dev.kohanaphp.com/projects/kohana2/activity.atom');
     // Show debug info
     echo Kohana::debug($feed);
     echo Kohana::lang('core.stats_footer');
 }
 public function __toString()
 {
     $line = '';
     $line .= isset($this->user_id) ? Kohana::lang('ui_admin.edited_by') . " " . $this->user->name . ". " : '';
     $line .= $this->changed_data() ? Kohana::lang('revision.changed_fields') . " " . $this->changed_data_str() . " " : '';
     $line .= "(" . $this->time . ")";
     return $line;
 }
示例#28
0
 /**
  * Méthode : Logout un utilisateur via le lien quitter de menu top
  */
 public function logout()
 {
     $authentic = Auth::instance();
     if ($authentic->logged_in()) {
         $authentic->logout(true);
     }
     return self::redirection(Kohana::lang('logger.disconnect'));
 }
示例#29
0
 private function _receive()
 {
     $secret = "";
     $success = "false";
     //Sometimes user send blank SMSs or GSM operators will
     //send promotional SMSs with no phone number, so this way
     //these messages will always end up on the backend and not float around
     //on the phones forever.
     $message_description = Kohana::lang("ui_main.empty");
     $message_from = "00000000";
     $non_numeric_source = false;
     if (isset($this->request['secret'])) {
         $secret = $this->request['secret'];
     }
     if (isset($this->request['from']) && strlen($this->request['from']) > 0) {
         $message_from = $this->request['from'];
         $original_from = $message_from;
         $message_from = preg_replace("#[^0-9]#", "", $message_from);
         if (strlen($message_from) == 0) {
             $message_from = "00000000";
             $non_numeric_source = true;
         }
     }
     if (isset($this->request['message']) && strlen($this->request['message']) > 0) {
         $message_description = $this->request['message'];
     }
     if ($non_numeric_source) {
         $message_description = '<div style="color:red;">' . Kohana::lang("ui_main.message_non_numeric_source") . " \"" . $original_from . "\" </div>" . $message_description;
     }
     if (!empty($message_from) and !empty($message_description)) {
         $secret_match = TRUE;
         // Is this a valid Secret?
         $smssync = ORM::factory('smssync_settings')->find(1);
         if ($smssync->loaded) {
             $smssync_secret = $smssync->smssync_secret;
             if ($smssync_secret and $secret != $smssync_secret) {
                 // A Secret has been set and they don't match
                 $secret_match = FALSE;
             }
         } else {
             // No Secret Set
             $secret_match = TRUE;
         }
         if ($secret_match) {
             if (stristr($message_description, "alert")) {
                 alert::mobile_alerts_register($message_from, $message_description);
                 $success = "true";
             } elseif (stristr($message_description, "off")) {
                 alert::mobile_alerts_unsubscribe($message_from, $message_description);
                 $success = "true";
             } else {
                 sms::add($message_from, $message_description);
                 $success = "true";
             }
         }
     }
     echo json_encode(array("payload" => array("success" => $success)));
 }
示例#30
0
 public function validate()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array('assoc' => NULL, 'count' => 0);
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         if (empty($request_data['product_id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         if (empty($request_data['goods']) or !is_array($request_data['goods'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         try {
             $product = BLL_Product::get($request_data['product_id']);
         } catch (MyRuntimeException $ex) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         foreach ($request_data['goods'] as $index => $good) {
             if (isset($good['sku'])) {
                 empty($good['id']) and $good['id'] = 0;
                 if (BLL_Product_Type_Assembly::good_sku_exists($good['sku'], $good['id'])) {
                     throw new MyRuntimeException(sprintf(Kohana::lang('o_product.good_sku_has_exists'), $index), 403);
                 }
             } else {
                 throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
             }
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             //* html 输出 ==根据业务逻辑定制== */
             $this->template = new View('layout/commonfix_html');
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View($this->package_name . '/product/merge/list');
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }