public function cron_job($type)
 {
     sh_cache::disable();
     $start = time();
     if ($type == sh_cron::JOB_HOUR) {
         $this->backupSite();
     }
 }
 public function startPage()
 {
     sh_cache::disable();
     $this->linker->html->setTitle($this->getI18n('startPage_title'));
     $values = array('login' => $this->getParam('models>0>login'));
     $values['links']['try'] = $this->getParam('models>0>link');
     $values['links']['createAccount'] = $this->linker->path->getLink('user/createAccount/');
     $this->render('startPage', $values);
     return true;
 }
Esempio n. 3
0
 public function getForSending()
 {
     sh_cache::disable();
     $mailer = $_GET['mailer'];
     $id = $_GET['id'];
     $extMailer = $this->getParam('mailers>external>name', '');
     $intMailer = $this->getParam('mailers>internal>name', '');
     if ($mailer == $extMailer || $mailer == SH_CUSTOM_PREFIX . $extMailer) {
         $usedMailer = $this->get(true);
     } elseif ($mailer == $intMailer || $mailer == SH_CUSTOM_PREFIX . $intMailer) {
         $usedMailer = $this->get(false);
     } else {
         $this->linker->path->error(404);
     }
     // We decode in order to use iso-8859-1 charset
     echo $usedMailer->nl_getContent($id, false);
     return true;
 }
Esempio n. 4
0
 /**
  * Returns the page from the given uri
  * @param string $page The page we want to translate to uri
  * @return string|bool The uri, or false
  */
 public function translateUriToPage($uri)
 {
     $index = array('/', '/index.php', '/index.php3', '/index.htm', '/index.html');
     if (in_array($uri, $index)) {
         // We check if there is an history
         if (!isset($_SESSION[__CLASS__]['introPageShown'])) {
             // We check if there is an intro page
             if ($this->getParam('intro>activated', false)) {
                 sh_cache::disable();
                 $page = $this->getParam('intro>class') . '/' . $this->getParam('intro>method') . '/';
                 $page .= $this->getParam('intro>id', '');
                 $_SESSION[__CLASS__]['introPageShown'] = true;
                 return $page;
             }
             $_SESSION[__CLASS__]['introPageShown'] = true;
         }
         $page = $this->getParam('class') . '/' . $this->getParam('action') . '/';
         $page .= $this->getParam('id', '');
         return $page;
     }
     if ($uri == '/' . $this->shortClassName . '/' . $this->getI18n('choose_uri') . '.php') {
         $page = $this->shortClassName . '/choose/';
         return $page;
     }
     return parent::translatePageToUri($page);
 }
Esempio n. 5
0
 public function editImage()
 {
     $this->debug(__METHOD__, 2, __LINE__);
     sh_cache::disable();
     $id = (int) $this->linker->path->page['id'];
     $name = $_SESSION[__CLASS__]['uploaded_images'][$id]['name'];
     $srcFolder = $_SESSION[__CLASS__]['uploaded_images'][$id]['src'];
     $destFolder = $_SESSION[__CLASS__]['uploaded_images'][$id]['destination'];
     $filePath = $srcFolder . $name;
     $values['img']['src'] = $this->linker->path->changeToShortFolder($filePath);
     if (file_exists($destFolder . self::DIMENSIONFILE)) {
         // The file has to be resized
         $dims = file_get_contents($destFolder . self::DIMENSIONFILE);
         $margins = !file_exists($destFolder . self::NOMARGINS);
         list($width, $height) = explode('x', $dims);
         $haxFixedDimensions = true;
     } elseif (file_exists($destFolder . self::MAXDIMENSIONFILE)) {
         // The file has to be resized
         $dims = file_get_contents($destFolder . self::MAXDIMENSIONFILE);
         list($width, $height) = explode('x', $dims);
         $haxMaxDimensions = true;
     }
     if (isset($_GET['cancel'])) {
         $this->linker->path->redirect(__CLASS__, __FUNCTION__, $id);
     }
     if (isset($_GET['crop'])) {
         $filePath = $this->crop_image($filePath, $_GET['startX'], $_GET['startY'], $_GET['stopX'], $_GET['stopY']);
         $name = baseName($filePath);
         $_SESSION[__CLASS__]['uploaded_images'][$id]['name'] = $name;
         $this->linker->path->redirect(__CLASS__, __FUNCTION__, $id);
     } elseif (isset($_GET['rotation'])) {
         $rotation = $_GET['rotation'];
         $filePath = $this->rotateImage($filePath, $rotation);
         $_SESSION[__CLASS__]['uploaded_images'][$id]['name'] = basename($filePath);
         $this->linker->path->redirect(__CLASS__, __FUNCTION__, $id);
     }
     if (isset($_GET['action'])) {
         $action = $_GET['action'];
         if ($action == 'crop') {
             if ($margins) {
                 $values['dimensions']['forced'] = true;
                 $values['dimensions']['forcedX'] = $width;
                 $values['dimensions']['forcedY'] = $height;
             } elseif ($haxFixedDimensions) {
                 $values['dimensions']['max'] = true;
                 $values['dimensions']['maxX'] = $width;
                 $values['dimensions']['maxY'] = $height;
             }
             echo $this->render('editor/crop', $values, false, false);
         } elseif ($action == 'rotate') {
             $ext = '.' . array_pop(explode('.', $name));
             $miniPath = $filePath . '.mini';
             copy($filePath, $miniPath . $ext);
             $newFile = $this->resize_image($miniPath . $ext, 100, 100, true);
             $ext = '.png';
             copy($newFile, $miniPath . '.90' . $ext);
             $this->rotateImage($miniPath . '.90' . $ext, 90);
             copy($newFile, $miniPath . '.180' . $ext);
             $this->rotateImage($miniPath . '.180' . $ext, 180);
             copy($newFile, $miniPath . '.270' . $ext);
             $this->rotateImage($miniPath . '.270' . $ext, 270);
             $values['images']['path'] = $this->linker->path->changeToShortFolder($miniPath);
             echo $this->render('editor/rotate', $values, false, false);
         } elseif ($action == 'validate') {
             list($oWidth, $oHeight) = getImageSize($filePath);
             if ($haxFixedDimensions) {
                 $filePath = $this->resize_image($filePath, $width, $height, $margins);
             } elseif ($haxMaxDimensions && ($oWidth > $width || $oHeight > $height)) {
                 $filePath = $this->resize_image($filePath, $width, $height, false);
             } elseif (($oWidth > 900 || $oHeight > 900) && !file_exists($destFolder . self::NOMAXSIZEFILE)) {
                 $filePath = $this->resize_image($filePath, 900, 900, false);
             }
             $name = basename($filePath);
             rename($filePath, $destFolder . $name);
             $this->raiseEvent(self::ONADD, $destFolder);
             $session = $_SESSION[__CLASS__]['uploaded_images'][$id]['browserSession'];
             unset($_SESSION[__CLASS__]['uploaded_images'][$id]);
             header('location: /browser/show.php?type=session&session=' . $session);
             return true;
         }
     } else {
         list($oWidth, $oHeight) = getImageSize($filePath);
         if ($oWidth > $oHeight) {
             $values['img']['direction'] = 'hImage';
         } else {
             $values['img']['direction'] = 'vImage';
         }
         $actions = scandir(SH_CLASS_FOLDER . $this->__tostring() . '/renderFiles/editor/');
         foreach ($actions as $action) {
             if (substr($action, 0, 1) != '.') {
                 $name = substr($action, 0, -7);
                 $values['actions'][] = array('name' => $name, 'description' => $this->getI18n('editor_' . $name));
             }
         }
         echo $this->render('editImage', $values, false, false);
     }
     return true;
 }
