Example #1
0
 function action_settings($args)
 {
     global $manager, $tree, $user, $lang;
     /* Get all admins */
     $admins = $manager->adminHandlers;
     /* Sort admins based on position */
     $compare_position = create_function('$a, $b', 'return ($a["position"] == $b["position"]) ? 0 : (($a["position"] < $b["position"]) ? -1 : 1);');
     uasort($admins, $compare_position);
     /* Decode arguments */
     $current = '';
     if (count($args)) {
         $current = array_shift($args);
     }
     if ($current == '' && count($admins)) {
         $current = key($admins);
     }
     reset($admins);
     // Setup template
     $page = new admin();
     // Notify plugins of a PreSkinParse event;
     $data = array('page' => &$page, 'template' => &$page->template, 'type' => 'admin', 'params' => array('action' => 'admin', 'args' => $args));
     $manager->handleEvent('PreSkinParse', $data);
     // Handle authorisation
     $ticket = false;
     if (isset($_REQUEST['ticket'])) {
         if (ticket::authorize($_REQUEST['ticket']) == $current) {
             $ticket = true;
         }
     }
     if ($ticket || $user->root() || $user->admin() && $admins[$current]['public']) {
         $t = new Template($this->getTemplate('tab.template'));
         $t->set('tabs', $admins);
         $t->set('current', $current);
         $page->template->set('tabs', $t->fetch());
         $manager->handleAdmin($current, $data);
         $page->show();
     } else {
         header('Location: ' . url::root());
         exit;
     }
 }
Example #2
0
 function action_stream($args)
 {
     global $tree;
     if (count($args)) {
         $filename = array_shift($args);
         $res = sql::query("\r\n\t\t\t\t\tSELECT \r\n\t\t\t\t\t\t* \r\n\t\t\t\t\tFROM \r\n\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents_movie \r\n\t\t\t\t\tWHERE \r\n\t\t\t\t\t\tfilename='" . addslashes($filename) . "'\r\n\t\t\t\t");
         if ($row = sql::fetch_array($res)) {
             if ($item =& $tree->getItemById($row['ID'])) {
                 $ticket = false;
                 if (isset($_REQUEST['ticket'])) {
                     if (ticket::authorize($_REQUEST['ticket']) == $item['id']) {
                         $ticket = true;
                     }
                 }
                 if ($ticket || $item['visible']) {
                     if ($fp = fopen(_BASE_MEDIA_ . 'movies/' . $row['filename'], 'rb')) {
                         ob_end_clean();
                         header("Content-Encoding: none");
                         header("Accept-Ranges: bytes");
                         /* Determine the ranges requested */
                         $ranges = array();
                         $multiple = false;
                         if (isset($_SERVER['HTTP_RANGE'])) {
                             $r = explode(',', $_SERVER['HTTP_RANGE']);
                             $errors = false;
                             if (count($r) > 1) {
                                 $multiple = true;
                             }
                             while (list(, $range) = each($r)) {
                                 if (preg_match('/([0-9]*)-([0-9]*)/', $range, $matches)) {
                                     if ($matches[1] != '') {
                                         $start = intval($matches[1]);
                                     } else {
                                         $start = null;
                                     }
                                     if ($matches[2] != '') {
                                         $end = intval($matches[2]);
                                     } else {
                                         $end = null;
                                     }
                                     if (is_numeric($start) && is_numeric($end)) {
                                         if ($start > $end || $end >= $row['size']) {
                                             $errors = true;
                                         } else {
                                             $ranges[] = array('start' => $start, 'length' => $end - $start + 1, 'end' => $end);
                                         }
                                     }
                                     if (is_numeric($start) && is_null($end)) {
                                         if ($start >= $row['size']) {
                                             $errors = true;
                                         } else {
                                             $ranges[] = array('start' => $start, 'length' => $row['size'] - $start, 'end' => $row['size'] - 1);
                                         }
                                     }
                                     if (is_null($start) && is_numeric($end)) {
                                         if ($end > $row['size']) {
                                             $errors = true;
                                         } else {
                                             $ranges[] = array('start' => $row['size'] - $end, 'length' => $end, 'end' => $row['size'] - 1);
                                         }
                                     }
                                 }
                             }
                             // We've encountered an invalid range and
                             // There are no ranges left to satify
                             if ($errors && !count($ranges)) {
                                 // Fall back to full contents
                                 if (isset($_SERVER['HTTP_IF_RANGE'])) {
                                     $multiple = false;
                                 } else {
                                     header('HTTP/1.1 416 Requested Range Not Satisfiable');
                                     header('Content-Range: bytes */' . $row['size']);
                                     header('Content-Type: ' . $row['type']);
                                     exit;
                                 }
                             }
                         }
                         // A single range or a full download
                         if (!$multiple) {
                             if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/i", $_SERVER['HTTP_USER_AGENT'])) {
                                 header('Cache-control: private');
                                 header('Content-Type: application/force-download');
                                 header('Content-Disposition: inline; filename="' . $row['name'] . '"');
                             } else {
                                 header('Content-Type: ' . $row['type']);
                                 header('Content-Disposition: attachment; filename="' . $row['name'] . '"');
                                 header('Content-Length: ' . $row['size']);
                             }
                             // Single range
                             if (count($ranges)) {
                                 list(, $range) = each($ranges);
                                 header('HTTP/1.1 206 Partial Content');
                                 header('Content-Range: bytes ' . $range['start'] . '-' . $range['end'] . '/' . $row['size']);
                                 fseek($fp, $range['start']);
                                 print fread($fp, $range['length']);
                             } else {
                                 while (!feof($fp)) {
                                     print fread($fp, 1024 * 8);
                                     flush();
                                 }
                             }
                         } else {
                             $boundary = 'dashboard_' . md5($row['filename'] . date('YMdHis'));
                             header("HTTP/1.1 206 Partial Content");
                             header("Content-type: multipart/byteranges; boundary=" . $boundary);
                             while (list(, $range) = each($ranges)) {
                                 print "--" . $boundary . "\n";
                                 print "Content-Type: " . $row['type'] . "\n";
                                 print "Content-Range: bytes " . $range['start'] . "-" . $range['end'] . "/" . $row['size'] . "\n\n";
                                 fseek($fp, $range['start']);
                                 print fread($fp, $range['length']);
                                 print "\n\n";
                             }
                             print "--" . $boundary . "--\n";
                         }
                         fclose($fp);
                         // Stop processing...
                         // This prevents the templates from loading and
                         // allows us to send our own content
                         exit;
                     }
                 }
             }
         }
     }
 }
