Esempio n. 1
0
 /**
  * Handles the submission of the import form, importing data from a WordPress database.
  * This function should probably be broken into an importer class, since it is WordPress-specific.
  */
 public function post_import()
 {
     if (!isset($_POST['importer'])) {
         Utils::redirect(URL::get('display_import'));
     }
     $this->get_import();
 }
 public function action_form_publish($form, $post)
 {
     $selector = $form->append('wrapper', 'type_selector');
     $selector->class = 'container';
     // Utils::debug( 'bob' );
     if (Controller::get_var('to_type') != NULL && $post->content_type != Controller::get_var('to_type')) {
         /* set type */
         $post->content_type = Post::type(Controller::get_var('to_type'));
         $post->update();
         Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
         // Refresh view
     }
     foreach (Post::list_active_post_types() as $type) {
         if ($type != 0) {
             if ($post->id == 0) {
                 $url = URL::get('admin', 'page=publish&content_type=' . Post::type_name($type));
             } else {
                 $url = URL::get('admin', 'page=publish&to_type=' . Post::type_name($type) . '&id=' . $post->id);
             }
             $html = '<a href="' . $url . '"';
             if (Post::type_name($type) == $post->content_type || $type == $post->content_type) {
                 $html .= ' class="active"';
             }
             $html .= '>' . Post::type_name($type) . '</a>';
             $selector->append('static', 'type_selector_' . $type, $html);
         }
     }
     $selector->move_before($selector, $form);
     return $form;
 }
Esempio n. 3
0
 public function run()
 {
     $msg = '';
     if (!empty($_POST['submit'])) {
         if (!empty($_POST['password'])) {
             $user = new User();
             if ($user->findUserByUsername($_POST['username'])) {
                 if ($user->getForgot_hash() == $_REQUEST['token']) {
                     $password = '******' . Utils::encryptPassword($_POST['password']);
                     $user->setPassword($password)->setForgot_hash(md5(uniqid()))->save();
                     Utils::sendTemplateEmail($_POST['username'], 'changed_pass', array('app_name' => APP_NAME));
                     Utils::redirect('./');
                 }
             } else {
                 $msg = 'The link to reset your password has expired or is invalid. <a href="./forgot">Please try again.</a>';
             }
         } else {
             $msg = "Please enter a password!";
         }
     }
     if (empty($_REQUEST['token'])) {
         // no required information specified, redirect user
         $this->view = null;
         Utils::redirect('./');
     }
     $this->write('msg', $msg);
     $this->write('un', isset($_REQUEST['un']) ? base64_decode($_REQUEST['un']) : "");
     $this->write('token', $_REQUEST['token']);
     parent::run();
 }
Esempio n. 4
0
 /**
  * Handles the submission of the import form, importing data from a WordPress database.
  * This function should probably be broken into an importer class, since it is WordPress-specific.
  */
 public function post_import()
 {
     if (!isset($_POST['importer'])) {
         Utils::redirect(URL::get('admin', 'page=import'));
     }
     $this->get_import();
 }
Esempio n. 5
0
 public function getContent()
 {
     if (LoggedUser::whoIsLogged()) {
         if (isset($_COOKIE['ref_url'])) {
             $url = $_COOKIE['ref_url'];
             $absolute = FALSE;
         } else {
             $page = PageActionMap::getPageByTypeAndLanguage('rooms');
             $url = PageActionMap::createUrl($page['alias']);
             $absolute = TRUE;
         }
         Utils::redirect($url, $absolute);
     }
     if (Utils::post('login')) {
         MySmarty::assign('username', Utils::post('username'));
         $validation = LoggedUser::userLogin();
         //var_Dump($validation);exit();
         if ($validation === TRUE) {
             Utils::redirect(Utils::getActualUrlWithoutGetParameters(), FALSE);
         } else {
             MySmarty::assign('errors', $validation);
         }
     }
     return MySmarty::fetch('login.tpl');
 }
Esempio n. 6
0
 public function getContent()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if ($loggedUser !== NULL) {
         LoggedUser::userLogout();
     }
     Utils::redirect(Utils::getActualUrl(), FALSE);
 }
