function fatal_handler()
{
    $errfile = "unknown file";
    $errstr = "shutdown";
    $errno = E_CORE_ERROR;
    $errline = 0;
    $error = error_get_last();
    if ($error !== NULL) {
        $errno = $error["type"];
        $errfile = $error["file"];
        $errline = $error["line"];
        $errstr = $error["message"];
        $html = format_error($errno, $errstr, $errfile, $errline);
        // Отправляем письмо, если есть соответствующий плагин
        if ($errno == 1) {
            $errors_to_email = load_plugin('errors_to_email');
            if (!empty($errors_to_email)) {
                $headers = "MIME-Version: 1.0\r\n";
                $headers .= "Content-Type: text/html\r\n";
                mail($errors_to_email, 'CPATracker error', $html, $headers);
            }
        }
        if (_ENABLE_DEBUG && isset($_GET['debug']) && $_GET['debug'] == 1) {
            echo $html;
        } else {
            if ($errno == 1) {
                echo '<div class="alert alert-error">Произошла ошибка. Обратитесь, пожалуйста, в техническую поддержку.</div>';
            }
        }
    }
}
Esempio n. 2
0
function fatal_handler()
{
    $errfile = "unknown file";
    $errstr = "shutdown";
    $errno = E_CORE_ERROR;
    $errline = 0;
    $error = error_get_last();
    if ($error !== NULL) {
        $errno = $error["type"];
        $errfile = $error["file"];
        $errline = $error["line"];
        $errstr = $error["message"];
        mail(EMAIL_ADMIN_EMAIL, "Fatal Error: " . NOTIFY_FROM_NAME, format_error($errno, $errstr, $errfile, $errline), "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n");
    }
}
Esempio n. 3
0
function fatal_handler()
{
    $errfile = "unknown file";
    $errstr = "shutdown";
    $errno = E_CORE_ERROR;
    $errline = 0;
    $error = error_get_last();
    if ($error !== NULL) {
        $errno = $error["type"];
        $errfile = $error["file"];
        $errline = $error["line"];
        $errstr = $error["message"];
        echo format_error($errno, $errstr, $errfile, $errline);
    }
}
function fatal_handler()
{
    $errfile = "unknown file";
    $errstr = "shutdown";
    $errno = E_CORE_ERROR;
    $errline = 0;
    $error = error_get_last();
    if ($error !== NULL) {
        $errno = $error["type"];
        $errfile = $error["file"];
        $errline = $error["line"];
        $errstr = $error["message"];
        #error_mail(format_error( $errno, $errstr, $errfile, $errline));
        $formattedError = format_error($errno, $errstr, $errfile, $errline);
        $myfile = fopen("debug.html", "a+") or die("Unable to open file!");
        fwrite($myfile, print_r($formattedError, true));
        fclose($myfile);
    }
}
Esempio n. 5
0
/**
 * faq_edit 
 * 
 * @param string $id unique identifier for te FAQ
 *
 * @access public
 * @return string
 */
function faq_edit($id)
{
    $data = array();
    $faq = Faq::fetch($id);
    if (!$faq) {
        throw new NotFoundException();
    }
    if (is_post()) {
        $faq->fromArray($_POST);
        if ($faq->isValid()) {
            $faq->save();
            return redirect('/faq/list');
        } else {
            $data['errors'] = array();
            $data['errors']['faq'] = format_error($faq);
        }
    }
    $data['faq'] = $faq;
    return render('faq_form.tpl', $data);
}
Esempio n. 6
0
 function changepassword()
 {
     $old_pw = $_POST["old_password"];
     $new_pw = $_POST["new_password"];
     $con_pw = $_POST["confirm_password"];
     if ($old_pw == "") {
         print "ERROR: " . format_error("Old password cannot be blank.");
         return;
     }
     if ($new_pw == "") {
         print "ERROR: " . format_error("New password cannot be blank.");
         return;
     }
     if ($new_pw != $con_pw) {
         print "ERROR: " . format_error("Entered passwords do not match.");
         return;
     }
     $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
     if (method_exists($authenticator, "change_password")) {
         print format_notice($authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw));
     } else {
         print "ERROR: " . format_error("Function not supported by authentication module.");
     }
 }
