Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/pornstar/components/add.php
Строк: 165
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_pornstar_add
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$db            VF::factory('database');
        
$pcfg        VF::cfg('module.pornstar');
        
        
$unique        mt_rand().'_'.time();
        
$errors        = array();
        
$messages    = array();
        
$pornstar    = array(
            
'name' => '''slug' => '''description' => '''gender' => '',
            
'birth_date' => '0000-00-00''birth_location' => '''birth_name' => '',
            
'aliases' => '''eye_color' => '''hair_color' => '''weight' => '',
            
'height' => '''measurements' => '''natural_bust' => '''ethnicity' => '',
            
'performs' => '''links' => ''
        
);
        
        if (isset(
$_POST['submit_pornstar_add'])) {
            
$filter            VF::factory('filter');
            
$unique            $filter->get('unique');
            
$name            $filter->get('name');
            
$slug            $filter->get('slug');
            
$description    trim($_POST['description']);
            
$gender            $filter->get('gender');
            
$birth_year        = (int) trim($_POST['Date_year']);
            
$birth_month    = (int) trim($_POST['Date_month']);
            
$birth_day        = (int) trim($_POST['Date_day']);
            
$birth_location    $filter->get('birth_location');
            
$birth_name        $filter->get('birth_name');
            
$aliases        $filter->get('aliases');
            
$eye_color        $filter->get('eye_color');
            
$hair_color        $filter->get('hair_color');
            
$weight            $filter->get('weight');
            
$height            $filter->get('height');
            
$measurements    $filter->get('measurements');
            
$natural_bust    $filter->get('natural_bust');
            
$ethnicity        $filter->get('ethnicity');
            
$file_path        $filter->get('file_path');
            
$performs        $filter->get('performs');
            
$links            trim($_POST['links']);
            
            if (
$name == '') {
                
$errors[]    = 'Pornstar name field cannot be left blank!';
            } else {
                
$pornstar['name'] = $name;
            }
            
            if (
$slug == '') {
                
$errors[]    = 'Pornstar SLUG field cannot be left blank!';
            } elseif (!
VValid::slug($slug)) {
                
$errors[]    = 'Pornstar SLUG can contain only lowertype letters and dashes!';
            } else {
                
$db->query("SELECT model_id
                            FROM #__model
                            WHERE slug = '"
.$db->escape($slug)."'
                            LIMIT 1"
);
                if (
$db->affected_rows()) {
                    
$errors[]    = 'Pornstar SLUG is already used for another pornstar entry!';
                } else {
                    
$pornstar['slug'] = $slug;
                }
            }
            
            
            if (
$gender != '') {
                if (
in_array($gender, array('female''male''tranny'))) {
                    
$pornstar['gender'] = $gender;
                } else {
                    
$errors[] = 'Invalid pornstar gender! What exactly did you select!?';
                }
            }

            if (
$birth_day !== OR $birth_month !== OR $birth_year !== 0) {
                  if (
$birth_day === OR $birth_month === OR $birth_year === 0) {
                      
$errors[] = 'Please enter pornstar complete birth date!';
                } else {
                      if (!
checkdate($birth_month$birth_day$birth_year)) {
                          
$errors[] = 'Birth date is not a valid date!';
                    } else {
                        
$birth_date $birth_year.'-'.sprintf('%02d'$birth_month).'-'.sprintf('%02d'$birth_day);
                    }
                }
            } else {
                
$birth_date '0000-00-00';
            }
            
            if (
$file_path != '') {
                  if (!
file_exists($file_path) OR !is_file($file_path)) {
                      
$errors[] = 'Invalid pornstar photo path!';
                  } else {
                      
$ext    VFile::ext($file_path);
                  }
              } else {
                  
$errors[] = 'Please upload a photo for this pornstar!';
            }
            
            
$pornstar['description']    = $description;
            
$pornstar['aliases']        = $aliases;
            
$pornstar['birth_location']    = $birth_location;
            
$pornstar['birth_name']        = $birth_name;
            
$pornstar['eye_color']        = $eye_color;
            
$pornstar['hair_color']        = $hair_color;
            
$pornstar['weight']            = $weight;
            
$pornstar['height']            = $height;
            
$pornstar['measurements']    = $measurements;
            
$pornstar['ethnicity']        = $ethnicity;
            
$pornstar['performs']        = $performs;
            
$pornstar['links']            = $links;
            
            if (!
$errors) {
                  
$db->query("INSERT INTO #__model
                              SET name = '"
.$db->escape($name)."',
                                  slug = '"
.$db->escape($slug)."',
                                  description = '"
.$db->escape($description)."',
                                  gender = '"
.$db->escape($gender)."',
                                  ext = '"
.$db->escape($ext)."',
                                  add_date = '"
.date('Y-m-d h:i:s')."',
                                  status = '0'"
);
                  if (
$db->affected_rows()) {
                      
$model_id    $db->get_last_insert_id('#__model');
                      
$db->query("INSERT INTO #__model_bio
                                  SET model_id = "
.$model_id.",
                                      birth_date = '"
.$db->escape($birth_date)."',
                                      birth_location = '"
.$db->escape($birth_location)."',
                                      birth_name = '"
.$db->escape($birth_name)."',
                                      aliases = '"
.$db->escape($aliases)."',
                                      eye_color = '"
.$db->escape($eye_color)."',
                                      hair_color = '"
.$db->escape($hair_color)."',
                                      weight = '"
.$db->escape($weight)."',
                                      height = '"
.$db->escape($height)."',
                                      measurements = '"
.$db->escape($measurements)."',
                                      natural_bust = '"
.$db->escape($natural_bust)."',
                                      ethnicity = '"
.$db->escape($ethnicity)."',
                                      performs = '"
.$db->escape($performs)."',
                                      links = '"
.$db->escape($links)."'");
                      
                      
$image VF::factory('image');
                      if (
$image->load($file_path)) {
                          
$dst MEDIA_DIR.'/pornstars/'.$model_id.'.'.$ext;
                          if (isset(
$_POST['photo'])) {
                              
$x          = (int) $_POST['x'];
                              
$y          = (int) $_POST['y'];
                              
$x2         = (int) $_POST['x2'];
                              
$y2         = (int) $_POST['y2'];
                              
$w          = (int) $_POST['w'];
                              
$h          = (int) $_POST['h'];
                              if (!
$image->crop($x$y$w$h$dst)) {
                                  
$errors[] = $image->get_error();
                              }                                                                                                                       
                          } else {
                              if (!
$image->canvas($pcfg['photo_width'], $pcfg['photo_height'], '000000') OR
                                  !
$image->resize($pcfg['photo_width'], $pcfg['photo_height'], 'ASPECT_RATIO') OR
                                  !
$image->crop_from_center($pcfg['photo_width'], $pcfg['photo_height'], $dst)) {
                                  
$errors[] = $image->get_error();
                              }
                          }
                      } else {
                          
$errors[] = $image->get_error();
                      }
                      
                      if (!
$errors) {
                          
VFile::delete($file_path);

                          
$db->query("UPDATE #__model SET status = '1' WHERE model_id = ".$model_id." LIMIT 1");
                          
$messages[] = 'Pornstar added!';
                      }
                  } else {
                      
$errors[] = 'Failed to add pornstar database entry! Application error!?';
                  }
            }
        }
    
        
$tpl VF::factory('template');
        
$tpl->menu            'pornstar';
        
$tpl->submenu        'pornstar_add';
        
$tpl->meta_title    'Admin::Pornstar::Add';
        
$tpl->css            = array(TPL_REL.'/css/jquery.Jcrop.css');
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->pcfg            $pcfg;
        
$tpl->unique        $unique;
        
$tpl->pornstar        $pornstar;
        
$tpl->load(array('header''pornstar_add''footer'));
        
$tpl->display();
    }
}
Онлайн: 0
Реклама