Beispiel #1
0
 static function redirect($path = null, $parms = array())
 {
     if (!is_array($path) && preg_match('#^(\\w+:/)?/#i', $path)) {
         wp_redirect($path);
         exit;
     } else {
         if (!is_array($path) && ($path == '/' || $path === '' || $path === null)) {
             wp_redirect(get_bloginfo('home'));
             exit;
         } else {
             wp_redirect(get_link_to($path, $params));
             exit;
         }
     }
 }
Beispiel #2
0
 function form_open($path = array(), $attributes = '', $hidden = array(), $use_validation_engine = TRUE)
 {
     // default form method is post
     if (is_array($attributes) && !isset($attributes['method'])) {
         $attributes['method'] = 'post';
     } else {
         if (is_string($attributes) && stripos($attributes, 'method=') === FALSE) {
             $attributes .= ' method="post"';
         }
     }
     if (is_array($path) || !preg_match('#^(\\w+:/)?/#i', $path)) {
         extract(get_link_to($path, array(), TRUE));
         if ($context == 'back') {
             // if method is get, then page is a hidden input parameter
             // otherwise, it must be a Query String parameter in the form action
             if (is_array($attributes) && strtolower($attributes['method']) == 'get' || stripos($attributes, 'method="get"') !== FALSE) {
                 $form_action = $host;
                 $hidden = array_merge($hidden, array('page' => $page));
             } else {
                 $form_action = $host . '?page=' . $page;
             }
             // when app is null, $page does not include the parts of the CI path
             // spec that tell CI what to execute... so we include them as hidden
             // parameters
             if (!$app) {
                 $hidden = array_merge($hidden, array('a' => $application, 'c' => $controller, 'm' => $action, 'd' => $directory));
             }
         } else {
             // on the front-end, $url always has everything it needs to be the form action...
             $form_action = $url;
         }
     } else {
         $form_action = $path;
     }
     $form = $form_action ? '<form action="' . $form_action . '"' : '<form';
     // generate a random id, if one is not defined (to support the validation engine)
     $form_id = md5(uniqid() . $form_action . time());
     if ($use_validation_engine) {
         if (is_array($attributes)) {
             if (!isset($attributes['id'])) {
                 $attributes['id'] = $form_id;
             } else {
                 $form_id = $attributes['id'];
             }
         } else {
             $matches = array();
             if (!preg_match('#id="([^"]+)?"#i', $attributes, $matches)) {
                 $attributes .= ' id="' . $form_id . '"';
             } else {
                 // defined
                 $form_id = $matches[1];
             }
         }
     }
     $form .= _attributes_to_string($attributes, TRUE);
     $form .= '>';
     if ($use_validation_engine) {
         // make sure that our localization helper has been loaded
         $CI =& get_instance();
         if ($CI) {
             $CI->load->helper('localization');
             $locale = substr(locale(), 0, 2);
         } else {
             $locale = 'en';
         }
         wp_enqueue_script("jquery-ve-{$locale}", resource("/js/jquery.ve-{$locale}.js"), array('jquery'));
         wp_enqueue_script('jquery-ve', resource('/js/jquery.ve.js'), array("jquery-ve-{$locale}"));
         wp_enqueue_style('jquery-ve', resource('/css/ve.jquery.css'));
         $id = $attributes['id'];
         $form .= "\n<script type=\"text/javascript\"> jQuery(function() { jQuery('#{$form_id}').validationEngine(); }); </script>";
     }
     wp_enqueue_script('wpci-admin', resource('/js/admin.js'), array('jquery'));
     if (is_array($hidden) and count($hidden) > 0) {
         $form .= form_hidden($hidden);
     }
     return $form;
 }