Example #1
0
function printAvailableImages($imgFolder, $standardFolder)
{
    if (!isset($standardFolder)) {
        $standardFolder = 1;
    }
    $aFileArray = array();
    //Let's have a look at the images...
    $handle = opendir($imgFolder);
    while ($file = readdir($handle)) {
        if (!is_dir($file)) {
            $aFileArray[] = $file;
        }
    }
    closedir($handle);
    //Sort the array
    sort($aFileArray);
    $aAlowedExtensions = array('jpg', 'jpeg', 'gif', 'png');
    echo '<table border="0" cellpadding="5" cellspacing="0">';
    //For each file inside the array...
    for ($i = 0; $i < count($aFileArray); $i++) {
        $aFileParts = pathinfo($aFileArray[$i]);
        //If file has an allowed extension...
        if (in_array($aFileParts['extension'], $aAlowedExtensions)) {
            if (!isset($aRadioPosition) || $aRadioPosition == 2) {
                $aRadioPosition = 1;
                echo '<tr><td>';
            } else {
                $aRadioPosition = 2;
                echo '<td>';
            }
            //User has the opportunity to choose this image file
            if ($standardFolder == 1) {
                echo '<input type="radio" name="usrStarImage" value="' . $aFileArray[$i] . '"';
                if (get_option('usrStarImage') == $aFileArray[$i]) {
                    echo ' checked';
                }
                echo '> ';
                _e(insertUSR(array("=3.5", "img" => $aFileArray[$i], "text" => "false", "usrPreviewImg" => "true", "max" => "5")), 'universal-star-rating');
                echo ' <code>' . $aFileArray[$i] . '</code></td>';
            } else {
                echo '<input type="radio" name="usrStarImage" value="c' . $aFileArray[$i] . '"';
                if (get_option('usrStarImage') == 'c' . $aFileArray[$i]) {
                    echo ' checked';
                }
                echo '> ';
                _e(insertUSR(array("=3.5", "img" => 'c' . $aFileArray[$i], "text" => "false", "usrPreviewImg" => "true", "max" => "5")), 'universal-star-rating');
                echo ' <code>c' . $aFileArray[$i] . '</code></td>';
            }
            if ($i + 1 == count($aFileArray) || $aRadioPosition == 2) {
                echo '</tr>';
            }
        }
    }
}
function usrOptionsPage()
{
    //globals
    global $MESSAGES;
    //If options shall be resetted
    if (isset($_POST['usrOptionsReset'])) {
        updateUSRSettings(USR_DEFAULT_LANG, USR_DEFAULT_STAR_SIZE, USR_DEFAULT_MAX_STARS, USR_DEFAULT_STAR_TEXT, USR_DEFAULT_CALC_AVERAGE, USR_DEFAULT_PERMIT_SHORTCODE_COMMENTS, USR_DEFAULT_SCHEMA_ORG, USR_DEFAULT_SCHEMA_ORG_TYPE, USR_DEFAULT_CUSTOM_IMAGE_FOLDER, USR_DEFAULT_STAR_IMAGE);
        //Tell user that options are updated
        echo '<div class="updated fade"><p><strong>' . __($MESSAGES['INFO']['SettingsUpdated'][USR_DEFAULT_LANG], "universal-star-rating") . '</strong></p></div>';
    }
    //If options shall be updated
    if (isset($_POST['usrOptionsUpdate'])) {
        $usrLang = $_POST["usrLang"];
        $usrStarSize = $_POST["usrStarSize"];
        $usrMaxStars = $_POST["usrMaxStars"];
        $usrStarText = $_POST["usrStarText"];
        $usrCalcAverage = $_POST["usrCalcAverage"];
        $usrPermitShortcodedComments = $_POST["usrPermitShortcodedComments"];
        $usrSchemaOrg = $_POST["usrSchemaOrg"];
        $usrSchemaOrgType = $_POST["usrSchemaOrgType"];
        $usrCustomImagesFolder = $_POST["usrCustomImagesFolder"];
        $usrStarImage = $_POST["usrStarImage"];
        updateUSRSettings($usrLang, $usrStarSize, $usrMaxStars, $usrStarText, $usrCalcAverage, $usrPermitShortcodedComments, $usrSchemaOrg, $usrSchemaOrgType, $usrCustomImagesFolder, $usrStarImage);
        //Tell user that options are updated
        echo '<div class="updated fade"><p><strong>' . __($MESSAGES['INFO']['SettingsUpdated'][$usrLang], "universal-star-rating") . '</strong></p></div>';
    }
    // Show options page
    ?>

		<div class="wrap" style="width: 800px;">		
			<div class="options">		
				<form method="post" action="options-general.php?page=<?php 
    global $usrPluginFilename;
    echo $usrPluginFilename;
    ?>
">
        
				<h2><?php 
    global $usrPluginName, $SETTINGS;
    $usrLang = get_option('usrLang');
    if ($usrLang == '') {
        $usrLang = 'en';
    }
    printf(__('%s - ' . $SETTINGS['GLOBAL']['Settings'][$usrLang], 'universal_star_rating'), $usrPluginName);
    ?>
</h2>

					<h3><?php 
    _e($SETTINGS['NOU']['NotesOnUsage'][$usrLang], 'universal-star-rating');
    ?>
</h3>					
					<p><?php 
    _e($SETTINGS['NOU']['ShortCodeDefinition'][$usrLang], 'universal-star-rating');
    ?>
</p>					
					<p><?php 
    _e($SETTINGS['NOU']['HowToUSR'][$usrLang], 'universal-star-rating');
    ?>
</p>					
					<p><?php 
    _e($SETTINGS['NOU']['HowToUSRList'][$usrLang], 'universal-star-rating');
    ?>
</p>					
          <p><?php 
    _e($SETTINGS['NOU']['HowToShortCodes'][$usrLang], 'universal-star-rating');
    ?>
</p>

					<h3><?php 
    _e($SETTINGS['OPT']['Options'][$usrLang], 'universal-star-rating');
    ?>
</h3>					
					<p><?php 
    _e($SETTINGS['OPT']['ExplainOptions'][$usrLang], 'universal-star-rating');
    ?>
</p>
					<p>
            <table border="0">
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainLanguageSetting'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td><td>
      					<?php 
    $usrLang = get_option('usrLang');
    if ($usrLang == '') {
        $usrLang = USR_DEFAULT_LANG;
    }
    echo '<select name="usrLang">';
    //dynamically show all available languages
    $usrLocales = scandir(WP_PLUGIN_DIR . '/universal-star-rating/includes/locales/');
    foreach ($usrLocales as $usrLocale) {
        if ($usrLocale != "." && $usrLocale != ".." && $usrLocale != "locale.temp") {
            $localeParts = explode('.', $usrLocale);
            echo '<option value="' . $localeParts[1] . '"';
            if ($usrLang == $localeParts[1]) {
                echo ' selected';
            }
            echo '>' . $SETTINGS['OPT']['OriginLanguage'][$localeParts[1]] . '</option>';
        }
    }
    echo '</select>';
    ?>
                </td><td><?php 
    _e($SETTINGS['OPT']['DefaultLanguage'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainStarSizeSetting'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td>
                  <input type="text" size="10" name="usrStarSize" id="usrStarSize" value="<?php 
    echo get_option('usrStarSize');
    ?>
" />
      					</td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultStarSize'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainStarCountSetting'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td>
      					  <input type="text" size="10" name="usrMaxStars" id="usrMaxStars" value="<?php 
    echo get_option('usrMaxStars');
    ?>
" />
      					</td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultStarCount'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainStarText'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td>
                <?php 
    $usrStarText = get_option('usrStarText');
    echo '<select name="usrStarText"><option value="true"';
    if ($usrStarText == "true") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultEnabled'][$usrLang] . '</option><option value="false"';
    if ($usrStarText == "false") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultDisabled'][$usrLang] . '</option></select>';
    ?>
                </td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultStarText'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainAverageCalculation'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td>
                <?php 
    $usrCalcAverage = get_option('usrCalcAverage');
    echo '<select name="usrCalcAverage"><option value="true"';
    if ($usrCalcAverage == "true") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultEnabled'][$usrLang] . '</option><option value="false"';
    if ($usrCalcAverage == "false") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultDisabled'][$usrLang] . '</option></select>';
    ?>
                </td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultAverageCalculation'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainPermitShortcodedComment'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td><?php 
    $usrPermitShortcodedComments = get_option('usrPermitShortcodedComments');
    echo '<select name="usrPermitShortcodedComments"><option value="true"';
    if ($usrPermitShortcodedComments == "true") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultEnabled'][$usrLang] . '</option><option value="false"';
    if ($usrPermitShortcodedComments == "false") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultDisabled'][$usrLang] . '</option></select>';
    ?>
                </td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultPermitShortcodedComment'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainSchemaOrg'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td><?php 
    $usrSchemaOrg = get_option('usrSchemaOrg');
    echo '<select name="usrSchemaOrg"><option value="true"';
    if ($usrSchemaOrg == "true") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultEnabled'][$usrLang] . '</option><option value="false"';
    if ($usrSchemaOrg == "false") {
        echo ' selected';
    }
    echo '>' . $SETTINGS['OPT']['DefaultDisabled'][$usrLang] . '</option></select>';
    ?>
                </td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultSchemaOrg'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <?php 
    if (get_option("usrSchemaOrg") == "true") {
        ?>
              <tr>
              	<td><?php 
        _e($SETTINGS['OPT']['ExplainSchemaOrgType'][$usrLang] . ":", 'universal-star-rating');
        ?>
</td>
              	<td><?php 
        $usrSchemaOrgType = get_option('usrSchemaOrgType');
        echo '<select name="usrSchemaOrgType"><option value="rating"';
        if ($usrSchemaOrgType == "rating") {
            echo ' selected';
        }
        echo '>rating</option><option value="reviewRating"';
        if ($usrSchemaOrgType == "reviewRating") {
            echo ' selected';
        }
        echo '>reviewRating</option></select>';
        ?>
      			</td>
              	<td><?php 
        _e($SETTINGS['OPT']['DefaultSchemaOrgType'][$usrLang], 'universal-star-rating');
        ?>
</td>
              </tr>
              <?php 
    }
    ?>
              <tr>
                <td><?php 
    _e($SETTINGS['OPT']['ExplainCUSRI'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td><?php 
    $usrCustomImagesFolder = get_option('usrCustomImagesFolder');
    echo '/wp-content/<input type="text" size="5" name="usrCustomImagesFolder" id="usrCustomImagesFolder" value="' . $usrCustomImagesFolder . '" />';
    ?>
                </td>
                <td><?php 
    _e($SETTINGS['OPT']['DefaultCUSRI'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td valign="top"><?php 
    _e($SETTINGS['OPT']['ExplainStarImage'][$usrLang] . ":", 'universal-star-rating');
    ?>
</td>
                <td colspan="2">
      
                <?php 
    $imgHeight = get_option('usrStarSize');
    if ($imgHeight <= 20) {
        $imgFolder = 20;
    } elseif ($imgHeight <= 40) {
        $imgFolder = 40;
    } elseif ($imgHeight <= 60) {
        $imgFolder = 60;
    } elseif ($imgHeight <= 80) {
        $imgFolder = 80;
    } elseif ($imgHeight <= 100) {
        $imgFolder = 100;
    } else {
        $imgFolder = 189;
    }
    //Print images which come within this plugin
    printAvailableImages(WP_PLUGIN_DIR . "/universal-star-rating/images/" . $imgFolder . "/", 1);
    //Is there a custom images folder?
    $customImagesFolder = WP_CONTENT_DIR . '/' . get_option("usrCustomImagesFolder") . '/';
    if (file_exists($customImagesFolder)) {
        //Print custom images
        proofCUSRIStructure($customImagesFolder);
        printAvailableImages($customImagesFolder . $imgFolder, 0);
    }
    echo '</table>';
    ?>
                
                </td>
              </tr>
            </table>
					</p>

					<h3><?php 
    _e($SETTINGS['PREV']['Preview'][$usrLang], 'universal-star-rating');
    ?>
</h3>
          <p>
            <table border="1" cellspacing="0" cellpadding="5" width="100%">
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['Example'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleResult'][$usrLang], 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsr'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrResult'][$usrLang] . insertUSR(array("=3.5", "usrPreviewImg" => "true")), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrList'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e(insertUSRList(array($SETTINGS['PREV']['ExampleUsrListResult'][$usrLang][1], $SETTINGS['PREV']['ExampleUsrListResult'][$usrLang][2], $SETTINGS['PREV']['ExampleUsrListResult'][$usrLang][3], "usrPreviewImg" => "true")), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrOverriddenImage'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrResult'][$usrLang] . insertUSR(array("=3.5", "img" => "03.png", "usrPreviewImg" => "true")), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrOverriddenText'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrResult'][$usrLang] . insertUSR(array("=3.5", "text" => "false", "usrPreviewImg" => "true")), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrOverriddenMax'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrResult'][$usrLang] . insertUSR(array("=3.5", "max" => "3", "usrPreviewImg" => "true")), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrSize'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrResult'][$usrLang] . insertUSR(array("=3.5", "usrPreviewImg" => "true", "size" => 20)), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrOverriddenAll'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrResult'][$usrLang] . insertUSR(array("=3.5", "max" => "3", "text" => "false", "img" => "03.png", "usrPreviewImg" => "true", "size" => 20)), 'universal-star-rating');
    ?>
</td>
              </tr>
              <tr>
                <td><?php 
    _e($SETTINGS['PREV']['ExampleUsrListOverriddenAverage'][$usrLang], 'universal-star-rating');
    ?>
</td>
                <td><?php 
    _e(insertUSRList(array($SETTINGS['PREV']['ExampleUsrListResult'][$usrLang][1], $SETTINGS['PREV']['ExampleUsrListResult'][$usrLang][2], $SETTINGS['PREV']['ExampleUsrListResult'][$usrLang][3], "avg" => "true", "usrPreviewImg" => "true")), 'universal-star-rating');
    ?>
</td>
              </tr>
            </table>
          </p>
          
          <?php 
    if (function_exists('settings_fields')) {
        settings_fields('rating_settings');
    }
    ?>
					<input type='submit' name='usrOptionsUpdate' class="button-primary" value='<?php 
    _e($SETTINGS['GLOBAL']['SubmitButton'][$usrLang], 'universal_star_rating');
    ?>
' />
					<input type='submit' name='usrOptionsReset' class="button" value='<?php 
    _e($SETTINGS['GLOBAL']['ResetButton'][$usrLang], 'universal_star_rating');
    ?>
' />
				</form>				
			</div>
			<div id="usrFooter" class="wrap">
				<?php 
    echo 'Plugin Version: <strong>' . get_option('usrVersion') . '</strong>';
    ?>
			</div>
		</div>

<?php 
}