Пример #1
0
 public function authenticateUserRequest()
 {
     $authResult = $this->authenticateKey($this->request->getParameter('_key'));
     switch ($authResult) {
         case self::AUTH_FAIL_KEY:
             $this->response->setStatusCode(401);
             sfLoader::loadHelpers('Partial');
             $partial = get_partial('global/401');
             $this->response->setContent($partial);
             $this->response->setHttpHeader('WWW-Authenticate', 'Your request must include a query parameter named "_key" with a valid API key value. To obtain an API key, visit http://api.littlesis.org/register');
             $this->response->sendHttpHeaders();
             $this->response->sendContent();
             throw new sfStopException();
             break;
         case self::AUTH_FAIL_LIMIT:
             $this->response = sfContext::getInstance()->getResponse();
             $this->response->setStatusCode(403);
             $user = Doctrine::getTable('ApiUser')->findOneByApiKey($this->request->getParameter('_key'));
             sfLoader::loadHelpers('Partial');
             $partial = get_partial('global/403', array('request_limit' => $user->request_limit));
             $this->response->setContent($partial);
             $this->response->sendHttpHeaders();
             $this->response->sendContent();
             throw new sfStopException();
             break;
         case self::AUTH_SUCCESS:
             break;
         default:
             throw new Exception("Invalid return value from LsApi::autheticate()");
     }
 }
 public function getDecorator()
 {
     sfLoader::loadHelpers('Url');
     sfLoader::loadHelpers('Tag');
     $decorator = link_to('%s', '@hyperword_processor?word=%s', array('class' => 'hyperword'));
     return str_replace('%25s', '%s', $decorator);
 }
 protected function getCacheManifestFilesForConfig($config, $callback, $files = array())
 {
     $context = $this->getContext();
     // compatibility with symfony 1.0:
     if (method_exists($context, 'getConfiguration') && method_exists($context->getConfiguration(), 'loadHelpers')) {
         $context->getConfiguration()->loadHelpers('Asset');
     } else {
         if (method_exists('sfLoader', 'loadHelpers')) {
             sfLoader::loadHelpers('Asset');
             //maintain compatibility to symfony versions prior to 1.3
         }
     }
     foreach ($config as $key => $value) {
         if (is_string($value)) {
             $files[] = $callback($value);
         } else {
             if (is_array($value)) {
                 foreach ($value as $filename => $options) {
                     $files[] = $callback($filename);
                 }
             }
         }
     }
     return $files;
 }
Пример #4
0
 public static function extractSummaryArray($body, $min, $total)
 {
     //replace whitespaces with space
     $body = preg_replace("/(\\r?\\n[ \\t]*)+/", " ", $body);
     //find paragraphs
     $matches = array();
     preg_match_all("/<p>(.+)<\\/p>/isU", $body, $matches, PREG_SET_ORDER);
     //put paragraphs to a fresh array and calculate total length
     $total_length = 0;
     $paragraphs = array();
     foreach ($matches as $match) {
         $len = 0;
         if (($len = strlen($match[1])) > $min) {
             $paragraphs[] = $match[1];
             $total_length += strlen($match[1]);
         }
     }
     //chop paragraphs
     sfLoader::loadHelpers('Text');
     $final = array();
     for ($i = 0; $i < sizeof($paragraphs); $i++) {
         $share = (int) ($total * strlen($paragraphs[$i]) / $total_length);
         if ($share < $min) {
             $total_length -= strlen($paragraphs[$i]);
             continue;
         }
         $final[] = truncate_text($paragraphs[$i], $share, "", true);
     }
     return $final;
 }
    public function __construct(array $workflowtemplate, $workflowversionid) {
        sfLoader::loadHelpers('Partial');
        $this->workflowtemplate = $workflowtemplate;
        $this->version = $workflowversionid;
        $this->setUserSettings($workflowtemplate['sender_id']);
        $this->sendWorkflowCompletedEmail();

    }
