private function update_position($request)
 {
     $fields_list = json_decode(TextHelper::html_entity_decode($request->get_value('tree')));
     foreach ($fields_list as $position => $tree) {
         PersistenceContext::get_querier()->inject("UPDATE " . DB_TABLE_MEMBER_EXTENDED_FIELDS_LIST . " SET \r\n\t\t\t\tposition = :position\r\n\t\t\t\tWHERE id = :id", array('position' => $position, 'id' => $tree->id));
     }
 }
 protected function load_lang(HTTPRequestCustom $request)
 {
     $locale = TextHelper::htmlspecialchars($request->get_string('lang', UpdateController::DEFAULT_LOCALE));
     LangLoader::set_locale($locale);
     UpdateUrlBuilder::set_locale($locale);
     $this->lang = LangLoader::get('update', 'update');
 }
Esempio n. 3
0
 function getValue($filtered = true)
 {
     $values = explode($this->separator, $this->_value);
     $tags = array();
     foreach ($values as &$value) {
         $value = trim($value);
         if ($value != '') {
             if ($this->_filter && $filtered) {
                 $value = call_user_func($this->_filter, $value, $this->getName());
             }
             $tags[] = $value;
         }
     }
     $ids = array();
     foreach ($tags as $tag) {
         $ds = new TableReader('blog_tag');
         $id = $ds->select('blog_tag_id')->where('tag', $tag)->fetchScalar();
         if (!$id) {
             $writer = new TableWriter('blog_tag');
             $id = $writer->insert(array('tag' => $tag, 'url_tag' => TextHelper::urlize($tag)));
         }
         $ids[] = $id;
     }
     return $ids;
 }
 private static function register_archive($language_type, $title, $contents, $id_cat)
 {
     $number_subscribers = self::number_subscribers($id_cat);
     $title = TextHelper::strprotect($title, TextHelper::HTML_NO_PROTECT, TextHelper::ADDSLASHES_FORCE);
     $contents = TextHelper::strprotect($contents, HTML_NO_PROTECT, ADDSLASHES_FORCE);
     self::$db_querier->inject("INSERT INTO " . NewsletterSetup::$newsletter_table_archive . " (id_cat, title, contents, timestamp, type, subscribers)\r\n\t\t\tVALUES (:id_cat, :title, :contents, :timestamp, :type, :field_type, :subscribers)", array('id_cat' => $id_cat, 'title' => $title, 'contents' => $contents, 'timestamp' => time(), 'type' => $language_type, 'subscribers' => 0));
 }
    private function build_table()
    {
        $table_model = new SQLHTMLTableModel(CalendarSetup::$calendar_events_table, 'table', array(new HTMLTableColumn(LangLoader::get_message('form.title', 'common'), 'title'), new HTMLTableColumn(LangLoader::get_message('category', 'categories-common'), 'id_category'), new HTMLTableColumn(LangLoader::get_message('author', 'common'), 'display_name'), new HTMLTableColumn(LangLoader::get_message('date', 'date-common'), 'start_date'), new HTMLTableColumn($this->lang['calendar.titles.repetition']), new HTMLTableColumn('')), new HTMLTableSortingRule('start_date', HTMLTableSortingRule::ASC));
        $table_model->set_caption($this->lang['calendar.events_list']);
        $table_model->add_permanent_filter('parent_id = 0');
        $table_model->add_filter(new HTMLTableDateTimeGreaterThanOrEqualsToSQLFilter('start_date', 'filter1', $this->lang['calendar.labels.start_date'] . ' ' . TextHelper::lowercase_first(LangLoader::get_message('minimum', 'common'))));
        $table_model->add_filter(new HTMLTableDateTimeLessThanOrEqualsToSQLFilter('start_date', 'filter2', $this->lang['calendar.labels.start_date'] . ' ' . TextHelper::lowercase_first(LangLoader::get_message('maximum', 'common'))));
        $table = new HTMLTable($table_model);
        $table->set_filters_fieldset_class_HTML();
        $results = array();
        $result = $table_model->get_sql_results('event
			LEFT JOIN ' . CalendarSetup::$calendar_events_content_table . ' event_content ON event_content.id = event.content_id
			LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = event_content.author_id');
        foreach ($result as $row) {
            $event = new CalendarEvent();
            $event->set_properties($row);
            $category = $event->get_content()->get_category();
            $user = $event->get_content()->get_author_user();
            $edit_link = new LinkHTMLElement(CalendarUrlBuilder::edit_event(!$event->get_parent_id() ? $event->get_id() : $event->get_parent_id()), '', array('title' => LangLoader::get_message('edit', 'common')), 'fa fa-edit');
            $delete_link = new LinkHTMLElement(CalendarUrlBuilder::delete_event($event->get_id()), '', array('title' => LangLoader::get_message('delete', 'common'), 'data-confirmation' => !$event->belongs_to_a_serie() ? 'delete-element' : ''), 'fa fa-delete');
            $user_group_color = User::get_group_color($user->get_groups(), $user->get_level(), true);
            $author = $user->get_id() !== User::VISITOR_LEVEL ? new LinkHTMLElement(UserUrlBuilder::profile($user->get_id()), $user->get_display_name(), !empty($user_group_color) ? array('style' => 'color: ' . $user_group_color) : array(), UserService::get_level_class($user->get_level())) : $user->get_display_name();
            $br = new BrHTMLElement();
            $results[] = new HTMLTableRow(array(new HTMLTableRowCell(new LinkHTMLElement(CalendarUrlBuilder::display_event($category->get_id(), $category->get_rewrited_name(), $event->get_id(), $event->get_content()->get_rewrited_title()), $event->get_content()->get_title()), 'left'), new HTMLTableRowCell(new SpanHTMLElement($category->get_name(), array('style' => $category->get_id() != Category::ROOT_CATEGORY && $category->get_color() ? 'color:' . $category->get_color() : ''))), new HTMLTableRowCell($author), new HTMLTableRowCell(LangLoader::get_message('from_date', 'main') . ' ' . $event->get_start_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) . $br->display() . LangLoader::get_message('to_date', 'main') . ' ' . $event->get_end_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE)), new HTMLTableRowCell($event->belongs_to_a_serie() ? $this->get_repeat_type_label($event) . ' - ' . $event->get_content()->get_repeat_number() . ' ' . $this->lang['calendar.labels.repeat_times'] : LangLoader::get_message('no', 'common')), new HTMLTableRowCell($edit_link->display() . $delete_link->display())));
        }
        $table->set_rows($table_model->get_number_of_matching_rows(), $results);
        $this->view->put('table', $table->display());
    }
