Exemplo n.º 1
0
function generate($download, $template = '_pages/_commercials.html')
{
    $tmp = '_tmp/Pefi_COMRES/';
    $retVal = '';
    createDirsInPath($tmp);
    if ($download) {
        $retVal .= downloadCommercialResZip($tmp);
    } else {
        $retVal .= '<p>Did not ask for Zip download...</p>';
    }
    // hopefully there is only one file... TODO rethink
    $zip_files = discoverFiles($tmp, '.zip');
    if (count($zip_files) == 0) {
        $retVal .= "<p>No zip file in dir: {$tmp}</p>";
    } else {
        $zip = new ZipArchive();
        $retValVal = $zip->open($zip_files[0]);
        $zip->extractTo($tmp);
        $zip->close();
        $files = discoverFiles($tmp . 'tmp', '.html');
        $retVal .= '<p>NrOfComResFiles in zip-dir:' . count($files) . "</p>";
        $urls = explode(';', tr('commercials.urls:admin'));
        $retVal .= '<p>NrOfComResURLs in commercials.urls:' . count($urls) . "</p>";
        $i = 0;
        foreach ($files as $file) {
            if ($i < count($urls)) {
                $fName = '_pages/' . $urls[$i++];
                $f = fopen($fName, 'w');
                fwrite($f, "\n<?php \$content = function () { ?>\n");
                fwrite($f, change_strings($file));
                fwrite($f, "\n<?php } ?>\n");
                fwrite($f, "\n<?php include '{$template}'; ?>\n");
                fclose($f);
                $retVal .= "<p>Created file: {$fName} </p>";
            } else {
                $retVal .= '<p>------ Attention sizes of files in zip from outside
                            source is different than number of URLs! ------</p>';
            }
        }
    }
    return $retVal;
}
Exemplo n.º 2
0
if (!$_PEFI->crdntls->can('assets', 'LIST')) {
    redirect_to_login($_PEFI->route->page);
}
$uri = $_REQUEST['page'];
$r = new Pefi_Router($uri, $_PEFI->tr);
$page = $r->page->getKey();
$imgsdir = "images/{$page}";
$imgs = discoverFiles($imgsdir, array('jpg', 'gif', 'png'));
if ($_PEFI->crdntls->can('assets')) {
    if ($todo === 'assets-generatethumbs') {
        $_PEFI->view->content .= thumbs($imgs);
    } elseif ($todo === 'assets-upload') {
        $_PEFI->view->messages[] = upload($imgsdir);
        // images were added: discover again
        $imgs = discoverFiles($imgsdir, array('jpg', 'gif', 'png'));
    }
}
if ($todo !== 'assets-generatethumbs') {
    $_PEFI->view->content = images($imgs);
    if ($_PEFI->crdntls->can('assets')) {
        $_PEFI->view->content .= form($page);
    }
}
$_PEFI->view->title = 'Assets management';
function upload($imgsdir)
{
    if ($_FILES['newImage']['size'] !== 0) {
        $name = basename($_POST['newImageName'] == '' ? strtolower($_FILES['newImage']['name']) : strtolower($_POST['newImageName']), '.jpg');
        $fName = $imgsdir . '/' . $name . '.jpg';
        createDirsInPath($fName);
Exemplo n.º 3
0
Arquivo: util.php Projeto: sziszu/pefi
function publishPage($uri, $with_imgs)
{
    $_PEFI = $GLOBALS['_PEFI'];
    $tr = $_PEFI->tr;
    $files = array();
    // publish current page
    $edit = $_PEFI->tr->getEdit();
    $tr->setEdit(false);
    // publishing has to be done as anonymous user
    $vlog = $tr->get('log.visitor');
    // log.visitor = visitor tracking
    $setlog = $vlog->getData();
    $vlog->setData('1');
    $tr->save($vlog);
    include_once 'pefi_Router.class.php';
    $route = new Pefi_Router($uri, $tr);
    $imgsdir = 'images/' . $route->page->getKey();
    $files[$uri] = cacheFile($route);
    if ($with_imgs) {
        foreach (discoverFiles($imgsdir, array('jpg', 'gif', 'png')) as $f) {
            $files[$f] = $f;
        }
    }
    $server = $tr->get('ftp.server')->getData();
    $ret = '<div>Cached file ' . $files[$uri] . '</div>';
    if (!empty($server) && $server != 'server_address_goes_here') {
        $ret .= ftpFilesToServer($files, $tr->get('ftp.filepref')->getData(), $server, $tr->get('ftp.user')->getData(), $tr->get('ftp.pass')->getData());
    }
    // publishing had to be done as anonymous user, now revert
    $tr->setEdit($edit);
    $vlog->setData($setlog);
    $tr->save($vlog);
    return $ret;
}
Exemplo n.º 4
0
 function path($uri)
 {
     // todo escape module, controller, action
     $module = $controller = $action = '';
     $parts = explode('/', $uri);
     $parts_size = count($parts);
     if ($parts_size >= 1 && $parts[0] === $this->get('adminString')) {
         if ($parts_size >= 2) {
             $module = $parts[1];
         }
         if ($parts_size >= 3) {
             $controller = $parts[2];
         }
         if ($parts_size >= 4) {
             $action = $parts[3];
         }
     }
     return [$module, $controller, $action];
     $uriRemain = '';
     if (strpos($uri, '?')) {
         $uri = substr($uri, 0, strpos($uri, '?'));
     }
     if (strpos($uri, '#')) {
         $uri = substr($uri, 0, strpos($uri, '#'));
         $uriRemain = substr($uri, strpos($uri, '#'));
     }
     // figure out the language, remove part from uri
     $lang = null;
     $langs = $this->get('langUris');
     $urimap = $this->get('urimap');
     // check aliases
     if ($urimap) {
         $urirec = $urimap->getByAlias($uri);
         if ($urirec) {
             $uri = $urirec . getUri();
             $lang = $urirec . getLang();
         }
     }
     if (!$lang) {
         $lang = $this->get('mainLang');
     }
     $this->action = $this->getActionFromURL($this->uri);
     if ($this->action) {
         // frameworks own actions
         $this->page = $this->settings->getByData($this->params['uri'], $this->params['lang'], 'slug');
         $this->pageFile = $this->params['uri'];
     } else {
         // check aliases
         // get page identified with an alias
         $this->page = $this->settings->getByData($this->uri, $this->lang, 'slug');
         // page's unique name (a file in {$this->pageDir}/curr_lang dir)
         if (is_dir("{$this->pageDir}/{$this->lang}")) {
             $this->pageFile = discoverFiles("{$this->pageDir}/{$this->lang}", array($this->page->getKey()), true);
         } else {
             $this->pageFile = array();
         }
         if (count($this->pageFile) > 0) {
             $this->pageFile = $this->pageFile[0];
         } else {
             if (!is_dir($this->params['pageDir'])) {
                 die("Put your pages in {$this->params['pageDir']} directory");
             }
             // page's unique name (a file in {$this->pageDir} dir)
             $this->pageFile = discoverFiles($this->pageDir, array($this->page->getKey()), true);
             if (count($this->pageFile) > 0 && substr(basename($this->pageFile[0]), 0, 1) != '_') {
                 // found in {$this->pageDir} dir, doesn't start with _
                 $this->pageFile = $this->pageFile[0];
             } else {
                 $this->page = $this->settings->get("site.notfound", $this->lang, 'notfound.html', 'admin');
                 $this->pageFile = discoverFiles($this->pageDir, array($this->page->getData()), true);
                 if (count($this->pageFile) > 0) {
                     $this->pageFile = $this->pageFile[0];
                 } else {
                     die("Create dir {$this->pageDir} and the files\n                             index.html and notfound.html inside it.");
                 }
             }
         }
     }
     // check language uris
     $this->params['langURIs'] = array();
     if ($langURIs[0] != 'langsURI') {
         $i = 0;
         foreach ($langURIs as $l) {
             $this->langURIs[$this->params['langs'][$i]] = $l;
             $pos = strpos($this->params['uri'], '/' . $l . '/');
             if ($pos === 0 || $this->params['uri'] === '/' . $l) {
                 $this->params['lang'] = $this->params['langs'][$i];
                 $this->params['langURI'] = $l;
                 $this->params['uri'] = substr($this->params['uri'], strlen($l) + 1);
             }
             $i++;
         }
     }
     // entrance uri from settings
     $defURI = $this->settings->get('site.defURI', '', 'index.html');
     if (strpos($this->params['uri'], '/') === 0) {
         $this->params['uri'] = substr($this->params['uri'], 1);
     }
     if (!$this->params['uri']) {
         $this->params['uri'] = $defURI == 'site.defURI' ? 'index.html' : $defURI;
     }
     $this->params['uri'] = strval($this->params['uri']);
 }
Exemplo n.º 5
0
    $_PEFI->view->content = "Version raised to {$version->getData()}";
} elseif ($todo == 'resetlog') {
    $logger->reset();
    $text = "Log file reseted by {$_PEFI->user->name}.";
    $_PEFI->view->messages[] = $text;
    $logger->info($text);
} elseif ($todo == 'build') {
    $edit = $tr->getEdit();
    $tr->setEdit(False);
    $log = $tr->get('log.visitor');
    $tr->save($tr->get('log.visitor')->setData(1));
    unlinkRecursive('_cache');
    $_PEFI->view->messages[] = 'Cache Cleaned';
    $nr = 1;
    $content = '<ol>';
    foreach (discoverFiles('_pages', '') as $fName) {
        // shouldn't end with ~
        if (!in_array(substr($fName, strlen($fName) - 1, 1), array('~')) && !in_array(substr($fName, 7, 1), array('_'))) {
            $content .= "<li><p>{$fName}</p><ul>";
            foreach ($_PEFI->route->langs as $lang) {
                $route = new Pefi_Router(createURL(basename($fName), $lang), $tr);
                $content .= '<li>' . $lang . ' - ' . cacheFile($route) . '</li>';
            }
            $content .= '</ul></li>';
        }
    }
    $content .= '</ol>';
    $_PEFI->view->content = $content;
    $tr->setEdit($edit);
    $tr->save($log);
} elseif ($todo == 'clearcache') {