Ejemplo n.º 1
0
 /**
  * preserve content across page modification
  *
  * @see overlays/overlay.php
  *
  * @param the hosting attributes
  * @return a list of ($label, $input, $hint)
  */
 function get_fields($host, $field_pos = NULL)
 {
     global $context;
     // form fields
     $fields = array();
     // item identifier
     if (!isset($this->attributes['overlay_id'])) {
         $this->attributes['overlay_id'] = '';
     }
     // only associates can change the overlay id
     if (Surfer::is_associate()) {
         // isset($host['anchor']) && ($parent =&  Anchors::get($host['anchor'])) && $parent->is_assigned()) {
         $label = i18n::s('Overlay identifier');
         $input = '<input type="text" name="overlay_id" value="' . encode_field($this->attributes['overlay_id']) . '" />';
     } else {
         $label = 'hidden';
         $input = '<input type="hidden" name="overlay_id" value="' . encode_field($this->attributes['overlay_id']) . '" />';
     }
     // hidden attributes
     foreach ($this->attributes as $name => $value) {
         if (preg_match('/_content$/', $name)) {
             $input .= '<input type="hidden" name="' . encode_field($name) . '" value="' . encode_field($value) . '" />';
         }
     }
     // we do have something to preserve
     $fields[] = array($label, $input);
     // job done
     return $fields;
 }