Esempio n. 6
0
 public function parse()
 {
     $this->content = TextHelper::html_entity_decode($this->content);
     foreach (static::$parsers as $parser) {
         $this->content = $parser->unparse($this->content);
     }
 }
 public static function getAchievementsDefinitions()
 {
     $dir = Config::$achievementsDefinitionsDirectory;
     $imgFiles = scandir(Config::$imageDirectory . DIRECTORY_SEPARATOR . 'achievement');
     $definitions = array_fill_keys(Media::getConstList(), []);
     foreach (glob($dir . DIRECTORY_SEPARATOR . '*.json') as $file) {
         $definition = TextHelper::loadJson($file);
         $prevAch = null;
         foreach ($definition->achievements as &$ach) {
             foreach ($imgFiles as $f) {
                 if (preg_match('/' . $ach->id . '[^0-9a-zA-Z_-]/', $f)) {
                     $ach->path = $f;
                 }
             }
             $ach->next = null;
         }
         foreach ($definition->achievements as &$ach) {
             if ($prevAch !== null) {
                 $prevAch->next = $ach;
             }
             $ach->prev = $prevAch;
             $prevAch =& $ach;
         }
         unset($ach);
         unset($prevAch);
         $definitions[$definition->media][] = $definition;
     }
     foreach (Media::getConstList() as $key) {
         uasort($definitions[$key], function ($a, $b) {
             return $a->order - $b->order;
         });
     }
     return $definitions;
 }
 /**
  * @desc Builds a list of alerts matching the required criteria(s). You can specify many criterias. When you use several of them, it's a AND condition.
  * It will only return the alert which match all the criterias.
  * @param int $id_in_module Id in the module. 
  * @param string $type Alert type.
  * @param string $identifier Alert identifier.
  * @return AdministratorAlert[] The list of the matching alerts.
  */
 public static function find_by_criteria($id_in_module = null, $type = null, $identifier = null)
 {
     $criterias = array();
     if ($id_in_module != null) {
         $criterias[] = "id_in_module = '" . intval($id_in_module) . "'";
     }
     if ($type != null) {
         $criterias[] = "type = '" . TextHelper::strprotect($type) . "'";
     }
     if ($identifier != null) {
         $criterias[] = "identifier = '" . TextHelper::strprotect($identifier) . "'";
     }
     //Restrictive criteria
     if (!empty($criterias)) {
         $array_result = array();
         $result = self::$db_querier->select("SELECT id, entitled, fixing_url, current_status, creation_date, identifier, id_in_module, type, priority, description\n\t\t\tFROM " . DB_TABLE_EVENTS . "\n\t\t\tWHERE contribution_type = '" . ADMINISTRATOR_ALERT_TYPE . "' AND " . implode($criterias, " AND "));
         while ($row = $result->fetch()) {
             $alert = new AdministratorAlert();
             $alert->build($row['id'], $row['entitled'], $row['description'], $row['fixing_url'], $row['current_status'], new Date($row['creation_date'], Timezone::SERVER_TIMEZONE), $row['id_in_module'], $row['identifier'], $row['type'], $row['priority']);
             $array_result[] = $alert;
         }
         $result->dispose();
         return $array_result;
     } else {
         return AdministratorAlertCache::load()->get_all_alerts_number();
     }
 }