Esempio n. 7
0
 public function updated_config(FormUI $ui)
 {
     Session::notice(_t('Settings saved.', 's3siloplugin'));
     $ui->save();
     if (is_null(Options::get('s3_bucket'))) {
         Session::notice(_t('Please select a bucket from your S3 account.', 's3siloplugin'));
     }
     Utils::redirect();
 }
 /**
  * Handler FormUI success action and do the replacement
  **/
 public function filter_do_replace($show_form, $form)
 {
     if (DB::query('UPDATE {posts} SET content = REPLACE(content, ? , ?)', array($form->search->value, $form->replace->value))) {
         Session::notice(sprintf(_t('Successfully replaced \'%s\' with \'%s\' in all posts'), $form->search->value, $form->replace->value));
         Utils::redirect(URL::get('admin', array('page' => 'plugins', 'configure' => Plugins::id_from_file(__FILE__), 'configaction' => _t('Replace'))), false);
     } else {
         Session::error(_t('There was an error with replacement.'));
     }
     return false;
 }
Esempio n. 9
0
 public function logout($redirect = null)
 {
     unset($this->user);
     unset($this->token);
     Session::instance('ThinSession')->forgetAuthToken();
     Session::instance('ThinSession')->forgetAuthUser();
     if (null !== $redirect) {
         Utils::redirect($redirect);
     }
 }
Esempio n. 10
0
 /**
  * function action_init
  * A function which makes sure we are good to go for plugin activation.
  */
 public function action_init()
 {
     if (!class_exists('RenderCache')) {
         Session::error(_t("LaTeX activation failed. This plugin requires the RenderCache class which was not found."));
         Plugins::deactivate_plugin(__FILE__);
         //Deactivate plugin
         Utils::redirect();
         //Refresh page. Unfortunately, if not done so then results don't appear
     }
 }
Esempio n. 11
0
 /**
  * This control only executes its on_success callbacks when it was clicked
  * @return bool|string A string to replace the rendering of the form with, or false
  */
 public function do_success($form)
 {
     $actions = $this->get_setting('actions', array());
     if (isset($actions[$this->value])) {
         if (isset($actions[$this->value]['fn']) && is_callable($actions[$this->value]['fn'])) {
             $fn = $actions[$this->value]['fn'];
             call_user_func($fn, $form);
         } elseif (isset($actions[$this->value]['href']) && is_string(isset($actions[$this->value]['href']))) {
             Utils::redirect($actions[$this->value]['href'], true);
         }
     }
     return parent::do_success($form);
 }
Esempio n. 12
0
 /**
  * Initialize by added directory variables
  */
 public function action_init()
 {
     $this->logs = dirname(__FILE__) . '/logs';
     $this->cache = dirname(__FILE__) . '/cache';
     if (!$this->confirm_dirs($error)) {
         Session::error("Clickheat error: {$error}");
         Plugins::deactivate_plugin(__FILE__);
         // Deactivate plugin
         Utils::redirect();
         //Refresh page
         exit;
     }
 }
Esempio n. 13
0
 public function run()
 {
     $msg = "";
     $to = 1;
     $user = new User();
     if (isset($_REQUEST['str'])) {
         $email = mysql_real_escape_string(base64_decode($_REQUEST['str']));
         $confirm_string = substr($_REQUEST['cs'], 0, 10);
         // verify the email belongs to a user
         if ($user->findUserByUsername($email) && substr($user->getConfirm_string(), 0, 10) == $confirm_string) {
             $sql = "\n                    UPDATE " . USERS . "\n                    SET\n                        confirm_string = '',\n                        confirm = 1,\n                        is_active = 1\n                    WHERE username = '******'";
             mysql_query($sql);
             // send welcome email
             Utils::sendTemplateEmail($user->getUsername(), 'welcome', array('nickname' => $user->getNickname()), 'Worklist <*****@*****.**>');
             User::login($user, false);
             //Optionally can login with confirm URL
             $jumbotron = "\n                    <h2>Welcome to Worklist!</h2>\n                    <p>\n                      Click on a job and add your bid, or come join us in our \n                      <a href='https://gitter.im/highfidelity/worklist' target='_blank'>public chat room</a>.\n                      Questions? Check out the <a href='./help'>help tab</a>.\n                    </p>";
         } else {
             Utils::redirect('./');
         }
     } elseif (isset($_REQUEST['ppstr'])) {
         // paypal address confirmation
         $paypal_email = mysql_real_escape_string(base64_decode($_REQUEST['ppstr']));
         $hash = mysql_real_escape_string($_REQUEST['pp']);
         // verify the email belongs to a user
         if (!$user->findUserByPPUsername($paypal_email, $hash)) {
             // hacking attempt, or some other error
             Utils::redirect('./');
         } else {
             $user->setPaypal_verified(true);
             $user->setPaypal_hash('');
             $user->save();
             $jumbotron = "\n                    <h2>Thank you for confirming your Paypal address.</h2>\n                    <p>You can now bid on items in the Worklist!</p>";
         }
     } elseif (isset($_REQUEST['emstr'])) {
         // new email address confirmation
         $new_email = mysql_real_escape_string(base64_decode($_REQUEST['emstr']));
         if (!$user->findUserByUsername($_SESSION['username'])) {
             Utils::redirect('login');
             //we are not logged in
         }
         //save new email
         $user->setUsername($new_email);
         $user->save();
         $_SESSION['username'] = $new_email;
         $jumbotron = "<h2>Thank you for confirming your changed email address.</h2>";
     }
     $jobs = new JobController();
     $jobs->view->jumbotron = $jumbotron;
     $jobs->listView();
 }