Esempio n. 6
0
    }
    return true;
}
// Create the linker object
$linker = sh_linker::getInstance();
$updater = $linker->updater;
define('SH_MOBILE_DEVICE', $linker->session->checkIfIsMobileDevice());
// Verifies if the site can be accessed to any user
$linker->user->siteIsOpen();
// If the file is cached, we show it and exit
if (!$linker->admin->isAdmin()) {
    /*if(!($linker->rights->getUserRights() & sh_rights::RIGHT_READ)){
          $linker->path->error(403);
          exit;
      }*/
    $cache = sh_cache::getCachedFile();
    if ($cache) {
        echo $cache;
        exit(1);
    }
}
// Gets some variables
$element = $linker->path->page['element'];
$action = $linker->path->page['action'];
if (!$linker->{$element}->isMinimal($action)) {
    sh_html::$willRender = true;
}
// Redirect to the 404 error page if the required method doesn't exist.
if (!method_exists($linker->{$element}, $action)) {
    $linker->path->error('404');
}
Esempio n. 7
0
 public function useConnectionTicket_master()
 {
     $this->checkIntegrity();
     sh_cache::disable();
     $id = md5(__CLASS__ . $site . microtime());
     $site = $this->getFromAnyServer('site');
     $siteName = $this->getFromAnyServer('siteName');
     $ticketId = $this->getFromAnyServer('ticket');
     $ticketId = $this->linker->masterServer->uncrypt($ticketId, $site);
     // We look for the ticket
     $ticketsFile = SH_SITE_FOLDER . __CLASS__ . '/tickets/' . $siteName . '.params.php';
     $this->linker->params->addElement($ticketsFile, true);
     $tickets = $this->linker->params->get($ticketsFile, '', null);
     $ticket = $this->linker->params->get($ticketsFile, $ticketId, null);
     if (is_null($ticket)) {
         echo 'Response' . "\n" . self::WRONG_DATA_TEXT . "\n";
         echo sh_masterServer::LINE_SEPARATOR . "\n";
         echo 'text' . "\nELEMENT NOT FOUND!!\n";
         return false;
     }
     if ($ticket['eraseDate'] > date('U') && $ticket['maxUseTimes'] > 0) {
         echo 'response' . "\n" . self::OK . "\n";
         echo sh_masterServer::LINE_SEPARATOR . "\n";
         echo 'id' . "\n";
         echo $ticket['id'];
         $ticket['maxUseTimes']--;
         if ($ticket['maxUseTimes'] == 0) {
             unlink($ticketsFile);
         } else {
             $this->linker->params->set($ticketsFile, $ticketId, $ticket);
             $this->linker->params->write($ticketsFile);
         }
         return true;
     }
     echo 'response' . "\n" . self::DELAY_ELAPSED;
     return false;
 }
 /**
  * public function search
  */
 public function search()
 {
     $this->debug(__FUNCTION__, 3, __LINE__);
     if ($this->getParam('activated', true) === false) {
         $this->linker->path->error(404);
     }
     sh_cache::disable();
     $search = stripslashes(urldecode($_GET['value']));
     $this->linker->html->setTitle($this->getI18n('theQueryWas') . ' [' . str_replace(array('&', '<', '>'), array('&#38;', '&#60;', '&#62;'), $search) . ']');
     $this->activeSearch = $search;
     $search = trim($this->cleanSearchText($search));
     $rfNoResults = 'show_noResults';
     if (strlen(trim($search)) < 3) {
         $values['error']['tooShort'] = true;
         $this->render($rfNoResults, $values);
         return true;
     }
     // Global search
     $allKeyWordsResults = $this->db_execute('searchAllWords', array('search' => $search, 'lang' => $this->linker->i18n->getLang()));
     if (!is_array($allKeyWordsResults)) {
         $this->render($rfNoResults);
         return true;
     }
     // Giving points for the amount of found words in all rows
     $sorted = array();
     foreach ($allKeyWordsResults as $res) {
         $name =& $sorted[$res['class']][$res['method']][$res['id']];
         $name = 1000 - 100 * $res['keywords'];
     }
     // Search in each rows
     $results[0] = $this->db_execute('search', array('search' => $search, 'lang' => $this->linker->i18n->getLang(), 'level' => 1, 'weight' => 8));
     $results[1] = $this->db_execute('search', array('search' => $search, 'lang' => $this->linker->i18n->getLang(), 'level' => 2, 'weight' => 3));
     $results[2] = $this->db_execute('search', array('search' => $search, 'lang' => $this->linker->i18n->getLang(), 'level' => 3, 'weight' => 1));
     // Giving points using Mysql's match return
     foreach ($results as $level => $oneLevelResults) {
         if (!is_null($oneLevelResults)) {
             foreach ($oneLevelResults as $res) {
                 $name =& $sorted[$res['class']][$res['method']][$res['id']];
                 $name -= $res['match'] * $res['weight'];
             }
         }
     }
     // Sorting the results
     foreach ($sorted as $class => &$methods) {
         foreach ($methods as $method => &$elements) {
             asort($elements);
             $counts[$class][$method] = count($elements);
             $elements = array_chunk($elements, 8, true);
             if (count($elements[0]) > 5) {
                 $cpt = 0;
                 foreach ($elements[0] as $id => $content) {
                     $smallResultsList[$id] = $content;
                     if (++$cpt >= 5) {
                         break;
                     }
                 }
                 array_unshift($elements, $smallResultsList);
             } else {
                 array_unshift($elements, $elements[0]);
             }
         }
     }
     // We save the results in the session in order to show some other results
     $searchId = substr(md5($search), 0, 6);
     $_SESSION[__CLASS__]['results'][$searchId] = $sorted;
     $_SESSION[__CLASS__]['results'][$searchId]['search'] = $search;
     // Rendering
     $showingOrder = $this->getParam('showingOrder');
     $resultsLink = $this->translatePageToUri($this->shortClassName . '/showResults/');
     $cpt = 0;
     if (is_array($showingOrder)) {
         foreach ($showingOrder as $type) {
             if (is_array($sorted[$type])) {
                 foreach ($sorted[$type] as $method => $element) {
                     if ($this->linker->method_exists($type, 'searcher_showResults')) {
                         $link = $resultsLink . '?searchId=' . $searchId;
                         $link .= '&scope=' . $type . '&action=' . $method;
                         $rendered = $this->linker->{$type}->searcher_showResults($method, array_keys($element[0]));
                         if (!empty($rendered)) {
                             $values['results'][$cpt] = $rendered;
                             if (isset($element[2]) || count($element[1]) > count($element[0])) {
                                 $values['results'][$cpt]['listLink'] = $link;
                             }
                             if ($counts[$type][$method] > 1) {
                                 $values['results'][$cpt]['count'] = $counts[$type][$method];
                             }
                             $cpt++;
                         }
                     }
                 }
             }
         }
     }
     if (empty($values['results'])) {
         $this->render($rfNoResults);
         return true;
     }
     $this->render('show_results', $values);
     return true;
 }
