Example #1
0
 function execute(&$form, $action_id)
 {
     $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
     $config = new \GCore\Libs\Parameter($config);
     $file_path = $config->get('path');
     if (\GCore\Libs\File::exists($file_path)) {
         \GCore\Libs\Download::send($file_path);
     }
 }
 function delete_cache()
 {
     $path = \GCore\C::get('GCORE_FRONT_PATH') . 'cache' . DS;
     $files = \GCore\Libs\Folder::getFiles($path);
     $count = 0;
     foreach ($files as $k => $file) {
         if (basename($file) != 'index.html' and basename($file) != 'demos.cf5bak') {
             $result = \GCore\Libs\File::delete($file);
             if ($result) {
                 $count++;
             }
         }
     }
     $session = \GCore\Libs\Base::getSession();
     $session->setFlash('info', $count . ' ' . l_('CACHE_FILES_DELETED'));
     $this->redirect(r_('index.php?ext=chronoforms'));
 }
Example #3
0
 function processUpload(&$form, $file_post = array(), $field_name, $file_extensions)
 {
     //check valid file
     if (!\GCore\Libs\Upload::valid($file_post)) {
         return false;
     }
     //check not empty file upload
     if (!\GCore\Libs\Upload::not_empty($file_post)) {
         return false;
     }
     //check errors
     if (!isset($file_post['tmp_name']) or !is_uploaded_file($file_post['tmp_name'])) {
         if (!empty($file_post['error']) and $file_post['error'] !== UPLOAD_ERR_OK) {
             $form->debug[$action_id][self::$title][] = 'PHP returned this error for file upload by : ' . $field_name . ', PHP error is: ' . $file_post['error'];
             $form->errors[$field_name] = $file_post['error'];
         }
         $this->events['fail'] = 1;
         return false;
     } else {
         $form->debug[$action_id][self::$title][] = 'Upload routine started for file upload by : ' . $field_name;
     }
     if ((bool) $this->config->get('safe_file_name', 1) === true) {
         $file_name = \GCore\Libs\File::makeSafe($file_post['name']);
     } else {
         $file_name = utf8_decode($file_post['name']);
     }
     $real_file_name = $file_name;
     $file_tmp_name = $file_post['tmp_name'];
     $file_info = pathinfo($file_name);
     //mask the file name
     if (strlen($this->config->get('forced_file_name', '')) > 0) {
         $file_name = str_replace('FILE_NAME', $file_name, $this->config->get('forced_file_name', ''));
     } else {
         $file_name = date('YmdHis') . '_' . $file_name;
     }
     //check the file size
     if ($file_tmp_name) {
         //check max size
         if ($file_post['error'] === UPLOAD_ERR_INI_SIZE) {
             $form->debug[$action_id][self::$title][] = 'File : ' . $field_name . ' size is over the max PHP configured limit.';
             $form->errors[$field_name] = $this->config->get('max_error', 'Sorry, Your uploaded file size (' . $file_post["size"] / 1024 . ' KB) exceeds the allowed limit.');
             $this->events['fail'] = 1;
             return false;
         } elseif ($file_post["size"] / 1024 > (int) $this->config->get('max_size', 100)) {
             $form->debug[$action_id][self::$title][] = 'File : ' . $field_name . ' size is over the max limit.';
             $form->errors[$field_name] = $this->config->get('max_error', 'Sorry, Your uploaded file size (' . $file_post["size"] / 1024 . ' KB) exceeds the allowed limit.');
             $this->events['fail'] = 1;
             return false;
         } elseif ($file_post["size"] / 1024 < (int) $this->config->get('min_size', 0)) {
             $form->debug[$action_id][self::$title][] = 'File : ' . $field_name . ' size is less than the minimum limit.';
             $form->errors[$field_name] = $this->config->get('min_error', 'Sorry, Your uploaded file size (' . $file_post["size"] / 1024 . ' KB) is less than the minimum limit.');
             $this->events['fail'] = 1;
             return false;
         } elseif (!in_array(strtolower($file_info['extension']), $file_extensions)) {
             $form->debug[$action_id][self::$title][] = 'File : ' . $field_name . ' extension is not allowed.';
             $form->errors[$field_name] = $this->config->get('type_error', 'Sorry, Your uploaded file type is not allowed.');
             $this->events['fail'] = 1;
             return false;
         } else {
             $uploaded_file = \GCore\Libs\Upload::save($file_tmp_name, $this->upload_path . $file_name);
             if ($uploaded_file) {
                 $uploaded_file_data = array();
                 $uploaded_file_data = array('name' => $file_name, 'original_name' => $real_file_name, 'path' => $this->upload_path . $file_name, 'size' => $file_post["size"]);
                 //Try to generate an auto file link
                 $site_link = \GCore\C::get('GCORE_FRONT_URL');
                 if (substr($site_link, -1) == "/") {
                     $site_link = substr_replace($site_link, '', -1);
                 }
                 $uploaded_file_data['link'] = str_replace(array(\GCore\C::get('GCORE_FRONT_PATH'), DS), array($site_link, "/"), $this->upload_path . $file_name);
                 //$form->data[$field_name] = $file_name;
                 $form->debug[$action_id][self::$title][] = $this->upload_path . $file_name . ' has been uploaded successfully.';
                 $this->events['success'] = 1;
                 return $uploaded_file_data;
             } else {
                 $form->debug[$action_id][self::$title][] = $this->upload_path . $file_name . ' could not be uploaded!!';
                 $this->events['fail'] = 1;
                 return false;
             }
         }
     }
 }
