Esempio n. 1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     $configdata = $instance->get('configdata');
     $smarty = smarty_core();
     if (!empty($configdata['collection'])) {
         $views = $instance->get_data('collection', $configdata['collection'])->views();
         if (!empty($views)) {
             $smarty->assign('views', $views['views']);
         }
     }
     $smarty->assign('currentview', $instance->get('view'));
     return $smarty->fetch('blocktype:navigation:navigation.tpl');
 }
Esempio n. 2
0
 public static function instance_config_validate(Pieform $form, $values)
 {
     if (strpos($values['url'], '://') == false) {
         // try add on http://
         $values['url'] = 'http://' . $values['url'];
     } else {
         $proto = substr($values['url'], 0, strpos($values['url'], '://'));
         if (!in_array($proto, array('http', 'https'))) {
             $form->set_error('url', get_string('invalidurl', 'blocktype.externalfeed'), false);
         }
     }
     // If you're changing the URL on an authenticated feed, force them to re-enter the password
     if (!empty($values['blockconfig'])) {
         $instance = new BlockInstance($values['blockconfig']);
         $configdata = $instance->get('configdata');
         if (!empty($configdata['feedid'])) {
             $olddata = $instance->get_data('feed', $configdata['feedid']);
             if ($olddata) {
                 if ($values['url'] != $olddata->url && $olddata->authpassword != '' && $values['authpassword']['submittedvalue'] === null) {
                     $form->set_error('authpassword', get_string('reenterpassword', 'blocktype.externalfeed'), false);
                     return;
                 }
             }
         }
     }
     if (!$form->get_error('url')) {
         try {
             $authpassword = $values['authpassword']['submittedvalue'] !== null ? $values['authpassword']['submittedvalue'] : $values['authpassword']['defaultvalue'];
             self::parse_feed($values['url'], $values['insecuresslmode'], $values['authuser'], $authpassword);
             return;
         } catch (XML_Feed_Parser_Exception $e) {
             $form->set_error('url', get_string('invalidfeed', 'blocktype.externalfeed', hsc($e->getMessage())), false);
         }
     }
 }