public function saveOptions($newOptions)
 {
     // Validate template options
     $dsplLayout = isset($newOptions['dsplLayout']) ? $newOptions['dsplLayout'] : 'Grid';
     erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
     VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$scThemesFolder), $dsplLayout);
     $theme = VPluginThemeFactory::getThemeByName($dsplLayout);
     $templateOptions = array();
     if ($theme) {
         $templateOptions = $theme->saveSettings($newOptions);
         foreach ($theme->getDefOptions() as $key => $value) {
             unset($newOptions[$key]);
         }
     }
     $this->options = $templateOptions + $this->validateCommonOptions($newOptions) + $this->validateShortcodeOptions($newOptions);
     if (isset($this->profileName)) {
         $this->profiles[$this->profileName] = array_merge(erpPRODefaults::$comOpts + erpPRODefaults::$shortCodeOpts, $this->options);
         return update_option(self::$shortCodeProfilesArrayName, $this->profiles);
     } else {
         return array_merge(erpPRODefaults::$comOpts + erpPRODefaults::$shortCodeOpts, $this->options);
     }
 }
/**
 * Shortcode function
 *
 * @param array $attrs
 * @return string
 * @author Panagiotis Vagenas <*****@*****.**>
 * @since 1.0.0
 */
function erpPROShortcode($attrs)
{
    // If no profile is set return empty string
    if (!isset($attrs['profile'])) {
        return '';
    }
    global $post;
    if ($post == null) {
        return '';
    }
    erpPROPaths::requireOnce(erpPROPaths::$erpPROShortcode);
    $sc = new erpPROShortcode($attrs['profile']);
    return $sc->display($post->ID);
}
                        <th colspan="2">Theme options</th>
                    </tr>
                    <tr>
                        <td>
                            <label for="dsplLayout">Theme :</label>
                        </td>
                        <td>
                            <select 
                                class="dsplLayout"  
                                name="dsplLayout"
                                data-tooltip 
                                title="From the dropdown you can define the appearance of the plugin in the main content area. When a theme is selected the additional options will show up bellow theme selection dropdown"
                                >
                                    <?php 
erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$scThemesFolder));
$templates = VPluginThemeFactory::getThemesNames();
foreach ($templates as $key => $val) {
    echo '<option value="' . $val . '"' . selected($erpPROOptions['dsplLayout'], $val, FALSE) . '>' . $val . '</option>';
}
?>
                            </select>
                        </td>
                    </tr>
                </table>
                <div class="templateSettings"></div>
            </div>
        </form>
    </div>
    <!-- 	</form> -->
    <script type="text/javascript">
 /**
  * Sanitize widget form values as they are saved.
  *
  * @see WP_Widget::update()
  *
  * @param array $new_instance
  *        	Values just sent to be saved.
  * @param array $old_instance
  *        	Previously saved values from database.
  * @return array Updated safe values to be saved.
  * @since 1.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function update($new_instance, $old_instance)
 {
     /* #? Verify nonce */
     if (!isset($_POST['erpPRO_meta_box_nonce']) || !wp_verify_nonce($_POST['erpPRO_meta_box_nonce'], 'erpPRO_meta_box_nonce')) {
         return;
     }
     erpPROPaths::requireOnce(erpPROPaths::$erpPROWidOpts);
     // get an instance to validate options
     $widOpts = new erpPROWidOpts($old_instance);
     // validate wid options
     $widOptsValidated = $widOpts->saveOptions($new_instance, $old_instance);
     // validate template options
     if (isset($new_instance['dsplLayout'])) {
         erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
         VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$widgetThemesFolder), $new_instance['dsplLayout']);
         $theme = VPluginThemeFactory::getThemeByName($new_instance['dsplLayout']);
         if ($theme) {
             $themeValidated = $theme->saveSettings($new_instance);
             foreach ($theme->getDefOptions() as $key => $value) {
                 unset($new_instance[$key]);
             }
         } else {
             // TODO Set notices class
             //                $message = new WP_Error_Notice('Theme ' . $new_instance ['dsplLayout'] . ' not found. Theme options discarded');
             //                WP_Admin_Notices::getInstance()->addNotice($message);
         }
     }
     // save updated options
     return $widOptsValidated + $themeValidated;
 }
 private function setSuppressOthers()
 {
     // Setting supress others option
     erpPROPaths::requireOnce(erpPROPaths::$erpPROTheme);
     if ($this->optObj->getSuppressOthers() === true) {
         erpPROTheme::suppressOthers(true);
     } elseif ($this->optObj->getSuppressOthers() === false) {
         erpPROTheme::suppressOthers(false);
     }
 }
 /**
  * Uses bfi resizer to resize image and returns url to new image
  * @param string $url
  * @param int $width
  * @param int $height
  * @param bool $crop
  * @return string
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 private function resize($url, $width = NULL, $height = NULL, $crop = true)
 {
     erpPROPaths::requireOnce(erpPROPaths::$bfiResizer);
     return bfi_thumb($url, array('width' => $width, 'height' => $height, 'crop' => $crop));
 }
 /**
  *
  * @param array $options
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 protected function __construct($options)
 {
     if (!class_exists('erpPROQueryFormater')) {
         erpPROPaths::requireOnce(erpPROPaths::$erpPROQueryFormater);
     }
     if (!class_exists('erpPRODBActions')) {
         erpPROPaths::requireOnce(erpPROPaths::$erpPRODBActions);
     }
     if (!class_exists('erpPRORatingSystem')) {
         erpPROPaths::requireOnce(erpPROPaths::$erpPRORatingSystem);
     }
     if (!class_exists('erpPRORelData')) {
         erpPROPaths::requireOnce(erpPROPaths::$erpPRORelData);
     }
     $this->options = $options;
     $this->dbActions = erpPRODBActions::getInstance();
     $this->wpSession = WP_Session::get_instance();
 }
 /**
  * Fired for each blog when the plugin is activated.
  *
  * @since 1.0.0
  */
 private static function single_activate()
 {
     erpPROPaths::requireOnce(erpPROPaths::$erpPROActivator);
     $compareVersions = erpPRODefaults::compareVersion(get_option(erpPRODefaults::versionNumOptName));
     if ($compareVersions < 0) {
         erpPROActivator::createERPTable();
         erpPROActivator::addNonExistingMainOptions(erpPRODefaults::$comOpts + erpPRODefaults::$mainOpts, EPR_PRO_MAIN_OPTIONS_ARRAY_NAME);
         erpPROActivator::addNonExistingWidgetOptions(erpPRODefaults::$comOpts + erpPRODefaults::$widOpts, 'widget_' . erpPRODefaults::erpPROWidgetOptionsArrayName);
         erpPRODefaults::updateVersionNumbers();
     } elseif ($compareVersions === 0) {
         // Major update
         erpPRODefaults::updateVersionNumbers();
     } elseif ($compareVersions === 1) {
         // Release update
         erpPRODefaults::updateVersionNumbers();
     } elseif ($compareVersions === 2) {
         // Minor update
         erpPRODefaults::updateVersionNumbers();
     }
     // Cron jobs
     wp_schedule_event(time(), 'weekly', 'erpPRO_weekly_event_hook');
 }
                        <?php 
}
?>
                </table>
            </div>
            <!--</div>-->
        </div>
        <?php 
