Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/pornstar/components/add_xml.php
Строк: 136
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_pornstar_add_xml
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
$warnings    = array();
    
        
$method        'file';
        
$force        TRUE;
        if (isset(
$_POST['submit-add-xml'])) {
            
$method        VF::factory('filter')->get('method');
            
$force        = (isset($_POST['force'])) ? TRUE FALSE;
            
            if (
$method    == 'text') {
                
$xml    trim($_POST['xml']);
            } elseif (
$method == 'file') {
                if (!
$file VUpload::process('file'1000, array('txt''xml'))) {
                    
$errors VUpload::error();
                }
                
                if (!
$errors) {
                    
$xml    file_get_contents($file['path']);
                }
            } else {
                
$errors[] = 'Invalid import method! What exactly did you select!?';
            }
            
            if (!
$errors) {
                
libxml_use_internal_errors(true);
                
$xml    simplexml_load_string($xml);
                if (!
$xml) {
                      foreach (
libxml_get_errors() as $error) {
                          echo 
VF::Debug($error);
                          
$errors[] = 'XML Error: '.$error->message;
                    }
                }
                
                if (!
$errors) {
                      
$total    0;
                      
$added    0;
                      
$exists    0;
                      
                      
$db        VF::factory('database');
                      
$image    VF::factory('image');
                      
                      
session_write_close();
                      
                      foreach (
$xml as $pornstar) {
                          ++
$total;
                      
                          
$pornstar         VArray::from_xml($pornstar);
                          
$first_name        = (isset($pornstar['firstname'])) ? $pornstar['firstname'] : NULL;
                          
$last_name        = (isset($pornstar['lastname'])) ? $pornstar['lastname'] : NULL;
                          
$bio            = (isset($pornstar['bio'])) ? $pornstar['bio'] : NULL;
                          
$birth_date        = (isset($pornstar['birth_date'])) ? $pornstar['birth_date'] : NULL;
                          
$age            = (isset($pornstar['age'])) ? $pornstar['age'] : NULL;
                          
$age            = (isset($age) && (int) $age 100) ? $age;
                          
$aliases        = (isset($pornstar['alias'])) ? $pornstar['alias'] : NULL;
                          
$height            = (isset($pornstar['height'])) ? $pornstar['height'] : NULL;
                          
$weight            = (isset($pornstar['weight'])) ? $pornstar['weight'] : NULL;
                          
$measurements    = (isset($pornstar['measurements'])) ? $pornstar['measurements'] : NULL;
                          
$breast            = (isset($pornstar['breast'])) ? $pornstar['breast'] : NULL;
                          
$waist            = (isset($pornstar['waist'])) ? $pornstar['waist'] : NULL;
                          
$hips            = (isset($pornstar['hips'])) ? $pornstar['hips'] : NULL;
                          
$tattoes        = (isset($pornstar['tattoo'])) ? $pornstar['tattoo'] : NULL;
                          
$piercings        = (isset($pornstar['piercing'])) ? $pornstar['piercing'] : NULL;
                          
$nationality    = (isset($pornstar['nationality'])) ? $pornstar['nationality'] : NULL;
                          
$ethnicity        = (isset($pornstar['ethnicity'])) ? $pornstar['ethnicity'] : NULL;
                          
$hair_color        = (isset($pornstar['hairy_color'])) ? $pornstar['hair_color'] : NULL;
                          
$eye_color        = (isset($pornstar['eye_color'])) ? $pornstar['eye_color'] : NULL;
                          
$skin_color        = (isset($pornstar['skin_color'])) ? $pornstar['skin_color'] : NULL;
                          
                          if (isset(
$first_name) && isset($last_name)) {
                              
$name    $first_name.' '.$last_name;
                              
$slug    prepare_string($nameTRUE);
                              
                              
$db->query("SELECT model_id
                                          FROM #__model
                                          WHERE slug = '"
.$db->escape($slug)."'
                                          LIMIT 1"
);
                              if (
$db->affected_rows()) {
                                  ++
$exists;
                                  continue;
                              }
                              
                              
$ext    FALSE;
                              
                              
$db->query("INSERT INTO #__model
                                          SET name = '"
.$db->escape($name)."',
                                              slug = '"
.$db->escape($slug)."'");
                              if (
$db->affected_rows()) {
                                  
$model_id    $db->get_last_insert_id('#__model');
                                  
                                  if (isset(
$pornstar['photo_url']) && $pornstar['photo_url'] != '') {
                                      
$url        $pornstar['photo_url'];
                                      
$tmp_file    tempnam(TMP_DIR.'/downloads''model_');
                                      if (
VCurl::file($url$tmp_file)) {
                                          if (
$image->load($tmp_file)) {
                                              
$ext    $image->src['ext'];
                                          }
                                      }
                                  }
                                  
                                  if (!
$ext) {
                                      
$ext         'gif';
                                      
$tmp_file    MEDIA_DIR.'/users/nopic-hidden.gif';
                                  }
                                  
                                  
copy($tmp_fileMEDIA_DIR.'/pornstars/'.$model_id.'.'.$ext);
                                  
                                  
$db->query("UPDATE #__model
                                              SET ext = '"
.$db->escape($ext)."'
                                              WHERE model_id = "
.$model_id."
                                              LIMIT 1"
);
                                              
                                  if (isset(
$breast) && isset($waist) && isset($hips)) {
                                      
$measurements $breast.'-'.$waist.'-'.$hips;
                                  }
                                  
                                  
$db->query("INSERT INTO #__model_bio
                                              SET model_id = "
.$model_id.",
                                                  birth_date = '"
.$db->escape($birth_date)."',
                                                  age = "
.$age.",
                                                  aliases = '"
.$db->escape($aliases)."',
                                                  skin_color = '"
.$db->escape($skin_color)."',
                                                  eye_color = '"
.$db->escape($eye_color)."',
                                                  hair_color = '"
.$db->escape($hair_color)."',
                                                  weight = '"
.$db->escape($weight)."',
                                                  height = '"
.$db->escape($height)."',
                                                  measurements = '"
.$db->escape($measurements)."',
                                                  nationality = '"
.$db->escape($nationality)."',
                                                  ethnicity = '"
.$db->escape($ethnicity)."'");
                                  ++
$added;
                                                  
                              }
                          }
                      }
                      
                      
$messages[] = 'XML contains '.$total.' models! Added '.$added.'!';
                      if (!empty(
$exists)) {
                          
$warnings[] = $exists.' models already found in your database!';
                      }
                }
            }
        }
        
    
        
$tpl                VF::factory('template');
        
$tpl->menu            'pornstar';
        
$tpl->submenu        'pornstar_add';
        
$tpl->extramenu        'pornstar_add_xml';
        
$tpl->meta_title    'Pornstar::Add::XML';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->warnings        $warnings;
        
$tpl->method        $method;
        
$tpl->force            $force;
        
$tpl->load(array('header''pornstar_add_xml''footer'));
        
$tpl->display();
    }
}
Онлайн: 0
Реклама