Exemplo n.º 1
0
 public function motopressTable($attrs, $content = null)
 {
     extract(shortcode_atts(self::addStyleAtts(array()), $attrs));
     global $motopressCESettings;
     require_once $motopressCESettings['plugin_root'] . '/' . $motopressCESettings['plugin_name'] . '/includes/getLanguageDict.php';
     $motopressCELang = motopressCEGetLanguageDict();
     if (!empty($classes)) {
         $classes = ' ' . $classes;
     }
     if (self::$isNeedFix && empty($mp_style_classes)) {
         if (!empty($style) && $style != 'none') {
             $mp_style_classes = 'motopress-table-style-' . $style;
         }
         if (!empty($custom_class)) {
             $mp_style_classes .= ' ' . $custom_class;
         }
     }
     if (!empty($mp_style_classes)) {
         $mp_style_classes = ' ' . $mp_style_classes;
     }
     $result = '<div class="motopress-table-obj' . self::getMarginClasses($margin) . $classes . '">';
     $content = trim($content);
     $content = preg_replace('/^<p>|<\\/p>$/', '', $content);
     $content = preg_replace('/<br[^>]*>\\s*\\r*\\n*/is', "\n", $content);
     if (!empty($content)) {
         //            $result .= '<table class="' . self::getBasicClasses(self::PREFIX . 'table', true) . $mp_style_classes   . '">';
         $result .= '<table class="' . self::getBasicClasses(self::PREFIX . 'table') . $mp_style_classes . '">';
         $i = 0;
         if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
             $rows = explode("\n", $content);
             $rowsCount = count($rows);
             foreach ($rows as $row) {
                 $row = str_getcsv($row);
                 $isLast = $i === $rowsCount - 1 ? true : false;
                 self::addRow($row, $i, $isLast, $result);
                 $i++;
             }
         } else {
             $tmpFile = new SplTempFileObject();
             $tmpFile->setFlags(SplFileObject::SKIP_EMPTY);
             $tmpFile->setFlags(SplFileObject::DROP_NEW_LINE);
             $write = $tmpFile->fwrite($content);
             if (!is_null($write)) {
                 $tmpFile->rewind();
                 while (!$tmpFile->eof()) {
                     $row = $tmpFile->fgetcsv();
                     $isLast = $tmpFile->eof();
                     self::addRow($row, $i, $isLast, $result);
                     $i++;
                 }
             }
         }
         $result .= '</table>';
     } else {
         $result .= $motopressCELang->CETableObjNoData;
     }
     $result .= '</div>';
     return $result;
 }