Esempio n. 14
0
 function action_admin_theme_get_rules($handler, $theme)
 {
     $handler_vars = $handler->handler_vars;
     if (isset($handler_vars['names'])) {
         foreach ($handler_vars['names'] as $key => $name) {
             $changes = array('name' => $name, 'parse_regex' => $handler_vars['regexes'][$key], 'action' => $handler_vars['actions'][$key], 'priority' => $handler_vars['priorities'][$key], 'description' => $handler_vars['descriptions'][$key]);
             self::add_rewrite_rule($key, $changes);
         }
         Session::notice(_t('Rewrite rules updated.'));
         Utils::redirect();
     }
     $theme->display('rules');
     exit;
 }
Esempio n. 15
0
 /**
  * Initialize some internal values when plugin initializes
  */
 public function action_init()
 {
     $user_path = HABARI_PATH . '/' . Site::get_path('user', true);
     $this->root = $user_path . 'files';
     //Options::get('simple_file_root');
     $this->url = Site::get_url('user', true) . 'files';
     //Options::get('simple_file_url');
     if (!$this->check_files()) {
         Session::error(_t("Habari Silo activation failed. The web server does not have permission to create the 'files' directory for the Habari Media Silo."));
         Plugins::deactivate_plugin(__FILE__);
         //Deactivate plugin
         Utils::redirect();
         //Refresh page. Unfortunately, if not done so then results don't appear
     }
 }
Esempio n. 16
0
	/**
	 * Verifies user credentials before creating the theme and displaying the request.
	 */
	public function __construct()
	{
		$user = User::identify();
		if ( !$user->loggedin ) {
			Session::add_to_set( 'login', $_SERVER['REQUEST_URI'], 'original' );
			if ( URL::get_matched_rule()->action == 'admin_ajax' && isset( $_SERVER['HTTP_REFERER'] ) ) {
				 $ar = new AjaxResponse(408, _t('Your session has ended, please log in and try again.') );
				 $ar->out();
			}
			else {
				$post_raw = $_POST->get_array_copy_raw();
				if ( !empty( $post_raw ) ) {
					Session::add_to_set( 'last_form_data', $post_raw, 'post' );
					Session::error( _t( 'We saved the last form you posted. Log back in to continue its submission.' ), 'expired_form_submission' );
				}
				$get_raw = $_GET->get_array_copy_raw();
				if ( !empty( $get_raw ) ) {
					Session::add_to_set( 'last_form_data', $get_raw, 'get' );
					Session::error( _t( 'We saved the last form you posted. Log back in to continue its submission.' ), 'expired_form_submission' );
				}
				Utils::redirect( URL::get( 'auth', array( 'page' => 'login' ) ) );
			}
			exit;
		}

		$last_form_data = Session::get_set( 'last_form_data' ); // This was saved in the "if ( !$user )" above, UserHandler transferred it properly.
		/* At this point, Controller has not created handler_vars, so we have to modify $_POST/$_GET. */
		if ( isset( $last_form_data['post'] ) ) {
			$_POST = $_POST->merge( $last_form_data['post'] );
			$_SERVER['REQUEST_METHOD'] = 'POST'; // This will trigger the proper act_admin switches.
			Session::remove_error( 'expired_form_submission' );
		}
		if ( isset( $last_form_data['get'] ) ) {
			$_GET = $_GET->merge( $last_form_data['get'] );
			Session::remove_error( 'expired_form_submission' );
			// No need to change REQUEST_METHOD since GET is the default.
		}
		$user->remember();

		// Create an instance of the active public theme so that its plugin functions are implemented
		$this->active_theme = Themes::create();

		// setup the stacks for javascript in the admin - it's a method so a plugin can call it externally
		self::setup_stacks();
		
		// on every page load check the plugins currently loaded against the list we last checked for updates and trigger a cron if we need to
		Update::check_plugins();
	}
