Example #1
0
 protected function setUp()
 {
     date_default_timezone_set("Europe/Paris");
     $this->valid_config = array("settings" => array("dinkly_version" => Dinkly::getConfigValue('dinkly_version', 'global')), "apps" => array("frontend" => array("default_app" => true, "default_module" => "landing", "base_href" => "/", "enabled" => true, "app_name" => "Dinkly Frontend", "app_description" => "The humblest little MVC Framework"), "admin" => array("default_module" => "home", "base_href" => "/admin", "enabled" => true, "app_name" => "Dinkly Admin", "app_description" => "Admin for the humblest little MVC", "copyright" => "Dinkly"), "api" => array("base_href" => "/api", "enabled" => true, "default_module" => "api", "app_name" => "Dinkly API"), "doc" => array("app_name" => "Dinkly Documentation", "base_href" => "/doc", "default_module" => "home", "enabled" => true)));
     $this->bad_config = array("settings" => array("dinkly_version" => Dinkly::getConfigValue('dinkly_version', 'global')), "apps" => array());
     $this->valid_modules = array("home", "login", "user");
     $context = null;
     $this->valid_context = array('current_app_name' => 'admin', 'module' => 'home', 'view' => 'default', 'parameters' => array('id' => 1));
 }
Example #2
0
<!DOCTYPE html>
<html lang="en">
  
  <head>
    <meta charset="utf-8">
    <title><?php 
echo Dinkly::getConfigValue('app_name');
?>
 v<?php 
echo Dinkly::getConfigValue('dinkly_version', 'global');
?>
</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Le styles -->
    <link href="/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/dinkly.css" rel="stylesheet">
    <link href="/css/typeahead.css" rel="stylesheet">
    <link href="/css/styles.css" rel="stylesheet">
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
      </script>
    <![endif]-->
    
    <script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/typeahead.bundle.js"></script>
Example #3
0
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="/admin">
        <?php 
echo Dinkly::getConfigValue('app_name', 'admin');
?>
      </a>
    </div>
    <div class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
          <li <?php 
echo Dinkly::getCurrentModule() == 'home' ? 'class="active"' : '';
?>
>
              <a href="/admin">Home</a>
          </li>
        <?php 