Esempio n. 9
0
 static function parse($path, $replacements = array(), &$substitutions = array())
 {
     $path = self::replaceUploadsDir($path);
     $matches1 = array();
     preg_match_all('/{(appd|uploads|public|random|date|root)(?:\\[([0-9a-zA-Z-_]+)\\])?}/', $path, $matches1, PREG_SET_ORDER);
     $matches2 = array();
     $expression = implode('|', array_keys($replacements));
     preg_match_all('/{(' . $expression . ')(?:\\[([0-9a-zA-Z-_]+)\\])?}/', $path, $matches2, PREG_SET_ORDER);
     $matches = array_merge($matches1, $matches2);
     foreach ($matches as $match) {
         if (isset($replacements[$match[1]])) {
             $substitutions[$match[0]] = $replacements[$match[1]];
             if (isset($match[2])) {
                 if (is_numeric($match[2])) {
                     $substitutions[$match[0]] = substr($substitutions[$match[0]], 0, $match[2]);
                 } elseif (is_callable($match[2])) {
                     $substitutions[$match[0]] = call_user_func($match[2], $substitutions[$match[0]]);
                 } elseif ($match[2] == 'url') {
                     $substitutions[$match[0]] = TextHelper::urlize($substitutions[$match[0]]);
                 }
             }
         } else {
             $param = isset($match[2]) ? $match[2] : null;
             $substitutions[$match[0]] = self::replace($match[1], $param);
         }
     }
     return str_replace(array_keys($substitutions), array_values($substitutions), $path);
 }
Esempio n. 10
0
 function test_named_cycles()
 {
     $this->assertEqual('odd', TextHelper::cycle(array('odd', 'even', 'name' => '1st')));
     $this->assertEqual('red', TextHelper::cycle('red', 'black'));
     $this->assertEqual('even', TextHelper::cycle(array('odd', 'even', 'name' => '1st')));
     $this->assertEqual('black', TextHelper::cycle('red', 'black'));
 }
 public function __construct($error_message = '')
 {
     if (empty($error_message)) {
         $error_message = LangLoader::get_message('form.doesnt_match_tel_regex', 'status-messages-common');
     }
     $this->set_validation_error_message($error_message);
     parent::__construct(self::$regex, TextHelper::to_js_string(self::$js_regex), $error_message);
 }
 protected function load_lang(HTTPRequestCustom $request)
 {
     $locale = TextHelper::htmlspecialchars($request->get_string('lang', self::DEFAULT_LOCALE));
     $locale = in_array($locale, InstallationServices::get_available_langs()) ? $locale : self::DEFAULT_LOCALE;
     LangLoader::set_locale($locale);
     InstallUrlBuilder::set_locale($locale);
     $this->lang = LangLoader::get('install', 'install');
 }
