/**
 * Load a remote page using an HTTP request
 * @param array $configurations A set of key/value pairs that configure the
 * default Ajax request. Important frequency value makes the ajax call is executed
 * periodically
 * @param boolean $isInternal If this function is inner a javascript body
 * @return string jQuery syntax
 */
function jquery_ajax($configurations = null, $isInternal = false)
{
    if (is_array($configurations) && sizeof($configurations) > 0) {
        $suffix = '';
        $prefix = '';
        if (isset($configurations['frequency'])) {
            $suffix = 'setInterval(function(){';
            $prefix = '}, ' . (int) $configurations['frequency'] * 1000 . ')';
        }
        if (isset($configurations['condition']) && trim($configurations['condition']) != '') {
            $prefix = isset($configurations['onFailureCondition']) ? sprintf('} else {%s} ', $configurations['onFailureCondition']) . $prefix : '}' . $prefix;
            $suffix .= sprintf("if(%s){ ", $configurations['condition']);
        }
        if (isset($configurations['confirmation']) && trim($configurations['confirmation']) != '') {
            $prefix = isset($configurations['onNoConfirmation']) ? sprintf('} else {%s} ', $configurations['onNoConfirmation']) . $prefix : '}' . $prefix;
            $suffix .= sprintf("if(confirm('%s')){ ", $configurations['confirmation']);
        }
        if (isset($configurations['csrf']) && $configurations['csrf']) {
            $sfForm = new BaseForm();
            if ($sfForm->isCSRFProtected()) {
                $csrfArray = array($sfForm->getCSRFFieldName() => "'" . $sfForm->getCSRFToken() . "'");
                $configurations['data'] = isset($configurations['data']) ? array_merge($configurations['data'], $csrfArray) : $csrfArray;
            }
        }
        if (isset($configurations['listener']) && is_array($configurations['listener'])) {
            $listener = $configurations['listener'];
            $selector = isset($listener['selector']) ? $listener['selector'] : 'document';
            $event = isset($listener['event']) ? $listener['event'] : 'ready';
            $ajaxTemplate = ui_ajax_pattern($configurations);
            if ($isInternal) {
                return $suffix . jquery_support($selector, $event, like_function($suffix . jquery_support(null, 'ajax', $ajaxTemplate) . $prefix));
            } else {
                return add_jquery_support($selector, $event, like_function($suffix . jquery_support(null, 'ajax', $ajaxTemplate) . $prefix));
            }
        } else {
            $ajaxTemplate = ui_ajax_pattern($configurations);
            return $suffix . jquery_support(null, 'ajax', $ajaxTemplate) . $prefix;
        }
    }
}
예제 #2
0
 public function checkCSRFProtection()
 {
     $form = new BaseForm();
     $form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
     if (!$form->isValid()) {
         throw $form->getErrorSchema();
     }
 }
예제 #3
0
<?php

op_mobile_page_title(__('Delete this %community%'), $community->getName());
$form = new BaseForm();
op_include_parts('yesNo', 'deleteConfirmForm', array('body' => __('Do you delete this %community%?'), 'yes_form' => '<input type="hidden" name="is_delete">' . '<input type="hidden" name="' . $form->getCSRFFieldName() . '" value="' . $form->getCSRFToken() . '">', 'button' => __('Delete')));
            <li><?php echo link_to(__('Delete'), 'sfSimpleBlogPostAdmin/deleteVersion?id='.$version->getId().'&version='.$version->getVersion(), array('confirm' => __('Are your sure?'), 'method' => 'delete')) ?></li>
          </ul>
        </td>
      </tr>
    </tbody>
  <?php endforeach; ?>
    <tfoot>
      <tr>
        <th colspan="5">&nbsp</th>
      </tr>
    </tfoot>
  </table>
  </fieldset>
  <?php if (count($versions) > 0): ?>
    <?php $form = new BaseForm(); if ($form->isCSRFProtected()): ?>
      <input type="hidden" name="<?php echo $form->getCSRFFieldName() ?>" value="<?php echo $form->getCSRFToken() ?>" />
    <?php endif; ?>
    <input type="submit" value="Delete Versions" />
  <?php endif; ?>
  </form>
  