Пример #6
0
 public function loadHelper() {
     sfLoader::loadHelpers('Date');
     sfLoader::loadHelpers('Url');
     sfLoader::loadHelpers('CalculateDate');
     sfLoader::loadHelpers('ColorBuilder');
     sfLoader::loadHelpers('I18N');
     sfLoader::loadHelpers('Icon');
 }
 public function  __construct(sfContext $context_in, myUser $user) {
     sfLoader::loadHelpers('I18N');
     sfLoader::loadHelpers('Date');
     sfLoader::loadHelpers('Url');
     sfLoader::loadHelpers('CalculateDate');
     sfLoader::loadHelpers('ColorBuilder');
     $this->context = $context_in;
     $this->user = $user;
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     sfLoader::loadHelpers('Javascript');
     if ($this->getOption("plain")) {
         return $value . input_hidden_tag($name, $value);
     } else {
         return input_auto_complete_tag($name, $value, 'tag/searchTag?src=' . $this->getOption('src'), array('autocomplete' => 'off', 'size' => '15'), array('use_style' => 'true'));
     }
 }
Пример #9
0
 public static function prepareRelData($rel)
 {
     sfLoader::loadHelpers(array("Asset", "Url"));
     try {
         $url = url_for(RelationshipTable::generateRoute($rel));
     } catch (Exception $e) {
         $url = "http://littlesis.org/relationship/view/id/" . $rel['id'];
     }
     return array("id" => self::integerize($rel["id"]), "entity1_id" => self::integerize($rel["entity1_id"]), "entity2_id" => self::integerize($rel["entity2_id"]), "category_id" => self::integerize($rel["category_id"]), "category_ids" => (array) self::integerize($rel["category_ids"]), "is_current" => self::integerize($rel["is_current"]), "end_date" => @$rel["end_date"], "value" => 1, "label" => $rel["label"], "url" => $url, "x1" => @$rel["x1"], "y1" => @$rel["y1"], "fixed" => true);
 }
Пример #10
0
    /**
     * Action loads an IFrame for the email, when settings are set IFRAME and HTML
     * the template getIframeSuccess.php adds the needed fields to the iframe
     * @param sfWebRequest $request
     * @return <type>
     */

    public function executeGetIFrame(sfWebRequest $request) {
        sfLoader::loadHelpers('Url', 'I18N');
        $serverUrl  = str_replace('/layout', '', url_for('layout/index', true));
        $versionId = $request->getParameter('versionid');
        $templateId = $request->getParameter('workflowid');
        $userId = $request->getParameter('userid');
        $userSettings = new UserMailSettings($userId);
        $context = sfContext::getInstance();

        $sf_i18n = $context->getI18N();
        $sf_i18n->setCulture($userSettings->userSettings['language']);


        $this->linkto = $context->getI18N()->__('Direct link to workflow' ,null,'sendstationmail');
        

        $wfSettings = WorkflowVersionTable::instance()->getWorkflowVersionById($versionId);
        $workflow = $wfSettings[0]->getWorkflowTemplate()->toArray();

        $detailObj = new WorkflowDetail(false);
        $detailObj->setServerUrl($serverUrl);
        $detailObj->setCulture($userSettings->userSettings['language']);
        $detailObj->setContext($context);
        

        $editObj = new WorkflowEdit(false);
        $editObj->setServerUrl($serverUrl);
        $editObj->setContext($context);
        $editObj->setCulture($userSettings->userSettings['language']);
        $editObj->setUserId($userId);
        $this->slots = $editObj->buildSlots($wfSettings , $versionId);


        $content['workflow'][0] = $context->getI18N()->__('You have to fill out the fields in the workflow' ,null,'sendstationmail');
        $content['workflow'][1] = $workflow[0]['name'];
        $content['workflow'][2] = $context->getI18N()->__('Slot' ,null,'sendstationmail');
        $content['workflow'][3] = $context->getI18N()->__('Yes' ,null,'sendstationmail');
        $content['workflow'][4] = $context->getI18N()->__('No' ,null,'sendstationmail');
        $content['workflow'][5] = $context->getI18N()->__('Field' ,null,'sendstationmail');
        $content['workflow'][6] = $context->getI18N()->__('Value' ,null,'sendstationmail');
        $content['workflow'][7] = $context->getI18N()->__('File' ,null,'sendstationmail');
        $content['workflow'][8] = $context->getI18N()->__('Accept Workflow' ,null,'sendstationmail');
        $content['workflow'][9] = $context->getI18N()->__('Deny Workflow' ,null,'sendstationmail');
        $content['workflow'][10] = $context->getI18N()->__('Save' ,null,'sendstationmail');

        $this->error = $request->getParameter('error',0);
        $this->serverPath = $serverUrl;
        $this->workflowverion = $versionId;
        $this->userid  = $userId;
        $this->workflow  = $templateId;
        $this->text = $content;
	$this->setLayout(false);
	$this->setTemplate('getIFrame');
        return sfView::SUCCESS;
    }