Esempio n. 13
0
 function Add_msg($idtopic, $idcat, $contents, $title, $last_page, $last_page_rewrite, $new_topic = false)
 {
     global $LANG;
     ##### Insertion message #####
     $last_timestamp = time();
     $result = PersistenceContext::get_querier()->insert(PREFIX . 'forum_msg', array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id(), 'contents' => FormatingHelper::strparse($contents), 'timestamp' => $last_timestamp, 'timestamp_edit' => 0, 'user_id_edit' => 0, 'user_ip' => AppContext::get_request()->get_ip_address()));
     $last_msg_id = $result->get_last_inserted_id();
     //Topic
     PersistenceContext::get_querier()->inject("UPDATE " . PREFIX . "forum_topics SET " . ($new_topic ? '' : 'nbr_msg = nbr_msg + 1, ') . "last_user_id = '" . AppContext::get_current_user()->get_id() . "', last_msg_id = '" . $last_msg_id . "', last_timestamp = '" . $last_timestamp . "' WHERE id = '" . $idtopic . "'");
     //On met à jour le last_topic_id dans la catégorie dans le lequel le message a été posté
     PersistenceContext::get_querier()->update(ForumSetup::$forum_cats_table, array('last_topic_id' => $idtopic), 'WHERE id = :id', array('id' => $idcat));
     //Mise à jour du nombre de messages du membre.
     PersistenceContext::get_querier()->inject("UPDATE " . DB_TABLE_MEMBER . " SET posted_msg = posted_msg + 1 WHERE user_id = '" . AppContext::get_current_user()->get_id() . "'");
     //On marque le topic comme lu.
     mark_topic_as_read($idtopic, $last_msg_id, $last_timestamp);
     ##### Gestion suivi du sujet mp/mail #####
     if (!$new_topic) {
         //Message précédent ce nouveau message.
         $previous_msg_id = 0;
         try {
             $previous_msg_id = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_msg", 'MAX(id)', 'WHERE idtopic = :idtopic AND id < :id', array('idtopic' => $idtopic, 'id' => $last_msg_id));
         } catch (RowNotFoundException $e) {
         }
         $title_subject = TextHelper::html_entity_decode($title);
         $title_subject_pm = $title_subject;
         if (AppContext::get_current_user()->get_id() > 0) {
             $pseudo = '';
             try {
                 $pseudo = PersistenceContext::get_querier()->get_column_value(DB_TABLE_MEMBER, 'display_name', 'WHERE user_id = :id', array('id' => AppContext::get_current_user()->get_id()));
             } catch (RowNotFoundException $e) {
             }
             $pseudo_pm = '<a href="' . UserUrlBuilder::profile(AppContext::get_current_user()->get_id())->rel() . '">' . $pseudo . '</a>';
         } else {
             $pseudo = $LANG['guest'];
             $pseudo_pm = $LANG['guest'];
         }
         $next_msg_link = '/forum/topic' . url('.php?id=' . $idtopic . $last_page, '-' . $idtopic . $last_page_rewrite . '.php') . ($previous_msg_id ? '#m' . $previous_msg_id : '');
         $preview_contents = substr($contents, 0, 300);
         //Récupération des membres suivant le sujet.
         $max_time = time() - SessionsConfig::load()->get_active_session_duration();
         $result = PersistenceContext::get_querier()->select("SELECT m.user_id, m.display_name, m.email, tr.pm, tr.mail, v.last_view_id\n\t\t\tFROM " . PREFIX . "forum_track tr\n\t\t\tLEFT JOIN " . DB_TABLE_MEMBER . " m ON m.user_id = tr.user_id\n\t\t\tLEFT JOIN " . PREFIX . "forum_view v ON v.idtopic = :idtopic AND v.user_id = tr.user_id\n\t\t\tWHERE tr.idtopic = :idtopic AND v.last_view_id IS NOT NULL AND m.user_id != :user_id", array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id()));
         while ($row = $result->fetch()) {
             //Envoi un Mail à ceux dont le last_view_id est le message précedent.
             if ($row['last_view_id'] == $previous_msg_id && $row['mail'] == '1') {
                 AppContext::get_mail_service()->send_from_properties($row['email'], $LANG['forum_mail_title_new_post'], sprintf($LANG['forum_mail_new_post'], $row['display_name'], $title_subject, AppContext::get_current_user()->get_display_name(), $preview_contents, HOST . DIR . $next_msg_link, HOST . DIR . '/forum/action.php?ut=' . $idtopic . '&trt=1', 1));
             }
             //Envoi un MP à ceux dont le last_view_id est le message précedent.
             if ($row['last_view_id'] == $previous_msg_id && $row['pm'] == '1') {
                 $content = sprintf($LANG['forum_mail_new_post'], $row['display_name'], $title_subject_pm, AppContext::get_current_user()->get_display_name(), $preview_contents, '<a href="' . $next_msg_link . '">' . $next_msg_link . '</a>', '<a href="/forum/action.php?ut=' . $idtopic . '&trt=2">/forum/action.php?ut=' . $idtopic . '&trt=2</a>');
                 PrivateMsg::start_conversation($row['user_id'], $LANG['forum_mail_title_new_post'], nl2br($content), '-1', PrivateMsg::SYSTEM_PM);
             }
         }
         $result->dispose();
         forum_generate_feeds();
         //Regénération du flux rss.
     }
     return $last_msg_id;
 }
 private function get_message()
 {
     $msg = $this->error_message;
     if ($this->input != null) {
         $msg .= "\n" . 'line ' . $this->tpl_line . ' offset ' . $this->offset . ' near';
         $msg .= ' "...' . TextHelper::htmlentities($this->input->to_string(-100, 200)) . '..."';
     }
     return $msg;
 }
