示例#1
0
 /**
  * Imports a single article from Publisher
  */
 public function article()
 {
     global $xoopsSecurity, $xoopsDB;
     $this->prepare_ajax_response();
     $functions = MWFunctions::get();
     if (!$xoopsSecurity->check(true, false, 'CUTOKEN')) {
         $this->ajax_response(__('Session token not valid!', 'mywords'), 1, 0);
     }
     $id = RMHttpRequest::post('id', 'integer', 0);
     if ($id <= 0) {
         $this->ajax_response(sprintf(__('Article ID %u is not valid!', 'mywords'), $id), 0, 1, ['result' => 'error']);
     }
     $sql = "SELECT * FROM " . $xoopsDB->prefix("publisher_items") . " WHERE itemid = {$id}";
     $result = $xoopsDB->query($sql);
     if ($xoopsDB->getRowsNum($result)) {
         if ($id <= 0) {
             $this->ajax_response(sprintf(__('Article with ID %u was not found!', 'mywords'), $id), 0, 1, ['result' => 'error']);
         }
     }
     $row = $xoopsDB->fetchArray($result);
     $cache = $this->loadCache();
     $post = new MWPost();
     $post->setVar('title', $row['title']);
     $post->setVar('shortname', TextCleaner::getInstance()->sweetstring($row['title']));
     $post->setVar('content', $row['body']);
     switch ($row['status']) {
         case 1:
         case 4:
             $status = 'pending';
             break;
         case 2:
             $status = 'publish';
             break;
         case 3:
             $status = 'draft';
             break;
     }
     $post->setVar('status', $status);
     $post->setVar('visibility', 'public');
     $post->setVar('author', $row['uid']);
     $post->setVar('comstatus', 1);
     $post->setVar('pubdate', $row['datesub']);
     $post->setVar('created', $row['datesub']);
     $post->setVar('reads', $row['counter']);
     $post->setVar('description', $row['summary']);
     $post->setVar('keywords', $row['meta_keywords']);
     $post->setVar('format', 'post');
     if (isset($cache['categories'][$row['categoryid']])) {
         $post->add_categories($cache['categories'][$row['categoryid']]);
     }
     unset($row);
     if (!$post->save()) {
         $this->ajax_response(sprintf(__('Article %s could not be saved!', 'mywords'), $post->title), 0, 1, ['result' => 'error']);
     }
     $this->ajax_response(sprintf(__('Article %s imported successfully!', 'mywords'), '<strong>' . $post->title . '</strong>'), 0, 1, ['result' => 'success']);
 }