예제 #1
0
파일: import.php 프로젝트: 01J/bealtine
 function _importAceSEF(&$lines)
 {
     $fieldsMap = array('cpt' => 'cpt', 'sefurl' => 'url_sef', 'origurl' => 'url_real', 'Itemid' => 'Itemid', 'metadesc' => 'metadesc', 'metakey' => 'metakey', 'metatitle' => 'metatitle', 'metalang' => 'metalang', 'metarobots' => 'metarobots', 'metagoogle' => 'metagoogle', 'canonicallink' => 'metacanonical', 'dateadd' => 'date', 'priority' => 'ordering');
     $result = true;
     for ($i = 0, $n = count($lines); $i < $n; $i++) {
         // Trim line
         $line = trim($lines[$i]);
         // Ignore empty lines
         if (strlen($line) == 0) {
             continue;
         }
         // If the query continues at the next line.
         while (substr($line, -1) != ';' && $i + 1 < count($lines)) {
             $i++;
             $newLine = trim($lines[$i]);
             if (strlen($newLine) == 0) {
                 continue;
             }
             $line .= ' ' . $lines[$i];
         }
         if (preg_match('/^INSERT\\s+INTO\\s+`?\\w+acesef_urls`?/i', $line) > 0) {
             // Parse the line
             $pos = strpos($line, '(');
             if ($pos !== false) {
                 $line = substr($line, $pos + 1);
             }
             $line = str_replace(');', '', $line);
             // Split the line to fields and values
             list($fields, $values) = explode(') VALUES (', $line);
             $fields = explode(',', $fields);
             $values = explode("', '", $values);
             $this->_cleanFields($fields);
             $this->_cleanFields($values);
             // Create the associative array of fields and values
             $assoc = array_combine($fields, $values);
             // Modify the assoc array to match our needs
             $assoc['cpt'] = 0;
             $assoc['Itemid'] = SEFTools::extractVariable($assoc['url_real'], 'Itemid');
             // Insert line to database
             if (!SEFModelImport::_insertLine($assoc, $fieldsMap)) {
                 $result = false;
             }
         } else {
             JError::raiseWarning(100, JText::_('COM_SEF_IGNORING_LINE') . ': ' . $line);
         }
     }
     return $result;
 }