Пример #11
0
function display_page_header($module, $document, $id, $metadata, $current_version, $options = array())
{
    $is_archive = $document->isArchive();
    $mobile_version = c2cTools::mobileVersion();
    $content_class = $module . '_content';
    $lang = $document->getCulture();
    $version = $is_archive ? $document->getVersion() : NULL;
    $slug = '';
    $prepend = _option($options, 'prepend', '');
    $separator = _option($options, 'separator', '');
    $nav_options = _option($options, 'nav_options');
    $item_type = _option($options, 'item_type', '');
    $nb_comments = _option($options, 'nb_comments');
    $creator_id = _option($options, 'creator_id');
    if (!$is_archive) {
        if ($module != 'users') {
            $slug = get_slug($document);
            $url = "@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug={$slug}";
        } else {
            $url = "@document_by_id_lang?module={$module}&id={$id}&lang={$lang}";
        }
    } else {
        $url = "@document_by_id_lang_version?module={$module}&id={$id}&lang={$lang}&version={$version}";
    }
    if (!empty($prepend)) {
        $prepend .= $separator;
    }
    echo display_title($prepend . $document->get('name'), $module, true, 'default_nav', $url);
    if (!$mobile_version) {
        echo '<div id="nav_space">&nbsp;</div>';
        sfLoader::loadHelpers('WikiTabs');
        $tabs = tabs_list_tag($id, $lang, $document->isAvailable(), 'view', $version, $slug, $nb_comments);
        echo $tabs;
        // liens internes vers les sections repliables du document
        if ($nav_options == null) {
            include_partial("{$module}/nav_anchor");
        } else {
            include_partial("{$module}/nav_anchor", array('section_list' => $nav_options));
        }
        // boutons vers des fonctions annexes et de gestion du document
        include_partial("{$module}/nav", isset($creator_id) ? array('id' => $id, 'document' => $document, 'creator_id' => $creator_id) : array('id' => $id, 'document' => $document));
        if ($module != 'users') {
            sfLoader::loadHelpers('Button');
            echo '<div id="nav_share" class="nav_box">' . button_share() . '</div>';
        }
    }
    echo display_content_top('doc_content', $item_type);
    echo start_content_tag($content_class);
    if ($merged_into = $document->get('redirects_to')) {
        include_partial('documents/merged_warning', array('merged_into' => $merged_into));
    }
    if ($is_archive) {
        include_partial('documents/versions_browser', array('id' => $id, 'document' => $document, 'metadata' => $metadata, 'current_version' => $current_version));
    }
}
Пример #12
0
 /**
  * Load core and standard helpers to be use in the template.
  */
 protected function loadCoreAndStandardHelpers()
 {
     static $coreHelpersLoaded = 0;
     if ($coreHelpersLoaded) {
         return;
     }
     $coreHelpersLoaded = 1;
     $core_helpers = array('Helper', 'Url', 'Asset', 'Tag', 'Escaping');
     $standard_helpers = sfConfig::get('sf_standard_helpers');
     $helpers = array_unique(array_merge($core_helpers, $standard_helpers));
     sfLoader::loadHelpers($helpers);
 }
 /**
  *
  * @param int $currentWorklfowSlotId, workflowslotid of the current slot
  * @param int $nextSlotId , SlotId of the next slot
  */
 public function  __construct($currentWorklfowSlotId, $nextWorkflowSlotId, $workflowtemplateId, $workflowversionId) { 
     sfLoader::loadHelpers('EndAction');
     $this->setWorkflowTemplateSettings($workflowtemplateId);
     if($this->checkState() == 1) {
         sfLoader::loadHelpers('Partial');
         $this->workflowVersionId = $workflowversionId;
         $this->setCurrentSlot($currentWorklfowSlotId);
         $this->setNextSlot($nextWorkflowSlotId);
         $this->setUserSettings();
         $this->sendSlotReachedMail();
     }
 }
 public function getSlotEditor($slot)
 {
     $options = array('size' => '80x10', 'id' => 'edit_textarea' . $slot->getName(), 'tinymce_options' => sfConfig::get('app_sfSimpleCMS_tinymce_options', 'width: "100%"'));
     $script = '';
     if (sfConfig::get('app_sfSimpleCMS_rich_editing', false)) {
         sfLoader::loadHelpers(array('Javascript'));
         sfContext::getInstance()->getResponse()->addJavascript('/sfSimpleCMSPlugin/js/tiny_mce_AJAX.js', 'last');
         $script = javascript_tag('setTextareaToTinyMCE("edit_textarea' . $slot->getName() . '");');
         $options['rich'] = 'TinyMCE';
     }
     return $script . textarea_tag('slot_content', $slot->getValue(), $options);
 }
 static function convertValueForDisplay($value, $field, $excerpt = 40)
 {
     if (is_null($value)) {
         return 'NULL';
     }
     if (!($mod = self::loadModification($field))) {
         return $value;
     }
     $table = Doctrine::getTable($mod['object_model']);
     $columns = $table->getColumns();
     if ($mod['object_model'] == 'Entity') {
         if (!array_key_exists($field['field_name'], $columns)) {
             if ($extensionName = EntityTable::getExtensionNameByFieldName($field['field_name'])) {
                 $table = Doctrine::getTable($extensionName);
             }
         }
     } elseif ($mod['object_model'] == 'Relationship') {
         if (!array_key_exists($field['field_name'], $columns)) {
             $table = Doctrine::getTable(RelationshipTable::getCategoryNameByFieldName($field['field_name']));
         }
     }
     if ($alias = self::getFieldNameAlias($field)) {
         $class = $table->getRelation($alias)->getClass();
         if ($record = Doctrine::getTable($class)->find($value, Doctrine::HYDRATE_ARRAY)) {
             if ($class == 'Entity') {
                 sfLoader::loadHelpers('Ls');
                 return entity_link($record, null);
             } elseif ($class == 'sfGuardUser') {
                 sfLoader::loadHelpers('Ls');
                 return user_link($record);
             }
             return $record;
         }
     }
     if (in_array($field['field_name'], array('start_date', 'end_date'))) {
         return Dateable::convertForDisplay($value);
     }
     $def = $table->getColumnDefinition($field['field_name']);
     switch ($def['type']) {
         case 'integer':
             return (double) $value;
             break;
         case 'boolean':
             return $value ? 'yes' : 'no';
             break;
     }
     if ($excerpt) {
         $short = LsString::excerpt($value, $excerpt);
         return $short == $value ? $value : '<span title="' . strip_tags($value) . '">' . $short . '</span>';
     }
     return $value;
 }
