Exemplo n.º 1
0
Arquivo: anchor.php Projeto: rair/yacs
 /**
  * get the named url for this anchor
  *
  * If the anchor as been named, this function returns the related url.
  *
  *
  * @return an url to view the anchor page, or NULL
  */
 function get_named_url()
 {
     if (isset($this->item['nick_name']) && $this->item['nick_name']) {
         return normalize_shortcut($this->item['nick_name']);
     }
     return NULL;
 }
Exemplo n.º 2
0
Arquivo: search.php Projeto: rair/yacs
//
// extra panel
//
// extend the search, but only at first page
if ($search) {
    // a tool to update the related category
    if (Surfer::is_member()) {
        $context['page_tools'][] = Skin::build_link('categories/set_keyword.php?search=' . urlencode($search), i18n::s('Remember this search'));
    }
    // same keywords on whole site
    if ($section_id) {
        $context['page_tools'][] = Skin::build_link('search.php?search=' . urlencode($search), i18n::s('Search in all sections'), 'basic');
    }
    // submit one token to our page locator
    if (preg_match('/^([\\S-]+)/', $search, $matches)) {
        $context['page_tools'][] = Skin::build_link(normalize_shortcut($matches[1]), i18n::s('Look for a named page'), 'basic');
    }
}
// general help on this page
$context['components']['boxes'] = Skin::build_box(i18n::s('Help'), i18n::s('This search engine only display pages that have all words in it. <p>Also, only exact matches will be listed. Therefore "category" and "categories" won\'t give the same results. Note that "red" and "reds" may also give different results.</p>'), 'boxes', 'help');
// how to stay tuned
$lines = array();
if ($search) {
    $lines[] = Skin::build_link('services/search.php?search=' . urlencode($search), i18n::s('Matching pages'), 'xml');
}
$context['components']['boxes'] .= Skin::build_box(i18n::s('Monitor'), join(BR, $lines), 'boxes', 'feeds');
// side bar with the list of most recent keywords
$cache_id = 'search.php#keywords_by_date';
if (!($text = Cache::get($cache_id))) {
    if ($items = Categories::list_keywords_by_date(0, COMPACT_LIST_SIZE)) {
        $text =& Skin::build_box(i18n::s('Recent searches'), Skin::build_list($items, 'compact'), 'boxes');
Exemplo n.º 3
0
            $details[] = '{' . $item['rank'] . '}';
        }
        // locked section
        if ($item['locked'] == 'Y') {
            $details[] = LOCKED_FLAG . ' ' . i18n::s('page is locked.');
        }
    }
    // inline details
    if (count($details)) {
        $text .= ucfirst(implode(', ', $details));
    }
    // reference this item
    if (Surfer::is_logged()) {
        $text .= BR . sprintf(i18n::s('Code to reference this page: %s'), '[section=' . $item['id'] . ']');
        // the nick name
        if ($item['nick_name'] && ($link = normalize_shortcut($item['nick_name'], TRUE))) {
            $text .= BR . sprintf(i18n::s('Name: %s'), $link);
        }
        // short link
        if ($context['with_friendly_urls'] == 'R') {
            $text .= BR . sprintf(i18n::s('Shortcut: %s'), $context['url_to_home'] . $context['url_to_root'] . Sections::get_short_url($item));
        }
    }
    // no more details
    $text .= "</p>\n";
    // update page details
    $context['page_details'] = $text;
}
//
// main panel -- $context['text']
//
Exemplo n.º 4
0
Arquivo: codes.php Projeto: rair/yacs
 /**
  * render a link to an object
  *
  * Following types are supported:
  * - article - link to an article page
  * - category - link to a category page
  * - comment - link to a comment page
  * - download - link to a download page
  * - file - link to a file page
  * - flash - display a file as a native flash object, or play a flash video
  * - go
  * - image - display an in-line image
  * - next - link to an article page
  * - previous - link to an article page
  * - section - link to a section page
  * - server - link to a server page
  * - user - link to a user page
  *
  * @param string the type
  * @param string the id, with possible options or variant
  * @return string the rendered text
  **/
 public static function render_object($type, $id)
 {
     global $context;
     $id = Codes::fix_tags($id);
     // depending on type
     switch ($type) {
         // link to an article
         case 'article':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Articles::get($id))) {
                 $output = '[article=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Articles::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, $type);
             }
             return $output;
             // insert article description
         // insert article description
         case 'article.description':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Articles::get($id))) {
                 $output = '[article.description=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Articles::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, 'article');
                 // the introduction text, if any
                 $output .= BR . Codes::beautify($item['introduction']);
                 // load overlay, if any
                 if (isset($item['overlay']) && $item['overlay']) {
                     $overlay = Overlay::load($item, 'article:' . $item['id']);
                     // get text related to the overlay, if any
                     if (is_object($overlay)) {
                         $output .= $overlay->get_text('view', $item);
                     }
                 }
                 // the description, which is the actual page body
                 $output .= '<div>' . Codes::beautify($item['description']) . '</div>';
             }
             return $output;
             // link to a category
         // link to a category
         case 'category':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Categories::get($id))) {
                 $output = '[category=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Categories::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, $type);
             }
             return $output;
             // insert category description
         // insert category description
         case 'category.description':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Categories::get($id))) {
                 $output = '[category.description=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Categories::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, 'category');
                 // the introduction text, if any
                 $output .= BR . Codes::beautify($item['introduction']);
                 // load overlay, if any
                 if (isset($item['overlay']) && $item['overlay']) {
                     $overlay = Overlay::load($item, 'category:' . $item['id']);
                     // get text related to the overlay, if any
                     if (is_object($overlay)) {
                         $output .= $overlay->get_text('view', $item);
                     }
                 }
                 // the description, which is the actual page body
                 $output .= '<div>' . Codes::beautify($item['description']) . '</div>';
             }
             return $output;
             // link to a comment
         // link to a comment
         case 'comment':
             include_once $context['path_to_root'] . 'comments/comments.php';
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Comments::get($id))) {
                 $output = '[comment=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                 } else {
                     $text = i18n::s('View this comment');
                 }
                 // make a link to the target page
                 $url = $context['url_to_home'] . $context['url_to_root'] . Comments::get_url($item['id']);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, 'basic');
             }
             return $output;
             // link to a download
         // link to a download
         case 'download':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Files::get($id))) {
                 // file does not exist anymore
                 if (isset($attributes[1]) && $attributes[1]) {
                     $output = $attributes[1] . '<p class="details">' . i18n::s('[this file has been deleted]') . '</p>';
                 } else {
                     $output = '[download=' . $id . ']';
                 }
             } else {
                 // label for this file
                 $prefix = $text = $suffix = '';
                 // signal restricted and private files
                 if ($item['active'] == 'N') {
                     $prefix .= PRIVATE_FLAG;
                 } elseif ($item['active'] == 'R') {
                     $prefix .= RESTRICTED_FLAG;
                 }
                 // ensure we have a label for this link
                 if (isset($attributes[1]) && $attributes[1]) {
                     $text .= $attributes[1];
                     // this may describe a previous file, which has been replaced
                     if ($item['edit_action'] != 'file:create' && $attributes[1] != $item['file_name']) {
                         $text .= ' <p class="details">' . i18n::s('[this file has been replaced]') . '</p>';
                         $output = $prefix . $text . $suffix;
                         return $output;
                     }
                 } else {
                     $text = Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name']));
                 }
                 // flag files uploaded recently
                 if ($item['create_date'] >= $context['fresh']) {
                     $suffix .= NEW_FLAG;
                 } elseif ($item['edit_date'] >= $context['fresh']) {
                     $suffix .= UPDATED_FLAG;
                 }
                 // always download the file
                 $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']);
                 // return a complete anchor
                 $output = $prefix . Skin::build_link($url, $text, 'file') . $suffix;
             }
             return $output;
             // link to a file
         // link to a file
         case 'file':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database --ensure we get a fresh copy of the record, not a cached one
             if (!($item = Files::get($id, TRUE))) {
                 // file does not exist anymore
                 if (isset($attributes[1]) && $attributes[1]) {
                     $output = $attributes[1] . '<p class="details">' . i18n::s('[this file has been deleted]') . '</p>';
                 } else {
                     $output = '[file=' . $id . ']';
                 }
             } else {
                 // maybe we want to illustrate this file
                 if ($item['edit_action'] != 'file:create' && isset($attributes[1]) && $attributes[1] || !($output = Files::interact($item))) {
                     // label for this file
                     $output = $prefix = $text = $suffix = '';
                     // signal restricted and private files
                     if ($item['active'] == 'N') {
                         $prefix .= PRIVATE_FLAG;
                     } elseif ($item['active'] == 'R') {
                         $prefix .= RESTRICTED_FLAG;
                     }
                     // ensure we have a label for this link
                     if (isset($attributes[1]) && $attributes[1]) {
                         $text .= $attributes[1];
                         // this may describe a previous file, which has been replaced
                         if ($item['edit_action'] != 'file:create' && $attributes[1] != $item['file_name']) {
                             $text .= '<p class="details">' . i18n::s('[this file has been replaced]') . '</p>';
                             $output = $prefix . $text . $suffix;
                             return $output;
                         }
                     } else {
                         $text .= Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name']));
                     }
                     // flag files uploaded recently
                     if ($item['create_date'] >= $context['fresh']) {
                         $suffix .= NEW_FLAG;
                     } elseif ($item['edit_date'] >= $context['fresh']) {
                         $suffix .= UPDATED_FLAG;
                     }
                     // make a link to the target page
                     $url = Files::get_download_url($item);
                     // return a complete anchor
                     $output .= $prefix . Skin::build_link($url, $text, 'basic') . $suffix;
                 }
             }
             return $output;
             // invoke the selector
         // invoke the selector
         case 'go':
             // extract the label, if any
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $name = $attributes[0];
             // ensure we have a label for this link
             if (isset($attributes[1])) {
                 $text = $attributes[1];
             } else {
                 $text = $name;
             }
             // return a complete anchor
             $output = Skin::build_link($context['url_to_home'] . $context['url_to_root'] . normalize_shortcut($name), $text, 'basic');
             return $output;
             // embed an image
         // embed an image
         case 'image':
             include_once $context['path_to_root'] . 'images/images.php';
             // get the variant, if any
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             if (isset($attributes[1])) {
                 $variant = $attributes[1];
             } else {
                 $variant = 'inline';
             }
             // get the image record
             if (!($image = Images::get($id))) {
                 $output = '[image=' . $id . ']';
                 return $output;
             }
             // a title for the image --do not force a title
             if (isset($image['title'])) {
                 $title = $image['title'];
             } else {
                 $title = '';
             }
             // provide thumbnail if not defined, or forced, or for large images
             if (!$image['use_thumbnail'] || $image['use_thumbnail'] == 'A' || $image['use_thumbnail'] == 'Y' && $image['image_size'] > $context['thumbnail_threshold']) {
                 // not inline anymore, but thumbnail --preserve other variants
                 if ($variant == 'inline') {
                     $variant = 'thumbnail';
                 }
                 // where to fetch the image file
                 $href = Images::get_thumbnail_href($image);
                 // to drive to plain image
                 $link = Images::get_icon_href($image);
                 // add an url, if any
             } elseif ($image['link_url']) {
                 // flag large images
                 if ($image['image_size'] > $context['thumbnail_threshold']) {
                     $variant = rtrim('large ' . $variant);
                 }
                 // where to fetch the image file
                 $href = Images::get_icon_href($image);
                 // transform local references, if any
                 include_once $context['path_to_root'] . '/links/links.php';
                 $attributes = Links::transform_reference($image['link_url']);
                 if ($attributes[0]) {
                     $link = $context['url_to_root'] . $attributes[0];
                 } else {
                     $link = $image['link_url'];
                 }
                 // get the <img ... /> element
             } else {
                 // do not append poor titles to inline images
                 if ($variant == 'inline') {
                     $title = '';
                 }
                 // flag large images
                 if ($image['image_size'] > $context['thumbnail_threshold']) {
                     $variant = rtrim('large ' . $variant);
                 }
                 // where to fetch the image file
                 $href = Images::get_icon_href($image);
                 // no link
                 $link = '';
             }
             // use the skin
             if (Images::allow_modification($image['anchor'], $id)) {
                 // build editable image
                 $output =& Skin::build_image($variant, $href, $title, $link, $id);
             } else {
                 $output =& Skin::build_image($variant, $href, $title, $link);
             }
             return $output;
             // embed a stack of images
         // embed a stack of images
         case 'images':
             include_once $context['path_to_root'] . 'images/images.php';
             // get the list of ids
             $ids = preg_split("/\\s*,\\s*/", $id);
             if (!count($ids)) {
                 $output = '[images=id1, id2, ...]';
                 return $output;
             }
             // build the list of images
             $items = array();
             foreach ($ids as $id) {
                 // get the image record
                 if ($image = Images::get($id)) {
                     // a title for the image --do not force a title
                     if (isset($image['title'])) {
                         $title = $image['title'];
                     } else {
                         $title = '';
                     }
                     // provide thumbnail if not defined, or forced, or for large images
                     $variant = 'inline';
                     if (!$image['use_thumbnail'] || $image['use_thumbnail'] == 'A' || $image['use_thumbnail'] == 'Y' && $image['image_size'] > $context['thumbnail_threshold']) {
                         // not inline anymore, but thumbnail
                         $variant = 'thumbnail';
                         // where to fetch the image file
                         $href = Images::get_thumbnail_href($image);
                         // to drive to plain image
                         $link = $context['url_to_root'] . Images::get_url($id);
                         // add an url, if any
                     } elseif ($image['link_url']) {
                         // flag large images
                         if ($image['image_size'] > $context['thumbnail_threshold']) {
                             $variant = rtrim('large ' . $variant);
                         }
                         // where to fetch the image file
                         $href = Images::get_icon_href($image);
                         // transform local references, if any
                         include_once $context['path_to_root'] . '/links/links.php';
                         $attributes = Links::transform_reference($image['link_url']);
                         if ($attributes[0]) {
                             $link = $context['url_to_root'] . $attributes[0];
                         } else {
                             $link = $image['link_url'];
                         }
                         // get the <img ... /> element
                     } else {
                         // flag large images
                         if ($image['image_size'] > $context['thumbnail_threshold']) {
                             $variant = rtrim('large ' . $variant);
                         }
                         // where to fetch the image file
                         $href = Images::get_icon_href($image);
                         // no link
                         $link = '';
                     }
                     // use the skin
                     $label =& Skin::build_image($variant, $href, $title, $link);
                     // add item to the stack
                     $items[] = $label;
                 }
             }
             // format the list
             $output = '';
             if (count($items)) {
                 // stack items
                 $output = Skin::finalize_list($items, 'stack');
                 // rotate items
                 $output = Skin::rotate($output);
             }
             // done
             return $output;
             // link to the next article
         // link to the next article
         case 'next':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Articles::get($id))) {
                 $output = '[next=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Articles::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, 'next');
             }
             return $output;
             // link to the previous article
         // link to the previous article
         case 'previous':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Articles::get($id))) {
                 $output = '[previous=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Articles::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, 'previous');
             }
             return $output;
             // link to a section
         // link to a section
         case 'section':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Sections::get($id))) {
                 $output = '[section=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = Sections::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, $type);
             }
             return $output;
             // link to a server
         // link to a server
         case 'server':
             include_once $context['path_to_root'] . 'servers/servers.php';
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Servers::get($id))) {
                 $output = '[server=' . $id . ']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } else {
                     $text = Skin::strip($item['title']);
                 }
                 // make a link to the target page
                 $url = $context['url_to_home'] . $context['url_to_root'] . Servers::get_url($id);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, $type);
             }
             return $output;
             // link to a user
         // link to a user
         case 'user':
             // maybe an alternate title has been provided
             $attributes = preg_split("/\\s*,\\s*/", $id, 2);
             $id = $attributes[0];
             // load the record from the database
             if (!($item = Users::get($id))) {
                 $output = '[user='******']';
             } else {
                 // ensure we have a label for this link
                 if (isset($attributes[1])) {
                     $text = $attributes[1];
                     $type = 'basic';
                 } elseif (isset($item['full_name']) && $item['full_name']) {
                     $text = ucfirst($item['full_name']);
                 } else {
                     $text = ucfirst($item['nick_name']);
                 }
                 // make a link to the target page
                 $url = Users::get_permalink($item);
                 // return a complete anchor
                 $output =& Skin::build_link($url, $text, $type);
             }
             return $output;
             // invalid type
         // invalid type
         default:
             $output = '[' . $type . ']';
             return $output;
     }
 }