Ejemplo n.º 2
0
 /**
  * Check if surfer is allowed to add sub-categories
  * 
  * @param string $type
  * @return boolean 
  */
 function allow_creation($type = '')
 {
     // surfer as to be a associate or editor of the category
     if ($this->is_assigned() || Surfer::is_associate()) {
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 3
0
 /**
  * extend the page menu
  *
  * @param string script name
  * @param string target anchor, if any
  * @param array current menu
  * @return array updated menu
  */
 function add_commands($script, $anchor, $menu = array())
 {
     global $context;
     // limit the scope of our check to viewed pages
     if (!preg_match('/articles\\/view/', $script)) {
         return $menu;
     }
     // surfer has to be authenticated
     if (!Surfer::is_logged()) {
         return $menu;
     }
     // sanity checks
     if (!$anchor) {
         Logger::error(i18n::s('No anchor has been found.'));
     } elseif (!($target = Anchors::get($anchor))) {
         Logger::error(i18n::s('No anchor has been found.'));
     } elseif (!$this->parameters) {
         Logger::error(sprintf(i18n::s('No parameter has been provided to %s'), 'behaviors/move_on_article_access'));
     } else {
         // look at parent container if possible
         if (!($origin = Anchors::get($target->get_parent()))) {
             $origin = $target;
         }
         // only container editors can proceed
         if ($origin->is_assigned() || Surfer::is_associate()) {
             // load target section
             $tokens = explode(' ', $this->parameters, 2);
             if ($section = Anchors::get('section:' . $tokens[0])) {
                 // make a label
                 if (count($tokens) < 2) {
                     $tokens[1] = sprintf(i18n::s('Move to %s'), $section->get_title());
                 }
                 // the target link to move the page
                 $link = Articles::get_url(str_replace('article:', '', $anchor), 'move', str_replace('section:', '', $section->get_reference()));
                 // make a sub-menu
                 $menu = array_merge(array($link => array('', $tokens[1], '', 'button')), $menu);
             }
         }
     }
     return $menu;
 }
Ejemplo n.º 4
0
Archivo: review.php Proyecto: rair/yacs
            $context['text'] .= $rows;
        }
    }
    // biggest files
    if (Surfer::is_associate() && ($rows = Files::list_by_size(0, 25, 'full'))) {
        $context['text'] .= Skin::build_block(i18n::s('Biggest files'), 'title');
        if (is_array($rows)) {
            $context['text'] .= Skin::build_list($rows, 'decorated');
        } else {
            $context['text'] .= $rows;
        }
    }
    // list files with very few hits
    if (Surfer::is_associate() && ($rows = Files::list_unused(0, 25))) {
        $context['text'] .= Skin::build_block(i18n::s('Less downloaded files'), 'title');
        if (is_array($rows)) {
            $context['text'] .= Skin::build_list($rows, 'decorated');
        } else {
            $context['text'] .= $rows;
        }
    }
    // size of noise words
    if (Surfer::is_associate() && is_readable($context['path_to_root'] . 'files/noise_words.php')) {
        include_once $context['path_to_root'] . 'files/noise_words.php';
        if (@count($noise_words)) {
            $context['text'] .= '<p>' . sprintf(i18n::s('%d items in the list of noise words'), count($noise_words)) . '</p>';
        }
    }
}
// render the skin
render_skin();
Ejemplo n.º 5
0
Archivo: index.php Proyecto: rair/yacs
// news
$context['components']['news'] = $text;
// list extra boxes
$text = '';
if ($anchor = Sections::lookup('extra_boxes')) {
    // the maximum number of boxes is a global parameter
    if (!isset($context['site_extra_maximum']) || !$context['site_extra_maximum']) {
        $context['site_extra_maximum'] = 7;
    }
    // articles to be displayed as extra boxes
    if ($items =& Articles::list_for_anchor_by('publication', $anchor, 0, $context['site_extra_maximum'], 'boxes')) {
        foreach ($items as $title => $attributes) {
            $text .= Skin::build_box($title, $attributes['content'], 'boxes', $attributes['id']) . "\n";
        }
    }
}
// boxes
$context['components']['boxes'] = $text;
// referrals, if any
if (Surfer::is_associate() || isset($context['with_referrals']) && $context['with_referrals'] == 'Y') {
    $context['components']['referrals'] =& Skin::build_referrals('index.php');
}
//
// compute navigation information -- $context['navigation']
//
// a meta link to a feeding page
$context['page_header'] .= "\n" . '<link rel="alternate" href="' . $context['url_to_root'] . Feeds::get_url('rss') . '" title="RSS" type="application/rss+xml" />';
// a meta link to our blogging interface
$context['page_header'] .= "\n" . '<link rel="EditURI" href="' . $context['url_to_home'] . $context['url_to_root'] . 'services/describe.php" title="RSD" type="application/rsd+xml" />';
// render the skin
render_skin();
Ejemplo n.º 6
0
Archivo: vote.php Proyecto: rair/yacs
}
$vote = strip_tags($vote);
// next url
$next = '';
if (isset($_REQUEST['next'])) {
    $next = $_REQUEST['next'];
}
if (isset($context['arguments'][2])) {
    $next = $context['arguments'][2];
}
$next = strip_tags($next);
//
// is this surfer allowed to browse the resulting page?
//
// associates and editors can do what they want
if (Surfer::is_associate() || Articles::is_assigned($id) || is_object($anchor) && $anchor->is_assigned()) {
    $permitted = TRUE;
} elseif (Surfer::get_id() && isset($item['create_id']) && $item['create_id'] == Surfer::get_id()) {
    $permitted = TRUE;
} elseif (is_object($anchor) && !$anchor->is_viewable()) {
    $permitted = FALSE;
} elseif (isset($item['active']) && $item['active'] == 'R' && Surfer::is_member()) {
    $permitted = TRUE;
} elseif (isset($item['active']) && $item['active'] == 'Y') {
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// load the skin, maybe with a variant
load_skin('polls', $anchor);
// the path to this page
Ejemplo n.º 7
0
Archivo: links.php Proyecto: rair/yacs
 /**
  * get some statistics
  *
  * @return the resulting ($count, $min_date, $max_date) array
  *
  * @see links/index.php
  */
 public static function stat()
 {
     global $context;
     // if not associate, restrict to links attached to public published not expired pages
     if (!Surfer::is_associate()) {
         $where = ", " . SQL::table_name('articles') . " AS articles " . " WHERE ((links.anchor_type LIKE 'article') AND (links.anchor_id = articles.id))" . " AND (articles.active='Y')" . " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND ((articles.expiry_date is NULL)" . "\tOR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'))" . " AND (links.edit_id > 0)";
     } else {
         $where = "WHERE (links.edit_id > 0)";
     }
     // select among available items
     $query = "SELECT COUNT(links.link_url) as count, MIN(links.edit_date) as oldest_date, MAX(links.edit_date) as newest_date" . " FROM " . SQL::table_name('links') . " AS links " . $where;
     $output = SQL::query_first($query);
     return $output;
 }
Ejemplo n.º 8
0
Archivo: view.php Proyecto: rair/yacs
    }
    // page details
    if (is_array($details)) {
        $context['text'] .= '<p class="details">' . ucfirst(implode(', ', $details)) . "</p>\n";
    }
    // insert anchor suffix
    if (is_object($anchor)) {
        $context['text'] .= $anchor->get_suffix();
    }
    // back to the anchor page
    if (is_object($anchor) && $anchor->is_viewable()) {
        $menu = array(Skin::build_link($anchor->get_url(), i18n::s('Back to main page'), 'button'));
        $context['text'] .= Skin::build_block(Skin::finalize_list($menu, 'menu_bar'), 'bottom');
    }
    //
    // populate the extra panel
    //
    // commands for associates and editors
    if (Surfer::is_associate() || is_object($anchor) && $anchor->is_assigned()) {
        $context['page_tools'][] = Skin::build_link(Locations::get_url($id, 'edit'), i18n::s('Edit'));
        $context['page_tools'][] = Skin::build_link(Locations::get_url($id, 'delete'), i18n::s('Delete'));
        // commands for the author
    } elseif (Surfer::is($item['edit_id'])) {
        $context['page_tools'][] = Skin::build_link(Locations::get_url($item['id'], 'edit'), i18n::s('Edit'));
    }
    // referrals, if any, in a sidebar
    //
    $context['components']['referrals'] =& Skin::build_referrals(Locations::get_url($item['id']));
}
// render the skin
render_skin();
Ejemplo n.º 9
0
// include global declarations
include_once '../shared/global.php';
// load localized strings
i18n::bind('scripts');
// load the skin
load_skin('scripts');
// the path to this page
$context['path_bar'] = array('control/' => i18n::s('Control Panel'));
// the title of the page
$context['page_title'] = i18n::s('Run one-time scripts');
// the list of script to take into account
global $scripts;
$scripts = array();
// if the user table exists, check that the user is an admin
$query = "SELECT count(*) FROM " . SQL::table_name('users');
if (SQL::query($query) !== FALSE && !Surfer::is_associate()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // open the directory
} elseif (!($dir = Safe::opendir($context['path_to_root'] . 'scripts/run_once'))) {
    Logger::error(sprintf(i18n::s('Impossible to read %s.'), $context['path_to_run_once_scripts']));
} else {
    while (($item = Safe::readdir($dir)) !== FALSE) {
        // script name has to start with a number --actually, a date
        if ($item[0] < '0' || $item[0] > '9') {
            continue;
        }
        // we only consider php scripts, of course
        if (strlen($item) < 5 || substr($item, -4) != '.php') {
            continue;
        }
Ejemplo n.º 10
0
Archivo: test.php Proyecto: rair/yacs
echo '<p>' . i18n::s('Server GMT offset:') . ' UTC ' . ($offset > 0 ? "+" : "") . $offset . ' ' . i18n::s('hour(s)') . ' (' . date('Y-M-d H:i:s') . ")</p>\n";
// run-time information
if (Surfer::is_associate()) {
    echo '<p>';
    // current directory
    if (is_callable('getcwd')) {
        echo 'getcwd()=' . getcwd() . BR . "\n";
    }
    // PHP SAPI name
    if (is_callable('php_sapi_name')) {
        echo 'php_sapi_name()=' . php_sapi_name() . BR . "\n";
    }
    echo "</p>\n";
}
// do not reveal names of accounts used on server side
if (Surfer::is_associate() && !file_exists($context['path_to_root'] . 'parameters/demo.flag')) {
    // user/group of this script
    if (is_callable('getmyuid') && ($uid = getmyuid()) !== FALSE && is_callable('getmygid') && ($gid = getmygid()) !== FALSE) {
        // describe user
        $ulabel = $uid;
        if (is_callable('posix_getpwuid') && ($uinfo = posix_getpwuid($uid)) !== FALSE) {
            if (isset($uinfo['name'])) {
                $ulabel = $uinfo['name'] . '[' . $uid . ']';
            }
        }
        // describe group and members
        $glabel = $gid;
        if (is_callable('posix_getgrgid') && ($ginfo = posix_getgrgid($gid)) !== FALSE) {
            // group name
            if (isset($ginfo['name'])) {
                $glabel = $ginfo['name'] . '[' . $gid . ']';
Ejemplo n.º 11
0
Archivo: view.php Proyecto: rair/yacs
     // linked in
     Skin::define_img('PAGERS_LINKEDIN_IMG', 'pagers/linkedin.gif');
     $lines[] = Skin::build_link('http://www.linkedin.com/shareArticle?mini=true&url=' . $url . '&title=' . urlencode($item['title']) . '&summary=' . urlencode($item['introduction']) . '&source=' . urlencode($anchor->get_title()), PAGERS_LINKEDIN_IMG . i18n::s('Share at LinkedIn'), 'basic', i18n::s('Spread the word'));
 }
 // invite participants
 if (($cur_article->is_owned() || $item['active'] == 'Y') && isset($context['with_email']) && $context['with_email'] == 'Y') {
     Skin::define_img('ARTICLES_INVITE_IMG', 'articles/invite.gif');
     $lines[] = Skin::build_link(Articles::get_url($item['id'], 'invite'), ARTICLES_INVITE_IMG . i18n::s('Invite participants'), 'basic', i18n::s('Spread the word'));
 }
 // notify participants
 if (($cur_article->is_owned() || Surfer::is_associate()) && isset($context['with_email']) && $context['with_email'] == 'Y') {
     Skin::define_img('ARTICLES_EMAIL_IMG', 'articles/email.gif');
     $lines[] = Skin::build_link(Articles::get_url($item['id'], 'mail'), ARTICLES_EMAIL_IMG . i18n::s('Notify participants'));
 }
 // manage editors
 if ($cur_article->is_owned() || Surfer::is_associate()) {
     Skin::define_img('ARTICLES_ASSIGN_IMG', 'articles/assign.gif');
     $lines[] = Skin::build_link(Users::get_url('article:' . $item['id'], 'select'), ARTICLES_ASSIGN_IMG . i18n::s('Manage participants'));
 }
 // the command to track back
 if (Links::allow_trackback()) {
     Skin::define_img('TOOLS_TRACKBACK_IMG', 'tools/trackback.gif');
     $lines[] = Skin::build_link('links/trackback.php?anchor=' . urlencode('article:' . $item['id']), TOOLS_TRACKBACK_IMG . i18n::s('Reference this page'), 'basic', i18n::s('Various means to link to this page'));
 }
 // more tools
 if (isset($context['with_export_tools']) && $context['with_export_tools'] == 'Y' || is_object($anchor) && $anchor->has_option('with_export_tools')) {
     // check tools visibility
     if (Surfer::is_member() || isset($context['with_anonymous_export_tools']) && $context['with_anonymous_export_tools'] == 'Y') {
         // get a PDF version
         Skin::define_img('ARTICLES_PDF_IMG', 'articles/export_pdf.gif');
         $lines[] = Skin::build_link(Articles::get_url($item['id'], 'fetch_as_pdf'), ARTICLES_PDF_IMG . i18n::s('Save as PDF'), 'basic', i18n::s('Save as PDF'));
Ejemplo n.º 12
0
 /**
  * get some introductory text from an article
  *
  * This function is used to introduce comments, or any sub-item related to an anchor.
  * Compared to the standard anchor implementation, this one adds the ability to handle overlay data.
  *
  * If there is some introductory text, it is used. Else the description text is used instead.
  * The number of words is capped in both cases.
  *
  * Also, the number of remaining words is provided.
  *
  * Following variants may be selected to adapt to various situations:
  * - 'basic' - strip every tag, we want almost plain ASCII - maybe this will be send in a mail message
  * - 'hover' - some text to be displayed while hovering a link
  * - 'quote' - strip most HTML tags
  * - 'teaser' - limit the number of words, tranform YACS codes, and link to permalink
  *
  * @see shared/anchor.php
  *
  * @param string an optional variant, including
  * @return NULL, of some text
  */
 function &get_teaser($variant = 'basic')
 {
     global $context;
     // no item bound
     if (!isset($this->item['id'])) {
         $text = NULL;
         return $text;
     }
     // the text to be returned
     $text = '';
     // use the introduction field, if any
     if ($this->item['introduction']) {
         $text = trim($this->item['introduction']);
         // may be rendered as an empty strings
         if ($variant != 'hover') {
             // remove toc and toq codes
             $text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
             // render all codes
             if (is_callable(array('Codes', 'beautify'))) {
                 $text = Codes::beautify($text, $this->item['options']);
             }
         }
         // combine with description
         if ($variant == 'quote') {
             $text .= BR . BR;
         }
     }
     // use overlay data, if any
     if (!$text) {
         if (!isset($this->overlay) && isset($this->item['overlay'])) {
             $this->overlay = Overlay::load($this->item, 'article:' . $this->item['id']);
         }
         if (is_object($this->overlay)) {
             $text .= $this->overlay->get_text('list', $this->item);
         }
     }
     // use the description field, if any
     $in_description = FALSE;
     if (!$text && $variant != 'hover') {
         $text .= trim($this->item['description']);
         $in_description = TRUE;
         // remove toc and toq codes
         $text = preg_replace(FORBIDDEN_IN_TEASERS, '', $text);
         // render all codes
         if ($variant == 'teaser' && is_callable(array('Codes', 'beautify'))) {
             $text = Codes::beautify($text, $this->item['options']);
         }
     }
     // turn html entities to unicode entities
     $text = utf8::transcode($text);
     // now we have to process the provided text
     switch ($variant) {
         // strip everything
         case 'basic':
         default:
             // strip every HTML and limit the size
             if (is_callable(array('Skin', 'strip'))) {
                 $text = Skin::strip($text, 70, NULL, '');
             }
             // done
             return $text;
             // some text for pop-up panels
         // some text for pop-up panels
         case 'hover':
             // strip every HTML and limit the size
             if (is_callable(array('Skin', 'strip'))) {
                 $text = Skin::strip($text, 70, NULL, '');
             }
             // ensure we have some text
             if (!$text) {
                 $text = i18n::s('View the page');
             }
             // mention shortcut to article
             if (Surfer::is_associate()) {
                 $text .= ' [article=' . $this->item['id'] . ']';
             }
             // done
             return $text;
             // quote this
         // quote this
         case 'quote':
             // strip every HTML and limit the size
             if (is_callable(array('Skin', 'strip'))) {
                 $text = Skin::strip($text, 300, NULL, '<a><b><br><i><img><strong><u>');
             }
             // done
             return $text;
             // preserve as much as possible
         // preserve as much as possible
         case 'teaser':
             // lower level of titles
             $text = str_replace(array('<h4', '</h4'), array('<h5', '</h5'), $text);
             $text = str_replace(array('<h3', '</h3'), array('<h4', '</h4'), $text);
             $text = str_replace(array('<h2', '</h2'), array('<h3', '</h3'), $text);
             // limit the number of words
             if (is_callable(array('Skin', 'cap'))) {
                 $text = Skin::cap($text, WORDS_IN_TEASER, $this->get_url());
             }
             // done
             return $text;
     }
 }
Ejemplo n.º 13
0
Archivo: chmod.php Proyecto: rair/yacs
 */
// common definitions and initial processing
include_once '../shared/global.php';
include_once '../scripts/scripts.php';
// load localized strings
i18n::bind('control');
// load the skin
load_skin('control');
// the path to this page
$context['path_bar'] = array('control/' => i18n::s('Control Panel'));
// the title of the page
$context['page_title'] = i18n::s('Update file permissions');
// anonymous users are invited to log in or to register
if (!Surfer::is_logged()) {
    Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode('control/chmod.php'));
} elseif (!Surfer::is_associate() && !(file_exists($context['path_to_root'] . 'parameters/switch.on') || file_exists($context['path_to_root'] . 'parameters/switch.off'))) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // forward to the index page
    $menu = array('control/' => i18n::s('Control Panel'));
    $context['text'] .= Skin::build_list($menu, 'menu_bar');
    // do the action
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'confirm') {
    // list running scripts
    $context['text'] .= '<p>' . i18n::s('Listing files...') . BR . "\n";
    // locate script files starting at root
    $scripts = Scripts::list_scripts_at(NULL);
    if (is_array($scripts)) {
        $context['text'] .= BR . sprintf(i18n::s('%d scripts have been found.'), count($scripts)) . "\n";
    }
    $context['text'] .= "</p>\n";
Ejemplo n.º 14
0
Archivo: delete.php Proyecto: rair/yacs
        $cells = array(i18n::s('Downloads'), 'left=' . Skin::build_number($item['hits'], i18n::s('downloads')));
        $context['text'] .= Skin::table_row($cells, $lines++);
    }
    // the first poster
    if ($item['create_name']) {
        $cells = array(i18n::s('Posted by'), $item['create_name']);
        $context['text'] .= Skin::table_row($cells, $lines++);
    }
    // the last poster
    if ($item['edit_name'] != $item['create_name']) {
        $cells = array(i18n::s('Updated by'), $item['edit_name']);
        $context['text'] .= Skin::table_row($cells, $lines++);
    }
    // date of last action
    $cells = array(i18n::s('Last action'), Skin::build_date($item['edit_date']));
    $context['text'] .= Skin::table_row($cells, $lines++);
    // associates may change the active flag: Yes/public, Restricted/logged, No/associates
    if (Surfer::is_associate()) {
        if ($item['active'] == 'N' && Surfer::is_associate()) {
            $context['text'] .= Skin::table_row(array(i18n::s('Access'), 'left=' . i18n::s('Private - Access is restricted to selected persons')), $lines++);
        } elseif ($item['active'] == 'R' && Surfer::is_member()) {
            $context['text'] .= Skin::table_row(array(i18n::s('Access'), 'left=' . i18n::s('Community -Access is granted to any identified surfer')), $lines++);
        }
    }
    // end of the table
    $context['text'] .= Skin::table_suffix();
    // count items related to this file
    $context['text'] .= Anchors::stat_related_to('file:' . $item['id'], i18n::s('Following items are attached to this record and will be deleted as well.'));
}
// render the skin
render_skin();
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
0
Archivo: page.php Proyecto: rair/yacs
 /**
  * show site tabs
  *
  * Tabs are derived by top-level sections of the server.
  *
  * Prefix and suffix tabs can be provided as links packaged in arrays of ( $url => array($label_prefix, $label, $label_suffix, $link_class) )
  *
  * @param boolean TRUE to add a tab to the front page, FALSE otherwise
  * @param boolean TRUE to reverse order of tabs, FALSE otherwise
  * @param array of links to be used as tabs before the regular set
  * @param array of links to be used as tabs after the regular set
  * @param string layout name to use for listing sub-sections (horizontal drop down menu)
  */
 public static function tabs($with_home = TRUE, $with_reverse = FALSE, $prefix = NULL, $suffix = NULL, $layout_subsections = NULL)
 {
     global $context;
     // only for live servers Or Associate
     if (!file_exists($context['path_to_root'] . 'parameters/switch.on') && !Surfer::is_associate()) {
         return;
     }
     // we have no database back-end
     if (!is_callable(array('sql', 'query'))) {
         return;
     }
     // limit listing for drop-down menu
     if (!defined('TABS_DROP_LIST_SIZE')) {
         define('TABS_DROP_LIST_SIZE', 5);
     }
     // cache this across requests
     $cache_id = 'skins/page.php#tabs';
     if (!($text = Cache::get($cache_id))) {
         // an array of tabs
         $site_bar = array();
         // prefix tabs, if any
         if (is_array($prefix) && count($prefix)) {
             $site_bar = array_merge($site_bar, $prefix);
         }
         // the first tab links to the front page
         if ($with_home && is_callable(array('i18n', 's'))) {
             $site_bar = array_merge($site_bar, array($context['url_to_root'] => array('', i18n::s('Home'), '', 'home')));
         }
         // default number of sections to list
         if (!isset($context['root_sections_count_at_home']) || $context['root_sections_count_at_home'] < 1) {
             $context['root_sections_count_at_home'] = 5;
         }
         // query the database to get dynamic tabs
         if (is_callable(array('Sections', 'list_by_title_for_anchor')) && ($items = Sections::list_by_title_for_anchor(NULL, 0, $context['root_sections_count_at_home'], 'main_tabs'))) {
             if (count($items)) {
                 //query subsections if layout is provided
                 if ($layout_subsections) {
                     //Parse mother-sections previously selected to get sub-sections
                     foreach ($items as $url => $item) {
                         //get id of mother section
                         $mother_id = str_replace('_', ':', $item[3]);
                         //get subsections list
                         $subsections = '';
                         $subsections = Sections::list_by_title_for_anchor($mother_id, 0, TABS_DROP_LIST_SIZE, $layout_subsections);
                         //transform list into string if necessary (depend layout output)
                         if (is_array($subsections)) {
                             $subsections = Skin::build_list($subsections, $layout_subsections);
                         }
                         //get real number of subsections
                         $nb_subsections = Sections::count_for_anchor($mother_id);
                         //hint unlisted subsections if any
                         $hint = '<p class="details" id="dropcount">';
                         if ($nb_subsections > TABS_DROP_LIST_SIZE) {
                             $hint .= '( ';
                             $hint .= sprintf(i18n::ns('%d section', '%d sections', $nb_subsections), $nb_subsections);
                             $hint .= ' )</p>';
                         } else {
                             // provide empty <p> to preserve alignment
                             $hint .= '&nbsp;</p>';
                         }
                         $subsections = $hint . $subsections;
                         //store sub-sections list into "suffix" of this tab's label
                         if ($subsections) {
                             $items[$url][2] = "\n<div class=dropmenu>" . $subsections . '</div>';
                         }
                     }
                 }
                 $site_bar = array_merge($site_bar, $items);
             }
         }
         // suffix tabs, if any
         if (is_array($suffix) && count($suffix)) {
             $site_bar = array_merge($site_bar, $suffix);
         }
         // the skin will reverse the order
         if ($with_reverse) {
             $site_bar = array_reverse($site_bar);
         }
         // shape tabs
         $text = Skin::build_list($site_bar, 'tabs') . "\n";
         // cache result
         Cache::put($cache_id, $text, 'sections');
     }
     echo $text;
 }
Ejemplo n.º 17
0
     $input = Articles::build_options_input($item);
     $hint = Articles::build_options_hint($item);
     $fields[] = array($label, $input, $hint);
 }
 // language of this page
 $label = i18n::s('Language');
 $input = i18n::get_languages_select(isset($item['language']) ? $item['language'] : '');
 $hint = i18n::s('Select the language used for this page');
 $fields[] = array($label, $input, $hint);
 // meta information
 $label = i18n::s('Meta information');
 $input = '<textarea name="meta" rows="10" cols="50">' . encode_field(isset($item['meta']) ? $item['meta'] : '') . '</textarea>';
 $hint = i18n::s('Type here any XHTML tags to be put in page header.');
 $fields[] = array($label, $input, $hint);
 // associates can change the overlay --complex interface
 if (Surfer::is_associate() && Surfer::has_all()) {
     // current type
     $overlay_type = '';
     if (is_object($overlay)) {
         $overlay_type = $overlay->get_type();
     }
     // list overlays available on this system
     $label = i18n::s('Change the overlay');
     $input = '<select name="overlay_type">';
     if ($overlay_type) {
         $input .= '<option value="none">(' . i18n::s('none') . ")</option>\n";
         $hint = i18n::s('If you change the overlay you may loose some data.');
     } else {
         $hint = i18n::s('No overlay has been selected yet.');
         $input .= '<option value="" selected="selected">' . i18n::s('none') . "</option>\n";
     }
Ejemplo n.º 18
0
// post an image, if upload is allowed
if (Images::allow_creation($item, $anchor, 'section')) {
    Skin::define_img('IMAGES_ADD_IMG', 'images/add.gif');
    $context['page_tools'][] = Skin::build_link('images/edit.php?anchor=' . urlencode('section:' . $item['id']), IMAGES_ADD_IMG . i18n::s('Add an image'), 'basic', i18n::s('You can upload a camera shot, a drawing, or another image file.'));
}
// ensure that the surfer can change content
if (Sections::allow_modification($item, $anchor)) {
    // modify this page
    Skin::define_img('SECTIONS_EDIT_IMG', 'sections/edit.gif');
    if (!is_object($overlay) || !($label = $overlay->get_label('edit_command', 'sections'))) {
        $label = i18n::s('Edit this section');
    }
    $context['page_tools'][] = Skin::build_link(Sections::get_url($item['id'], 'edit'), SECTIONS_EDIT_IMG . $label, 'basic', i18n::s('Press [e] to edit'), FALSE, 'e');
}
// commands for section owners
if (Sections::is_owned($item, $anchor) || Surfer::is_associate()) {
    // access previous versions, if any
    if ($has_versions) {
        Skin::define_img('SECTIONS_VERSIONS_IMG', 'sections/versions.gif');
        $context['page_tools'][] = Skin::build_link(Versions::get_url('section:' . $item['id'], 'list'), SECTIONS_VERSIONS_IMG . i18n::s('Versions'), 'basic', i18n::s('Restore a previous version if necessary'));
    }
    // lock the page
    if (!isset($item['locked']) || $item['locked'] == 'N') {
        Skin::define_img('SECTIONS_LOCK_IMG', 'sections/lock.gif');
        $context['page_tools'][] = Skin::build_link(Sections::get_url($item['id'], 'lock'), SECTIONS_LOCK_IMG . i18n::s('Lock'), 'basic');
    } else {
        Skin::define_img('SECTIONS_UNLOCK_IMG', 'sections/unlock.gif');
        $context['page_tools'][] = Skin::build_link(Sections::get_url($item['id'], 'lock'), SECTIONS_UNLOCK_IMG . i18n::s('Unlock'), 'basic');
    }
    // delete the page
    Skin::define_img('SECTIONS_DELETE_IMG', 'sections/delete.gif');
Ejemplo n.º 19
0
Archivo: tables.php Proyecto: rair/yacs
 /**
  * build one table
  *
  * Accept following variants:
  * - csv - to provide a downloadable csv page
  * - json - to provide all values in one column
  * - inline - to render tables within articles
  * - simple - the legacy fixed table
  * - sortable - click on column to sort the row
  *
  * @param the id of the table to build
  * @param string the variant to provide - default is 'simple'
  * @return a displayable string
  */
 public static function build($id, $variant = 'simple')
 {
     global $context;
     // split parameters
     $attributes = preg_split("/\\s*,\\s*/", $id, 3);
     $id = $attributes[0];
     // get the table object
     if (!($table = Tables::get($id))) {
         return NULL;
     }
     // do the SELECT statement
     if (!($rows = SQL::query($table['query']))) {
         Logger::error(sprintf(i18n::s('Error in table query %s'), $id) . BR . htmlspecialchars($table['query']) . BR . SQL::error());
         return NULL;
     }
     // build the resulting string
     $text = '';
     switch ($variant) {
         // produce a table readable into MS-Excel
         case 'csv':
             // comma separated values
             $separator = ",";
             // one row for the title
             if ($table['title']) {
                 $label = preg_replace('/\\s/', ' ', $table['title']);
                 // encode to ASCII
                 $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 // escape quotes to preserve them in the data
                 $label = str_replace('"', '""', $label);
                 $text .= '"' . $label . '"';
                 $text .= "\n";
             }
             // one row for header fields
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 if ($index++) {
                     $text .= $separator;
                 }
                 $label = trim(preg_replace('/\\s/', ' ', ucfirst($field->name)));
                 // encode
                 $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 // escape quotes to preserve them in the data
                 $label = str_replace('"', '""', $label);
                 $text .= '"' . $label . '"';
             }
             $text .= "\n";
             // process every table row
             $row_index = 0;
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // glue cells
                     if ($index++) {
                         $text .= $separator;
                     }
                     // remove HTML tags
                     $value = strip_tags(str_replace('</', ' </', str_replace(BR, ' / ', $value)));
                     // clean spaces
                     $label = trim(preg_replace('/\\s+/', ' ', $value));
                     // encode
                     $label = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // make a link if this is a reference
                     if ($index == 1 && $table['with_zoom'] == 'Y') {
                         $label = $context['url_to_home'] . $context['url_to_root'] . $label;
                     }
                     // quote data
                     $text .= '"' . $label . '"';
                 }
                 // new line
                 $text .= "\n";
             }
             return $text;
             // a JSON set of values
         // a JSON set of values
         case 'json':
             // get header labels
             $labels = array();
             while ($field = SQL::fetch_field($rows)) {
                 $labels[] = trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
             }
             // all items
             $data = array();
             $data['items'] = array();
             while ($row = SQL::fetch_row($rows)) {
                 // all rows
                 $datum = array();
                 $label = FALSE;
                 $index = 0;
                 $link = NULL;
                 foreach ($row as $name => $value) {
                     $index++;
                     // first column is only a link
                     if ($index == 1 && $table['with_zoom'] == 'Y') {
                         $link = $context['url_to_home'] . $context['url_to_root'] . ltrim($value, '/');
                         continue;
                     }
                     // adjust types to not fool the json encoder
                     if (preg_match('/^(\\+|-){0,1}[0-9]+$/', $value)) {
                         $value = intval($value);
                     } elseif (preg_match('/^(\\+|-){0,1}[0-9\\.,]+$/', $value)) {
                         $value = floatval($value);
                     } elseif (preg_match('/^(true|false)$/i', $value)) {
                         $value = intval($value);
                     }
                     // ensure we have some label for SIMILE Exhibit
                     if (!$label) {
                         $label = $value;
                     }
                     // combine first and second columns
                     if ($index == 2 && $link) {
                         $value = Skin::build_link($link, $value, 'basic');
                     }
                     // save this value
                     $datum[$labels[$name]] = utf8::to_ascii($value, PRINTABLE_SAFE_ALPHABET);
                 }
                 if ($label && !in_array('label', $labels)) {
                     $datum['label'] = utf8::to_ascii($label, PRINTABLE_SAFE_ALPHABET);
                 }
                 // add a tip, if any
                 $data['items'][] = $datum;
             }
             include_once $context['path_to_root'] . 'included/json.php';
             $text .= json_encode2($data);
             return $text;
             // list of facets for SIMILE Exhibit
         // list of facets for SIMILE Exhibit
         case 'json-facets':
             // columns are actual facets
             $facets = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $index++;
                 // first column is only a link
                 if ($index == 1 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // first column has a link
                 if ($index == 2 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // column is a facet
                 $label = '.' . trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
                 $title = trim(str_replace(',', '', ucfirst($field->name)));
                 $facets[] = '<div ex:role="facet" ex:expression="' . $label . '" ex:facetLabel="' . $title . '"></div>';
                 // only last columns can be faceted
                 if (count($facets) > 7) {
                     array_shift($facets);
                 }
             }
             // reverse facet order
             $facets = array_reverse($facets);
             // job done
             $text = join("\n", $facets);
             return $text;
             // list of columns for SIMILE Exhibit
         // list of columns for SIMILE Exhibit
         case 'json-labels':
             // get header labels
             $labels = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $index++;
                 // first column is only a link
                 if ($index == 1 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // column id
                 $labels[] = '.' . trim(preg_replace('/[^\\w]+/', '', ucfirst($field->name)));
                 // limit the number of columns put on screen
                 if (count($labels) >= 7) {
                     break;
                 }
             }
             // job done
             $text = join(', ', $labels);
             return $text;
             // titles of columns for SIMILE Exhibit
         // titles of columns for SIMILE Exhibit
         case 'json-titles':
             // get header labels
             $labels = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $index++;
                 // first column is only a link
                 if ($index == 1 && $table['with_zoom'] == 'Y') {
                     continue;
                 }
                 // column header
                 $labels[] = trim(str_replace(',', '', ucfirst($field->name)));
             }
             $text = join(', ', $labels);
             return $text;
             // produce an HTML table
         // produce an HTML table
         default:
         case 'inline':
         case 'sortable':
             // a table with a grid
             $text .= Skin::table_prefix('grid');
             // the title, with a menu to download the table into Excel
             if ($variant == 'inline') {
                 $item_bar = array();
                 $item_bar += array(Tables::get_url($id) => $table['title']);
                 $item_bar += array(Tables::get_url($id, 'fetch_as_csv') => 'CSV (Excel)');
                 if (Surfer::is_associate()) {
                     $item_bar += array(Tables::get_url($id, 'edit') => i18n::s('edit'));
                 }
                 if (count($item_bar)) {
                     $text .= '<caption>' . Skin::build_list($item_bar, 'menu') . "</caption>\n";
                 }
             }
             // column headers are clickable links
             $cells = array();
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 if ($index++ != 0 || $table['with_zoom'] != 'Y') {
                     $cells[] = ucfirst($field->name);
                 }
             }
             $text .= "\t\t" . Skin::table_row($cells, 'sortable');
             // the table body
             $count = 0;
             $row_index = 0;
             while ($row = SQL::fetch_row($rows)) {
                 $cells = array();
                 $link = '';
                 for ($index = 0; $index < count($row); $index++) {
                     if ($index == 0 && $table['with_zoom'] == 'Y') {
                         $link = $row[$index];
                     } elseif ($link) {
                         $cells[] = Skin::build_link($link, $row[$index]);
                         $link = '';
                     } else {
                         $cells[] = $row[$index];
                     }
                 }
                 $text .= "\t\t" . Skin::table_row($cells, $count++);
             }
             $text .= Skin::table_suffix();
             return $text;
             // adapted to open chart flash
         // adapted to open chart flash
         case 'chart':
             // get title for y series
             $y_title = $y2_title = $y3_title = NULL;
             $y_index = $y2_index = $y3_index = 0;
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 // time will be used for x labels
                 if ($index == 0 && $table['with_zoom'] == 'T') {
                 } elseif ($index == 0 && $table['with_zoom'] == 'Y') {
                 } elseif (!$y_title) {
                     $y_title = '"' . ucfirst($field->name) . '"';
                     $y_index = $index;
                 } elseif (!$y2_title) {
                     $y2_title = '"' . ucfirst($field->name) . '"';
                     $y2_index = $index;
                 } elseif (!$y3_title) {
                     $y3_title = '"' . ucfirst($field->name) . '"';
                     $y3_index = $index;
                     break;
                 }
                 $index++;
             }
             // process every table row
             $x_labels = array();
             $y_values = array();
             $y2_values = array();
             $y3_values = array();
             $y_min = $y_max = NULL;
             $count = 1;
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // clean spaces
                     $label = trim(preg_replace('/\\s/', ' ', $value));
                     // encode in iso8859
                     $label = utf8::to_iso8859($label);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // quote data
                     if (preg_match('/-*[^0-9\\,\\.]/', $label)) {
                         $label = '"' . $label . '"';
                     }
                     // x labels
                     if ($index == 0) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($x_labels, $label);
                         } else {
                             $x_labels[] = $count++;
                         }
                         // y value
                     } elseif ($index == $y_index) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($y_values, $label);
                         } else {
                             $y_values[] = $label;
                         }
                         if (!isset($y_min) || intval($label) < $y_min) {
                             $y_min = intval($label);
                         }
                         if (!isset($y_max) || intval($label) > $y_max) {
                             $y_max = intval($label);
                         }
                         // y2 value
                     } elseif ($index == $y2_index) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($y2_values, $label);
                         } else {
                             $y_values[] = $label;
                         }
                         if (!isset($y_min) || intval($label) < $y_min) {
                             $y_min = intval($label);
                         }
                         if (!isset($y_max) || intval($label) > $y_max) {
                             $y_max = intval($label);
                         }
                         // y3 value
                     } elseif ($index == $y3_index) {
                         if ($table['with_zoom'] == 'T') {
                             array_unshift($y3_values, $label);
                         } else {
                             $y_values[] = $label;
                         }
                         if (!isset($y_min) || intval($label) < $y_min) {
                             $y_min = intval($label);
                         }
                         if (!isset($y_max) || intval($label) > $y_max) {
                             $y_max = intval($label);
                         }
                         // we won't process the rest
                         break;
                     }
                     // next column
                     $index++;
                 }
             }
             // y minimum
             if ($y_min > 0) {
                 $y_min = 0;
             }
             // y maximum
             $y_max = strval($y_max);
             if (strlen($y_max) == 1) {
                 $y_max = 10;
             } elseif (strlen($y_max) == 2) {
                 $y_max = (intval(substr($y_max, 0, 1)) + 1) * 10;
             } elseif (strlen($y_max) == 3) {
                 $y_max = (intval(substr($y_max, 0, 2)) + 1) * 10;
             } else {
                 $y_max = strval(intval(substr($y_max, 0, 2)) + 1) . substr('0000000000000000000000000000000000000000000000000000', 0, strlen($y_max) - 2);
             }
             // data series
             $elements = array();
             if (count($y_values)) {
                 $elements[] = '{ "type":"bar_glass", "colour":"#BF3B69", "values": [ ' . join(',', $y_values) . ' ], "text": ' . $y_title . ', "font-size": 12 }';
             }
             if (count($y2_values)) {
                 $elements[] = '{ "type": "line", "width": 1, "colour": "#5E4725", "values": [ ' . join(',', $y2_values) . ' ], "text": ' . $y2_title . ', "font-size": 12 }';
             }
             if (count($y3_values)) {
                 $elements[] = '{ "type":"bar_glass", "colour":"#5E0722", "values": [ ' . join(',', $y3_values) . ' ], "text": ' . $y3_title . ', "font-size": 12 }';
             }
             // the full setup
             $text = '{ "elements": [ ' . join(',', $elements) . ' ], "x_axis": { "offset": false, "steps": 1, "labels": { "steps": 3, "rotate": 310, "labels": [ ' . join(',', $x_labels) . ' ] } }, "y_axis": { "min": ' . $y_min . ', "max": ' . $y_max . ' } }';
             return $text;
             // first number
         // first number
         case 'column':
             // comma separated values
             $separator = ",";
             // process every table row
             while ($row = SQL::fetch($rows)) {
                 // not always the first column
                 $index = 0;
                 foreach ($row as $name => $value) {
                     $index++;
                     // skip dates and links
                     if ($index == 1 && $table['with_zoom'] != 'N') {
                         continue;
                     }
                     // glue cells
                     if ($text) {
                         $text .= $separator;
                     }
                     // clean spaces
                     $label = trim(preg_replace('/\\s/', ' ', $value));
                     // encode in iso8859
                     $label = utf8::to_iso8859($label);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // quote data
                     if (preg_match('/[^a-zA-Z0-9\\,\\.\\-_]/', $label)) {
                         $text .= '"' . $label . '"';
                     } else {
                         $text .= $label;
                     }
                     // only first column
                     break;
                 }
             }
             return $text;
             // produce a raw table
         // produce a raw table
         case 'raw':
             // comma separated values
             $separator = ",";
             // process every table row
             while ($row = SQL::fetch($rows)) {
                 // one cell at a time
                 $index = 0;
                 foreach ($row as $name => $value) {
                     // glue cells
                     if ($index++) {
                         $text .= $separator;
                     }
                     // clean spaces
                     $label = trim(preg_replace('/\\s/', ' ', $value));
                     // encode in iso8859
                     $label = utf8::to_iso8859($label);
                     // escape quotes to preserve them in the data
                     $label = str_replace('"', '""', $label);
                     // make a link if this is a reference
                     if ($index == 0 && $table['with_zoom'] == 'Y') {
                         $label = $context['url_to_home'] . $context['url_to_root'] . $label;
                     }
                     // quote data
                     if (preg_match('/[^a-zA-Z0-9\\-_]/', $label)) {
                         $text .= '"' . $label . '"';
                     } else {
                         $text .= $label;
                     }
                 }
                 // new line
                 $text .= "\n";
             }
             return $text;
             // a simple table
         // a simple table
         case 'simple':
             $text .= Skin::table_prefix('table');
             // columns headers
             $index = 0;
             while ($field = SQL::fetch_field($rows)) {
                 $cells[] = ucfirst($field->name);
             }
             $text .= Skin::table_row($cells, 'header');
             // other rows
             while ($row = SQL::fetch_row($rows)) {
                 $text .= Skin::table_row($row, $count++);
             }
             $text .= Skin::table_suffix();
             return $text;
             // xml table
         // xml table
         case 'xml':
             $text = '';
             while ($row = SQL::fetch($rows)) {
                 $text .= '	<item>' . "\n";
                 foreach ($row as $name => $value) {
                     $type = preg_replace('/[^a-z0-9]+/i', '_', $name);
                     if (preg_match('/^[^a-z]/i', $type)) {
                         $type = '_' . $type;
                     }
                     $text .= '		<' . $type . '>' . preg_replace('/&(?!(amp|#\\d+);)/i', '&amp;', utf8::transcode(str_replace(array('left=', 'right='), '', $value))) . '</' . $type . '>' . "\n";
                 }
                 $text .= '	</item>' . "\n\n";
             }
             return '<?xml version="1.0" encoding="' . $context['charset'] . '"?>' . "\n" . '<items>' . "\n" . $text . '</items>' . "\n";
     }
 }
