Esempio n. 1
0
File: values.php Progetto: rair/yacs
 /**
  * retrieve one record by name
  *
  * You can access $result['value'] and $result['edit_date'] after one single
  * fetch.
  *
  * @param string the id of the value to be retrieved
  * @param string an optional default value
  * @return string cached information, or NULL if the no accurate information is available for this id
  */
 public static function get_record($id, $default_value = NULL)
 {
     global $context;
     // sanity check
     if (!$id) {
         $output = NULL;
         return $output;
     }
     // select among available items -- exact match
     $query = "SELECT * FROM " . SQL::table_name('values') . " WHERE id LIKE '" . SQL::escape($id) . "'";
     // do not report on error
     if (!($item = SQL::query_first($query, TRUE))) {
         return $item;
     }
     // default value
     if (!isset($item['value']) || !$item['value']) {
         $item['value'] = $default_value;
     }
     // we have a valid item
     return $item;
 }
Esempio n. 2
0
 /**
  * get enrolment record
  *
  * @param string to designate the target anchor
  * @param int target user, or NULL for current surfer
  * @return array enrolment attributes, or NULL
  */
 public static function get_record($reference, $id = NULL)
 {
     global $context;
     // which surfer?
     if (!$id) {
         $id = Surfer::get_id();
     }
     // look for surfer id, if any
     if ($id) {
         $where = "user_id LIKE '" . SQL::escape($id) . "'";
     } elseif (isset($_REQUEST['surfer_address']) && $_REQUEST['surfer_address']) {
         $where = "user_email LIKE '" . SQL::escape($_REQUEST['surfer_address']) . "'";
     } elseif ($email = Surfer::get_email_address()) {
         $where = "user_email LIKE '" . SQL::escape($email) . "'";
     } else {
         return NULL;
     }
     // get at least one record
     $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE (anchor LIKE '" . $reference . "') AND " . $where;
     return SQL::query_first($query);
 }
