Esempio n. 1
0
 public function actionAdv()
 {
     // renders the view file 'protected/views/site/index.php'
     // using the default layout 'protected/views/layouts/main.php'
     $model = new Notices('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['Notices'])) {
         $model->attributes = $_GET['Notices'];
     }
     $this->render('adv', array('model' => $model));
 }
Esempio n. 2
0
 /**
  * Creates a notice and ensures the type/message combo is unique
  *
  * @param	string	 $type
  * @param	string	 $msg_key
  * @param	array	 $values
  * @param	boolean	 $persistent
  */
 public function __construct($type, $msg_key, array $values = NULL, $persistent = FALSE)
 {
     parent::__construct($type, $msg_key, $values, $persistent);
     foreach (Notices::get_all($this->type) as $notice) {
         if ($this->similar_to($notice)) {
             throw new Exception('The new notice is not unique.');
         }
     }
 }
 public function actionIndex()
 {
     $this->pageTitle = "论坛首页";
     // 论坛公告
     $notices = Notices::model()->find();
     // 讨论区类别
     $bbsType = BbsType::model()->findAll();
     // 话题计数
     $bbsCount = BbsInfo::model()->count();
     // 回帖计数
     $revCount = Reviews::model()->count();
     // 用户计数
     $userCount = UserInfo::model()->count();
     // 绑定数据
     $data = array('notices' => $notices, 'bbsType' => $bbsType, 'bbsCount' => $bbsCount, 'revCount' => $revCount, 'userCount' => $userCount);
     $this->render('index', $data);
 }
 /**
  * Test the Notices::add_unique(...) method
  *
  * @test
  * @dataProvider providerAddUnique
  */
 public function testAddUnique($type, $message, $persist, $allowed)
 {
     // Put an initial Notice in the Notices queue
     $original = Notices::add('success', 'You have succeeded!', FALSE);
     // Try to create a unique Notice
     $result = Notices::add_unique($type, $message, $persist);
     // Retrieve the Notices queue
     $notices = Session::instance()->get('notices', array());
     // Make sure that uniqueness is enforced
     $this->assertSame($allowed, (bool) $result);
     // If it was unique, perform assertions similar to testAdd
     if ($result) {
         // Make sure the result is a Notice
         $this->assertTrue($result instanceof Notice);
         // Make sure the result was added to the session
         $this->assertTrue(isset($notices[$result->hash]));
         // Make sure the notice in the session matches the result
         $this->assertTrue($result->similar_to($notices[$result->hash]));
     }
 }
