/** * Validation code * @see $this->validate_required() * @param object $field_obj * @param mixed $params not used * @return void */ function __construct($field_obj, $params) { $resp = recaptcha_check_answer(get_tina_mvc_setting('recaptcha_pri_key'), $_SERVER['REMOTE_ADDR'], get_Post('recaptcha_challenge_field'), get_Post('recaptcha_response_field')); if (!$resp->is_valid) { $this->validation_message = 'The reCaptcha was incorrect. Please try again.'; } }
/** * An autoloader * * @param string $folder * @param string $shortcode_content * @uses $this->include_controller() * * @return boolean TRUE on success. FALSE only if called from a shortcode. Other failures trigger an error. */ private function get_instance_of($folder = '', $shortcode_content) { // $this->called_from = PAGE_FILTER,WIDGET,SHORTCODE,CALL_CONTROLLLER // $this->request // pr( $this->called_from ); $this->tina_mvc_page = FALSE; // default - used for page_filter requests if ($this->called_from == 'PAGE_FILTER') { if (!($page = $this->request[0])) { error("Invalid request"); } else { $this->tina_mvc_page = $page; if (isset($this->request[1])) { $controller = $this->request[1]; } else { $controller = $this->request[1] = 'index'; } } } else { $controller = $this->request[0]; } $controller_filename = $controller . '_controller.php'; /** * Checks the custom folder */ if ($folder) { if (file_exists("{$folder}/{$controller_filename}")) { $this->include_controller("{$folder}/{$controller_filename}", $controller); return TRUE; } $err_msg = "<strong>Controller file '{$folder}/{$controller_filename}' does not exist.</strong>"; if ($this->called_from == 'SHORTCODE' or $this->called_from == 'WIDGET') { $this->CONTROLLER = new tina_mvc_controller_class(); $this->CONTROLLER->set_post_content($err_msg); return FALSE; } else { error($err_msg); } } /** * Is demo mode enabled? */ if (get_tina_mvc_setting('demo_mode')) { if (file_exists($f = plugin_folder() . "/demo/pages/tina_mvc_demo_and_docs/{$controller_filename}")) { $this->include_controller($f, $controller); return TRUE; } } $search_errors = array(); // default $controller_file = find_app_file($controller_filename, $this->tina_mvc_page, $this->called_from, $search_errors); if ($controller_file !== FALSE) { $this->include_controller($controller_file, $controller); return TRUE; } else { /** * If we got here we have failed to find a controller */ if (get_tina_mvc_setting('missing_page_controller_action') == 'display_error') { $e = "<strong>Can't find controller for request:</strong>"; $e .= "<small><pre>" . print_r($this->request, 1) . "</pre></small>\r\n"; $e .= "Looked for file '" . $controller . "_controller.php' in:"; $e .= "<small><pre>"; foreach ($search_errors as $d) { $e .= str_replace(plugin_folder(), '', $d) . "\r\n"; } $e .= "</pre></small>\r\n"; if ($this->called_from == 'SHORTCODE' or $this->called_from == 'WIDGET') { $this->request = array(); $this->CONTROLLER = new tina_mvc_controller_class(); $this->CONTROLLER->set_post_content($e); return FALSE; } else { error($e, $suppress_esc = TRUE); } } elseif (get_tina_mvc_setting('missing_page_controller_action') == 'display_404') { $this->request = array(); $this->CONTROLLER = new tina_mvc_controller_class(); $this->CONTROLLER->set_post_content(FALSE); $this->is_404 = TRUE; return FALSE; } elseif (get_tina_mvc_setting('missing_page_controller_action') == 'redirect') { wp_redirect(site_url()); exit; } else { error('TODO: Error setting ' . get_tina_mvc_setting('missing_page_controller_action') . ' not implemented'); } } }
/** * Searches for a file in the standard Tina MVC application folders * * In case of error the locations we looked in are stored in $find_app_file_error for * use in an error message later. * * @param string $filename * @param string $tina_mvc_page the page the controller is accessed through * @param string $called_from PAGE_FILTER, WIDGET, SHORTCODE, CALLABLE_CONTROLLER * @param array $find_app_file_error contains a list of places searched (for use in case of error) * @return mixed FALSE or the full path and filename to the file to be included */ function find_app_file($filename = '', $tina_mvc_page = '', $called_from = 'PAGE_FILTER', &$find_app_file_error) { $find_app_file_error = array(); $looked_for = array(); if ($called_from == 'PAGE_FILTER') { // this is left empty if a custom folder location is used if ($tina_mvc_page) { $page_folder = $tina_mvc_page . '/'; } /** * Is demo mode enabled? */ if (get_tina_mvc_setting('demo_mode')) { if (file_exists($f = plugin_folder() . "/demo/pages/tina_mvc_demo_and_docs/{$filename}")) { return $f; } $looked_for[] = $f; } if (file_exists($f = app_folder() . '/pages/' . $page_folder . $filename)) { return $f; } $looked_for[] = $f; // don't bother looking if there is no $tina_mvc_page - we've already looked in the location in the check above if ($tina_mvc_page and get_tina_mvc_setting('app_cascade')) { if (file_exists($f = app_folder() . '/pages/' . $filename)) { return $f; } $looked_for[] = $f; } if ($secondary_folder = app_folder(TRUE)) { // multisite and multisite app cascade enabled if (file_exists($f = $secondary_folder . '/pages/' . $page_folder . $filename)) { return $f; } $looked_for[] = $f; if (get_tina_mvc_setting('app_cascade')) { if (file_exists($f = $secondary_folder . '/pages/' . $filename)) { return $f; } } $looked_for[] = $f; } if (file_exists($f = tina_mvc_folder() . '/pages/' . $filename)) { return $f; } $looked_for[] = $f; } elseif ($called_from == 'WIDGET' or $called_from == 'SHORTCODE' or $called_from == 'CALLABLE_CONTROLLER') { $search_folder = strtolower($called_from) . 's'; // i.e. "widget" -> "widgets", etc if (file_exists($f = app_folder() . "/{$search_folder}/{$filename}")) { return $f; } $looked_for[] = $f; if ($secondary_folder = app_folder(TRUE)) { // multisite and multisite app cascade enabled if (file_exists($f = $secondary_folder . "/{$search_folder}/{$filename}")) { return $f; } $looked_for[] = $f; } } else { error("Invalid parameter. No action for '\$called_from' == '{$called_from}'"); } // we have an error $find_app_file_error = $looked_for; return FALSE; }