Esempio n. 3
0
 /**
  * get some statistics for some sections
  *
  * Only sections matching following criteria are returned:
  * - section is visible (active='Y')
  * - section is restricted (active='R'), but surfer is a logged user
  * - section is hidden (active='N'), but surfer is an associate
  *
  * Non-activated and expired sections are counted as well.
  *
  * @param string the selected anchor (e.g., 'section:12')
  * @return array the resulting ($count, $min_date, $max_date) array
  *
  * @see sections/delete.php
  * @see sections/index.php
  * @see sections/layout_sections.php
  * @see sections/layout_sections_as_yahoo.php
  * @see sections/view.php
  */
 public static function stat_for_anchor($anchor = '')
 {
     global $context;
     // limit the query to one level
     if ($anchor) {
         $where = "(sections.anchor LIKE '" . SQL::escape($anchor) . "')";
     } else {
         $where = "(sections.anchor='' OR sections.anchor is NULL)";
     }
     // show everything if we are about to suppress a section
     if (!preg_match('/delete\\.php/', $context['script_url'])) {
         // display active and restricted items
         $where .= "AND (sections.active='Y'";
         // list restricted sections to authenticated surfers
         if (Surfer::is_logged()) {
             $where .= " OR sections.active='R'";
         }
         // list hidden sections to associates, editors and readers
         if (Surfer::is_empowered('S')) {
             $where .= " OR sections.active='N'";
         }
         $where .= ")";
         // hide sections removed from index maps
         $where .= " AND (sections.index_map = 'Y')";
         // non-associates will have only live sections
         if ($anchor && !Surfer::is_empowered()) {
             $where .= " AND ((sections.activation_date is NULL)" . "\tOR (sections.activation_date <= '" . $context['now'] . "'))" . " AND ((sections.expiry_date is NULL)" . "\tOR (sections.expiry_date <= '" . NULL_DATE . "') OR (sections.expiry_date > '" . $context['now'] . "'))";
         }
     }
     // list sections
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('sections') . " AS sections" . " WHERE " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 4
0
 /**
  * pull most recent notification
  *
  * This script will wait for new updates before providing them to caller.
  * Because of potential time-outs, you have to care of retries.
  *
  * @return array attributes of the oldest notification, if any
  *
  * @see users/heartbit.php
  */
 public static function pull()
 {
     global $context;
     // return by reference
     $output = NULL;
     // only authenticated surfers can be notified
     if (!Surfer::get_id()) {
         Safe::header('Status: 401 Unauthorized', TRUE, 401);
         die(i18n::s('You are not allowed to perform this operation.'));
     }
     // only consider recent records -- 180 = 3 minutes * 60 seconds
     $threshold = gmstrftime('%Y-%m-%d %H:%M:%S', time() - 180);
     // the query to get time of last update
     $query = "SELECT * FROM " . SQL::table_name('notifications') . " AS notifications " . " WHERE (notifications.recipient = " . SQL::escape(Surfer::get_id()) . ")" . "\tAND (edit_date >= '" . SQL::escape($threshold) . "')" . " ORDER BY notifications.edit_date" . " LIMIT 1";
     // stop if there is nothing to return
     if (!($record = SQL::query_first($query)) || !isset($record['data'])) {
         return 'NTR';
     }
     // restore the entire record
     $output = Safe::unserialize($record['data']);
     // localize on server-side message displayed by the client software
     $lines = array();
     switch ($output['type']) {
         case 'alert':
             // a new item has been created
             if (strpos($output['action'], ':create')) {
                 $lines[] = sprintf(i18n::s('New page: %s'), $output['title']) . "\n" . sprintf(i18n::s('%s by %s'), ucfirst(Anchors::get_action_label($output['action'])), $output['nick_name']) . "\n";
                 // surfer prompt
                 $lines[] = i18n::s('Would you like to browse the page?');
                 // else consider this as an update
             } else {
                 // provide a localized message
                 $lines[] = sprintf(i18n::s('Updated: %s'), $output['title']) . "\n" . sprintf(i18n::s('%s by %s'), ucfirst(Anchors::get_action_label($output['action'])), $output['nick_name']) . "\n";
                 // surfer prompt
                 $lines[] = i18n::s('Would you like to browse the page?');
             }
             break;
         case 'browse':
             // message is optional
             if (isset($output['message']) && trim($output['message'])) {
                 $lines[] = sprintf(i18n::s('From %s:'), $output['nick_name']) . "\n" . $output['message'] . "\n";
             }
             // address is mandatory
             $lines[] = i18n::s('Would you like to browse the page?');
             break;
         case 'hello':
             // message is optional
             if (isset($output['message']) && trim($output['message'])) {
                 $lines[] = sprintf(i18n::s('From %s:'), $output['nick_name']) . "\n" . $output['message'] . "\n";
             }
             // address is present on new chat
             if (isset($output['address']) && trim($output['address'])) {
                 $lines[] = i18n::s('Would you like to browse the page?');
             }
             break;
     }
     // content of the dialog box that will be displayed to surfer
     if (count($lines)) {
         $output['dialog_text'] = implode("\n", $lines);
     }
     // forget this notification
     $query = "DELETE FROM " . SQL::table_name('notifications') . " WHERE id = " . SQL::escape($record['id']);
     SQL::query($query, TRUE);
     // return the new notification
     return $output;
 }
Esempio n. 5
0
 /**
  * get some statistics for one anchor
  *
  * @param the selected anchor (e.g., 'section:12')
  * @return the resulting ($count, $min_date, $max_date) array
  */
 public static function stat_for_anchor($anchor)
 {
     global $context;
     // sanity check
     if (!$anchor) {
         return NULL;
     }
     $anchor = SQL::escape($anchor);
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('versions') . " AS versions" . " WHERE (versions.anchor LIKE '" . SQL::escape($anchor) . "')";
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 6
0
File: files.php Progetto: rair/yacs
 /**
  * get some statistics for one anchor
  *
  * @param the selected anchor (e.g., 'article:12')
  * @return the resulting ($count, $oldest_date, $newest_date, $total_size) array
  */
 public static function stat_for_anchor($anchor)
 {
     global $context;
     // sanity check
     if (!$anchor) {
         return NULL;
     }
     // limit the scope of the request
     $where = Files::get_sql_where();
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . ", SUM(file_size) as total_size" . " FROM " . SQL::table_name('files') . " AS files" . " WHERE files.anchor LIKE '" . SQL::escape($anchor) . "' AND " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 7
0
File: users.php Progetto: rair/yacs
 /**
  * count present users
  *
  * Only users matching following criteria are returned:
  * - user is visible (active='Y')
  * - user is restricted (active='R'), but surfer is a logged member
  * - user is restricted (active='N'), but surfer is an associate
  * - user has clicked during the last 15 minutes
  *
  * @return the resulting ($count, $min_date, $max_date) array
  *
  * @see users/index.php
  */
 public static function stat_present()
 {
     global $context;
     // limit the scope of the request
     $where = "users.active='Y'";
     if (Surfer::is_member()) {
         $where .= " OR users.active='R'";
     }
     if (Surfer::is_associate()) {
         $where .= " OR users.active='N'";
     }
     // present means 'a click not too long in the past'
     $threshold = gmstrftime('%Y-%m-%d %H:%M:%S', time() - 15 * 60);
     $where = "(" . $where . ") AND (click_date > '" . $threshold . "')";
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(users.edit_date) as oldest_date, MAX(users.edit_date) as newest_date" . " FROM " . SQL::table_name('users') . " AS users" . " WHERE " . $where;
     $output = SQL::query_first($query, FALSE, $context['users_connection']);
     return $output;
 }
Esempio n. 8
0
File: search.php Progetto: rair/yacs
$section_id = '';
if (isset($_REQUEST['anchor']) && strpos($_REQUEST['anchor'], 'section:') === 0) {
    $section_id = str_replace('section:', '', $_REQUEST['anchor']);
}
$section_id = strip_tags($section_id);
// offset, to navigate in result set
$offset = 1.0;
if (isset($_REQUEST['offset'])) {
    $offset = (double) $_REQUEST['offset'];
}
if ($offset > 1.0 || $offset < 0.0) {
    $offset = 1.0;
}
// minimum size for any search token - depends of mySQL setup
$query = "SHOW VARIABLES LIKE 'ft_min_word_len'";
if (!defined('MINIMUM_TOKEN_SIZE') && ($row = SQL::query_first($query)) && $row['Value'] > 0) {
    define('MINIMUM_TOKEN_SIZE', $row['Value']);
}
// by default MySQL indexes words with at least four chars
if (!defined('MINIMUM_TOKEN_SIZE')) {
    define('MINIMUM_TOKEN_SIZE', 4);
}
// kill short and redundant tokens; adapt to boolean search
$boolean_search = '';
$tokens = preg_split('/[\\s,]+/', $search);
if (@count($tokens)) {
    foreach ($tokens as $token) {
        // too short
        if (strlen(preg_replace('/&.+?;/', 'x', $token)) < MINIMUM_TOKEN_SIZE) {
            continue;
        }
Esempio n. 9
0
File: dates.php Progetto: rair/yacs
 /**
  * get some statistics for one anchor
  *
  * @param the selected anchor (e.g., 'article:12')
  * @return the resulting ($count, $min_date, $max_date) array
  */
 public static function stat_past_for_anchor($anchor)
 {
     global $context;
     // restrict the query to addressable content
     $where = Articles::get_sql_where();
     // put only published pages in boxes
     if (isset($variant) && $variant == 'boxes') {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // provide published pages to anonymous surfers
     } elseif (!Surfer::is_logged()) {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // logged surfers that are non-associates are restricted to their own articles, plus published articles
     } elseif (!Surfer::is_empowered()) {
         $where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
     }
     // now
     $match = gmstrftime('%Y-%m-%d %H:%M:%S');
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(articles.edit_date) as oldest_date, MAX(articles.edit_date) as newest_date " . " FROM " . SQL::table_name('dates') . " as dates " . ", " . SQL::table_name('articles') . " AS articles" . " WHERE ((dates.anchor_type LIKE 'article') AND (dates.anchor_id = articles.id))" . "\tAND (dates.date_stamp < '" . SQL::escape($match) . "') AND\t(articles.anchor = '" . SQL::escape($anchor) . "') AND " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 10
0
File: phpdoc.php Progetto: rair/yacs
 /**
  * get one documentation snippet
  *
  * @param string the name of the snippet to fetch
  * @return the resulting $row array, with at least keys: 'name', 'anchor' and 'content'
  */
 public static function get($name)
 {
     global $context;
     // select among available items
     $query = "SELECT * FROM " . SQL::table_name('phpdoc') . " AS phpdoc " . " WHERE phpdoc.name = '" . SQL::escape($name) . "'";
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 11
0
File: backup.php Progetto: rair/yacs
         $to_avoid[] = str_replace('`', '', SQL::table_name($token));
     }
 }
 //enumerate tables
 $queries = 0;
 $tables = SQL::list_tables($context['database']);
 while ($row = SQL::fetch_row($tables)) {
     // table name
     $table_name = $row[0];
     // skip unmatched prefixes
     if (isset($_REQUEST['backup_prefix']) && !preg_match('/' . preg_quote($_REQUEST['backup_prefix'], '/') . '/i', $table_name)) {
         continue;
     }
     // the string to re-create table structure
     $query = "SHOW CREATE TABLE " . $table_name;
     if (!($result = SQL::query_first($query)) || !isset($result['Create Table'])) {
         continue;
     }
     // strip constraints and keep only engine definition
     $create_query = preg_replace('/(ENGINE=\\w+)\\b.*$/i', '$1', $result['Create Table']);
     // split lines
     $create_query = str_replace('\\n', "\n", $create_query);
     // build the table creation query
     $sql = 'DROP TABLE IF EXISTS `' . $table_name . "`;\n\n" . $create_query . ";\n\n";
     if ($compressed) {
         gzwrite($handle, $sql);
     } else {
         fwrite($handle, $sql);
     }
     // skip content of some tables
     if (in_array($table_name, $to_avoid)) {
Esempio n. 12
0
File: cache.php Progetto: rair/yacs
 /**
  * retrieve cached information
  *
  * @param string the id of the text to be retrieved
  * @return string cached information, or NULL if the no accurate information is available for this id
  */
 public static function get($id, $f_capa = true, $f_lang = true, $f_gmt_off = true)
 {
     global $context;
     // return by reference
     $output = NULL;
     // recover from previous poisoining, if any
     $context['cache_has_been_poisoned'] = FALSE;
     // always disable cache when server is not switched on
     if (!file_exists($context['path_to_root'] . 'parameters/switch.on')) {
         return $output;
     }
     // the sql back-end may be not available during software updates or on NO_MODEL_PRELOAD
     if (!is_callable(array('SQL', 'query'))) {
         return $output;
     }
     // maybe we don't have to cache
     if (isset($context['without_cache']) && $context['without_cache'] == 'Y') {
         return $output;
     }
     // sanity check
     if (!$id) {
         return $output;
     }
     // cached content depends on surfer capability
     if ($f_capa) {
         $id .= '/' . Surfer::get_capability();
     }
     // cached content depends on selected language
     if ($f_lang) {
         $id .= '/' . $context['language'];
     }
     // cached content depends on time offset
     if ($f_gmt_off) {
         $id .= '/' . Surfer::get_gmt_offset();
     }
     // select among available items -- exact match
     $query = "SELECT * FROM " . SQL::table_name('cache') . " AS cache" . " WHERE (cache.id LIKE '" . SQL::escape($id) . "')";
     // do not report on error
     if (!($item = SQL::query_first($query, TRUE))) {
         return $output;
     }
     // check item validity
     if ($item['expiry_date'] < gmstrftime('%Y-%m-%d %H:%M:%S')) {
         return $output;
     }
     // we have a valid cached item
     $output = $item['text'];
     return $output;
 }
Esempio n. 13
0
File: enroll.php Progetto: rair/yacs
             // send the message
             Mailer::notify(Surfer::from(), $recipient, $subject, $message, $headers, $attachments);
         }
     }
     // drop enrolment record
     $query = "DELETE FROM " . SQL::table_name('enrolments') . " WHERE id = " . SQL::escape($_REQUEST['target']);
     SQL::query($query);
 }
 // validate an application
 if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'validate' && isset($_REQUEST['target']) && $_REQUEST['target']) {
     // update enrolment record
     $query = "UPDATE " . SQL::table_name('enrolments') . " SET approved = 'Y' WHERE id = " . SQL::escape($_REQUEST['target']);
     SQL::query($query);
     // list enrolment for this meeting
     $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE id = " . SQL::escape($_REQUEST['target']);
     if (($result = SQL::query_first($query)) && ($user = Users::get($result['user_id']))) {
         // add the page to the watch list
         Members::assign($anchor->get_reference(), 'user:'******'id']);
         // ensure that the enrolled person can access private pages
         if ($anchor->is_hidden()) {
             Members::assign('user:'******'id'], $anchor->get_reference());
         }
         // confirm enrolment by e-mail
         if ($user['email'] && preg_match(VALID_RECIPIENT, $user['email'])) {
             // use this email address
             if ($user['full_name']) {
                 $recipient = Mailer::encode_recipient($user['email'], $user['full_name']);
             } else {
                 $recipient = Mailer::encode_recipient($user['email'], $user['nick_name']);
             }
             // mail subject
Esempio n. 14
0
 /**
  * get some statistics for some categories
  *
  * Only categories matching following criteria are returned:
  * - category is visible (active='Y')
  * - category is restricted (active='R'), but surfer is a logged user
  * - an anchor has been provided and category is hidden (active='N'), but surfer is an associate
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param the selected anchor (e.g., 'category:12')
  * @return the resulting ($count, $min_date, $max_date) array
  */
 public static function stat_for_anchor($anchor)
 {
     global $context;
     // limit the scope of the request
     $where = "categories.active='Y'";
     if (Surfer::is_member()) {
         $where .= " OR categories.active='R'";
     }
     // list hidden categories to associates, but not on the category tree
     // they will be listed through a call to list_inactive_by_title() -- see categories/index.php
     if ($anchor && Surfer::is_associate()) {
         $where .= " OR categories.active='N'";
     }
     // only consider live categories
     $where = "(" . $where . ")" . " AND ((categories.expiry_date is NULL)" . "\tOR (categories.expiry_date <= '" . NULL_DATE . "') OR (categories.expiry_date > '" . $context['now'] . "'))";
     // limit the query to one level
     if ($anchor) {
         $where = "(categories.anchor LIKE '" . SQL::escape($anchor) . "') AND (" . $where . ')';
     } else {
         $where = "(categories.anchor='' OR categories.anchor is NULL) AND (" . $where . ')';
     }
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('categories') . " AS categories" . " WHERE " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 15
0
 /**
  * get some statistics
  *
  * @return the number of rows in table
  *
  * @see control/index.php
  */
 public static function stat()
 {
     global $context;
     // select among available items
     $query = "SELECT COUNT(*) as count FROM " . SQL::table_name('profiles');
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 16
0
 /**
  * get some statistics
  *
  * @return the resulting ($count, $min_date, $max_date) array
  */
 public static function stat()
 {
     global $context;
     // select among active and restricted items
     $where = "servers.active='Y'";
     if (Surfer::is_member()) {
         $where .= " OR servers.active='R'";
     }
     if (Surfer::is_associate()) {
         $where .= " OR servers.active='N'";
     }
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . ' FROM ' . SQL::table_name('servers') . ' AS servers' . ' WHERE (' . $where . ')';
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 17
0
File: issue.php Progetto: rair/yacs
 /**
  * build the history for this issue
  *
  * @return string an unnumbered list of dates
  */
 function get_history()
 {
     global $context;
     // sanity check
     if (!is_object($this->anchor)) {
         return NULL;
     }
     $query = "SELECT * FROM " . SQL::table_name('issues') . " AS issues " . " WHERE (issues.anchor LIKE '" . SQL::escape($this->anchor->get_reference()) . "')";
     // fetch the first row
     if (!($row = SQL::query_first($query))) {
         return NULL;
     }
     // text returned
     $text = '';
     // the creation step
     if ($row['create_date'] && $row['create_date'] > NULL_DATE) {
         $text .= self::get_history_item(i18n::s('Submission'), $row['create_date'], $row['create_name'], $row['create_address'], $row['create_id']);
     }
     // all steps
     $steps = array('cancelled:suspect', 'on-going:problem', 'cancelled:problem', 'on-going:issue', 'cancelled:issue', 'on-going:solution', 'cancelled:solution', 'completed:solution');
     // the qualification step
     if (in_array($this->attributes['status'], $steps) && $row['qualification_date'] && $row['qualification_date'] > NULL_DATE) {
         $text .= self::get_history_item(i18n::s('Qualification'), $row['qualification_date'], $row['qualification_name'], $row['qualification_address'], $row['qualification_id']);
     }
     // remove qualification
     array_shift($steps);
     array_shift($steps);
     // the analysis step
     if (in_array($this->attributes['status'], $steps) && $row['analysis_date'] && $row['analysis_date'] > NULL_DATE) {
         $text .= self::get_history_item(i18n::s('Analyzis'), $row['analysis_date'], $row['analysis_name'], $row['analysis_address'], $row['analysis_id']);
     }
     // remove analysis
     array_shift($steps);
     array_shift($steps);
     // the solution step
     if (in_array($this->attributes['status'], $steps) && $row['resolution_date'] && $row['resolution_date'] > NULL_DATE) {
         $text .= self::get_history_item(i18n::s('Action'), $row['resolution_date'], $row['resolution_name'], $row['resolution_address'], $row['resolution_id']);
     }
     // remove resolution
     array_shift($steps);
     array_shift($steps);
     // the close step
     if (in_array($this->attributes['status'], $steps) && $row['close_date'] && $row['close_date'] > NULL_DATE) {
         $text .= self::get_history_item(i18n::s('Finalization'), $row['close_date'], $row['close_name'], $row['close_address'], $row['close_id']);
     }
     if ($text) {
         return "<ul>" . $text . "</ul>";
     }
     return NULL;
 }
Esempio n. 18
0
File: sql.php Progetto: rair/yacs
 /**
  * initialize connections to the database
  *
  * @return TRUE on success, FALSE on failure
  */
 public static function initialize()
 {
     global $context;
     // no database parameters
     if (!isset($context['database_server']) || !isset($context['database_user']) || !isset($context['database_password']) || !isset($context['database'])) {
     } elseif (!($context['connection'] = SQL::connect($context['database_server'], $context['database_user'], $context['database_password'], $context['database']))) {
         // exit if batch mode
         if (!isset($_SERVER['REMOTE_ADDR'])) {
             exit(sprintf(i18n::s('Impossible to connect to %s.'), $context['database']));
         }
         // else jump to the control panel, if not in it already
         if (!preg_match('/(\\/control\\/|\\/included\\/|setup|login\\.php$)/i', $context['script_url'])) {
             Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'control/');
         }
     }
     // connect to the database for user records
     if (isset($context['users_database_server']) && $context['users_database_server']) {
         // additional connection for users table
         $context['users_connection'] = SQL::connect($context['users_database_server'], $context['users_database_user'], $context['users_database_password'], $context['users_database']);
     } elseif (isset($context['connection'])) {
         $context['users_connection'] = $context['connection'];
     }
     // the table prefix
     if (!isset($context['table_prefix'])) {
         $context['table_prefix'] = 'yacs_';
     }
     // sanity check
     if (!$context['connection']) {
         return FALSE;
     }
     // ensure we are talking utf8 to the database server
     $query = "SET NAMES 'utf8'";
     SQL::query($query);
     // detect utf8 database, if any
     if (!isset($_SESSION['database_is_utf8'])) {
         $_SESSION['database_is_utf8'] = FALSE;
         $query = "SHOW VARIABLES LIKE 'character_set_database'";
         if (($result = SQL::query_first($query)) && $result['Value'] == 'utf8') {
             $_SESSION['database_is_utf8'] = TRUE;
         }
     }
     // ask only once per session
     $context['database_is_utf8'] = $_SESSION['database_is_utf8'];
     // database ok
     return TRUE;
 }
Esempio n. 19
0
 /**
  * get some statistics for one anchor
  *
  * Only articles matching following criteria are returned:
  * - article is visible (active='Y')
  * - article is restricted (active='R'), but the surfer is an authenticated member,
  * or YACS is allowed to show restricted teasers
  * - article is protected (active='N'), but surfer is an associate, and we are not feeding someone
  * - surfer is anonymous or the variant is 'boxes', and article has been officially published
  * - logged surfers are restricted to their own articles, plus published articles
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param the selected anchor (e.g., 'section:12')
  * @param boolean FALSE to include sticky pages, TRUE otherwise
  * @return the resulting ($count, $min_date, $max_date) array
  *
  * @see sections/view.php
  */
 public static function stat_for_anchor($anchor, $without_sticky = FALSE)
 {
     global $context;
     // sanity check
     if (!$anchor) {
         return NULL;
     }
     // restrict the query to addressable content
     $where = Articles::get_sql_where();
     // avoid sticky articles
     if ($without_sticky) {
         $where .= " AND (articles.rank >= 10000)";
     }
     // anonymous surfers and subscribers will see only published articles
     if (!Surfer::is_member()) {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
         // logged surfers that are non-associates are restricted to their own articles, plus published articles
     } elseif (!Surfer::is_empowered()) {
         $where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
     }
     // only consider live articles
     $where .= " AND ((articles.expiry_date is NULL) " . "OR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . $context['now'] . "'))";
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('articles') . " AS articles" . " WHERE (articles.anchor LIKE '" . SQL::escape($anchor) . "') AND (" . $where . ")";
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 20
0
File: links.php Progetto: rair/yacs
 /**
  * get some statistics for one anchor
  *
  * @param the selected anchor (e.g., 'article:12')
  * @return the resulting ($count, $min_date, $max_date) array
  *
  * @see articles/delete.php
  * @see articles/view.php
  * @see categories/delete.php
  * @see categories/view.php
  * @see sections/delete.php
  * @see sections/sections.php
  * @see sections/view.php
  * @see skins/layout_home_articles_as_alistapart.php
  * @see skins/layout_home_articles_as_hardboiled.php
  * @see skins/layout_home_articles_as_daily.php
  * @see skins/layout_home_articles_as_newspaper.php
  * @see skins/layout_home_articles_as_slashdot.php
  * @see skins/skin_skeleton.php
  * @see users/delete.php
  */
 public static function stat_for_anchor($anchor)
 {
     global $context;
     // select among available items
     $query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('links') . " AS links" . " WHERE links.anchor LIKE '" . SQL::escape($anchor) . "'";
     $output = SQL::query_first($query);
     return $output;
 }
Esempio n. 21
0
} elseif (isset($_REQUEST['email']) && (!preg_match(VALID_RECIPIENT, $_REQUEST['email']) || !$_REQUEST['email'])) {
    $syntax = FALSE;
    $searchin = 'email';
}
if ($syntax) {
    if (isset($_REQUEST['nick_name'])) {
        $searchin = 'nick_name';
        $searchfor = $_REQUEST['nick_name'];
        $search_label = i18n::s('nick name');
    } else {
        $searchin = 'email';
        $searchfor = $_REQUEST['email'];
        $search_label = i18n::s('e-mail');
    }
    $query = "SELECT id FROM " . SQL::table_name('users') . " WHERE " . $searchin . " = '" . $searchfor . "'";
    $found = SQL::query_first($query);
    if ($found) {
        $output['can'] = false;
        $output['message'] = sprintf(i18n::s('Sorry this %s is already used.'), $search_label);
    } else {
        $output['can'] = true;
        $output['message'] = i18n::s('Ok, you can use this');
    }
} else {
    // bad syntax
    $output['can'] = false;
    if ($searchin === 'nick_name') {
        $output['message'] = i18n::s('Sorry some characters are forbidden here.');
    } else {
        $output['message'] = i18n::s('Incomplete or illegal character used');
    }