/** * list users * * @param resource the SQL result * @return array of ($nick_name => $more) * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($nick_name => $more) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list while ($item = SQL::fetch($result)) { // unique identifier $key = $item['nick_name']; // use the full name, if nick name is not part of it $more = ''; if ($item['full_name'] && !preg_match('/\\b' . preg_quote($item['nick_name'], '/') . '\\b/', $item['full_name'])) { $more = ucfirst($item['full_name']) . ' '; } // else use e-mail address, if any --but only to authenticated surfer if ($item['email'] && Surfer::is_logged()) { if ($more) { $more .= '<' . $item['email'] . '>'; } else { $more .= $item['email']; } } elseif ($item['introduction']) { $more .= $item['introduction']; } // record this item $items[$key] = $more; } // end of processing SQL::free($result); return $items; }
/** * 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; }
public function get_comment_notification($item) { global $context; // build a tease notification for simple members // sanity check if (!isset($item['anchor']) || !($anchor = Anchors::get($item['anchor']))) { throw new Exception('no anchor for this comment'); } // headline $headline = sprintf(i18n::c('%s has replied'), Surfer::get_link()); $content = BR; // shape these $tease = Skin::build_mail_content($headline, $content); // a set of links $menu = array(); // call for action $link = $context['url_to_home'] . $context['url_to_root'] . Comments::get_url($item['id'], 'view'); $menu[] = Skin::build_mail_button($link, i18n::c('View the reply'), TRUE); // link to the container $menu[] = Skin::build_mail_button($anchor->get_url(), $anchor->get_title(), FALSE); // finalize links $tease .= Skin::build_mail_menu($menu); // assemble all parts of the mail $mail = array(); $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Reply in the discussion'), strip_tags($anchor->get_title())); $mail['notification'] = Comments::build_notification($item); // full notification $mail['tease'] = Mailer::build_notification($tease, 1); return $mail; }
/** * list servers * * @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)) { $output = array(); return $output; } // we return an array of ($url => $attributes) $items = array(); // process all items in the list while ($item = SQL::fetch($result)) { // initialize variables $prefix = $suffix = $icon = ''; // the url to view this item $url = Servers::get_url($item['id']); // use the title as a label $label = Skin::strip($item['title'], 10); // flag files uploaded recently if ($item['edit_date'] >= $context['fresh']) { $prefix = NEW_FLAG . $prefix; } // description if ($item['description']) { $suffix .= ' ' . ucfirst(trim($item['description'])); } // the menu bar for associates and poster if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) { $menu = array(Servers::get_url($item['id'], 'edit') => i18n::s('Edit'), Servers::get_url($item['id'], 'delete') => i18n::s('Delete')); $suffix .= ' ' . Skin::build_list($menu, 'menu'); } // add a separator if ($suffix) { $suffix = ' - ' . $suffix; } // append details to the suffix $suffix .= BR . '<span class="details">'; // details $details = array(); // item poster if ($item['edit_name']) { $details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } // the edition date $details[] = Skin::build_date($item['edit_date']); // all details if (count($details)) { $suffix .= ucfirst(implode(', ', $details)) . "\n"; } // end of details $suffix .= '</span>'; // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'server', $icon); } // end of processing SQL::free($result); return $items; }
/** * list comments as successive notes in a thread * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // we return formatted text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // build a list of comments while ($item = SQL::fetch($result)) { // automatic notification if ($item['type'] == 'notification') { $text = '<dd class="thread_other" style="font-style: italic;">' . ucfirst(trim($item['description'])) . '</dd>' . $text; } else { // link to user profile -- open links in separate window to enable side browsing of participant profiles if ($item['create_id']) { if ($user = Users::get($item['create_id']) && $user['full_name']) { $hover = $user['full_name']; } else { $hover = NULL; } $author = Users::get_link($item['create_name'], $item['create_address'], $item['create_id'], TRUE, $hover); } else { $author = Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id'], TRUE); } // differentiate my posts from others if (Surfer::get_id() && $item['create_id'] == Surfer::get_id()) { $style = ' class="thread_me"'; } else { $style = ' class="thread_other"'; } // a clickable label $stamp = '#'; // flag old items on same day if (!strncmp($item['edit_date'], gmstrftime('%Y-%m-%d %H:%M:%S', time()), 10)) { $stamp = Skin::build_time($item['edit_date']); } else { $stamp = Skin::build_date($item['edit_date']); } // append this at the end of the comment $stamp = ' <div style="float: right; font-size: x-small">' . Skin::build_link(Comments::get_url($item['id']), $stamp, 'basic', i18n::s('Edit')) . '</div>'; // package everything --change order to get oldest first $text = '<dt' . $style . '>' . $author . '</dt><dd' . $style . '>' . $stamp . ucfirst(trim($item['description'])) . '</dd>' . $text; } } // end of processing SQL::free($result); // finalize the returned definition list if ($text) { $text = '<dl>' . $text . '</dl>'; } // process yacs codes $text = Codes::beautify($text); return $text; }
/** * 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; }
/** * get form fields to change the day * * @see overlays/overlay.php * * @param array hosting attributes * @return a list of ($label, $input, $hint) */ function get_fields($host, $field_pos = NULL) { global $context; $options = '<input type="hidden" name="time_stamp" value="12:00" />' . '<input type="hidden" name="duration" value="1440" />'; // default value is now if (!isset($this->attributes['date_stamp']) || $this->attributes['date_stamp'] <= NULL_DATE) { $this->attributes['date_stamp'] = gmstrftime('%Y-%m-%d %H:%M', time() + Surfer::get_gmt_offset() * 3600); } else { $this->attributes['date_stamp'] = Surfer::from_GMT($this->attributes['date_stamp']); } // split date from time list($date, $time) = explode(' ', $this->attributes['date_stamp']); // event time $label = i18n::s('Date'); $input = Skin::build_input_time('date_stamp', $date, 'date') . $options; $hint = i18n::s('Use format YYYY-MM-DD'); $fields[] = array($label, $input, $hint); // ensure that we do have a date Page::insert_script('func' . 'tion validateOnSubmit(container) {' . "\n" . "\n" . ' if(!Yacs.trim(container.date_stamp.value)) {' . "\n" . ' alert("' . i18n::s('Please provide a date.') . '");' . "\n" . ' container.date_stamp.focus();' . "\n" . ' Yacs.stopWorking();' . "\n" . ' return false;' . "\n" . ' }' . "\n\n" . ' return true;' . "\n" . '}' . "\n"); return $fields; }
// the submit button $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . "\n" . Skin::finalize_list($menu, 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '" />' . "\n" . '<input type="hidden" name="confirm" value="yes" />' . "\n" . '</p></form>' . "\n"; // set the focus Page::insert_script('$("#confirmed").focus();'); // the title of the table if (isset($item['title'])) { $context['text'] .= Skin::build_block($item['title'], 'title'); } // display the full text $context['text'] .= Skin::build_block($item['description'], 'description'); // execute the query string to build the table if (isset($item['query']) && $item['query']) { $context['text'] .= Tables::build($item['id'], 'sortable'); } // display the query string, if any if (isset($item['query']) && $item['query']) { $context['text'] .= BR . '<pre>' . $item['query'] . '</pre>' . BR . "\n"; } // details $details = array(); // information on uploader if (Surfer::is_member() && $item['edit_name']) { $details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } // all details if ($details) { $context['text'] .= '<p class="details">' . ucfirst(implode(', ', $details)) . '</p>' . "\n"; } } // render the skin render_skin();
// stop crawlers if (Surfer::is_crawler()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); die(i18n::s('You are not allowed to perform this operation.')); } // page title if (isset($item['title'])) { $context['page_title'] = $item['title']; } // not found if (!$item['id']) { include '../error.php'; // access denied } elseif (!Sections::allow_access($item, $anchor)) { // give anonymous surfers a chance for HTTP authentication if (!Surfer::is_logged()) { Safe::header('WWW-Authenticate: Basic realm="' . utf8::to_iso8859($context['site_name']) . '"'); Safe::header('Status: 401 Unauthorized', TRUE, 401); } // permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // describe the section } else { // compute the url for this section $url = Sections::get_permalink($item); // get a description if ($item['introduction']) { $description = Codes::beautify($item['introduction']); } else { $description = Skin::strip(Codes::beautify($item['description']), 50);
/** * list users * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!($count = SQL::count($result))) { return $text; } // allow for several lists in the same page static $serial; if (isset($serial)) { $serial++; } else { $serial = 1; } // don't blast too many people if ($count > 100) { $checked = ''; } elseif (isset($this->layout_variant) && $this->layout_variant == 'unchecked') { $checked = ''; } else { $checked = ' checked="checked"'; } // div prefix $text .= '<div id="users_as_mail_panel_' . $serial . '">'; // allow to select/deslect multiple rows at once $text .= '<input type="checkbox" class="row_selector" onclick="check_user_as_mail_panel_' . $serial . '(\'div#users_as_mail_panel_' . $serial . '\', this);"' . $checked . ' /> ' . i18n::s('Select all/none') . BR; // process all items in the list $count = 0; while ($item = SQL::fetch($result)) { // we need some address if (!$item['email']) { continue; } // do not write to myself if ($item['id'] == Surfer::get_id()) { continue; } // get the related overlay, if any $overlay = Overlay::load($item, 'user:'******'id']); // column to select the row $text .= '<input type="checkbox" name="selected_users[]" class="row_selector" value="' . encode_field($item['email']) . '"' . $checked . ' />'; // signal restricted and private users if ($item['active'] == 'N') { $text .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $text .= RESTRICTED_FLAG; } // the url to view this item $url = Users::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['full_name']); } // sanity check if (!$title) { $title = $item['nick_name']; } // link to this page $text .= Skin::build_link($url, $title, 'user'); // the introductory text if ($item['introduction']) { $text .= '<span class="tiny"> - ' . Codes::beautify_introduction($item['introduction']) . '</span>'; } // insert overlay data, if any if (is_object($overlay)) { $text .= $overlay->get_text('list', $item); } // display all tags if ($item['tags']) { $text .= ' <span class="tags">' . Skin::build_tags($item['tags'], 'user:'******'id']) . '</span>'; } // append the row $text .= BR; $count++; } // the script used to check all items at once Page::insert_script('function check_user_as_mail_panel_' . $serial . '(scope, handle) {' . "\n" . ' $(scope + " input[type=\'checkbox\'].row_selector").each(' . "\n" . ' function() { $(this).attr("checked", $(handle).is(":checked"));}' . "\n" . ' );' . "\n" . '}' . "\n"); // div suffix $text .= '</div>'; // no valid account has been found if (!$count) { $text = ''; } // end of processing SQL::free($result); return $text; }
$text .= ' ' . Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's'); $text .= BR . '<span class="details">' . i18n::s('Select a .png, .gif or .jpeg image.') . ' (< ' . Skin::build_number($image_maximum_size, i18n::s('bytes')) . ')</span>'; // end of the form $text .= '</div></form>'; // the script used for form handling at the browser Page::insert_script('$("#upload").focus();'); $context['text'] .= Skin::build_content(NULL, i18n::s('Upload an image'), $text); } // use the library // // where images are $path = 'skins/_reference/avatars'; // browse the path to list directories and files if ($dir = Safe::opendir($context['path_to_root'] . $path)) { $text = ''; if (Surfer::may_upload()) { $text .= '<p>' . i18n::s('Click on one image below to make it your new picture.') . '</p>' . "\n"; } // build the lists while (($image = Safe::readdir($dir)) !== FALSE) { // skip some files if ($image[0] == '.') { continue; } if (is_dir($context['path_to_root'] . $path . '/' . $image)) { continue; } // consider only images if (!preg_match('/(\\.gif|\\.jpeg|\\.jpg|\\.png)$/i', $image)) { continue; }
/** * 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; }
} // 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();
// look for the id $id = NULL; if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; } elseif (isset($context['arguments'][0])) { $id = $context['arguments'][0]; } elseif (Surfer::is_logged()) { $id = Surfer::get_id(); } $id = strip_tags($id); // get the item from the database $item = Users::get($id); // associates can do what they want if (Surfer::is_associate()) { $permitted = TRUE; } elseif ($item['active'] == 'R' && Surfer::is_member()) { $permitted = TRUE; } elseif ($item['active'] == 'Y') { $permitted = TRUE; } else { $permitted = FALSE; } // load the skin load_skin('users'); // path to this page $context['path_bar'] = array('users/' => i18n::s('People')); // page title $context['page_title'] = i18n::s('RSS feed'); // not found if (!isset($item['id'])) { include '../error.php';
/** * 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; }
/** * embed an interactive object * * The id designates the target file. * It can also include width and height of the target canvas, as in: '12, 100%, 250px' * * @param string id of the target file * @return string the rendered string **/ public static function render_embed($id) { global $context; // split parameters $attributes = preg_split("/\\s*,\\s*/", $id, 4); $id = $attributes[0]; // get the file if (!($item = Files::get($id))) { $output = '[embed=' . $id . ']'; return $output; } // stream in a separate page if (isset($attributes[1]) && preg_match('/window/i', $attributes[1])) { if (!isset($attributes[2])) { $attributes[2] = i18n::s('Play in a separate window'); } $output = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'stream', $item['file_name']) . '" onclick="window.open(this.href); return false;" class="button"><span>' . $attributes[2] . '</span></a>'; return $output; } // file extension $extension = strtolower(substr($item['file_name'], -3)); // set a default size if (!isset($attributes[1])) { if (!strcmp($extension, 'gan')) { $attributes[1] = '98%'; } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_width'])) { $attributes[1] = $context['skins_freemind_canvas_width']; } else { $attributes[1] = 480; } } if (!isset($attributes[2])) { if (!strcmp($extension, 'gan')) { $attributes[2] = '300px'; } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_height'])) { $attributes[2] = $context['skins_freemind_canvas_height']; } else { $attributes[2] = 360; } } // object attributes $width = $attributes[1]; $height = $attributes[2]; $flashvars = ''; if (isset($attributes[3])) { $flashvars = $attributes[3]; } // rendering depends on file extension switch ($extension) { // stream a video case '3gp': case 'flv': case 'm4v': case 'mov': case 'mp4': // a flash player to stream a flash video $flvplayer_url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/player_flv_maxi.swf'; // file is elsewhere if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); } // pass parameters to the player if ($flashvars) { $flashvars = str_replace('autostart=true', 'autoplay=1', $flashvars) . '&'; } $flashvars .= 'width=' . $width . '&height=' . $height; // if there is a static image for this video, use it if (isset($item['icon_url']) && $item['icon_url']) { $flashvars .= '&startimage=' . urlencode($item['icon_url']); } // if there is a subtitle file for this video, use it if (isset($item['file_name']) && ($srt = 'files/' . str_replace(':', '/', $item['anchor']) . '/' . str_replace('.' . $extension, '.srt', $item['file_name'])) && file_exists($context['path_to_root'] . $srt)) { $flashvars .= '&srt=1&srturl=' . urlencode($context['url_to_home'] . $context['url_to_root'] . $srt); } // if there is a logo file in the skin, use it Skin::define_img_href('FLV_IMG_HREF', 'codes/flvplayer_logo.png', ''); if (FLV_IMG_HREF) { $flashvars .= '&top1=' . urlencode(FLV_IMG_HREF . '|10|10'); } // rely on Flash if (Surfer::has_flash()) { // the full object is built in Javascript --see parameters at http://flv-player.net/players/maxi/documentation/ $output = '<div id="flv_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var flashvars = { flv:"' . $url . '", ' . str_replace(array('&', '='), array('", ', ':"'), $flashvars) . '", autoload:0, margin:1, showiconplay:1, playeralpha:50, iconplaybgalpha:30, showfullscreen:1, showloading:"always", ondoubleclick:"fullscreen" }' . "\n" . 'var params = { allowfullscreen: "true", allowscriptaccess: "always" }' . "\n" . 'var attributes = { id: "file_' . $item['id'] . '", name: "file_' . $item['id'] . '"}' . "\n" . 'swfobject.embedSWF("' . $flvplayer_url . '", "flv_' . $item['id'] . '", "' . $width . '", "' . $height . '", "9", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", flashvars, params);' . "\n"); // native support } else { // <video> is HTML5, <object> is legacy $output = '<video width="' . $width . '" height="' . $height . '" autoplay="" controls="" src="' . $url . '" >' . "\n" . ' <object width="' . $width . '" height="' . $height . '" data="' . $url . '" type="' . Files::get_mime_type($item['file_name']) . '">' . "\n" . ' <param value="' . $url . '" name="movie" />' . "\n" . ' <param value="true" name="allowFullScreen" />' . "\n" . ' <param value="always" name="allowscriptaccess" />' . "\n" . ' <a href="' . $url . '">No video playback capabilities, please download the file</a>' . "\n" . ' </object>' . "\n" . '</video>' . "\n"; } // job done return $output; // a ganttproject timeline // a ganttproject timeline case 'gan': // where the file is $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']); // we actually use a transformed version of the file $cache_id = Cache::hash($path) . '.xml'; // apply the transformation if (!file_exists($context['path_to_root'] . $cache_id) || filemtime($context['path_to_root'] . $cache_id) < filemtime($context['path_to_root'] . $path) || !($text = Safe::file_get_contents($context['path_to_root'] . $cache_id))) { // transform from GanttProject to SIMILE Timeline $text = Files::transform_gan_to_simile($path); // put in cache Safe::file_put_contents($cache_id, $text); } // load the SIMILE Timeline javascript library in shared/global.php $context['javascript']['timeline'] = TRUE; // cache would kill the loading of the library cache::poison(); // 1 week ago $now = gmdate('M d Y H:i:s', time() - 7 * 24 * 60 * 60); // load the right file $output = '<div id="gantt" style="height: ' . $height . '; width: ' . $width . '; border: 1px solid #aaa; font-family: Trebuchet MS, Helvetica, Arial, sans serif; font-size: 8pt"></div>' . "\n"; Page::insert_script('var simile_handle;' . "\n" . 'function onLoad() {' . "\n" . ' var eventSource = new Timeline.DefaultEventSource();' . "\n" . ' var theme = Timeline.ClassicTheme.create();' . "\n" . ' theme.event.bubble.width = 350;' . "\n" . ' theme.event.bubble.height = 300;' . "\n" . ' var bandInfos = [' . "\n" . ' Timeline.createBandInfo({' . "\n" . ' eventSource: eventSource,' . "\n" . ' date: "' . $now . '",' . "\n" . ' width: "80%",' . "\n" . ' intervalUnit: Timeline.DateTime.WEEK,' . "\n" . ' intervalPixels: 200,' . "\n" . ' theme: theme,' . "\n" . ' layout: "original" // original, overview, detailed' . "\n" . ' }),' . "\n" . ' Timeline.createBandInfo({' . "\n" . ' showEventText: false,' . "\n" . ' trackHeight: 0.5,' . "\n" . ' trackGap: 0.2,' . "\n" . ' eventSource: eventSource,' . "\n" . ' date: "' . $now . '",' . "\n" . ' width: "20%",' . "\n" . ' intervalUnit: Timeline.DateTime.MONTH,' . "\n" . ' intervalPixels: 50' . "\n" . ' })' . "\n" . ' ];' . "\n" . ' bandInfos[1].syncWith = 0;' . "\n" . ' bandInfos[1].highlight = true;' . "\n" . ' bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());' . "\n" . ' simile_handle = Timeline.create(document.getElementById("gantt"), bandInfos, Timeline.HORIZONTAL);' . "\n" . ' simile_handle.showLoadingMessage();' . "\n" . ' Timeline.loadXML("' . $context['url_to_home'] . $context['url_to_root'] . $cache_id . '", function(xml, url) { eventSource.loadXML(xml, url); });' . "\n" . ' simile_handle.hideLoadingMessage();' . "\n" . '}' . "\n" . "\n" . 'var resizeTimerID = null;' . "\n" . 'function onResize() {' . "\n" . ' if (resizeTimerID == null) {' . "\n" . ' resizeTimerID = window.setTimeout(function() {' . "\n" . ' resizeTimerID = null;' . "\n" . ' simile_handle.layout();' . "\n" . ' }, 500);' . "\n" . ' }' . "\n" . '}' . "\n" . "\n" . '// observe page major events' . "\n" . '$(document).ready( onLoad);' . "\n" . '$(window).resize(onResize);' . "\n"); // job done return $output; // a Freemind map // a Freemind map case 'mm': // if we have an external reference, use it if (isset($item['file_href']) && $item['file_href']) { $target_href = $item['file_href']; // else redirect to ourself } else { // ensure a valid file name $file_name = utf8::to_ascii($item['file_name']); // where the file is $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']); // map the file on the regular web space $url_prefix = $context['url_to_home'] . $context['url_to_root']; // redirect to the actual file $target_href = $url_prefix . $path; } // allow several viewers to co-exist in the same page static $freemind_viewer_index; if (!isset($freemind_viewer_index)) { $freemind_viewer_index = 1; } else { $freemind_viewer_index++; } // load flash player $url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/visorFreemind.swf'; // variables $flashvars = 'initLoadFile=' . $target_href . '&openUrl=_self'; $output = '<div id="freemind_viewer_' . $freemind_viewer_index . '">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.menu = "false";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "freemind_viewer_' . $freemind_viewer_index . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); // offer to download a copy of the map $menu = array($target_href => i18n::s('Browse this map with Freemind')); // display menu commands below the viewer $output .= Skin::build_list($menu, 'menu_bar'); // job done return $output; // native flash // native flash case 'swf': // where to get the file if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . rawurlencode($item['file_name']); } $output = '<div id="swf_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.allowfullscreen = "true";' . "\n" . 'params.allowscriptaccess = "always";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "swf_' . $item['id'] . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); return $output; // link to file page // link to file page default: // link label $text = Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name'])); // make a link to the target page $url = Files::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text); return $output; } }
/** * list articles * * @param resource the SQL result * @return string * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // sanity check if (!isset($this->focus)) { $this->focus = NULL; } // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; $odd = TRUE; while ($item = SQL::fetch($result)) { // get the related overlay $overlay = Overlay::load($item, 'article:' . $item['id']); // get the anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // build a title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > $context['now']) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // some details $details = array(); // info on related files --optional if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related comments --mandatory if ($count = Comments::count_for_anchor('article:' . $item['id'], FALSE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // info on related links --optional if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // details if (count($details)) { $suffix .= ' <span class="details">(' . ucfirst(implode(', ', $details)) . ')</span>'; } // flag popular pages if ($item['hits'] > 300) { $suffix .= POPULAR_FLAG; } // last contribution if ($item['edit_action']) { $action = Anchors::get_action_label($item['edit_action']) . ' '; } else { $action = i18n::s('edited'); } if ($item['edit_name']) { $suffix .= '<br /><span class="details">' . sprintf(i18n::s('%s by %s %s'), $action, Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])) . '</span>'; } else { $suffix .= '<br /><span class="details">' . $action . ' ' . Skin::build_date($item['edit_date']) . '</span>'; } // flag articles updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item, $this->focus); } // the hovering title if ($item['introduction'] && $context['skins_with_details'] == 'Y') { $hover = strip_tags(Codes::beautify_introduction($item['introduction'])); } else { $hover = i18n::s('View the page'); } // help members to reference this page if (Surfer::is_member()) { $hover .= ' [article=' . $item['id'] . ']'; } // add an image if available if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // format the image if ($icon) { $icon = Skin::build_link($url, '<img src="' . $icon . '" />', 'basic', $hover); } // list all components for this item if ($odd = !$odd) { $class = ' class="odd"'; } else { $class = ' class="even"'; } // use a table to layout the image properly if ($icon) { $text .= '<div' . $class . '><table class="decorated"><tr><td class="image" style="text-align: center">' . $icon . '</td><td class="content">' . $prefix . Skin::build_link($url, Skin::strip($title, 30), 'basic', $hover) . $suffix . '</td></tr></table></div>'; } else { $text .= '<div' . $class . '>' . $prefix . Skin::build_link($url, Skin::strip($title, 30), 'basic', $hover) . $suffix . '</div>'; } } // end of processing SQL::free($result); return $text; }
/** * list sections as topics in a forum * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // empty list if (!SQL::count($result)) { $output = array(); return $output; } // layout in a table $text = Skin::table_prefix('wide'); // 'even' is used for title rows, 'odd' for detail rows $class_title = 'odd'; $class_detail = 'even'; // build a list of sections $family = ''; include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // change the family if ($item['family'] != $family) { $family = $item['family']; // show the family $text .= Skin::table_suffix() . '<h2><span>' . $family . ' </span></h2>' . "\n" . Skin::table_prefix('wide'); } // get the related overlay, if any $overlay = Overlay::load($item, 'section:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // reset everything $prefix = $label = $suffix = $icon = ''; // signal restricted and private sections if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // indicate the id in the hovering popup $hover = i18n::s('View the section'); if (Surfer::is_member()) { $hover .= ' [section=' . $item['id'] . ']'; } // the url to view this item $url = Sections::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // use the title as a link to the page $title =& Skin::build_link($url, $title, 'basic', $hover); // flag sections updated recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $suffix = EXPIRED_FLAG . ' '; } elseif ($item['create_date'] >= $context['fresh']) { $suffix = NEW_FLAG . ' '; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix = UPDATED_FLAG . ' '; } // this is another row of the output $text .= '<tr class="' . $class_title . '"><th>' . $prefix . $title . $suffix . '</th><th>' . i18n::s('Poster') . '</th><th>' . i18n::s('Messages') . '</th><th>' . i18n::s('Last active') . '</th></tr>' . "\n"; $count = 1; // get last posts for this board --avoid sticky pages if (preg_match('/\\barticles_by_([a-z_]+)\\b/i', $item['options'], $matches)) { $order = $matches[1]; } else { $order = 'edition'; } if ($articles =& Articles::list_for_anchor_by($order, 'section:' . $item['id'], 0, 5, 'raw', TRUE)) { foreach ($articles as $id => $article) { // get the related overlay, if any $article_overlay = Overlay::load($article, 'article:' . $id); // flag articles updated recently if ($article['expiry_date'] > NULL_DATE && $article['expiry_date'] <= $context['now']) { $flag = EXPIRED_FLAG . ' '; } elseif ($article['create_date'] >= $context['fresh']) { $flag = NEW_FLAG . ' '; } elseif ($article['edit_date'] >= $context['fresh']) { $flag = UPDATED_FLAG . ' '; } else { $flag = ''; } // use the title to label the link if (is_object($article_overlay)) { $title = Codes::beautify_title($article_overlay->get_text('title', $article)); } else { $title = Codes::beautify_title($article['title']); } // title $title = Skin::build_link(Articles::get_permalink($article), $title, 'article'); // poster $poster = Users::get_link($article['create_name'], $article['create_address'], $article['create_id']); // comments $comments = Comments::count_for_anchor('article:' . $article['id']); // last editor $action = ''; if ($article['edit_date']) { // label the action if (isset($article['edit_action'])) { $action = Anchors::get_action_label($article['edit_action']); } else { $action = i18n::s('edited'); } $action = '<span class="details">' . $action . ' ' . Skin::build_date($article['edit_date']) . '</span>'; } // this is another row of the output $text .= '<tr class="' . $class_detail . '"><td>' . $title . $flag . '</td><td>' . $poster . '</td><td style="text-align: center;">' . $comments . '</td><td>' . $action . '</td></tr>' . "\n"; } } // more details $details = array(); // board introduction if ($item['introduction']) { $details[] = Codes::beautify_introduction($item['introduction']); } // indicate the total number of threads here if (($count = Articles::count_for_anchor('section:' . $item['id'])) && $count >= 5) { $details[] = sprintf(i18n::s('%d threads'), $count) . ' »'; } // link to the section index page if ($details) { $details = Skin::build_link(Sections::get_permalink($item), join(' - ', $details), 'basic'); } else { $details = ''; } // add a command for new post $poster = ''; if (Surfer::is_empowered()) { $poster = Skin::build_link('articles/edit.php?anchor=' . urlencode('section:' . $item['id']), i18n::s('Add a page') . ' »', 'basic'); } // insert details in a separate row if ($details || $poster) { $text .= '<tr class="' . $class_detail . '"><td colspan="3">' . $details . '</td><td>' . $poster . '</td></tr>' . "\n"; } // more details $more = array(); // board moderators if ($moderators = Sections::list_editors_by_name($item, 0, 7, 'comma5')) { $more[] = sprintf(i18n::ns('Moderator: %s', 'Moderators: %s', count($moderators)), $moderators); } // children boards if ($children =& Sections::list_by_title_for_anchor('section:' . $item['id'], 0, COMPACT_LIST_SIZE, 'compact')) { $more[] = sprintf(i18n::ns('Child board: %s', 'Child boards: %s', count($children)), Skin::build_list($children, 'comma')); } // as a compact list if (count($more)) { $content = '<ul class="compact">'; foreach ($more as $list_item) { $content .= '<li>' . $list_item . '</li>' . "\n"; } $content .= '</ul>' . "\n"; // insert details in a separate row $text .= '<tr class="' . $class_detail . '"><td colspan="4">' . $content . '</td></tr>' . "\n"; } } // end of processing SQL::free($result); $text .= Skin::table_suffix(); return $text; }
/** * list users * * @param resource the SQL result * @return array of resulting items ($score, $summary), or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of array($score, $summary) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // flag idle users $idle = gmstrftime('%Y-%m-%d %H:%M:%S', time() - 600); // process all items in the list while ($item = SQL::fetch($result)) { // one box at a time $box = ''; // initialize variables $prefix = $suffix = $icon = ''; // the url to view this item $url = Users::get_permalink($item); // flag profiles updated recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // signal locked profiles if ($item['capability'] == '?') { $prefix .= EXPIRED_FLAG; } // item title if ($item['full_name']) { $title = ucfirst(Skin::strip($item['full_name'], 10)); $hover = $item['nick_name']; } else { $title = ucfirst(Skin::strip($item['nick_name'], 10)); $hover = $item['full_name']; } // show contact information if (Surfer::may_contact()) { $suffix .= Users::build_presence($item); } // the introduction if ($item['introduction']) { if (is_callable(array('codes', 'beautify'))) { $suffix .= ' - ' . Codes::beautify($item['introduction']); } else { $suffix .= ' - ' . $item['introduction']; } } // display all tags if ($item['tags']) { $suffix .= ' <span class="tags">' . Skin::build_tags($item['tags'], 'user:'******'id']) . '</span>'; } // details $details = array(); // capability if ($item['capability'] == 'A') { $details[] = i18n::s('Associate'); } elseif ($item['capability'] == 'S') { $details[] = i18n::s('Subscriber'); } else { $details[] = i18n::s('Member'); } // creation date if ($item['create_date']) { $details[] = sprintf(i18n::s('registered %s'), Skin::build_date($item['create_date'])); } // last login if ($this->layout_variant == 'dates') { if (isset($item['login_date']) && $item['login_date'] > NULL_DATE) { $address = ''; if ($item['login_address']) { $address = ' (' . $item['login_address'] . ')'; } $details[] = sprintf(i18n::s('last login %s'), Skin::build_date($item['login_date']) . $address); } else { $details[] = i18n::s('no login'); } } // last post if ($this->layout_variant == 'dates') { if (isset($item['post_date']) && $item['post_date'] > NULL_DATE) { $details[] = sprintf(i18n::s('last post %s'), Skin::build_date($item['post_date'])); } } // posts if (intval($item['posts']) > 1) { $details[] = sprintf(i18n::s('%d posts'), intval($item['posts'])); } if (count($details)) { if ($this->layout_variant == 'full') { $suffix .= ' <span class="details">(' . implode(', ', $details) . ')</span>'; } else { $suffix .= ' <span class="details">' . implode(', ', $details) . '</span>'; } } // flag idle users if (isset($item['click_date']) && $item['click_date'] < $idle) { $class = 'idle user'; } else { $class = 'user'; } // item summary $box .= $prefix . Skin::build_link($url, $title, 'user') . $suffix; // use the avatar, if any if (isset($item['avatar_url']) && isset($context['users_with_avatars']) && $context['users_with_avatars'] == 'Y') { $icon = $item['avatar_url']; } // layout this item if ($icon) { // build the complete HTML element $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($title)) . '" />'; // make it a clickable link $icon = Skin::build_link($url, $icon, 'basic'); $list = array(array($box, $icon)); $items[] = array($item['score'], Skin::finalize_list($list, 'decorated')); // put the item in a division } else { $items[] = array($item['score'], '<div style="margin: 0 0 1em 0">' . $box . '</div>'); } } // end of processing SQL::free($result); return $items; }
/** * 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; }
} // archive the letter $context['text'] .= i18n::s('Archiving the new letter') . BR . "\n"; // save the letter as a published article, but don't use special categories $fields = array(); $fields['anchor'] = $anchor; $fields['title'] = $_REQUEST['letter_title']; $label = $_REQUEST['letter_recipients']; if ($_REQUEST['letter_recipients'] == 'custom' && isset($_REQUEST['mail_to'])) { $label = $_REQUEST['mail_to']; } $fields['introduction'] = sprintf(i18n::c('Sent %s to "%s"'), Skin::build_date(time(), 'full', $context['preferred_language']), $label); $fields['description'] = $_REQUEST['letter_body']; $fields['publish_name'] = Surfer::get_name(); $fields['publish_id'] = Surfer::get_id(); $fields['publish_address'] = Surfer::get_email_address(); $fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S'); $fields['id'] = Articles::post($fields); // from: from configuration files if (isset($context['letter_reply_to']) && $context['letter_reply_to']) { $from = $context['letter_reply_to']; } elseif (isset($context['mail_from']) && $context['mail_from']) { $from = $context['mail_from']; } else { $from = $context['site_name']; } // to: build the list of recipients $recipients = array(); switch ($_REQUEST['letter_recipients']) { case 'all': $recipients = Users::list_by_posts(0, MAXIMUM_RECIPIENTS, 'address');
} $id = strip_tags($id); // get the anchor $anchor = Anchors::get($id); // get the related overlay, if any $overlay = NULL; if (is_object($anchor)) { $fields = array(); $fields['id'] = $anchor->get_value('id'); $fields['overlay'] = $anchor->get_value('overlay'); $overlay = Overlay::load($fields, $anchor->get_reference()); } // load the skin, maybe with a variant load_skin('articles', $anchor); // 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 (!is_object($anchor)) { include '../../error.php'; // permission denied } elseif (!$anchor->is_owned()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // no overlay } elseif (!is_object($overlay) || !is_callable(array($overlay, 'get_start_url'))) { Logger::error(i18n::s('You are not allowed to perform this operation.')); } elseif (count($context['error'])) { } elseif (!($follow_up = $overlay->get_start_url())) { Logger::error(i18n::s('You are not allowed to perform this operation.'));
$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 $context['path_bar'] = Surfer::get_path_bar($anchor); // the title of the page if (isset($item['title']) && $item['title']) { $context['page_title'] = $item['title']; } else { $context['page_title'] = i18n::s('Vote for a poll'); } // no subject if (!isset($item['id'])) { include '../../error.php'; // no overlay } elseif (!is_object($overlay)) { Logger::error(i18n::s('This page has no overlay')); // not a valid poll } elseif (!@count($overlay->attributes['answers'])) { Logger::error(i18n::s('Not a valid poll'));
// 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; }
/** * render a compact list of voted pages * * @param string the anchor (e.g. 'section:123') * @param string layout to use * @return string the rendered text **/ public static function render_voted($anchor = '', $layout = 'simple') { global $context; // we return some text; $text = ''; // number of items to display $count = COMPACT_LIST_SIZE; if (($position = strpos($anchor, ',')) !== FALSE) { $count = (int) trim(substr($anchor, $position + 1)); if (!$count) { $count = COMPACT_LIST_SIZE; } $anchor = trim(substr($anchor, 0, $position)); } // scope is limited to current surfer if ($anchor == 'self' && Surfer::get_id()) { $anchor = 'user:'******'section:') === 0) { // look at this branch of the content tree $anchors = Sections::get_branch_at_anchor($anchor); // query the database and layout that stuff $text =& Articles::list_for_anchor_by('rating', $anchors, 0, $count, $layout); // scope is limited to pages of one surfer } elseif (strpos($anchor, 'user:'******'rating', substr($anchor, 5), 0, $count, $layout); } else { $text =& Articles::list_by('rating', 0, $count, $layout); } // we have an array to format if (is_array($text)) { $text =& Skin::build_list($text, $layout); } // job done return $text; }
$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.'));
$context['text'] .= '<p>' . i18n::s('The server is currently switched on. Pages are provided normally to surfers.') . "</p>\n"; // failure } else { Logger::error(i18n::s('The server has NOT been switched on successfully. Please rename the file parameters/switch.off to parameters/switch.on.')); } // back to the control panel $menu = array('control/' => i18n::s('Control Panel')); $context['text'] .= Skin::build_list($menu, 'menu_bar'); // reset localized strings to reload those who could have changed during the update if (is_callable(array('i18n', 'reset'))) { i18n::reset(); } // switch off } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'off') { // build the new configuration file $content = '<?php' . "\n" . '// This file has been created by the configuration script control/switch.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n" . 'global $context;' . "\n"; if (isset($_REQUEST['switch_target'])) { $content .= '$context[\'switch_target\']=\'' . addcslashes($_REQUEST['switch_target'], "\\'") . "';\n"; } if (isset($_REQUEST['switch_contact'])) { $content .= '$context[\'switch_contact\']=\'' . addcslashes($_REQUEST['switch_contact'], "\\'") . "';\n"; } $content .= '?>' . "\n"; // save switch parameters, if any if (!Safe::file_put_contents('parameters/switch.include.php', $content)) { // not enough rights to write the file Logger::error(sprintf(i18n::s('Impossible to write to %s.'), 'parameters/switch.include.php.')); // allow for a manual update $context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually change the configuration, please copy and paste following lines by yourself in file %s.'), 'parameters/switch.include.php') . "</p>\n"; // display updated parameters $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($content), 'folded');
/** * remember that surfer is enrolled in a meeting * * @param string reference of the target page */ public static function confirm($reference) { global $context; // sanity check if (!$reference) { return; } // ensure that the joiner has been enrolled... if (!($item = enrolments::get_record($reference))) { if (Surfer::get_id()) { // fields to save $query = array(); $query[] = "anchor = '" . $reference . "'"; $query[] = "approved = 'Y'"; $query[] = "edit_date = '" . SQL::escape(gmstrftime('%Y-%m-%d %H:%M:%S')) . "'"; $query[] = "user_id = " . SQL::escape(Surfer::get_id()); $query[] = "user_email = '" . SQL::escape(Surfer::get_email_address()) . "'"; // insert a new record $query = "INSERT INTO " . SQL::table_name('enrolments') . " SET " . implode(', ', $query); SQL::query($query); } // each joiner takes one seat } else { $query = "UPDATE " . SQL::table_name('enrolments') . " SET approved = 'Y' WHERE id = " . SQL::escape($item['id']); SQL::query($query); } }
} // 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";
/** * list articles for search requests * * @param resource the SQL result * @return array of resulting items ($score, $summary), or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of array($score, $summary) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // one box at a time $box = ''; // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // introduction $introduction = ''; if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } else { $introduction = $item['introduction']; } // the introductory text if ($introduction) { $suffix .= ' - ' . Codes::beautify_introduction($introduction); // link to description, if any if ($item['description']) { $suffix .= ' ' . Skin::build_link($url, MORE_IMG, 'more', i18n::s('View the page')) . ' '; } } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // details $details = array(); // the author if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id']), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id'])); } else { $details[] = sprintf(i18n::s('by %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id'])); } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // info on related comments if ($count = Comments::count_for_anchor('article:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // the main anchor link if (is_object($anchor)) { $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'section')); } // display all tags if ($item['tags']) { $details[] = '<span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>'; } // combine in-line details if (count($details)) { $suffix .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; } // insert a suffix separator if (trim($suffix)) { $suffix = ' ' . $suffix; } // item summary $box .= $prefix . Skin::build_link($url, $title, 'article') . $suffix; // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // build the complete HTML element if ($icon) { $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($title)) . '" />'; // make it a clickable link $icon = Skin::build_link($url, $icon, 'basic'); // default icon } else { $icon = DECORATED_IMG; } // layout this item $list = array(array($box, $icon)); $items[] = array($item['score'], Skin::finalize_list($list, 'decorated')); } // end of processing SQL::free($result); return $items; }