Example #3
0
 function action_view($args)
 {
     global $manager, $tree, $config, $user, $lang;
     // If no arguments are provided redirect
     if (!count($args)) {
         $id = $tree->getHome();
         if (!is_null($id)) {
             header('Location: ' . url::item($id));
             exit;
         }
         // There are no pages
         $id = 0;
         $type = '';
         $ext = '';
         $item = null;
         if ($user->admin()) {
             // Allow admins to add pages...
             $action = 'edit';
             $page = new admin();
             // Notify plugins of a PreSkinParse event;
             $data = array('page' => &$page, 'template' => &$page->template, 'type' => $type, 'params' => array('action' => $action, 'id' => $id, 'ext' => $ext, 'args' => $args));
             $manager->handleEvent('PreSkinParse', $data);
             $page->show();
             exit;
         } else {
             if ($lang->id != _DEFAULT_LANGUAGE_) {
                 // Redirect to the default language
                 header('Location: ' . url::language(_DEFAULT_LANGUAGE_));
             } else {
                 // Show error message that website is offline
                 $config = new config();
                 $lang = new language(_DEFAULT_LANGUAGE_, _DEFAULT_SITE_, true);
                 $page = new theme();
                 $page->showError(_OFFLINE_MESSAGE_, 4);
             }
         }
     } else {
         // Decode argumenst
         $id = array_shift($args);
         // Check if the id contains an file extension
         if (preg_match('/(.*)\\.([a-z0-9]+)$/i', $id, $matches)) {
             $id = $matches[1];
             $ext = $matches[2];
         } else {
             $ext = '';
         }
         // Load the page
         $item =& $tree->getItemById($id);
         $id = $item['id'];
         $type = $item['type'];
         $action = 'view';
         // Setup Theme
         $page = new theme($id, $type);
     }
     // Notify plugins of a PreSkinParse event;
     $data = array('page' => &$page, 'template' => &$page->template, 'type' => $type, 'params' => array('action' => $action, 'id' => $id, 'ext' => $ext, 'args' => $args));
     $manager->handleEvent('PreSkinParse', $data);
     // Handle authorisation
     $ticket = false;
     if (isset($_REQUEST['ticket'])) {
         if (ticket::authorize($_REQUEST['ticket']) == $data['params']['id']) {
             $ticket = true;
         }
     }
     if ($ticket || $tree->_hasRights('view', $item['rights'])) {
         $page->title->set($item['name']);
         if ($item['title'] != '') {
             $page->title->set($item['title']);
         }
         $manager->handleType($type, $data);
         $page->template->set('action', $action);
         $page->template->set('id', $id);
         $page->template->set('slug', isset($item['slug']) ? $item['slug'] : '');
         $page->template->set('type', $type);
         if (isset($item)) {
             if (!isset($manager->types[$item['type']]['generated']) || !$manager->types[$item['type']]['generated']) {
                 if ($config->get('showLastModified')) {
                     $page->template->set('modified', revisions::getModificationDate($id, $item['revision']));
                 }
             }
         }
     } else {
         if ($config->get('redirectToLogin') && $user->anonymous()) {
             array_unshift($args, $id);
             $manager->handleAction('login', $args);
             //header ('Location: ' . url::item($id, 'login'));
             exit;
         } else {
             $page->template->set('error', $lang->s('notenoughrights'));
         }
     }
     $page->show();
 }