Esempio n. 9
0
 public function cron_job($type)
 {
     sh_cache::disable();
     $start = time();
     if ($type == sh_cron::JOB_QUARTERHOUR) {
         echo 'Shop : Sending the bills... ';
         // We check if there are any bill to send made
         $bills = $this->getParam('bills_to_create', array());
         if (!empty($bills)) {
             foreach ($bills as $billId => $bill) {
                 if ($time + 60 * 12 > time()) {
                     // We won't take the risk to have 2 cron jobs in the same time trying to do the same thing...
                     // so we stop after 12 minutes
                     echo 'Time is out, so we will continue on next cron job<br />';
                     echo 'Started at ' . $time . ', and time is now ' . ($time + 60 * 12) . '<br />';
                     break;
                 }
                 if ($bill != 'done') {
                     $this->sendBill($bill);
                     $this->setParam('bills_to_create>' . $billId, 'done');
                     $this->writeParams();
                     echo 'One bill has been sent...<br />';
                     flush();
                 }
             }
         } else {
             echo 'There is no bill to create and send';
         }
     } elseif ($type == sh_cron::JOB_HALFDAY) {
         echo 'Shop : Deleting old pending files... ';
         // Cleaning old pending command files (older than 4 hours)
         $timestamp = floatval(date('YmdHi', mktime(date('H') - 4, 0, 0, date('m'), date('d'), date('Y'))));
         $pendingFiles = scandir($this->commandsFolder . 'pending');
         foreach ($pendingFiles as $file) {
             if (substr($file, 0, 1) != '.') {
                 $fileTimestamp = floatval(substr($file, 0, 12));
                 if ($fileTimestamp < $timestamp) {
                     echo 'Removing old pending file ' . $file . '<br />';
                     unlink($this->commandsFolder . 'pending/' . $file);
                     $pendingFilesDeleted = true;
                 }
             }
         }
         if (!$pendingFilesDeleted) {
             echo 'There was no old pending files to delete<br />';
         }
     } elseif ($type == sh_cron::JOB_DAY) {
         // We should update the prices, in case there are discounts that have
         //just started/ended
         echo 'Shop : Caching the prices... ';
         $this->cachePrices();
         echo 'Done!<br />';
     }
     return true;
 }
