예제 #1
0
 protected function _export($start)
 {
     // do we have a valid filename
     $this->_filename = Sh404sefHelperFiles::createFileName($this->_filename, 'sh404sef_export_' . $this->_context);
     // put some data in the file
     $end = $start + self::MAX_PAGEIDS_PER_STEP + 1;
     $end = $end > $this->_total ? $this->_total : $end;
     // fetch shURLs record from model
     $model =& JModel::getInstance('urls', 'Sh404sefModel');
     $model->setContext('urls.default');
     $options = (object) array('layout' => 'export', 'getMetaData' => true);
     $records = $model->getList($options, $returnZeroElement = false, $start, $forcedLimit = self::MAX_PAGEIDS_PER_STEP);
     // do we need a header written to the file, for first record
     $header = $start == 0 ? Sh404sefHelperGeneral::getExportHeaders($this->_context) . "\n" : '';
     // format them for text file output
     $data = '';
     $counter = $start;
     $glue = Sh404sefHelperFiles::$stringDelimiter . Sh404sefHelperFiles::$fieldDelimiter . Sh404sefHelperFiles::$stringDelimiter;
     if (!empty($records)) {
         foreach ($records as $record) {
             $counter++;
             $textRecord = $record->oldurl . $glue . $record->newurl . $glue . $record->cpt . $glue . $record->rank . $glue . $record->dateadd . $glue . Sh404sefHelperFiles::csvQuote($record->metatitle) . $glue . Sh404sefHelperFiles::csvQuote($record->metadesc) . $glue . Sh404sefHelperFiles::csvQuote($record->metakey) . $glue . Sh404sefHelperFiles::csvQuote($record->metalang) . $glue . Sh404sefHelperFiles::csvQuote($record->metarobots) . Sh404sefHelperFiles::$stringDelimiter;
             $line = Sh404sefHelperFiles::$stringDelimiter . $counter . $glue . $textRecord;
             $data .= $line . "\n";
         }
     }
     // prepare data for storage
     if (!empty($header)) {
         // first record written to file, prepend header
         $data = $header . $data;
     }
     // store in file
     $status = Sh404sefHelperFiles::appendToFile($this->_filename, $data);
     // return any error
     return $status;
 }
 /**
  * Creates an export file line, based on db record
  *
  * @param $record the data coming from DB
  * @param $counter, running counter
  * @param $glue , glue string between elements of records
  */
 protected function _createLine($record, $counter, $glue)
 {
     $textRecord = $record->oldurl . $glue . $record->newurl . $glue . (empty($record->cpt) ? 0 : $record->cpt) . $glue . (empty($record->rank) ? 0 : $record->rank) . $glue . (!isset($record->dateadd) ? '0000-00-00' : $record->dateadd) . $glue . Sh404sefHelperFiles::csvQuote($record->metatitle) . $glue . Sh404sefHelperFiles::csvQuote($record->metadesc) . $glue . Sh404sefHelperFiles::csvQuote($record->metakey) . $glue . Sh404sefHelperFiles::csvQuote($record->metalang) . $glue . Sh404sefHelperFiles::csvQuote($record->metarobots) . Sh404sefHelperFiles::$stringDelimiter;
     $line = Sh404sefHelperFiles::$stringDelimiter . $counter . $glue . $textRecord . "\n";
     return $line;
 }