Esempio n. 15
0
 public static function modelTranslator($json, $lang)
 {
     if (TextHelper::isJson($json)) {
         $array = json_decode($json, true);
         return $array[$lang];
     } else {
         return $json;
     }
 }
 public function __construct($label, $link, $css_class_image = '')
 {
     $full_label = '';
     if (!empty($css_class_image)) {
         $full_label = '<i class="' . $css_class_image . '" title="' . $label . '"></i>';
     } else {
         $full_label = $label;
     }
     parent::__construct('button', $full_label, '', 'window.location=' . TextHelper::to_js_string(Url::to_rel($link)), 'image');
 }
Esempio n. 17
0
 /**
 * Uses TextHelper::format to take the text and format it, indented two spaces for
 * each line, and wrapped at 72 columns.
 */
  function block_format($text)
  {
      $formatted = '';
      $paragraphs = split("(\n|\r){2,}",$text);
      foreach ((array)$paragraphs as $paragraph){
          $formatted .= TextHelper::format($paragraph, array('columns' => 72, 'first_indent' => 2, 'body_indent' => 2));
      }
      // Make list points stand on their own line
      return preg_replace("/[ ]*([*]+) ([^*]*)/"," $1 $2\n", preg_replace("/[ ]*([#]+) ([^#]*)/"," $1 $2\n",$formatted));
  }
Esempio n. 18
0
 public function __construct($label, $link, $img = '')
 {
     $full_label = '';
     if (!empty($img)) {
         $full_label = '<img src="' . $img . '" alt="' . $label . '" title="' . $label . '" />';
     } else {
         $full_label = $label;
     }
     parent::__construct('button', $full_label, '', 'window.location=' . TextHelper::to_js_string(Url::to_rel($link)), !empty($img) ? 'image' : '');
 }
