Ejemplo n.º 1
0
 /**
  * Creates a link to a fav icon.
  * Output example:
  * <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  * <link rel="icon" href="/favicon.ico" type="image/x-icon" />
  * @param type $path 
  */
 public function faviconLink($path)
 {
     $relativePath = Path::relativePath($path);
     $html = '<link rel="shortcut icon" href="' . $relativePath . '" type="image/x-icon" />';
     $html .= '<link rel="icon" href="' . $relativePath . '" type="image/x-icon" />';
     echo $html;
 }
Ejemplo n.º 2
0
 /**
  * Loads the given configs into \Pvik\Core\Config.
  * @param array $configPaths
  * @return \Pvik\Core\Core
  */
 public function loadConfig(array $configPaths)
 {
     foreach ($configPaths as $configPath) {
         Config::load(Path::realPath($configPath));
     }
     Log::writeLine('[Info] Loaded: ' . implode(",", $configPaths));
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Checks if the value is a file.
  * @return ValidationState 
  */
 public function validation()
 {
     parent::validation();
     if ($this->validationState->getError($this->fieldName) == null && !is_file(\Pvik\Core\Path::realPath($this->getPOST()))) {
         $this->validationState->setError($this->fieldName, 'Must be a valid file.');
     }
     return $this->validationState;
 }
Ejemplo n.º 4
0
 /**
  * Updates the model.
  */
 public function update()
 {
     $fieldName = $this->fieldName;
     $field = $this->configurationHelper->getField($fieldName);
     // wrong 'UseField' configuration
     if (!isset($field['UseField']) || !$this->fieldDefinitionHelper->fieldExists($field['UseField'])) {
         throw new \Exception('PvikAdminTools: UseField for ' . $fieldName . ' is not set up correctly. UseField is missing or it the stated field does not exists.');
     }
     $useField = $field['UseField'];
     $this->model->{$fieldName} = filesize(\Pvik\Core\Path::realPath($this->getPOST($useField)));
 }
Ejemplo n.º 5
0
 /**
  * 
  */
 public function __construct()
 {
     $this->logTrace = array();
     $date = new \DateTime();
     if (Config::$config['Log']['UseOneFile'] == false) {
         $generatedFilePath = Path::realPath('~/logs') . '/log-' . $date->getTimestamp() . '.txt';
     } else {
         $generatedFilePath = Path::realPath('~/logs/log-file.txt');
     }
     $this->logFileHandle = fopen($generatedFilePath, 'w');
 }
Ejemplo n.º 6
0
 /**
  * Logic for uploading a file.
  */
 public function uploadFileAction()
 {
     if ($this->checkPermission()) {
         $validationState = new ValidationState();
         $uploaded = false;
         // post data send
         if ($this->request->isPOST('submit')) {
             $folders = \Pvik\Core\Config::$config['PvikAdminTools']['FileFolders'];
             $selectedFolder = $this->request->getPOST('folder');
             $folderValid = false;
             foreach ($folders as $folder) {
                 if ($selectedFolder == $folder) {
                     $folderValid = true;
                     break;
                 }
             }
             if ($folderValid && isset($_FILES['file']) && $_FILES['file']['error'] == 0) {
                 $fileName = $_FILES['file']['name'];
                 if ($this->request->isPOST('name') && $this->request->getPOST('name') != '') {
                     $fileName = $this->request->getPOST('name');
                 }
                 $diretoryName = dirname(\Pvik\Core\Path::realPath($selectedFolder . $fileName));
                 if (!is_dir($diretoryName)) {
                     if (!mkdir($diretoryName, 0777, true)) {
                         $validationState->setError('File', 'error creating folder');
                     }
                 }
                 if ($validationState->isValid()) {
                     move_uploaded_file($_FILES['file']['tmp_name'], \Pvik\Core\Path::realPath($selectedFolder . $fileName));
                     $uploaded = true;
                 }
             } else {
                 $validationState->setError('File', 'error uploading');
             }
         }
         $this->viewData->set('ValidationState', $validationState);
         $this->viewData->set('Uploaded', $uploaded);
         $this->executeView();
     }
 }
Ejemplo n.º 7
0
 /**
  * Tries to load a class.
  * @param String $class  
  */
 protected function loadClass($class)
 {
     if ($class[0] !== '\\') {
         $class = '\\' . $class;
     }
     $name = $class;
     foreach ($this->getNamespaceAssociationList() as $namespace => $path) {
         if (strpos($name, $namespace . '\\') === 0) {
             // starts with
             $name = str_replace($namespace, $path, $name);
             break;
         }
     }
     $path = str_replace('\\', '/', $name);
     $path = str_replace('//', '/', $path);
     $path = Path::realPath($path . '.php');
     if (file_exists($path)) {
         require $path;
         if (class_exists('\\Pvik\\Core\\Log')) {
             Log::writeLine('[Include] ' . $path);
         }
         return true;
     }
 }
Ejemplo n.º 8
0
 /**
  * Tries to show an error page for an exception.
  * @param \Exception $exception 
  */
 public static function showErrorPage(\Exception $exception)
 {
     try {
         $exceptionClass = get_class($exception);
         $errorPages = Config::$config['ErrorPages'];
         if (isset($errorPages[$exceptionClass])) {
             $file = Path::realPath($errorPages[$exceptionClass]);
             if (file_exists($file)) {
                 self::executeErrorPage($exception, $file);
             } else {
                 throw new \Exception('Erropage ' . $file . ' not found');
             }
         } else {
             $file = Path::realPath($errorPages['Default']);
             if (file_exists($file)) {
                 self::executeErrorPage($exception, $file);
             } else {
                 throw new \Exception('Erropage ' . $file . ' not found');
             }
         }
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
 }
Ejemplo n.º 9
0
<?php

require "lessc.inc.php";
chdir('../');
// set up path mapper
require './Library/Pvik/Core/Path.php';
\Pvik\Core\Path::Init();
// set up class loader
require \Pvik\Core\Path::RealPath('~/Library/Pvik/Core/ClassLoader.php');
$ClassLoader = new \Pvik\Core\ClassLoader();
$ClassLoader->SetNamespaceAssociation('\\Pvik', '~/Library/Pvik/');
$ClassLoader->SetNamespaceAssociation('\\Dashbird', '~/Application/');
$ClassLoader->Init();
$Core = new \Pvik\Core\Core();
$Core->LoadConfig(array('~/Application/Configs/DefaultConfig.php', '~/Application/Configs/Config.php'));
$less = new lessc();
$css = $less->compileFile(Pvik\Core\Path::RealPath("~/Application/less/dashboard.less"));
// delete previous files
$regex = '/^dashbird-/';
if ($fileHandle = opendir(\Pvik\Core\Path::RealPath('~/css/'))) {
    while (false !== ($file = readdir($fileHandle))) {
        if (preg_match($regex, $file)) {
            unlink(\Pvik\Core\Path::RealPath('~/css/' . $file));
        }
    }
    closedir($fileHandle);
}
$Version = Pvik\Core\Config::$Config['Version'];
file_put_contents(Pvik\Core\Path::RealPath('~/css/dashbird-' . $Version . '.css'), $css);
Ejemplo n.º 10
0
 /**
  * Redirect to a url via setting the location in the header.
  * @param string $path 
  */
 protected function redirectToPath($path)
 {
     $relativePath = Path::relativePath($path);
     header("Location: " . $relativePath);
 }
Ejemplo n.º 11
0
<?php

error_reporting(E_ALL ^ E_NOTICE);
// set up path mapper
require './Library/Pvik/Core/Path.php';
\Pvik\Core\Path::Init();
// set up class loader
require \Pvik\Core\Path::RealPath('~/Library/Pvik/Core/ClassLoader.php');
$ClassLoader = new \Pvik\Core\ClassLoader();
$ClassLoader->SetNamespaceAssociation('\\Pvik', '~/Library/Pvik/');
$ClassLoader->SetNamespaceAssociation('\\Dashbird', '~/Application/');
$ClassLoader->SetNamespaceAssociation('\\PvikAdminTools', '~/Library/PvikAdminTools');
$ClassLoader->Init();
$Core = new \Pvik\Core\Core();
$Core->LoadConfig(array('~/Application/Configs/DefaultConfig.php', '~/Application/Configs/Config.php', '~/Application/Configs/PvikAdminTools.php', '~/Library/PvikAdminTools/Configs/Configure.php'));
$Core->StartWeb();
Ejemplo n.º 12
0
 /**
  * Fetches the current url and converts it to a pretty url
  * @return string
  */
 protected function fetchUrl()
 {
     // get the file base
     $requestUri = $_SERVER['REQUEST_URI'];
     // Delete Parameters
     $queryStringPos = strpos($requestUri, '?');
     if ($queryStringPos !== false) {
         $requestUri = substr($requestUri, 0, $queryStringPos);
     }
     // urldecode for example cyrillic charset
     $requestUri = urldecode($requestUri);
     $url = substr($requestUri, strlen(Path::getRelativeFileBase()));
     if (strlen($url) != 0) {
         // add a / at the start if not already has
         if ($url[0] != '/') {
             $url = '/' . $url;
         }
         // add a / at the end if not already has
         if ($url[strlen($url) - 1] != '/') {
             $url = $url . '/';
         }
     } else {
         $url = '/';
     }
     $this->url = $url;
     return $this->url;
 }
Ejemplo n.º 13
0
$Core = new \Pvik\Core\Core();
$Core->LoadConfig(array('~/Application/Configs/DefaultConfig.php', '~/Application/Configs/Config.php'));
$Version = \Pvik\Core\Config::$Config['Version'];
$Files = array('~/Application/js/simple-js-lib/base-object.js', '~/Application/js/simple-js-lib/event-handler.js', '~/Application/js/simple-js-lib/single-request-queue.js', '~/Application/js/simple-js-lib/observable.js', '~/Application/js/simple-js-lib/mapping-array.js', '~/Application/js/dashbird/_.js', '~/Application/js/dashbird/controllers/_.js', '~/Application/js/dashbird/controllers/post.js', '~/Application/js/dashbird/controllers/posts.js', '~/Application/js/dashbird/controllers/user.js', '~/Application/js/dashbird/controllers/utils/_.js', '~/Application/js/dashbird/controllers/utils/ajax.js', '~/Application/js/dashbird/controllers/utils/ajax-response.js', '~/Application/js/dashbird/models/_.js', '~/Application/js/dashbird/models/comment.js', '~/Application/js/dashbird/models/comments.js', '~/Application/js/dashbird/models/post.js', '~/Application/js/dashbird/view-models/_.js', '~/Application/js/dashbird/view-models/activity-feed.js', '~/Application/js/dashbird/view-models/comment-feed.js', '~/Application/js/dashbird/view-models/comment.js', '~/Application/js/dashbird/view-models/comments.js', '~/Application/js/dashbird/view-models/post-feed.js', '~/Application/js/dashbird/view-models/post.js', '~/Application/js/dashbird/view-models/bbcode/_.js', '~/Application/js/dashbird/view-models/bbcode/bold.js', '~/Application/js/dashbird/view-models/bbcode/image.js', '~/Application/js/dashbird/view-models/bbcode/link.js', '~/Application/js/dashbird/view-models/bbcode/video.js', '~/Application/js/dashbird/view-models/commands/_.js', '~/Application/js/dashbird/view-models/commands/base.js', '~/Application/js/dashbird/view-models/commands/comment.js', '~/Application/js/dashbird/view-models/commands/edit.js', '~/Application/js/dashbird/view-models/commands/remove.js', '~/Application/js/dashbird/view-models/commands/share.js', '~/Application/js/dashbird/view-models/utils/_.js', '~/Application/js/dashbird/view-models/utils/drawing-manager.js', '~/Application/js/dashbird/views/_.js', '~/Application/js/dashbird/views/board/_.js', '~/Application/js/dashbird/views/board/feed.js', '~/Application/js/dashbird/views/board/latest.js', '~/Application/js/dashbird/views/board/new-post.js', '~/Application/js/dashbird/views/board/notification.js', '~/Application/js/dashbird/views/board/search.js', '~/Application/js/dashbird/views/board/single-view.js', '~/Application/js/dashbird/views/board/stack.js', '~/Application/js/dashbird/views/utils/_.js', '~/Application/js/dashbird/views/utils/modal.js', '~/Application/js/dashbird/views/utils/view-model-posts-manager.js', '~/Application/js/dashbird/views/utils/templates.js', '~/Application/js/dashbird/utils.js', '~/Application/js/dashbird/views/board/bootstrap.js');
$PostsJavascript = '';
foreach ($Files as $File) {
    $PostsJavascript .= file_get_contents(\Pvik\Core\Path::RealPath($File)) . "\n";
}
// delete empty lines
$PostsJavascript = str_replace("\n\n", "\n", $PostsJavascript);
$Files = array('~/Application/js/simple-js-lib/base-object.js', '~/Application/js/dashbird/_.js', '~/Application/js/dashbird/controllers/_.js', '~/Application/js/dashbird/controllers/user.js', '~/Application/js/dashbird/controllers/user-settings.js', '~/Application/js/dashbird/controllers/utils/_.js', '~/Application/js/dashbird/controllers/utils/ajax.js', '~/Application/js/dashbird/controllers/utils/ajax-response.js', '~/Application/js/dashbird/views/_.js', '~/Application/js/dashbird/views/settings/_.js', '~/Application/js/dashbird/views/settings/settings.js', '~/Application/js/dashbird/views/settings/bootstrap.js');
$SettingsJavascript = '';
foreach ($Files as $File) {
    $SettingsJavascript .= file_get_contents(\Pvik\Core\Path::RealPath($File)) . "\n";
}
// delete empty lines
$SettingsJavascript = str_replace("\n\n", "\n", $SettingsJavascript);
// delete previous files
$regex = '/^dashbird-developer-/';
if ($fileHandle = opendir(\Pvik\Core\Path::RealPath('~/js/'))) {
    while (false !== ($file = readdir($fileHandle))) {
        if (preg_match($regex, $file)) {
            unlink(\Pvik\Core\Path::RealPath('~/js/' . $file));
        }
    }
    closedir($fileHandle);
}
// write new files
file_put_contents(\Pvik\Core\Path::RealPath('~/js/dashbird-developer-' . $Version . '.js'), $PostsJavascript);
file_put_contents(\Pvik\Core\Path::RealPath('~/js/dashbird-developer-settings-' . $Version . '.js'), $SettingsJavascript);
Ejemplo n.º 14
0
 /**
  * Adds a table footer to the html.
  */
 protected function addHtmlTableFooter()
 {
     $modelTable = $this->entityArray->getModelTable();
     $this->html .= '<tr>';
     $newButtonUrl = \Pvik\Core\Path::relativePath('~' . \Pvik\Core\Config::$config['PvikAdminTools']['Url']) . 'tables/' . strtolower($modelTable->getModelTableName()) . ':new';
     if ($this->newButtonPresetValues != null) {
         $newButtonUrl .= '/';
         $first = true;
         foreach ($this->newButtonPresetValues as $key => $value) {
             if ($first) {
                 $first = false;
             } else {
                 $newButtonUrl .= ':';
             }
             $newButtonUrl .= strtolower($key) . ':' . $value;
         }
     }
     $newButtonUrl .= '/';
     if ($this->buttonRedirectBack != null) {
         $newButtonUrl .= '?redirect-back-url=' . urlencode($this->buttonRedirectBack);
     }
     for ($index = 0; $index < $this->columns; $index++) {
         if ($index + 1 == $this->columns) {
             // last column
             $this->html .= '<td class="options">[';
             $this->html .= '<a href="' . $newButtonUrl . '">new</a>';
             $this->html .= ']</td>';
         } else {
             $this->html .= '<td>';
             $this->html .= '</td>';
         }
     }
     $this->html .= '</tr>';
 }
Ejemplo n.º 15
0
	vertical-align: baseline;
}
a {text-decoration:none;}
ul {list-style-type: none;}
table {
	border-collapse: collapse;
	border-spacing: 0;
}

/* formatting */
body {font-family: "Courier New";color:black;font-size: 12px;}
#content {width: 500px;margin: 40px auto ;}

h1 {font-weight:bold;}
h1 {font-size:24px;}
p {margin: 20px 5px;}
img {margin: 0px 15px;float: left;}
</style>
</head>
<body>
<div id="content">
<h1>Under Construction</h1>
<p><img alt="" src="<?php 
echo \Pvik\Core\Path::RelativePath('~/images/under-construction.jpg');
?>
" />Sorry, but this page is currently unavailable during a normal update proccess. Please try it in a few minutes again. You can contact me via my email address: admin@website.com. Feel free to ask anything.</p>
</div>
</body>
</html>

Ejemplo n.º 16
0
 /**
  * Returns a relative file path with the PvikAdminTools base path.
  * @param string $path
  * @return string 
  */
 public static function fileRelativePath($path)
 {
     return \Pvik\Core\Path::relativePath(\Pvik\Core\Config::$config['PvikAdminTools']['BasePath'] . $path);
 }
Ejemplo n.º 17
0
 /**
  * Shortcut to Path::realPath function
  * @param string $path
  * @return string
  */
 protected function realPath($path)
 {
     return Path::realPath($path);
 }