Esempio n. 10
0
 public function render()
 {
     $this->debug('function : ' . __FUNCTION__, 2, __LINE__);
     self::$willRender = false;
     // We check if there are classes to construct before managing the contents (as they may add some)
     $classes = $this->helper->getClassesSharedMethods(__CLASS__, 'construct');
     foreach ($classes as $class) {
         $tempClass = $this->linker->{$class};
     }
     $tempClass = null;
     // We first prepare the common contents for mobile and complete versions
     $specialContentsClasses = $this->get_shared_methods('add_special_content');
     foreach ($specialContentsClasses as $class) {
         $this->linker->{$class}->add_special_content();
     }
     $data = $this->specialContents;
     $data['html']['isAdminPage'] = $this->helper->isAdminPage();
     if ($data['html']['isAdminPage']) {
         $data['html']['isAdminPage_class'] = 'this_is_an_admin_page';
     } else {
         $data['html']['isAdminPage_class'] = 'this_is_not_an_admin_page';
     }
     $data['body']['headline'] = $this->getHeadLine();
     $data['body']['title'] = $this->getTitle(true);
     $data['body']['content'] = '';
     $data['body']['beforeContent'] = '';
     if (!empty($_SESSION[__CLASS__]['messages_alert'])) {
         $values['messages'] = $_SESSION[__CLASS__]['messages_alert'];
         $data['body']['content'] .= parent::render('message_alert', $values, false, false);
         $data['body']['beforeContent'] .= parent::render('message_alert', $values, false, false);
         unset($_SESSION[__CLASS__]['messages_alert']);
     }
     if (!empty($_SESSION[__CLASS__]['messages_normal'])) {
         $values['messages'] = $_SESSION[__CLASS__]['messages_normal'];
         $data['body']['content'] .= parent::render('message_normal', $values, false, false);
         $data['body']['beforeContent'] .= parent::render('message_normal', $values, false, false);
         unset($_SESSION[__CLASS__]['messages_normal']);
     }
     $data['body']['onlyContent'] = $this->getBodyContent();
     $data['body']['content'] .= $data['body']['onlyContent'];
     $data['body']['logo'] = $this->linker->site->logo;
     $data['body']['copyrights'] = $this->linker->legacy->getLegacyLine();
     $data['body']['analytics'] = $this->linker->googleServices->getAnalytics(true);
     /*if($this->linker->session->checkIfIsMobileDevice()) {
                 // We render using a special template
                 // We only get the first menu for the mobile template
                 $menuNumber = 1;
                 $data['menu'] = $this->linker->menu->getForMobile($menuNumber);
                 $data['language']['selector'] = $this->linker->i18n->getLanguageSelector(true);
                 $data['head']['content'] = $this->getHead(true);
                 // Sending to classic mode
                 $uri = $this->linker->path->url;
                 if(strpos($uri,'?') === false) {
                     $linkerChar = '?';
                 }else {
                     $linkerChar = '&';
                 }
                 $data['mode']['classicLink'] = $uri.$linkerChar.'mode=classic';
                 $variation = $this->linker->site->variation;
                 $data['variation']['background'] = $this->getParam('variation_'.$variation);
     
                 // Rendering
                 $pageContent = parent::render('mobile_template',$data,false,false);
                 $pageContent = str_replace('</body>',$data['body']['adminpanel'].$data['body']['analytics'].'</body>',$pageContent);
                 $pageContent = $this->linker->renderer->toHtml($pageContent);
     
                 $docType = '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd">'."\n";
     
             }else {/**/
     // We render the complete version
     $this->linker->javascript->get(sh_javascript::SCRIPTACULOUS);
     $this->linker->javascript->get(sh_javascript::POPUPS);
     $this->linker->javascript->get(sh_javascript::WINDOW);
     $this->addCSS('main.css', 'MAIN', '/templates/global/global.css', 'GLOBAL');
     $data['language']['selector'] = $this->linker->i18n->getLanguageSelector();
     $loadClasses = $this->linker->template->get('loadClasses', array());
     if (is_array($loadClasses)) {
         foreach ($loadClasses as $loadClass) {
             $this->linker->{$loadClass};
         }
     }
     // Prepares the data for the output
     $this->bodyContent = $this->fromRoot(str_replace('#TEMPLATE_DIR#', $this->template, $this->bodyContent));
     // Sets the variables to fill the output
     $data['body']['adminpanel'] = $this->linker->admin->get();
     $data['body']['searchEngine'] = $this->linker->searcher->get();
     for ($menuNumber = 1; $menuNumber <= $this->menusNumber; $menuNumber++) {
         $data['body']['menu_' . $menuNumber] = $this->linker->menu->get($menuNumber);
     }
     $data['body']['global_image'] = str_replace(SH_ROOT_FOLDER, SH_ROOT_PATH, $this->global_image);
     $data['body']['global_image_text'] = $this->global_image_text;
     $data['diaporamas']['display'] = $this->linker->site->diaporamaDisplay;
     $data['body']['otherContents'] = $this->getOtherContent();
     $data['body']['otherContents'] .= '<script>$$(".toggle_next_element").each(function(el){el.next().addClassName("toggle_keep_hidden")});</script>';
     $data['body']['otherContents'] .= '<style>.toggle_keep_hidden{display:none;}</style>';
     //$data['body']['analytics'] = $this->linker->googleServices->getAnalytics(true);
     $ending = '';
     $data['body']['analytics'] .= '<script type="text/javascript">' . $this->endingScripts . '</script>';
     list($action, $link) = $this->linker->user->getConnectionLink();
     $data[$action]['link'] = $link;
     $data['profile']['link'] = $this->linker->user->getProfileLink();
     // These vars should be built just before rendering,
     // to be sure that they contain everything that is built
     $this->addToBody('class', 'shopsailors_navigator');
     $data['body']['data'] = $this->getBodyData();
     $data['body']['beginning'] = $this->getAfterBody();
     $data['head']['content'] = $this->getHead();
     // Renders the html document
     $template = $this->template . '/template.rf.xml';
     if (!empty($this->specialTemplate)) {
         $template = $this->specialTemplate;
     }
     $pageContent = parent::render($template, $data, false, false);
     $pageContent = str_replace('</body>', $data['body']['adminpanel'] . $data['body']['analytics'] . '</body>', $pageContent);
     $pageContent = $this->linker->renderer->toHtml($pageContent);
     $docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
     /*}/**/
     $cpt = 1;
     $pageContent = str_replace('<html ', '<html xmlns="http://www.w3.org/1999/xhtml" ', $pageContent, $cpt);
     // xmlDeclaration
     $xmlTag = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
     // DocType
     $pageContent = $xmlTag . $docType . $pageContent;
     if ($_SESSION['this_is_a_temp_session']) {
         // We don't cache temp sessions pages
         $pageContent = preg_replace(array('`(src|href)="([^\\?"]*)"`', '`(src|href)="([^"]*)\\?([^"]*)"`'), array('$1="$2?nothing_special=true"', '$1="$2?$3&temp_session=' . $_SESSION['temp_session'] . '"'), $pageContent);
         echo $pageContent;
     } else {
         echo sh_cache::saveCache($pageContent);
     }
 }
