public function onBeforeRender()
 {
     $config = OW::getConfig();
     $apiKey = $config->getValue('socialsharing', 'api_key');
     if (empty($apiKey)) {
         $this->setVisible(false);
     } else {
         $order = $config->getValue('socialsharing', 'order');
         $defautOrder = SOCIALSHARING_CLASS_Settings::getEntityList();
         if (!empty($order)) {
             $order = json_decode($order, true);
             if (!is_array($order)) {
                 $order = $defautOrder;
             }
             $result = array();
             foreach ($order as $key => $item) {
                 if (in_array($key, $defautOrder)) {
                     $result[$key] = $key;
                 }
             }
             if (!empty($order)) {
                 $order = $result;
             } else {
                 $order = $defautOrder;
             }
         } else {
             $order = $defautOrder;
         }
         foreach ($order as $key => $item) {
             $var = $config->getValue('socialsharing', $item);
             if (empty($var)) {
                 unset($order[$key]);
             }
         }
         $id = uniqid(rand(0, 999999));
         $this->assign('id', $id);
         OW::getDocument()->addStyleSheet(OW::getPluginManager()->getPlugin('socialsharing')->getStaticCssUrl() . 'style.css');
         $script = "";
         if (!empty($this->imageUrl)) {
             OW::getDocument()->addMetaInfo('image', $this->imageUrl, 'itemprop');
             OW::getDocument()->addMetaInfo('og:image', $this->imageUrl, 'property');
             $script .= " image: " . json_encode($this->imageUrl) . ", ";
         }
         if (!empty($this->url)) {
             $script .= " url: " . json_encode($this->url) . ",";
             OW::getDocument()->addMetaInfo('og:url', $this->url, 'property');
         }
         if (!empty($this->description)) {
             $script .= " description: " . json_encode($this->description) . ",";
             OW::getDocument()->addMetaInfo('og:description', $this->description, 'property');
         }
         if (!empty($this->title)) {
             $script .= " title: " . json_encode($this->title) . ",";
             OW::getDocument()->addMetaInfo('og:title', $this->title, 'property');
         }
         OW::getDocument()->addScript('//s7.addthis.com/js/300/addthis_widget.js#pubid=' . urlencode(OW::getConfig()->getValue('socialsharing', 'api_key')) . '&async=1');
         $script = substr($script, 0, -1);
         OW::getDocument()->addOnloadScript("\n\t\t\t\tvar addthis_share  =\n\t\t\t\t{\n\t\t\t\t\t{$script}\n\t\t\t\t};\n\t\t\t\taddthis.init();\n\t\t\t\taddthis.toolbox('.addthis_toolbox', {}, addthis_share);\n\t\t\t");
         $this->assign('url', $this->url);
         $this->assign('title', $this->title);
         $this->assign('description', $this->description);
         $this->assign('script', $script);
         $this->assign('order', $order);
         $this->assign('class', $this->class);
         $this->assign('imageUrl', $this->imageUrl);
         if ($this->displayBlock) {
             $this->setTemplate(OW::getPluginManager()->getPlugin('socialsharing')->getCmpViewDir() . 'share_buttons_block.html');
         }
     }
     return parent::onBeforeRender();
 }
Example #2
0
 /**
  * Default action
  */
 public function index()
 {
     $this->contentMenu->getElement('socialsharing_index')->setActive(true);
     $config = OW::getConfig();
     $order = $config->getValue('socialsharing', 'order');
     $defautOrder = SOCIALSHARING_CLASS_Settings::getEntityList();
     if (!empty($order)) {
         $order = json_decode($order, true);
         if (!is_array($order)) {
             $order = $defautOrder;
         }
         $result = array();
         foreach ($order as $key => $item) {
             if (in_array($key, $defautOrder)) {
                 $result[$key] = $key;
             }
         }
         if (!empty($order)) {
             $order = $result;
         } else {
             $order = $defautOrder;
         }
     } else {
         $order = $defautOrder;
     }
     $this->assign('order', $order);
     $settings = new Form('settings');
     //printVar($order);
     foreach ($order as $item) {
         $element = new CheckboxField($item);
         $element->setValue($config->getValue('socialsharing', $item));
         $settings->addElement($element);
     }
     $submit = new Submit('save_settings');
     $settings->addElement($submit);
     //printVar($config->getValue('socialsharing', 'facebook'));
     $apiKeyForm = new Form('api_key_form');
     $key = new TextField('api_key');
     $key->setLabel(OW::getLanguage()->text('socialsharing', 'api_key_label'));
     $key->setRequired();
     $apiKey = OW::getConfig()->getValue('socialsharing', 'api_key');
     $key->setValue($apiKey);
     $apiKeyForm->addElement($key);
     $apiKeySubmit = new Submit('save_api_key');
     $apiKeyForm->addElement($apiKeySubmit);
     $this->addForm($apiKeyForm);
     if (OW::getRequest()->isPost()) {
         if (isset($_POST['save_settings'])) {
             if ($settings->isValid($_POST)) {
                 $data = $settings->getValues();
                 $config->saveConfig('socialsharing', 'facebook', (bool) $data['facebook']);
                 $config->saveConfig('socialsharing', 'twitter', (bool) $data['twitter']);
                 $config->saveConfig('socialsharing', 'googlePlus', (bool) $data['googlePlus']);
                 $config->saveConfig('socialsharing', 'pinterest', (bool) $data['pinterest']);
                 OW::getFeedback()->info(OW::getLanguage()->text('socialsharing', 'settings_saved'));
                 //Setting succsessfully saved
                 $this->redirect();
             } else {
                 OW::getFeedback()->error(OW::getLanguage()->text('socialsharing', 'settings_saved_error'));
                 //
             }
         } else {
             if (isset($_POST['save_api_key'])) {
                 if ($apiKeyForm->isValid($_POST)) {
                     $data = $apiKeyForm->getValues();
                     $config->saveConfig('socialsharing', 'api_key', $data['api_key']);
                     OW::getFeedback()->info(OW::getLanguage()->text('socialsharing', 'api_key_saved'));
                     //Setting succsessfully saved
                     //$this->redirect();
                 } else {
                     OW::getFeedback()->error(OW::getLanguage()->text('socialsharing', 'settings_saved_error'));
                     //
                 }
             }
         }
     }
     $this->addForm($settings);
     OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('socialsharing')->getStaticJsUrl() . "admin.js");
     OW::getDocument()->addOnloadScript(" window.sharing = new socialSharingAdmin(" . json_encode(array("ajaxResponderUrl" => OW::getRouter()->urlFor('SOCIALSHARING_CTRL_Admin', 'ajaxResponder'))) . ") ");
 }