Ejemplo n.º 1
0
 /**
  * Add keyword
  */
 function editTags()
 {
     JRequest::checkToken() or die('Invalid Token');
     //$user =& JFactory::getUser();
     //$model =& $this->getModel('akseo');
     $id = JRequest::getInt('artid');
     $newTag = JRequest::getWord('newTag');
     $tagArray = JRequest::getVar('tags', '', 'post', 'array');
     $tagEdit = JRequest::getInt('tagEdit');
     $row =& JTable::getInstance('content');
     $row->load($id);
     //if tags selected, remove from keywords
     if (isset($tagArray) and !empty($tagArray)) {
         $keywordArray = explode(",", $row->metakey);
         $newKeys = array_diff($keywordArray, $tagArray);
         $row->metakey = implode(",", $newKeys);
     }
     if (isset($newTag)) {
         $row->metakey = $row->metakey . ', ' . $newTag;
     }
     if (isset($newTag) or isset($newKeys)) {
         if (!$row->save($row)) {
             return JError::raiseWarning(500, $row->getError());
         }
     }
     //$article = $model->getOptions($user->id);
     return plgSystemAddKeywords::tagList($row, $addkeyParams = null, $tagEdit, $ajax = 1);
 }
Ejemplo n.º 2
0
 private function generateDescription($oldDesc, $text, $processGlobals)
 {
     // Description to preserve
     if ($this->addkeyParams->preserveDesc == 1) {
         //$oldEncoding = plgSystemAddKeywords::fixEncoding($oldDesc);
         $oldDesc = html_entity_decode($oldDesc, ENT_QUOTES, "UTF-8");
         plgSystemAddKeywords::cleanWhitespace($oldDesc);
         if (preg_match('#{([^}][\\s\\S]*)}#u', $oldDesc, $matches)) {
             $savedDesc = $matches[1];
             if (JString::strpos($savedDesc, "[start]")) {
                 $position = "start";
                 $savedDesc = JString::str_ireplace("[start]", "", $savedDesc);
             } else {
                 $position = "end";
             }
         }
     }
     //$encoding = plgSystemAddKeywords::fixEncoding($text);
     $text = html_entity_decode($text, ENT_QUOTES, "UTF-8");
     // Start cleaning up the article text
     //$text = strip_tags($text);
     // Cleans up plugin calls
     $text = preg_replace('#{[^}]*?}(?(?=[^{]*?{\\/[^}]*?})[^{]*?{\\/[^}]*?})#u', '', $text);
     // Get rid of all forms of whitespace except single spaces
     //plgSystemAddKeywords::cleanWhitespace($text);
     $text = preg_replace('#[\\s]{2,}#u', ' ', $text);
     // Use sentence, word or char count to make description
     // Char count is now the fallback method
     if ($this->addkeyParams->descPrimary == 'sentence') {
         // Setup pattern to find sentences and create description depending on defined number of sentences
         $description = "";
         $pattern = '#\\b(.+?[\\.|\\!|\\?])#u';
         for ($i = 0; $i < $this->addkeyParams->descSentCount; $i++) {
             $offset = "";
             if (preg_match($pattern, $text, $matches)) {
                 $match = $matches[1];
             } else {
                 break;
             }
             $description .= " " . $match;
             $offset = JString::strpos($text, $match);
             $offset += strlen($match);
             $text = JString::substr($text, $offset);
         }
     }
     if ($this->addkeyParams->descPrimary == 'word') {
         $explode = explode(' ', JString::trim($text));
         $string = '';
         for ($i = 0; $i < $this->addkeyParams->descWordCount; $i++) {
             if (isset($explode[$i])) {
                 $string .= $explode[$i] . " ";
             } else {
                 break;
             }
         }
         $description = JString::trim($string);
     }
     // If description is null, fallback to char count
     if ($this->addkeyParams->descPrimary == 'char' or $description == '') {
         $description = JString::substr(JString::trim($text), 0, $this->addkeyParams->descCharCount);
     }
     // Add in the preserved description
     if (isset($savedDesc)) {
         if ($position == "start") {
             $description = JString::trim($savedDesc) . " " . JString::trim($description);
         } elseif ($position == "end") {
             $description = JString::trim($description) . " " . JString::trim($savedDesc);
         }
     }
     if ($this->addkeyParams->dotdotdot) {
         if (!JString::strpos($description, '...')) {
             $description .= '...';
         }
     }
     if ($processGlobals) {
         $this->akProcessDesc = 1;
     }
     return JString::trim($description);
 }