Esempio n. 11
0
 public function construct()
 {
     if (!isset($_SESSION)) {
         session_start();
     }
     $installedVersion = $this->getClassInstalledVersion();
     if ($installedVersion != self::CLASS_VERSION) {
         // The class datas are not in the same version as this file, or don't exist (installation)
         $this->setClassInstalledVersion(self::CLASS_VERSION);
     }
     // Sets the main variables
     $this->domain = $_SERVER['SERVER_NAME'];
     $this->pathinfo = pathInfo($_SERVER['REQUEST_URI']);
     if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
         $this->protocol = 'https';
     } else {
         $this->protocol = 'http';
     }
     $request = $_SERVER['REQUEST_URI'];
     $uriParts = explode('?', $request);
     $this->uri = $uriParts[0];
     $this->baseUri = $this->protocol . '://' . $this->domain;
     $this->url = $this->baseUri . $request;
     $this->thisLink = $request;
     $this->parsed_url = parse_url($this->url);
     parse_str($this->parsed_url['query'], $this->parsed_url['parsed_query']);
     // If we're not waiting for an html file :
     if (isset($_GET['path_type']) && $_GET['path_type'] == 'favicon') {
         // We are asking for the favicon image.
         $this->page = array('element' => 'favicon', 'action' => 'get');
     } elseif (isset($_GET['path_type']) && $_GET['path_type'] == 'css') {
         // We are asking for a CSS file.
         $this->page = array('element' => 'css', 'action' => 'get');
         sh_cache::content_is_css();
     } elseif (isset($_GET['path_type']) && $_GET['path_type'] == 'image') {
         // We are asking for an image
         if (isset($_GET['width']) && isset($_GET['height'])) {
             $_GET['file'] .= '.resized.' . $_GET['width'] . '.' . $_GET['height'] . '.png';
         } elseif (isset($_GET['width'])) {
             $_GET['file'] .= '.resizedX.' . $_GET['width'] . '.png';
         } elseif ($_GET['file'] != 'createPreview' && isset($_GET['height'])) {
             //echo '<div><span class="bold">$_GET : </span>'.nl2br( htmlentities( print_r( $_GET, true ) ) ).'</div>';exit;
             $_GET['file'] .= '.resizedY.' . $_GET['height'] . '.png';
         }
         $this->page = array('element' => 'images', 'action' => 'get');
     } elseif (isset($_GET['path_type']) && $_GET['path_type'] == 'menuImage') {
         // We are asking for an image
         $this->page = array('element' => 'images', 'action' => 'get_menuImage');
     } elseif (isset($_GET['path_type']) && $_GET['path_type'] == 'browser') {
         // We are asking for a browser
         $this->page = array('element' => 'browser', 'action' => 'show');
     } elseif (isset($_GET['path_type']) && $_GET['path_type'] == 'mp3') {
         // We are loading a sound
         sh_cache::disable();
         if (file_exists(SH_SITE_FOLDER . 'sh_mp3/' . $_GET['folder'] . $_GET['file'])) {
             header('Content-type: audio/mpeg');
             readfile(SH_SITE_FOLDER . 'sh_mp3/' . $_GET['file']);
             exit;
         }
         $this->error(404);
     } else {
         // Updates the session's history variable, if needed
         if (!isset($_SESSION['history'])) {
             $_SESSION['history'] = array();
         }
         if ($_SESSION['history'][0] != urldecode($request)) {
             array_unshift($_SESSION['history'], urldecode($request));
         }
         if (count($_SESSION['history']) > 10) {
             array_pop($_SESSION['history']);
         }
         // If we don't find the url in the db, we send a 404 error
         $data = $this->getPage($this->uri);
         if (!$data) {
             $this->error(404);
         }
         $this->thisPage = $data;
         $parts = explode('/', $data);
         // Set the $page var with every usefull things
         $this->page = array('element' => $parts[0], 'action' => $parts[1], 'id' => $parts[2], 'page' => $data);
         $this->linker->html->addToBody('class', 'pages_' . $this->page['element']);
         $this->linker->html->addToBody('class', 'pages_' . $this->page['element'] . '_' . $this->page['action']);
         $this->linker->html->addToBody('class', 'pages_' . $this->page['element'] . '_' . $this->page['action'] . '_' . $this->page['id']);
     }
     if (SH_MASTERSERVER && !SH_MASTERISUSER) {
         // We check if the page that is called may be called on a master server
         if (!$this->linker->masterServer->isPathAllowed($this->linker->cleanObjectName($parts[0]), $parts[1])) {
             header('HTTP/1.1 403 Forbidden');
             echo 'ERROR : 403';
             exit;
         }
     }
 }