Esempio n. 5
0
function set_server_config_notices()
{
    $notices = Notices::get_instance();
    $messages = array();
    if (!is_dir(Path::get_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable. Please create the folder manually.', 'backupwordpress'), '<code>' . esc_html(dirname(Path::get_path())) . '</code>');
    }
    if (is_dir(Path::get_path()) && !wp_is_writable(Path::get_path())) {
        $messages[] = __('The backups directory isn\'t writable. Please fix the permissions.', 'backupwordpress');
    }
    if (Backup_Utilities::is_safe_mode_on()) {
        $messages[] = sprintf(__('%1$s is running in %2$s, please contact your host and ask them to disable it. BackUpWordPress may not work correctly whilst %3$s is on.', 'backupwordpress'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'backupwordpress'), __('Safe Mode', 'backupwordpress')), '<code>' . __('Safe Mode', 'backupwordpress') . '</code>');
    }
    if (defined('HMBKP_PATH') && HMBKP_PATH) {
        // Suppress open_basedir warning https://bugs.php.net/bug.php?id=53041
        if (!path_in_php_open_basedir(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your server has an %1$s restriction in effect and your custom backups directory (%2$s) is not within the allowed path(s): (%3$s).', 'backupwordpress'), '<code>open_basedir</code>', '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(@ini_get('open_basedir')) . '</code>');
        } elseif (!file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress'));
        } else {
            if (!is_dir(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
            if (is_dir(HMBKP_PATH) && !wp_is_writable(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
        }
    }
    if (!is_readable(Path::get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . Path::get_root() . '</code>');
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        $messages[] = sprintf(__('Your database cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>mysqldump</code>', '<code>PDO</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}
Esempio n. 6
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
Route::set('notice-add', 'notice/add/<type>/<message>(/<persist>)')->defaults(array('controller' => 'notice', 'action' => 'add', 'persist' => FALSE));
Route::set('notice-remove', 'notice/remove/<hash>')->defaults(array('controller' => 'notice', 'action' => 'remove'));
Notices::init();
Esempio n. 7
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Notices the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Notices::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Esempio n. 8
0
/**
 * Dismiss an error and then redirect back to the backups page
 */
function dismiss_error()
{
    Path::get_instance()->cleanup();
    Notices::get_instance()->clear_all_notices();
    wp_safe_redirect(wp_get_referer(), 303);
    die;
}
Esempio n. 9
0
 public function noticeDelete()
 {
     $notice_id = Input::get('deleteId');
     Notices::find($notice_id)->delete();
     return Redirect::to('notice-edit');
 }
Esempio n. 10
0
 private function reset_notices()
 {
     $reflection = new \ReflectionClass(Notices::get_instance());
     $instance = $reflection->getProperty('instance');
     $instance->setAccessible(true);
     $instance->setValue(null, null);
     $instance->setAccessible(false);
     $this->notices = Notices::get_instance();
 }
Esempio n. 11
0
 /**
  * The `__callStatic()` allows the creation of notices using the shorter
  * syntax: `Notices::success('message');` This works for PHP 5.3+ only
  *
  * @param	string	$method  Method name
  * @param	array	$args    method arguments
  * @return	mixed
  */
 public static function __callStatic($method, $args)
 {
     if (strpos($method, Notices::UNIQUE_PREFIX) === 0) {
         return Notices::add_unique(substr($method, strlen(Notices::UNIQUE_PREFIX)), Arr::get($args, 0), Arr::get($args, 1), Arr::get($args, 2));
     } else {
         return Notices::add($method, Arr::get($args, 0), Arr::get($args, 1), Arr::get($args, 2));
     }
 }
Esempio n. 12
0
 /**
  * Adds a new Notice and sends the rendered HTML as a repsonse
  *
  * @ajax
  * @param   string  type
  * @param   string  message
  * @param   string  persist
  */
 public function action_add()
 {
     if (!Request::$is_ajax) {
         throw new Kohana_Request_Exception('Trying to access an AJAX method without AJAX.');
     }
     $type = strtolower(urldecode($this->request->param('type')));
     $message = urldecode($this->request->param('message'));
     $persist = (bool) $this->request->param('persist');
     $response = array('status' => 'success', 'message' => 'A Notice was added.', 'data' => NULL);
     try {
         $type = urldecode($type);
         $message = urldecode($message);
         $persist = (bool) $persist == 'TRUE';
         $notice = Notices::add($type, $message, $persist);
         $response['message'] = 'Notice ' . $notice->hash . ' was added.';
         $response['data'] = $notice->render();
         Notices::save();
     } catch (Exception $e) {
         $response['status'] = 'error';
         $response['message'] = 'The was a problem adding the Notice.';
     }
     $this->request->response = json_encode($response);
 }
Esempio n. 13
0
function display_error_and_offer_to_email_it()
{
    check_ajax_referer('hmbkp_nonce', 'nonce');
    if (empty($_POST['hmbkp_error'])) {
        die;
    }
    $errors = explode("\n", wp_strip_all_tags(stripslashes($_POST['hmbkp_error'])));
    Notices::get_instance()->set_notices('backup_errors', $errors);
    wp_send_json_success(wp_get_referer());
}
Esempio n. 14
0
					persist = (persist == 'TRUE');
					$('#notices-container').add_notice(type, message, persist);
				});
			});
		</script>
	</head>
	<body>
		<h1>Notices Demo</h1>
		<p>Number of notices in queue <em>before</em> display: <?php 
echo Notices::count();
?>
</p>

		<div id="notices-container">
			<?php 
echo Notices::display();
?>
		</div>

		<br />

		<fieldset>
			<legend><h2>Add a Notice via AJAX</h2></legend>
			<p>
				<label for="type">Notice Type (can be anything):</label>
				<br />
				<input id="type" type="text" />
			</p>
			<p>
				<label for="message">Message:</label>
				<br />
Esempio n. 15
0
 public function saveItem()
 {
     $cat_id = Input::get('cat_id');
     $item_id = Input::get('id');
     //获取表单
     if ($cat_id == 0) {
         //新闻编辑
         $title = Input::get('title');
         $content = Input::get('content');
         $abstract = Input::get('abstract');
         $item = News::find($item_id);
     } else {
         if ($cat_id == 1) {
             //项目编辑
             $title = Input::get('title');
             $content = Input::get('content');
             $abstract = Input::get('abstract');
             $begin_time = Input::get('begin_time');
             $end_time = Input::get('end_time');
             $item = Researches::find($item_id);
         } else {
             if ($cat_id == 2) {
                 //通知编辑
                 //
                 $title = Input::get('title');
                 $content = Input::get('content');
                 $item = Notices::find($item_id);
             } else {
                 if ($cat_id == 3) {
                     //课程编辑
                     $course_name = Input::get('course_name');
                     $course_info = Input::get('course_info');
                     $teacher_address = Input::get('teacher_address');
                     $teacher_mail = Input::get('teacher_mail');
                     $TA_name = Input::get('TA_name');
                     $TA_address = Input::get('TA_address');
                     $TA_mail = Input::get('TA_mail');
                     $item = Courses::find($item_id);
                     $homeworks = Courses::find($item_id)->homework;
                     $coursewares = Courses::find($item_id)->courseware;
                     $course_notices = Courses::find($item_id)->comments;
                     foreach ($course_notices as $notice) {
                         $update_notice = Comments::find($notice->id);
                         $update_notice->comment = Input::get('course_notice_content' . $notice->id);
                         $update_notice->updated_at = date("Y-m-d H:i:s");
                         $update_notice->save();
                     }
                     foreach ($homeworks as $homework) {
                         //对已有项进行编辑
                         $delete_or_not = Input::get('homework_delete' . $homework->id);
                         if ($delete_or_not) {
                             //如果标记为删除则将已有作业进行删除
                             $delete_item = Homework::find($homework->id);
                             $delete_item->delete();
                         } else {
                             $update_item = Homework::find($homework->id);
                             $update_item->homework_item = Input::get('homework_label' . $homework->id);
                             $update_item->submit_deadline = Input::get('homework_submit_time' . $homework->id);
                             $update_item->deliver_deadline = Input::get('homework_deliver_time' . $homework->id);
                             $update_item->updated_at = date("Y-m-d H:i:s");
                             $update_item->save();
                         }
                     }
                     foreach ($coursewares as $courseware) {
                         $update_item = Courseware::find($courseware->id);
                         $update_item->label = Input::get('courseware_label' . $courseware->id);
                         $update_file_source = 'courseware_ppt' . $courseware->id;
                         $new_source = HomeController::upload_course($item_id, $update_file_source);
                         if ($new_source != "") {
                             //跟新源的同时将旧的课件删除
                             HomeController::delete_file($update_item->source);
                             $update_item->source = $new_source;
                         } else {
                         }
                         $update_item->updated_at = date("Y-m-d H:i:s");
                         $update_item->save();
                     }
                 }
             }
         }
     }
     //保存数据
     if ($item) {
         //表中已经存在该条目
         if ($cat_id == 0) {
             //新闻编辑
             $item->title = $title;
             $item->content = $content;
             $item->abstract = $abstract;
             $item->save();
             return Redirect::to(URL::to('/news-detail', [$item_id]));
         } else {
             if ($cat_id == 1) {
                 //项目编辑
                 $item->title = $title;
                 $item->content = $content;
                 $item->abstract = $abstract;
                 $item->begin_time = $begin_time;
                 $item->end_time = $end_time;
                 $item->save();
                 return Redirect::to(URL::to('/research-detail', [$item_id]));
             } else {
                 if ($cat_id == 2) {
                     //通知编辑
                     $item->title = $title;
                     $item->content = $content;
                     $item->save();
                     return Redirect::to(URL::to('/notice-detail', [$item_id]));
                 } else {
                     if ($cat_id == 3) {
                         //课程编辑
                         $item->course_name = $course_name;
                         $item->course_info = $course_info;
                         $item->teacher_address = $teacher_address;
                         $item->teacher_mail = $teacher_mail;
                         $item->TA_name = $TA_name;
                         $item->TA_address = $TA_address;
                         $item->TA_mail = $TA_mail;
                         $item->save();
                         $course_notices_add_count = Input::get('course_notice_add_count');
                         if ($course_notices_add_count) {
                             //增加新的通知
                             for ($i = 1; $i <= $course_notices_add_count; $i++) {
                                 $add_or_not = Input::get('course_notice_add_or_not' . $i);
                                 if (!$add_or_not) {
                                     $notice = new Comments();
                                     $notice->course_id = $item_id;
                                     $notice->comment = Input::get('course_notice_add_content' . $i);
                                     $notice->created_at = date("Y-m-d H:i:s");
                                     $notice->updated_at = date("Y-m-d H:i:s");
                                     $notice->save();
                                 }
                             }
                         }
                         $homework_add_count = Input::get('homework_add_count');
                         if ($homework_add_count) {
                             //当添加了新的作业,将其添加到homework数据库中
                             for ($i = 1; $i <= $homework_add_count; $i++) {
                                 $add_or_not = Input::get('homework_add_or_not' . $i);
                                 if (!$add_or_not) {
                                     $homework = new Homework();
                                     $homework->course_id = $item_id;
                                     $homework->homework_item = Input::get('homework_add_item' . $i);
                                     $homework->submit_deadline = Input::get('homework_add_submit_time' . $i);
                                     $homework->deliver_deadline = Input::get('homework_add_deliver_time' . $i);
                                     $homework->created_at = date("Y-m-d H:i:s");
                                     $homework->updated_at = date("Y-m-d H:i:s");
                                     $homework->save();
                                 }
                             }
                         }
                         $courseware_add_count = Input::get('courseware_add_count');
                         if ($courseware_add_count) {
                             //当添加了新的课件,将其添加到courseware表中
                             for ($i = 1; $i <= $courseware_add_count; $i++) {
                                 $courseware = new Courseware();
                                 $courseware->course_id = $item_id;
                                 $courseware->label = Input::get('courseware_add_label' . $i);
                                 //先将课件上传到数据库中
                                 $file_source = 'courseware_add_source' . $i;
                                 $courseware->source = HomeController::upload_course($item_id, $file_source);
                                 $courseware->created_at = date("Y-m-d H:i:s");
                                 $courseware->updated_at = date("Y-m-d H:i:s");
                                 $courseware->save();
                             }
                         }
                         return Redirect::to(URL::to('/course', [$item_id]));
                     }
                 }
             }
         }
     } else {
         //对已有条目进行更新
         if ($cat_id == 0) {
             //新闻条目
             News::insert(['title' => $title, 'abstract' => $abstract, 'content' => $content]);
             $item = News::all()->last();
             return Redirect::to(URL::to('/news-detail', [$item->id]));
         } else {
             if ($cat_id == 1) {
                 //项目条目
                 Researches::insert(['title' => $title, 'abstract' => $abstract, 'content' => $content, 'begin_time' => $begin_time, 'end_time' => $end_time]);
                 $item = Researches::all()->last();
                 return Redirect::to(URL::to('/research-detail', [$item->id]));
             } else {
                 if ($cat_id == 2) {
                     //通知编辑
                     Notices::insert(['title' => $title, 'content' => $content]);
                     $item = Notices::all()->last();
                     return Redirect::to(URL::to('/notice-detail', [$item->id]));
                 } else {
                     if ($cat_id == 3) {
                         Courses::insert(['course_name' => $course_name, 'course_info' => $course_info, 'teacher_address' => $teacher_address, 'TA_name' => $TA_name, 'TA_address' => $TA_address]);
                         $item = Courses::all()->last();
                         return Redirect::to(URL::to('/course', [$item->id]));
                     }
                 }
             }
         }
     }
     //return View::make('/news-detail',[$item_id]);
 }
Esempio n. 16
0
 /**
  * Return messages recorded by this object
  *
  * @param string|array $options One or more of array elements or space separated string of:
  * 	first: only first item will be returned (string)
  * 	last: only last item will be returned (string)
  * 	all: include all items of type (messages or errors) beyond the scope of this object
  * 	clear: clear out all items that are returned from this method (includes both local and global)
  * 	errors: returns errors rather than messages.
  * @return Notices|string Array of NoticeError error messages or string if last, first or str option was specified.
  *
  */
 public function messages($options = array())
 {
     if (!is_array($options)) {
         $options = explode(' ', strtolower($options));
     }
     $type = in_array('errors', $options) ? 'errors' : 'messages';
     $clear = in_array('clear', $options);
     if (in_array('all', $options)) {
         // get all of either messages or errors (either in or out of this object instance)
         $value = new Notices();
         foreach ($this->wire('notices') as $notice) {
             if ($notice->getName() != $type) {
                 continue;
             }
             $value->add($notice);
             if ($clear) {
                 $this->wire('notices')->remove($notice);
             }
             // clear global
         }
         if ($clear) {
             $this->_notices[$type] = null;
         }
         // clear local
     } else {
         // get messages or errors specific to this object instance
         $value = is_null($this->_notices[$type]) ? new Notices() : $this->_notices[$type];
         if (in_array('first', $options)) {
             $value = $clear ? $value->shift() : $value->first();
         } else {
             if (in_array('last', $options)) {
                 $value = $clear ? $value->pop() : $value->last();
             } else {
                 if ($clear) {
                     $this->_notices[$type] = null;
                 }
             }
         }
         if ($clear && $value) {
             $this->wire('notices')->removeItems($value);
         }
         // clear from global notices
     }
     return $value;
 }
 /**
  * Run the backup
  *
  */
 public function run()
 {
     // Don't run if this schedule is already running
     if ($this->status->is_started()) {
         return;
     }
     // Setup our Site Backup Object
     $backup = new Backup($this->get_backup_filename(), $this->get_database_dump_filename());
     $backup->set_type($this->get_type());
     $backup->set_excludes($this->get_excludes());
     $backup->set_status($this->status);
     $this->do_action('hmbkp_backup_started', $backup);
     $this->status->start($this->get_backup_filename(), __('Starting backup...', 'backupwordpress'));
     $this->status->set_status(__('Deleting old backups...', 'backupwordpress'));
     // Delete old backups now in-case we fatal error during the backup process
     $this->delete_old_backups();
     $backup->run();
     $errors = array_merge($backup->errors, $backup->warnings);
     $notices = array();
     foreach ($errors as $key => $error) {
         $key = str_replace(array(__NAMESPACE__ . '\\', '_File_Backup_Engine', '_Database_Backup_Engine'), array('', '', ''), $key);
         $notices[] = $key . ': ' . implode(', ', $error);
     }
     Notices::get_instance()->set_notices('backup_errors', $notices);
     $this->status->set_status(__('Deleting old backups...', 'backupwordpress'));
     // Delete old backups again
     $this->delete_old_backups();
     $this->do_action('hmbkp_backup_complete', $backup);
     $this->status->finish();
     $this->update_average_schedule_run_time($this->status->get_start_time(), time());
 }