Beispiel #1
0
 public function feedFragment($request)
 {
     $review = $this->get_patch()->get_review();
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($request->project->shortname, $review->id));
     $title = sprintf(__('%s: Updated review %d - %s'), Pluf_esc($request->project->name), $review->id, Pluf_esc($review->summary));
     $url .= '#ic' . $this->id;
     $date = Pluf_Date::gmDateToGmString($this->creation_dtime);
     $context = new Pluf_Template_Context_Request($request, array('url' => $url, 'author' => $this->get_submitter(), 'title' => $title, 'c' => $this, 'review' => $review, 'date' => $date));
     $tmpl = new Pluf_Template('idf/review/feedfragment.xml');
     return $tmpl->render($context);
 }
Beispiel #2
0
 function callbackWikiPage($m)
 {
     $sql = new Pluf_SQL('project=%s AND title=%s', array($this->project->id, $m[2]));
     $pages = Pluf::factory('IDF_WikiPage')->getList(array('filter' => $sql->gen()));
     if ($pages->count() != 1 and $this->request->rights['hasWikiAccess'] and !$this->request->user->isAnonymous()) {
         return '<img style="vertical-align: text-bottom;" alt=" " src="' . Pluf::f('url_media') . '/idf/img/add.png" /><a href="' . Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::create', array($this->project->shortname), array('name' => $m[2])) . '" title="' . __('Create this documentation page') . '">' . $m[1] . '</a>';
     }
     if (!$this->request->rights['hasWikiAccess'] or $pages->count() == 0) {
         return $m[1];
     }
     return '<a href="' . Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($this->project->shortname, $pages[0]->title)) . '" title="' . Pluf_esc($pages[0]->summary) . '">' . $m[1] . '</a>';
 }
Beispiel #3
0
 /**
  * Returns a HTML snippet with a line-by-line pre-rendered table
  * for the given source content
  *
  * @param array file information as returned by getMimeType or getMimeTypeFromContent
  * @param string the content of the file
  * @return string
  */
 public static function highLight($fileinfo, $content)
 {
     $pretty = '';
     if (self::isSupportedExtension($fileinfo[2])) {
         $pretty = ' prettyprint';
     }
     $table = array();
     $i = 1;
     foreach (preg_split("/\r\n|\r|\n/", $content) as $line) {
         $table[] = '<tr class="c-line"><td class="code-lc" id="L' . $i . '"><a href="#L' . $i . '">' . $i . '</a></td>' . '<td class="code mono' . $pretty . '">' . IDF_Diff::padLine(Pluf_esc($line)) . '</td></tr>';
         $i++;
     }
     return Pluf_Template::markSafe(implode("\n", $table));
 }
Beispiel #4
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('404.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = sprintf('The requested URL %s was not found on this server.' . "\n" . 'Please check the URL and try again.' . "\n\n" . '404 - Not Found', Pluf_esc($request->query));
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 404;
 }
Beispiel #5
0
 function __construct($request)
 {
     $content = '';
     try {
         $context = new Pluf_Template_Context(array('query' => $request->query));
         $tmpl = new Pluf_Template('503.html');
         $content = $tmpl->render($context);
         $mimetype = null;
     } catch (Exception $e) {
         $mimetype = 'text/plain';
         $content = sprintf('The requested URL %s is not available at the moment.' . "\n" . 'Please try again later.' . "\n\n" . '503 - Service Unavailable', Pluf_esc($request->query));
     }
     parent::__construct($content, $mimetype);
     $this->status_code = 503;
     $this->headers['Retry-After'] = 300;
     // retry after 5 minutes
 }
Beispiel #6
0
 /**
  * We need the user object and the request.
  *
  * If the user object is null (for example a non associated
  * commit), we can use the $text value for an alternative display.
  *
  * @param Pluf_User
  * @param Pluf_HTTP_Request
  * @param string Alternate text ('')
  */
 function start($user, $request, $text = '', $echo = true)
 {
     if ($user == null) {
         $out = strlen($text) ? strip_tags($text) : __('Anonymous');
     } else {
         if (!$user->isAnonymous() and $user->id == $request->user->id) {
             $utext = __('Me');
             $url = Pluf_HTTP_URL_urlForView('idf_dashboard');
         } else {
             $utext = Pluf_esc($user);
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_User::view', array($user->login));
         }
         $out = sprintf('<a href="%s" class="username">%s</a>', $url, $utext);
     }
     if ($echo) {
         echo $out;
     } else {
         return $out;
     }
 }
