Current Path : /var/www/html/clients/tatneft-nhs.ru/plugins/content/ |
Current File : /var/www/html/clients/tatneft-nhs.ru/plugins/content/excel.php |
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.plugin.plugin' ); jimport( 'joomla.application.component.helper' ); class plgContentExcel extends JPlugin { var $_plgExcelNr = 0; function _setExcelPluginNumber() { $this->_plgExcelNr = (int)$this->_plgExcelNr + 1; } function plgContentExcel ( &$subject, $params ) { parent::__construct( $subject, $params ); } function imgshow($imgid) { $jxlspppif = JURI::base().'/components/com_excel/pricesimg/'; echo "<div align=\"center\" id=\"prsimg\"><a href='$jxlspppif$imgid' rel='lightbox' title='".$imgid."'>"; echo "<img src='".JURI::base()."/components/com_excel/images/image.png' height=\"16px\" width=\"16px\" border=\"0\" "; echo "</a></div>"; } function uc2html($str) { $ret = ''; for( $i=0; $i<strlen($str)/2; $i++ ) { $charcode = ord($str[$i*2])+256*ord($str[$i*2+1]); $ret .= '&#'.$charcode; } return $ret; } function fatal($msg = '') { echo JText::_('pex error'); if( strlen($msg) > 0 ) echo ": $msg"; echo "<br />".JText::_('pex complete')."<br />"; if( $f_opened) @fclose($fh); // exit(); } function onPrepareContent( &$article, &$params, $limitstart ) { global $mainframe; // Старт $regex_one = '/({excel\s*)(.*?)(})/si'; $regex_all = '/{excel\s*.*?}/si'; $matches = array(); $count_matches = preg_match_all($regex_all,$article->text,$matches,PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER); // Start if count_matches if ($count_matches != 0) { $document = &JFactory::getDocument(); $db = &JFactory::getDBO(); $menu = &JSite::getMenu(); $plugin = &JPluginHelper::getPlugin('content', 'excel'); $paramsP = new JParameter( $plugin->params ); $component = 'com_excel'; $table =& JTable::getInstance('component'); $table->loadByOption( $component ); $paramsC = new JParameter( $table->params ); $tmpl = array(); for($i = 0; $i < $count_matches; $i++) { $this->_setExcelPluginNumber(); $mC = 'PlgPM'.(int)$this->_plgExcelNr; $view = ''; $file = ''; $text = ''; // Get plugin parameters $excel = $matches[0][$i][0]; preg_match($regex_one,$excel,$excel_parts); $parts = explode("|", $excel_parts[2]); $values_replace = array ("/^'/", "/'$/", "/^'/", "/'$/", "/<br \/>/"); foreach($parts as $key => $value) { $values = explode("=", $value, 2); foreach ($values_replace as $key2 => $values2) { $values = preg_replace($values2, '', $values); } // Get plugin parameters from article if($values[0]=='view') { $view = $values[1]; } else if($values[0]=='file') { $file = $values[1]; } else if($values[0]=='text') { $text = $values[1]; } } $output = ''; switch($view) { // - - - - - - - - - - - - - - - - // Map // - - - - - - - - - - - - - - - - case 'xls': $jxlspppath = JURI::base().'components/com_excel'; $header = ''; $header .= "<link href=\"$jxlspppath"."/styles/jxlstyle.css\" rel=\"stylesheet\" type=\"text/css\" />\n"; JHTML::_('behavior.mootools'); $header .= "<script type=\"text/javascript\" src=\"$jxlspppath/js/slimbox/js/slimbox.js\"></script>\n"; $header .= "<link rel=\"stylesheet\" href=\"$jxlspppath/js/slimbox/css/slimbox.css\" type=\"text/css\" media=\"screen\" />\n"; $mainframe->addCustomHeadTag($header); $excel_file = JPATH_SITE.DS.'components'.DS.'com_excel'.DS.'prices'.DS.$file; require(JPATH_SITE.DS.'components'.DS.'com_excel'.DS.'excel.excel.class.php'); $err_corr = JText::_('pex error_format'); if( $excel_file == '' ) $this->fatal(JText::_('pex not_load')); $excelfile = new ExcelFileParser("debug.log", ABC_NO_LOG );//ABC_VAR_DUMP); $res = $excelfile->ParseFromFile($excel_file); switch ($res) { case 0: break; case 1: $this->fatal(JText::_('pex error_notfound')); break; case 2: $this->fatal(JText::_('pex error_size')); break; case 3: $this->fatal(JText::_('pex error_head')); break; case 4: $this->fatal(JText::_('pex error_read')); break; case 5: $this->fatal(JText::_('pex error_file')); break; case 6: $this->fatal(JText::_('pex error_corrupt')); break; case 7: $this->fatal(JText::_('pex error_empty')); break; case 8: $this->fatal(JText::_('pex error_vers')); break; default: $this->fatal(JText::_('pex error_unknown')); break; } for( $ws_num=0; $ws_num<count($excelfile->worksheet['name']); $ws_num++ ) { //вывод заголовка листа $output .= '<table cellspacing="1" width="100%" cellpadding="5" class="table_excel" border="0"><tbody><tr bgcolor="#e8edf4"><td><b>'.JText::_('page').': '; if( $excelfile->worksheet['unicode'][$ws_num] ) { $output .= $this->uc2html($excelfile->worksheet['name'][$ws_num]); } else $output .= $excelfile->worksheet['name'][$ws_num]; $output .= "</b></td></tr></tbody></table>"; $ws = $excelfile->worksheet['data'][$ws_num]; if( is_array($ws) && isset($ws['max_row']) && isset($ws['max_col']) ) { $output .= '<table cellspacing="1" width="100%" cellpadding="5" class="table_excel" border="0"><tbody>'; /*$output .= "<tr><td> </td>"; for( $j=0; $j<=$ws['max_col']; $j++ ) { $output .= "<td class=index> "; if( $j>25 ) $output .= chr((int)($j/26)+64); $output .= chr(($j % 26) + 65)." </td>"; //$output .= "</td>"; }*/ for( $i=0; $i<=$ws['max_row']; $i++ ) { $output .= "<tr>"; // $output .= "<tr><td class=index><font color=ffffff>".($i+1)."</font></td>"; // <td class=index>".($i+1)."</td>"; if(isset($ws['cell'][$i]) && is_array($ws['cell'][$i]) ) { for( $j=0; $j<=$ws['max_col']; $j++ ) { if( ( is_array($ws['cell'][$i]) ) && ( isset($ws['cell'][$i][$j]) ) ) { // $output .= cell data $output .= "<td class=\""; $data = $ws['cell'][$i][$j]; // $font = $ws['cell'][$i][$j]['font']; // $style = " style ='".ExcelFont::ExcelToCSS($excelfile->fonts[$font])."'"; switch ($data['type']) { // string case 0: $output .= "dt_string\">"; $ind = $data['data']; if( $excelfile->sst['unicode'][$ind] ) { $s = $this->uc2html($excelfile->sst['data'][$ind]); } else $s = $excelfile->sst['data'][$ind]; if( strlen(trim($s))==0 ) $output .= " "; else //определение наличия ссылки на изображение if (eregi("[0-9a-z]+.jpg",$s,$out)) { $this->imgshow($out[0]); } else $output .= $s; break; // integer number case 1: $output .= "dt_int\"> "; $output .= $data['data']; break; // float number case 2: $output .= "dt_float\"> "; $output .= $data['data']; break; // date case 3: $output .= "dt_date\"> "; $ret = $data[data];//str_replace ( " 00:00:00", "", gmdate("d-m-Y H:i:s",$excelfile->xls2tstamp($data[data])) ); $output .= ( $ret ); break; default: $output .= "dt_unknown\"> "; break; } $output .= "</td>"; } else { $output .= '<td class="empty"> </td>'; } } } else { // $output .= an empty row for( $j=0; $j<=$ws['max_col']; $j++ ) $output .= '<td class="empty"> </td>'; } $output .= "</tr>"; } $output .= "</tbody></table><br />"; } else { // emtpty worksheet e8edf4 $output .= "<b> -". JText::_('pex empty') ."</b><br />"; } $output .= "<br /><div class=\"smallgrey\" align=\"right\"><a href=\"http://yar-it.com/\" target=\"_blank\" style=\"color:#CCC; font-size:9px;\">Joomla Excel</a></div>"; } break; } $article->text = preg_replace($regex_all, $output, $article->text, 1); } } return true; } } ?>