Esempio n. 17
0
 /**
  * Matches an admin route by regex and adds a menu item
  * @param  string [ Regular Expression ] $routeRegex
  * @param  string $name
  * @param  string $queryVars
  * @param  Closure $callback
  * @param  Array  $options - array of options for add_menu_page
  * @return null
  */
 public function adminRoute($routeRegex, $name, $queryVars, $callback, $options = array())
 {
     $defaults = array('capability' => 'administrator', 'page_title' => $name, 'menu_title' => $name, 'menu_slug' => $name . '_route', 'icon_url' => '', 'position' => 1);
     $options = (object) array_merge($defaults, $options);
     $this->match($routeRegex, $options->menu_slug, $queryVars, function ($input) use($options) {
         $input['routeAlias'] = true;
         $var = Utils::cacheSet('matchData', json_encode($input));
         Utils::redirect('/wp-admin/admin.php?page=' . $options->menu_slug);
     }, false, true);
     Actions::on('admin_menu', function () use($callback, $options) {
         $input = json_decode(Utils::cacheGet('matchData'));
         add_menu_page($options->page_title, $options->menu_title, $options->capability, $options->menu_slug, function () use($input, $callback) {
             return call_user_func($callback, $input);
         }, $options->icon_url, $options->position);
     });
     return null;
 }
Esempio n. 18
0
 public function getContent()
 {
     if (Utils::get('identifier')) {
         $page = PageActionMap::getPageByTypeAndLanguage('character');
         if ($page['alias'] != Utils::get('action')) {
             $url = PageActionMap::createUrl(array($page['alias'], Utils::get('identifier')), Utils::get('language'));
             Utils::redirect($url);
         }
         $box = new CharacterDetailBox();
     } else {
         $page = PageActionMap::getPageByTypeAndLanguage('characters');
         if ($page['alias'] != Utils::get('action')) {
             $url = PageActionMap::createUrl(array($page['alias']), Utils::get('language'));
             Utils::redirect($url);
         }
         $box = new CharacterListingBox();
     }
     return $box->render();
 }
Esempio n. 19
0
 public function run($action, $param = '')
 {
     $method = '';
     switch ($action) {
         case 'add':
         case 'scan':
         case 'remove':
         case 'listForJob':
             $method = $action;
             break;
         default:
             if (is_numeric($action)) {
                 $method = 'view';
                 $param = (int) $action;
             } else {
                 Utils::redirect('./');
             }
             break;
     }
     $params = preg_split('/\\//', $param);
     call_user_func_array(array($this, $method), $params);
 }
