Esempio n. 1
0
 function test_numeric()
 {
     $ret = NumberHelper::numeric(10);
     self::assertTrue(is_int($ret) and $ret == 10);
     $ret = NumberHelper::numeric(10.55, 'float');
     self::assertTrue(is_float($ret) and $ret == 10.55);
     $ret = NumberHelper::numeric('bidon');
     self::assertTrue(is_int($ret) and $ret == 0);
 }
 public function get_search_request($args)
 {
     $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1;
     $search = $args['search'];
     $idcat = !empty($args['ForumIdcat']) ? NumberHelper::numeric($args['ForumIdcat']) : -1;
     $time = (!empty($args['ForumTime']) ? NumberHelper::numeric($args['ForumTime']) : 30000) * 3600 * 24;
     $where = !empty($args['ForumWhere']) ? TextHelper::strprotect($args['ForumWhere']) : 'all';
     require_once PATH_TO_ROOT . '/forum/forum_defines.php';
     $authorized_categories = ForumService::get_authorized_categories(Category::ROOT_CATEGORY);
     if ($where == 'all') {
         // All
         return "SELECT " . $args['id_search'] . " AS `id_search`,\n\t\t\t\tMIN(msg.id) AS `id_content`,\n\t\t\t\tt.title AS `title`,\n\t\t\t\tMAX(( 2 * FT_SEARCH_RELEVANCE(t.title, '" . $search . "') + FT_SEARCH_RELEVANCE(msg.contents, '" . $search . "') ) / 3) * " . $weight . " AS `relevance`,\n\t\t\t\tCONCAT('" . PATH_TO_ROOT . "/forum/topic.php?id=', t.id, '#m', msg.id) AS `link`\n\t\t\tFROM " . PREFIX . "forum_msg msg\n\t\t\tJOIN " . PREFIX . "forum_topics t ON t.id = msg.idtopic\n\t\t\tJOIN " . PREFIX . "forum_cats c ON c.id_parent != 0 AND c.id = t.idcat\n\t\t\tWHERE ( FT_SEARCH(t.title, '" . $search . "') OR FT_SEARCH(msg.contents, '" . $search . "') ) AND msg.timestamp > '" . (time() - $time) . "'\n\t\t\t" . ($idcat > 0 ? " AND c.id = " . $idcat : '') . " AND c.id IN (" . implode(',', $authorized_categories) . ")\n\t\t\tGROUP BY t.id\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT " . FORUM_MAX_SEARCH_RESULTS;
     }
     if ($where == 'contents') {
         // Contents
         return "SELECT " . $args['id_search'] . " AS `id_search`,\n\t\t\t\tMIN(msg.id) AS `id_content`,\n\t\t\t\tt.title AS `title`,\n\t\t\t\tMAX(FT_SEARCH_RELEVANCE(msg.contents, '" . $search . "')) * " . $weight . " AS `relevance`,\n\t\t\t\tCONCAT('" . PATH_TO_ROOT . "/forum/topic.php?id=', t.id, '#m', msg.id) AS `link`\n\t\t\tFROM " . PREFIX . "forum_msg msg\n\t\t\tJOIN " . PREFIX . "forum_topics t ON t.id = msg.idtopic\n\t\t\tJOIN " . PREFIX . "forum_cats c ON c.id_parent != 0 AND c.id = t.idcat\n\t\t\tWHERE FT_SEARCH(msg.contents, '" . $search . "') AND msg.timestamp > '" . (time() - $time) . "'\n\t\t\t" . ($idcat > 0 ? " AND c.id = " . $idcat : '') . " AND c.id IN (" . implode(',', $authorized_categories) . ")\n\t\t\tGROUP BY t.id\n\t\t\tLIMIT " . FORUM_MAX_SEARCH_RESULTS;
     } else {
         // Title only
         return "SELECT " . $args['id_search'] . " AS `id_search`,\n\t\t\t\tmsg.id AS `id_content`,\n\t\t\t\tt.title AS `title`,\n\t\t\t\tFT_SEARCH_RELEVANCE(t.title, '" . $search . "') * " . $weight . " AS `relevance`,\n\t\t\t\tCONCAT('" . PATH_TO_ROOT . "/forum/topic.php?id=', t.id, '#m', msg.id) AS `link`\n\t\t\tFROM " . PREFIX . "forum_msg msg\n\t\t\tJOIN " . PREFIX . "forum_topics t ON t.id = msg.idtopic\n\t\t\tJOIN " . PREFIX . "forum_cats c ON c.id_parent != 0 AND c.id = t.idcat\n\t\t\tWHERE FT_SEARCH(t.title, '" . $search . "') AND msg.timestamp > '" . (time() - $time) . "'\n\t\t\t" . ($idcat > 0 ? " AND c.id = " . $idcat : '') . " AND c.id IN (" . implode(',', $authorized_categories) . ")\n\t\t\tGROUP BY t.id\n\t\t\tLIMIT " . FORUM_MAX_SEARCH_RESULTS;
     }
 }
 private function compute_nb_items_per_page()
 {
     if (isset($this->parameters['items'])) {
         $items_per_page = $this->parameters['items'];
         if (is_numeric($items_per_page)) {
             $items_per_page = NumberHelper::numeric($items_per_page);
             if (is_int($items_per_page) && $items_per_page > 0) {
                 $this->nb_items_per_page = $items_per_page;
             }
         }
     }
 }
