/**
  * Called when the widget form element is rendered.
  */
 public function form($aInstance)
 {
     // Avoid undefined index warnings.
     $_oDefaultTemplate = new FetchTweets_Template();
     // pass nothing to get the default template.
     $aInstance = $aInstance + $this->_aStructure_FormElements;
     $aInstance['template'] = isset($aInstance['template']) ? $aInstance['template'] : $_oDefaultTemplate->getSlug();
     $_aIDs = $this->_getFieldValues('id');
     $_aNames = $this->_getFieldValues('name');
     $this->echoFormElements($aInstance, $_aIDs, $_aNames);
 }
 /**
  * Returns an array holding the labels(names) of activated templates.
  * 
  * This is used for the widget form or the template meta box to let the user select a template.
  * 
  * @since       unknown
  * @since       2.3.9           Moved form the templates class.
  */
 public static function getTemplateArrayForSelectLabel($aTemplates = null)
 {
     $_oOption = FetchTweets_Option::getInstance();
     if (!$aTemplates) {
         $aTemplates = $_oOption->getActiveTemplates();
     }
     $_aLabels = array();
     foreach ($aTemplates as $_sSlug => $_aTemplate) {
         $_oTemplate = new FetchTweets_Template($_aTemplate['sSlug']);
         $_sName = $_oTemplate->get('sName');
         if (!$_sName) {
             continue;
         }
         // it may be broken.
         $_aLabels[$_aTemplate['sSlug']] = $_sName;
     }
     return $_aLabels;
 }
 /**
  * Returns the template name by post ID.
  */
 public function cell_fetch_tweets_template($sCell, $iPostID)
 {
     // cell_{post type slug}_{column key}
     $_sTemplateSlug = get_post_meta($iPostID, 'fetch_tweets_template', true);
     $_oTemplate = new FetchTweets_Template($_sTemplateSlug);
     return $sCell . $_oTemplate->get('sName');
 }
 /**
  * Returns the path of the specified template.
  * 
  * @since       Unknown
  * @since       2.3.9       Changed it to use the relative path to WordPress installed directory.
  * @return      The template path; false if not exist.
  */
 protected function _getTemplatePathBySlug($sTemplateSlug)
 {
     $_oTemplate = new FetchTweets_Template($sTemplateSlug);
     // passing none to the constructor creates default template object.
     return $_oTemplate->getPathByFileName('template.php');
 }
 /**
  * Loads the file of active template of the given file name.
  * 
  * @since       2.3.9
  * @param       string      $sFileName      The file base name with file extension to load.
  * @param       string      $sMethod        The method to load. Either 'include' or 'enqueue_style' is accepted. Use 'enqueue_style' for styles.
  */
 private function _loadFileOfActiveTemplatesByFileName($sFileName = 'functions.php', $sMethod = 'include')
 {
     $_oOption = FetchTweets_Option::getInstance();
     foreach ($_oOption->getActiveTemplates() as $_aTemplate) {
         $_oTemplate = new FetchTweets_Template($_aTemplate['sSlug']);
         $_sFilePath = $_oTemplate->getPathByFileName($sFileName);
         if (!$_sFilePath) {
             continue;
         }
         if (in_array($_sFilePath, self::$_aLoaded)) {
             continue;
         }
         self::$_aLoaded[$_sFilePath] = $_sFilePath;
         switch ($sMethod) {
             default:
             case 'include':
                 include $_sFilePath;
                 break;
             case 'enqueue_style':
                 wp_register_style("fetch-tweets-" . md5($_aTemplate['sDirPath']), FetchTweets_WPUtilities::getSRCFromPath($_sFilePath));
                 wp_enqueue_style("fetch-tweets-" . md5($_aTemplate['sDirPath']));
                 break;
         }
     }
 }
 public function setUp()
 {
     $_oTemplate = new FetchTweets_Template();
     // passing an empty value will make the object default template.
     $this->addSettingFields(array('field_id' => 'fetch_tweets_template', 'title' => __('Select Template', 'fetch-tweets'), 'description' => __('Set the default template for this rule. If a template is specified in a widget, the shortcode, or the function, this setting will be overridden.', 'fetch-tweets'), 'label' => $arr = FetchTweets_PluginUtility::getTemplateArrayForSelectLabel(), 'type' => 'select', 'default' => $_oTemplate->getSlug(), 'show_title_column' => false), array());
 }