</div>
<script type="text/javascript">
/* <![CDATA[ */
function checkAll()
{
  var boxes = document.getElementsByTagName('input'); for(var index = 0; index < boxes.length; index++) { box = boxes[index]; if (box.type == 'checkbox' && box.className == 'sf_admin_batch_checkbox') box.checked = document.getElementById('sf_admin_list_batch_checkbox').checked } return true;
}
/* ]]> */
</script>
예제 #5
0
 /**
  * Calls a request to a uri.
  *
  * @param string $uri          The URI to fetch
  * @param string $method       The request method
  * @param array  $parameters   The Request parameters
  * @param bool   $changeStack  Change the browser history stack?
  *
  * @return sfBrowserBase
  */
 public function call($uri, $method = 'get', $parameters = array(), $changeStack = true)
 {
     // check that the previous call() hasn't returned an uncatched exception
     $this->checkCurrentExceptionIsEmpty();
     $uri = $this->fixUri($uri);
     // add uri to the stack
     if ($changeStack) {
         $this->stack = array_slice($this->stack, 0, $this->stackPosition + 1);
         $this->stack[] = array('uri' => $uri, 'method' => $method, 'parameters' => $parameters);
         $this->stackPosition = count($this->stack) - 1;
     }
     list($path, $queryString) = false !== ($pos = strpos($uri, '?')) ? array(substr($uri, 0, $pos), substr($uri, $pos + 1)) : array($uri, '');
     $queryString = html_entity_decode($queryString);
     // remove anchor
     $path = preg_replace('/#.*/', '', $path);
     // removes all fields from previous request
     $this->fields = array();
     // prepare the request object
     $_SERVER = $this->defaultServerArray;
     $_SERVER['HTTP_HOST'] = $this->hostname;
     $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['HTTP_USER_AGENT'] = 'PHP5/CLI';
     $_SERVER['REMOTE_ADDR'] = $this->remote;
     $_SERVER['REQUEST_METHOD'] = strtoupper($method);
     $_SERVER['PATH_INFO'] = $path;
     $_SERVER['REQUEST_URI'] = '/index.php' . $uri;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['SCRIPT_FILENAME'] = '/index.php';
     $_SERVER['QUERY_STRING'] = $queryString;
     if ($this->stackPosition >= 1) {
         $_SERVER['HTTP_REFERER'] = sprintf('http%s://%s%s', isset($this->defaultServerArray['HTTPS']) ? 's' : '', $this->hostname, $this->stack[$this->stackPosition - 1]['uri']);
     }
     foreach ($this->vars as $key => $value) {
         $_SERVER[strtoupper($key)] = $value;
     }
     foreach ($this->headers as $header => $value) {
         $_SERVER['HTTP_' . strtoupper(str_replace('-', '_', $header))] = $value;
     }
     $this->headers = array();
     // request parameters
     $_GET = $_POST = array();
     if (in_array(strtoupper($method), array('POST', 'DELETE', 'PUT'))) {
         if (isset($parameters['_with_csrf']) && $parameters['_with_csrf']) {
             unset($parameters['_with_csrf']);
             $form = new BaseForm();
             $parameters[$form->getCSRFFieldName()] = $form->getCSRFToken();
         }
         $_POST = $parameters;
     }
     if (strtoupper($method) == 'GET') {
         $_GET = $parameters;
     }
     // handle input type="file" fields
     $_FILES = array();
     if (count($this->files)) {
         $_FILES = $this->files;
     }
     $this->files = array();
     parse_str($queryString, $qs);
     if (is_array($qs)) {
         $_GET = array_merge($qs, $_GET);
     }
     // expire cookies
     $cookies = $this->cookieJar;
     foreach ($cookies as $name => $cookie) {
         if ($cookie['expire'] && $cookie['expire'] < time()) {
             unset($this->cookieJar[$name]);
         }
     }
     // restore cookies
     $_COOKIE = array();
     foreach ($this->cookieJar as $name => $cookie) {
         $_COOKIE[$name] = $cookie['value'];
     }
     $this->doCall();
     $response = $this->getResponse();
     // save cookies
     foreach ($response->getCookies() as $name => $cookie) {
         // FIXME: deal with path, secure, ...
         $this->cookieJar[$name] = $cookie;
     }
     // support for the ETag header
     if ($etag = $response->getHttpHeader('Etag')) {
         $this->vars['HTTP_IF_NONE_MATCH'] = $etag;
     } else {
         unset($this->vars['HTTP_IF_NONE_MATCH']);
     }
     // support for the last modified header
     if ($lastModified = $response->getHttpHeader('Last-Modified')) {
         $this->vars['HTTP_IF_MODIFIED_SINCE'] = $lastModified;
     } else {
         unset($this->vars['HTTP_IF_MODIFIED_SINCE']);
     }
     // for HTML/XML content, create a DOM and sfDomCssSelector objects for the response content
     $this->dom = null;
     $this->domCssSelector = null;
     if (preg_match('/(x|ht)ml/i', $response->getContentType(), $matches)) {
         $this->dom = new DomDocument('1.0', $response->getCharset());
         $this->dom->validateOnParse = true;
         if ('x' == $matches[1]) {
             @$this->dom->loadXML($response->getContent());
         } else {
             @$this->dom->loadHTML($response->getContent());
         }
         $this->domCssSelector = new sfDomCssSelector($this->dom);
     }
     return $this;
 }