Пример #16
0
 public function configure()
 {
     $choices = LsListTable::getNetworksForSelect();
     $this->setWidgets(array('home_network_id' => new sfWidgetFormSelect(array('choices' => $choices)), 'name_first' => new sfWidgetFormInput(array(), array('size' => 30)), 'name_last' => new sfWidgetFormInput(array(), array('size' => 30)), 'public_name' => new sfWidgetFormInput(array(), array('size' => 30)), 'email' => new sfWidgetFormInput(array(), array('size' => 30)), 'reason' => new sfWidgetFormTextarea(array(), array('cols' => 50, 'rows' => 3)), 'password1' => new sfWidgetFormInputPassword(array(), array('size' => 30)), 'password2' => new sfWidgetFormInputPassword(array(), array('size' => 30)), 'user_agrees' => new sfWidgetFormInputCheckbox(), 'captcha' => new sfWidgetFormReCaptcha(array('public_key' => sfConfig::get('app_recaptcha_public_key')))));
     $this->setValidators(array('home_network_id' => new sfValidatorChoice(array('choices' => array_keys($choices), 'required' => true)), 'name_last' => new sfValidatorString(array('max_length' => 50)), 'name_first' => new sfValidatorString(array('max_length' => 50)), 'public_name' => new sfValidatorRegex(array('pattern' => '/^[a-z0-9\\.]{4,30}$/i')), 'email' => new sfValidatorEmail(array('required' => true), array('invalid' => 'You must enter a valid email address')), 'reason' => new sfValidatorString(array('required' => true), array('required' => 'Who are you and why are you signing up?')), 'password1' => new sfValidatorRegex(array('pattern' => '/^[a-z0-9]{6,20}$/i')), 'password2' => new sfValidatorString(array(), array('required' => 'You must enter the password twice')), 'user_agrees' => new sfValidatorBoolean(array('required' => true), array('required' => 'You must accept the user agreement')), 'captcha' => new sfValidatorReCaptcha(array('private_key' => sfConfig::get('app_recaptcha_private_key')), array('invalid' => 'You didn\'t pass the spam test!'))));
     $this->validatorSchema['captcha']->addMessage('captcha', 'You didn\'t pass the spam test!');
     $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('password1', sfValidatorSchemaCompare::EQUAL, 'password2'), array(), array('invalid' => 'You must enter the same password twice'));
     sfLoader::loadHelpers(array('Helper', 'Tag', 'Url'));
     $this->widgetSchema->setLabels(array('home_network_id' => 'Local network', 'name_first' => 'First name', 'name_last' => 'Last name', 'reason' => 'A little about you and why you\'re signing up', 'analyst_reason' => 'Why you want to be an ' . link_to('analyst', '@howto'), 'public_name' => 'Public username', 'password1' => 'Password', 'password2' => 'Password (again)', 'user_agrees' => 'Terms of use', 'captcha' => 'Spam test'));
     $this->widgetSchema->setNameFormat('user[%s]');
     $this->validatorSchema->setOption('allow_extra_fields', true);
     $this->validatorSchema->setOption('filter_extra_fields', false);
 }