echo get_submit_button('Update options', 'primary large', 'Save');
?>
        <input id="tab-spec" type="hidden" name="tab-spec" value="0">
        <input id="clearCacheButton" class="button" type="button" value="Clear cache" name="clearCacheButton">
        <?php 
//<input id="rebuildCacheButton" class="button" type="button" value="Rebuild cache" name="rebuildCacheButton">
?>
        <script type="text/javascript">
            var templateRoot = "<?php 
echo erpPROPaths::getAbsPath(erpPROPaths::$mainThemesFolder);
?>
";
            var options = {};
<?php 
$tabSpec = filter_input(INPUT_GET, 'tab-spec');
if ($tabSpec !== null && $tabSpec !== false) {
    echo 'options.active= ' . (int) $tabSpec . ';';
}
?>
        </script>
    </form>
</div>
 /**
  * Increases displayed values for given pids
  *
  * @param int $pid
  * @param array $pids
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 public static function addDisplayed($pid, array $pids)
 {
     erpPROPaths::requireOnce(erpPROPaths::$erpPRODBActions);
     $db = erpPRODBActions::getInstance();
     $db->addDisplayed($pid, $pids);
 }
 /**
  * This is called through ajax hook and returns the plugin options as defined in template settings file
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 public function loadSCTemplateOptions()
 {
     if (!isset($_POST['template'])) {
         echo json_encode(false);
         die;
     }
     erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
     if (isset($_POST['profileName'])) {
         $profileName = $_POST['profileName'];
         erpPROPaths::requireOnce(erpPROPaths::$erpPROShortCodeOpts);
         $profilesOptionsArray = get_option(erpPROShortCodeOpts::$shortCodeProfilesArrayName);
         $profileOpts = isset($profilesOptionsArray[$profileName]) ? $profilesOptionsArray[$profileName] : null;
     }
     if (empty($profileOpts)) {
         $profileOpts = erpPRODefaults::$comOpts + erpPRODefaults::$shortCodeOpts;
         $profileName = 'default';
     }
     VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$scThemesFolder), $_POST['template']);
     $templateObj = VPluginThemeFactory::getThemeByName($_POST['template']);
     if (!$templateObj) {
         echo json_encode(false);
         die;
     }
     $templateObj->setOptions($profileOpts);
     $data = array('content' => $templateObj->renderSettings('', FALSE), 'optionValues' => $profilesOptionsArray);
     echo json_encode($data);
     die;
 }
" style="border: 1px solid lightblue;padding: 10px;border-radius: 5px;">
    <span style="position: relative; top: -21px; float: left; background-color: white;"> Theme options </span><br>
    <?php 
foreach ($templates as $key => $value) {
    $temp = VPluginThemeFactory::getThemeByName($value);
    echo '<span class="templateSettings" data-template="' . $value . '" hidden="hidden">';
    $temp->setOptions($options);
    echo $temp->renderSettings($widgetInstance);
    echo '</span>';
}
?>

</p>
<script type="text/javascript">
    var templateRoot = "<?php 
echo erpPROPaths::getAbsPath(erpPROPaths::$widgetThemesFolder);
?>
";
    jQuery(document).ready(function($) {

        jQuery('#<?php 
echo $widgetInstance->get_field_id("postTitleColor");
?>
').wpColorPicker();
        jQuery('#<?php 
echo $widgetInstance->get_field_id("excColor");
?>
').wpColorPicker();

    });
</script>
 /**
  * Get default thumb url
  * @return string|NULL
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 public function getDefaultThumbnail()
 {
     if ($this instanceof erpPROMainOpts) {
         $t = $this->getValue('defaultThumbnail');
     } else {
         erpPROPaths::requireOnce(erpPROPaths::$erpPROMainOpts);
         $mOpts = new erpPROMainOpts();
         $t = $mOpts->getDefaultThumbnail();
     }
     return !empty($t) ? $t : erpPRODefaults::$comOpts['defaultThumbnail'];
 }
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * @copyright 2014 Panagiotis Vagenas <*****@*****.**>
 */
