Exemple #1
0
 public static function getLang($value = '')
 {
     static $array = array();
     static $set;
     static $current;
     if ($value == 'array' && count($array)) {
         return $array;
     }
     if ($value == 'set' && !is_null($set)) {
         return $set;
     }
     if (in_array($value, array('locale', 'name', 'segment', 'index', 'dateformat')) && !is_null($current)) {
         return $current[$value];
     }
     if ($value == '' && !is_null($current)) {
         return $current;
     }
     //no static cache?  so cycle languages and uri and fill static vars
     $segments = array();
     foreach (rpd::config("languages") as $lang) {
         if ($lang['segment'] == '') {
             $default = $lang;
             continue;
         }
         $segments[$lang['segment']] = $lang;
     }
     $current = $default;
     if (count($segments) > 0) {
         //piu' di una lingua
         $set = '(' . implode('|', array_keys($segments)) . ')';
         if (preg_match('@^' . $set . '/?@i', url_helper::get_uri(), $match)) {
             $current = $segments[$match[1]];
         }
     }
     $array = array_merge(array('default' => $default), $segments);
     $curr = array_search($current, $array);
     $array[$curr]['is_current'] = true;
     if ($value == 'array') {
         return $array;
     }
     if ($value == 'set') {
         return $set;
     }
     if (in_array($value, array('locale', 'name', 'segment', 'index'))) {
         return $current[$value];
     }
     return $current;
 }
 /**
  * main method it detect status, exec action and build output
  *
  * @param string $method
  */
 public function build($method = 'form')
 {
     $this->process_url = $this->process_url . $this->hash;
     //detect form status (output)
     if (isset($this->model)) {
         $this->status = $this->model->loaded ? "modify" : "create";
     } else {
         $this->status = "create";
     }
     //build fields
     $this->build_fields();
     //process only if instance is a dataform
     if (is_a($this, 'dataform_library')) {
         //build buttons
         $this->build_buttons();
         //sniff action
         if (isset($_POST) && url_helper::value('process')) {
             $this->action = $this->status == "modify" ? "update" : "insert";
         }
         //process
         $this->process();
     }
     $method = 'build_' . $method;
     $this->output = $this->{$method}();
 }