Пример #17
0
 public static function getNamesForAutocomplete($q)
 {
     sfLoader::loadHelpers("Url");
     $c = new Criteria();
     $c->add(TagPeer::NAME, $q . "%", Criteria::LIKE);
     $c->setLimit(10);
     $names = array();
     $tags = TagPeer::doSelect($c);
     foreach ($tags as $tag) {
         $names[] = array("id" => $tag->getId(), "name" => $tag->getName(), "searchUrl" => url_for("job_listby_tag", $tag));
     }
     return $names;
 }
Пример #18
0
 /**
  *
  * @param int $versionId, id of the current workflow
  * @param String $text, the text to replace
  * @param String $culture, the language
  * @param sfContext $context , context object
  */
 public function __construct($versionId, $text, $culture, $context = false) {
     if($context == false) {
         sfLoader::loadHelpers('Date');
     }
     else {
         $context->getConfiguration()->loadHelpers('Date');
     }
     $this->setWorkflow($versionId);
     $this->setWorkflowVersion($versionId);
     $this->culture = $culture;
     $this->theSender = new UserMailSettings($this->workflow['sender_id']);
     $this->newText = $this->replacePlaceholder($text);
 }
 public function executeCategories()
 {
     $installed = array_keys($this->getLuceneInstance()->getCategories()->getAllCategories());
     sfLoader::loadHelpers('I18N');
     $categories = array(null => __('All'));
     if (count($installed)) {
         sort($installed);
         $categories += array_combine($installed, $installed);
     }
     $this->categories = $categories;
     $this->show = count($categories) > 1 ? true : false;
     $this->selected = $this->getRequestParameter('category', 0);
 }