erpPROPaths::requireOnce(erpPROPaths::$erpPROTheme);
/**
 * Description of erpTheme
 * 
 * @author Panagiotis Vagenas <*****@*****.**>
 */
class erpPROListTheme extends erpPROTheme
{
    /**
     * The name of the theme
     * @var string 
     */
    protected $name = 'List';
    /**
     * A description for theme
     * @var string
 public function formPostData(WP_Query $wpq, erpPROOptions $optionsObj, $ratings = array())
 {
     erpPROPaths::requireOnce(erpPROPaths::$erpPROPostData);
     $from = get_the_ID();
     $data = array('title' => $optionsObj->getValue('title'), 'options' => $this->options, 'uniqueID' => $this->uniqueID, 'optionsObj' => $optionsObj, 'posts' => array());
     while ($wpq->have_posts()) {
         $wpq->the_post();
         $rating = isset($ratings[get_the_ID()]) ? $ratings[get_the_ID()] : null;
         $postData = new erpPROPostData($wpq->post, $optionsObj, $rating, $from);
         if ($optionsObj->haveToShowExcerpt()) {
             $postData->setExcerpt($optionsObj->getValue('excLength'), $optionsObj->getValue('moreTxt'));
         }
         if ($optionsObj->haveToShowThumbnail()) {
             $postData->setThumbnail($optionsObj->getDefaultThumbnail());
         }
         array_push($data['posts'], $postData);
     }
     wp_reset_postdata();
     $this->setAdditionalViewData(array_merge($data, $this->options));
     return $this;
 }
<?php

/**
 * Easy related posts PRO.
 *
 * @package   Easy_Related_Posts_Options
 * @author    Panagiotis Vagenas <*****@*****.**>
 * @link      http://erp.xdark.eu
 * @copyright 2014 Panagiotis Vagenas <*****@*****.**>
 */
erpPROPaths::requireOnce(erpPROPaths::$erpPROOptions);
/**
 * Main plugin options class.
 *
 * @package Easy_Related_Posts_Options
 * @author    Panagiotis Vagenas <*****@*****.**>
 */
class erpPROMainOpts extends erpPROOptions
{
    public function __construct()
    {
        parent::__construct();
        $this->optionsArrayName = EPR_PRO_MAIN_OPTIONS_ARRAY_NAME;
        $this->defaults = erpPRODefaults::$mainOpts + erpPRODefaults::$comOpts;
        $this->loadOptions();
    }
    public function loadOptions()
    {
        $opt = get_option($this->optionsArrayName);
        if ($opt) {
            $this->options = $opt;
 private static function delShortCodeProfiles()
 {
     erpPROPaths::requireOnce(erpPROPaths::$erpPROShortCodeOpts);
     delete_option(erpPROShortCodeOpts::$shortCodeProfilesArrayName);
 }