Esempio n. 20
0
 /**
  * Autoload function to load plugin file from classname
  */
 public static function _autoload($class)
 {
     if (isset(self::$plugin_files[$class])) {
         require self::$plugin_files[$class];
         if (!class_exists($class, false)) {
             // The classname of a plugin changed.
             $filename = self::$plugin_files[$class];
             EventLog::log(_t('Plugin file "%s" has changed its plugin class name.', array($filename)));
             Session::error(_t('Plugin file "%s" has changed its plugin class name.', array($filename)));
             // Remove the plugin from the active list
             $active_plugins = Options::get('active_plugins');
             unset($active_plugins[$class]);
             self::$plugin_files = array();
             Options::set('active_plugins', $active_plugins);
             self::list_active(true);
             // Refresh the internal list
             // Reactivate it to try to get the new class loaded
             self::activate_plugin($filename);
             Utils::redirect();
         }
     }
 }
 public function formui_submit(FormUI $form)
 {
     $filename = basename($form->pluginurl);
     //local file path (e.g. habari_installation/system/plugins/plugin.zip)
     $filePath = $this->downloadplugin_pluginsPath . $filename;
     // check if the remote file is successfully opened
     if ($fp = fopen($form->pluginurl, 'r')) {
         $content = '';
         // keep reading until there's nothing left
         while ($line = fread($fp, 1024)) {
             $content .= $line;
         }
         $fp = fopen($filePath, 'w');
         fwrite($fp, $content);
         fclose($fp);
     } else {
         Session::notice(_t("Error during file download", 'plugin_locale'));
         break;
     }
     $zip = new ZipArchive();
     $res = $zip->open($filePath);
     if ($res === TRUE) {
         $zip->extractTo($this->downloadplugin_pluginsPath);
         $zip->close();
         //SET 775 Permission ?
         Session::notice(_t('Plugin installed', 'plugin_locale'));
     } else {
         Session::notice(_t('Error during plugin installation', 'plugin_locale'));
         $form->save();
         unlink($filePath);
         break;
     }
     unlink($filePath);
     $form->pluginurl->value = '';
     $form->save();
     Utils::redirect(URL::get('admin', 'page=plugins'));
 }
 public function action_plugin_ui($plugin_id, $action)
 {
     if ($plugin_id == $this->plugin_id()) {
         switch ($action) {
             case _t('Configure'):
                 $ui = new FormUI(strtolower(get_class($this)));
                 $person = $ui->append('text', 'person', 'flickrfill__person', _t('Flickr ID Number: '));
                 // $ui->on_success( array( $this, 'updated_config' ) );
                 $number = $ui->append('text', 'number', 'flickrfill__number', _t('Number of Pictures to Display: '));
                 $size = $ui->append('select', 'size', 'flickrfill__size', _t('Size of Images to Display'));
                 /**
                 					TODO Make this tranlateable
                 					**/
                 $size->options = array('_s' => 'Square (75px Each Side)', '_t' => 'Thumbnail (Longest Side 100px)', '_m' => 'Small (Longest Side 240px )', '' => 'Medium (Longest Side 500px)');
                 $ui->append('submit', 'save', _t('Save'));
                 $ui->out();
                 break;
             case _t('Refresh'):
                 $this->theme_flickrfill();
                 Utils::redirect(URL::get('admin', 'page=plugins'));
                 break;
         }
     }
 }
Esempio n. 23
0
 public function create($args)
 {
     $p = PermissionHandler::getInstance();
     // do we have an error thing?
     if (!$p->allowedto(PermissionHandler::PERM_CREATE_PROJECT)) {
         Utils::error("You don't have permission to create projects.");
         return;
     }
     if (isset($_POST['go'])) {
         // ok, if the user has selected to do automatic lookup
         // of the series or automatic adding of episodes,
         // then we need to confirm that we're looking up the right
         // series.
         // scratch that. we should confirm no matter what, but if they chose
         // automatic lookup, do it here.
         $this->vars['tid'] = 0;
         $this->vars['search'] = array();
         if (!isset($_POST['confirm'])) {
             // implement automatic lookup
             // if the user wants automatic lookup, do it.
             if (isset($_POST['autolookup'])) {
                 if ($_POST['autolookup'] == "on") {
                     require_once dirname(__FILE__) . "/../plugins/animedata.php";
                     // fill in the autolookup stuff...
                     // first we need to find the anime.
                     $search = AnimeData::search($_POST['name']);
                     if ($search) {
                         if (!isset($_POST['tid'])) {
                             $tidkey = 0;
                         } else {
                             foreach ($search as $key => $entry) {
                                 if ($entry[0] == $_POST['tid']) {
                                     $tidkey = $key;
                                 }
                             }
                         }
                         $this->vars['tid'] = $search[$tidkey][0];
                         $this->vars['search'] = $search;
                         $description = AnimeData::description($search[$tidkey][0]);
                         if ($description) {
                             $_POST['description'] = $description;
                         } else {
                             Utils::warning("Could not find description.");
                         }
                         $epcount = AnimeData::epcount($search[$tidkey][0]);
                         $_POST['epsaired'] = $epcount['aired'];
                         $_POST['epstotal'] = $epcount['total'];
                         $_POST['airtime'] = $epcount['airtime'];
                     } else {
                         Utils::warning("Could not find anime.");
                     }
                 }
             }
             $this->vars['confirm'] = $_POST;
             // LOL LAZY
             // display a confirmation
             $this->view = "confirm";
             return;
         }
         // if they've already confirmed, then go ahead and create the project
         $project = new Project();
         $project->name = $_POST['name'];
         $project->shortname = $_POST['shortname'];
         $project->description = $_POST['description'];
         $project->episodes = $_POST['epstotal'];
         if ($_POST['leader'] != "none") {
             $project->leader = $_POST['leader'];
         }
         if ($_POST['template'] != "none") {
             $project->template = $_POST['template'];
             $template = Doctrine::getTable('Template')->find(0);
         }
         if (isset($_POST['tid'])) {
             $project->syoboi_id = $_POST['tid'];
         }
         $project->created = date("Y-m-d H:i:s");
         $project->save();
         if (isset($_POST['tid'])) {
             require_once dirname(__FILE__) . "/../plugins/animedata.php";
             $times = AnimeData::times($_POST['tid']);
         }
         // if the user has chosen to automatically add episodes, do so now
         if ($_POST['autoeps'] == "aired") {
             $total = $_POST['epsaired'];
         } else {
             if ($_POST['autoeps'] == "total") {
                 $total = $_POST['epstotal'];
             } else {
                 $total = 0;
             }
         }
         for ($i = 1; $i <= $total; $i++) {
             $episode = new Episode();
             $episode->project = $project->id;
             $episode->episode = $i;
             if (isset($times)) {
                 $episode->airdate = strtok($times[$i][0]['airtime'], " ");
             }
             $episode->created = date("Y-m-d H:i:s");
             $episode->save();
             if (isset($template)) {
                 $template->createTasks($episode->id);
             }
         }
         // and finally, send them to the project page.
         Utils::redirect("projects/display/" . $project->id);
         $this->view = null;
         return;
     }
     // otherwise, i don't think we actually need to do anything... right?
     // YEAH WE DO RETARD. ITS CALLED GIVE TEMPLATE SHIT.
     $q = Doctrine_Query::create()->select('s.id,s.nickname')->from('Staff s');
     $users = $q->fetchArray();
     // make this easier to use.
     foreach ($users as $row) {
         $this->vars['users'][] = array($row['id'], $row['nickname']);
     }
     $q = Doctrine_Query::create()->select('t.id, t.name')->from('Template t');
     $templates = $q->fetchArray();
     // make this easier to use.
     foreach ($templates as $row) {
         $this->vars['templates'][] = array($row['id'], $row['name']);
     }
 }
