Example #1
0
File: links.php Project: rair/yacs
 *
 * @see codes/index.php
 *
 * @author Bernard Paques
 * @author GnapZ
 * @reference
 * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
 */
// common definitions and initial processing
include_once '../shared/global.php';
// load localized strings
i18n::bind('codes');
// load the skin
load_skin('codes');
// default section
$section_id = Sections::get_default();
// newest article
$article_id = 1;
if ($item =& Articles::get_newest_for_anchor(NULL, TRUE)) {
    $article_id = $item['id'];
}
// newest file
$file_id = 1;
if ($item =& Files::get_newest()) {
    $file_id = $item['id'];
}
// the path to this page
$context['path_bar'] = array('help/' => i18n::s('Help index'), 'codes/' => i18n::s('Formatting Codes'));
// the title of the page
$context['page_title'] = i18n::s('Codes to format links');
// the date of last modification
Example #2
0
 /**
  * process one message
  *
  * This function looks for a target anchor in message title. It also performs some security
  * checks before accepting actual submission.
  *
  * The subject line may indicate the container for the post, as per following patterns:
  * - [#1234] - a comment to be appended to article 1234
  * - [#s1234] - a page to be created in section 1234
  *
  * If no anchor is defined in message title, then the section id defined in queue parameters is
  * used. If no section has been defined for the queue, then a new page is created in the default
  * section.
  *
  * @param string message raw content
  */
 public static function process_message($entity)
 {
     global $context;
     // sanity check
     if (!trim($entity)) {
         return NULL;
     }
     // retrieve queue parameters
     list($server, $account, $password, $allowed, $match, $section, $options, $hooks, $prefix, $suffix) = $context['mail_queue'];
     // split headers and body
     if (!($position = strpos($entity, "\n\n"))) {
         Logger::remember('agents/messages.php: Can not split header and body', $entity);
         return NULL;
     }
     $message_headers = substr($entity, 0, $position);
     // security match
     if ($match && !preg_match('/' . preg_quote($match, '/') . '/i', $message_headers)) {
         Logger::remember('agents/messages.php: Message does not match /' . preg_quote($match, '/') . '/');
         return NULL;
     }
     // parse and decode all headers
     $message_headers = Messages::parse_headers($message_headers);
     // identify message sender
     $post_sender = NULL;
     foreach ($message_headers as $header) {
         if (preg_match('/From/i', $header['name'])) {
             $post_sender = $header['value'];
             break;
         }
     }
     // use only the mail address
     if (preg_match('/^[^<>]*<([^<>]+)>/', $post_sender, $matches)) {
         $post_sender = $matches[1];
     }
     // no poster
     if (!$post_sender) {
         Logger::remember('agents/messages.php: No poster address');
         return NULL;
     }
     // ensure poster is allowed to move forward
     $granted = FALSE;
     // maybe the sender has been recorded
     $user = Users::get($post_sender);
     // the address is in the list of allowed addresses, including anyone
     if ($allowed && preg_match('/\\b(' . preg_quote($post_sender, '/') . '|anyone)\\b/i', $allowed)) {
         $granted = TRUE;
         // email addresses not present in the database are allowed
         if (!$user['id']) {
             list($user['nick_name'], $domain) = explode('@', $post_sender);
             $user['id'] = 0;
             $user['email'] = $post_sender;
             $user['capability'] = 'M';
         }
         // the poster has to be recorded in the database
     } elseif (!$user['id']) {
         Logger::remember('agents/messages.php: Unknown poster address ' . $post_sender);
         return NULL;
         // maybe subscribers are allowed to post here
     } elseif ($user['capability'] == 'S' && $allowed && preg_match('/\\bany_subscriber\\b/i', $allowed)) {
         $granted = TRUE;
     } elseif ($user['capability'] == 'M' && $allowed && preg_match('/\\bany_member\\b/i', $allowed)) {
         $granted = TRUE;
     } elseif ($user['capability'] != 'A') {
         Logger::remember('agents/messages.php: Poster ' . $post_sender . ' is not allowed to contribute by e-mail');
         return NULL;
     }
     // message post date
     $context['mail_date'] = gmdate('D, j M Y G:i:s') . ' GMT';
     foreach ($message_headers as $header) {
         if (preg_match('/Date/i', $header['name'])) {
             $context['mail_date'] = $header['value'];
             break;
         }
     }
     // process message subject line --set in $context['mail_subject']
     $context['mail_subject'] = i18n::c('Item sent by e-mail');
     $anchor = NULL;
     foreach ($message_headers as $header) {
         if (preg_match('/Subject/i', $header['name'])) {
             $context['mail_subject'] = $header['value'];
             if (preg_match('/\\[#(a|s)*([0-9]+)\\]/', $header['value'], $matches)) {
                 $context['mail_subject'] = preg_replace('/' . preg_quote($matches[0], '/') . '/', '', $header['value']);
                 if (!$matches[1] || $matches[1] == 'a') {
                     $anchor = 'article:' . $matches[2];
                 } else {
                     $anchor = 'section:' . $matches[2];
                 }
             }
             break;
         }
     }
     // anchor is defined in queue parameters
     if (!$anchor && $section) {
         $anchor = 'section:' . $section;
     }
     // use default section
     if (!$anchor && ($section = Sections::get_default())) {
         $anchor = 'section:' . $section;
     }
     // no anchor to use
     if (!$anchor) {
         Logger::remember('agents/messages.php: No anchor has been found');
         return NULL;
     }
     // do the job
     include_once $context['path_to_root'] . 'comments/comments.php';
     if ($reference = Messages::process_entity($entity, $user, $anchor, NULL)) {
         // trigger hooks
         if (is_callable(array('Hooks', 'include_scripts'))) {
             // set hook parameters -- $context['mail_queue'] has queue attributes
             $context['mail_headers'] = $message_headers;
             $context['mail_body'] = substr($entity, $position + 2);
             $context['mail_poster'] = $user;
             $context['mail_anchor'] = $anchor;
             $context['mail_reference'] = $reference;
             // insert 'inbound-mail' in hooks to call
             $hooks = trim('inbound-mail ' . $hooks);
             // trigger each hook one by one
             $hooks = preg_split('/[\\s,]+/', $hooks, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($hooks as $hook) {
                 Hooks::include_scripts($hook);
             }
         }
     }
 }
Example #3
0
 /**
  * get sections as options of a &lt;SELECT&gt; field
  *
  * Only sections matching following criteria are returned:
  * - section is visible (active='Y')
  * - section is restricted (active='R'), but surfer is a logged user
  * - section is restricted (active='N'), but surfer is an associate
  * - an expiry date has not been defined, or is not yet passed
  *
  * This function uses the cache to save on database requests.
  *
  * @param string the current anchor to an existing section (e.g., 'section:12')
  * @param array list of sections made of $id => $attributes
  * @return the HTML to insert in the page
  *
  * @see articles/edit.php
  * @see articles/import.php
  * @see files/edit.php
  * @see images/edit.php
  * @see links/edit.php
  * @see panel.php
  * @see skins/upload.php
  */
 public static function get_options($default = NULL, $to_avoid = NULL)
 {
     global $context;
     // all options
     $text = '';
     // we don't want a default section
     if ($default == 'none') {
         $default = NULL;
     } elseif (!$default) {
         $default = 'section:' . Sections::get_default();
     }
     // list sections recursively
     $text .= Sections::get_options_for_anchor(NULL, '', $default, $to_avoid);
     // associates can also see inactive sections at the top level
     if (Surfer::is_associate() && ($sections = Sections::list_inactive_by_title_for_anchor(NULL, 0, 100, 'raw'))) {
         $text .= '<optgroup label="' . i18n::s('Other sections') . '">';
         // add to text
         foreach ($sections as $id => $attributes) {
             if (Sections::match($id, $to_avoid)) {
                 continue;
             }
             // this section
             $reference = 'section:' . $id;
             $text .= '<option value="' . $reference . '"';
             if ($default && $default == $reference) {
                 $text .= ' selected="selected"';
             }
             $text .= '>' . Skin::strip($attributes['title']) . "</option>\n";
             // list sub-sections recursively
             $text .= Sections::get_options_for_anchor($reference, '&nbsp;&nbsp;', $default, $to_avoid);
         }
         $text .= "</optgroup>\n";
     }
     return $text;
 }
Example #4
0
File: test.php Project: rair/yacs
if (!($user_id = Surfer::get_id())) {
    $user_id = 1;
}
// newest article
$article_id = 1;
if ($item =& Articles::get_newest_for_anchor(NULL, TRUE)) {
    $article_id = $item['id'];
}
// newest file
$file_id = 1;
if ($item =& Files::get_newest()) {
    $file_id = $item['id'];
}
$compact_items = array('[article=' . $article_id . ']', '[section=' . Sections::get_default() . ']', '[category=featured]', '[user='******']', '[download=' . $file_id . ']', '[email]foo@bar.com[/email]', '[link=Cisco]http://www.cisco.com/[/link]', '[script]skins/test.php[/script]', Skin::build_link('skins/test.php', 'skins/test.php', 'shortcut'), Skin::strip(DUMMY_TEXT, 7, 'skins/test.php'), RESTRICTED_FLAG . i18n::s('Community - Access is granted to any identified surfer'), PRIVATE_FLAG . i18n::s('Private - Access is restricted to selected persons'), i18n::s('This item is new') . NEW_FLAG, i18n::s('This item has been updated') . UPDATED_FLAG, DRAFT_FLAG . i18n::s('This item is a draft, and is not publicly visible'));
// $context['text'] - basic content with links, etc.
$text .= '[toc]' . DUMMY_TEXT . "\n" . '<ul>' . "\n" . '<li>[article=' . $article_id . ']</li>' . "\n" . '<li>[section=' . Sections::get_default() . ']</li>' . "\n" . '<li>[category=featured]</li>' . "\n" . '<li>[user='******']</li>' . "\n" . '<li>[download=' . $file_id . ']</li>' . "\n" . '<li>[email]foo@bar.com[/email]</li>' . "\n" . '<li>[link=Cisco]http://www.cisco.com/[/link]</li>' . "\n" . '<li>[script]skins/test.php[/script]</li>' . "\n" . '<li>' . Skin::build_link('skins/test.php', 'skins/test.php', 'shortcut') . '</li>' . "\n" . '<li>' . Skin::strip(DUMMY_TEXT, 7, 'skins/test.php') . '</li>' . "\n" . '<li>' . RESTRICTED_FLAG . i18n::s('Community - Access is granted to any identified surfer') . '</li>' . "\n" . '<li>' . PRIVATE_FLAG . i18n::s('Private - Access is restricted to selected persons') . '</li>' . "\n" . '<li>' . i18n::s('This item is new') . NEW_FLAG . '</li>' . "\n" . '<li>' . i18n::s('This item has been updated') . UPDATED_FLAG . '</li>' . "\n" . '<li>' . DRAFT_FLAG . i18n::s('This item is a draft, and is not publicly visible') . '</li>' . "\n" . '</ul>' . "\n" . '<p>' . DUMMY_TEXT . "</p>\n" . Skin::finalize_list($compact_items, 'compact') . '<p>' . DUMMY_TEXT . "</p>\n" . '<div class="menu_bar">[button=' . i18n::s('Click to reload this page') . ']skins/test.php[/button]</div>' . "\n" . '<p>' . DUMMY_TEXT . "</p>\n" . ' [title]' . i18n::s('level 1 title') . '[/title] ' . "\n" . DUMMY_TEXT . "\n" . ' [subtitle]' . i18n::s('level 2 title') . '[/subtitle] ' . "\n" . DUMMY_TEXT;
// a sidebar
$sidebar =& Skin::build_box(i18n::s('sidebar box'), DUMMY_TEXT, 'sidebar');
// $context['text'] - section with sidebar box
$text .= Skin::build_box(i18n::s('with a sidebar box'), $sidebar . '<p>' . DUMMY_TEXT . '</p><p>' . DUMMY_TEXT . '</p>');
// a folded box
$folder =& Skin::build_box(i18n::s('folded box'), DUMMY_TEXT, 'folded');
// $context['text'] - section with folded box
$text .= Skin::build_box(i18n::s('with a folded box'), DUMMY_TEXT . $folder . DUMMY_TEXT);
// a menu bar
$menu_bar = array('skins/test.php' => i18n::s('Test page'), 'skins/' => i18n::s('Themes'), 'scripts/' => i18n::s('Server software'));
// $context['text'] - section with a menu bar
$text .= Skin::build_box(i18n::s('with a menu bar'), DUMMY_TEXT . Skin::build_list($menu_bar, 'menu_bar') . DUMMY_TEXT);
// page neighbours
$neighbours = array('#previous', i18n::s('Previous'), '#next', i18n::s('Next'), '', '<a class="pager-item">1</a> &nbsp; <a class="pager-current">2</a>');
// $context['text'] - section with neighbours