Пример #20
0
 /**
  * Loads core and standard helpers to be use in the template.
  */
 protected function loadCoreAndStandardHelpers()
 {
     static $coreHelpersLoaded = 0;
     if ($coreHelpersLoaded) {
         return;
     }
     $coreHelpersLoaded = 1;
     $helpers = array_unique(array_merge(array('Helper', 'Url', 'Asset', 'Tag', 'Escaping'), sfConfig::get('sf_standard_helpers')));
     // remove default Form helper if compat_10 is false
     if (!sfConfig::get('sf_compat_10') && false !== ($i = array_search('Form', $helpers))) {
         unset($helpers[$i]);
     }
     sfLoader::loadHelpers($helpers);
 }
Пример #21
0
    /**
    * Show the login page
    *
    * @param sfRequest $request A request object
    */
    public function executeIndex(sfWebRequest $request) {
        $this->getUser()->setAuthenticated(false);
        sfLoader::loadHelpers('Url');
        $this->getUser()->setCulture(Language::loadDefaultLanguage());
        $tm = new ThemeManagement();
        $systemTheme = UserConfigurationTable::instance()->getUserConfiguration()->toArray();
        $this->theTheme = $systemTheme[0]['theme'];

        /*
         * -1 is set when user uses login form to login
         * int is set, when user logges in from en email link, then a workflow needs to opened
         */
        $this->version_id = $request->getParameter('versionid',-1);
        $this->workflow_id = $request->getParameter('workflow',-1);
        $this->window  = $request->getParameter('window',-1);
        return sfView::SUCCESS;
    }
Пример #22
0
 public function convertValueForDisplay($value)
 {
     if (is_null($value)) {
         return '<span class="text_small">NULL</span>';
     }
     if (!($record = $this->Modification->getObject(true))) {
         return $value;
     }
     $table = $record->getTable();
     if ($record instanceof Entity) {
         $data = $record->getData();
         if (!array_key_exists($this->field_name, $data)) {
             if ($extensionName = EntityTable::getExtensionNameByFieldName($this->field_name)) {
                 $table = Doctrine::getTable($extensionName);
             }
         }
     } elseif ($record instanceof Relationship) {
         $data = $record->getData();
         if (!array_key_exists($this->field_name, $data)) {
             $table = Doctrine::getTable(RelationshipTable::getCategoryNameByFieldName($this->field_name));
         }
     }
     if ($alias = $this->getFieldNameAlias()) {
         $class = $table->getRelation($alias)->getClass();
         if ($record = Doctrine::getTable($class)->find($value)) {
             if ($record instanceof Entity) {
                 sfLoader::loadHelpers('Ls');
                 return entity_link($record, null);
             }
             return $record;
         }
     }
     if (in_array($this->field_name, array('start_date', 'end_date'))) {
         return Dateable::convertForDisplay($value);
     }
     $def = $table->getColumnDefinition($this->field_name);
     switch ($def['type']) {
         case 'integer':
             return (string) $value;
             break;
         case 'boolean':
             return $value ? 'yes' : 'no';
             break;
     }
     return LsString::excerpt($value);
 }
 public function executeCreate(sfWebRequest $request)
 {
     $this->setLayout(FALSE);
     sfConfig::set('sf_web_debug', false);
     sfLoader::loadHelpers('I18N');
     $this->getResponse()->setTitle(__('Image Upload'));
     $this->getResponse()->addStyleSheet('/sfTinyMceImageBrowser/css/sfTinyMceImageBrowser.css', 'last');
     $this->getResponse()->addJavascript('/lib/tiny_mce/tiny_mce_popup.js');
     $this->getResponse()->addJavaScript('/sfTinyMceImageBrowser/js/sfTinyMceImageBrowser.js');
     $this->form = new sfTinyMceImageForm(new sfTinyMceImage());
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             if ($this->form->save()) {
                 $this->redirect('sfTinyMceImageBrowser/create');
             }
         }
     }
 }
