<commit_before><?php
namespace Craft;

class ImportController extends BaseController 
{

    public function actionGetEntryTypes() 
    {
    
        // Only ajax post requests
        $this->requirePostRequest();
        $this->requireAjaxRequest();
        
        // Get section
        $section = craft()->request->getPost('section');
        $section = craft()->sections->getSectionById($section);
        
        // Get entry types
        $entrytypes = $section->getEntryTypes();
        
        // Return JSON
        $this->returnJson($entrytypes);
    
    }

    // Upload file and process it for mapping
    public function actionUploadFile() 
    {
    
        // Only post requests
        $this->requirePostRequest();
    
        // Get file
        $file = \CUploadedFile::getInstanceByName('importFile');
 
        // Save file to Craft's temp folder for later use
        $file->saveAs(craft()->path->getTempUploadsPath().$file->getName());
         
        // Get section
        $section = craft()->request->getPost('importSection');
        $entrytype = craft()->request->getPost('importEntryType');
        
        // Get behavior
        $behavior = craft()->request->getPost('importBehavior');
        
        // Send e-mail?
        $email = craft()->request->getPost('importEmail');
        
        // Backup?
        $backup = craft()->request->getPost('importBackup');
        
        // Put vars in model
        $import            = new ImportModel();
        $import->file      = craft()->path->getTempUploadsPath().$file->getName();
        $import->type      = $file->getType();
        $import->section   = $section;
        $import->entrytype = $entrytype;
        $import->behavior  = $behavior;
        $import->email     = $email;
        $import->backup    = $backup;
        
        // Validate model
        if($import->validate()) {
        
            // Get columns
            $columns = craft()->import->columns($import->file);
            
            // Template options
            $options = array(
                'import' => $import,
                'columns' => $columns
            );
            
            // Render template (by hook, so you can edit the template)
            $templates = craft()->plugins->call('registerImportTemplate', array('map', $options));
                        
            // Check if there's a custom template
            foreach($templates as $plugin => $template) {
            
                // If so, return that template
                craft()->end($template);
            
            }
            
            // Else, return the normal template
            $this->renderTemplate('import/_map', $options);
        
        } else {
        
            // Not validated, show error
            craft()->userSession->setError(Craft::t('This filetype is not valid!').': '.$import->type);
            
        }
    
    }
    
    // Start import task
    public function actionImportFile() 
    {
    
        // Only post requests
        $this->requirePostRequest();
        
        // Get section
        $section = craft()->request->getParam('section');
        $entrytype = craft()->request->getParam('entrytype');
        <commit_msg>Fixed a bug with rendering hook templates<commit_after><?php
namespace Craft;

class ImportController extends BaseController 
{

    public function actionGetEntryTypes() 
    {
    
        // Only ajax post requests
        $this->requirePostRequest();
        $this->requireAjaxRequest();
        
        // Get section
        $section = craft()->request->getPost('section');
        $section = craft()->sections->getSectionById($section);
        
        // Get entry types
        $entrytypes = $section->getEntryTypes();
        
        // Return JSON
        $this->returnJson($entrytypes);
    
    }

    // Upload file and process it for mapping
    public function actionUploadFile() 
    {
    
        // Only post requests
        $this->requirePostRequest();
    
        // Get file
        $file = \CUploadedFile::getInstanceByName('importFile');
 
        // Save file to Craft's temp folder for later use
        $file->saveAs(craft()->path->getTempUploadsPath().$file->getName());
         
        // Get section
        $section = craft()->request->getPost('importSection');
        $entrytype = craft()->request->getPost('importEntryType');
        
        // Get behavior
        $behavior = craft()->request->getPost('importBehavior');
        
        // Send e-mail?
        $email = craft()->request->getPost('importEmail');
        
        // Backup?
        $backup = craft()->request->getPost('importBackup');
        
        // Put vars in model
        $import            = new ImportModel();
        $import->file      = craft()->path->getTempUploadsPath().$file->getName();
        $import->type      = $file->getType();
        $import->section   = $section;
        $import->entrytype = $entrytype;
        $import->behavior  = $behavior;
        $import->email     = $email;
        $import->backup    = $backup;
        
        // Validate model
        if($import->validate()) {
        
            // Get columns
            $columns = craft()->import->columns($import->file);
            
            // Template options
            $options = array(
                'import' => $import,
                'columns' => $columns
            );
            
            // Render template (by hook, so you can edit the template)
            $templates = craft()->plugins->call('registerImportTemplate', array('map'));
                        
            // Check if there's a custom template
            foreach($templates as $plugin => $template) {
            
                // If so, return that template
                $this->renderTemplate($template, $options);
            
            }
            
            // Else, return the normal template
            $this->renderTemplate('import/_map', $options);
        
        } else {
        
            // Not validated, show error
            craft()->userSession->setError(Craft::t('This filetype is not valid!').': '.$import->type);
            
        }
    
    }
    
    // Start import task
    public function actionImportFile() 
    {
    
        // Only post requests
        $this->requirePostRequest();
        
        // Get section
        $section = craft()->request->getParam('section');
        $entrytype = craft()->request->getParam('entrytype');
        
{'fraction_non_alphanumeric': 0.13411836672274047, 'fraction_numerical': 0.0, 'mean_word_length': 1.5839589095219282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4900326', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1584, 'n_words': 356}