Esempio n. 19
0
 public function testWordSafeShortText()
 {
     $this->assertEquals("This is a simple test...", $this->object->wordSafeShortText("This is a simple test case", 24, "..."));
     $this->assertEquals("This is a simple test etc", $this->object->wordSafeShortText("This is a simple test case", 22, " etc"));
     $this->assertEquals("This is a simple test.", $this->object->wordSafeShortText("This is a simple test case", 21, "."));
     $this->assertEquals("The quick brown fox jumps over the lazy dog", $this->object->wordSafeShortText("The quick brown fox jumps over the lazy dog"));
     $this->assertEquals("The lazy fox jumps over the quick brown dog", $this->object->wordSafeShortText("The lazy fox jumps over the quick brown dog", 0));
     $this->assertEquals("This_is_a_simple_test_ca…", $this->object->wordSafeShortText("This_is_a_simple_test_case", 24, "…"));
 }
 public function __construct($field_id = 0, $error_message = '')
 {
     if (!empty($field_id)) {
         $this->field_id = $field_id;
     }
     if (empty($error_message)) {
         $error_message = LangLoader::get_message('message.field_name_already_used', 'common', 'contact');
     }
     $this->set_validation_error_message($error_message);
     $this->error_message = TextHelper::to_js_string($error_message);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-profile';
     $viewContext->meta->title = $viewContext->user->name . '\'s profile &#8212; ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s profile.';
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addMiniSections($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $viewContext->yearsOnMal = null;
     if (intval($viewContext->user->join_date)) {
         list($year, $month, $day) = explode('-', $viewContext->user->join_date);
         $time = mktime(0, 0, 0, $month, $day, $year);
         $diff = time() - $time;
         $diff /= 3600 * 24;
         $viewContext->yearsOnMal = $diff / 361.25;
     }
     $viewContext->friends = $viewContext->user->getFriends();
     $viewContext->finished = [];
     $viewContext->meanUserScore = [];
     $viewContext->meanGlobalScore = [];
     $viewContext->franchiseCount = [];
     $viewContext->mismatchedCount = [];
     foreach (Media::getConstList() as $media) {
         $list = $viewContext->user->getMixedUserMedia($media);
         $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
         $viewContext->finished[$media] = count($listFinished);
         unset($listFinished);
         $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
         $viewContext->meanUserScore[$media] = RatingDistribution::fromEntries($listNonPlanned)->getMeanScore();
         $franchises = Model_MixedUserMedia::getFranchises($listNonPlanned);
         $viewContext->franchiseCount[$media] = count(array_filter($franchises, function ($franchise) {
             return count($franchise->ownEntries) > 1;
         }));
         unset($franchises);
         unset($listNonPlanned);
         if ($media == Media::Anime) {
             $viewContext->episodes = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_episodes;
             }, $list));
         } else {
             $viewContext->chapters = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_chapters;
             }, $list));
         }
         $mismatched = $viewContext->user->getMismatchedUserMedia($list);
         $viewContext->mismatchedCount[$media] = count($mismatched);
         unset($mismatched);
         unset($list);
         $globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
         $viewContext->meanGlobalScore[$media] = array_map(function ($v) {
             return RatingDistribution::fromArray($v);
         }, $globalsCache['rating-dist'])[$media]->getMeanScore();
     }
 }
Esempio n. 22
0
 /**
  * Returns a JavaScript snippet to be used on the AJAX callbacks for starting
  * visual effects.
  *
  * Example:
  *  ScriptaculousHelper::visual_effect('highlight', 'posts',
  *    array('duration' => 0.5 ));
  *
  * If no '$element_id' is given, it assumes "element" which should be a local
  * variable in the generated JavaScript execution context. This can be used
  * for example with drop_receiving_element():
  *
  *  ScriptaculousHelper::drop_receving_element(..., array(...
  *        'loading' => ScriptaculousHelper::visual_effect('fade')));
  *
  * This would fade the element that was dropped on the drop receiving element.
  *
  * You can change the behaviour with various options, see
  * http://script.aculo.us for more documentation.
  *
  * @param type <description>
  * @param type <description>
  * @param type <description>
  *
  * @return string <description>
  */
 function visual_effect($name, $element_id = FALSE, $js_opt = array())
 {
     $element = $element_id ? "'{$element_id}'" : 'element';
     switch ($name) {
         case 'toggle_appear':
         case 'toggle_blind':
         case 'toggle_slide':
             return sprintf("new Effect.toggle(%s, '%s', %s)", $element, substr($name, 7), JsHelper::options_for_javascript($js_opt));
     }
     return sprintf("new Effect.%s(%s, %s)", TextHelper::camelize($name), $element, JsHelper::options_for_javascript($js_opt));
 }