Пример #24
0
 public static function getRegions($area_type, $user_prefered_langs, $ids = array())
 {
     sfLoader::loadHelpers(array('General'));
     $filter_type = !empty($area_type);
     $filter_ids = !empty($ids);
     $select = 'a.id, i.name';
     if (!$filter_type) {
         $select .= ', a.area_type';
     }
     $q = Doctrine_Query::create()->select($select)->from('Area a')->leftJoin('a.AreaI18n i');
     if ($filter_type) {
         $q->where('a.area_type = ?', array($area_type));
     }
     if ($filter_ids) {
         $condition_array = array();
         foreach ($ids as $id) {
             $condition_array[] = '?';
         }
         $q->where('a.id IN ( ' . implode(', ', $condition_array) . ' )', array($ids));
     }
     if ($filter_type || $filter_ids) {
         $q->orderBy('i.search_name');
     } else {
         $q->orderBy('a.area_type');
     }
     $results = $q->execute(array(), Doctrine::FETCH_ARRAY);
     // build the actual results based on the user's prefered language
     $out = array();
     foreach ($results as $result) {
         $ref_culture_rank = 10;
         // fake high value
         foreach ($result['AreaI18n'] as $translation) {
             $tmparray = array_keys($user_prefered_langs, $translation['culture']);
             $rank = array_shift($tmparray);
             if ($rank < $ref_culture_rank) {
                 $best_name = $translation['name'];
                 $ref_culture_rank = $rank;
             }
         }
         $out[$result['id']] = ucfirst($best_name);
     }
     return $out;
 }
  /**
   * Executes this filter.
   *
   * @param sfFilterChain A sfFilterChain instance
   */
  public function execute($filterChain)
  {
    // execute next filter
    $filterChain->execute();

    $response = $this->getContext()->getResponse();
    $content = $response->getContent();

    // include UJS
    if ((false !== ($pos = strpos($content, '</body>'))) && !$response->getParameter('included', false, 'symfony/view/UJS'))
    {
      sfLoader::loadHelpers(array('Tag', 'UJS'));

      if ($html = get_UJS())
      {
        $response->setContent(substr($content, 0, $pos).$html.substr($content, $pos));
      }
    }
    
    $response->setParameter('included', false, 'symfony/view/UJS');
  }
 public function getSlotValue($slot)
 {
     sfLoader::loadHelpers(array('Partial'));
     $components = sfYaml::load($slot->getValue());
     $res = '';
     foreach ($components as $name => $params) {
         if (!isset($params['component']) && !isset($params['partial'])) {
             return sprintf('<strong>Error</strong>: The value of slot %s in incorrect. Component %s has no \'component\' or \'partial\' key.', $slot->getName(), $name);
         }
         if (isset($params['component'])) {
             // component
             list($module, $action) = split('/', $params['component']);
             unset($params['component']);
             $res .= get_component($module, $action, $params);
         } else {
             // partial
             $res .= get_partial($params['partial'], $params);
             unset($params['partial']);
         }
     }
     return $res;
 }
Пример #27
0
 public function execute($filterChain)
 {
     $request = $this->getContext()->getRequest();
     $sessionUser = $this->getContext()->getUser();
     if ($sessionUser->isAuthenticated() && !$sessionUser->hasCredential('admin') && !$sessionUser->hasCredential('deleter') && $request->isMethod('post') && $request->getParameter('action') != 'descriptions') {
         $user = $sessionUser->getGuardUser();
         $params = array_diff_key($request->getParameterHolder()->getAll(), array('module' => null, 'action' => null));
         //log form post
         $post = new UserFormPost();
         $post->User = $user;
         $post->module = $request->getParameter('module');
         $post->action = $request->getParameter('action');
         $post->params = in_array($request->getParameter('action'), array('signin', 'join', 'changePassword')) ? null : http_build_query($params);
         $post->save();
         //check for badness
         $banned = false;
         $fiveMinutesAgo = date('Y-m-d H:i:s', time() - 5 * 60);
         $q = LsDoctrineQuery::create()->from('UserFormPost p')->where('p.user_id = ? AND p.created_at > ?', array($user->id, $fiveMinutesAgo))->orderBy('p.created_at DESC');
         if ($q->count() > 40) {
             //BAD! logout and de-activate user
             $sessionUser->setAuthenticated(false);
             $user->is_active = false;
             $user->save();
             $banned = true;
         }
         if ($q->count() > 20) {
             //SUSPICIOUS! notify admins
             sfLoader::loadHelpers('Partial');
             $mailBody = get_partial('home/formpostnotify', array('user' => $user, 'posts' => $q->execute(), 'banned' => $banned));
             $mailer = new Swift(new Swift_Connection_NativeMail());
             $message = new Swift_Message('Suspicious user activity', $mailBody, 'text/plain');
             $address = new Swift_Address(sfConfig::get('app_mail_alert_sender_address'), sfConfig::get('app_mail_alert_sender_name'));
             $mailer->send($message, sfConfig::get('app_mail_alert_recipient_address'), $address);
             $mailer->disconnect();
             $this->sent = true;
         }
     }
     $filterChain->execute();
 }