Esempio n. 12
0
 /**
  * public function get
  *
  */
 public function job()
 {
     sh_cache::disable();
     $log = '';
     $allowed = false;
     list($part1, $part2, $part3, $part4) = explode('.', $_SERVER['REMOTE_ADDR']);
     foreach ($this->getParam('launchers', array()) as $launcher) {
         list($launcherPart1, $launcherPart2, $launcherPart3, $launcherPart4) = explode('.', $_SERVER['REMOTE_ADDR']);
         if ($launcherPart1 == '*') {
             $allowed = true;
             break;
         } elseif ($launcherPart1 == $part1) {
             if ($launcherPart2 == '*') {
                 $allowed = true;
                 break;
             } elseif ($launcherPart2 == $part2) {
                 if ($launcherPart3 == '*') {
                     $allowed = true;
                     break;
                 } elseif ($launcherPart3 == $part3) {
                     if ($launcherPart4 == '*' || $launcherPart2 == $part2) {
                         $allowed = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($allowed) {
         $id = (int) $this->linker->path->page['id'];
         if ($id == 0) {
             // We ask not to launch new actions after 4 minutes, in order
             // not to have 2 jobs running at the same time
             $stopAt = microtime(true) + 4 * 60;
             $ret = true;
             $classes = $this->get_shared_methods();
             $lastLaunchedJobs = $this->getParam('lastLaunchedJobs', array());
             list($now, $y, $m, $d, $h, $i, $s) = explode('-', date('U-Y-m-d-H-i-s'));
             $datesFor = array(self::JOB_YEAR => date('U', mktime($h, $i, $s, $m, $d, $y - 1)), self::JOB_HALFYEAR => date('U', mktime($h, $i, $s, $m - 6, $d, $y)), self::JOB_QUARTERYEAR => date('U', mktime($h, $i, $s, $m - 3, $d, $y)), self::JOB_MONTH => date('U', mktime($h, $i, $s, $m - 1, $d, $y)), self::JOB_WEEK => date('U', mktime($h, $i, $s, $m, $d - 7, $y)), self::JOB_DAY => date('U', mktime($h, $i, $s, $m, $d - 1, $y)), self::JOB_HALFDAY => date('U', mktime($h - 12, $i, $s, $m, $d, $y)), self::JOB_HOUR => date('U', mktime($h - 1, $i, $s, $m, $d, $y)), self::JOB_HALFHOUR => date('U', mktime($h, $i - 30, $s, $m, $d, $y)), self::JOB_QUARTERHOUR => date('U', mktime($h, $i - 15, $s, $m, $d, $y)));
             $method = 'cron_job';
             for ($job = self::JOB_FROM; $job <= self::JOB_TO; $job++) {
                 $lastDate = $lastLaunchedJobs[$job];
                 if (empty($lastDate) || $datesFor[$job] > $lastDate) {
                     $log .= 'Launching a job #' . $job . ' (last : ' . $lastDate . ')' . "\n";
                     foreach ($classes as $class) {
                         if (microtime(true) > $stopAt) {
                             $log .= 'Cron stopped because of its durations. Will be started again later' . "\n";
                             $ret = false;
                             break;
                         }
                         $log .= 'Cron (' . $job . ') on ' . $class . "\n";
                         $tempRet = $this->linker->{$class}->{$method}($job, $stopAt) && $ret !== false;
                         if (!empty($tempRet)) {
                             $ret = $ret && $tempRet;
                         }
                     }
                     if ($ret !== false) {
                         $this->setParam('lastLaunchedJobs>' . $job, date('U'));
                         $this->writeParams();
                     }
                 } else {
                     $log .= 'No need for a cron job #' . $job . '. Last one was on ' . date('Y-m-d \\a\\t H:i:s', $lastDate) . "\n";
                 }
             }
         } else {
             $ret = true;
             $classes = $this->get_shared_methods();
             foreach ($classes as $class) {
                 $method = 'cron_job';
                 $log .= 'Cron (' . $id . ') on ' . $class . "\n";
                 $ret = $this->linker->{$class}->{$method}($id) && $ret;
             }
         }
         $this->helper->writeInFile(SH_TEMP_FOLDER . __CLASS__ . '/' . SH_SITENAME . '_last.log', 'Called cron job is ' . $id . ' - ' . date('H:i:s') . "\n" . $log);
         echo 'OK';
         return $ret;
     }
     echo 'YOU ARE NOT ALLOWED TO LAUNCH CRON JOBS FROM YOUR IP (' . $_SERVER['REMOTE_ADDR'] . ')!' . "\n";
     return false;
 }
 public function confirmSubscription()
 {
     sh_cache::disable();
     $mail = $_GET['mail'];
     $verif = $_GET['verif'];
     $mailer = $this->linker->mailer->get(true);
     $list = $mailer->ml_getAll();
     if (is_array($list)) {
         foreach ($list as $id => $newsletter) {
             $paramsFile = SH_SITEPARAMS_FOLDER . __CLASS__ . '_sub_' . $id;
             $this->linker->params->addElement($paramsFile, true);
             $preliminaryList = $this->linker->params->get($paramsFile, 'needConfirmation', array());
             if (isset($preliminaryList[$mail])) {
                 $date = $preliminaryList[$mail]['date'];
                 if ($date > date('U')) {
                     if ($verif == $preliminaryList[$mail]['verif']) {
                         $this->linker->params->set($paramsFile, 'needConfirmation>' . $mail . '>verif', 'DONE');
                         $this->linker->params->write($paramsFile);
                         $mailer = $this->linker->mailer->get(true);
                         $mailer->ml_addAddress($newsletter['id'], $mail);
                         $values['response']['ok'] = true;
                         $values['response']['validated'] = true;
                     } elseif ('DONE' == $preliminaryList[$mail]['verif']) {
                         $values['response']['ok'] = true;
                         $values['response']['alreadyValidated'] = true;
                     }
                 } else {
                     $values['response']['dateOver'] = true;
                 }
             }
         }
     }
     $values['links']['subscribe'] = $this->translatePageToUri('/subscribe/');
     $values['site']['base'] = $this->linker->path->getBaseUri();
     $this->render('subscription_confirmation', $values);
     return true;
 }
Esempio n. 14
0
 /**
  * This method is automatically called by sh_template when the admin/master
  * changes the template he is using.<br />
  * It does everything that has to be done in this class when it occurs.
  * @param str $template The name of the template that will now be used.
  */
 public function template_change($template)
 {
     // We remove the generated images from the disk
     $this->reset();
     $this->uid = substr(md5(microtime()), 0, 6);
     $this->setParam('uid', $this->uid);
     $this->writeParams();
     //Removes the cache
     sh_cache::removeCache();
     // We check if we can rebuild the menus
     $menus = array_keys($this->linker->template->get('menuButtons'));
     foreach ($menus as $menu) {
         $activated = $this->getParamForMenu($menu, 'activated', true);
         if ($activated) {
             // checking if the menu may be rebuilt
             // We should get the texts from the database and the datas from the params file
             $textHeight = $this->getParamForMenu($menu, 'textHeight', 16);
             $font = $this->getParamForMenu($menu, 'font');
             $entries = $this->getParamForMenu($menu, 'entries');
             foreach ($entries as $entryId => $entry) {
                 $categories[$entryId]['name'] = $this->getI18n($entry['title'], '*');
                 $categories[$entryId]['link'] = $entry['link'];
             }
             $_POST = array('real' => true, 'id' => $menu, 'font' => $font, 'textHeight' => $textHeight, 'sectionsCount' => count($entries), 'categories' => $categories, 'menuState' => true);
             if (!$this->verifyLength(true, $menu)) {
                 if (is_int($menu)) {
                     $this->setParamForMenu($menu, 'activated', false);
                     $this->writeParamsForMenu($menu);
                     $_SESSION[__CLASS__]['template_change_deactivated_menu'] = true;
                 }
             } else {
                 $this->updateDB($menu);
             }
         }
     }
     return true;
 }
Esempio n. 15
0
 /**
  * Verifies if a master session is opened.<br />
  * If so, disables the cache.
  * @static
  * @return boolean
  * True if a master session has been opened.<br />
  * False if not.
  */
 public static function staticIsMaster()
 {
     if ($_SESSION[__CLASS__]['master']) {
         sh_cache::disable();
         return true;
     }
     return false;
 }
Esempio n. 16
0
 public function edit()
 {
     $this->debug(__FUNCTION__ . '();', 2, __LINE__);
     sh_cache::disable();
     if (!$this->linker->user->isConnected()) {
         $this->linker->path->error(403);
         exit;
     }
     // There are 3 possibilities :
     //  - the user is an admin/master
     //      He can set rights on any documents
     //      He can give rights_managements rights to others for the documents he can manage
     //  - the user has rights_managements right
     //      He can view his own rights on the documents he has access to
     //      He can allow other users/groups to access the documents
     //  - the user is a simple user
     //      He can view his rights on the documents he has access to
     // We list all the rights this user has access to
     $user = $this->user;
     // We get the user's groups
     $groups_for_query = $this->getUserGroups($user);
     foreach ($groups_for_query as $group) {
         $groups[] = $group['group_id'];
     }
     if ($this->isAdmin()) {
         $pages = $this->db_execute('get_all_manager_pages', array());
         $this->showManagerPages($pages);
     } elseif ($this->isManager($user)) {
         $pages = $this->db_execute('get_manager_pages', array('user_id' => $user));
         $this->showManagerPages($pages);
     } else {
         echo 'The user has no management rights<br />';
     }
 }
Esempio n. 17
0
 public function connect($as = self::CONNECT_AS_USER)
 {
     sh_cache::removeCache();
     if ($as == self::CONNECT_AS_MASTER) {
         $_SESSION[__CLASS__]['admin'] = true;
         $_SESSION[__CLASS__]['master'] = true;
         $_SESSION[__CLASS__]['user'] = true;
         $_SESSION[__CLASS__]['newConnexion'] = true;
         $this->admin = true;
         $this->master = true;
         $this->linker->events->onMasterConnection();
         return true;
     }
     if ($as == self::CONNECT_AS_ADMIN) {
         $_SESSION[__CLASS__]['master'] = false;
         $_SESSION[__CLASS__]['admin'] = true;
         $_SESSION[__CLASS__]['user'] = true;
         $_SESSION[__CLASS__]['newConnexion'] = true;
         $this->master = false;
         $this->admin = true;
         $this->linker->events->onAdminConnection();
         return true;
     }
     $_SESSION[__CLASS__]['admin'] = false;
     $_SESSION[__CLASS__]['master'] = false;
     $_SESSION[__CLASS__]['user'] = true;
     $_SESSION[__CLASS__]['newConnexion'] = true;
     $this->master = false;
     $this->admin = false;
     $this->linker->events->onUserConnection();
     return true;
 }
 public function setCryptingCode()
 {
     sh_cache::disable();
     $site = urldecode(stripslashes($_POST['site']));
     $crypting_key = urldecode(stripslashes($_POST['crypting_key']));
     $site = $this->linker->crypter->uncrypt($site, md5(__CLASS__));
     $crypting_key = $this->linker->crypter->uncrypt($crypting_key, md5(__CLASS__));
     // We save those datas in the params file
     $this->setParam('sites>' . $site, $crypting_key);
     $this->writeParams();
     $ok = $this->linker->crypter->crypt('OK', $crypting_key);
     echo $ok;
     exit;
 }
Esempio n. 19
0
 public static function content_is_css()
 {
     self::$isCss = true;
 }
Esempio n. 20
0
 public function callPage()
 {
     $this->debug(__FUNCTION__, 3, __LINE__);
     sh_cache::disable();
     $id = $this->linker->path->page['id'];
     if ($this->getParam('callPage>' . $id, false)) {
         $session = $this->getParam('callPage>' . $id);
         $bank = $this->get($session['bank']);
         $method = $session['method'];
         if ($this->linker->method_exists($bank, $method)) {
             return $bank->{$method}($session['id'], $id);
         }
     }
     return false;
 }
Esempio n. 21
0
 public function test()
 {
     $this->onlyMaster();
     sh_cache::disable();
     if (isset($_GET['rf'])) {
         $rf = $_GET['rf'];
         $values = array();
         if (file_exists(dirname(__FILE__) . '/renderFiles/tests/' . $rf . '.values.php')) {
             include dirname(__FILE__) . '/renderFiles/tests/' . $rf . '.values.php';
         }
         $this->render('tests/' . $rf, $values);
         return true;
     }
     $this->linker->html->insert('L\'url doit se finir par ?rf=nom_du_rf_sans_extension');
     return false;
 }