コード例 #1
0
 public function regenerateAll($external, $doDesc, $excluded = null)
 {
     if ($external) {
         if (!isset($this->addkeyParams)) {
             $plugin =& JPluginHelper::getPlugin('system', 'addkeywords');
             $params = new JParameter($plugin->params);
             $this->addkeyParams = plgSystemAddKeywords::allParams($params);
         }
     }
     $db =& JFactory::getDBO();
     $this->addkeyParams->doAllArchived ? $where = "" : ($where = "WHERE state >= 0");
     $query = "SELECT COUNT(id) FROM " . $db->nameQuote('#__content');
     $query .= $where;
     $db->setQuery($query);
     $numArticles = $db->loadResult();
     $limitArray = array();
     for ($i = 0; $numArticles >= 0; $numArticles -= 500, $i++) {
         if ($numArticles < 500) {
             $limitArray[$i] = "0,{$numArticles}";
         } else {
             $limitArray[$i] = $numArticles - 499 . ",{$numArticles}";
         }
     }
     foreach ($limitArray as $value) {
         $query = "SELECT * FROM " . $db->nameQuote('#__content') . " " . $where . " LIMIT " . $value . "";
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         foreach ($rows as $row) {
             // check if we should exclude this article
             if ($row->id == $excluded) {
                 $endNow = 1;
             } else {
                 $endNow = plgSystemAddKeywords::sectionCheck($row->sectionid, $row->catid);
             }
             if (!$endNow) {
                 $description = '';
                 $keywords = '';
                 if ($this->addkeyParams->useTitle) {
                     $getTextDesc = strip_tags($row->introtext . " " . $row->fulltext);
                     $getText = strip_tags($row->title . " " . $getTextDesc);
                 } else {
                     $getTextDesc = strip_tags($row->introtext . " " . $row->fulltext);
                     $getText = strip_tags($getTextDesc);
                 }
                 // create the keywords for the article
                 if ($external) {
                     if ($doDesc) {
                         $description = plgSystemAddKeywords::generateDescription($row->metadesc, $getTextDesc, true);
                     }
                 } else {
                     if ($this->addkeyParams->doDesc == 1) {
                         if ($this->addkeyParams->doEmptyDesc == 1) {
                             if ($row->metadesc == '') {
                                 $description = plgSystemAddKeywords::generateDescription($row->metadesc, $getTextDesc, true);
                             }
                         } else {
                             $description = plgSystemAddKeywords::generateDescription($row->metadesc, $getTextDesc, true);
                         }
                     }
                 }
                 if ($external) {
                     $keywords = plgSystemAddKeywords::generateKeywords($row->metakey, $getText, $row, true);
                 } else {
                     if ($this->addkeyParams->doKeys == 1) {
                         if ($this->addkeyParams->doEmptyKeys == 1) {
                             if ($row->metakey == '') {
                                 $keywords = plgSystemAddKeywords::generateKeywords($row->metakey, $getText, $row, true);
                             }
                         } else {
                             $keywords = plgSystemAddKeywords::generateKeywords($row->metakey, $getText, $row, true);
                         }
                     }
                 }
                 if ($external) {
                     if ($doDesc) {
                         $query = "UPDATE " . $db->nameQuote('#__content') . " SET " . $db->nameQuote('metakey') . " = " . $db->Quote($keywords) . ", " . $db->nameQuote('metadesc') . " = " . $db->Quote($description) . "";
                     } else {
                         $query = "UPDATE " . $db->nameQuote('#__content') . " SET " . $db->nameQuote('metakey') . " = " . $db->Quote($keywords) . "";
                     }
                 } else {
                     if ($description and $keywords) {
                         $query = "UPDATE " . $db->nameQuote('#__content') . " SET " . $db->nameQuote('metakey') . " = " . $db->Quote($keywords) . ", " . $db->nameQuote('metadesc') . " = " . $db->Quote($description) . "";
                     } elseif (!$description and $keywords) {
                         $query = "UPDATE " . $db->nameQuote('#__content') . " SET " . $db->nameQuote('metakey') . " = " . $db->Quote($keywords) . "";
                     } elseif ($description and !$keywords) {
                         $query = "UPDATE " . $db->nameQuote('#__content') . " SET " . $db->nameQuote('metadesc') . " = " . $db->Quote($description) . "";
                     }
                 }
                 if ($description or $keywords) {
                     $query .= "WHERE " . $db->nameQuote('id') . " = " . $db->Quote($row->id) . "";
                     $db->setQuery($query);
                     $db->query();
                 }
             }
         }
     }
     return true;
 }