Esempio n. 7
0
function print_error($msg)
{
    return print format_error($msg);
}
Esempio n. 8
0
#
# Famesy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Famesy; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
require_once "../../functions.php";
include_once "../../header.php";
// Get member
$m = $_REQUEST['m'];
if (strlen($m) == 0) {
    include "../../header.php";
    echo format_error("Missing member ID");
    include "../../footer.php";
}
$member = get_member($m);
if (!$member) {
    die("Member not found");
}
// Create invoice
$invoice = create_invoice($member);
if (!$invoice) {
    die("Invoice not found");
}
?>
<html>
<head>
<title>Facturer</title>
function initial_sanity_check($link)
{
    $errors = array();
    if (!file_exists("config.php")) {
        array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it.");
    } else {
        require_once "sanity_config.php";
        if (strpos(PLUGINS, "auth_") === FALSE) {
            array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php");
        }
        if (function_exists('posix_getuid') && posix_getuid() == 0) {
            array_push($errors, "Please don't run this script as root.");
        }
        if (version_compare("5.3.0", phpversion()) == 1) {
            array_push($errors, "PHP version 5.3.0 or newer required.");
        }
        if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) {
            array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value.");
        }
        if (!is_writable(CACHE_DIR . "/images")) {
            array_push($errors, "Image cache is not writable (chmod -R 777 " . CACHE_DIR . "/images)");
        }
        if (!is_writable(CACHE_DIR . "/export")) {
            array_push($errors, "Data export cache is not writable (chmod -R 777 " . CACHE_DIR . "/export)");
        }
        if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) {
            array_push($errors, "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh");
        }
        foreach ($requred_defines as $d) {
            if (!defined($d)) {
                array_push($errors, "Required configuration file parameter {$d} is not defined in config.php. You might need to copy it from config.php-dist.");
            }
        }
        if (SESSION_EXPIRE_TIME < 60) {
            array_push($errors, "SESSION_EXPIRE_TIME set in config.php is too low, please set it to an integer value >= 60");
        }
        if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME) {
            array_push($errors, "SESSION_EXPIRE_TIME set in config.php should be >= to SESSION_COOKIE_LIFETIME");
        }
        if (SINGLE_USER_MODE) {
            $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
            if ($link) {
                $result = db_query($link, "SELECT id FROM ttrss_users WHERE id = 1");
                if (db_num_rows($result) != 1) {
                    array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found.");
                }
            }
        }
        if (SELF_URL_PATH == "http://yourserver/tt-rss/") {
            if ($_SERVER['HTTP_REFERER']) {
                array_push($errors, "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>" . $_SERVER['HTTP_REFERER'] . "</b>)");
            } else {
                array_push($errors, "Please set SELF_URL_PATH to the correct value for your server.");
            }
        }
        if (!is_writable(ICONS_DIR)) {
            array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 " . ICONS_DIR . ").\n");
        }
        if (!is_writable(LOCK_DIRECTORY)) {
            array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 " . LOCK_DIRECTORY . ").\n");
        }
        if (ini_get("open_basedir")) {
            array_push($errors, "PHP configuration option open_basedir is not supported. Please disable this in PHP settings file (php.ini).");
        }
        if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
            array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
        }
        if (!function_exists("json_encode")) {
            array_push($errors, "PHP support for JSON is required, but was not found.");
        }
        if (DB_TYPE == "mysql" && !function_exists("mysql_connect")) {
            array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php.");
        }
        if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) {
            array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php");
        }
        if (!function_exists("mb_strlen")) {
            array_push($errors, "PHP support for mbstring functions is required but was not found.");
        }
        if (!function_exists("hash")) {
            array_push($errors, "PHP support for hash() function is required but was not found.");
        }
        if (!function_exists("ctype_lower")) {
            array_push($errors, "PHP support for ctype functions are required by HTMLPurifier.");
        }
        if (ini_get("safe_mode")) {
            array_push($errors, "PHP safe mode setting is not supported.");
        }
        if ((PUBSUBHUBBUB_HUB || PUBSUBHUBBUB_ENABLED) && !function_exists("curl_init")) {
            array_push($errors, "PHP support for CURL is required for PubSubHubbub.");
        }
        if (!class_exists("DOMDocument")) {
            array_push($errors, "PHP support for DOMDocument is required, but was not found.");
        }
    }
    if (count($errors) > 0 && $_SERVER['REQUEST_URI']) {
        ?>
			<html>
			<head>
			<title>Startup failed</title>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
				<link rel="stylesheet" type="text/css" href="utility.css">
			</head>
		<body>
		<div class="floatingLogo"><img src="images/logo_wide.png"></div>

			<h1>Startup failed</h1>

			<p>Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade. Please fix
			errors indicated by the following messages:</p>

			<?php 
        foreach ($errors as $error) {
            echo format_error($error);
        }
        ?>

			<p>You might want to check tt-rss <a href="http://tt-rss.org/wiki">wiki</a> or the
				<a href="http://tt-rss.org/forum">forums</a> for more information. Please search the forums before creating new topic
				for your question.</p>
		</body>
		</html>

		<?php 
        die;
    } else {
        if (count($errors) > 0) {
            echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n";
            echo "Please fix errors indicated by the following messages:\n\n";
            foreach ($errors as $error) {
                echo " * {$error}\n";
            }
            echo "\nYou might want to check tt-rss wiki or the forums for more information.\n";
            echo "Please search the forums before creating new topic for your question.\n";
            exit(-1);
        }
    }
}
Esempio n. 10
0
 /**
  * 致命错误处理函数。
  * 该函数会接受所有类型的错误,应该只处理致命错误
  * @param type $errno
  * @param type $errstr
  * @param type $errfile
  * @param type $errline
  * @return type
  */
 function woniu_fatal_handler()
 {
     $system = WoniuLoader::$system;
     $errfile = "unknown file";
     $errstr = "shutdown";
     $errno = E_CORE_ERROR;
     $errline = 0;
     $error = error_get_last();
     $fatal_err = array(E_ERROR, E_USER_ERROR, E_COMPILE_ERROR, E_CORE_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
     if ($error !== NULL && isset($error["type"]) && in_array($error["type"], $fatal_err)) {
         $errno = $error["type"];
         $errfile = $error["file"];
         $errline = $error["line"];
         $errstr = $error["message"];
         if ($system['log_error']) {
             $handle = $system['log_error_handle']['error'];
             if (!empty($handle)) {
                 if (is_array($handle)) {
                     $class = key($handle);
                     $method = $handle[$class];
                     $rclass_obj = new ReflectionClass($class);
                     $rclass_obj = $rclass_obj->newInstanceArgs();
                     if (method_exists($rclass_obj, $method)) {
                         $rclass_obj->{$method}($errno, $errstr, $errfile, $errline, get_strace());
                     }
                 } else {
                     if (function_exists($handle)) {
                         $handle($errno, $errstr, $errfile, $errline, get_strace());
                     }
                 }
             }
         }
         if ($system['debug']) {
             //@ob_clean();
             trigger500('<pre>' . format_error($errno, $errstr, $errfile, $errline) . '</pre>');
         }
         exit;
     }
 }
Esempio n. 11
0
/**
 * get_errors 
 * 
 * @param mixed $record a Doctrine model 
 *
 * @access public
 * @return void
 */
function get_errors($record)
{
    $record->isValid();
    return format_error($record->getErrorStack()->toArray());
}
 function paragon_jw_search($search_string, $field_list)
 {
     $field_list = "ID," . $field_list;
     $pk = "ID";
     global $db;
     $primary_field_string = "name";
     $secondary_field_string = "description";
     $stem_length = 3;
     $first_word_stem_length = 4;
     $second_time_stem_length = 2;
     $score1 = 1;
     $score2 = 0.99;
     $score3 = 0.98;
     $score4 = 0.97;
     // set up initial variables
     $primary_fields = explode(",", $primary_field_string);
     $secondary_fields = explode(",", $secondary_field_string);
     $final_results_array = array();
     $final_category_results_array = array();
     $words = explode(" ", $search_string);
     if (!$search_string) {
         format_error("No search text was entered.", 1);
     }
     // The first search is for product categories. This will provide links to the categories themselves.
     // Subsequent searches are through the products table.
     $sql_fields = array();
     $sql = "SELECT id,category_name,html_page_name,\"{$score1}\" AS score FROM product_categories WHERE active=1 AND ";
     foreach ($words as $word) {
         array_push($sql_fields, "category_name LIKE \"{$word}%\"");
     }
     $sql .= implode(" OR ", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         $h['name'] = "Category: " . $h['category_name'];
         if (!array_key_exists($h[$pk], $final_category_results)) {
             $final_category_results[$h[$pk]] = $h;
         }
     }
     // Product search - exact matches without trailing chars in primary field get a score of $score1
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score1}\" AS score FROM products WHERE (child_product IS NULL OR child_product = 0 or child_product=\"\") AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"{$search_string}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     // Product search - exact phrase match in the primary field, anywhere in the field. Primary field may contain extra text for a score of $score2.
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score2}\" AS score FROM products WHERE (child_product IS NULL OR child_product = 0 or child_product=\"\") AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"%{$search_string}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     // Product search - exact phrase match in the secondary field - anywhere in field
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score3}\" AS score FROM products WHERE (child_product IS NULL OR child_product = 0 or child_product=\"\") AND ";
     foreach ($secondary_fields as $sfield) {
         array_push($sql_fields, "{$sfield} LIKE \"%{$search_string}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     // Product search - each word separately in primary field
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score4}\" AS score FROM products WHERE (child_product IS NULL OR child_product = 0 or child_product=\"\") AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"%{$search_string}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     if (!$final_results) {
         $response = "An exact match could not be found. The closest matches to {$search_string} are";
     } else {
         $response = "Search Results";
         $response = "";
     }
     // FIRST JARO WINKLER SERCH
     $final_results = $this->jaro_winkler($search_string, $first_word_stem_length, $stem_length, "AND", 0, $final_results, $field_list, $pk);
     if (count($final_results) == 0) {
         $final_results = $this->jaro_winkler($search_string, $second_time_stem_length, $second_time_stem_length, "AND", 0, $final_results, $field_list, $pk);
     }
     // NEXT JARO IF NO RESULTS
     if (count($final_results) == 0) {
         $final_result = $this->jaro_winkler($search_string, $first_word_stem_length, $stem_length, "OR", 10, $final_results, $field_list, $pk);
     }
     // find out what our highest score actually is, it may be low and hence throw back totally irrelevant results
     foreach ($final_results as $result => $resultdata) {
         $topscore = $resultdata['score'];
         break;
     }
     if ($topscore < 0.75) {
         $response = "Sorry - we could not find any match for {$search_string}, however the closest matches to your search phrase (searching through product descriptions) are listed below:";
     }
     $print_now = 0;
     if ($print_now) {
         print "<p>{$response}</p>";
         print "<table>";
         foreach ($final_results as $result => $resultdata) {
             print "<tr><td>{$result}</td><td>" . $resultdata['name'] . "</td><td>" . $resultdata['score'] . "</td></tr>";
         }
         print "</table><br>";
         if ($final_category_results) {
             print "Category Results:<br />The following product categories may be of interest:<br /><br />";
             print "<table>";
             foreach ($final_category_results as $result => $resultdata) {
                 print "<tr><td>{$result}</td><td>" . $resultdata['name'] . "</td><td>" . $resultdata['score'] . "</td></tr>";
             }
             print "</table><br>";
         }
     }
     $return['category_results'] = $final_category_results;
     $return['results'] = $final_results;
     $return['search_response_message'] = $response;
     return $return;
 }
