Exemple #1
0
 public static function get_quotes($arr = array())
 {
     global $config_q, $table_prefix, $user;
     $s_where = $from = $original_translations = $original_sources = "";
     if (!isset($arr["order_by"])) {
         $order_by = " created_time desc ";
     } else {
         $order_by = $arr["order_by"];
     }
     if (isset($arr["tag"])) {
         $s_where = "\n\t\t\t\tAND\n\t\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.id = " . $config_q["db"]["prefix"] . "_tag_index_" . $config_q["locale"] . ".qid\n\t\t\t\tAND\n\t\t\t\t\t" . $config_q["db"]["prefix"] . "_tag_index_" . $config_q["locale"] . ".tag LIKE '" . addslashes($arr["tag"]) . "' ";
         $s_from = $config_q["db"]["prefix"] . "_tag_index_" . $config_q["locale"] . ",";
     }
     if (isset($arr["start"]) && isset($arr["length"])) {
         $limit = "LIMIT " . $arr["start"] . "," . $arr["length"];
     }
     if (isset($arr["current_page"])) {
         $limit = "LIMIT " . ($arr["current_page"] - 1) * $config_q["quotes_on_page"] . "," . $config_q["quotes_on_page"];
     }
     if (isset($arr["url_friendly_author_name"])) {
         $db_field_name_for_url_friendly_author_name = quote::get_db_field_name_for_url_friendly_author_name($arr["url_friendly_author_name"]);
         $s_where = " AND {$db_field_name_for_url_friendly_author_name} = \"" . $arr["url_friendly_author_name"] . "\" ";
     }
     if (isset($arr["users_favorite_quotes"])) {
         if (isset($arr["uid"])) {
             $r = q("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tquote_id\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . $config_q["db"]["prefix"] . "favorite_quotes\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tuser_id=" . $arr["uid"]);
             if (mysqli_num_rows($r) > 0) {
                 $s_where = " AND (";
                 while ($row = mysqli_fetch_array($r, MYSQL_ASSOC)) {
                     $s_where .= " " . $config_q["db"]["prefix"] . "quotes.id = " . $row["quote_id"] . " OR ";
                 }
                 $s_where = substr($s_where, 0, -3) . ")";
             } else {
                 return false;
             }
         }
     }
     if (isset($arr["users_added_quotes"])) {
         if (isset($arr["uid"])) {
             $s_where = "AND " . USERS_TABLE . ".user_id = '" . $arr["uid"] . "' ";
         }
     }
     if (isset($arr["q_id"])) {
         $s_where = " AND " . $config_q["db"]["prefix"] . "quotes.id = " . $arr["q_id"];
     }
     if (isset($arr["url_friendly_source_name"])) {
         $s_where = "AND " . $config_q["db"]["prefix"] . "sources.url_friendly_name_" . $config_q["locale"] . " = " . "\"" . urldecode($arr["url_friendly_source_name"]) . "\" ";
     }
     if ($config_q["locale"] == "et") {
         $author_wiki_url_et = "author_wiki_url_" . $config_q["locale"] . ", ";
     }
     if ($config_q["locale"] != "et") {
         $original_sources = $config_q["db"]["prefix"] . "sources.url_friendly_name_et as url_friendly_source_name_et,";
     }
     $q = "\n\t\t\tSELECT\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.id as quotes_id,\n\t\t\t\tquote,\n\t\t\t\trank,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.name_et as source_title_et,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.name_en as source_title_en,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.name_en as source_title_fr,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.name_en as source_title_hu,\n\t\t\t\t{$original_sources}\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.url_friendly_name_" . $config_q["locale"] . " as url_friendly_source_name_" . $config_q["locale"] . ",\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.source_year_start as source_year_start,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.source_year_start_circa as source_year_start_circa,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.source_year_end as source_year_end,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.source_year_end_circa as source_year_end_circa,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.amazon_product_link_" . $config_q["locale"] . " as amazon_product_link,\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.source_title_extra_prefix AS source_title_extra_prefix,\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.source_title_extra_sufix AS source_title_extra_sufix,\n\t\t\t\t{$original_translations}\n\t\t\t\tauthor_id,\n\t\t\t\tauthor_firstname_" . $config_q["locale"] . ",\n\t\t\t\tauthor_midname_" . $config_q["locale"] . ",\n\t\t\t\tauthor_lastname_" . $config_q["locale"] . ",\n\t\t\t\tauthor_profession_" . $config_q["locale"] . ",\n\t\t\t\tauthor_name_freeform_" . $config_q["locale"] . ",\n\t\t\t\t{$author_wiki_url_et}\n\t\t\t\tauthor_wiki_url_" . $config_q["locale"] . ",\n\t\t\t\turl_friendly_author_name_" . $config_q["locale"] . ",\n\t\t\t\tauthor_born,\n\t\t\t\tauthor_death,\n\t\t\t\tauthor_born_circa,\n\t\t\t\tauthor_death_circa,\n\t\t\t\tusername,\n\t\t\t\tcreated_by,\n\t\t\t\tcreated_time,\n\t\t\t\t" . $config_q["db"]["prefix"] . "categories.name_" . $config_q["locale"] . " as category,\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.tag as tag,\n\t\t\t\t" . $config_q["db"]["prefix"] . "favorite_quotes.quote_id as is_favorite\n\t\t\tFROM\n\t\t\t(\n\t\t\t\t{$s_from}\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes,\n\t\t\t\t" . $config_q["db"]["prefix"] . "quote_authors,\n\t\t\t\t" . USERS_TABLE . ",\n\t\t\t\t" . $config_q["db"]["prefix"] . "categories\n\t\t\t)\n\t\t\tLEFT JOIN\n\t\t\t\t" . $config_q["db"]["prefix"] . "favorite_quotes\n\t\t\tON \n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.id = " . $config_q["db"]["prefix"] . "favorite_quotes.quote_id\n\t\t\tAND\n\t\t\t\t" . $config_q["db"]["prefix"] . "favorite_quotes.user_id = " . $user->data["user_id"] . "\n\t\t\tLEFT JOIN\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources\n\t\t\tON\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.source_id = " . $config_q["db"]["prefix"] . "sources.id \n\t\t\tWHERE\n\t\t\t\t" . USERS_TABLE . ".user_id = " . $config_q["db"]["prefix"] . "quotes.created_by\n\t\t\tAND\n\t\t\t\t" . $config_q["db"]["prefix"] . "quote_authors.id = " . $config_q["db"]["prefix"] . "quotes.author_id\n\t\t\tAND\n\t\t\t\tlang = '" . $config_q["locale"] . "'\n\t\t\tAND\n\t\t\t\tactive = 1\n\t\t\tAND\n\t\t\t\t" . $config_q["db"]["prefix"] . "categories.id = " . $config_q["db"]["prefix"] . "quotes.category\n\t\t\t{$s_where}\n\t\t\tORDER BY\n\t\t\t\t{$order_by}\n\t\t\t{$limit};\n\t\t";
     $r = q($q);
     $a_out = array();
     while ($row = mysqli_fetch_array($r, MYSQL_ASSOC)) {
         $row = quote::parse_quote($row);
         $row = author::parse_author_image($row);
         $row = quote::parse_created_time($row);
         $row = author::parse_author_name($row);
         $row = author::parse_author_born_death($row);
         $row = author::parse_author_profession($row);
         $row = author::parse_url_friendly_author_name($row);
         $row = quote::parse_tags($row);
         $row = quote::parse_sources($row);
         //$row = $this->mk_urls($row);
         /*$row["source_year"] = $this->_source_year($row);
         		$row["author_nicename_for_title_and_h1"] = $this->get_author_name2($row);
         		$row["author_death_born"] = $this->get_author_death_born($row);
         		$row["author_profession"] = $this->get_author_profession($row);
         		$row["langs"] = $this->get_langs($row["q_id"]);
         		$row["tags"] = $this->get_tags($row);
         		//$row["source_year_start"] = $row["source_year_start"]<0 ? $row["source_year_start"]*(-1) : $row["source_year_start"];
         		$source_title_google = preg_replace("/^.*\"(.*)\".*$/imsU", "\"\\1\"", $row["source_title"]);
         		$source_title_google = str_replace("'", "", $source_title_google);
         		$row["source_title_google"] = str_replace(" ", "+", $source_title_google);
         		$row["source_title_user"] = preg_replace("/\"(.*)\"/imsU", "&#8220;\\1&#8221;", $row["source_title"]);
         		*/
         $a_out[] = $row;
     }
     $a_out = quote::get_quote_count($a_out, $q);
     // get quote count for certain query, maby should not
     // be here but maby faster though, and more
     // convenient
     $a_out = quote::parse_author_photos($a_out);
     return $a_out;
 }