if (DinklyUser::isMemberOf('admin')) {
    ?>
        <li <?php 
    echo Dinkly::getCurrentModule() == 'user' ? 'class="active"' : '';
    ?>
>
          <a href="/admin/user/">Users</a>
        </li>
        <li <?php 
    echo Dinkly::getCurrentModule() == 'group' ? 'class="active"' : '';
    ?>
>
          <a href="/admin/group/">Groups</a>
Example #4
0
<div class="row page-wrapper">
  <div class="col-md-12">
    <div class="jumbotron">
      <div>
        <h1>
          <?php 
echo Dinkly::translate('Welcome to Poetry Out Loud!');
?>
        </h1>
        <p>
          <?php 
echo Dinkly::getConfigValue('app_description');
?>
        </p>
        <h5>
          Brought to you by: <a href="https://github.com/bigSiebs">bigSiebs</a>.
        </h5>
      </div>
    </div>
  </div>
</div>
Example #5
0
 /**
  * Load desired module and redirect if necessary
  * 
  *
  * @param string $app_name name of app we are trying to load
  * @param string $module_name string of desired module to load
  * @param string $view string if passed goes to specified view otherwise default
  * @param bool $redirect default false, make true to redirect to different view
  * @param bool $draw_layout default true to get module view
  * @param array $parameters Array of parameters that can be used to populate views
  *
  * @return bool true if app loaded currectly else false and sent to default app
  */
 public function loadModule($app_name, $module_name = null, $view_name = 'default', $redirect = false, $draw_layout = true, $parameters = null)
 {
     //If nested, prevent output from doubling
     if (headers_sent()) {
         return false;
     }
     //If the app_name is not passed, assume whichever is set as the default in config.yml
     if (!$app_name) {
         $app_name = Dinkly::getDefaultApp(true);
     }
     //Validate passed app
     if (!in_array($app_name, Dinkly::getValidApps($app_name))) {
         throw new Exception('App "' . $app_name . '" cannot be loaded.');
         return false;
     }
     if (!Dinkly::isAppEnabled($app_name)) {
         $message = "The requested app (" . $app_name . ") is currently disabled.";
         error_log($message);
         if (self::isDevMode()) {
             echo $message;
         }
         return false;
     }
     //Set the current app to match whatever was passed
     $_SESSION['dinkly']['current_app_name'] = $app_name;
     //If no view is passed, look for one called 'default'
     if (!$view_name) {
         $view_name = 'default';
     }
     //Redirect page if true
     if ($redirect) {
         $base_href = Dinkly::getConfigValue('base_href', $app_name);
         if ($base_href == '/') {
             $base_href = null;
         }
         $path = $base_href . '/' . $module_name . '/' . $view_name;
         //Deal with parameters
         if ($parameters) {
             foreach ($parameters as $key => $value) {
                 $path .= '/' . $key . '/' . $value;
             }
         }
         header("Location: " . $path);
         die;
     }
     //Switch out paths later based on whether this is a plugin or not
     $is_plugin = false;
     if (Dinkly::getConfigValue('is_plugin', $app_name)) {
         $is_plugin = true;
     }
     //Load the app controller, if one exists
     $camel_app_controller_name = self::convertToCamelCase($app_name, true) . "Controller";
     if ($is_plugin) {
         $plugin_name = Dinkly::getConfigValue('plugin_name', $app_name);
         $app_controller_file = $_SERVER['APPLICATION_ROOT'] . '/plugins/' . $plugin_name . '/apps/' . $app_name . '/' . $camel_app_controller_name . '.php';
     } else {
         $app_controller_file = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/' . $camel_app_controller_name . '.php';
     }
     $has_app_controller = false;
     if (file_exists($app_controller_file)) {
         //Instantiate controller object
         require_once $app_controller_file;
         $has_app_controller = true;
     }
     //Get module controller
     $camel_module_name = self::convertToCamelCase($app_name, true) . self::convertToCamelCase($module_name, true) . "Controller";
     if ($is_plugin) {
         $controller_file = $_SERVER['APPLICATION_ROOT'] . '/plugins/' . $plugin_name . '/apps/' . $app_name . '/modules/' . $module_name . '/' . $camel_module_name . '.php';
     } else {
         $controller_file = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/modules/' . $module_name . '/' . $camel_module_name . '.php';
     }
     //Save these on the object so they can be retrieved as needed in controllers or views
     $this->view = $view_name;
     $this->module = $module_name;
     $this->parameters = $parameters;
     //If the controller doesn't exist, load 404 error page
     if (!file_exists($controller_file)) {
         //If there's an app controller, we instantiate that, in case it has overrides
         if ($has_app_controller) {
             $app_controller = new $camel_app_controller_name();
             $this->loadError($app_name, $camel_module_name, $view_name);
             return false;
         } else {
             $this->loadError($app_name, $camel_module_name, $view_name);
             return false;
         }
     }
     //Instantiate controller object
     require_once $controller_file;
     $controller = new $camel_module_name();
     //Migrate current dinkly variables over to our new controller
     $vars = get_object_vars($this);
     foreach ($vars as $name => $value) {
         $controller->{$name} = $value;
     }
     //Get this view's function
     $view_controller_name = self::convertToCamelCase($view_name, true);
     $view_function = "load" . $view_controller_name;
     if (method_exists($controller, $view_function)) {
         //If controller function returns false, don't draw layout wrapper
         if ($controller->{$view_function}($parameters)) {
             $draw_layout = true;
         } else {
             $draw_layout = false;
         }
         if (!in_array($module_name, Dinkly::getValidModules($app_name))) {
             throw new Exception('Module "' . $module_name . '" cannot be loaded.');
             return false;
         }
         //Migrate the scope of the declared variables to be local to the view
         $vars = get_object_vars($controller);
         foreach ($vars as $name => $value) {
             ${$name} = $value;
         }
         //Draw headers
         if ($draw_layout) {
             if ($is_plugin) {
                 $base_module_header_path = $_SERVER['APPLICATION_ROOT'] . '/plugins/' . $plugin_name . '/apps/' . $app_name . '/modules/' . $module_name . '/views/header';
             } else {
                 $base_module_header_path = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/modules/' . $module_name . "/views/header";
             }
             if (file_exists($base_module_header_path . '.php') || file_exists($base_module_header_path . '.md')) {
                 ob_start();
                 if (file_exists($base_module_header_path . '.php')) {
                     include $base_module_header_path . '.php';
                 } else {
                     if (file_exists($base_module_header_path . '.md')) {
                         include $base_module_header_path . '.md';
                     }
                 }
                 $header = ob_get_contents();
                 ob_end_clean();
                 $this->setModuleHeader($header);
             }
             //Set the powered-by header if the version number is in the config
             if ($version = self::getConfigValue('dinkly_version', 'global')) {
                 header('X-Powered-By: DINKLY/' . $version);
             }
             if ($is_plugin) {
                 $app_header_path = $_SERVER['APPLICATION_ROOT'] . '/plugins/' . $plugin_name . '/apps/' . $app_name . '/layout/header.php';
             } else {
                 $app_header_path = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/layout/header.php';
             }
             if (file_exists($app_header_path)) {
                 include $app_header_path;
             }
         }
         //Draw view
         if ($is_plugin) {
             $base_view_path = $_SERVER['APPLICATION_ROOT'] . '/plugins/' . $plugin_name . '/apps/' . $app_name . '/modules/' . $module_name . '/views/' . $view_name;
         } else {
             $base_view_path = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/modules/' . $module_name . '/views/' . $view_name;
         }
         if (file_exists($base_view_path . '.php')) {
             include $base_view_path . '.php';
         } else {
             if (file_exists($base_view_path . '.md')) {
                 $markdown_template = file_get_contents($base_view_path . '.md');
                 $Parsedown = new Parsedown();
                 echo $Parsedown->text($markdown_template);
             }
         }
         //Draw footer
         if ($draw_layout) {
             if ($is_plugin) {
                 $base_module_footer_path = $_SERVER['APPLICATION_ROOT'] . '/plugins/' . $plugin_name . '/apps/' . $app_name . '/modules/' . $module_name . "/views/footer";
             } else {
                 $base_module_footer_path = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/modules/' . $module_name . "/views/footer";
             }
             if (file_exists($base_module_footer_path . '.php') || file_exists($base_module_footer_path . '.md')) {
                 ob_start();
                 if (file_exists($base_module_footer_path . '.php')) {
                     include $base_module_footer_path . '.php';
                 } else {
                     if (file_exists($base_module_footer_path . '.md')) {
                         include $base_module_footer_path . '.md';
                     }
                 }
                 $header = ob_get_contents();
                 ob_end_clean();
                 $this->setModuleHeader($header);
             }
             if ($is_plugin) {
                 $app_footer_path = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/layout/footer.php';
             } else {
                 $app_footer_path = $_SERVER['APPLICATION_ROOT'] . '/apps/' . $app_name . '/layout/footer.php';
             }
             if (file_exists($app_footer_path)) {
                 include $app_footer_path;
             }
         }
     } else {
         $this->loadError($app_name, $camel_module_name, $view_name);
         return false;
     }
     return $draw_layout;
 }
Example #6
0
	</div><!-- Primary Container -->

	<?php 
echo $this->getModuleFooter();
?>

	<div id="footer" class="container-fluid">
		<div class="container">
			<footer>
				<p>Copyright © <?php 
echo Dinkly::getConfigValue('app_name') . ' ' . date('Y');
?>
</p>
			</footer>
		</div>
	</div>

	</body>
</html>
Example #7
0
 public function sendSetPasswordEmail()
 {
     $link = Dinkly::getConfigValue('current_app_url', 'admin') . "/admin/login/reset_password/k/" . $this->getAutoLoginHash();
     $to = $this->getUsername();
     $subject = "Reset Password";
     $message = "Here's the link to reset your password: "******"\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
     mail($to, $subject, $message, $headers);
     return true;
 }