Esempio n. 13
0
/**
 * page_edit 
 * 
 * @param string $slug the unique url slug for the page
 *
 * @access public
 * @return string
 */
function page_edit($slug)
{
    $data = array();
    $page = Pages::fetchBySlug($slug);
    if (!$page) {
        throw new NotFoundException();
    }
    if (is_post()) {
        $page->fromArray($_POST);
        if ($page->isValid()) {
            $page->save();
            return redirect('/page/list');
        } else {
            $data['errors'] = array();
            $data['errors']['page'] = format_error($page);
        }
    }
    $data['page'] = $page;
    return render('page_form.tpl', $data);
}
 protected function add_to_error_base($msg)
 {
     $this->global_page_error[] = format_error($msg);
 }
 function custom_search($dbf_search_for, $field_list)
 {
     $field_list = "ID," . $field_list;
     $pk = "ID";
     global $db;
     $primary_field_string = "artist";
     $secondary_field_string = "title";
     $stem_length = 3;
     $first_word_stem_length = 4;
     $second_time_stem_length = 2;
     $score1 = 1;
     $score2 = 0.99;
     $score3 = 0.98;
     $score4 = 0.97;
     // process initial vaariables
     $primary_fields = explode(",", $primary_field_string);
     $secondary_fields = explode(",", $secondary_field_string);
     $final_results_array = array();
     $final_category_results_array = array();
     $words = explode(" ", $dbf_search_for);
     if (!$dbf_search_for) {
         format_error("no search for so exit", 1);
     }
     // category search results - displayed separately by the framework
     $sql_fields = array();
     $sql = "SELECT id,artist,\"{$score1}\" AS score FROM artists WHERE active=1 AND ";
     foreach ($words as $word) {
         array_push($sql_fields, "artist LIKE \"{$word}%\"");
     }
     $sql .= implode(" OR ", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         $h['title'] = "Category: " . $h['artist'];
         if (!array_key_exists($h[$pk], $final_category_results)) {
             $final_category_results[$h[$pk]] = $h;
         }
     }
     // exact matches in primary field
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score1}\" AS score FROM products WHERE available IN (1,5) AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     //print "Exact phrase match - primary field - anywhere in field\n\n";
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score2}\" AS score FROM products WHERE available IN (1,5) AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"%{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     //print "Exact phrase match - secondary field - anywhere in field\n\n";
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score3}\" AS score FROM products WHERE available IN (1,5) AND ";
     foreach ($secondary_fields as $sfield) {
         array_push($sql_fields, "{$sfield} LIKE \"%{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     //print "Each word separately substr 4 \n\n";
     $sql_fields = array();
     $sql = "SELECT {$field_list},\"{$score4}\" AS score FROM products WHERE available IN (1,5) AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"%{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     if (!$final_results) {
         $response = "An exact match could not be found. The closest matches to {$dbf_search_for} are";
     } else {
         $response = "Search Results";
         $response = "";
     }
     // FIRST JARO WINKLER SERCH
     $final_results = $this->jaro_winkler($dbf_search_for, $first_word_stem_length, $stem_length, "AND", 0, $final_results, $field_list, $pk);
     if (count($final_results) == 0) {
         $final_results = $this->jaro_winkler($dbf_search_for, $second_time_stem_length, $second_time_stem_length, "AND", 0, $final_results, $field_list, $pk);
     }
     // FOURTH JARO IF NO RESULTS
     if (count($final_results) == 0) {
         $final_result = $this->jaro_winkler($dbf_search_for, $first_word_stem_length, $stem_length, "OR", 10, $final_results, $field_list, $pk);
     }
     // find out what our highest score actually is, it may be low nd hence throw back totally irrelevant results
     foreach ($final_results as $result => $resultdata) {
         $topscore = $resultdata['score'];
         break;
     }
     if ($topscore < 0.75) {
         $response = "Sorry - we could not find any match for {$dbf_search_for}, however the closest matches to your search phrase (searching through product descriptions) are listed below:";
     }
     $print_now = 0;
     if ($print_now) {
         print "<p>{$response}</p>";
         print "<table>";
         foreach ($final_results as $result => $resultdata) {
             print "<tr><td>{$result}</td><td>" . $resultdata['title'] . "</td><td>" . $resultdata['score'] . "</td></tr>";
         }
         print "</table><br>";
         if ($final_category_results) {
             print "Category Results:<br />The following product categories may be of interest:<br /><br />";
             print "<table>";
             foreach ($final_category_results as $result => $resultdata) {
                 print "<tr><td>{$result}</td><td>" . $resultdata['title'] . "</td><td>" . $resultdata['score'] . "</td></tr>";
             }
             print "</table><br>";
         }
     }
     $return['category_results'] = $final_category_results;
     $return['results'] = $final_results;
     $return['search_response_message'] = $response;
     return $return;
 }
Esempio n. 16
0
function member_query($sql)
{
    global $gdb;
    // singleton
    if ($_REQUEST["debug"] == 1) {
        echo "<div><pre>{$sql}</pre></div>";
    }
    if ($gdb == null) {
        $db_name = config('db_name');
        $gdb = mysql_connect(config('db_host'), config('db_user'), config('db_pass')) or die(format_error("Error connecting to db: " . mysql_error($gdb)));
        mysql_select_db($db_name, $gdb) or die(format_error("Error selecting '" . $db_name . "' db: " . mysql_error($gdb)));
    }
    $result = mysql_query($sql, $gdb) or die(format_error("Error executing query: " . mysql_error($gdb), $sql));
    return $result;
}
function initial_sanity_check()
{
    $errors = array();
    if (!file_exists("config.php")) {
        array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it.");
    } else {
        require_once "sanity_config.php";
        if (file_exists("install") && !file_exists("config.php")) {
            array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/");
        }
        if (strpos(PLUGINS, "auth_") === FALSE) {
            array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php");
        }
        if (function_exists('posix_getuid') && posix_getuid() == 0) {
            array_push($errors, "Please don't run this script as root.");
        }
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
            array_push($errors, "PHP version 5.3.0 or newer required.");
        }
        if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) {
            array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value.");
        }
        if (!is_writable(CACHE_DIR . "/images")) {
            array_push($errors, "Image cache is not writable (chmod -R 777 " . CACHE_DIR . "/images)");
        }
        if (!is_writable(CACHE_DIR . "/upload")) {
            array_push($errors, "Upload cache is not writable (chmod -R 777 " . CACHE_DIR . "/upload)");
        }
        if (!is_writable(CACHE_DIR . "/export")) {
            array_push($errors, "Data export cache is not writable (chmod -R 777 " . CACHE_DIR . "/export)");
        }
        if (!is_writable(CACHE_DIR . "/js")) {
            array_push($errors, "Javascript cache is not writable (chmod -R 777 " . CACHE_DIR . "/js)");
        }
        if (strlen(FEED_CRYPT_KEY) > 0 && strlen(FEED_CRYPT_KEY) != 24) {
            array_push($errors, "FEED_CRYPT_KEY should be exactly 24 characters in length.");
        }
        if (strlen(FEED_CRYPT_KEY) > 0 && !function_exists("mcrypt_decrypt")) {
            array_push($errors, "FEED_CRYPT_KEY requires mcrypt functions which are not found.");
        }
        if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) {
            array_push($errors, "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh");
        }
        foreach ($requred_defines as $d) {
            if (!defined($d)) {
                array_push($errors, "Required configuration file parameter {$d} is not defined in config.php. You might need to copy it from config.php-dist.");
            }
        }
        if (SINGLE_USER_MODE) {
            $result = db_query("SELECT id FROM ttrss_users WHERE id = 1");
            if (db_num_rows($result) != 1) {
                array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found.");
            }
        }
        if (SELF_URL_PATH == "http://example.org/tt-rss/") {
            $urlpath = preg_replace("/\\w+\\.php\$/", "", make_self_url_path());
            array_push($errors, "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>{$urlpath}</b>)");
        }
        if (!is_writable(ICONS_DIR)) {
            array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 " . ICONS_DIR . ").\n");
        }
        if (!is_writable(LOCK_DIRECTORY)) {
            array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 " . LOCK_DIRECTORY . ").\n");
        }
        if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
            array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
        }
        if (!function_exists("json_encode")) {
            array_push($errors, "PHP support for JSON is required, but was not found.");
        }
        if (DB_TYPE == "mysql" && !function_exists("mysql_connect") && !function_exists("mysqli_connect")) {
            array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php.");
        }
        if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) {
            array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php");
        }
        if (!function_exists("mb_strlen")) {
            array_push($errors, "PHP support for mbstring functions is required but was not found.");
        }
        if (!function_exists("hash")) {
            array_push($errors, "PHP support for hash() function is required but was not found.");
        }
        if (!function_exists("ctype_lower")) {
            array_push($errors, "PHP support for ctype functions are required by HTMLPurifier.");
        }
        if (!function_exists("iconv")) {
            array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
        }
        /* if (ini_get("safe_mode")) {
        				array_push($errors, "PHP safe mode setting is not supported.");
        			} */
        if ((PUBSUBHUBBUB_HUB || PUBSUBHUBBUB_ENABLED) && !function_exists("curl_init")) {
            array_push($errors, "PHP support for CURL is required for PubSubHubbub.");
        }
        if (SPHINX_ENABLED && class_exists("SphinxClient")) {
            array_push($errors, "Your PHP has a separate systemwide Sphinx client installed which conflicts with the client library used by tt-rss. Either remove the system library or disable Sphinx support.");
        }
        if (!class_exists("DOMDocument")) {
            array_push($errors, "PHP support for DOMDocument is required, but was not found.");
        }
    }
    if (count($errors) > 0 && $_SERVER['REQUEST_URI']) {
        ?>
			<html>
			<head>
			<title>Startup failed</title>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
				<link rel="stylesheet" type="text/css" href="css/utility.css">
			</head>
		<body>
		<div class="floatingLogo"><img src="images/logo_small.png"></div>
			<div class="content">

			<h1>Startup failed</h1>

			<p>Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade. Please fix
			errors indicated by the following messages:</p>

			<?php 
        foreach ($errors as $error) {
            echo format_error($error);
        }
        ?>

			<p>You might want to check tt-rss <a href="http://tt-rss.org/wiki">wiki</a> or the
				<a href="http://tt-rss.org/forum">forums</a> for more information. Please search the forums before creating new topic
				for your question.</p>

		</div>
		</body>
		</html>

		<?php 
        die;
    } else {
        if (count($errors) > 0) {
            echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n";
            echo "Please fix errors indicated by the following messages:\n\n";
            foreach ($errors as $error) {
                echo " * {$error}\n";
            }
            echo "\nYou might want to check tt-rss wiki or the forums for more information.\n";
            echo "Please search the forums before creating new topic for your question.\n";
            exit(-1);
        }
    }
}
 function custom_search($dbf_search_for, $field_list)
 {
     $field_list = "ID," . $field_list;
     $pk = "ID";
     global $db;
     $primary_field_string = "artists.artist";
     // This is our no.1 target field for searching in
     $secondary_field_string = "title, labels.label_name";
     // These are sub-target fields
     $tertiary_field_string = "full_description";
     // fields for a lower match score still
     $stem_length = 3;
     $first_word_stem_length = 4;
     $second_time_stem_length = 2;
     $score1 = 1;
     // a direct hit (perfect exact match) on our most revered fields
     $score2 = 0.99;
     // exact match on primary field but primary fields may contain other text as well
     $score3 = 0.98;
     // exact match but on secondary field list
     $score4 = 0.97;
     // searches for presence of all words in both primary and secondary fields
     $score5 = 0.96;
     // searches for an exact match in the tertiary field list
     // process initial vaariables
     $primary_fields = explode(",", $primary_field_string);
     $secondary_fields = explode(",", $secondary_field_string);
     $tertiary_fields = explode(",", $tertiary_field_string);
     $final_results_array = array();
     $final_category_results_array = array();
     $words = explode(" ", $dbf_search_for);
     $new_words = array();
     foreach ($words as $word) {
         if ($word != "and") {
             // lets not actually search for the word and, and focus on relevent words only
             array_push($new_words, $word);
         }
     }
     $words = $new_words;
     if (!$dbf_search_for) {
         format_error("no search for so exit", 1);
     }
     // category search
     $sql_fields = array();
     $sql = "SELECT ID,artist,\"{$score1}\" AS score FROM artists WHERE active =1 AND (";
     $countpercent = "";
     foreach ($words as $word) {
         array_push($sql_fields, "artist LIKE \"" . $countpercent . "{$word}%\"");
         $countpercent = "%";
     }
     $sql .= implode(" AND ", $sql_fields);
     $sql .= ")";
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         $h['title'] = "Category: " . $h['artist'];
         if (!array_key_exists($h[$pk], $final_category_results)) {
             $final_category_results[$h[$pk]] = $h;
         }
     }
     // If no exact category matches, check for the presence of ANY words in the category
     if (sizeof($final_category_results) == 0) {
         $sql_fields = array();
         $sql = "SELECT ID,artist,\"{$score1}\" AS score FROM artists WHERE active =1 AND (";
         foreach ($words as $word) {
             array_push($sql_fields, "artist LIKE \"" . $countpercent . "%{$word}%\"");
         }
         $sql .= implode(" OR ", $sql_fields);
         $sql .= ")";
         $res = $db->query($sql);
         while ($h = $db->fetch_array($res)) {
             //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
             $h['title'] = "Category: " . $h['artist'];
             if (!array_key_exists($h[$pk], $final_category_results)) {
                 $final_category_results[$h[$pk]] = $h;
             }
         }
     }
     //var_dump($final_category_results);
     // GONAO - MODIFY FIELD LIST
     $modified_field_list = "products.ID AS ID,products.artist,title,format,catalogue_number,price,full_description,products.image,label,release_date,allow_pre_orders,available";
     $modified_tables = "products INNER JOIN artists ON products.artist = artists.ID INNER JOIN labels ON products.label=labels.id";
     // exact matches in primary field
     $sql_fields = array();
     $sql = "SELECT {$modified_field_list},\"{$score1}\" AS score FROM {$modified_tables} WHERE (available = 1 OR (products.release_date >= NOW() AND allow_pre_orders=1)) AND hidden != 1 AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $sql .= "ORDER BY artists.artist,title";
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     //print "Exact phrase match - primary field - anywhere in field\n\n";
     $sql_fields = array();
     $sql = "SELECT {$modified_field_list},\"{$score2}\" AS score FROM {$modified_tables} WHERE (available = 1 OR (products.release_date >= NOW() AND allow_pre_orders=1)) AND hidden != 1 AND ";
     foreach ($primary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"%{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $sql .= "ORDER BY artists.artist,title";
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     //print "Exact phrase match - secondary field - anywhere in field\n\n";
     $sql_fields = array();
     $sql = "SELECT {$modified_field_list},\"{$score3}\" AS score FROM {$modified_tables} WHERE (available = 1 OR (products.release_date >= NOW() AND allow_pre_orders=1)) AND hidden != 1 AND ";
     foreach ($secondary_fields as $sfield) {
         array_push($sql_fields, "{$sfield} LIKE \"%{$dbf_search_for}%\"");
     }
     $sql .= implode(" OR ", $sql_fields);
     $sql .= "ORDER BY artists.artist,title";
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     //print "Each word separately substr 4 \n\n";
     $sql_fields = array();
     $sub_sql_fields = array();
     $sql = "SELECT {$modified_field_list},\"{$score4}\" AS score FROM {$modified_tables} WHERE (available = 1 OR (products.release_date >= NOW() AND allow_pre_orders=1)) AND hidden != 1 AND (";
     foreach ($primary_fields as $pfield) {
         foreach ($words as $word) {
             array_push($sub_sql_fields, "{$pfield} LIKE \"%{$word}%\"");
         }
         array_push($sql_fields, join(" AND ", $sub_sql_fields));
         $sub_sql_fields = array();
     }
     foreach ($secondary_fields as $pfield) {
         foreach ($words as $word) {
             array_push($sub_sql_fields, "{$pfield} LIKE \"%{$word}%\"");
         }
         array_push($sql_fields, join(" AND ", $sub_sql_fields));
         $sub_sql_fields = array();
     }
     if ($sql_fields) {
         $sql .= "(";
         $sql .= implode(") OR (", $sql_fields);
         $sql .= ")";
     }
     $sql .= ") ORDER BY artists.artist,title";
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     // description exact
     $sql_fields = array();
     $sql = "SELECT {$modified_field_list},\"{$score5}\" AS score FROM {$modified_tables} WHERE (available = 1 OR (products.release_date >= NOW() AND allow_pre_orders=1)) AND hidden != 1 AND ";
     foreach ($tertiary_fields as $pfield) {
         array_push($sql_fields, "{$pfield} LIKE \"%{$dbf_search_for}%\"");
     }
     $sql .= implode(",", $sql_fields);
     $sql .= "ORDER BY artists.artist,title";
     $res = $db->query($sql);
     while ($h = $db->fetch_array($res)) {
         //print $h[$pk] . " - " . $h['name'] . " - " . $h['score'] ."\n";
         if (!array_key_exists($h[$pk], $final_results)) {
             $final_results[$h[$pk]] = $h;
         }
     }
     if (!$final_results) {
         $response = "An exact match could not be found. The closest matches to {$dbf_search_for} are";
     } else {
         $response = "Search Results";
         $response = "";
     }
     // FIRST JARO WINKLER SERCH
     // find out what our highest score actually is, it may be low nd hence throw back totally irrelevant results
     foreach ($final_results as $result => $resultdata) {
         $topscore = $resultdata['score'];
         break;
     }
     if ($topscore < 0.97) {
         $response = "Sorry - we could not find any match for {$dbf_search_for}, however the closest matches to your search phrase (searching through product descriptions) are listed below:";
     }
     $print_now = 0;
     if ($print_now) {
         print "<p>{$response}</p>";
         print "<table>";
         foreach ($final_results as $result => $resultdata) {
             print "<tr><td>{$result}</td><td>" . $resultdata['title'] . "</td><td>" . $resultdata['score'] . "</td></tr>";
         }
         print "</table><br>";
         if ($final_category_results) {
             print "Category Results:<br />The following product categories may be of interest:<br /><br />";
             print "<table>";
             foreach ($final_category_results as $result => $resultdata) {
                 print "<tr><td>{$result}</td><td>" . $resultdata['title'] . "</td><td>" . $resultdata['score'] . "</td></tr>";
             }
             print "</table><br>";
         }
     }
     $return['category_results'] = $final_category_results;
     $return['results'] = $final_results;
     $return['search_response_message'] = $response;
     return $return;
 }
Esempio n. 19
0
function glitre_format_error($err, $format)
{
    global $config;
    //	if (list($mode, $type) = explode('.', $format)) {
    // TODO
    // $file = $config['base_path'] . 'plugin/' . $type . '.php';
    $file = $config['base_path'] . 'formats/' . $format . '.php';
    if (is_file($file)) {
        include $file;
        return format_error($err);
    } else {
        // TODO: Log false use of format
        return "{$file} not found!";
    }
    //	}
}