public function render(ddUploadify $up)
 {
     $widget_id = $this->getSlug() . '-input';
     $form = new BaseForm();
     $csrf_token = $form->getCSRFToken();
     $output = '<div class="container dd-img-upload-wrapper">';
     $output .= '<div id="fileQueue"></div>';
     $output .= '<input type="file" name="' . $up->getSlug() . '" id="' . $widget_id . '" />';
     $output .= '<p><a href="javascript:jQuery(\'#' . $widget_id . '\').uploadifyClearQueue()">Cancel All Uploads</a></p>';
     $output .= '<div class="swfupload-buttontarget">
     <noscript>
       We\'re sorry.  SWFUpload could not load.  You must have JavaScript enabled to enjoy SWFUpload.
     </noscript>
   </div>';
     $output .= '<script type="text/javascript">
     //<![CDATA[
     $(document).ready(function() {
       $(\'#' . $widget_id . ' \').uploadify({
         \'scriptData\': {\' ' . array_key($up->getSession()) . ' \': \' ' . array_value($up->getSession()) . ' \', \'_csrf_token\': \' ' . $csrf_token . ' \'},
         \'uploader\': \' ' . $up->getUploader() . ' \',
         \'cancelImg\': \'cancel.png\',
         \'auto\'      : true,
         \'script\': $(\'#' . $widget_id . '\').closest(\'form\').attr(\'action\')+\'/upload\',
         \'folder\': \'\',
         \'multi\': false,
         \'displayData\': \'speed \',
         \'fileDataName\': \' ' . $widget_id . ' \',
         \'simUploadLimit\': 2
       });
     });
     //]]>
   </script>';
     printf($output);
 }
Example #2
0
 public static function getToken()
 {
     $form = new BaseForm();
     if ($form->isCSRFProtected()) {
         return $form->getCSRFToken();
     }
     return '';
 }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        self::$INSTANCE_COUNT++;
        $output = parent::render($name, $value, $attributes, $errors);
        $widget_id = $this->getAttribute('id') ? $this->getAttribute('id') : $this->generateId($name);
        $session_name = ini_get('session.name');
        $session_id = session_id();
        $uploader = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_uploadify_path') . '/' . sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_uploader');
        $cancel_img = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_uploadify_path') . '/' . sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_cancel_img');
        $sim_upload_limit = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_sim_upload_limit');
        $display_data = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_display_data');
        $auto = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_auto');
        $multi = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_multi');
        $form = new BaseForm();
        $csrf_token = $form->getCSRFToken();
        $output .= <<<EOF
      <div class="swfupload-buttontarget">
        <noscript>
          We're sorry.  SWFUpload could not load.  You must have JavaScript enabled to enjoy SWFUpload.
        </noscript>
      </div>
      <script type="text/javascript">
        //<![CDATA[
        \$(document).ready(function() {
          \$('#{$widget_id}').uploadify({
            'scriptData': {'{$session_name}':'{$session_id}', '_csrf_token':'{$csrf_token}'},
            'uploader': '{$uploader}',
            'cancelImg': '{$cancel_img}',
            'auto'      : {$auto},
            'script': \$('#{$widget_id}').closest('form').attr('action')+'/upload',
            'folder': '/',
            'multi': {$multi},
            'displayData': '{$display_data}',
            'fileDataName': '{$widget_id}',
            'simUploadLimit': {$sim_upload_limit}
          });
        });
        //]]>
      </script>
EOF;
        return $output;
    }
/**
 * 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;
        }
    }
}
Example #5
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>
 /**
  * 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;
 }
Example #8
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;
}
Example #9
0
    ?>
 
      
      <?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>
  </li>
<?php 
}
Example #10
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()) . '"'));
Example #11
0
 /**
  * Executes importFile
  *
  * @param sfWebRequest $request
  */
 public function executeImportFile(sfWebRequest $request)
 {
     $baseForm = new BaseForm();
     $this->csrfToken = $baseForm->getCSRFToken();
     $this->form = new opImportCsvFileForm();
     $this->form->bind($request->getParameter('import'), $request->getFiles('import'));
     if ($this->form->isValid()) {
         $this->token = $this->getRandom(16);
         $validatedFile = $this->form->getValue('file');
         $dir = sfConfig::get('sf_app_cache_dir') . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'opCsvPlugin';
         $validatedFile->save($dir . DIRECTORY_SEPARATOR . $this->token . 'tmp.csv');
         Doctrine::getTable('SnsConfig')->set('op_csv_plugin_import', serialize(array($this->token => $validatedFile->getSavedName(), 'ts' => time())));
         return sfView::SUCCESS;
     }
     $this->setTemplate('import');
 }
Example #12
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;
 }
Example #14
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
    });
  }
});
');
Example #15
0
            <?php 
    if ($pager->haveToPaginate()) {
        ?>
              <?php 
        echo __('(page %%page%%/%%nb_pages%%)', array('%%page%%' => $pager->getPage(), '%%nb_pages%%' => $pager->getLastPage()), 'sf_admin');
        ?>
            <?php 
    }
    ?>
          </th>
        </tr>
      </tfoot>
      <tbody>
        <?php 
    $form = new BaseForm();
    $csrf = $form->getCSRFToken();
    ?>
        <?php 
    foreach ($pager->getResults() as $i => $sf_guard_user) {
        $odd = fmod(++$i, 2) ? 'odd' : 'even';
        ?>
          <tr class="sf_admin_row <?php 
        echo $odd;
        ?>
">
            <?php 
        include_partial('sfGuardUser/list_td_batch_actions', array('sf_guard_user' => $sf_guard_user, 'helper' => $helper));
        ?>
            <?php 
        include_partial('sfGuardUser/list_td_tabular', array('sf_guard_user' => $sf_guard_user));
        ?>