/**
 * This function sends a JSON message, and ends the script.
 *
 * Scripts receiving replies will recieve a JSON array with two fields:
 *
 *  - error: True or false depending on whether the request was successful
 *  - message: JSON data representing a message sent back from the script
 *
 * @param boolean $error   Whether the script ended in an error or not
 * @param string  $message A message to pass back to the user, can be an
 *                         array of JSON data
 */
function json_reply($error, $message, $returncode = 0)
{
    json_headers();
    echo json_encode(array('error' => $error, 'message' => $message, 'returnCode' => $returncode));
    perf_to_log();
    exit;
}
Example #2
0
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('INTERNAL', 1);
define('JSON', 1);
require dirname(dirname(__FILE__)) . '/init.php';
json_headers();
$data = new StdClass();
$data->view = param_integer('view');
$data->artefact = param_integer('artefact', null);
$data->message = param_variable('message');
$data->public = param_boolean('public') ? 1 : 0;
$data->attachment = param_integer('attachment', null);
$data->author = $USER->get('id');
$data->ctime = db_format_timestamp(time());
if ($data->artefact) {
    $table = 'artefact_feedback';
} else {
    $table = 'view_feedback';
}
if (!insert_record($table, $data, 'id', true)) {
    json_reply('local', get_string('addfeedbackfailed', 'view'));
 /**
  * Outputs json headers
  */
 public function jsonHeaders()
 {
     \json_headers();
 }
Example #4
0
 public function select()
 {
     $value = $this->input->get_post('selected', TRUE);
     $filter = rawurldecode($this->input->get_post('filter', TRUE));
     // Convert wild-cards to RegEx
     $filter = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $filter));
     $this->js_controller_params['method'] = 'select';
     $this->load->helper('array');
     $this->load->helper('form');
     $this->load->library('form_builder');
     $pages = $this->fuel->pages->options_list();
     $pdfs = $this->fuel->assets->dir_files('pdf', TRUE);
     if (!empty($pdfs) and !empty($_GET['pdfs'])) {
         $options[lang('page_select_pages')] = array_combine($pages, $pages);
         $options[lang('page_select_pdfs')] = array_combine($pdfs, $pdfs);
     } else {
         $options = array_combine($pages, $pages);
     }
     // apply filter
     if (!empty($filter)) {
         $filter_callback = create_function('$a', 'return preg_match(\'#^' . $filter . '$#\', $a);');
         $options = array_filter($options, $filter_callback);
     }
     // just return the options as json
     $fields['General'] = array('type' => 'fieldset', 'class' => 'tab');
     if (isset($_GET['options'])) {
         if (isset($_GET['format']) and strtolower($_GET['format']) == 'json') {
             json_headers();
             echo json_encode($options);
             return;
         } else {
             $str = '';
             if (isset($_GET['first_option'])) {
                 $first_option = $this->input->get('first_option', TRUE);
                 $str .= "<option value=\"\" label=\"" . Form::prep($first_option, FALSE) . "\">" . Form::prep($first_option, FALSE) . "</option>\n";
             }
             foreach ($options as $key => $val) {
                 $str .= "<option value=\"" . Form::prep($key, FALSE) . "\" label=\"" . Form::prep($val, FALSE) . "\">" . Form::prep($val, FALSE) . "</option>\n";
             }
             echo $str;
             return;
         }
     }
     $select_label = lang('form_label_page');
     $display_label_select = FALSE;
     if (isset($_GET['input'])) {
         $fields['input'] = array('value' => $this->input->get_post('input', TRUE), 'label' => lang('form_label_url'), 'size' => 100);
         $select_label = lang('form_label_or_select');
         $display_label_select = TRUE;
     }
     $fields['url_select'] = array('value' => $this->input->get_post('url_select', TRUE), 'label' => $select_label, 'type' => 'select', 'options' => $options, 'first_option' => lang('label_select_one'), 'display_label' => $display_label_select);
     $fields['Advanced'] = array('type' => 'fieldset', 'class' => 'tab');
     if (isset($_GET['target'])) {
         $target_options = array('' => '', '_blank' => '_blank', '_parent' => '_parent', '_top' => '_top');
         $fields['target'] = array('value' => $this->input->get_post('target', TRUE), 'label' => lang('form_label_target'), 'type' => 'select', 'options' => array('' => '', '_blank' => '_blank'));
         $fields['url_select']['display_label'] = TRUE;
     }
     if (isset($_GET['title'])) {
         $fields['title'] = array('value' => $this->input->get_post('title', TRUE), 'label' => lang('form_label_title'));
         $fields['url_select']['display_label'] = TRUE;
     }
     if (isset($_GET['class'])) {
         $fields['class'] = array('value' => $this->input->get_post('class', TRUE), 'label' => lang('form_label_class'));
         $fields['url_select']['display_label'] = TRUE;
     }
     $fields['selected'] = array('type' => 'hidden', 'value' => $this->input->get_post('selected', TRUE));
     $this->form_builder->submit_value = NULL;
     $this->form_builder->use_form_tag = FALSE;
     $this->form_builder->set_fields($fields);
     $this->form_builder->display_errors = FALSE;
     $vars['form'] = $this->form_builder->render();
     $this->fuel->admin->set_inline(TRUE);
     $crumbs = array('' => $this->module_name, lang('pages_select_action'));
     $this->fuel->admin->set_panel_display('notification', FALSE);
     $this->fuel->admin->set_titlebar($crumbs);
     $this->fuel->admin->render('modal_select', $vars, '', FUEL_FOLDER);
 }