Example #4
0
    public function on_list($fld, $ttl, &$data_columns)
    {
        $config = new \GCore\Libs\Parameter($this->connection['Connection']['extras']['plugins']['download']);
        if ($config->get('path_field') and $config->get('download_action')) {
            $path = $config->get('path_field');
            $action = $config->get('download_action');
            if ($fld == '_DOWNLOAD_.link') {
                $link = r_('index.php?ext=chronoconnectivity&cont=lists&act=' . $action . '&ccname=' . $this->connection['Connection']['title'] . '&gcb={' . $this->model->alias . '.' . $this->model->pkey . '}');
                $text = $ttl;
                if ($config->get('display_icon', 1)) {
                    $text = '<i class="fa fa-download fa-fw"></i> ' . $text;
                }
                $data_columns[$fld]['html'] = '<a class="' . $config->get('download_link_class', 'btn btn-success btn-xs') . '" href="' . $link . '">' . $text . '</a>';
            }
            $file_info = array();
            $file_info['filesize'] = '';
            $file_info['filetime'] = '';
            $file_info['filename'] = '';
            $get_file_info = function ($cell, $row, $column) use($path, $file_info, $config) {
                $file_path = \GCore\Libs\Arr::getVal($row, explode('.', $path));
                if ($config->get('download_path')) {
                    $file_path = rtrim($config->get('download_path'), DS) . DS . $file_path;
                }
                //$file_info = array();
                if (file_exists($file_path)) {
                    if (is_dir($file_path)) {
                        //this is a folder
                        $files = @\GCore\Libs\Folder::getFiles($file_path, false);
                        foreach ($files as $file) {
                            $found[$file] = filemtime($file);
                        }
                        if (empty($found)) {
                            return false;
                        }
                        arsort($found);
                        $files = array_keys($found);
                        sort($files);
                        $file = array_pop($files);
                        $file_info['filesize'] = \GCore\Libs\File::humanSize(filesize($file));
                        $file_info['filetime'] = date($config->get('filetime_format', 'd-m-Y H:i'), filemtime($file));
                        $file_info['filename'] = basename($file);
                    } else {
                        //this is a file
                        $file = $file_path;
                        $file_info['filesize'] = \GCore\Libs\File::humanSize(filesize($file));
                        $file_info['filetime'] = date($config->get('filetime_format', 'd-m-Y H:i'), filemtime($file));
                        $file_info['filename'] = basename($file);
                    }
                }
                foreach ($file_info as $k => $info) {
                    if ($column == '_DOWNLOAD_.' . $k) {
                        return $file_info[$k];
                    }
                }
                return '';
                //$file_info;
            };
            foreach ($file_info as $k => $info) {
                if ($fld == '_DOWNLOAD_.' . $k) {
                    $data_columns[$fld]['function'] = $get_file_info;
                }
            }
            if ($fld == '_HkkITS_.hot') {
                $data_columns[$fld]['function'] = create_function('$value,$row', '
					if(\\GCore\\Libs\\Arr::getVal($row, explode(".", "' . $download . '"), 0) >= (int)' . $config->get('hot_limit', '1000') . '){
						return 1;
					}else{
						return 0;
					}
				');
                $data_columns[$fld]['html'] = array(0 => '', 1 => '<span class="label label-danger">' . $config->get('hot_text', 'Hot') . '</span>');
            }
        }
    }
Example #5
0
	function execute(&$form, $action_id){
		$config =  $form->actions_config[$action_id];
		$config = new \GCore\Libs\Parameter($config);
		
		$content = $config->get('content', "");
		ob_start();
		eval('?>'.$content);
		$output = ob_get_clean();
		//if the content box was empty, display the form output
		if(empty($output)){
			$output = $form->form_output;
		}
		$output = \GCore\Libs\Str::replacer($output, $form->data);
		//begin tcpdf code
		require_once('tcpdf/config/lang/eng.php');
		require_once('tcpdf/tcpdf.php');
						
		// create new PDF document
		$pdf = new \TCPDF($config->get('pdf_page_orientation', 'P'), PDF_UNIT, $config->get('pdf_page_format', 'A4'), true, 'UTF-8', false);
		
		//set protection if enabled
		if((bool)$config->get('enable_protection', 0) === true){
			$owner_pass = ($config->get('owner_pass', "") ? $config->get('owner_pass', "") : null);
			$perms = (strlen($config->get('permissions', "")) > 0) ? explode(",", $config->get('permissions', "")) : array();
			$pdf->SetProtection($perms, $config->get('user_pass', ""), $owner_pass, $config->get('sec_mode', ""), $pubkeys=null);
		}

		// set document information
		$pdf->SetCreator(PDF_CREATOR);
		$pdf->SetAuthor($config->get('pdf_author', 'PDF Author.'));
		$pdf->SetTitle($config->get('pdf_title', 'PDF Title Goes Here.'));
		$pdf->SetSubject($config->get('pdf_subject', 'Powered by Chronoforms + TCPDF'));
		$pdf->SetKeywords($config->get('pdf_keywords', 'Chronoforms, PDF Plugin, TCPDF, PDF, '.$form->form['Form']['title']));
	
		// Willian	
		// set header data, font and margins
		if((bool)$config->get((bool)$config->get('pdf_header_show', 1))){
			if(strlen($config->get('pdf_title')) OR strlen($config->get('pdf_header'))){
                        	$pdf->SetHeaderData(false, 0, $config->get('pdf_title', 'PDF Title Goes Here.'), $config->get('pdf_header', 'Powered by Chronoforms + TCPDF'));
                	}
			$pdf->setHeaderFont(Array($config->get('pdf_header_font', 'helvetica'), '', (int)$config->get('pdf_header_font_size', 10)));
			$pdf->SetHeaderMargin($config->get('pdf_margin_header', 5));
			$pdf->setPrintHeader(true);
		} else {
			$pdf->setPrintHeader(false);
		}
		
		// set footer font and margins
		if((bool)$config->get((bool)$config->get('pdf_footer_show', 1))){
			$pdf->setFooterFont(Array($config->get('pdf_footer_font', 'helvetica'), '', (int)$config->get('pdf_footer_font_size', 8)));
			$pdf->SetFooterMargin($config->get('pdf_margin_footer', 10));
			$pdf->setPrintFooter(true);
		} else {
			$pdf->setPrintFooter(false);
		}

		// set default monospaced font
		$pdf->SetDefaultMonospacedFont($config->get('pdf_monospaced_font', 'courier'));

		//set margins
		$pdf->SetMargins($config->get('pdf_margin_left', 15), $config->get('pdf_margin_top', 27), $config->get('pdf_margin_right', 15));

		//set auto page breaks
		$pdf->SetAutoPageBreak(TRUE, $config->get('pdf_margin_bottom', 25));

		//set image scale factor
		$pdf->setImageScale($config->get('pdf_image_scale_ratio', 1.25));

		//set some language-dependent strings
		$pdf->setLanguageArray($l);

		// Willian
                // Mostrar/Esconder CabeƧalho
                $pdf->setPrintHeader((bool)$config->get('pdf_header_show', 1));
                // Mostrar/Esconder RodapƩ
                $pdf->setPrintHeader((bool)$config->get('pdf_footer_show', 1));
		
		// ---------------------------------------------------------

		// set font
		$pdf->SetFont($config->get('pdf_body_font', 'courier'), '', (int)$config->get('pdf_body_font_size', 14));

		// add a page
		$pdf->AddPage();
		// create some HTML content
		$css = "";
		
		$output = $css.$output;
		$html = $output;
		// output the HTML content
		$pdf->writeHTML($html, true, false, true, false, '');
		// reset pointer to the last page
		$pdf->lastPage();
		//Close and output PDF document
		if(isset($form->data['pdf_file_name']) && !empty($form->data['pdf_file_name'])){
			$PDF_file_name = $form->data['pdf_file_name'];
		}else{
			if(strlen(trim($config->get('pdf_file_name', ''))) > 0){
				$PDF_file_name = trim($config->get('pdf_file_name', ''))."_".date('YmdHis');
			}else{
				$PDF_file_name = $form->form['Form']['title']."_".date('YmdHis');
			}
		}
		$PDF_view = $config->get('pdf_view', 'I');
		if(($PDF_view == 'F') || ($PDF_view == 'FI') || ($PDF_view == 'FD')){
			jimport('joomla.utilities.error');
			jimport('joomla.filesystem.file');
			jimport('joomla.filesystem.folder');
			$upload_path = $config->get('pdf_save_path');
			if(!empty($upload_path)){
				$upload_path = str_replace(array("/", "\\"), DS, $upload_path);
				if(substr($upload_path, -1) == DS){
					$upload_path = substr_replace($upload_path, '', -1);
				}
				$upload_path = $upload_path.DS;
				$config->set('pdf_save_path', $upload_path);
			}else{
				$upload_path = \GCore\C::ext_path('chronoforms', 'front').'pdfs'.DS.$form->form['Form']['title'].DS;
			}
			//check the save files path is ok
			if(!file_exists($upload_path.DS.'index.html')){
				if(!\GCore\Libs\Folder::create($upload_path)){
					$form->errors[] = "Couldn't create upload directory: ".$upload_path;
					$this->events['fail'] = 1;
					return;
				}
				$dummy_c = '<html><body bgcolor="#ffffff"></body></html>';
				if(!\GCore\Libs\File::write($upload_path.DS.'index.html', $dummy_c)){
					$form->errors[] = "Couldn't create upload directory index file.";
					$this->events['fail'] = 1;
					return;
				}
			}
			
			$PDF_file_path = $upload_path.$PDF_file_name.".pdf";
			$pdf->Output($PDF_file_path, $PDF_view);
			
			//Try to generate an auto file link
			$site_link = \GCore\C::get('GCORE_FRONT_URL');
			if(substr($site_link, -1) == "/"){
				$site_link = substr_replace($site_link, '', -1);
			}
			
			if(strlen(trim($config->get('pdf_post_name', ''))) > 0){
				$form->files[trim($config->get('pdf_post_name', ''))] = array('name' => $PDF_file_name.".pdf", 'path' => $PDF_file_path, 'size' => 0);
				$form->files[trim($config->get('pdf_post_name', ''))]['link'] = str_replace(array(\GCore\C::get('GCORE_FRONT_PATH'), DS), array($site_link, "/"), $upload_path.$PDF_file_name.".pdf");
				$form->data[trim($config->get('pdf_post_name', ''))] = $PDF_file_name.".pdf";
				$form->debug[$action_id][self::$title][] = $PDF_file_path.' has been saved correctly.';
			}
		}else{
			$pdf->Output($PDF_file_name.".pdf", $PDF_view);
		}
		if($PDF_view != 'F'){
			@flush();
			@ob_flush();
			exit;
		}
	}
Example #6
0
 function restore()
 {
     $files = $_FILES;
     if (is_array($files) and !empty($files)) {
         $session = \GCore\Libs\Base::getSession();
         if (!\GCore\Libs\Upload::valid($files['ccbackup'])) {
             $session->setFlash('error', l_('CONN_CONNECTIONS_RESTORE_ERROR'));
             return false;
         }
         if (!\GCore\Libs\Upload::not_empty($files['ccbackup'])) {
             $session->setFlash('error', l_('CONN_CONNECTIONS_RESTORE_ERROR'));
             return false;
         }
         if (!\GCore\Libs\Upload::check_type($files['ccbackup'], array('cc5bak'))) {
             $session->setFlash('error', l_('CONN_CONNECTIONS_RESTORE_ERROR'));
             return false;
         }
         $path = \GCore\C::get('GCORE_FRONT_PATH') . DS . 'cache';
         $uploaded_file = \GCore\Libs\Upload::save($files['ccbackup']['tmp_name'], $path . DS . $files['ccbackup']['name']);
         if (!$uploaded_file) {
             $session->setFlash('error', l_('CONN_CONNECTIONS_RESTORE_ERROR'));
         } else {
             $data = file_get_contents($path . DS . $files['ccbackup']['name']);
             \GCore\Libs\File::delete($path . DS . $files['ccbackup']['name']);
             $connections = unserialize(base64_decode(trim($data)));
             if (!empty($connections)) {
                 foreach ($connections as $connection) {
                     if (isset($connection['Connection']['id'])) {
                         $connection['Connection']['id'] = null;
                         $connection['Connection']['published'] = 0;
                         $this->Connection->save($connection);
                     }
                 }
             }
             $session->setFlash('success', l_('CONN_CONNECTIONS_RESTORED'));
             $this->redirect(r_('index.php?ext=chronoconnectivity'));
         }
     }
 }