Ejemplo n.º 20
0
Archivo: review.php Proyecto: rair/yacs
}
// list future articles
if (Surfer::is_associate() && ($rows =& Articles::list_by('future', 0, 5))) {
    if (is_array($rows)) {
        $rows = Skin::build_list($rows, 'decorated');
    }
    $context['text'] .= Skin::build_box(i18n::s('Future articles'), $rows, 'header1', 'future');
}
// list dead articles
if (Surfer::is_associate() && ($rows =& Articles::list_by('expiry', 0, 10, 'hits'))) {
    if (is_array($rows)) {
        $rows = Skin::build_list($rows, 'decorated');
    }
    $context['text'] .= Skin::build_box(i18n::s('Dead articles'), $rows, 'header1', 'expired');
}
// list the oldest published articles, that have to be validated again
if (Surfer::is_associate() && ($rows =& Articles::list_by('review', 0, 10, 'review'))) {
    if (is_array($rows)) {
        $rows = Skin::build_list($rows, 'decorated');
    }
    $context['text'] .= Skin::build_box(i18n::s('Oldest articles'), $rows, 'header1', 'oldest');
}
// list articles with very few hits
if (Surfer::is_associate() && ($rows =& Articles::list_by('unread', 0, 10, 'hits'))) {
    if (is_array($rows)) {
        $rows = Skin::build_list($rows, 'decorated');
    }
    $context['text'] .= Skin::build_box(i18n::s('Less read articles'), $rows, 'header1', 'unread');
}
// render the skin
render_skin();
Ejemplo n.º 21
0
Archivo: delete.php Proyecto: rair/yacs
$id = NULL;
if (isset($_REQUEST['id'])) {
    $id = $_REQUEST['id'];
} elseif (isset($context['arguments'][0])) {
    $id = $context['arguments'][0];
}
$id = strip_tags($id);
// get the item from the database
$item = Locations::get($id);
// get the related anchor, if any
$anchor = NULL;
if (isset($item['anchor']) && $item['anchor']) {
    $anchor = Anchors::get($item['anchor']);
}
// associates and authenticated editors can do what they want
if (Surfer::is_associate() || Surfer::is_member() && is_object($anchor) && $anchor->is_assigned()) {
    $permitted = TRUE;
} elseif (is_object($anchor) && !$anchor->is_viewable()) {
    $permitted = FALSE;
} elseif (Surfer::is_member() && !strcmp($item['anchor'], 'user:'******'edit_id']) && Surfer::is($item['edit_id'])) {
    $permitted = TRUE;
} else {
    $permitted = FALSE;
}
// load the skin, mabe with a variant
load_skin('locations', $anchor);
// the path to this page
if (is_object($anchor)) {
    $context['path_bar'] = $anchor->get_path_bar();
Ejemplo n.º 22
0
Archivo: anchor.php Proyecto: rair/yacs
 /**
  * check that the surfer is allowed to display the anchor
  *
  * This function is used to control the authority delegation from the anchor.
  *
  * To be overloaded into derived class if field has a different name
  *
  * @param int optional reference to some user profile
  * @return TRUE or FALSE
  */
 function is_viewable($user_id = NULL)
 {
     global $context;
     // we need some data to proceed
     if (!isset($this->item['id'])) {
         return FALSE;
     }
     // surfer is a trusted host
     if (Surfer::is_trusted()) {
         return TRUE;
     }
     // section is public
     if (isset($this->item['active']) && $this->item['active'] == 'Y') {
         return TRUE;
     }
     // id of requesting user
     if (!$user_id) {
         $user_id = Surfer::get_id();
     }
     // anonymous is allowed
     if (!$user_id) {
         $user_id = 0;
     }
     // section is opened to members
     if ($user_id && isset($this->item['active']) && $this->item['active'] == 'R') {
         return TRUE;
     }
     // anchor has to be assigned
     return $this->is_assigned($user_id) || Surfer::is_associate();
 }
Ejemplo n.º 23
0
 /**
  * list articles as digg do
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $label = i18n::s('No page to display.');
         if (Surfer::is_associate()) {
             $label .= ' ' . sprintf(i18n::s('Use the %s to populate this server.'), Skin::build_link('help/populate.php', i18n::s('Content Assistant'), 'shortcut'));
         }
         $output = '<p>' . $label . '</p>';
         return $output;
     }
     // build a list of articles
     $text = '';
     $item_count = 0;
     include_once $context['path_to_root'] . 'comments/comments.php';
     include_once $context['path_to_root'] . 'links/links.php';
     while ($item = SQL::fetch($result)) {
         // permalink
         $url = Articles::get_permalink($item);
         // get the anchor
         $anchor = Anchors::get($item['anchor']);
         // get the related overlay, if any
         $overlay = Overlay::load($item, 'article:' . $item['id']);
         // next item
         $item_count += 1;
         // section opening
         if ($item_count == 1) {
             $text .= '<div class="newest">' . "\n";
         }
         // reset everything
         $content = $prefix = $label = $suffix = $icon = '';
         // the icon to put aside
         if ($item['thumbnail_url']) {
             $icon = $item['thumbnail_url'];
         } elseif (is_callable(array($anchor, 'get_bullet_url'))) {
             $icon = $anchor->get_bullet_url();
         }
         if ($icon) {
             $icon = '<a href="' . $context['url_to_root'] . $url . '"><img src="' . $icon . '" class="right_image" alt="' . encode_field(i18n::s('View the page')) . '" title="' . encode_field(i18n::s('View the page')) . '" /></a>';
         }
         // signal restricted and private articles
         if ($item['active'] == 'N') {
             $prefix .= PRIVATE_FLAG;
         } elseif ($item['active'] == 'R') {
             $prefix .= RESTRICTED_FLAG;
         }
         // flag articles updated recently
         if ($item['create_date'] >= $context['fresh']) {
             $suffix .= ' ' . NEW_FLAG;
         } elseif ($item['edit_date'] >= $context['fresh']) {
             $suffix .= ' ' . UPDATED_FLAG;
         }
         // add details
         $details = array();
         // the author
         if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') {
             if ($item['edit_name'] == $item['create_name']) {
                 $details[] = sprintf(i18n::s('by %s'), ucfirst($item['create_name']));
             } else {
                 $details[] = sprintf(i18n::s('by %s, %s'), ucfirst($item['create_name']), ucfirst($item['edit_name']));
             }
         }
         // the publish date
         $details[] = Skin::build_date($item['publish_date']);
         // rating
         $rating_label = '';
         if ($item['rating_count']) {
             $rating_label = Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])) . ' ' . sprintf(i18n::ns('%d rating', '%d ratings', $item['rating_count']), $item['rating_count']) . ' ';
         }
         // add a link to let surfer rate this item
         if (is_object($anchor) && !$anchor->has_option('without_rating')) {
             if (!$item['rating_count']) {
                 $rating_label .= i18n::s('Rate this page');
             }
             $rating_label = Skin::build_link(Articles::get_url($item['id'], 'like'), $rating_label, 'basic', i18n::s('Rate this page'));
         }
         // display current rating, and allow for rating
         $details[] = $rating_label;
         // details
         if (count($details)) {
             $content .= '<p class="details">' . ucfirst(implode(', ', $details)) . '</p>';
         }
         // the full introductory text
         if ($item['introduction']) {
             $content .= Codes::beautify($item['introduction'], $item['options']);
         } elseif (!is_object($overlay)) {
             include_once $context['path_to_root'] . 'articles/article.php';
             $article = new Article();
             $article->load_by_content($item);
             $content .= $article->get_teaser('teaser');
         }
         // insert overlay data, if any
         if (is_object($overlay)) {
             $content .= $overlay->get_text('list', $item);
         }
         // an array of links
         $menu = array();
         // rate the article
         $menu = array_merge($menu, array(Articles::get_url($item['id'], 'like') => i18n::s('Rate this page')));
         // read the article
         $menu = array_merge($menu, array($url => i18n::s('Read more')));
         // info on related files
         if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) {
             $details[] = Skin::build_link($url . '#_attachments', sprintf(i18n::ns('%d file', '%d files', $count), $count), 'basic');
         }
         // info on related comments
         if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) {
             $link = Comments::get_url('article:' . $item['id'], 'list');
             $menu = array_merge($menu, array($link => sprintf(i18n::ns('%d comment', '%d comments', $count), $count)));
         }
         // discuss
         if (Comments::allow_creation($item, $anchor)) {
             $menu = array_merge($menu, array(Comments::get_url('article:' . $item['id'], 'comment') => i18n::s('Discuss')));
         }
         // info on related links
         if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) {
             $menu = array_merge($menu, array($url . '#_attachments' => sprintf(i18n::ns('%d link', '%d links', $count), $count)));
         }
         // trackback
         if (Links::allow_trackback()) {
             $menu = array_merge($menu, array('links/trackback.php?anchor=' . urlencode('article:' . $item['id']) => i18n::s('Reference this page')));
         }
         // link to the anchor page
         if (is_object($anchor)) {
             $menu = array_merge($menu, array($anchor->get_url() => $anchor->get_title()));
         }
         // list up to three categories by title, if any
         if ($items = Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 3, 'raw')) {
             foreach ($items as $id => $attributes) {
                 $menu = array_merge($menu, array(Categories::get_permalink($attributes) => $attributes['title']));
             }
         }
         // append a menu
         $content .= Skin::build_list($menu, 'menu_bar');
         // insert a complete box
         $text .= Skin::build_box($icon . $prefix . Codes::beautify_title($item['title']) . $suffix, $content, 'header1', 'article_' . $item['id']);
         // section closing
         if ($item_count == 1) {
             $text .= '</div>' . "\n";
         }
     }
     // end of processing
     SQL::free($result);
     // add links to archives
     $anchor = Categories::get(i18n::c('monthly'));
     if (isset($anchor['id']) && ($items = Categories::list_by_date_for_anchor('category:' . $anchor['id'], 0, COMPACT_LIST_SIZE, 'compact'))) {
         $text .= Skin::build_box(i18n::s('Previous pages'), Skin::build_list($items, 'menu_bar'));
     }
     return $text;
 }
Ejemplo n.º 24
0
}
// the title of the page
$context['page_title'] = i18n::s('Use an image');
// stop crawlers
if (Surfer::is_crawler()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // not found
} elseif (!isset($item['id'])) {
    Safe::header('Status: 404 Not Found', TRUE, 404);
    Logger::error(i18n::s('No item has been found.'));
    // no anchor
} elseif (!is_object($anchor)) {
    Safe::header('Status: 404 Not Found', TRUE, 404);
    Logger::error(i18n::s('No anchor has been found.'));
    // operation is restricted to associates and editors
} elseif (!Surfer::is_associate() && !$anchor->is_assigned()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // set this image as the anchor icon
} else {
    // back to the anchor page if no error
    if (!($error = $anchor->touch('image:set_as_icon', $id))) {
        Safe::redirect($context['url_to_home'] . $context['url_to_root'] . $anchor->get_url());
    }
    Logger::error($error);
}
// failed operation
$context['text'] .= '<p>' . i18n::s('Operation has failed.') . '</p>';
// render the skin
render_skin();
Ejemplo n.º 25
0
Archivo: upload.php Proyecto: rair/yacs
$id = NULL;
$name = NULL;
// load the skin
load_skin('skins');
// the path to this page
$context['path_bar'] = array('skins/' => i18n::s('Themes'));
// the title of the page
$context['page_title'] = i18n::s('Upload a theme');
// stop crawlers
if (Surfer::is_crawler()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // anonymous users are invited to log in or to register
} elseif (!Surfer::is_logged()) {
    Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode('skins/upload.php'));
} elseif (!Surfer::is_associate()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // process uploaded data
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    // nothing has been uploaded
    if (!$_FILES['upload']['name'] || $_FILES['upload']['name'] == 'none') {
        Logger::error(i18n::s('Nothing has been received.'));
    } else {
        // access the temporary uploaded file
        $id = $_FILES['upload']['tmp_name'];
        $name = $_FILES['upload']['name'];
        // zero bytes transmitted
        $_REQUEST['file_size'] = $_FILES['upload']['size'];
        if (!$_FILES['upload']['size']) {
            Logger::error(i18n::s('Nothing has been received.'));
Ejemplo n.º 26
0
 /**
  * check if new locations can be added
  *
  * This function returns TRUE if locations can be added to some place,
  * and FALSE otherwise.
  *
  * @param object an instance of the Anchor interface, if any
  * @param array a set of item attributes, if any
  * @param string the type of item, e.g., 'section'
  * @return boolean TRUE or FALSE
  */
 public static function allow_creation($item = NULL, $anchor = NULL, $variant = NULL)
 {
     global $context;
     // backward compatibility, reverse parameters :
     // $anchor is always a object and $item a array
     if (is_object($item) || is_array($anchor)) {
         $permute = $anchor;
         $anchor = $item;
         $item = $permute;
     }
     // guess the variant
     if (!$variant) {
         // most frequent case
         if (isset($item['id'])) {
             $variant = 'article';
         } elseif (is_object($anchor)) {
             $variant = $anchor->get_type();
         } else {
             return FALSE;
         }
     }
     // only in articles
     if ($variant == 'article') {
         // 'no_links' option
         if (Articles::has_option('no_locations', $anchor, $item)) {
             return FALSE;
         }
         // other containers
     } else {
         // locations have to be activated explicitly
         if (isset($item['options']) && is_string($item['options']) && preg_match('/\\bwith_locations\\b/i', $item['options'])) {
         } elseif (is_object($anchor) && $anchor->has_option('with_locations')) {
         } else {
             return FALSE;
         }
     }
     // surfer is an associate
     if (Surfer::is_associate()) {
         return TRUE;
     }
     // submissions have been disallowed
     if (isset($context['users_without_submission']) && $context['users_without_submission'] == 'Y') {
         return FALSE;
     }
     // only in articles
     if ($variant == 'article') {
         // surfer owns this item, or the anchor
         if (Articles::is_owned($item, $anchor)) {
             return TRUE;
         }
         // surfer is an editor, and the page is not private
         if (isset($item['active']) && $item['active'] != 'N' && Articles::is_assigned($item['id'])) {
             return TRUE;
         }
         // only in sections
     } elseif ($variant == 'section') {
         // surfer owns this item, or the anchor
         if (Sections::is_owned($item, $anchor, TRUE)) {
             return TRUE;
         }
     }
     // surfer is an editor, and container is not private
     if (isset($item['active']) && $item['active'] != 'N' && is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     if (!isset($item['id']) && is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
         return TRUE;
     }
     // item has been locked
     if (isset($item['locked']) && $item['locked'] == 'Y') {
         return FALSE;
     }
     // anchor has been locked --only used when there is no item provided
     if (!isset($item['id']) && is_object($anchor) && $anchor->has_option('locked')) {
         return FALSE;
     }
     // surfer is an editor (and item has not been locked)
     if ($variant == 'article' && isset($item['id']) && Articles::is_assigned($item['id'])) {
         return TRUE;
     }
     if ($variant == 'section' && isset($item['id']) && Sections::is_assigned($item['id'])) {
         return TRUE;
     }
     if (is_object($anchor) && $anchor->is_assigned()) {
         return TRUE;
     }
     // container is hidden
     if (isset($item['active']) && $item['active'] == 'N') {
         return FALSE;
     }
     if (is_object($anchor) && $anchor->is_hidden()) {
         return FALSE;
     }
     // surfer is a member
     if (Surfer::is_member()) {
         return TRUE;
     }
     // container is restricted
     if (isset($item['active']) && $item['active'] == 'R') {
         return FALSE;
     }
     if (is_object($anchor) && !$anchor->is_public()) {
         return FALSE;
     }
     // authenticated members and subscribers are allowed to add locations
     if (Surfer::is_logged()) {
         return TRUE;
     }
     // anonymous contributions are allowed for articles
     if ($variant == 'article') {
         if (isset($item['options']) && preg_match('/\\banonymous_edit\\b/i', $item['options'])) {
             return TRUE;
         }
         if (is_object($anchor) && $anchor->has_option('anonymous_edit')) {
             return TRUE;
         }
     }
     // the default is to not allow for new locations
     return FALSE;
 }
Ejemplo n.º 27
0
 /**
  * main function to render layout
  * 
  * @param type $result MySQL object
  * @return string the rendering
  */
 public function layout($result)
 {
     global $context;
     // we return some text
     $text = '';
     // type of listed object
     $items_type = $this->listed_type;
     // this level root reference
     if (isset($this->focus) && $this->focus) {
         $root_ref = $this->focus;
     } elseif (isset($context['current_item']) && $context['current_item']) {
         $root_ref = $context['current_item'];
     } else {
         $root_ref = $items_type . ':index';
     }
     $this->tree_only = $this->has_variant('tree_only');
     // drag&drop zone
     $text .= '<div class="tm-ddz tm-drop" data-ref="' . $root_ref . '" data-variant="' . $this->layout_variant . '" >' . "\n";
     // root create command
     $text .= $this->btn_create();
     // root ul
     $text .= '<ul class="tm-sub_elems tm-root">' . "\n";
     while ($item = SQL::fetch($result)) {
         // get the object interface, this may load parent and overlay
         $entity = new $items_type($item);
         // title
         $title = '<a class="tm-zoom" href="' . $entity->get_permalink() . '"><span class="tm-folder">' . $entity->get_title() . '</span></a>';
         // sub elements of this entity
         $sub = $this->get_sub_level($entity);
         // command related to this entity
         $cmd = $this->get_interactive_menu();
         // one <li> per entity of this level of the tree
         $text .= '<li class="tm-drag tm-drop" data-ref="' . $entity->get_reference() . '">' . $title . $cmd . $sub . '</li>' . "\n";
     }
     // this level may have childs that are not folders (exept index)
     // do not search in variant tree_only is setted
     if (!preg_match('/index$/', $root_ref) && !$this->tree_only) {
         $thislevel = Anchors::get($root_ref);
         $text .= $this->get_sub_level($thislevel, true);
         // do not search for folders
     }
     // we have bound styles and scripts, but do not provide on ajax requests
     if (!isset($context['AJAX_REQUEST']) || !$context['AJAX_REQUEST']) {
         $this->load_scripts_n_styles();
         // init js depending on user privilege for this level
         if (isset($thislevel)) {
             // get surfer privilege for this level
             $powered = $thislevel->allows('creation');
         } else {
             $powered = Surfer::is_associate();
         }
         $powered = $powered ? 'powered' : '';
         // cast to string
         Page::insert_script('TreeManager.init("' . $powered . '");');
     }
     // end drag drop zone
     $text .= '</ul></div>' . "\n";
     // end of processing
     SQL::free($result);
     return $text;
 }
Ejemplo n.º 28
0
Archivo: review.php Proyecto: rair/yacs
    $context['text'] .= Skin::build_block(i18n::s('Most recent members'), 'title');
    if (is_array($rows)) {
        $context['text'] .= Skin::build_list($rows, 'decorated');
    } else {
        $context['text'] .= $rows;
    }
}
// oldest posts, but only to associates
if (Surfer::is_associate() && ($rows = Users::list_by_post_date())) {
    $context['text'] .= Skin::build_block(i18n::s('Oldest posts'), 'title');
    $context['text'] .= '<p>' . i18n::s('Users who have never contributed are not listed at all.') . '</p>' . "\n";
    if (is_array($rows)) {
        $context['text'] .= Skin::build_list($rows, 'decorated');
    } else {
        $context['text'] .= $rows;
    }
}
// oldest logins, but only to associates
if (Surfer::is_associate() && ($rows = Users::list_by_login_date())) {
    $context['text'] .= Skin::build_block(i18n::s('Oldest logins'), 'title');
    $context['text'] .= '<p>' . i18n::s('Users who have never been authenticated are not listed at all.') . '</p>' . "\n";
    if (is_array($rows)) {
        $context['text'] .= Skin::build_list($rows, 'decorated');
    } else {
        $context['text'] .= $rows;
    }
}
// the menu bar for this page
$context['page_tools'][] = Skin::build_link('users/', i18n::s('People'));
// render the skin
render_skin();
Ejemplo n.º 29
0
Archivo: select.php Proyecto: rair/yacs
 }
 // build a unlink button for this category
 if (Surfer::is_associate()) {
     $suffix .= BR . '<form method="post" action="' . $context['script_url'] . '"><div>' . '<input type="hidden" name="anchor" value="category:' . $category_id . '" />' . '<input type="hidden" name="member" value="' . encode_field($member) . '" />' . Skin::build_submit_button(i18n::s('Unlink')) . '</div></form>';
 }
 // a button to change the thumbnail of the anchored page
 if ($icon) {
     $suffix .= ' <form method="post" action="' . $context['url_to_root'] . 'categories/set_as_thumbnail.php"><div>' . '<input type="hidden" name="anchor" value="' . encode_field($member) . '" />' . '<input type="hidden" name="id" value="' . $category_id . '" />' . Skin::build_submit_button(i18n::s('Use this thumbnail as the thumbnail of the page')) . '</div></form>';
 }
 // list sub-categories to be linked, if any
 // display active and restricted items
 $where = "categories.active='Y'";
 if (Surfer::is_member()) {
     $where .= " OR categories.active='R'";
 }
 if (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 top level only
 $query = "SELECT categories.id, categories.title " . " FROM " . SQL::table_name('categories') . " AS categories " . " WHERE (" . $where . ") AND (categories.anchor='category:" . $category_id . "')" . " ORDER BY categories.title";
 $result = SQL::query($query);
 $sub_categories = array();
 while ($result && ($option = SQL::fetch($result))) {
     $sub_categories['category:' . $option['id']] = $option['title'];
 }
 if (count($sub_categories)) {
     $suffix .= '<form method="post" action="' . $context['script_url'] . '"><div>' . i18n::s('More specific:') . ' <select name="anchor">';
     foreach ($sub_categories as $option_reference => $option_label) {
         $suffix .= '<option value="' . $option_reference . '">' . $option_label . "</option>\n";
Ejemplo n.º 30
0
 /**
  * change only some attributes
  *
  * @param array an array of fields
  * @return TRUE on success, or FALSE on error
  **/
 public static function put_attributes(&$fields)
 {
     global $context;
     // id cannot be empty
     if (!isset($fields['id']) || !is_numeric($fields['id'])) {
         Logger::error(i18n::s('No item has the provided id.'));
         return FALSE;
     }
     // set default values for this editor
     Surfer::check_default_editor($fields);
     // quey components
     $query = array();
     // change access rights
     if (isset($fields['active_set'])) {
         // cascade anchor access rights
         if (isset($fields['anchor']) && ($anchor = Anchors::get($fields['anchor']))) {
             $fields['active'] = $anchor->ceil_rights($fields['active_set']);
         } else {
             $fields['active'] = $fields['active_set'];
         }
         // remember these in this record
         $query[] = "active='" . SQL::escape($fields['active']) . "'";
         $query[] = "active_set='" . SQL::escape($fields['active_set']) . "'";
         // cascade anchor access rights
         Anchors::cascade('section:' . $fields['id'], $fields['active']);
     }
     // other fields
     if (isset($fields['anchor'])) {
         $query[] = "anchor='" . SQL::escape($fields['anchor']) . "'";
     }
     if (isset($fields['articles_canvas'])) {
         $query[] = "articles_canvas='" . SQL::escape($fields['articles_canvas']) . "'";
     }
     if (isset($fields['articles_layout'])) {
         $query[] = "articles_layout='" . SQL::escape($fields['articles_layout']) . "'";
     }
     if (isset($fields['articles_templates'])) {
         $query[] = "articles_templates='" . SQL::escape($fields['articles_templates']) . "'";
     }
     if (isset($fields['behaviors'])) {
         $query[] = "behaviors='" . SQL::escape($fields['behaviors']) . "'";
     }
     if (isset($fields['content_overlay'])) {
         $query[] = "content_overlay='" . SQL::escape($fields['content_overlay']) . "'";
     }
     if (isset($fields['content_options'])) {
         $query[] = "content_options='" . SQL::escape($fields['content_options']) . "'";
     }
     if (isset($fields['description'])) {
         $query[] = "description='" . SQL::escape($fields['description']) . "'";
     }
     if (isset($fields['extra'])) {
         $query[] = "extra='" . SQL::escape($fields['extra']) . "'";
     }
     if (isset($fields['file_overlay'])) {
         $query[] = "file_overlay='" . SQL::escape($fields['file_overlay']) . "'";
     }
     if (isset($fields['handle']) && $fields['handle']) {
         $query[] = "handle='" . SQL::escape($fields['handle']) . "'";
     }
     if (isset($fields['icon_url'])) {
         $query[] = "icon_url='" . SQL::escape(preg_replace('/[^\\w\\/\\.,:%&\\?=-]+/', '_', $fields['icon_url'])) . "'";
     }
     if (isset($fields['home_panel'])) {
         $query[] = "home_panel='" . SQL::escape($fields['home_panel']) . "'";
     }
     if (isset($fields['index_map'])) {
         $query[] = "index_map='" . SQL::escape($fields['index_map']) . "'";
     }
     if (isset($fields['introduction'])) {
         $query[] = "introduction='" . SQL::escape($fields['introduction']) . "'";
     }
     if (isset($fields['index_title'])) {
         $query[] = "index_title='" . SQL::escape($fields['index_title']) . "'";
     }
     if (isset($fields['language'])) {
         $query[] = "language='" . SQL::escape($fields['language']) . "'";
     }
     if (isset($fields['locked'])) {
         $query[] = "locked='" . SQL::escape($fields['locked']) . "'";
     }
     if (isset($fields['maximum_items'])) {
         $query[] = "maximum_items='" . SQL::escape($fields['maximum_items']) . "'";
     }
     if (isset($fields['meta'])) {
         $query[] = "meta='" . SQL::escape($fields['meta']) . "'";
     }
     if (isset($fields['nick_name'])) {
         $query[] = "nick_name='" . SQL::escape($fields['nick_name']) . "'";
     }
     if (isset($fields['options'])) {
         $query[] = "options='" . SQL::escape($fields['options']) . "'";
     }
     if (isset($fields['overlay'])) {
         $query[] = "overlay='" . SQL::escape($fields['overlay']) . "'";
     }
     if (isset($fields['overlay_id'])) {
         $query[] = "overlay_id='" . SQL::escape($fields['overlay_id']) . "'";
     }
     if (isset($fields['owner_id'])) {
         $query[] = "owner_id=" . SQL::escape($fields['owner_id']);
     }
     if (isset($fields['prefix']) && Surfer::is_associate()) {
         $query[] = "prefix='" . SQL::escape($fields['prefix']) . "'";
     }
     if (isset($fields['rank'])) {
         $query[] = "rank='" . SQL::escape($fields['rank']) . "'";
     }
     if (isset($fields['sections_layout'])) {
         $query[] = "sections_layout='" . SQL::escape($fields['sections_layout']) . "'";
     }
     if (isset($fields['suffix']) && Surfer::is_associate()) {
         $query[] = "suffix='" . SQL::escape($fields['suffix']) . "'";
     }
     if (isset($fields['tags'])) {
         $query[] = "tags='" . SQL::escape($fields['tags']) . "'";
     }
     if (isset($fields['thumbnail_url'])) {
         $query[] = "thumbnail_url='" . SQL::escape(preg_replace('/[^\\w\\/\\.,:%&\\?=-]+/', '_', $fields['thumbnail_url'])) . "'";
     }
     if (isset($fields['title'])) {
         $fields['title'] = strip_tags($fields['title'], '<br>');
         $query[] = "title='" . SQL::escape($fields['title']) . "'";
     }
     if (isset($fields['trailer'])) {
         $query[] = "trailer='" . SQL::escape($fields['trailer']) . "'";
     }
     // nothing to update
     if (!count($query)) {
         return TRUE;
     }
     // maybe a silent update
     if (!isset($fields['silent']) || $fields['silent'] != 'Y') {
         $query[] = "edit_name='" . SQL::escape($fields['edit_name']) . "'";
         $query[] = "edit_id=" . SQL::escape($fields['edit_id']);
         $query[] = "edit_address='" . SQL::escape($fields['edit_address']) . "'";
         $query[] = "edit_action='article:update'";
         $query[] = "edit_date='" . SQL::escape($fields['edit_date']) . "'";
     }
     // actual update query
     $query = "UPDATE " . SQL::table_name('sections') . " SET " . implode(', ', $query) . " WHERE id = " . SQL::escape($fields['id']);
     if (!SQL::query($query)) {
         return FALSE;
     }
     // clear the cache
     Sections::clear($fields);
     // end of job
     return TRUE;
 }