Esempio n. 1
0
 public static function get_random_quote($arr = array())
 {
     global $config_q, $table_prefix, $user;
     $s_where = $original_translations = $original_sources = "";
     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"] . " = " . "'" . $arr["url_friendly_source_name"] . "' ";
     }
     if ($config_q["locale"] != "et") {
         $original_translations = "\n\t\t\tauthor_firstname_et,\n\t\t\tauthor_midname_et,\n\t\t\tauthor_lastname_et,\n\t\t\tauthor_profession_et,\n\t\t\tauthor_name_freeform_et,\n\t\t\turl_friendly_author_name_et,\n\t\t\t";
     }
     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 id,\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.q_id as q_id,\n\t\t\t\tquote,\n\t\t\t\trank,\n\t\t\t\t" . $config_q["db"]["prefix"] . "quotes.source_title as source_title_original,\n\t\t\t\t" . $config_q["db"]["prefix"] . "sources.name_et as source_title,\n        " . $config_q["db"]["prefix"] . "sources.name_en as source_title_en,\n        " . $config_q["db"]["prefix"] . "sources.name_en as source_title_fr,\n        " . $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        " . $config_q["db"]["prefix"] . "sources.source_year_end_circa as source_year_end_circa,\n\t\t\t\tauthor_id,\n\t\t\t\tauthor_firstname_et,\n\t\t\t\tauthor_firstname_en,\n\t\t\t\tauthor_firstname_de,\n\t\t\t\tauthor_midname_et,\n\t\t\t\tauthor_midname_en,\n\t\t\t\tauthor_midname_de,\n\t\t\t\tauthor_lastname_et,\n\t\t\t\tauthor_lastname_en,\n\t\t\t\tauthor_lastname_de,\n\t\t\t\tauthor_profession_et,\n\t\t\t\tauthor_profession_en,\n\t\t\t\tauthor_profession_de,\n\t\t\t\tauthor_name_freeform_et,\n\t\t\t\tauthor_name_freeform_en,\n\t\t\t\tauthor_name_freeform_de,\n\t\t\t\turl_friendly_author_name_et,\n\t\t\t\turl_friendly_author_name_en,\n\t\t\t\turl_friendly_author_name_de,\n\t\t\t\tauthor_wiki_url_et,\n\t\t\t\tauthor_wiki_url_en,\n\t\t\t\tauthor_wiki_url_de,\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"] . "quotes.category as category_id,\n\t\t\t\t" . $config_q["db"]["prefix"] . "categories.name_" . $config_q["locale"] . " as category,\n\t\t\t\ttag,\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" . $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 = 0\n\t\t\tAND\n\t\t\t\t" . $config_q["db"]["prefix"] . "categories.id = " . $config_q["db"]["prefix"] . "quotes.category\n\t\t\tAND\n\t\t\t\turl_friendly_author_name_en is NULL\n\t\t\tORDER BY created_time\n\t\t\tLIMIT 0, 1;\n\t\t";
     // AND
     //a_tsitaatcom2_quote_authors.id = 167
     $r = q($q);
     $a_out = array();
     while ($row = mysqli_fetch_array($r, MYSQL_ASSOC)) {
         foreach ($row as $key => $var) {
             $row[$key] = str_replace('"', """, $var);
         }
         $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);
         $a_out[] = $row;
     }
     return $a_out;
 }