Beispiel #7
0
 /**
  * From the input, find the bad logins.
  *
  * @throws Pluf_Form_Invalid exception when bad logins are found
  * @param string Comma, new line delimited list of logins
  * @return string Comma, new line delimited list of logins
  */
 public static function checkBadLogins($logins)
 {
     $bad = array();
     foreach (preg_split("/\r\n|\r|\n|\\,/", $logins, -1, PREG_SPLIT_NO_EMPTY) as $login) {
         $sql = new Pluf_SQL('login=%s', array(trim($login)));
         try {
             $user = Pluf::factory('Pluf_User')->getOne(array('filter' => $sql->gen()));
             if (null == $user) {
                 $bad[] = $login;
             }
         } catch (Exception $e) {
             $bad[] = $login;
         }
     }
     $n = count($bad);
     if ($n) {
         $badlogins = Pluf_esc(implode(', ', $bad));
         throw new Pluf_Form_Invalid(sprintf(_n('The following login is invalid: %s.', 'The following login are invalids: %s.', $n), $badlogins));
     }
     return $logins;
 }
Beispiel #8
0
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     unset($this->cleaned_data['password2']);
     $update_pass = false;
     if (strlen($this->cleaned_data['password']) == 0) {
         unset($this->cleaned_data['password']);
     } else {
         $update_pass = true;
     }
     $old_email = $this->user->email;
     $new_email = $this->cleaned_data['email'];
     unset($this->cleaned_data['email']);
     if ($old_email != $new_email) {
         $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
         $encrypted = trim($cr->encrypt($new_email . ':' . $this->user->id . ':' . time()), '~');
         $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted;
         $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false);
         $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false);
         $context = new Pluf_Template_Context(array('key' => Pluf_Template::markSafe($key), 'url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlik), 'email' => $new_email, 'user' => $this->user));
         $tmpl = new Pluf_Template('idf/user/changeemail-email.txt');
         $text_email = $tmpl->render($context);
         $email = new Pluf_Mail(Pluf::f('from_email'), $new_email, __('Confirm your new email address.'));
         $email->addTextMessage($text_email);
         $email->sendMail();
         $this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email)));
     }
     $this->user->setFromFormData($this->cleaned_data);
     // Add key as needed.
     if ('' !== $this->cleaned_data['ssh_key']) {
         $key = new IDF_Key();
         $key->user = $this->user;
         $key->content = $this->cleaned_data['ssh_key'];
         if ($commit) {
             $key->create();
         }
     }
     if ($commit) {
         $this->user->update();
         if ($update_pass) {
             /**
              * [signal]
              *
              * Pluf_User::passwordUpdated
              *
              * [sender]
              *
              * IDF_Form_UserAccount
              *
              * [description]
              *
              * This signal is sent when the user updated his
              * password from his account page.
              *
              * [parameters]
              *
              * array('user' => $user)
              *
              */
             $params = array('user' => $this->user);
             Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_UserAccount', $params);
         }
     }
     return $this->user;
 }
Beispiel #9
0
 public function renderCompared($chunks, $filename)
 {
     $fileinfo = IDF_FileUtil::getMimeType($filename);
     $pretty = '';
     if (IDF_FileUtil::isSupportedExtension($fileinfo[2])) {
         $pretty = ' prettyprint';
     }
     $out = '';
     $cc = 1;
     $i = 0;
     foreach ($chunks as $chunk) {
         foreach ($chunk as $line) {
             $line1 = '&nbsp;';
             $line2 = '&nbsp;';
             $line[2] = strlen($line[2]) ? self::padLine(Pluf_esc($line[2])) : '&nbsp;';
             if ($line[0] and $line[1]) {
                 $class = 'diff-c';
                 $line1 = $line2 = $line[2];
             } elseif ($line[0]) {
                 $class = 'diff-r';
                 $line1 = $line[2];
             } else {
                 $class = 'diff-a';
                 $line2 = $line[2];
             }
             $out .= sprintf('<tr class="diff-line"><td class="diff-lc">%s</td><td class="%s mono%s"><code>%s</code></td><td class="diff-lc">%s</td><td class="%s mono%s"><code>%s</code></td></tr>' . "\n", $line[0], $class, $pretty, $line1, $line[1], $class, $pretty, $line2);
         }
         if (count($chunks) > $cc) {
             $out .= '<tr class="diff-next"><td>...</td><td>&nbsp;</td><td>...</td><td>&nbsp;</td></tr>' . "\n";
         }
         $cc++;
         $i++;
     }
     return Pluf_Template::markSafe($out);
 }
Beispiel #10
0
/**
 * @credits http://www.sitepoint.com/blogs/2006/04/04/pretty-blue-screen/
 */
