Beispiel #1
0
 /**
  * list images
  *
  * @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)) {
         // get the anchor for this image
         if ($item['anchor']) {
             $anchor = Anchors::get($item['anchor']);
         }
         // url to view the image
         $url = $context['url_to_home'] . $context['url_to_root'] . Images::get_url($item['id']);
         // time of last update
         $time = SQL::strtotime($item['edit_date']);
         // the title as the label
         if ($item['title']) {
             $label = ucfirst($item['title']) . ' (' . $item['image_name'] . ')';
         } else {
             $label = $item['image_name'];
         }
         // the section
         $section = '';
         if (is_object($anchor)) {
             $section = ucfirst($anchor->get_title());
         }
         // the author(s) is an e-mail address, according to rss 2.0 spec
         $author = $item['create_address'] . ' (' . $item['create_name'] . ')';
         if ($item['create_address'] != $item['edit_address']) {
             if ($author) {
                 $author .= ', ';
             }
             $author .= $item['edit_address'] . ' (' . $item['edit_name'] . ')';
         }
         // the description
         $description = Codes::beautify($item['description']);
         // cap the number of words
         $description = Skin::cap($description, 300);
         // fix image references
         $description = preg_replace('#"/([^">]+?)"#', '"' . $context['url_to_home'] . '/$1"', $description);
         $introduction = $description;
         // other rss fields
         $extensions = array();
         // url for enclosure
         $type = Files::get_mime_type($item['image_name']);
         $extensions[] = '<enclosure url="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_path($item['anchor'], 'images') . '/' . $item['image_name'] . '"' . ' length="' . $item['image_size'] . '"' . ' type="' . $type . '" />';
         // list all components for this item
         $items[$url] = array($time, $label, $author, $section, NULL, $introduction, $description, $extensions);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
Beispiel #2
0
 /**
  * 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;
     }
 }
Beispiel #3
0
 $context['page_title'] = i18n::s('Thank you for your contribution');
 // the page has been published
 if (isset($_REQUEST['publish_date']) && $_REQUEST['publish_date'] > NULL_DATE) {
     $context['text'] .= '<p>' . i18n::s('The page has been successfully posted. Please review it now to ensure that it reflects your mind.') . '</p>';
 } elseif (Surfer::is_empowered()) {
     $context['text'] .= i18n::s('<p>Don\'t forget to publish the new page someday. Review the page, enhance it and then click on the Publish command to make it publicly available.</p>');
 } elseif (isset($context['users_with_auto_publish']) && $context['users_with_auto_publish'] == 'Y' || is_object($anchor) && $anchor->has_option('auto_publish')) {
     $context['text'] .= i18n::s('<p>Don\'t forget to publish the new page someday. Review the page, enhance it and then click on the Publish command to make it publicly available.</p>');
 } else {
     $context['text'] .= i18n::s('<p>The new page will now be reviewed before its publication. It is likely that this will be done within the next 24 hours at the latest.</p>');
 }
 if (!isset($_REQUEST['first_comment'])) {
     $_REQUEST['first_comment'] = '';
 }
 // attach some file
 $file_path = Files::get_path('article:' . $_REQUEST['id']);
 if (isset($_FILES['upload']) && ($uploaded = Files::upload($_FILES['upload'], $file_path, 'article:' . $_REQUEST['id']))) {
     // several files have been added
     if (is_array($uploaded)) {
         $_REQUEST['first_comment'] .= '<div>' . Skin::build_list(Files::list_for_anchor_and_name('article:' . $_REQUEST['id'], $uploaded, 'compact'), 'compact') . '</div>';
     } elseif ($file =& Files::get_by_anchor_and_name('article:' . $_REQUEST['id'], $uploaded)) {
         $_REQUEST['first_comment'] .= '<div>' . Codes::render_object('file', $file['id']) . '</div>';
         // silently delete the previous file if the name has changed
         if (isset($file['file_name']) && $file['file_name'] != $uploaded) {
             Safe::unlink($file_path . '/' . $file['file_name']);
         }
     }
 }
 // capture first comment too
 if (isset($_REQUEST['first_comment']) && $_REQUEST['first_comment']) {
     include_once $context['path_to_root'] . 'comments/comments.php';
Beispiel #4
0
                // validate content in cache
                if (http::validate($last_modified)) {
                    return;
                }
                // actual transmission except on a HEAD request
                if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
                    fpassthru($handle);
                }
                fclose($handle);
            }
            // the post-processing hook, then exit even on HEAD
            finalize_page();
            return;
        }
        // redirect to the actual file
        $target_href = $context['url_to_home'] . $context['url_to_root'] . Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']);
    }
    // let the web server provide the actual file
    if (!headers_sent()) {
        Safe::header('Status: 302 Found', TRUE, 302);
        Safe::header('Location: ' . $target_href);
        // this one may be blocked by anti-popup software
    } else {
        $context['site_head'] .= '<meta http-equiv="Refresh" content="1;url=' . $target_href . '" />' . "\n";
    }
    // help the surfer
    $context['text'] .= '<p>' . i18n::s('You are requesting the following file:') . '</p>' . "\n";
    $context['text'] .= '<p><a href="' . encode_field($target_href) . '">' . basename($target_href) . '</a></p>' . "\n";
    // automatic or not
    $context['text'] .= '<p>' . i18n::s('The download should start automatically within seconds. Else hit the provided link to trigger it manually.') . '</p>' . "\n";
}
Beispiel #5
0
        $fields['thumbnail_url'] = $context['url_to_master'] . $context['url_to_root'] . Files::get_path($target->get_reference()) . '/thumbs/' . urlencode($file->item['file_name']);
    }
    $output['success'] = $file->set_values($fields);
    // move file physicaly
    if ($output['success']) {
        $from = $context['path_to_root'] . Files::get_path($last_parent->get_reference()) . '/' . $file->item['file_name'];
        $dir = $context['path_to_root'] . Files::get_path($target->get_reference());
        $to = $dir . '/' . $file->item['file_name'];
        // check that dir exists
        if (!is_dir($dir)) {
            Safe::make_path($dir);
        }
        Safe::rename($from, $to);
        // move thumb if any
        if ($file->item['thumbnail_url']) {
            $from = Files::get_path($last_parent->get_reference()) . '/thumbs/' . $file->item['file_name'];
            // make directory thumbs
            $to = $dir . '/thumbs/' . $file->item['file_name'];
            // check that dir exist
            if (!is_dir($dir . '/thumbs')) {
                Safe::mkdir($dir . '/thumbs');
            }
            Safe::rename($from, $to);
        }
    }
}
// we return some JSON
$output = json_encode($output);
// allow for data compression
render_raw('application/json; charset=' . $context['charset']);
// actual transmission except on a HEAD request
Beispiel #6
0
        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.'));
    // stream this file
} else {
    // 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']);
        // redirect to the actual file
        $target_href = $context['url_to_home'] . $context['url_to_root'] . $path;
    }
    // determine attribute for this item
    $type = $mime = $text = '';
    // the default is to provide the file directly
    $fetched = FALSE;
    // embed the file depending on the file type
    $extension = strtolower(@array_pop(@explode('.', @basename($item['file_name']))));
    switch ($extension) {
        case 'aif':
        case 'aiff':
        case 'au':
        case 'mka':
        case 'mp3':
Beispiel #7
0
         // save content of the overlay in this item
         $_REQUEST['overlay'] = $overlay->save();
         $_REQUEST['overlay_id'] = $overlay->get_id();
     }
     // save in the database
     Files::post($_REQUEST);
     // log record creation
     if (!$item['id']) {
         $label = sprintf(i18n::c('New file in %s'), strip_tags($anchor->get_title()));
         $link = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($_REQUEST['id']);
         $description = sprintf(i18n::c('%s at %s'), $_REQUEST['file_name'], '<a href="' . $link . '">' . $link . '</a>');
         Logger::notify('files/edit.php: ' . $label, $description);
     }
     // a file has been uploaded
 } elseif (Files::get_uploaded('upload', 'name')) {
     $file_path = Files::get_path($_REQUEST['anchor']);
     // update an existing file record
     if (isset($item['id'])) {
         Files::set_uploaded('upload', 'id', $item['id']);
     }
     // attach some file
     if ($uploaded = Files::upload(Files::get_uploaded('upload'), $file_path, $anchor->get_reference(), $overlay)) {
         // actually, a new file
         if (!isset($item['id'])) {
             $action = 'file:create';
         } else {
             $action = 'file:upload';
         }
         // several files have been added
         if (is_array($uploaded)) {
             $compact_list = Skin::build_list(Files::list_for_anchor_and_name($anchor->get_reference(), $uploaded, 'compact'), 'compact');
Beispiel #8
0
     $rows[] = array(i18n::s('Source'), $item['source']);
 }
 // keywords
 if ($item['keywords']) {
     $rows[] = array(i18n::s('Keywords'), $item['keywords']);
 }
 // display these details
 $context['text'] .= Skin::table(NULL, $rows);
 // insert anchor prefix
 if (is_object($anchor)) {
     $context['text'] .= $anchor->get_prefix();
 }
 // if we have a local file
 if (!isset($item['file_href']) || !$item['file_href']) {
     // where the file is
     $path = $context['path_to_root'] . Files::get_path($item['anchor']) . '/' . rawurlencode(utf8::to_ascii($item['file_name']));
     //load some file parser if one is available
     $analyzer = NULL;
     if (is_readable($context['path_to_root'] . 'included/getid3/getid3.php')) {
         include_once $context['path_to_root'] . 'included/getid3/getid3.php';
         $analyzer = new getid3();
     }
     // parse file content, and streamline information
     $data = array();
     if (is_object($analyzer) && Files::is_stream($item['file_name'])) {
         $data = $analyzer->analyze($path);
         getid3_lib::CopyTagsToComments($data);
     }
     // details
     $rows = array();
     // artist
Beispiel #9
0
 /**
  * create a referenced image
  *
  * @param array of entity attributes (e.g., 'Content-Disposition')
  * @param string image actual content
  * @param array poster attributes
  * @param string the target anchor (e.g., 'article:123')
  * @param string reference of the object to be extended, if any
  * @return string reference to the created object, or NULL
  */
 public static function submit_image($entity_headers, $content, $user, $anchor, $target = NULL)
 {
     global $context;
     // retrieve queue parameters
     list($server, $account, $password, $allowed, $match, $section, $options, $hooks, $prefix, $suffix) = $context['mail_queue'];
     // locate content-disposition
     foreach ($entity_headers as $header) {
         if (preg_match('/Content-Disposition/i', $header['name'])) {
             $content_disposition = $header['value'];
             break;
         }
     }
     // find file name in content-disposition
     $file_name = '';
     if ($content_disposition && preg_match('/filename="*([a-zA-Z0-9\'\\(\\)\\+_,-\\.\\/:=\\? ]+)"*\\s*/i', $content_disposition, $matches)) {
         $file_name = $matches[1];
     }
     // as an alternative, look in content-type
     if (!$file_name) {
         // locate content-type
         foreach ($entity_headers as $header) {
             if (preg_match('/Content-Type/i', $header['name'])) {
                 $content_type = $header['value'];
                 break;
             }
         }
         // find file name in content-type
         if ($content_type && preg_match('/name="*([a-zA-Z0-9\'\\(\\)\\+_,-\\.\\/:=\\? ]+)"*\\s*/i', $content_type, $matches)) {
             $file_name = $matches[1];
         }
     }
     // as an alternative, look in content-description
     if (!$file_name) {
         // locate content-description
         foreach ($entity_headers as $header) {
             if (preg_match('/Content-Description/i', $header['name'])) {
                 $content_description = $header['value'];
                 break;
             }
         }
         // find file name in content-description
         $file_name = $content_description;
     }
     // sanity check
     if (!$file_name) {
         Logger::remember('agents/messages.php: No file name to use for submitted image');
         return NULL;
     }
     // file size
     $file_size = strlen($content);
     // sanity check
     if ($file_size < 7) {
         Logger::remember('agents/messages.php: Short image skipped', $file_name);
         return NULL;
     }
     // sanity check
     if (!$anchor) {
         Logger::remember('agents/messages.php: No anchor to use for submitted image', $file_name);
         return NULL;
     }
     // get anchor data -- this is a mutable object
     $host = Anchors::get($anchor, TRUE);
     if (!is_object($host)) {
         Logger::remember('agents/messages.php: Unknown anchor ' . $anchor, $file_name);
         return NULL;
     }
     // create target folders
     $file_path = Files::get_path($anchor, 'images');
     if (!Safe::make_path($file_path)) {
         Logger::remember('agents/messages.php: Impossible to create ' . $file_path);
         return NULL;
     }
     if (!Safe::make_path($file_path . '/thumbs')) {
         Logger::remember('agents/messages.php: Impossible to create ' . $file_path . '/thumbs');
         return NULL;
     }
     $file_path = $context['path_to_root'] . $file_path . '/';
     // save the entity in the file system
     if (!($file = Safe::fopen($file_path . $file_name, 'wb'))) {
         Logger::remember('agents/messages.php: Impossible to open ' . $file_path . $file_name);
         return NULL;
     }
     if (fwrite($file, $content) === FALSE) {
         Logger::remember('agents/messages.php: Impossible to write to ' . $file_path . $file_name);
         return NULL;
     }
     fclose($file);
     // get image information
     if (!($image_information = Safe::GetImageSize($file_path . $file_name))) {
         Safe::unlink($file_path . $file_name);
         Logger::remember('agents/messages.php: No image information in ' . $file_path . $file_name);
         return NULL;
     }
     // we accept only gif, jpeg and png
     if ($image_information[2] != 1 && $image_information[2] != 2 && $image_information[2] != 3) {
         Safe::unlink($file_path . $file_name);
         Logger::remember('agents/messages.php: Rejected image type for ' . $file_path . $file_name);
         return NULL;
     }
     // build a thumbnail
     $thumbnail_name = 'thumbs/' . $file_name;
     // do not stop on error
     include_once $context['path_to_root'] . 'images/image.php';
     if (!Image::shrink($file_path . $file_name, $file_path . $thumbnail_name, FALSE, FALSE)) {
         Logger::remember('agents/messages.php: No thumbnail has been created for ' . $file_path . $file_name);
     }
     // resize the image where applicable
     if (Image::adjust($file_path . $file_name, FALSE)) {
         $file_size = Safe::filesize($file_path . $file_name);
     }
     // all details
     $details = array();
     // image size
     if ($image_information = Safe::GetImageSize($file_path . $file_name)) {
         $details[] = i18n::c('Size') . ': ' . $image_information[0] . ' x ' . $image_information[1];
     }
     // update image description
     $item = array();
     $item['anchor'] = $anchor;
     $item['image_name'] = $file_name;
     $item['thumbnail_name'] = $thumbnail_name;
     $item['image_size'] = $file_size;
     $item['description'] = '';
     if (isset($content_description) && $content_description != $file_name) {
         $item['description'] .= $content_description;
     }
     if (@count($details)) {
         $item['description'] .= "\n\n" . '<p class="details">' . implode("<br />\n", $details) . "</p>\n";
     }
     $item['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time());
     $item['edit_name'] = $user['nick_name'];
     $item['edit_id'] = $user['id'];
     $item['edit_address'] = $user['email'];
     // create an image record in the database
     include_once $context['path_to_root'] . 'images/images.php';
     if (!($item['id'] = Images::post($item))) {
         Logger::remember('agents/messages.php: Impossible to save image ' . $item['image_name']);
         return NULL;
     }
     if ($context['debug_messages'] == 'Y') {
         Logger::remember('agents/messages.php: Messages::submit_image()', $item, 'debug');
     }
     // insert the image in the anchor page
     $host->touch('image:create', $item['id'], TRUE);
     return 'image:' . $item['id'];
 }
Beispiel #10
0
 /**
  * build a reference to a file
  *
  * Depending on parameter '[code]with_friendly_urls[/code]' and on action,
  * following results can be observed:
  *
  * - view - files/view.php?id=123 or files/view.php/123 or file-123
  *
  * - other - files/edit.php?id=123 or files/edit.php/123 or file-edit/123
  *
  * @param int the id of the file to handle
  * @param string the expected action ('view', 'print', 'edit', 'delete', ...)
  * @param string additional data, such as file name, if any
  * @return string a normalized reference
  *
  * @see control/configure.php
  */
 public static function get_url($id, $action = 'view', $name = NULL)
 {
     global $context;
     // get files in rss -- the id has to be an anchor (e.g., 'article:15')
     if ($action == 'feed') {
         if ($context['with_friendly_urls'] == 'Y') {
             return 'files/feed.php/' . str_replace(':', '/', $id);
         } elseif ($context['with_friendly_urls'] == 'R') {
             return 'files/feed.php/' . str_replace(':', '/', $id);
         } else {
             return 'files/feed.php?anchor=' . urlencode($id);
         }
     }
     // add a file -- the id has to be an anchor (e.g., 'article:15')
     if ($action == 'file') {
         if ($context['with_friendly_urls'] == 'Y') {
             return 'files/edit.php/' . str_replace(':', '/', $id);
         } elseif ($context['with_friendly_urls'] == 'R') {
             return 'files/edit.php/' . str_replace(':', '/', $id);
         } else {
             return 'files/edit.php?anchor=' . urlencode($id);
         }
     }
     // confirm the download
     if ($action == 'confirm') {
         $action = 'fetch';
         $name = 'confirm';
     }
     // clear assignment
     if ($action == 'release') {
         $action = 'fetch';
         $name = 'release';
     }
     // reserve the file
     if ($action == 'reserve') {
         $action = 'fetch';
         $name = 'reserve';
     }
     // direct access to the file
     if ($action == 'direct') {
         // get file data
         $file = Files::get($id);
         // get path to the file
         $url = Files::get_path($file['anchor']) . '/' . rawurlencode($file['file_name']);
         return $url;
     }
     // check the target action
     if (!preg_match('/^(author|delete|edit|fetch|list|stream|thread|view)$/', $action)) {
         return 'files/' . $action . '.php?id=' . urlencode($id) . '&action=' . urlencode($name);
     }
     // normalize the link
     return normalize_url(array('files', 'file'), $action, $id, $name);
 }
Beispiel #11
0
    // permission denied
} elseif (!$permitted) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // package the files
} else {
    // build a zip archive
    include_once '../shared/zipfile.php';
    $zipfile = new zipfile();
    // get related files from the database
    $items = array();
    if (isset($type) && isset($id)) {
        $items = Files::list_by_date_for_anchor($type . ':' . $id, 0, 20, 'raw');
    }
    // archive each file
    $file_path = $context['path_to_root'] . Files::get_path($type . ':' . $id);
    foreach ($items as $id => $attributes) {
        // read file content
        if ($content = Safe::file_get_contents($file_path . '/' . $attributes['file_name'], 'rb')) {
            // add the binary data
            $zipfile->deflate($attributes['file_name'], Safe::filemtime($file_path . '/' . $attributes['file_name']), $content);
        }
    }
    //
    // transfer to the user agent
    //
    // send the archive content
    if ($archive = $zipfile->get()) {
        // suggest a download
        Safe::header('Content-Type: application/octet-stream');
        // suggest a name for the saved file
Beispiel #12
0
    // back to the anchor page
    if (is_object($anchor) && $anchor->is_viewable()) {
        $context['text'] .= Skin::build_block(Skin::build_link($anchor->get_url(), i18n::s('Back to main page'), 'button'), 'bottom');
    }
    // page tools
    //
    if ($editable) {
        Skin::define_img('IMAGES_EDIT_IMG', 'images/edit.gif');
        $context['page_tools'][] = Skin::build_link(Images::get_url($item['id'], 'edit'), IMAGES_EDIT_IMG . i18n::s('Update this image'), 'basic', i18n::s('Press [e] to edit'), FALSE, 'e');
    }
    // the delete command is available to associates and editors
    if ($item['id'] && (Surfer::is_associate() || is_object($anchor) && $anchor->is_assigned())) {
        Skin::define_img('IMAGES_DELETE_IMG', 'images/delete.gif');
        $context['page_tools'][] = Skin::build_link(Images::get_url($item['id'], 'delete'), IMAGES_DELETE_IMG . i18n::s('Delete this image'));
    }
    // general help on this page
    //
    $help = '<p>' . i18n::s('To save this image on your hard drive, drag the mouse above the image and use the right button. A contextual pop-up menu should appear. Select the adequate command depending on the browser used.') . '</p>';
    $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
    // thumbnail, in an extra box
    //
    if (Surfer::is_associate() && $item['thumbnail_name'] && $item['thumbnail_name'] != $item['image_name']) {
        $url = $context['url_to_root'] . Files::get_path($item['anchor'], 'images') . '/' . $item['thumbnail_name'];
        $context['components']['boxes'] .= Skin::build_box(i18n::s('Thumbnail'), '<img src="' . $url . '" />', 'boxes');
    }
    // referrals, if any
    //
    $context['components']['referrals'] =& Skin::build_referrals(Images::get_url($item['id']));
}
// render the skin
render_skin();
Beispiel #13
0
 /**
  * upload a file as a image attach to a given anchor
  * to be used in custom "edit_as" script
  * 
  * @global string $context
  * @param object $anchor
  * @param array $file (from $_FILES)
  * @param bool $set_as_thumb
  * @param bool $put
  */
 public static function upload_to($anchor, $file, $set_as_thumb = false, $put = false)
 {
     global $context;
     // attach some image
     $path = Files::get_path($anchor->get_reference(), 'images');
     // $_REQUEST['action'] = 'set_as_icon'; // instruction for image::upload
     if (isset($file) && ($uploaded = Files::upload($file, $path, array('Image', 'upload')))) {
         // prepare image informations
         $image = array();
         $image['image_name'] = $uploaded;
         $image['image_size'] = $file['size'];
         $image['thumbnail_name'] = 'thumbs/' . $uploaded;
         $image['anchor'] = $anchor->get_reference();
         //$combined = array_merge($image, $_FILES);
         // post the image which was uploaded
         if ($image['id'] = Images::post($image)) {
             // successfull post
             $context['text'] .= '<p>' . i18n::s('Following image has been added:') . '</p>' . Codes::render_object('image', $image['id']) . '<br style="clear:left;" />' . "\n";
             // set image as icon and thumbnail
             if ($set_as_thumb) {
                 // delete former icon if any
                 /*if(isset($anchor->item['icon_url'])
                                                         && $anchor->item['icon_url']
                                                         && $match = Images::get_by_anchor_and_name($anchor->get_reference(), pathinfo($anchor->item['icon_url'],PATHINFO_BASENAME))) {
                 
                 
                                                     if($match['id'] != $image['id'])
                                                         Images::delete($match['id']);
                                                 }*/
                 $fields = array('thumbnail_url' => Images::get_thumbnail_href($image), 'icon_url' => Images::get_icon_href($image));
                 if ($put) {
                     $fields['id'] = $_REQUEST['id'];
                     $class = $anchor->get_static_group_class();
                     $class::put_attributes($fields);
                 } else {
                     $_REQUEST = array_merge($_REQUEST, $fields);
                 }
             }
         }
     }
 }
Beispiel #14
0
 if (!($result = SQL::query($query))) {
     $context['text'] .= Logger::error_pop() . BR . "\n";
     return;
     // parse the whole list
 } else {
     // fetch one anchor and the linked member
     $errors_count = 0;
     while ($row = SQL::fetch($result)) {
         // animate user screen and take care of time
         $count++;
         if (!($count % 100)) {
             $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
             // ensure enough execution time
             Safe::set_time_limit(30);
         }
         $file_from = Files::get_path($row['anchor']);
         if (!file_exists($context['path_to_root'] . $file_from . '/' . $row['file_name'])) {
             $errors_count++;
             $anchor = Anchors::get($row['anchor']);
             $context['text'] .= sprintf(i18n::s('Missing: %s'), 'file ' . Skin::build_link(Files::get_url($row['id']), $row['id'] . ' ' . $row['file_name'])) . ' ' . i18n::s('in') . ' ' . (is_object($anchor) ? Skin::build_link($anchor->get_url(), $row['anchor']) : '') . BR . "\n";
         }
     }
 }
 // ending message
 $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
 $context['text'] .= sprintf(i18n::s('%d missing files'), $errors_count) . BR . "\n";
 // display the execution time
 $time = round(get_micro_time() - $context['start_time'], 2);
 $context['text'] .= '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>';
 // forward to the index page
 $menu = array('images/' => i18n::s('Images'));
Beispiel #15
0
 function explode_callback($name)
 {
     global $context;
     // reject all files put in sub-folders
     $file_path = Files::get_path($_REQUEST['anchor'], 'images');
     if (($path = substr($name, strlen($file_path . '/'))) && strpos($path, '/') !== FALSE) {
         Safe::unlink($name);
     } elseif (!($attributes = Safe::GetImageSize($name))) {
         Safe::unlink($name);
     } elseif ($attributes[0] > 5000 || $attributes[1] > 5000) {
         Safe::unlink($name);
     }
 }
Beispiel #16
0
     $_REQUEST['description'] = str_replace("\n", BR, $_REQUEST['description']);
 }
 // append to previous comment during 10 secondes
 if (!isset($item['id']) && ($newest = Comments::get_newest_for_anchor($anchor->get_reference())) && $newest['type'] != 'notification' && Surfer::get_id() && (isset($newest['create_id']) && Surfer::get_id() == $newest['create_id']) && $newest['edit_date'] > gmstrftime('%Y-%m-%d %H:%M:%S', time() - 10)) {
     // copy from previous comment record
     $_REQUEST['id'] = $newest['id'];
     $_REQUEST['create_address'] = $newest['create_address'];
     $_REQUEST['create_date'] = $newest['create_date'];
     $_REQUEST['create_id'] = $newest['create_id'];
     $_REQUEST['create_name'] = $newest['create_name'];
     $_REQUEST['description'] = $newest['description'] . BR . $_REQUEST['description'];
     $_REQUEST['previous_id'] = $newest['previous_id'];
     $_REQUEST['type'] = $newest['type'];
 }
 // attach some file
 $file_path = Files::get_path($anchor->get_reference());
 if (isset($_FILES['upload']) && ($uploaded = Files::upload($_FILES['upload'], $file_path, $anchor->get_reference()))) {
     // sanity check
     if (!$_REQUEST['description']) {
         $_REQUEST['description'] = '';
     }
     // several files have been added
     if (is_array($uploaded)) {
         $_REQUEST['description'] .= '<div style="margin-top: 1em;">' . Skin::build_list(Files::list_for_anchor_and_name($anchor->get_reference(), $uploaded, 'compact'), 'compact') . '</div>';
     } elseif ($file =& Files::get_by_anchor_and_name($anchor->get_reference(), $uploaded)) {
         $_REQUEST['description'] .= '<div style="margin-top: 1em;">[file=' . $file['id'] . ',' . $file['file_name'] . ']</div>';
         // silently delete the previous file if the name has changed
         if (isset($file['file_name']) && $file['file_name'] != $uploaded) {
             Safe::unlink($file_path . '/' . $file['file_name']);
         }
     }