Esempio n. 24
0
<?php

//status of list
$status = Utils::getUrlParam('status');
//command
$cmd = Utils::getUrlParam('cmd');
$flightBooking = Utils::getFlightBookingByGetId();
$flightBooking->setStatus($cmd);
$dao = new FlightBookingDao();
$dao->save($flightBooking);
$msg = '';
if ($cmd === FlightBooking::VOIDED) {
    $smg = 'Flight booking deleted successfully.';
} else {
    $smg = 'Flight boooking changed successfully.';
}
Flash::addFlash($smg);
Utils::redirect('list', array('status' => $status));
Esempio n. 25
0
 /**
  * Helper method to allow RewriteRules to send a redirect. The method will
  * redirect to the build_str of the RewriteRule if matched.
  */
 public function act_redirect()
 {
     $vars = isset($_SERVER['QUERY_STRING']) ? Utils::get_params($_SERVER['QUERY_STRING']) : array();
     Utils::redirect(URL::get(null, $vars));
 }
    $foodOrder->setEmail($email);
    $foodOrder->setProductId($product_id);
    //set default status
    $foodOrder->setStatus('PENDING');
    //$foodOrder -> setPickupTime($pickup_time);
    $foodOrder->setDate(date("Y-m-d H:i:s"));
    $status = '';
    if (isset($_POST['food_order']['status'])) {
        $status = filter_var($_POST['food_order']['status'], FILTER_SANITIZE_STRING);
    } else {
        $status = 'PENDING';
    }
    $data = array('product_id' => $_POST['food_order']['order_list'], 'user_id' => 1, 'full_name' => 'Bob Smith', 'email' => '*****@*****.**', 'phone_number' => '0278839406', 'date' => date("Y-m-d H:i:s"), 'status' => $status);
    // var_dump($_POST);
    // die();
    // map
    FoodOrderMapper::map($foodOrder, $data);
    // validate
    //   $errors = FoodOrderValidator::validate($foodOrder);
    //   if (empty($errors)) {
    // save
    $dao = new FoodOrderDao();
    $foodOrder = $dao->save($foodOrder);
    Flash::addFlash('Thank you for ordering with us.');
    // redirect
    Utils::redirect('home');
    //   }
}
$productDao = new ProductDao();
$product_id = Utils::getUrlParam('product_id');
$products = $productDao->find();
Esempio n. 27
0
                    $config = ['type' => Utils::post('new_type'), 'title' => Utils::post('new_title'), 'editable' => true, 'mandatory' => false];
                    if ($config['type'] == 'select' || $config['type'] == 'multiple') {
                        $config['options'] = ['Première option'];
                    }
                    $champs->add($new, $config);
                }
                $membres->sessionStore('champs_membres', (string) $champs);
                Utils::redirect('/admin/config/membres.php?added');
            } catch (UserException $e) {
                $error = $e->getMessage();
            }
        } elseif (!empty($_POST['save'])) {
            try {
                $champs->save();
                $membres->sessionStore('champs_membres', null);
                Utils::redirect('/admin/config/membres.php?ok');
            } catch (UserException $e) {
                $error = $e->getMessage();
            }
        }
    }
}
$tpl->assign('error', $error);
$tpl->assign('review', isset($_GET['review']) ? true : false);
$types = $champs->getTypes();
$tpl->assign('champs', $champs->getAll());
$tpl->assign('types', $types);
$tpl->assign('presets', Membres\Champs::listUnusedPresets($champs));
$tpl->assign('new', Utils::post('new'));
$tpl->register_modifier('get_type', function ($type) use($types) {
    return $types[$type];
Esempio n. 28
0
    } else {
        try {
            $config->set('nom_asso', Utils::post('nom_asso'));
            $config->set('email_asso', Utils::post('email_asso'));
            $config->set('adresse_asso', Utils::post('adresse_asso'));
            $config->set('site_asso', Utils::post('site_asso'));
            $config->set('email_envoi_automatique', Utils::post('email_envoi_automatique'));
            $config->set('accueil_wiki', Utils::post('accueil_wiki'));
            $config->set('accueil_connexion', Utils::post('accueil_connexion'));
            $config->set('categorie_membres', Utils::post('categorie_membres'));
            $config->set('champ_identite', Utils::post('champ_identite'));
            $config->set('champ_identifiant', Utils::post('champ_identifiant'));
            $config->set('pays', Utils::post('pays'));
            $config->set('monnaie', Utils::post('monnaie'));
            $config->save();
            Utils::redirect('/admin/config/?ok');
        } catch (UserException $e) {
            $error = $e->getMessage();
        }
    }
}
$tpl->assign('error', $error);
$tpl->assign('garradin_version', garradin_version() . ' [' . (garradin_manifest() ?: 'release') . ']');
$tpl->assign('php_version', phpversion());
$v = \SQLite3::version();
$tpl->assign('sqlite_version', $v['versionString']);
$tpl->assign('pays', Utils::getCountryList());
$cats = new Membres\Categories();
$tpl->assign('membres_cats', $cats->listSimple());
$champs_liste = array_merge(['id' => ['title' => 'Numéro unique', 'type' => 'number']], $config->get('champs_membres')->getList());
$tpl->assign('champs', $champs_liste);
Esempio n. 29
0
	public function form_publish_success( FormUI $form )
	{
		$post_id = 0;
		if ( isset( $this->handler_vars['id'] ) ) {
			$post_id = intval( $this->handler_vars['id'] );
		}
		// If an id has been passed in, we're updating an existing post, otherwise we're creating one
		if ( 0 !== $post_id ) {
			$post = Post::get( array( 'id' => $post_id, 'status' => Post::status( 'any' ) ) );

			// Verify that the post hasn't already been updated since the form was loaded
			if ( $post->modified != $form->modified->value ) {
				Session::notice( _t( 'The post %1$s was updated since you made changes.  Please review those changes before overwriting them.', array( sprintf( '<a href="%1$s">\'%2$s\'</a>', $post->permalink, Utils::htmlspecialchars( $post->title ) ) ) ) );
				Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
				exit;
			}

			// REFACTOR: this is duplicated in the insert code below, move it outside of the conditions
			// Don't try to update form values that have been removed by plugins
			$expected = array('title', 'tags', 'content');

			foreach ( $expected as $field ) {
				if ( isset( $form->$field ) ) {
					$post->$field = $form->$field->value;
				}
			}
			if ( $form->newslug->value == '' && $post->status == Post::status( 'published' ) ) {
				Session::notice( _t( 'A post slug cannot be empty. Keeping old slug.' ) );
			}
			elseif ( $form->newslug->value != $form->slug->value ) {
				$post->slug = $form->newslug->value;
			}

			// REFACTOR: the permissions checks should go before any of this other logic

			// sorry, we just don't allow changing posts you don't have rights to
			if ( ! ACL::access_check( $post->get_access(), 'edit' ) ) {
				Session::error( _t( 'You don\'t have permission to edit that post' ) );
				$this->get_blank();
			}
			// sorry, we just don't allow changing content types to types you don't have rights to
			$user = User::identify();
			$type = 'post_' . Post::type_name( $form->content_type->value );
			if ( $form->content_type->value != $post->content_type && ( $user->cannot( $type ) || ! $user->can_any( array( 'own_posts' => 'edit', 'post_any' => 'edit', $type => 'edit' ) ) ) ) {
				Session::error( _t( 'Changing content types is not allowed' ) );
				$this->get_blank();
			}
			$post->content_type = $form->content_type->value;

			// if not previously published and the user wants to publish now, change the pubdate to the current date/time unless a date has been explicitly set
			if ( ( $post->status != Post::status( 'published' ) )
				&& ( $form->status->value == Post::status( 'published' ) )
				&& ( HabariDateTime::date_create( $form->pubdate->value )->int == $form->updated->value )
				) {
				$post->pubdate = HabariDateTime::date_create();
			}
			// else let the user change the publication date.
			//  If previously published and the new date is in the future, the post will be unpublished and scheduled. Any other status, and the post will just get the new pubdate.
			// This will result in the post being scheduled for future publication if the date/time is in the future and the new status is published.
			else {
				$post->pubdate = HabariDateTime::date_create( $form->pubdate->value );
			}
			$minor = $form->minor_edit->value && ( $post->status != Post::status( 'draft' ) );
			$post->status = $form->status->value;
		}
		else {
			// REFACTOR: don't do this here, it's duplicated in Post::create()
			$post = new Post();

			// check the user can create new posts of the set type.
			$user = User::identify();
			$type = 'post_'  . Post::type_name( $form->content_type->value );
			if ( ACL::user_cannot( $user, $type ) || ( ! ACL::user_can( $user, 'post_any', 'create' ) && ! ACL::user_can( $user, $type, 'create' ) ) ) {
				Session::error( _t( 'Creating that post type is denied' ) );
				$this->get_blank();
			}

			// REFACTOR: why is this on_success here? We don't even display a form
			$form->on_success( array( $this, 'form_publish_success' ) );
			if ( HabariDateTime::date_create( $form->pubdate->value )->int != $form->updated->value ) {
				$post->pubdate = HabariDateTime::date_create( $form->pubdate->value );
			}

			$postdata = array(
				'slug' => $form->newslug->value,
				'user_id' => User::identify()->id,
				'pubdate' => $post->pubdate,
				'status' => $form->status->value,
				'content_type' => $form->content_type->value,
			);

			// Don't try to add form values that have been removed by plugins
			$expected = array( 'title', 'tags', 'content' );

			foreach ( $expected as $field ) {
				if ( isset( $form->$field ) ) {
					$postdata[$field] = $form->$field->value;
				}
			}

			$minor = false;

			// REFACTOR: consider using new Post( $postdata ) instead and call ->insert() manually
			$post = Post::create( $postdata );
		}

		$post->info->comments_disabled = !$form->comments_enabled->value;

		// REFACTOR: admin should absolutely not have a hook for this here
		Plugins::act( 'publish_post', $post, $form );

		// REFACTOR: we should not have to update a post we just created, this should be moved to the post-update functionality above and only called if changes have been made
		// alternately, perhaps call ->update() or ->insert() as appropriate here, so things that apply to each operation (like comments_disabled) can still be included once outside the conditions above
		$post->update( $minor );

		$permalink = ( $post->status != Post::status( 'published' ) ) ? $post->permalink . '?preview=1' : $post->permalink;
		Session::notice( sprintf( _t( 'The post %1$s has been saved as %2$s.' ), sprintf( '<a href="%1$s">\'%2$s\'</a>', $permalink, Utils::htmlspecialchars( $post->title ) ), Post::status_name( $post->status ) ) );
		Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
	}
Esempio n. 30
0
 /**
  * Redirect a link to its original destination
  */
 public function action_plugin_act_link_redirect($handler)
 {
     $slug = $handler->handler_vars['slug'];
     $post = Post::get(array('slug' => $slug));
     if ($post == false) {
         $handler->theme->display('404');
         exit;
     }
     $type = Traffum::TYPE_SEND_NORMAL;
     if (isset($handler->handler_vars['refer']) && $handler->handler_vars['refer'] == 'atom') {
         $type = Traffum::TYPE_SEND_ATOM;
     }
     Traffum::create(array('post_id' => $post->id, 'type' => $type));
     Utils::redirect($post->info->url);
     exit;
 }