$calendar_type = !empty($date) ? 'timestamp' : 'date';
$field = !empty($field) ? trim($field) : 'calendar';
$date_lang = LangLoader::get('date-common');
$tpl = new FileTemplate('framework/util/mini_calendar_response.tpl');
$tpl->add_lang($date_lang);
//Type date.
if ($calendar_type == 'date') {
    $now = new Date();
    $year = $request->get_getint('y', $now->get_year());
    $month = $request->get_getint('m', $now->get_month());
    $day = $request->get_getint('d', $now->get_day());
    $input_date = !empty($input_date) ? trim($input_date) : $day . '/' . $month . '/' . $year;
    $selected = explode('/', $input_date);
    $selected_day = NumberHelper::numeric($selected[0]);
    $selected_month = NumberHelper::numeric($selected[1]);
    $selected_year = NumberHelper::numeric($selected[2]);
    if (!checkdate($month, $day, $year)) {
        list($year, $month, $day) = array(date('Y'), date('n'), date('j'));
    }
    $bissextile = date("L", mktime(0, 0, 0, 1, 1, $year)) == 1 ? 29 : 28;
    $array_month = array(31, $bissextile, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    $array_l_month = array($date_lang['january'], $date_lang['february'], $date_lang['march'], $date_lang['april'], $date_lang['may'], $date_lang['june'], $date_lang['july'], $date_lang['august'], $date_lang['september'], $date_lang['october'], $date_lang['november'], $date_lang['december']);
    $month_day = $array_month[$month - 1];
    $tpl->put_all(array('FIELD' => $field, 'INPUT_FIELD' => $input_field, 'CALENDAR_NUMBER' => $calendar_number, 'MONTH' => $month, 'YEAR' => $year, 'PREVIOUS_YEAR' => $month == 1 ? $year - 1 : $year, 'PREVIOUS_MONTH' => $month == 1 ? 12 : $month - 1, 'NEXT_YEAR' => $month == 12 ? $year + 1 : $year, 'NEXT_MONTH' => $month == 12 ? 1 : $month + 1));
    //Génération des select.
    for ($i = 1; $i <= 12; $i++) {
        $selected = $month == $i ? 'selected="selected"' : '';
        $tpl->assign_block_vars('month', array('MONTH' => '<option value="' . $i . '" ' . $selected . '>' . TextHelper::htmlentities($array_l_month[$i - 1]) . '</option>'));
    }
    for ($i = 1900; $i <= 2037; $i++) {
        $selected = $year == $i ? 'selected="selected"' : '';
 private function get_raw_float($value, $varname, $default_value)
 {
     if (is_float($value)) {
         return NumberHelper::numeric($value, 'float');
     }
     if ($default_value !== null) {
         return $default_value;
     } else {
         throw new ParameterTypeMismatchException($varname, 'float', $value);
     }
 }
Esempio n. 6
0
 function Add_poll($idtopic, $question, $answers, $nbr_votes, $type)
 {
     PersistenceContext::get_querier()->insert(PREFIX . "forum_poll", array('idtopic' => $idtopic, 'question' => $question, 'answers' => implode('|', $answers), 'voter_id' => 0, 'votes' => trim(str_repeat('0|', $nbr_votes)), 'type' => NumberHelper::numeric($type)));
 }
Esempio n. 7
0
 /**
  * @param int $value the feed's category
  */
 public function set_cat($value)
 {
     $this->category = is_numeric($value) ? NumberHelper::numeric($value) : 0;
 }
Esempio n. 8
0
         $start_timestamp = 0;
         $end_timestamp = 0;
     } else {
         $visible = 0;
         $start_timestamp = 0;
         $end_timestamp = 0;
     }
     $date = new Date($current_date);
     $timestamp = $date->get_timestamp();
     if ($timestamp > 0) {
         $timestamp += $hour * 3600 + $min * 60;
     } else {
         //Ajout des heures et minutes
         $timestamp = time();
     }
     $poll_type = NumberHelper::numeric($poll_type);
     $answers = '';
     $votes = '';
     for ($i = 0; $i < 20; $i++) {
         if ($request->has_postparameter('a' . $i)) {
             if (!empty(retrieve(POST, 'a' . $i, ''))) {
                 $answers .= str_replace('|', '', retrieve(POST, 'a' . $i, '')) . '|';
                 $votes .= str_replace('|', '', retrieve(POST, 'v' . $i, 0)) . '|';
             }
         }
     }
     PersistenceContext::get_querier()->insert(PREFIX . "poll", array('question' => $question, 'answers' => substr($answers, 0, strlen($answers) - 1), 'votes' => substr($votes, 0, strlen($votes) - 1), 'type' => $type, 'archive' => $archive, 'timestamp' => $timestamp, 'visible' => $visible, 'start' => $start_timestamp, 'end' => $start_timestamp, 'user_id' => AppContext::get_current_user()->get_id()));
     AppContext::get_response()->redirect('/poll/admin_poll.php');
 } else {
     AppContext::get_response()->redirect('/poll/admin_poll_add.php?error=incomplete#message_helper');
 }
 /**
  * @desc Update category and items position.
  * @param Category $category
  * @param int $id_parent
  * @param int $position
  */
 public function update_position(Category $category, $id_parent, $position)
 {
     $id = $category->get_id();
     if ($this->get_categories_cache()->category_exists($id) && $this->get_categories_cache()->category_exists($id_parent) && !($category->get_id_parent() == $id_parent && $category->get_order() == $position)) {
         $options = new SearchCategoryChildrensOptions();
         $childrens = $this->get_childrens($id, $options);
         $childrens[$id] = $category;
         if (!array_key_exists($id_parent, $childrens)) {
             $max_order = $this->db_querier->get_column_value($this->table_name, 'MAX(c_order)', 'WHERE id_parent=:id_parent', array('id_parent' => $id_parent));
             $max_order = NumberHelper::numeric($max_order);
             if ($position <= 0 || $position > $max_order) {
                 $this->db_querier->update($this->table_name, array('id_parent' => $id_parent, 'c_order' => $max_order + 1), 'WHERE id=:id', array('id' => $id));
             } else {
                 $this->db_querier->update($this->table_name, array('id_parent' => $id_parent, 'c_order' => $position), 'WHERE id=:id', array('id' => $id));
             }
             $this->regenerate_cache();
         }
     }
 }
Esempio n. 10
0
            if ($Gallery->get_error() != '') {
                AppContext::get_response()->redirect('/gallery/admin_gallery_add.php?error=' . $Gallery->get_error() . ($idcat_post ? '&cat=' . $idcat_post : '') . '#message_helper');
            }
            //Régénération du cache des photos aléatoires.
            GalleryMiniMenuCache::invalidate();
        }
    }
    AppContext::get_response()->redirect('/gallery/admin_gallery_add.php?add=' . $idpic . ($idcat_post ? '&cat=' . $idcat_post : ''));
} elseif ($valid && !empty($nbr_pics_post)) {
    for ($i = 1; $i <= $nbr_pics_post; $i++) {
        $activ = trim($request->get_postvalue($i . 'activ', ''));
        $uniq = trim($request->get_postvalue($i . 'uniq', ''));
        if ($activ && !empty($uniq)) {
            $name = TextHelper::strprotect($request->get_postvalue($i . 'name', ''));
            $cat = NumberHelper::numeric($request->get_postint($i . 'cat', 0));
            $del = NumberHelper::numeric($request->get_postint($i . 'del', 0));
            if ($del) {
                $file = new File('pics/' . $uniq);
                $file->delete();
            } else {
                $Gallery->Add_pics($cat, $name, $uniq, AppContext::get_current_user()->get_id());
            }
        }
    }
    //Régénération du cache des photos aléatoires.
    GalleryMiniMenuCache::invalidate();
    AppContext::get_response()->redirect('/gallery/admin_gallery_add.php');
} else {
    $tpl = new FileTemplate('gallery/admin_gallery_add.tpl');
    //Gestion erreur.
    $get_error = $request->get_getvalue('error', '');
Esempio n. 11
0
            $template->put('message_helper', MessageHelper::display($LANG['e_already_group'], MessageHelper::NOTICE));
        }
        //On recupère les dossier des images des groupes.
        $img_groups = '<option value="">--</option>';
        $image_folder_path = new Folder(PATH_TO_ROOT . '/images/group');
        foreach ($image_folder_path->get_files('`\\.(png|jpg|bmp|gif)$`i') as $image) {
            $file = $image->get_name();
            $selected = $file == $group['img'] ? ' selected="selected"' : '';
            $img_groups .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
        }
        $array_group = unserialize(stripslashes($group['auth']));
        $template->put_all(array('NAME' => $group['name'], 'IMG' => $group['img'], 'GROUP_ID' => $idgroup, 'IMG_GROUPS' => $img_groups, 'C_EDIT_GROUP' => true, 'AUTH_FLOOD_ENABLED' => $array_group['auth_flood'] == 1 ? 'checked="checked"' : '', 'AUTH_FLOOD_DISABLED' => $array_group['auth_flood'] == 0 ? 'checked="checked"' : '', 'PM_GROUP_LIMIT' => $array_group['pm_group_limit'], 'DATA_GROUP_LIMIT' => NumberHelper::round($array_group['data_group_limit'] / 1024, 2), 'COLOR_GROUP' => (substr($group['color'], 0, 1) != '#' ? '#' : '') . $group['color'], 'L_REQUIRE_PSEUDO' => $LANG['require_pseudo'], 'L_REQUIRE_LOGIN' => $LANG['require_name'], 'L_CONFIRM_DEL_USER_GROUP' => LangLoader::get_message('confirm.delete', 'status-messages-common'), 'L_GROUPS_MANAGEMENT' => $LANG['groups_management'], 'L_ADD_GROUPS' => $LANG['groups_add'], 'L_REQUIRE' => LangLoader::get_message('form.explain_required_fields', 'status-messages-common'), 'L_NAME' => $LANG['name'], 'L_IMG_ASSOC_GROUP' => $LANG['img_assoc_group'], 'L_IMG_ASSOC_GROUP_EXPLAIN' => $LANG['img_assoc_group_explain'], 'L_AUTH_FLOOD' => $LANG['auth_flood'], 'L_PM_GROUP_LIMIT' => $LANG['pm_group_limit'], 'L_PM_GROUP_LIMIT_EXPLAIN' => $LANG['pm_group_limit_explain'], 'L_DATA_GROUP_LIMIT' => $LANG['data_group_limit'], 'L_DATA_GROUP_LIMIT_EXPLAIN' => $LANG['data_group_limit_explain'], 'L_COLOR_GROUP' => $LANG['color_group'], 'L_YES' => LangLoader::get_message('yes', 'common'), 'L_NO' => LangLoader::get_message('no', 'common'), 'L_ADD' => LangLoader::get_message('add', 'common'), 'L_MB' => LangLoader::get_message('unit.megabytes', 'common'), 'L_MBR_GROUP' => $LANG['mbrs_group'], 'L_PSEUDO' => LangLoader::get_message('display_name', 'user-common'), 'L_SEARCH' => $LANG['search'], 'L_UPDATE' => $LANG['update'], 'L_RESET' => $LANG['reset'], 'L_DELETE' => LangLoader::get_message('delete', 'common'), 'L_ADD_MBR_GROUP' => $LANG['add_mbr_group']));
        //Liste des membres du groupe.
        $members = '';
        try {
            $members = PersistenceContext::get_querier()->get_column_value(DB_TABLE_GROUP, 'members', 'WHERE id=:id', array('id' => NumberHelper::numeric($group['id'])));
        } catch (RowNotFoundException $e) {
        }
        $number_member = 0;
        if (!empty($members)) {
            $members = str_replace('|', ',', $members);
            $result = PersistenceContext::get_querier()->select('SELECT user_id, display_name, level, groups
				FROM ' . DB_TABLE_MEMBER . '
				WHERE user_id IN (' . $members . ')');
            while ($row = $result->fetch()) {
                $group_color = User::get_group_color($row['groups'], $row['level']);
                $template->assign_block_vars('member', array('C_GROUP_COLOR' => !empty($group_color), 'USER_ID' => $row['user_id'], 'LOGIN' => $row['display_name'], 'LEVEL_CLASS' => UserService::get_level_class($row['level']), 'GROUP_COLOR' => $group_color, 'U_PROFILE' => UserUrlBuilder::profile($row['user_id'])->rel()));
                $number_member++;
            }
            $result->dispose();
        }
Esempio n. 12
0
    }
    $result->dispose();
    //Nombre de jours pour chaque mois (gestion des années bissextiles)
    $bissextile = date("L", mktime(0, 0, 0, 1, 1, $year)) == 1 ? 29 : 28;
    //Complément des jours manquant.
    $array_month = array(31, $bissextile, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    for ($i = 1; $i <= $array_month[$month - 1]; $i++) {
        if (!isset($array_stats[$i])) {
            $array_stats[$i] = 0;
        }
    }
    $Stats->load_data($array_stats, 'histogram', 5);
    //Tracé de l'histogramme.
    $Stats->draw_histogram(440, 250, '', array(LangLoader::get_message('days', 'date-common'), $LANG['page_s']), NO_DRAW_LEGEND, NO_DRAW_VALUES, 8);
} elseif ($get_pages_year) {
    $year = NumberHelper::numeric(retrieve(GET, 'year', ''));
    $array_stats = array();
    $result = PersistenceContext::get_querier()->select("SELECT SUM(pages) as total, stats_month\n\tFROM " . StatsSetup::$stats_table . "\n\tWHERE stats_year = :year\n\tGROUP BY stats_month\n\tORDER BY stats_month", array('year' => $year));
    while ($row = $result->fetch()) {
        $array_stats[$row['stats_month']] = $row['total'];
    }
    $result->dispose();
    //Complément des mois manquant
    for ($i = 1; $i <= 12; $i++) {
        if (!isset($array_stats[$i])) {
            $array_stats[$i] = 0;
        }
    }
    $Stats->load_data($array_stats, 'histogram', 5);
    //Tracé de l'histogramme.
    $Stats->draw_histogram(440, 250, '', array(LangLoader::get_message('month', 'date-common'), $LANG['page_s']), NO_DRAW_LEGEND, DRAW_VALUES, 8);
Esempio n. 13
0
function forum_history_collector($type, $user_id_action = '', $url_action = '')
{
    PersistenceContext::get_querier()->insert(PREFIX . "forum_history", array('action' => $type, 'user_id' => AppContext::get_current_user()->get_id(), 'user_id_action' => NumberHelper::numeric($user_id_action), 'url' => $url_action, 'timestamp' => time()));
}