Пример #1
0
 public function getArticle($publishstatus = NEWS_ANYUNPUBLISHED, $article_id = 0, $section_id = 0, $issue_id = 0, $orderby = "", $cover = false)
 {
     $dbData = array();
     if ($section_id == NEWS_ALLSECTIONS) {
         $section_id = 0;
     }
     // NEWS_ALLSECTIONS used in feed generation
     // ----------------------
     if ($publishstatus == NEWS_ANYUNPUBLISHED) {
         $wheres[] = "(A.issue_id='') || (A.issue_id='0') || (I.date_published='" . DATETIME_NULL . "') || (NOW()<I.date_published)";
     }
     if ($publishstatus == NEWS_TOBEPUBLISHED) {
         $wheres[] = "(A.articlestatus_id='1') && ((A.issue_id='') || (A.issue_id='0') || (I.date_published='" . DATETIME_NULL . "') || (NOW()<I.date_published))";
     }
     if ($publishstatus == NEWS_PUBLISHED) {
         $wheres[] = "(A.issue_id!='') && (A.issue_id!='0') && (I.date_published!='" . DATETIME_NULL . "') && (I.date_published<=NOW())";
     }
     if (!empty($article_id)) {
         $wheres[] = "A.article_id='" . addslashes(strip_tags($article_id)) . "'";
     }
     if (!empty($section_id)) {
         $wheres[] = "A.section_id='" . addslashes(strip_tags($section_id)) . "'";
     }
     if ($cover) {
         $wheres[] = "(A.cover_order!='0') && (A.section_id!='" . NEWS_FEATURE . "')";
     }
     if ($issue_id == NEWS_CURRENTISSUE) {
         $wheres[] = "A.issue_id='" . $this->getCurrentIssueId() . "'";
     } elseif (!empty($issue_id)) {
         $wheres[] = "A.issue_id='" . addslashes(strip_tags($issue_id)) . "'";
     }
     $where = isset($wheres) ? "WHERE (" . implode(") AND (", $wheres) . ")" : "";
     $order = !empty($orderby) ? " " . $orderby . "," : "";
     // ----------------------
     $sql = "SELECT " . "  A.article_id, " . "  A.title, " . "  A.text, " . "  A.date_lastchange, " . "  A.date_created, " . "  DATE_FORMAT(A.date,'%Y-%m-%d') AS 'date_written', " . "  DATE_FORMAT(A.date,'%e %M %Y') AS 'date', " . "  A.cover_image, " . "  A.issue_id, " . "  A.author_id, " . "  A.section_id, " . "  A.article_order, " . "  A.cover_order, " . "  A.cover_image, " . "  A.articlestatus_id, " . "  A.locked, " . "  F.user AS 'author_user', " . "  CONCAT(F.fname,' ',F.lname) AS 'author_name', " . "  F.email AS 'author_email', " . "  F.image AS 'author_image', " . "  F.authorstatus_id, " . "  F.adminstatus_id, " . "  I.year AS 'issue_year', " . "  I.number AS 'issue_number', " . "  I.date_published AS 'issue_date_published', " . "  I.last_preprint_year, " . "  I.last_preprint_number, " . "  CONCAT(I.last_preprint_year,'-',LPAD(I.last_preprint_number,3,'0')) AS 'issue_preprint_to', " . "  I.sent_no_subscribers AS 'issue_sent_no_subscribers', " . "  I.issuestatus_id " . "FROM " . "  " . $this->dbprefix . "article AS A " . "  LEFT JOIN " . $this->dbprefix . "author AS F " . "  ON A.author_id=F.author_id " . "  LEFT JOIN " . $this->dbprefix . "issue AS I " . "  ON A.issue_id=I.issue_id " . " " . $where . " " . "ORDER BY " . $order . "  A.section_id," . "  A.article_id" . "";
     $res = $this->query($sql, IS_TESTSERVER);
     // includes a call to connect
     if (!$res || $this->num_rows($res) == 0) {
         return array();
     }
     while ($data = $this->next_record_assoc($res)) {
         if (is_array($data) && !empty($data)) {
             // Assumes SQL selects unique articles:
             $dbData[$data["article_id"]] = functions::latin2utf($data);
         }
     }
     // ----------------------
     $dbSection = $dbCategory = $dbCountry = array();
     foreach ($dbData as $idx => $data) {
         // -------------
         $sql = "SELECT " . "  A.article_id, " . "  S.section_id, " . "  S.section " . "FROM " . "  " . $this->dbprefix . "article AS A " . "  LEFT JOIN " . $this->dbprefix . "section AS S " . "  ON A.section_id=S.section_id " . "WHERE " . "  A.article_id='" . $idx . "' " . "ORDER BY " . "  A.article_id" . "";
         $res = $this->query($sql, IS_TESTSERVER);
         // includes a call to connect
         if ($res !== false && $this->num_rows($res) > 0) {
             while ($data = $this->next_record_assoc($res)) {
                 if (is_array($data) && !empty($data) && !empty($data["section"])) {
                     $data = functions::latin2utf($data);
                     $dbData[$data["article_id"]]["section_id"] = $data["section_id"];
                     $dbData[$data["article_id"]]["section"] = $data["section"];
                 }
             }
         }
         // -------------
         $sql = "SELECT " . "  A.article_id, " . "  C.category_id, " . "  C.category " . "FROM " . "  " . $this->dbprefix . "article AS A " . "  LEFT JOIN " . $this->dbprefix . "article_category AS Y " . "  ON A.article_id=Y.article_id " . "  LEFT JOIN " . $this->dbprefix . "category AS C " . "  ON Y.category_id=C.category_id " . "WHERE " . "  A.article_id='" . $idx . "' " . "ORDER BY " . "  A.article_id" . "";
         $res = $this->query($sql, IS_TESTSERVER);
         // includes a call to connect
         if ($res !== false && $this->num_rows($res) > 0) {
             while ($data = $this->next_record_assoc($res)) {
                 if (is_array($data) && !empty($data) && !empty($data["category"])) {
                     $data = functions::latin2utf($data);
                     $dbCategory[$idx][] = $data;
                     $dbData[$idx]["category"][$data["category_id"]] = $data["category"];
                 }
             }
         }
         // -------------
         $sql = "SELECT " . "  A.article_id, " . "  L.country_id, " . "  L.country " . "FROM " . "  " . $this->dbprefix . "article AS A " . "  LEFT JOIN " . $this->dbprefix . "article_country AS Z " . "  ON A.article_id=Z.article_id " . "  LEFT JOIN " . $this->dbprefix . "country AS L " . "  ON Z.country_id=L.country_id " . "WHERE " . "  A.article_id='" . $idx . "' " . "ORDER BY " . "  A.article_id" . "";
         $res = $this->query($sql, IS_TESTSERVER);
         // includes a call to connect
         if ($res !== false && $this->num_rows($res) > 0) {
             while ($data = $this->next_record_assoc($res)) {
                 if (is_array($data) && !empty($data) && !empty($data["country"])) {
                     $data = functions::latin2utf($data);
                     $dbCountry[$idx][] = $data;
                     $dbData[$idx]["country"][$data["country_id"]] = $data["country"];
                 }
             }
         }
         // -------------
         $cmt = $this->getComment($idx);
         if (is_array($cmt) && !empty($cmt)) {
             $dbData[$idx]["comment"] = $cmt;
         }
     }
     // ----------------------
     // If specific db record requested, return only that single array
     if (!empty($article_id) && count($dbData)) {
         return array_shift($dbData);
     }
     return $dbData;
 }
Пример #2
0
 function next_record_assoc($resultset = FALSE)
 {
     if (!$resultset) {
         $resultset = $this->qresult;
     }
     if (!$resultset) {
         return false;
     }
     if (USE_MYSQLI) {
         // ---------------------------
         // MYSQLI version
         // ---------------------------
         if ($record = mysqli_fetch_assoc($resultset)) {
             //TODO: check if latin2utf8 conversion still needed
             //      $record = functions::latin2utf($record);
             //echo mysql_client_encoding($this->dblink);
             //debug::rr($record);
         } else {
             mysqli_free_result($resultset);
             unset($resultset);
         }
     } else {
         // ---------------------------
         // MYSQL version
         // ---------------------------
         if ($record = mysql_fetch_assoc($resultset)) {
             $record = functions::latin2utf($record);
         } else {
             mysql_free_result($resultset);
             unset($resultset);
         }
         // ---------------------------
     }
     return $record;
 }