function Pluf_HTTP_Response_ServerErrorDebug_Pretty($e)
{
    $o = create_function('$in', 'return htmlspecialchars($in);');
    $sub = create_function('$f', '$loc="";if(isset($f["class"])){
        $loc.=$f["class"].$f["type"];}
        if(isset($f["function"])){$loc.=$f["function"];}
        if(!empty($loc)){$loc=htmlspecialchars($loc);
        $loc="<strong>$loc</strong>";}return $loc;');
    $parms = create_function('$f', '$params=array();if(isset($f["function"])){
        try{if(isset($f["class"])){
        $r=new ReflectionMethod($f["class"]."::".$f["function"]);}
        else{$r=new ReflectionFunction($f["function"]);}
        return $r->getParameters();}catch(Exception $e){}}
        return $params;');
    $src2lines = create_function('$file', '$src=nl2br(highlight_file($file,TRUE));
        return explode("<br />",$src);');
    $clean = create_function('$line', 'return trim(strip_tags($line));');
    $desc = get_class($e) . " making " . $_SERVER['REQUEST_METHOD'] . " request to " . $_SERVER['REQUEST_URI'];
    $out = '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta name="robots" content="NONE,NOARCHIVE" />
     <title>' . $o($desc) . '</title>
  <style type="text/css">
    html * { padding:0; margin:0; }
    body * { padding:10px 20px; }
    body * * { padding:0; }
    body { font:small sans-serif; background: #70DBFF; }
    body>div { border-bottom:1px solid #ddd; }
    h1 { font-weight:normal; }
    h2 { margin-bottom:.8em; }
    h2 span { font-size:80%; color:#666; font-weight:normal; }
    h2 a { text-decoration:none; }
    h3 { margin:1em 0 .5em 0; }
    h4 { margin:0.5em 0 .5em 0; font-weight: normal; font-style: italic; }
    table { 
        border:1px solid #ccc; border-collapse: collapse; background:white; }
    tbody td, tbody th { vertical-align:top; padding:2px 3px; }
    thead th { 
        padding:1px 6px 1px 3px; background:#70FF94; text-align:left; 
        font-weight:bold; font-size:11px; border:1px solid #ddd; }
    tbody th { text-align:right; color:#666; padding-right:.5em; }
    table.vars { margin:5px 0 2px 40px; }
    table.vars td, table.req td { font-family:monospace; }
    table td { background: #70FFDB; }
    table td.code { width:95%;}
    table td.code div { overflow:hidden; }
    table.source th { color:#666; }
    table.source td { 
        font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
    ul.traceback { list-style-type:none; }
    ul.traceback li.frame { margin-bottom:1em; }
    div.context { margin:5px 0 2px 40px; background-color:#70FFDB; }
    div.context ol { 
        padding-left:30px; margin:0 10px; list-style-position: inside; }
    div.context ol li { 
        font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
    div.context li.current-line { color:black; background-color:#70FF94; }
    div.commands { margin-left: 40px; }
    div.commands a { color:black; text-decoration:none; }
    p.headers { background: #70FFDB; font-family:monospace; }
    #summary { background: #00B8F5; }
    #summary h2 { font-weight: normal; color: #666; }
    #traceback { background:#eee; }
    #request { background:#f6f6f6; }
    #response { background:#eee; }
    #summary table { border:none; background:#00B8F5; }
    #summary td  { background:#00B8F5; }
    .switch { text-decoration: none; }
    .whitemsg { background:white; color:black;}
  </style>
  <script type="text/javascript">
  //<!--
    function getElementsByClassName(oElm, strTagName, strClassName){
        // Written by Jonathan Snook, http://www.snook.ca/jon; 
        // Add-ons by Robert Nyman, http://www.robertnyman.com
        var arrElements = (strTagName == "*" && document.all)? document.all :
        oElm.getElementsByTagName(strTagName);
        var arrReturnElements = new Array();
        strClassName = strClassName.replace(/\\-/g, "\\-");
        var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
        var oElement;
        for(var i=0; i<arrElements.length; i++){
            oElement = arrElements[i];
            if(oRegExp.test(oElement.className)){
                arrReturnElements.push(oElement);
            }
        }
        return (arrReturnElements)
    }
    function hideAll(elems) {
      for (var e = 0; e < elems.length; e++) {
        elems[e].style.display = \'none\';
      }
    }
    function toggle() {
      for (var i = 0; i < arguments.length; i++) {
        var e = document.getElementById(arguments[i]);
        if (e) {
          e.style.display = e.style.display == \'none\' ? \'block\' : \'none\';
        }
      }
      return false;
    }
    function varToggle(link, id, prefix) {
      toggle(prefix + id);
      var s = link.getElementsByTagName(\'span\')[0];
      var uarr = String.fromCharCode(0x25b6);
      var darr = String.fromCharCode(0x25bc);
      s.innerHTML = s.innerHTML == uarr ? darr : uarr;
      return false;
    }
    function sectionToggle(span, section) {
      toggle(section);
      var span = document.getElementById(span);
      var uarr = String.fromCharCode(0x25b6);
      var darr = String.fromCharCode(0x25bc);
      span.innerHTML = span.innerHTML == uarr ? darr : uarr;
      return false;
    }
    
    window.onload = function() {
      hideAll(getElementsByClassName(document, \'table\', \'vars\'));
      hideAll(getElementsByClassName(document, \'div\', \'context\'));
      hideAll(getElementsByClassName(document, \'ul\', \'traceback\'));
      hideAll(getElementsByClassName(document, \'div\', \'section\'));
    }
    //-->
  </script>
</head>
<body>

<div id="summary">
  <h1>' . $o($desc) . '</h1>
  <h2>';
    if ($e->getCode()) {
        $out .= $o($e->getCode()) . ' : ';
    }
    $out .= ' ' . $o($e->getMessage()) . '</h2>
  <table>
    <tr>
      <th>PHP</th>
      <td>' . $o($e->getFile()) . ', line ' . $o($e->getLine()) . '</td>
    </tr>
    <tr>
      <th>URI</th>
      <td>' . $o($_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI']) . '</td>
    </tr>
  </table>
</div>

<div id="traceback">
  <h2>Stacktrace
    <a href=\'#\' onclick="return sectionToggle(\'tb_switch\',\'tb_list\')">
    <span id="tb_switch">▶</span></a></h2>
  <ul id="tb_list" class="traceback">';
    $frames = $e->getTrace();
    foreach ($frames as $frame_id => $frame) {
        if (!isset($frame['file'])) {
            $frame['file'] = 'No File';
            $frame['line'] = '0';
        }
        $out .= '<li class="frame">' . $sub($frame) . '
        [' . $o($frame['file']) . ', line ' . $o($frame['line']) . ']';
        if (isset($frame['args']) && count($frame['args']) > 0) {
            $params = $parms($frame);
            $out .= '
          <div class="commands">
              <a href=\'#\' onclick="return varToggle(this, \'' . $o($frame_id) . '\',\'v\')"><span>▶</span> Args</a>
          </div>
          <table class="vars" id="v' . $o($frame_id) . '">
            <thead>
              <tr>
                <th>Arg</th>
                <th>Name</th>
                <th>Value</th>
              </tr>
            </thead>
            <tbody>';
            foreach ($frame['args'] as $k => $v) {
                $name = (isset($params[$k]) and isset($params[$k]->name)) ? '$' . $params[$k]->name : '?';
                $out .= '
                <tr>
                  <td>' . $o($k) . '</td>
                  <td>' . $o($name) . '</td>
                  <td class="code">
                    <pre>' . Pluf_esc(print_r($v, true)) . '</pre>
                  </td>
                  </tr>';
            }
            $out .= '</tbody></table>';
        }
        if (is_readable($frame['file'])) {
            $out .= '
        <div class="commands">
            <a href=\'#\' onclick="return varToggle(this, \'' . $o($frame_id) . '\',\'c\')"><span>▶</span> Src</a>
        </div>
        <div class="context" id="c' . $o($frame_id) . '">';
            $lines = $src2lines($frame['file']);
            $start = $frame['line'] < 5 ? 0 : $frame['line'] - 5;
            $end = $start + 10;
            $out2 = '';
            foreach ($lines as $k => $line) {
                if ($k > $end) {
                    break;
                }
                $line = trim(strip_tags($line));
                if ($k < $start && isset($frames[$frame_id + 1]["function"]) && preg_match('/function( )*' . preg_quote($frames[$frame_id + 1]["function"]) . '/', $line)) {
                    $start = $k;
                }
                if ($k >= $start) {
                    if ($k != $frame['line']) {
                        $out2 .= '<li><code>' . $clean($line) . '</code></li>' . "\n";
                    } else {
                        $out2 .= '<li class="current-line"><code>' . $clean($line) . '</code></li>' . "\n";
                    }
                }
            }
            $out .= "<ol start=\"{$start}\">\n" . $out2 . "</ol>\n";
            $out .= '</div>';
        } else {
            $out .= '<div class="commands">No src available</div>';
        }
        $out .= '</li>';
    }
    // End of foreach $frames
    $out .= '
  </ul>
  
</div>

<div id="request">
  <h2>Request
    <a href=\'#\' onclick="return sectionToggle(\'req_switch\',\'req_list\')">
    <span id="req_switch">▶</span></a></h2>
  <div id="req_list" class="section">';
    if (function_exists('apache_request_headers')) {
        $out .= '<h3>Request <span>(raw)</span></h3>';
        $req_headers = apache_request_headers();
        $out .= '<h4>HEADERS</h4>';
        if (count($req_headers) > 0) {
            $out .= '<p class="headers">';
            foreach ($req_headers as $req_h_name => $req_h_val) {
                $out .= $o($req_h_name . ': ' . $req_h_val);
                $out .= '<br>';
            }
            $out .= '</p>';
        } else {
            $out .= '<p>No headers.</p>';
        }
        $req_body = file_get_contents('php://input');
        if (strlen($req_body) > 0) {
            $out .= '
      <h4>Body</h4>
      <p class="req" style="padding-bottom: 2em"><code>
       ' . $o($req_body) . '
      </code></p>';
        }
    }
    $out .= '
    <h3>Request <span>(parsed)</span></h3>';
    $superglobals = array('$_GET', '$_POST', '$_COOKIE', '$_SERVER', '$_ENV');
    foreach ($superglobals as $sglobal) {
        $sfn = create_function('', 'return ' . $sglobal . ';');
        $out .= '<h4>' . $sglobal . '</h4>';
        if (count($sfn()) > 0) {
            $out .= '
      <table class="req">
        <thead>
          <tr>
            <th>Variable</th>
            <th>Value</th>
          </tr>
        </thead>
        <tbody>';
            foreach ($sfn() as $k => $v) {
                $out .= '<tr>
              <td>' . $o($k) . '</td>
              <td class="code">
                <div>' . $o(print_r($v, TRUE)) . '</div>
                </td>
            </tr>';
            }
            $out .= '
        </tbody>
      </table>';
        } else {
            $out .= '
      <p class="whitemsg">No data</p>';
        }
    }
    $out .= '
      
  </div>
</div>';
    if (function_exists('headers_list')) {
        $out .= '
<div id="response">

  <h2>Response
    <a href=\'#\' onclick="return sectionToggle(\'resp_switch\',\'resp_list\')">
    <span id="resp_switch">▶</span></a></h2>
  
  <div id="resp_list" class="section">

    <h3>Headers</h3>';
        $resp_headers = headers_list();
        if (count($resp_headers) > 0) {
            $out .= '
    <p class="headers">';
            foreach ($resp_headers as $resp_h) {
                $out .= $o($resp_h);
                $out .= '<br>';
            }
            $out .= '    </p>';
        } else {
            $out .= '
      <p>No headers.</p>';
        }
        $out .= '
</div>';
    }
    $out .= '
</body>
</html>
';
    return $out;
}
Beispiel #11
0
 public static function makeBreadCrumb($project, $commit, $file, $sep = '/')
 {
     $elts = explode('/', $file);
     $out = array();
     $stack = '';
     $i = 0;
     foreach ($elts as $elt) {
         $stack .= $i == 0 ? rawurlencode($elt) : '/' . rawurlencode($elt);
         $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::tree', array($project->shortname, $commit, $stack));
         $out[] = '<a href="' . $url . '">' . Pluf_esc($elt) . '</a>';
         $i++;
     }
     return '<span class="breadcrumb">' . implode('<span class="sep">' . $sep . '</span>', $out) . '</span>';
 }
Beispiel #12
0
 public function changeEmailDo($request, $match)
 {
     $key = $match[1];
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey');
     try {
         list($email, $id, $time) = IDF_Form_UserChangeEmail::validateKey($key);
     } catch (Pluf_Form_Invalid $e) {
         return new Pluf_HTTP_Response_Redirect($url);
     }
     if ($id != $request->user->id) {
         return new Pluf_HTTP_Response_Redirect($url);
     }
     // Now we have a change link coming from the right user.
     $request->user->email = $email;
     $request->user->update();
     $request->user->setMessage(sprintf(__('Your new email address "%s" has been validated. Thank you!'), Pluf_esc($email)));
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_User::myAccount');
     return new Pluf_HTTP_Response_Redirect($url);
 }
Beispiel #13
0
 public function feedFragment($request)
 {
     $issue = $this->get_issue();
     $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($request->project->shortname, $issue->id));
     $title = sprintf(__('%s: Comment on issue %d - %s'), Pluf_esc($request->project->name), $issue->id, Pluf_esc($issue->summary));
     $url .= '#ic' . $this->id;
     $date = Pluf_Date::gmDateToGmString($this->creation_dtime);
     $context = new Pluf_Template_Context_Request($request, array('url' => $url, 'author' => $issue->get_submitter(), 'title' => $title, 'c' => $this, 'issue' => $issue, 'date' => $date));
     $tmpl = new Pluf_Template('idf/issues/feedfragment.xml');
     return $tmpl->render($context);
 }
Beispiel #14
0
 /**
  * Generate the link to a review.
  *
  * @param IDF_Review Review.
  * @param string Name of the link.
  * @return string Linked review.
  */
 public function linkReview($review, $title, $anchor = '')
 {
     $ic = in_array($review->status, $this->project->getTagIdsByStatus('closed')) ? 'issue-c' : 'issue-o';
     return '<a href="' . Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($this->project->shortname, $review->id)) . $anchor . '" class="' . $ic . '" title="' . Pluf_esc($review->summary) . '">' . Pluf_esc($title) . '</a>';
 }
Beispiel #15
0
    /**
     * Returns an HTML fragment used to display this issue in the
     * timeline.
     *
     * The request object is given to be able to check the rights and
     * as such create links to other items etc. You can consider that
     * if displayed, you can create a link to it.
     *
     * @param Pluf_HTTP_Request 
     * @return Pluf_Template_SafeString
     */
    public function timelineFragment($request)
    {
        $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($request->project->shortname, $this->id));
        $out = '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>';
        $stag = new IDF_Template_ShowUser();
        $user = $stag->start($this->get_submitter(), $request, '', false);
        $ic = in_array($this->status, $request->project->getTagIdsByStatus('closed')) ? 'issue-c' : 'issue-o';
        $out .= sprintf(__('<a href="%1$s" class="%2$s" title="View issue">Issue %3$d</a>, %4$s'), $url, $ic, $this->id, Pluf_esc($this->summary)) . '</td>';
        $out .= "\n" . '<tr class="extra"><td colspan="2">
<div class="helptext right">' . sprintf(__('Creation of <a href="%s" class="%s">issue&nbsp;%d</a>, by %s'), $url, $ic, $this->id, $user) . '</div></td></tr>';
        return Pluf_Template::markSafe($out);
    }
Beispiel #16
0
 /**
  * Generate the column headers for the table.
  */
 function colHeaders()
 {
     if (empty($this->list_display)) {
         return '<tr><th>' . __('Name') . '</th></tr>' . "\n";
     } else {
         $out = '<tr>';
         foreach ($this->list_display as $key => $col) {
             if (is_array($col)) {
                 $field = $col[0];
                 $name = $col[2];
                 Pluf::loadFunction($col[1]);
             } else {
                 $name = $col;
                 $field = $key;
             }
             if (!$this->sort_link_title) {
                 $out .= '<th><span class="px-header-title">' . Pluf_esc(ucfirst($name)) . '</span>' . $this->headerSortLinks($field) . '</th>';
             } else {
                 $out .= '<th><span class="px-header-title">' . $this->headerSortLinks($field, Pluf_esc(ucfirst($name))) . '</span></th>';
             }
         }
         $out .= '</tr>' . "\n";
         return $out;
     }
 }
Beispiel #17
0
 function showCompact()
 {
     return Pluf_Template::markSafe(Pluf_esc(substr($this->content, 0, 25)) . ' [...] ' . Pluf_esc(substr($this->content, -55)));
 }
Beispiel #18
0
/**
 * Display the summary of an review, then on a new line, display the
 * list of labels with a link to a view "by label only".
 *
 * The summary of the review is linking to the review.
 */
function IDF_Views_Review_SummaryAndLabels($field, $review, $extra = '')
{
    $edit = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($review->shortname, $review->id));
    $tags = array();
    foreach ($review->get_tags_list() as $tag) {
        $tags[] = Pluf_esc($tag);
    }
    $out = '';
    if (count($tags)) {
        $out = '<br /><span class="label note">' . implode(', ', $tags) . '</span>';
    }
    return sprintf('<a href="%s">%s</a>', $edit, Pluf_esc($review->summary)) . $out;
}
Beispiel #19
0
 /**
  * Create the autocomplete arrays for the little AJAX stuff.
  */
 public static function autoCompleteArrays($project)
 {
     $conf = new IDF_Conf();
     $conf->setProject($project);
     $st = preg_split("/\r\n|\r|\n/", $conf->getVal('labels_download_predefined', IDF_Form_UploadConf::init_predefined), -1, PREG_SPLIT_NO_EMPTY);
     $auto = '';
     foreach ($st as $s) {
         $v = '';
         $d = '';
         $_s = explode('=', $s, 2);
         if (count($_s) > 1) {
             $v = trim($_s[0]);
             $d = trim($_s[1]);
         } else {
             $v = trim($_s[0]);
         }
         $auto .= sprintf('{ name: "%s", to: "%s" }, ', Pluf_esc($d), Pluf_esc($v));
     }
     return substr($auto, 0, -2);
 }
Beispiel #20
0
 /**
  * Create the autocomplete arrays for the little AJAX stuff.
  */
 public static function autoCompleteArrays($project)
 {
     $conf = new IDF_Conf();
     $conf->setProject($project);
     $auto = array('auto_status' => '', 'auto_labels' => '');
     $auto_raw = array('auto_status' => '', 'auto_labels' => '');
     $st = $conf->getVal('labels_issue_open', IDF_Form_IssueTrackingConf::init_open);
     $st .= "\n" . $conf->getVal('labels_issue_closed', IDF_Form_IssueTrackingConf::init_closed);
     $auto_raw['auto_status'] = $st;
     $auto_raw['auto_labels'] = $conf->getVal('labels_issue_predefined', IDF_Form_IssueTrackingConf::init_predefined);
     foreach ($auto_raw as $key => $st) {
         $st = preg_split("/\r\n|\r|\n/", $st, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($st as $s) {
             $v = '';
             $d = '';
             $_s = explode('=', $s, 2);
             if (count($_s) > 1) {
                 $v = trim($_s[0]);
                 $d = trim($_s[1]);
             } else {
                 $v = trim($_s[0]);
             }
             $auto[$key] .= sprintf('{ name: "%s", to: "%s" }, ', Pluf_esc($d), Pluf_esc($v));
         }
         $auto[$key] = substr($auto[$key], 0, -2);
     }
     // Get the members/owners
     $m = $project->getMembershipData();
     $auto['_auto_owner'] = $m['members'];
     $auto['auto_owner'] = '';
     foreach ($m['owners'] as $owner) {
         if (!Pluf_Model_InArray($owner, $auto['_auto_owner'])) {
             $auto['_auto_owner'][] = $owner;
         }
     }
     foreach ($auto['_auto_owner'] as $owner) {
         $auto['auto_owner'] .= sprintf('{ name: "%s", to: "%s" }, ', Pluf_esc($owner), Pluf_esc($owner->login));
     }
     $auto['auto_owner'] = substr($auto['auto_owner'], 0, -2);
     unset($auto['_auto_owner']);
     return $auto;
 }
Beispiel #21
0
    /**
     * Returns the timeline fragment for the file.
     *
     *
     * @param Pluf_HTTP_Request
     * @return Pluf_Template_SafeString
     */
    public function timelineFragment($request)
    {
        $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', array($request->project->shortname, $this->id));
        $out = '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>';
        $stag = new IDF_Template_ShowUser();
        $user = $stag->start($this->get_submitter(), $request, '', false);
        $out .= sprintf(__('<a href="%1$s" title="View download">Download %2$d</a>, %3$s'), $url, $this->id, Pluf_esc($this->summary)) . '</td>';
        $out .= '</tr>';
        $out .= "\n" . '<tr class="extra"><td colspan="2">
<div class="helptext right">' . sprintf(__('Addition of <a href="%s">download&nbsp;%d</a>, by %s'), $url, $this->id, $user) . '</div></td></tr>';
        return Pluf_Template::markSafe($out);
    }
Beispiel #22
0
    /**
     * Returns the timeline fragment for the commit.
     *
     *
     * @param Pluf_HTTP_Request 
     * @return Pluf_Template_SafeString
     */
    public function timelineFragment($request)
    {
        $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit', array($request->project->shortname, $this->scm_id));
        $out = '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>';
        $stag = new IDF_Template_ShowUser();
        $user = $stag->start($this->get_author(), $request, $this->origauthor, false);
        $tag = new IDF_Template_IssueComment();
        $out .= $tag->start($this->summary, $request, false);
        if (0 && $this->fullmessage) {
            $out .= '<br /><br />' . $tag->start($this->fullmessage, $request, false);
        }
        $out .= '</td>
</tr>
<tr class="extra">
<td colspan="2">
<div class="helptext right">' . sprintf(__('Commit&nbsp;%s, by %s'), '<a href="' . $url . '" class="mono">' . $this->scm_id . '</a>', $user) . '</div></td></tr>';
        return Pluf_Template::markSafe($out);
    }
Beispiel #23
0
    public function timelineFragment($request)
    {
        $page = $this->get_wikipage();
        $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($request->project->shortname, $page->title));
        $out = "\n" . '<tr class="log"><td><a href="' . $url . '">' . Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')) . '</a></td><td>';
        $stag = new IDF_Template_ShowUser();
        $user = $stag->start($this->get_submitter(), $request, '', false);
        $out .= sprintf(__('<a href="%1$s" title="View page">%2$s</a>, %3$s'), $url, Pluf_esc($page->title), Pluf_esc($this->summary));
        if ($this->changedRevision()) {
            $out .= '<div class="issue-changes-timeline">';
            $changes = $this->changes;
            foreach ($changes as $w => $v) {
                $out .= '<strong>';
                switch ($w) {
                    case 'lb':
                        $out .= __('Labels:');
                        break;
                }
                $out .= '</strong>&nbsp;';
                if ($w == 'lb') {
                    $out .= Pluf_esc(implode(', ', $v));
                } else {
                    $out .= Pluf_esc($v);
                }
                $out .= ' ';
            }
            $out .= '</div>';
        }
        $out .= '</td></tr>';
        $out .= "\n" . '<tr class="extra"><td colspan="2">
<div class="helptext right">' . sprintf(__('Change of <a href="%s">%s</a>, by %s'), $url, Pluf_esc($page->title), $user) . '</div></td></tr>';
        return Pluf_Template::markSafe($out);
    }
Beispiel #24
0
/**
 * Var export returning a safe string.
 *
 * @param mixed Input
 * @return string Safe to display in HTML.
 */
function Pluf_Template_varExport($mixed)
{
    return Pluf_Template_unsafe('<pre>' . Pluf_esc(var_export($mixed, true)) . '</pre>');
}
Beispiel #25
0
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     unset($this->cleaned_data['password2']);
     $update_pass = false;
     if (strlen($this->cleaned_data['password']) == 0) {
         unset($this->cleaned_data['password']);
     } else {
         $update_pass = true;
     }
     $old_email = $this->user->email;
     $new_email = $this->cleaned_data['email'];
     unset($this->cleaned_data['email']);
     if ($old_email != $new_email) {
         $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
         $encrypted = trim($cr->encrypt($new_email . ':' . $this->user->id . ':' . time()), '~');
         $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted;
         $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false);
         $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false);
         $context = new Pluf_Template_Context(array('key' => Pluf_Template::markSafe($key), 'url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlik), 'email' => $new_email, 'user' => $this->user));
         $tmpl = new Pluf_Template('idf/user/changeemail-email.txt');
         $text_email = $tmpl->render($context);
         $email = new Pluf_Mail(Pluf::f('from_email'), $new_email, __('Confirm your new email address.'));
         $email->addTextMessage($text_email);
         $email->sendMail();
         $this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email)));
     }
     $this->user->setFromFormData($this->cleaned_data);
     // Add key as needed.
     if ('' !== $this->cleaned_data['public_key']) {
         $key = new IDF_Key();
         $key->user = $this->user;
         $key->content = $this->cleaned_data['public_key'];
         if ($commit) {
             $key->create();
         }
     }
     if ($commit) {
         $this->user->update();
         // FIXME: go the extra mile and check the input lengths for
         // all fields here!
         // FIXME: this is all doubled in admin/UserUpdate!
         $user_data = IDF_UserData::factory($this->user);
         // Add or remove avatar - we need to do this here because every
         // single setter directly leads to a save in the database
         if ($user_data->avatar != '' && ($this->cleaned_data['remove_custom_avatar'] == 1 || $this->cleaned_data['custom_avatar'] != '')) {
             $avatar_path = Pluf::f('upload_path') . '/avatars/' . basename($user_data->avatar);
             if (basename($avatar_path) != '' && is_file($avatar_path)) {
                 unlink($avatar_path);
             }
             $user_data->avatar = '';
         }
         if ($this->cleaned_data['custom_avatar'] != '') {
             $user_data->avatar = $this->cleaned_data['custom_avatar'];
         }
         $user_data->description = $this->cleaned_data['description'];
         $user_data->twitter = $this->cleaned_data['twitter'];
         $user_data->public_email = $this->cleaned_data['public_email'];
         $user_data->website = $this->cleaned_data['website'];
         if ($update_pass) {
             /**
              * [signal]
              *
              * Pluf_User::passwordUpdated
              *
              * [sender]
              *
              * IDF_Form_UserAccount
              *
              * [description]
              *
              * This signal is sent when the user updated his
              * password from his account page.
              *
              * [parameters]
              *
              * array('user' => $user)
              *
              */
             $params = array('user' => $this->user);
             Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_UserAccount', $params);
         }
     }
     return $this->user;
 }