Advertisement:

Author Topic: New helper functions  (Read 1577 times)

lucky_strike

  • Guest
New helper functions
« on: November 09, 2012, 10:32:49 pm »
hello everyone..   lets have a  topic where can gather new helper  functions y hope that helps few of us... and someone customize that into better one ...

this one
can  prevent insertion.... of ugly strings:) ;)

Code: [Select]
function prevent_long_strings($post, $limit = 3) {
    $words_array = explode(" ", $post);
    $cut_string = "";
    foreach ($words_array as $val) {
        if (preg_match("/(.)\\1{".$limit.",}/", $val)) {
            $char_array = preg_split("//", $val);
            $check = 0;
            for ($i = 0; $i < count($char_array); $i++) {
                if ($char_array[$i] == $char_array[$i-1]) {
                    if ($check < $limit - 1) {
                        $new_word[] = $char_array[$i];
                    }
                    $check++;
                } else {
                    $new_word[] = $char_array[$i];
                    $check = 0;
                }
            }
            $cut_string .= implode("", $new_word)." ";
            unset($new_word);
        } else {
            $cut_string .= $val." ";
        }
    }
    return $cut_string;
}
// Example:
echo prevent_long_strings("Hello, can you heeeeeeeeaaaaaaaar meeeeeeeeeeeee !!!!!!!!!!!!!!!!!!! !!!!!!!!", 3);
// is converted to "Hello, can you heeeaaar meee !!! !!!"
« Last Edit: November 14, 2012, 04:35:18 am by lucky_strike »

lucky_strike

  • Guest
Re: New helper functions
« Reply #1 on: November 14, 2012, 04:04:27 am »

new helper function :) look nicer like this :)

<p class="filters">
        <?php _e('Sort by', 'modern'); ?>:
                    <?php  osc_list_orders_list();?>
</p>
 here is the function
Code: [Select]
function osc_list_orders_list() {

$i = 0 ;
         $orders = osc_list_orders();
        foreach($orders as $label => $params) {
            $orderType = ($params['iOrderType'] == 'asc') ? '0' : '1';
             if(osc_search_order() == $params['sOrder'] && osc_search_order_type() == $orderType) {
               echo' <a class="current" href="'; echo osc_update_search_url($params) ;
   echo'">'; echo $label;
   echo'</a>';
            } else {
               echo' <a href="';
    echo osc_update_search_url($params) ;
echo'">';
echo $label;
echo'</a>';
             }
           if ($i != count($orders)-1) {
   echo'<span>&middot;</span>';
             }
             $i++ ;
       }
   }

lucky_strike

  • Guest
Re: New helper functions
« Reply #2 on: November 14, 2012, 04:12:13 am »
or u can switch to dropdown.. and allows  more options ..sort by oldest .. sort by published last week.. last 7 days... last 30 days..
dont forget to complete osc_list_orders function form include/helpers hsearch with  those options before u use it :)

 __('new first')        => array('sOrder' => 'dt_pub_date', 'iOrderType' => 'desc')
,__('old first')        => array('sOrder' => 'dt_pub_date', 'iOrderType' => 'asc')

and looks like this. into search_list.php

<p class="filters">
        <?php _e('Sort by', 'modern'); ?>:
                    <?php osc_list_orders_drop();?>
</p>

Code: [Select]
function osc_list_orders_drop() {

   $orders = osc_list_orders();
   echo '<select name="order" id="order" ONCHANGE="location = this.options[this.selectedIndex].value;">';


       

        foreach($orders as $label => $params){
           $orderType = ($params['iOrderType'] == 'asc') ? '0' : '1';
            echo '<option value="'.osc_update_search_url($params).'">';
echo $label;
echo'</option>';   

        }

       echo'</select>';
}


 this one has a bug :)
 did not retain the value as y espected.. on change..  but.. hope that php masters.. solve this little
its a  little late .. the midlle  of the night ...ill take my time anytime soon to finish this.:)
« Last Edit: November 14, 2012, 04:55:45 am by lucky_strike »