Esempio n. 23
0
 function edit()
 {
     if ($this->Request->isAjax() && ($Class =& $this->AkelosClass->find(@$this->params['id']))) {
         $Class->set('description', @$this->params['value']);
         $Class->save();
         $Class->reload();
         $this->renderText(TextHelper::markdown($Class->get('description')));
     } else {
         $this->renderNothing(400);
     }
 }
 private function update_position(HTTPRequestCustom $request)
 {
     $fields = $this->config->get_fields();
     $sorted_fields = array();
     $fields_list = json_decode(TextHelper::html_entity_decode($request->get_value('tree')));
     foreach ($fields_list as $position => $tree) {
         $sorted_fields[$position + 1] = $fields[$tree->id];
     }
     $this->config->set_fields($sorted_fields);
     ContactConfig::save();
 }
Esempio n. 25
0
 private static function build_raw_value($value)
 {
     if (is_bool($value)) {
         return $value ? 'true' : 'false';
     } elseif (is_int($value)) {
         return strval($value);
     } elseif (is_float($value)) {
         return strval($value);
     }
     return TextHelper::to_json_string($value);
 }
 private static function addRecsFromStaticRecommendations($media)
 {
     $staticRecIds = TextHelper::loadSimpleList(Config::$staticRecommendationListPath);
     $weights = [];
     foreach ($staticRecIds as $id) {
         $recMedia = substr($id, 0, 1);
         if ($recMedia == $media) {
             $weights[$id] = null;
         }
     }
     return $weights;
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-favorites';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - favorites (' . Media::toString($viewContext->media) . ')';
     $viewContext->meta->description = $viewContext->user->name . '&rsquo;s ' . Media::toString($viewContext->media) . ' favorites on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']);
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned);
     $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned);
     $favYears = MediaYearDistribution::fromEntries($listNonPlanned);
     $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned);
     $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned);
     $viewContext->favCreators = $favCreators;
     $viewContext->favGenres = $favGenres;
     $viewContext->favYears = $favYears;
     $viewContext->favDecades = $favDecades;
     $viewContext->favTypes = $favTypes;
     $distMeanScore = [];
     $distTimeSpent = [];
     foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) {
         $meanScore = [];
         $timeSpent = [];
         foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) {
             $meanScore[$safeKey] = 0;
             $timeSpent[$safeKey] = 0;
             $subEntries = $dist->getGroupEntries($key);
             $scoreCount = 0;
             foreach ($subEntries as $entry) {
                 $timeSpent[$safeKey] += $entry->finished_duration;
                 $meanScore[$safeKey] += $entry->score;
                 $scoreCount += $entry->score > 0;
             }
             $meanScore[$safeKey] /= max(1, $scoreCount);
         }
         $distMeanScore[get_class($dist)] = $meanScore;
         $distTimeSpent[get_class($dist)] = $timeSpent;
     }
     $viewContext->creatorScores = $distMeanScore[get_class($favCreators)];
     $viewContext->genreScores = $distMeanScore[get_class($favGenres)];
     $viewContext->yearScores = $distMeanScore[get_class($favYears)];
     $viewContext->decadeScores = $distMeanScore[get_class($favDecades)];
     $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)];
     $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)];
     $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes());
     $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres);
     $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators);
 }