Пример #28
0
 protected function handleErrorForAjax()
 {
     $errors = $this->getRequest()->getErrors();
     $field_error = sfConfig::get('app_form_field_error');
     $js_errors = "'#" . implode(", #", array_keys($errors)) . "'";
     $arrow = sfConfig::get('sf_validation_error_prefix', '');
     $this->getResponse()->setStatusCode(404);
     sfLoader::loadHelpers(array('Javascript', 'Tag'));
     // add error class on fields via js
     $js = "\$('.{$field_error}').removeClass('{$field_error}');";
     $js .= "\$('.form_error').hide();";
     // remove all errors
     $js .= "\$({$js_errors}).addClass('{$field_error}');";
     // display new ones (if any);
     // global form error
     $toReturn = $this->__('Oups!') . '<ul>';
     foreach ($errors as $name => $error) {
         $js .= "\$('#error_for_{$name}').html(" . json_encode($arrow . $this->__($error) . $arrow) . ").show();";
         $toReturn .= '<li>' . $this->__($error) . '</li>';
     }
     $toReturn .= '</ul>';
     return $this->renderText(javascript_tag($js) . $toReturn);
 }
 /**
  * Executes this filter.
  *
  * @param sfFilterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     // execute next filter
     $filterChain->execute();
     // execute this filter only once
     $response = $this->getContext()->getResponse();
     // include javascripts and stylesheets
     $content = $response->getContent();
     if (false !== ($pos = strpos($content, '</head>'))) {
         sfLoader::loadHelpers(array('Tag', 'Asset'));
         $html = '';
         if (!$response->getParameter('javascripts_included', false, 'symfony/view/asset')) {
             $html .= get_javascripts($response);
         }
         if (!$response->getParameter('stylesheets_included', false, 'symfony/view/asset')) {
             $html .= get_stylesheets($response);
         }
         if ($html) {
             $response->setContent(substr($content, 0, $pos) . $html . substr($content, $pos));
         }
     }
     $response->setParameter('javascripts_included', false, 'symfony/view/asset');
     $response->setParameter('stylesheets_included', false, 'symfony/view/asset');
 }
<?php

/*
 * This file is part of the openparlamento
 * 
 * @author Guglielmo Celata <*****@*****.**>
 */
sfLoader::loadHelpers(array('Javascript', 'Tag', 'I18N'));
$response = sfContext::getInstance()->getResponse();
$css = '/deppPropelActAsVotableBehaviorPlugin/css/depp_voting';
$response->addStylesheet($css);
/**
 * Return the HTML code the div containing the voter tool
 * If the user has already voted, then a message appears
 * 
 * @param  BaseObject  $object   Propel object instance to vote
 * @param  string      $domid    unique css identifier for the block (div) containing the voter tool
 * @param  array       $options  Array of HTML options to apply on the HTML list
 * @return string
 **/
function depp_voting_block($object, $domid = 'depp-voter-block', $options = array())
{
    $response->addJavascript('prototype.js');
    return content_tag('div', depp_voter($object, $domid, '', $options), array('id' => $domid));
}
/**
 * Return the HTML code for an unordered list showing opinions that can be voted (AJAX)
 * If the user has already voted, then a message appears
 * 
 * @param  BaseObject  $object   Propel object instance to vote
 * @param  string      $domid    unique css identifier for the block (div) containing the voter tool