Dotclear

Changeset 361 for plugins/previewpost


Ignore:
Timestamp:
03/20/08 12:39:43 (16 years ago)
Author:
bruno
Message:

Started rethinking plugin.

  • User can now connect from public page (through widget), and can see offline posts directly on his blog, if connected.
  • Added templates EntryIfOffline? to provide specific css style (same usage as EntryIfOdd?, ...)
Location:
plugins/previewpost
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • plugins/previewpost/_admin.php

    r356 r361  
    2121# 
    2222# ***** END LICENSE BLOCK ***** 
     23require dirname(__FILE__).'/_widgets.php'; 
    2324 
    2425$core->addBehavior('adminPostHeaders',array('previewBehaviors','postHeaders')); 
     
    2930     { 
    3031          global $post_url,$core; 
    31           return '<script type="text/javascript" src="index.php?pf=previewpost/js/post.js"></script>'. 
     32          return '<script type="text/javascript" src="index.php?pf=preview/js/post.js"></script>'. 
    3233          '<script type="text/javascript">'."\n". 
    3334          "//<![CDATA[\n". 
  • plugins/previewpost/_define.php

    r356 r361  
    2323 
    2424$this->registerModule( 
    25      /* Name */               "Preview Post", 
     25     /* Name */               "Preview", 
    2626     /* Description*/         "Public part post Preview for Dotclear2", 
    2727     /* Author */             "Bruno Hondelatte", 
    28      /* Version */            '0.2', 
     28     /* Version */            'SVN', 
    2929     /* Permissions */        'usage,contentadmin' 
    3030); 
  • plugins/previewpost/_prepend.php

    r356 r361  
    2323 
    2424$GLOBALS['core']->url->register('preview','preview','^preview/(.+)$',array('urlPreview','post')); 
     25$GLOBALS['core']->url->register('public_auth','public_auth','^login$',array('urlPreview','login')); 
    2526 
    2627?> 
  • plugins/previewpost/_public.php

    r356 r361  
    2121# 
    2222# ***** END LICENSE BLOCK ***** 
     23 
     24require dirname(__FILE__).'/_widgets.php'; 
     25$core->addBehavior('publicPrepend',array('PreviewBehavior','publicPrepend')); 
     26 
     27$core->tpl->addValue('EntryIfOffline',array('tplPreview','EntryIfOffline')); 
    2328 
    2429class urlPreview extends dcUrlHandlers 
     
    6873          exit; 
    6974     } 
     75 
     76     public static function login($args) 
     77     { 
     78          global $core; 
     79          if (!isset($_POST['user_id']) || !isset($_POST['user_pwd'])) { 
     80               header('Location: '.$core->blog->url); 
     81               return; 
     82          } 
     83          $user_id=$_POST['user_id']; 
     84          $user_pwd = $_POST['user_pwd']; 
     85          if ($core->auth->checkUser($user_id,$user_pwd) === true) { 
     86               $core->session->start(); 
     87               $_SESSION['sess_user_id'] = $user_id; 
     88               $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); 
     89                
     90               if (!empty($_POST['blog'])) { 
     91                    $_SESSION['sess_blog_id'] = $_POST['blog']; 
     92               } 
     93               if (!empty($_POST['user_remember'])) 
     94               { 
     95                    $cookie_admin = 
     96                         http::browserUID(DC_MASTER_KEY.$user_id.crypt::hmac(DC_MASTER_KEY,$user_pwd)). 
     97                         bin2hex(pack('a32',$user_id)); 
     98                          
     99                    setcookie('dc_admin',$cookie_admin,strtotime('+15 days'),'','',DC_ADMIN_SSL); 
     100               } 
     101               header('Location: '.$core->blog->url); 
     102               return; 
     103          }; 
     104 
     105     } 
    70106} 
    71107 
     108 
     109class PreviewBehavior { 
     110     public static function publicPrepend(&$core) { 
     111          if (isset($_COOKIE[DC_SESSION_NAME])) 
     112          { 
     113               $core->session->start(); 
     114               $core->auth->checkUser($_SESSION['sess_user_id']); 
     115          } 
     116           
     117     } 
     118} 
     119 
     120class tplPreview { 
     121     public static function EntryIfOffline($attr) { 
     122          $ret = isset($attr['return']) ? $attr['return'] : 'offline'; 
     123          $ret = html::escapeHTML($ret); 
     124           
     125          return '<?php if ($_ctx->posts->post_status != 1) { '. "echo '".addslashes($ret)."'; } ?".">"; 
     126     } 
     127 
     128     public static function authWidget(&$w) { 
     129          global $core; 
     130                $title = $w->title ? html::escapeHTML($w->title) : __('Connection'); 
     131          $is_authenticated=isset($_COOKIE[DC_SESSION_NAME]); 
     132                
     133          $res = '<div id="auth">'. 
     134               '<h2>'.$title.'</h2>'; 
     135 
     136          if (!$is_authenticated) { 
     137               $res .= '<form action="'.$core->blog->url.'login" method="post">'. 
     138                    '<p><label>'.__('Login').' '. 
     139                    form::field("user_id",20,32).'</label></p>'. 
     140                    '<p><label>'.__('Password').' '. 
     141                    form::password("user_pwd",20,255).'</label></p>'. 
     142                    '<p><input type="submit" value="'.__('login').'" tabindex="3" />'. 
     143                    '</form>'; 
     144          } else { 
     145               $res .= "You are authenticated"; 
     146          } 
     147          $res .= '</div>'; 
     148          return $res; 
     149 
     150     } 
     151} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map