Plugin Directory

Changeset 426703


Ignore:
Timestamp:
08/21/2011 01:29:14 PM (15 years ago)
Author:
Beaver6813
Message:

2.0b2.110821

  • Converted options pages to use Settings API
  • Added behavior selection (Manual triggering)
Location:
infinite-scroll/branches/Beta
Files:
5 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • infinite-scroll/branches/Beta/includes/infinite-scroll.class.php

    r425612 r426703  
    66public function __construct()
    77    {
    8     self::$Version = '2.0b2.110818';
     8    self::$Version = '2.0b2.110821';
    99    self::$PresetRepo = 'http://plugins.svn.wordpress.org/infinite-scroll/branches/PresetDB/PresetDB.csv.php';
    1010    self::$PresetDB = WP_PLUGIN_DIR."/infinite-scroll/PresetDB.csv.php";
     
    1212    //Load defaults
    1313    self::$Defaults = array(
    14         'infscr_state'              => array('enabledforadmins',
    15                                                 'If InfiniteScroll is turned on, off, or in maintenance'),
    16         'infscr_js_calls'           => array('',
    17                                                 'Javascript to execute when new content loads in'),
    18         'infscr_image'              => array(plugins_url('infinite-scroll/ajax-loader.gif'),
    19                                                 'Loading image'),
    20         'infscr_text'               => array('<em>Loading the next set of posts...</em>',
    21                                                 'Loading text'),
    22         'infscr_donetext'           => array('<em>Congratulations, you\'ve reached the end of the internet.</em>',
    23                                                 'Completed text'),
    24         'infscr_content_selector'   => array('#content',
    25                                                 'Content Div css selector'),
    26         'infscr_nav_selector'       => array('div.navigation',
    27                                                 'Navigation Div css selector'),
    28         'infscr_post_selector'      => array('#content  div.post',
    29                                                 'Post Div css selector'),
    30         'infscr_next_selector'      => array('div.navigation a:first',
    31                                                 'Next page Anchor css selector'),
    32         'infscr_viewed_options'     => array(false,
    33                                                 'Ever Viewed Options Page'),
    34         'infscr_debug'              => array('0',
    35                                                 'Debug Mode'),
    36         'infscr_image_align'        => array(1,
    37                                                 'Loading Image Alignment 0=Left, 1=Centre, 2=Right'));
    38     //Add to Wordpress
    39     foreach(self::$Defaults as $key=>$value)
    40         {
    41         add_option($key, $value[0], $value[1]);
    42         }   
    43     }
    44 
     14        'general'   => array(
     15            'infscr_state'              => array('enabledforadmins',"Infinite Scroll State Is","dropdown",array("disabled"=>"OFF","disabledforadmins"=>"ON for Visitors Only","enabledforadmins"=>"ON for Admins Only","enabled"=>"ON")),
     16            'infscr_debug'              => array('0',"Debug Mode","dropdown",array(0=>"OFF",1=>"ON")),
     17            'infscr_behavior'           => array('undefined',"Scrolling Behavior","dropdown",array('undefined'=>"Automatic",'twitter'=>"Manual Triggering")),
     18            'infscr_js_calls'           => array('',"Javascript to be called after the next posts are fetched","textarea"),
     19            'infscr_image'              => array(plugins_url('infinite-scroll/ajax-loader.gif'),"Loading Image","fileupload"),
     20            'infscr_image_align'        => array(1,"Loading Image Align","dropdown",array(0=>"Left",1=>"Centre",2=>"Right")),
     21            'infscr_text'               => array('<em>Loading the next set of posts...</em>',"Loading Text","textarea"),
     22            'infscr_donetext'           => array('<em>Congratulations, you\'ve reached the end of the internet.</em>',"\"You've reached the end\" text","textarea")),
     23        'selectors' => array(
     24            'infscr_content_selector'   => array('#content',"Content Selector","text"),
     25            'infscr_post_selector'      => array('#content  div.post',"Posts Selector","text"),
     26            'infscr_nav_selector'       => array('div.navigation',"Navigation Selector","text"),
     27            'infscr_next_selector'      => array('div.navigation a:first',"Next Page Selector","text")),
     28        'misc'      => array(
     29            'infscr_viewed_options'     => array(false,false,false,false))
     30        ); 
     31    }
     32public static function addDefaults()
     33    {
     34    $tmp = get_option('infscr_options');
     35    if(!is_array($tmp))
     36        {
     37        //infscr_options doesn't exist, check for legacy
     38        $stateopts = get_option('infscr_state');
     39        if(!empty($stateopts))
     40            {
     41            //We have legacy! Lets run an import
     42            $legacyarray = array();
     43            foreach(self::$Defaults as $key => $value)
     44                {
     45                foreach($value as $innerkey => $innerval)
     46                    {
     47                    $legacyarray[$innerkey] = get_option($innerkey);
     48                    }
     49                }
     50            update_option('infscr_options', $legacyarray);
     51            //We'll now check that that was successful and if it was, remove the legacy variables
     52            //If it didn't work then we'll leave them for now
     53            $tmp = get_option('infscr_options');
     54            if(is_array($tmp)) {
     55                foreach(self::$Defaults as $key => $value)
     56                    {
     57                    foreach($value as $innerkey => $innerval)
     58                        {
     59                        delete_option($innerkey);
     60                        }
     61                    }
     62                }   
     63            }
     64        else
     65            {
     66            //If there are no legacy variables
     67            $newsettings = array();
     68            foreach(self::$Defaults as $key => $value)
     69                {
     70                foreach($value as $innerkey => $innerval)
     71                    {
     72                    $newsettings[$innerkey] = $innerval[0];
     73                    }
     74                }
     75            update_option('infscr_options', $newsettings);
     76            }
     77        }       
     78    }
    4579public static function addjQuery()
    4680    {
     
    6094        //IMPORTANT. Our versions of jQuery, like Wordpress, also append jQuery.noConflict();
    6195        if((stripslashes(get_option('infscr_debug'))==1))
    62             wp_register_script( 'jquery', plugins_url('infinite-scroll')."/js/jquery-1.6.2.js", array(), '1.6.2', false );
     96            wp_enqueue_script( 'jquery', plugins_url('infinite-scroll')."/js/jquery-1.6.2.js", array(), '1.6.2', false );
    6397        else
    64             wp_register_script( 'jquery', plugins_url('infinite-scroll')."/js/jquery-1.6.2.min.js", array(), '1.6.2', false );
    65         }
    66     wp_enqueue_script( 'jquery' );
     98            wp_enqueue_script( 'jquery', plugins_url('infinite-scroll')."/js/jquery-1.6.2.min.js", array(), '1.6.2', false );
     99        }
    67100    return true;   
    68101    }
     
    107140        $nextpage_no        = intval($current_page) + 1;
    108141        $max_page           = $wp_query->max_num_pages;
    109         if ( !$max_page || $max_page >= $nextpage )
     142        if ( !$max_page || $max_page >= $nextpage_no )
    110143            {
    111144            self::addjQuery();
     
    115148            $pathParse[]        = $current_page;
    116149            $pathInfo           = base64_encode(serialize(array($pathParse,md5(NONCE_KEY.$pathParse[0]."infscr".$pathParse[1].self::$Version.$pathParse[2]))));
    117             wp_register_script( "infinite-scroll-init", "$plugin_dir/infinitescroll.init.js.php?p=$pathInfo", array("jquery"), NULL, false );
    118             wp_enqueue_script( "infinite-scroll-init" );
     150            wp_enqueue_script( "infinite-scroll-init" , "$plugin_dir/infinitescroll.init.js.php?p=$pathInfo", array("jquery"), NULL, false );
    119151            return true;
    120152            }       
     
    201233    return explode("|||INF-SPLITHERE|||",$result);
    202234    }
    203 //FYI We use this function for a certain part of the presetAdd as we don't want eol.
    204 private static function presetToCSV($data)
    205     {
    206     $outstream = fopen("php://temp", 'r+');
    207     fputcsv($outstream, $data, ',', '"');
    208     rewind($outstream);
    209     $csv = fgets($outstream);
    210     fclose($outstream);
    211     $csv = substr($csv, 0, (0 - strlen(PHP_EOL)));
    212     return $csv;
    213     }
    214 public static function presetAdd($themename,$content,$nav,$post,$next,$overwrite)
    215     {
    216     if (($handle = @fopen(self::$PresetDB, "r+")) !== FALSE) {
    217         //Discard first and second line
    218         fgets($handle, 4096);
    219         fgets($handle, 4096);
    220         $continueparse = true;
    221         $previouscursor = ftell($handle);
    222         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE && $continueparse == true) {
    223             if(isset($data[0])&&$data[0]==$themename)
    224                 {
    225                 if($overwrite==1)
    226                     {
    227                     fseek($handle,$previouscursor);
    228                     fwrite($handle, self::presetToCSV(array($themename,$content,$nav,$post,$next)));
    229                     $continueparse = false;
    230                     }
    231                 else
    232                     return array("ERROR","A preset for this theme already exists!");
    233                 }
    234             elseif($data[0]=='End Preset DB*/ ?>')
    235                 {
    236                 fseek($handle,$previouscursor);
    237                 fputcsv($handle,array($themename,$_POST['infscr_content_selector'],$_POST['infscr_nav_selector'],$_POST['infscr_post_selector'],$_POST['infscr_next_selector']),",");
    238                 fwrite($handle,'End Preset DB*/ ?>');
    239                 $continueparse = false;
    240                 }
    241             $previouscursor = ftell($handle);
    242             }
    243         fclose($handle);
    244         //If we're still here then we presume it went okay...
    245         return array("OK","Preset Added Successfully.");
    246         }
    247     else
    248         return array("ERROR","Preset Database Doesn't Exist. Try Updating From Preset Manager.");
    249        
    250     }
    251 public static function presetGet($themename)
    252     {
    253     if (($handle = @fopen(self::$PresetDB, "r")) !== FALSE) {
    254         //Discard first and second line
    255         fgets($handle, 4096);
    256         fgets($handle, 4096);
    257         $continueparse = true;
    258         $themeinfo = false;
    259         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE && $continueparse == true) {
    260             if(isset($data[0])&&$data[0]==$themename)
    261                 {
    262                 $themeinfo = array("name"=>$data[0],"content"=>$data[1],"nav"=>$data[2],"post"=>$data[3],"next"=>$data[4]);
    263                 $continueparse = false;
    264                 }
    265             }
    266         fclose($handle);
    267         if($themeinfo!=false)
    268             return array("OK",$themeinfo);
    269         else
    270             return array("ERROR","Could not find preset for theme.");
    271         }
    272     else
    273         return array("ERROR","Preset Database Doesn't Exist. Try Updating From Preset Manager.");
    274        
    275     }
    276 public static function presetGetAll()
    277     {
    278     if (($handle = @fopen(self::$PresetDB, "r")) !== FALSE) {
    279         //Discard first and second line
    280         fgets($handle, 4096);
    281         fgets($handle, 4096);
    282         $presets = array();
    283         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    284             if(count($data)>2)
    285                 {
    286                 $presets[] = array("name"=>$data[0],"content"=>$data[1],"nav"=>$data[2],"post"=>$data[3],"next"=>$data[4]);
    287                 }
    288             }
    289         fclose($handle);
    290         return array("OK",$presets);
    291         }
    292     else
    293         return array("ERROR","Preset Database Doesn't Exist. Try Updating.");
    294     }
    295 public static function presetUpdate()
    296     {
    297     //First get current rev version
    298     if (($handle = @fopen(self::$PresetRev, "r")) !== FALSE) {
    299         //Discard first line
    300         fgets($handle, 4096);
    301         $currentrev = fgets($handle, 4096);
    302         fclose($handle);
    303         }
    304     if(!isset($currentrev))
    305         $currentrev = 0;
    306     //Now check SubVersion
    307     $headresponse = get_headers(self::$PresetRepo,1);
    308     if($headresponse[0]!='HTTP/1.1 404 Not Found'&&!empty($headresponse['ETag']))
    309         {
    310         $etag = trim($headresponse['ETag'],'"');
    311         $exetag = explode("//",$etag);
    312         $reporev = $exetag[0];
    313         if($reporev>$currentrev)
    314             {
    315             $newdb = file_get_contents(self::$PresetRepo);
    316             if(file_put_contents(self::$PresetDB,$newdb))
    317                 {
    318                 if(file_put_contents(self::$PresetRev,"<?php /*Infinite-Scroll Preset DB Rev File. Contains Subversion Rev Info.\n$reporev\nEnd Preset DB Rev File*/ ?>"))
    319                     return array("OK","Successfully Updated Preset Database To Latest Version");
    320                 else
    321                     return array("ERROR","Could not update revision file. Please check that ".WP_PLUGIN_DIR."/infinite-scroll/ is writable.");
    322                 }
    323             else
    324                 return array("ERROR","Could not update preset file. Please check that ".WP_PLUGIN_DIR."/infinite-scroll/ is writable.");
    325             }
    326         else
    327             {
    328             return array("OK","You already have the most current version!");   
    329             }
    330         }
    331     else
    332         return array("ERROR","Could not contact Wordpress repo. Are you behind a Firewall? Couldn't access: ".self::$PresetRepo);
    333     }
    334 public static function presetExport()
    335     {
    336     if(file_exists(self::$PresetDB))
    337         {
    338         header("Content-Description: Preset DB Export");
    339         header("Content-Disposition: attachment; filename=PresetDB.csv.php");
    340         header("Content-Type: text/csv");
    341         readfile(self::$PresetDB);
    342         return true;
    343         }
    344     else
    345         return false;
     235public static function initOptions()
     236    {
     237    include("options.class.php");
     238    include("presets.class.php");
     239    //Load Settings
     240    register_setting('infinitescroll', 'infscr_options', array('infiniteScrollOptions','validateOptions'));
     241    infiniteScrollOptions::loadSettings("general",'general_section', '', array('infiniteScrollOptions','generalText'), "infiniteScrollGeneral");
     242    infiniteScrollOptions::loadSettings("selectors",'selectors_section', '', array('infiniteScrollOptions','selectorsText'), "infiniteScrollSelectors");   
     243    //Add setup warning if required
     244    $currentopts        = get_option('infscr_options');
     245    if ( $currentopts['infscr_state'] == self::$Defaults['general']['infscr_state'][0] && $currentopts['infscr_viewed_options'] == false  && !isset($_POST['submit']) )
     246        add_action('admin_notices', array('infiniteScroll', 'showSetupWarning'));   
     247    }
     248public static function addOptPageLoader()
     249    {
     250    $optionspage = add_options_page('Infinite Scroll Options', 'Infinite Scroll', 'manage_options', 'wp_infinite_scroll.php', array('infiniteScrollOptions', 'addOptPage'));
     251    add_action("load-".$optionspage, array('infiniteScrollOptions', 'addOptJavascript'));
     252    add_action('admin_print_styles-'.$optionspage, array('infiniteScrollOptions', 'addOptStyle') );
     253    add_contextual_help($optionspage,str_replace("{INFSCROLL_VERSION}",self::$Version,file_get_contents(WP_PLUGIN_DIR."/infinite-scroll/includes/helpinfo.html")));
    346254    }
    347255public static function slashOnlyDouble($text)
  • infinite-scroll/branches/Beta/includes/options.class.php

    r425606 r426703  
    11<?php
    22/*Infinite-Scroll Options Class
    3 Dependencies: Wordpress.*/
     3Dependencies: Wordpress, infiniteScroll.*/
    44class infiniteScrollOptions extends infiniteScroll {
    55
     
    3535        }
    3636    }
    37 
    38 public static function updateOptions()
    39     {   
    40     // update state
    41     $infscr_state = $_POST['infscr_state'];
    42     if ($infscr_state != 'enabled' && $infscr_state != 'disabled' && $infscr_state != 'disabledforadmins' && $infscr_state != 'enabledforadmins')
    43         $infscr_state = parent::$Defaults['infscr_state'][0];
    44     update_option('infscr_state', esc_js($infscr_state));
    45     // update debug
    46     $infscr_debug = $_POST['infscr_debug'];
    47     update_option('infscr_debug', esc_js($infscr_debug));
    48     // update js calls field
    49     $infscr_js_calls = $_POST['infscr_js_calls'];
    50     update_option('infscr_js_calls', $infscr_js_calls);
    51     // update image
     37public static function selectorsText()
     38    {
     39    echo " <p>All CSS selectors are found with the jQuery javascript library. See the <a href=\"http://docs.jquery.com/Selectors\">jQuery CSS Selector documentation</a> for an overview of all possibilities. Single-quotes are not allowed&mdash;only double-quotes may be used.</p>
     40        <table class=\"editform infscroll-opttable\" cellspacing=\"0\" >
     41          <tbody>
     42          <tr>
     43                <th width=\"20%\" >
     44                    <label for=\"themepresets\">Theme Presets:</label>
     45                </th>
     46                <td>";
     47    $presetinfo = infiniteScrollPresets::presetGet(strtolower(get_current_theme()));
     48    if($presetinfo[0]=='Error')
     49        {
     50        if($presetinfo[1]=='Could not find preset for theme.')
     51            echo "<img src=\"".site_url('/wp-includes/images/smilies/icon_cry.gif')."\" alt=\":-(\"/> We don't currently have a preset for your theme. You'll have to try and enter the right selectors manually using their description and default values."; 
     52        else
     53            echo $presetinfo[1];   
     54        }
     55    else
     56        {
     57        echo "We found a preset for your theme: ".get_current_theme();
     58        echo "<p class=\"submit\">
     59        <input type='button' name='auto_fill' value='Auto-Fill' />
     60        <input name='auto_fill_content' type='hidden' value='{$presetinfo[1]['content']}' />
     61        <input name='auto_fill_post' type='hidden' value='{$presetinfo[1]['post']}' />
     62        <input name='auto_fill_nav' type='hidden' value='{$presetinfo[1]['nav']}' />
     63        <input name='auto_fill_next' type='hidden' value='{$presetinfo[1]['next']}' />
     64    </p>"; 
     65        }
     66        echo "</td>
     67            <td width=\"50%\">
     68              <p>To help new (or lazy) users, we have a new preset function. We've compiled a list of common themes and the selectors you should use on infinite-scroll for them.</p>
     69              </td>
     70            </tr>
     71            </tbody>
     72        </table>";
     73    }
     74public static function generalText()
     75    {
     76    echo "<p style=\"font-style:italic;\">NOTE: If you haven't already, make sure you choose the correct selectors for your theme in the selectors tab above. This is needed for the plugin to work correctly. If you've tried and it still doesn't work then check out the Help menu in the top right!</p>";   
     77    }
     78//We use a little dirty hack to get around the stupid limitations put on the design of the settings pages
     79//FYI this is closing </td> and opening a new one for our descriptions
     80public static function addFieldtext($callbackarr)
     81    {
     82    $options = get_option('infscr_options');
     83    if(isset($options[$callbackarr[0]]))
     84        $value = $options[$callbackarr[0]];
     85    else
     86        $value = parent::$Defaults[$callbackarr[1]][$callbackarr[0]][0];
     87    echo "<input id='infscr_options[$callbackarr[0]]' name='infscr_options[$callbackarr[0]]' size='40' type='text' value='$value' /></td><td width='50%'>".self::getDescription($callbackarr[0])."</td>";   
     88    }
     89public static function addFielddropdown($callbackarr)
     90    {
     91    $options = get_option('infscr_options');
     92    if(isset($options[$callbackarr[0]]))
     93        $value = $options[$callbackarr[0]];
     94    else
     95        $value = parent::$Defaults[$callbackarr[1]][$callbackarr[0]][0];
     96    echo "<select name='infscr_options[$callbackarr[0]]' id='infscr_options[$callbackarr[0]]'>\n";
     97    foreach(parent::$Defaults[$callbackarr[1]][$callbackarr[0]][3] as $optkey => $optval)
     98        {
     99        echo "<option value='$optkey'";
     100        if ($value == $optkey)
     101            echo "selected='selected'";
     102        echo ">$optval</option>\n";
     103        }                       
     104    echo "</select></td><td width='50%'>".self::getDescription($callbackarr[0])."</td>";   
     105    }
     106public static function addFieldtextarea($callbackarr)
     107    {
     108    $options = get_option('infscr_options');
     109    if(isset($options[$callbackarr[0]]))
     110        $value = $options[$callbackarr[0]];
     111    else
     112        $value = parent::$Defaults[$callbackarr[1]][$callbackarr[0]][0];
     113    echo "<textarea name='infscr_options[$callbackarr[0]]' rows='2'  style='width: 95%;'>\n";
     114    echo stripslashes($value);
     115    echo "</textarea></td><td width='50%'>".self::getDescription($callbackarr[0])."</td>";
     116    }
     117public static function addFieldfileupload($callbackarr)
     118    {
     119    echo "<input type='file' name='infscr_options[$callbackarr[0]]' id='infscr_options[$callbackarr[0]]' size='30' /></td><td width='50%'>".self::getDescription($callbackarr[0])."</td>"; 
     120    }
     121
     122public static function loadSettings($settingsgrp, $id, $title, $callback, $page)
     123    {
     124    add_settings_section($id, $title, $callback, $page);
     125    foreach(parent::$Defaults[$settingsgrp] as $key=>$value)
     126        {
     127        add_settings_field($key, $value[1], array("infiniteScrollOptions","addField".$value[2]), $page, $id, array($key,$settingsgrp));
     128        }
     129    }
     130public static function validateOptions($input)
     131    {
     132    $options = get_option('infscr_options');
     133    if (isset($input['infscr_state']) && ($input['infscr_state'] == 'enabled' || $input['infscr_state'] == 'disabled' || $input['infscr_state'] == 'disabledforadmins' || $input['infscr_state'] == 'enabledforadmins'))
     134        $options['infscr_state'] = $input['infscr_state'];
     135    if (isset($input['infscr_debug']) && ($input['infscr_debug'] == 0 || $input['infscr_debug'] == 1))
     136        $options['infscr_debug'] = $input['infscr_debug'];
     137    if (isset($input['infscr_behavior']) && ($input['infscr_behavior'] == 'undefined' || $input['infscr_behavior'] == 'twitter'))
     138        $options['infscr_behavior'] = $input['infscr_behavior'];
     139    if (isset($input['infscr_js_calls']))
     140        $options['infscr_js_calls'] = $input['infscr_js_calls'];
     141    if (isset($input['infscr_image_align']) && ($input['infscr_image_align'] == 0 || $input['infscr_image_align'] == 1 || $input['infscr_image_align'] == 2))
     142        $options['infscr_image_align'] = $input['infscr_image_align'];
     143    if (isset($input['infscr_text']))
     144        $options['infscr_text'] = $input['infscr_text'];
     145    if (isset($input['infscr_donetext']))
     146        $options['infscr_donetext'] = $input['infscr_donetext'];
     147    if (isset($input['infscr_content_selector']))
     148        $options['infscr_content_selector'] = esc_js($input['infscr_content_selector']);
     149    if (isset($input['infscr_nav_selector']))
     150        $options['infscr_nav_selector'] = esc_js($input['infscr_nav_selector']);
     151    if (isset($input['infscr_post_selector']))
     152        $options['infscr_post_selector'] = esc_js($input['infscr_post_selector']);
     153    if (isset($input['infscr_next_selector']))
     154        $options['infscr_next_selector'] = esc_js($input['infscr_next_selector']);
     155   
    52156    /* Handle Image Upload */
    53     if(!empty($_FILES['infscr_image']['tmp_name']))
    54         {
    55         $infscr_image = $_FILES['infscr_image'];
    56         $uploaddetails = wp_check_filetype($infscr_image["name"]);
     157    //FYI I do know that the add_settings_error() function does work, but only as of 3.0. I'd rather keep compatability with 2.7.
     158    if(!empty($_FILES['infscr_options']['tmp_name']['infscr_image']))
     159        {
     160        $uploaddetails = wp_check_filetype($_FILES['infscr_options']['name']['infscr_image']);
    57161        if(!empty($uploaddetails['ext']))
    58162            {
    59             $uploadres = wp_upload_bits("inf-loading-".rand().".".$uploaddetails['ext'], null, file_get_contents($infscr_image["tmp_name"]));
     163            $uploadres = wp_upload_bits("inf-loading-".rand().".".$uploaddetails['ext'], null, file_get_contents($_FILES['infscr_options']['tmp_name']['infscr_image']));
    60164            if(!$uploadres['error'])
    61                 update_option('infscr_image', $uploadres['url']);   
    62             else
    63                 return parent::showError("Error Saving Loading Bar: {$uploadres['error']}");   
     165                $options['infscr_image'] = $uploadres['url'];   
     166
    64167            }
    65         else
     168        }
     169    return $options;
     170    }
     171public static function addOptStyle()
     172    {
     173    $plugin_dir         = plugins_url('infinite-scroll');
     174    wp_enqueue_style( "infinite-scroll-admin-style" , "$plugin_dir/includes/admin.css", false, parent::$Version, false );
     175    }
     176public static function addOptJavascript()
     177    {
     178    parent::addjQuery();
     179    if(self::pageActive("presets","tab")=="")
     180        $presetdefault = 1;
     181    else
     182        $presetdefault = 2;
     183    if(!empty($_GET['infpage'])&&((int) $_GET['infpage']) == $_GET['infpage']&&$_GET['infpage']>=0)
     184        $infscr_preset_page = $_GET['infpage'];
     185    else
     186        $infscr_preset_page = 1;
     187    $plugin_dir         = plugins_url('infinite-scroll');
     188    $pathParse          = array("options-general.php?page=wp_infinite_scroll.php&infpage=","",$infscr_preset_page);
     189    $pathInfo           = base64_encode(serialize(array($pathParse,md5(NONCE_KEY.$pathParse[0]."infscr".$pathParse[1].                  parent::$Version.$pathParse[2]))));
     190    wp_enqueue_script( "infinite-scroll-init", "$plugin_dir/infinitescroll.init.js.php?p=$pathInfo&a=$presetdefault", array("jquery"), NULL, false );
     191    wp_enqueue_script( "infinite-scroll-admin", "$plugin_dir/js/admin_options.js", array("jquery", "infinite-scroll-init"), parent::$Version, false );     
     192    }
     193public static function addOptPage()
     194    {
     195    $plugin_dir         = plugins_url('infinite-scroll');
     196    $currentopts        = get_option('infscr_options');
     197
     198    //Check if user wants to add preset
     199    if(isset($_POST['preset_add']))
     200        {
     201        if(isset($_POST['preset_overwrite']))
     202            $overwrite = 1;
     203        else
     204            $overwrite = 0;
     205        $addresult = infiniteScrollPresets::presetAdd($_POST['preset_themename'],$_POST['preset_content'],$_POST['preset_nav'],$_POST['preset_posts'],$_POST['preset_next'],$overwrite);   
     206        if($addresult[0]=='OK')
    66207            {
    67             return parent::showError("Could Not Determine File Extension. Supported Files Are: .jpg, .jpeg. gif. .png");
     208            echo "<div class='updated'><p><strong>{$addresult[1]}</strong></p></div>";
    68209            }
    69         }
    70     // update image alignment
    71     $infscr_image_align = $_POST['infscr_image_align'];
    72     if ($infscr_image_align != 0 && $infscr_image_align != 1 && $infscr_image_align != 2)
    73         $infscr_image_align = 1;
    74     update_option('infscr_image_align', esc_js($infscr_image_align));
    75     // update text
    76     $infscr_text = $_POST['infscr_text'];
    77     update_option('infscr_text', $infscr_text);
    78     // update done text
    79     $infscr_donetext = $_POST['infscr_donetext'];
    80     update_option('infscr_donetext', $infscr_donetext);
    81     // update content selector
    82     $content_selector = $_POST['infscr_content_selector'];
    83     update_option('infscr_content_selector', esc_js($content_selector));
    84     // update the navigation selector
    85     $navigation_selector = $_POST['infscr_nav_selector'];
    86     update_option('infscr_nav_selector', esc_js($navigation_selector));
    87     // update the post selector
    88     $post_selector = $_POST['infscr_post_selector'];
    89     update_option('infscr_post_selector', esc_js($post_selector));
    90     // update the next selector
    91     $next_selector = $_POST['infscr_next_selector'];
    92     update_option('infscr_next_selector', esc_js($next_selector));
    93     // update notification
    94     return "<div class='updated'><p><strong>Infinite Scroll options updated</strong></p></div>";       
    95     }
    96 
    97 public static function addOptStyle()
    98     {
    99     return "<style type=\"text/css\">
    100 table.infscroll-opttable { width: 100%;}
    101 table.infscroll-opttable td, table.infscroll-opttable th { vertical-align: top; padding: 9px 4px;  }
    102 table.infscroll-opttable th { padding-top: 9px; text-align: right;}
    103 table.infscroll-opttable td p { margin: 0;}
    104 table.infscroll-opttable dl { font-size: 90%; color: #666; margin-top: 5px; }
    105 table.infscroll-opttable dd { margin-bottom: 0 }
    106 .infscroll-tab { display:none; }
    107 .infscroll-tab-active { display:block; }
    108 .infscroll_preset_nav { text-align: right; padding-top: 25px;}
    109 </style>"; 
     210        else
     211            echo parent::showError($addresult[1]);
     212        }
     213    //Update that they have viewed options
     214    if(!$currentopts['infscr_viewed_options'])
     215        {
     216        $currentopts['infscr_viewed_options'] = true;
     217        update_option("infscr_options", $currentopts);
     218        }
     219    //Check if user wants to update preset db
     220    if(isset($_GET['presetup'])&&$_GET['presetup']==1)
     221        {
     222        $updateresult = infiniteScrollPresets::presetUpdate();
     223        if($updateresult[0]=='OK')
     224            {
     225            echo "<div class='updated'><p><strong>{$updateresult[1]}</strong></p></div>";
     226            }
     227        else
     228            echo parent::showError($updateresult[1]);   
     229        }
     230   
     231    if($currentopts['infscr_state'] == 'disabled')
     232        echo parent::showError("Infinite-Scroll plugin is <strong>disabled</strong>.");
     233
     234    if (function_exists('wp_tiny_mce')) {
     235        add_filter('teeny_mce_buttons', create_function('$a', "
     236        return array('bold, italic, underline, separator, strikethrough, justifyleft, justifycenter, justifyright, code');"));
     237        add_filter('teeny_mce_before_init', create_function('$a', '
     238        $a["theme"] = "advanced";
     239        $a["skin"] = "wp_theme";
     240        $a["height"] = "50";
     241        $a["width"] = "240";
     242        $a["onpageload"] = "";
     243        $a["mode"] = "exact";
     244        $a["elements"] = "'.'infscr_options[infscr_text]'.','.'infscr_options[infscr_donetext]'.'";
     245        $a["editor_selector"] = "mceEditor";
     246        $a["plugins"] = "safari,inlinepopups,spellchecker";
     247        return $a;'));
     248   
     249        wp_tiny_mce(true);
     250        }
     251    echo '<div class="wrap">
     252    <form name="infinitescrollform" action="options.php" method="post" enctype="multipart/form-data">';
     253    settings_fields('infinitescroll');
     254    echo '<h2>Infinite Scroll Options</h2>
     255    <h2 class="nav-tab-wrapper">
     256<a href="options-general.php?page=wp_infinite_scroll.php&default=general" class="nav-tab'.self::pageActive("general","nav").'" rel="general">General</a><a href="options-general.php?page=wp_infinite_scroll.php&default=selectors" class="nav-tab'.self::pageActive("selectors","nav").'" rel="selectors">Selectors</a><a href="options-general.php?page=wp_infinite_scroll.php&default=presets" class="nav-tab'.self::pageActive("presets","nav").'" rel="presets" style="float:right;">Preset Manager</a>
     257</h2>';
     258    echo '<div class="infscroll-tab infscroll-tab-general'.infiniteScrollOptions::pageActive("general","tab").'">';
     259    do_settings_sections('infiniteScrollGeneral');
     260    echo '<p class="submit" style="text-align:center;">
     261            <input name="Submit" type="submit" class="button-primary" value="';
     262    esc_attr_e('Save Changes');
     263    echo '" />
     264    </p>
     265    </div>';
     266    echo '<div class="infscroll-tab infscroll-tab-selectors'.infiniteScrollOptions::pageActive("selectors","tab").'">';
     267    do_settings_sections('infiniteScrollSelectors');
     268    echo '<p class="submit" style="text-align:center;">
     269        <input name="Submit" type="submit" class="button-primary" value="';
     270    esc_attr_e('Save Changes');
     271    echo '" />
     272    </p>
     273    </div>';
     274    echo "</form>";
     275    include("presets.tab.php");
     276    echo "</div>";
     277    }
     278public static function getDescription($key)
     279    {
     280    switch($key)
     281        {
     282        case 'infscr_state':
     283            $description = '"ON for Admins Only" will enable the plugin code only for logged-in administrators&mdash;visitors will not be affected while you configure the plugin. "ON for Visitors Only" is useful for administrators when customizing the blog&mdash;infinite scroll will be disabled for them, but still enabled for any visitors.';
     284        break;
     285        case 'infscr_debug':
     286            $description = 'ON will turn on Debug mode. This will enable developer javascript console logging whilst in use. (Recommended: OFF, May break some browsers).';
     287        break;
     288        case 'infscr_behavior':
     289            $description = 'Automatic behavior is the default behavior used by infinite scroll, once the user reaches the end of the page, it\'ll load the next set of posts. Manual triggering turns off automatic loading, it won\'t use AJAX to load any more posts until the user clicks the link/button for more posts.'; 
     290        break;
     291        case 'infscr_js_calls':
     292            $description = 'Any functions that are applied to the post contents on page load will need to be executed when the new content comes in.'; 
     293        break;
     294        case 'infscr_image':
     295            $options = get_option('infscr_options');
     296            $description = 'Current Image:<br /><div style="text-align:center;margin-bottom:15px;"><img src="'.$options['infscr_image'].'" alt="The Loading Image" /></div>
     297<p>URL of image that will be displayed while content is being loaded. Visit <a href="http://www.ajaxload.info" target="_blank">www.ajaxload.info</a> to customize your own loading spinner.</p>';   
     298        break;
     299        case 'infscr_image_align':
     300            $description = ''; 
     301        break;
     302        case 'infscr_text':
     303            $description = 'Text will be displayed while content is being loaded.';
     304        break;
     305        case 'infscr_donetext':
     306            $description = 'Text will be displayed when all entries have already been retrieved. The plugin will show this message, fade it out, and cease working.';   
     307        break;
     308        case 'infscr_content_selector':
     309            $description = 'The selector of the content div on the main page.';
     310        break;
     311        case 'infscr_post_selector':
     312            $description = '<p>The selector of the post block.</p>
     313                  <dl>
     314                    <dt>Examples:</dt>
     315                    <dd>#content &gt; *</dd>
     316                    <dd>#content div.post</dd>
     317                    <dd>div.primary div.entry</dd>
     318                </dl>';
     319        break;
     320        case 'infscr_nav_selector':
     321            $description = 'The selector of the navigation div (the one that includes the next and previous links).';   
     322        break;
     323        case 'infscr_next_selector':
     324            $description = '<p>The selector of the previous posts (next page) A tag.</p>
     325                  <dl>
     326                    <dt>Examples:</dt>
     327                    <dd>div.navigation a:first</dd>
     328                    <dd>div.navigation a:contains(Previous)</dd>
     329                </dl>';
     330        break;
     331        default:
     332            $description = '';
     333        break;
     334        }
     335    return $description;
    110336    }
    111337}
  • infinite-scroll/branches/Beta/includes/presets.tab.php

    r425606 r426703  
    11<div class="infscroll-tab infscroll-tab-presets<?php echo infiniteScrollOptions::pageActive("presets","tab");?>">
    2           <p>&nbsp;</p>
     2          <p>For advanced users only. Generally you shouldn't need to use this.</p>
    33    <table class="editform infscroll-opttable" cellspacing="0" >
    44          <tbody>
     5          <tr>
     6                <th width="20%" >
     7                    <label for="themepresets">Add Preset:</label>
     8                </th>
     9                <td colspan="2">
     10                <form action="options-general.php?page=wp_infinite_scroll.php&default=presets" method="post">
     11                <table>
     12                 <tr valign="top"><th scope="row">Theme Name</th><td><input type="text" value="<?php if(isset($_POST['preset_themename'])) echo $_POST['preset_themename']; else echo strtolower(get_current_theme());?>" size="40" name="preset_themename" id="preset_themename"></td></tr>
     13                <tr valign="top"><th scope="row">Content Selector</th><td><input type="text" value="<?php if(isset($_POST['preset_content'])) echo $_POST['preset_content'];?>" size="40" name="preset_content" id="preset_content"></td></tr>
     14                <tr valign="top"><th scope="row">Posts Selector</th><td><input type="text" value="<?php if(isset($_POST['preset_posts'])) echo $_POST['preset_posts'];?>" size="40" name="preset_posts" id="preset_posts"></td></tr>
     15                <tr valign="top"><th scope="row">Navigation Selector</th><td><input type="text" value="<?php if(isset($_POST['preset_nav'])) echo $_POST['preset_nav'];?>" size="40" name="preset_nav" id="preset_next"></td></tr>
     16                <tr valign="top"><th scope="row">Next Page Selector</th><td><input type="text" value="<?php if(isset($_POST['preset_next'])) echo $_POST['preset_next'];?>" size="40" name="preset_next" id="preset_next"></td></tr>
     17                </table>
     18                <p class="submit" style="text-align:left;">
     19<input type='submit' name='preset_add' value='Add to Preset DB' /><br /><label for="preset_overwrite">Overwrite Existing Theme Preset: </label><input name="preset_overwrite" id="preset_overwrite" type="checkbox" value="1" />
     20    </p>
     21                </form>
     22            </td>
     23            </tr>
    524          <tr>
    625                <th width="20%" >
     
    4362                    //Will be quite a memory hog when the database gets larger
    4463                    //TODO: Work on nosql style method of selecting ranges
    45                     $finalpresets = infiniteScroll::presetGetAll();
     64                    if(!empty($_GET['infpage'])&&((int) $_GET['infpage']) == $_GET['infpage']&&$_GET['infpage']>=0)
     65                        $infscr_preset_page = $_GET['infpage'];
     66                    else
     67                        $infscr_preset_page = 1;
     68                    $finalpresets = infiniteScrollPresets::presetGetAll();
    4669                    if($finalpresets[0]=='ERROR')
    4770                        {
  • infinite-scroll/branches/Beta/infinitescroll.init.js.php

    r425606 r426703  
    2020    //Lets setup settings!
    2121    $plugin_dir         = plugins_url('infinite-scroll');
    22     $debug              = (stripslashes(get_option("infscr_debug"))==1) ? "true" : "false";
     22    $infscropts         = get_option("infscr_options");
     23    //Go through and check for defaults
     24    foreach(infiniteScroll::$Defaults as $key => $value)
     25        {
     26        foreach($value as $inkey => $invalue)
     27            {
     28            if(!isset($infscropts[$inkey]))
     29                $infscropts[$inkey] = $invalue[0]; 
     30            }
     31        }
     32    $debug              = (stripslashes($infscropts['infscr_debug'])==1) ? "true" : "false";
    2333    $scheme             = (is_ssl()) ? "https://" : "http://";
    24     if($_GET['a']>0)
     34    if(isset($_GET['a']) && $_GET['a']>0)
    2535        {
    2636        $noscheme           = parse_url(stripslashes($plugin_dir."/ajax-loader.gif")); 
     
    3242        $next_selector      = ".infscroll_preset_nav a:first";
    3343        $js_calls           = "if(jQuery('.infscroll_preset_list tr:last td:first').text()=='No More Presets Available...') { window.setTimeout(function() { jQuery(\".infscroll_preset_list\").infinitescroll(\"destroy\"); }, 10); };";
     44        $behavior           = 'undefined';
    3445        }
    3546    else
    3647        {
    37         $noscheme           = parse_url(stripslashes(get_option("infscr_image")));
    38         $loading_text       = infiniteScroll::slashOnlyDouble(get_option("infscr_text"));
    39         $donetext           = infiniteScroll::slashOnlyDouble(get_option("infscr_donetext"));
    40         $content_selector   = stripslashes(get_option("infscr_content_selector"));
    41         $navigation_selector= stripslashes(get_option("infscr_nav_selector"));
    42         $post_selector      = stripslashes(get_option("infscr_post_selector"));
    43         $next_selector      = stripslashes(get_option("infscr_next_selector"));
    44         $js_calls           = stripslashes(get_option("infscr_js_calls"));
     48        $noscheme           = parse_url(stripslashes($infscropts['infscr_image']));
     49        $loading_text       = infiniteScroll::slashOnlyDouble($infscropts['infscr_text']);
     50        $donetext           = infiniteScroll::slashOnlyDouble($infscropts['infscr_donetext']);
     51        $content_selector   = stripslashes($infscropts['infscr_content_selector']);
     52        $navigation_selector= stripslashes($infscropts['infscr_nav_selector']);
     53        $post_selector      = stripslashes($infscropts['infscr_post_selector']);
     54        $next_selector      = stripslashes($infscropts['infscr_next_selector']);
     55        $js_calls           = stripslashes($infscropts['infscr_js_calls']);
     56        $behavior           = stripslashes($infscropts['infscr_behavior']);
    4557        }
    4658    $loading_image      = $scheme.$noscheme['host'].$noscheme['path']; 
     
    5163        {
    5264        echo file_get_contents("js/jquery.infinitescroll.js");
     65        if($behavior=='twitter')
     66            echo file_get_contents("js/behaviors/manual-trigger.js");
    5367        echo '//We leave a function outside the infinite-scroll area so that it works with older jQuery versions
    5468            function infinite_scroll_callback(newElements,data) {
     
    6882                        currPage    : "'.$pathInfo[0][2].'"
    6983                        },
     84                    behavior        : "'.$behavior.'",
    7085                    nextSelector    : "'.$next_selector.'",
    7186                    navSelector     : "'.$navigation_selector.'",
     
    7691                    ';
    7792            //If its on the admin page and the tab is not active by default, pause it!
    78             if($_GET['a']==1)
     93            if(isset($_GET['a']) && $_GET['a']==1)
    7994                echo '$("'.$content_selector.'").infinitescroll("pause");';
    8095            echo '});';
     
    8499        {
    85100        echo file_get_contents("js/jquery.infinitescroll.min.js");
     101        if($behavior=='twitter')
     102            echo file_get_contents("js/behaviors/manual-trigger.min.js");
    86103        echo 'function infinite_scroll_callback(newElements,data){'.$js_calls.'}
    87 jQuery(document).ready(function($){$("'.$content_selector.'").infinitescroll({debug:'.$debug.',loading:{img:"'.$loading_image.'",msgText:"'.$loading_text.'",finishedMsg:"'.$donetext.'"},state:{currPage:"'.$pathInfo[0][2].'"},nextSelector:"'.$next_selector.'",navSelector:"'.$navigation_selector.'",contentSelector:"'.$content_selector.'",itemSelector:"'.$post_selector.'",pathParse:["'.$pathInfo[0][0].'","'.$pathInfo[0][1].'"]},function(){window.setTimeout(infinite_scroll_callback(newElements,data),1);});';
    88         if($_GET['a']==1)
     104jQuery(document).ready(function($){$("'.$content_selector.'").infinitescroll({debug:'.$debug.',loading:{img:"'.$loading_image.'",msgText:"'.$loading_text.'",finishedMsg:"'.$donetext.'"},state:{currPage:"'.$pathInfo[0][2].'"},behavior:"'.$behavior.'",nextSelector:"'.$next_selector.'",navSelector:"'.$navigation_selector.'",contentSelector:"'.$content_selector.'",itemSelector:"'.$post_selector.'",pathParse:["'.$pathInfo[0][0].'","'.$pathInfo[0][1].'"]},function(){window.setTimeout(infinite_scroll_callback(newElements,data),1);});';
     105        if(isset($_GET['a']) && $_GET['a']==1)
    89106                echo '$("'.$content_selector.'").infinitescroll("pause");';
    90107        echo '});';
  • infinite-scroll/branches/Beta/js/admin_options.js

    r425606 r426703  
    1414    $(".submit input[name=auto_fill]").click(function (event) {
    1515        event.preventDefault();
    16         $("input[name=infscr_content_selector]").val($(this).siblings("input[name=auto_fill_content]").val());
    17         $("input[name=infscr_post_selector]").val($(this).siblings("input[name=auto_fill_post]").val());
    18         $("input[name=infscr_nav_selector]").val($(this).siblings("input[name=auto_fill_nav]").val());
    19         $("input[name=infscr_next_selector]").val($(this).siblings("input[name=auto_fill_next]").val());
     16        $(document.infinitescrollform["infscr_options[infscr_content_selector]"]).val($(this).siblings("input[name=auto_fill_content]").val());
     17        $(document.infinitescrollform["infscr_options[infscr_post_selector]"]).val($(this).siblings("input[name=auto_fill_post]").val());
     18        $(document.infinitescrollform["infscr_options[infscr_nav_selector]"]).val($(this).siblings("input[name=auto_fill_nav]").val());
     19        $(document.infinitescrollform["infscr_options[infscr_next_selector]"]).val($(this).siblings("input[name=auto_fill_next]").val());
    2020        $('.infscroll-tab-selectors input[type=text]').animate({backgroundColor: "yellow"},50, function () {
    2121    jQuery('.infscroll-tab-selectors input[type=text]').animate({ backgroundColor: "white" }, 500);});
  • infinite-scroll/branches/Beta/presetdb.php

    r425606 r426703  
    33wp();
    44check_admin_referer();
     5include("includes/presets.class.php");
    56//What are we being asked for?
    67if($_GET['do']=='export')
    78    {
    8     if(!infiniteScroll::presetExport())
     9    if(!infiniteScrollPresets::presetExport())
    910        echo "Error exporting file. (Could not find the database to export). Please try again.";
    1011    }
  • infinite-scroll/branches/Beta/readme.txt

    r425612 r426703  
    4949
    5050== Changelog ==
     51= 2.0b2.110821 =
     52* Converted options pages to use Settings API
     53* Added behavior selection (Manual triggering)
     54
    5155= 2.0b2.110818 =
    5256* Completely revamped admin panel adding more modular management
  • infinite-scroll/branches/Beta/wp_infinite_scroll.php

    r425606 r426703  
    22/*
    33Plugin Name: Infinite Scroll
    4 Version: 2.0b2.110723
     4Version: 2.0b2.110821
    55Plugin URI: http://www.infinite-scroll.com
    66Description: Automatically loads the next page of posts into the bottom of the initial page.
     
    1111include("includes/infinite-scroll.class.php");
    1212new infiniteScroll();
    13 //Add Actions
    14 add_action('template_redirect'  , create_function('', "infiniteScroll::addInfiniteScroll();"));
    15 add_action('wp_head'            , create_function('', "infiniteScroll::addStyle();"));
    16 add_action('admin_menu'         , 'add_wp_inf_scroll_options_page');
     13//Add Generic Actions
     14add_action('init'                   , array('infiniteScroll', 'addDefaults'));
     15
     16//Add Main Blog Actions
     17add_action('template_redirect'      , array('infiniteScroll', 'addInfiniteScroll'));
     18add_action('wp_head'                , array('infiniteScroll', 'addStyle'));
    1719/*Because recently (3.0) WP doesn't always throw a 404 when posts aren't found.
    1820Infinite-Scroll relies on 404 errors to terminate.. so we'll force them. */
    19 add_action("wp"                 , create_function('', "infiniteScroll::trigger404();"));
     21add_action("wp"                     , array('infiniteScroll', 'trigger404'));
    2022
    21 if ( get_option('infscr_state') == infscr_state_default && get_option(key_infscr_viewed_options) == false && !isset($_POST['submit']) )
    22     add_action('admin_notices', create_function('', "echo infiniteScroll::showSetupWarning();"));   
    23 
    24 function add_wp_inf_scroll_options_page()
    25     {
    26     $optionspage = add_options_page('Infinite Scroll Options', 'Infinite Scroll', 8, basename(__FILE__), 'wp_inf_scroll_options_page');
    27     add_action("load-".$optionspage, create_function('', "infiniteScroll::addjQuery();"));
    28    
    29     $loadhelp = str_replace("{INFSCROLL_VERSION}",infiniteScroll::$Version,file_get_contents(WP_PLUGIN_DIR."/infinite-scroll/includes/helpinfo.html"));
    30     add_contextual_help($optionspage,$loadhelp);
    31     }
    32    
    33 function wp_inf_scroll_options_page()
    34     {
    35     check_admin_referer();
    36     include("includes/options.class.php");
    37     $plugin_dir         = plugins_url('infinite-scroll');
    38    
    39     if(!empty($_GET['infpage'])&&((int) $_GET['infpage']) == $_GET['infpage']&&$_GET['infpage']>=0)
    40         $infscr_preset_page = $_GET['infpage'];
    41     else
    42         $infscr_preset_page = 1;
    43    
    44     $pathParse          = array("options-general.php?page=".basename(__FILE__)."&infpage=","",$infscr_preset_page);
    45     $pathInfo           = base64_encode(serialize(array($pathParse,md5(NONCE_KEY.$pathParse[0]."infscr".$pathParse[1].                  infiniteScroll::$Version.$pathParse[2]))));
    46     if(infiniteScrollOptions::pageActive("presets","tab")=="")
    47         $presetdefault = 1;
    48     else
    49         $presetdefault = 2;
    50     //If theres POST, update the options
    51     if (isset($_POST['info_update']))
    52         echo infiniteScrollOptions::updateOptions();
    53     //Check if user wants to add preset
    54     if(isset($_POST['preset_add']))
    55         {
    56         $addresult = infiniteScroll::presetAdd(strtolower(get_current_theme()),$_POST['infscr_content_selector'],$_POST['infscr_nav_selector'],$_POST['infscr_post_selector'],$_POST['infscr_next_selector'],$_POST['preset_overwrite']);   
    57         if($addresult[0]=='OK')
    58             {
    59             echo "<div class='updated'><p><strong>{$addresult[1]}</strong></p></div>";
    60             }
    61         else
    62             echo infiniteScroll::showError($addresult[1]);
    63         }
    64     //Update that they have viewed options
    65     update_option("infscr_viewed_options", true);
    66     //Check if user wants to update preset db
    67     if(isset($_GET['presetup'])&&$_GET['presetup']==1)
    68         {
    69         $updateresult = infiniteScroll::presetUpdate();
    70         if($updateresult[0]=='OK')
    71             {
    72             echo "<div class='updated'><p><strong>{$updateresult[1]}</strong></p></div>";
    73             }
    74         else
    75             echo infiniteScroll::showError($updateresult[1]);   
    76         }
    77    
    78     if (get_option('infscr_state') == 'disabled')
    79         echo infiniteScroll::showError("Infinite-Scroll plugin is <strong>disabled</strong>.");
    80 
    81     if (function_exists('wp_tiny_mce')) {
    82         add_filter('teeny_mce_buttons', create_function('$a', "
    83         return array('bold, italic, underline, separator, strikethrough, justifyleft, justifycenter, justifyright, code');"));
    84         add_filter('teeny_mce_before_init', create_function('$a', '
    85         $a["theme"] = "advanced";
    86         $a["skin"] = "wp_theme";
    87         $a["height"] = "50";
    88         $a["width"] = "240";
    89         $a["onpageload"] = "";
    90         $a["mode"] = "exact";
    91         $a["elements"] = "'.'infscr_donetext'.','.'infscr_text'.'";
    92         $a["editor_selector"] = "mceEditor";
    93         $a["plugins"] = "safari,inlinepopups,spellchecker";
    94         return $a;'));
    95    
    96         wp_tiny_mce(true);
    97         }
    98     echo infiniteScrollOptions::addOptStyle();
    99     echo "<script type=\"text/javascript\" src=\"$plugin_dir/infinitescroll.init.js.php?p=$pathInfo&a=$presetdefault\"></script>
    100     <script type=\"text/javascript\" src=\"$plugin_dir/js/admin_options.js\"></script>";
     23//Add Admin Panel Actions
     24add_action('admin_init'             , array('infiniteScroll', 'initOptions'));
     25add_action('admin_menu'             , array('infiniteScroll', 'addOptPageLoader'));
    10126?>
    102     <div class="wrap">
    103     <form action="options-general.php?page=<?php echo basename(__FILE__); ?>" method="post" enctype="multipart/form-data">
    104     <h2>Infinite Scroll Options</h2>
    105     <h2 class="nav-tab-wrapper">
    106 <a href="options-general.php?page=<?php echo basename(__FILE__); ?>&default=general" class="nav-tab<?php echo infiniteScrollOptions::pageActive("general","nav");?>" rel="general">General</a><a href="options-general.php?page=<?php echo basename(__FILE__); ?>&default=selectors" class="nav-tab<?php echo infiniteScrollOptions::pageActive("selectors","nav");?>" rel="selectors">Selectors</a><a href="options-general.php?page=<?php echo basename(__FILE__); ?>&default=presets" class="nav-tab<?php echo infiniteScrollOptions::pageActive("presets","nav");?>" rel="presets" style="float:right;">Preset Manager</a>
    107 </h2>
    108 <?php
    109     include("includes/general.tab.php");
    110     include("includes/selectors.tab.php");
    111     echo "</form>";
    112     include("includes/presets.tab.php");
    113     echo "</div>";
    114     }?>
Note: See TracChangeset for help on using the changeset viewer.