function exit_json($arr = array())
{
    json_headers();
    exit(@json_encode($arr));
}
Example #6
0
                            process_new_login('', 1, $vbulletin->GPC['cssprefs']);
                            cache_permissions($vbulletin->userinfo, true);
                            $vbulletin->session->save();
                        }
                    }
                }
            } else {
                $valid_entries = FALSE;
                $messages['errors'][] = $message = "Please check your username and password.";
                $messages['fields'][] = $error_type = "username-member";
                $messages['errors'][] = $message = "";
                $messages['fields'][] = $error_type = "password-member";
                if ($vbulletin->options['usestrikesystem']) {
                    $strikes = verify_strike_status($vbulletin->GPC['username']);
                    exec_strike_user($vbulletin->GPC['username']);
                    if ($strikes >= 4) {
                        unset($messages);
                        $message = fetch_error('badlogin_strikes', $vbulletin->options['bburl'], $vbulletin->session->vars['sessionurl'], $strikes);
                        $message = rewrite_error($message);
                        $messages['errors'][] = $message;
                        $messages['fields'][] = $error_type = "username-member";
                        $messages['errors'][] = "";
                        $messages['fields'][] = $error_type = "password-member";
                    }
                }
            }
        }
        $arr = array("valid_entries" => $valid_entries, "messages" => $messages, "url" => $url);
        json_headers($arr);
        break;
}
Example #7
0
 /**
  * Includes $this->page_path after hooks:
  *     - uri
  *     - run-first
  *     - including script files
  *     - setting constants
  *     - then run-last
  * Uses Page::includePath() to emulate them being executed in the same scope.
  * @return \Sky\Page $this
  */
 public function run()
 {
     try {
         // uri hook
         $vars = $this->includePath('lib/core/hooks/uri/uri.php', $this->vars);
         // set constants
         $this->setConstants();
         // map input stream to $_POST if applicable
         $this->checkInputStream();
         // execute run first
         $vars = $this->includePath('pages/run-first.php', $vars);
         // execute script files
         foreach (array_keys($this->script_files) as $file) {
             $vars = $this->includePath($file, $vars);
         }
         // add page_css/page_js
         $this->setAssetsByPath($this->page_path);
         // see if we're not rendering html but returning JS
         $get_contents = (bool) ($_POST['_json'] || $_GET['_script']);
         if ($get_contents) {
             if ($_GET['_script']) {
                 $this->no_template = true;
             }
             ob_start();
         }
         // run-first / settings / script files need to be executed in the same scope
         $vars = $this->includePath($this->page_path, $vars);
         if ($get_contents) {
             // refreshing a secondary div after an ajax state change
             if (is_array($this->div)) {
                 $this->div['page'] = ob_get_contents();
             } else {
                 $this->div->page = ob_get_contents();
             }
             ob_end_clean();
             $this->sky_end_time = microtime(true);
             if ($_POST['_json']) {
                 \json_headers();
                 echo json_encode($this);
             } else {
                 header('Content-type: text/javascript');
                 echo sprintf("%s(%s,'%s','%s', '%s');", $_GET['_fn'] ?: 'render_page', json_encode($this), $this->uri, $_SERVER['HTTP_HOST'], $_GET['_script_div'] ?: 'page');
             }
         }
         // run-last hook
         $this->includePath('pages/run-last.php', $vars);
     } catch (\Sky\AQL\Exception\Connection $e) {
         $this->includePath('pages/503.php');
         echo '<!--' . $e->getMessage() . '-->';
     }
     return $this;
 }