Beispiel #1
0
 /**
  * Update facebook page status
  */
 public function post($type)
 {
     // if type is exists
     if (!$this->is_type_exists($type)) {
         return false;
     }
     // if ( ! is_allowed_time() ) return false;
     $count = 0;
     $this->page_type = $type;
     $urls = $this->get_posts();
     if (empty($urls)) {
         return false;
     }
     $index = range(0, $this->post_limit - 1);
     shuffle($index);
     while ($count < 8) {
         $url = $urls[$index[$count]];
         $site = $this->get_site_by_site_id($url['site_id']);
         $post_title = $url['title'];
         // get post url
         $post_url = $this->get_post_url($url['request_uri'], $site);
         $is_url_exists = is_url_exists(urldecode($post_url));
         //
         // TODO
         // don't know why some URL isn't exists
         // e.g. https://blog.eduzones.com/studyabroad/143177
         //
         if ($this->page_type == 'edu') {
             $is_url_exists = true;
         }
         if ($this->page_type == 'youv') {
             $is_url_exists = true;
         }
         if ($is_url_exists) {
             //
             // TODO - Use comment as a title
             //
             // $comment = array();
             // $comment_element = $site['comment_element'];
             // if ($site['has_comment'] == 1) $comment = $this->get_targeted_data($post_url, $comment_element);
             //
             // Facebook
             try {
                 $action = $this->publish_facebook($post_title, $post_url);
                 $action_id = $action['id'];
                 $this->news_model->update_published_link($url['id']);
             } catch (FacebookRequestException $ex) {
                 printf('FacebookRequestException: %s', $ex->getMessage());
                 $this->news_model->insert_error_log('post', 'FacebookRequestException : ' . $e->getMessage());
                 return false;
             } catch (\Exception $ex) {
                 printf('Caught exception: %s', $ex->getMessage());
                 $this->news_model->insert_error_log('post', 'Exception : ' . $e->getMessage());
                 return false;
             }
             break;
         } else {
             $this->news_model->insert_error_log('post', 'link number ' . $url['id'] . ' is broken');
             $this->news_model->update_broken_link($url['id']);
         }
         $count++;
     }
     if (isset($action_id) && !is_null_or_empty_string($action_id)) {
         $this->news_model->insert_published_log($url['id'], $action_id);
         printf('<code>Published</code>');
     } else {
         $this->news_model->insert_error_log('post', 'all urls are not exist');
         printf('<code>Can not publish (all urls are not exist)</code>');
     }
 }
Beispiel #2
0
 /**
  * Добавление внешнего JS скрипта
  *   
  * @param string $url
  * @param bool $head - в заголовке <HEAD> или перед </BODY>
  * @return Theme
  */
 public function useExternalJs($url, $head = true)
 {
     if (!is_array($this->_js_list)) {
         $this->_js_list = [];
     }
     $position = $head === false ? 'footer' : 'header';
     if (!is_array($this->_js_list[$position])) {
         $this->_js_list[$position] = [];
     }
     if (is_url_exists($url)) {
         $this->_js_list[$position][] = $url;
     }
     return $this;
 }