Esempio n. 28
0
 private function protect_content()
 {
     //Breaking the HTML code
     $this->content = TextHelper::htmlspecialchars($this->content, ENT_NOQUOTES);
     $this->content = strip_tags($this->content);
     //While we aren't in UTF8 encoding, we have to use HTML entities to display some special chars, we accept them.
     $this->content = preg_replace('`&amp;((?:#[0-9]{2,5})|(?:[a-z0-9]{2,8}));`i', "&\$1;", $this->content);
     //Treatment of the Word pasted characters
     $array_str = array('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?');
     $array_str_replace = array('&#8364;', '&#8218;', '&#402;', '&#8222;', '&#8230;', '&#8224;', '&#8225;', '&#710;', '&#8240;', '&#352;', '&#8249;', '&#338;', '&#381;', '&#8216;', '&#8217;', '&#8220;', '&#8221;', '&#8226;', '&#8211;', '&#8212;', '&#732;', '&#8482;', '&#353;', '&#8250;', '&#339;', '&#382;', '&#376;');
     $this->content = str_replace($array_str, $array_str_replace, $this->content);
 }
 public static function update_extended_field(ExtendedField $extended_field)
 {
     self::change_extended_field_to_member($extended_field);
     $data_field = self::select_data_field_by_id($extended_field);
     $former_field_type = $data_field['field_type'];
     $new_field_type = $extended_field->get_field_type();
     self::$db_querier->inject("UPDATE " . DB_TABLE_MEMBER_EXTENDED_FIELDS_LIST . " SET \r\n\t\t\tname = :name, field_name = :field_name, description = :description, field_type = :field_type, possible_values = :possible_values, default_value = :default_value, required = :required, display = :display, regex = :regex, freeze = :freeze, auth = :auth\r\n\t\t\tWHERE id = :id", array('name' => TextHelper::htmlspecialchars($extended_field->get_name()), 'field_name' => $extended_field->get_field_name(), 'description' => TextHelper::htmlspecialchars($extended_field->get_description()), 'field_type' => $extended_field->get_field_type(), 'possible_values' => serialize($extended_field->get_possible_values()), 'default_value' => TextHelper::htmlspecialchars($extended_field->get_default_value()), 'required' => (string) $extended_field->get_required(), 'display' => (string) $extended_field->get_display(), 'regex' => TextHelper::htmlspecialchars($extended_field->get_regex()), 'freeze' => (string) $extended_field->get_is_freeze(), 'auth' => serialize($extended_field->get_authorization()), 'id' => $extended_field->get_id()));
     // If change field type, delete old informations
     if ($former_field_type !== $new_field_type) {
         self::delete_empty_fields_member($extended_field);
     }
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-favorites';
     $viewContext->meta->title = $viewContext->user->name . ' &#8212; Favorites (' . Media::toString($viewContext->media) . ') &#8212; ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' favorites.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned);
     $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned);
     $favYears = MediaYearDistribution::fromEntries($listNonPlanned);
     $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned);
     $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned);
     $viewContext->favCreators = $favCreators;
     $viewContext->favGenres = $favGenres;
     $viewContext->favYears = $favYears;
     $viewContext->favDecades = $favDecades;
     $viewContext->favTypes = $favTypes;
     $distMeanScore = [];
     $distTimeSpent = [];
     foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) {
         $meanScore = [];
         $timeSpent = [];
         foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) {
             $meanScore[$safeKey] = 0;
             $timeSpent[$safeKey] = 0;
             $subEntries = $dist->getGroupEntries($key);
             $scoreCount = 0;
             foreach ($subEntries as $entry) {
                 $timeSpent[$safeKey] += $entry->finished_duration;
                 $meanScore[$safeKey] += $entry->score;
                 $scoreCount += $entry->score > 0;
             }
             $meanScore[$safeKey] /= max(1, $scoreCount);
         }
         $distMeanScore[get_class($dist)] = $meanScore;
         $distTimeSpent[get_class($dist)] = $timeSpent;
     }
     $viewContext->creatorScores = $distMeanScore[get_class($favCreators)];
     $viewContext->genreScores = $distMeanScore[get_class($favGenres)];
     $viewContext->yearScores = $distMeanScore[get_class($favYears)];
     $viewContext->decadeScores = $distMeanScore[get_class($favDecades)];
     $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)];
     $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)];
     $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes());
     $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres);
     $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators);
 }