예제 #6
0
function _method_javascript_function($method)
{
    $function = "var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = this.href;";
    if ('post' != strtolower($method)) {
        $function .= "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); ";
        $function .= sprintf("m.setAttribute('name', 'sf_method'); m.setAttribute('value', '%s'); f.appendChild(m);", strtolower($method));
    }
    // CSRF protection
    $form = new BaseForm();
    if ($form->isCSRFProtected()) {
        $function .= "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); ";
        $function .= sprintf("m.setAttribute('name', '%s'); m.setAttribute('value', '%s'); f.appendChild(m);", $form->getCSRFFieldName(), $form->getCSRFToken());
    }
    $function .= "f.submit();";
    return $function;
}
예제 #7
0
</option>
      <?php 
    }
    ?>
 
      
      <?php 
    $form = new BaseForm();
    ?>
 
      
      <?php 
    if ($form->isCSRFProtected()) {
        ?>
        <input type="hidden" name="<?php 
        echo $form->getCSRFFieldName();
        ?>
" value="<?php 
        echo $form->getCSRFToken();
        ?>
" />
      <?php 
    }
    ?>

      <input type="submit" value="<?php 
    echo __('go', array(), 'sf_admin');
    ?>
" />

    </select>
예제 #8
0
            echo $row;
            ?>
</td>
<?php 
        }
    }
}
?>

<td colspan="2">
<?php 
foreach ($form as $row) {
    if ($row->isHidden()) {
        echo $row;
    }
}
?>
<input type="submit" value="<?php 
echo __('Add');
?>
" />
</td>
</tr>
</form>

</table>

<?php 
$form = new BaseForm();
echo sortable_element('type_' . $type, array('tag' => 'tbody', 'only' => 'sortable', 'url' => 'community/categorySort', 'with' => 'Sortable.serialize("type_' . $type . '")+"&' . urlencode($form->getCSRFFieldName()) . '=' . urlencode($form->getCSRFToken()) . '"'));
예제 #9
0
<?php

slot('submenu');
include_partial('submenu');
end_slot();
?>

<?php 
slot('title', __('Delete %community%'));
?>

<p><?php 
echo __('Are you sure you want to delete this %community%?');
?>
</p>

<?php 
$form = new BaseForm();
$csrfToken = '<input type="hidden" name="' . $form->getCSRFFieldName() . '" value="' . $form->getCSRFToken() . '"/>';
?>

<form action="<?php 
url_for('community/delete?id=' . $community->getId());
?>
" method="post">
<?php 
include_partial('community/communityInfo', array('community' => $community, 'moreInfo' => array($csrfToken . '<input type="submit" value="削除" />')));
?>
</form>

 /**
  * Get CSRF token
  * 
  * @return  string|false    CSRF token string
  */
 public function getCsrfToken()
 {
     if (is_null($this->csrfToken)) {
         $this->csrfToken = $this->csrfField = false;
         $form = new BaseForm();
         if ($form->isCSRFProtected()) {
             $this->csrfToken = $form->getCSRFToken();
             $this->csrfField = $form->getCSRFFieldName();
         }
     }
     return $this->csrfToken;
 }
예제 #11
0
        echo $row;
    }
}
?>
<input type="submit" value="<?php 
echo __('Add');
?>
" />
</td>
</tr>
</form>

</table>

<?php 
$form = new BaseForm();
echo javascript_tag('
$("#type_' . $type . ' tbody").sortable({
  items: "> .sortable",
  update: function (event, ui) {
    var postData = $(this).sortable("serialize", { expression: /(type_' . $type . ')_(.+)/ });
    postData += "&' . urlencode($form->getCSRFFieldName()) . '=' . urlencode($form->getCSRFToken()) . '";

    $.ajax({
      url: "' . url_for('community/categorySort') . '",
      type: "POST",
      data: postData
    });
  }
});
');