Esempio n. 1
2
 public function fetch($delete = false)
 {
     $oImap = imap_open('{' . $this->mail_server . ':993/imap/ssl/notls/novalidate-cert}', $this->username, $this->password);
     $oMailboxStatus = imap_check($oImap);
     $aMessages = imap_fetch_overview($oImap, "1:{$oMailboxStatus->Nmsgs}");
     $validMessages = array();
     foreach ($aMessages as $oMessage) {
         print "Trying message '" . $oMessage->subject . "'";
         $fileContent = $fileType = '';
         $geocoder = factory::create('geocoder');
         $postCode = $geocoder->extract_postcode($oMessage->subject);
         $fromName = null;
         $fromEmail = null;
         if (strpos($oMessage->from, '<')) {
             $split = split('<', $oMessage->from);
             //name - make sure name not an email address
             $fromName = trim($split[0]);
             if (valid_email($fromName)) {
                 $fromName = null;
             }
             //email
             $fromEmail = trim(str_replace('>', '', $split[1]));
         } else {
             $fromEmail = $oMessage->from;
         }
         $images = array();
         $messageStructure = imap_fetchstructure($oImap, $oMessage->msgno);
         if (isset($messageStructure->parts)) {
             $partNumber = 0;
             foreach ($messageStructure->parts as $oPart) {
                 $partNumber++;
                 if ($oPart->subtype == 'PLAIN' && !$postCode) {
                     $messageContent = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     if ($oPart->encoding == 4) {
                         $messageContent = quoted_printable_decode($messageContent);
                     }
                     $postCode = geocoder::extract_postcode($messageContent);
                 } elseif ($oPart->encoding == 3 && in_array($oPart->subtype, array('JPEG', 'PNG'))) {
                     $oImage = null;
                     $encodedBody = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     $fileContent = base64_decode($encodedBody);
                     $oImage = imagecreatefromstring($fileContent);
                     if (imagesx($oImage) > $this->min_import_size && imagesy($oImage) > $this->min_import_size) {
                         array_push($images, $oImage);
                     }
                     $fileType = strtolower($oPart->subtype);
                 }
             }
         }
         //add to the messages array
         array_push($validMessages, array('postcode' => $postCode, 'images' => $images, 'file_type' => $fileType, 'from_address' => $fromAddress, 'from_email' => $fromEmail, 'from_name' => $fromName));
         if ($delete) {
             imap_delete($oImap, $oMessage->msgno);
         }
     }
     imap_close($oImap, CL_EXPUNGE);
     $this->messages = $validMessages;
 }
 /**
  * Whether we can perform certain action
  *
  * @param mixed $action_code_or_id
  * @return boolean
  */
 public static function can($action_code_or_id)
 {
     if (self::$cache_actions === null) {
         self::$cache_actions = factory::model('numbers_backend_system_controller_model_actions')->get();
     }
     if (is_string($action_code_or_id)) {
         foreach (self::$cache_actions as $k => $v) {
             if ($v['sm_cntractn_code'] == $action_code_or_id) {
                 $action_code_or_id = $k;
                 break;
             }
         }
     }
     if (!isset(self::$cache_actions[$action_code_or_id])) {
         throw new Exception('Unknown action!');
     }
     $permissions = application::get(['controller', 'acl', 'permissions']);
     $start = $action_code_or_id;
     do {
         // see if we have permission
         if (empty($permissions[$start])) {
             break;
         }
         // we need to check permission on a parent
         if (!empty(self::$cache_actions[$start]['sm_cntractn_parent_id'])) {
             $start = self::$cache_actions[$start]['sm_cntractn_parent_id'];
         } else {
             // exit if there's no parent
             return true;
         }
     } while (1);
     return false;
 }
Esempio n. 3
0
 /**
  * Constructing cache object
  *
  * @param string $cache_link
  * @param string $class
  */
 public function __construct($cache_link = null, $class = null)
 {
     // if we need to use default link from application
     if (empty($cache_link)) {
         $cache_link = application::get(['flag', 'global', 'cache', 'default_cache_link']);
         if (empty($cache_link)) {
             throw new Exception('You must specify cache link and/or class!');
         }
     }
     // get object from factory
     $temp = factory::get(['cache', $cache_link]);
     // if we have class
     if (!empty($class) && !empty($cache_link)) {
         // replaces in case we have it as submodule
         $class = str_replace('.', '_', trim($class));
         // if we are replacing database connection with the same link we
         // need to manually close connection
         if (!empty($temp['object']) && $temp['class'] != $class) {
             $object = $temp['object'];
             $object->close();
             unset($this->object);
         }
         $this->object = new $class($cache_link);
         // putting every thing into factory
         factory::set(['cache', $cache_link], ['object' => $this->object, 'class' => $class]);
     } else {
         if (!empty($temp['object'])) {
             $this->object = $temp['object'];
         } else {
             throw new Exception('You must specify cache link and/or class!');
         }
     }
 }
Esempio n. 4
0
 /**
  * Get the unique cache instance
  *
  * @param array $cfg Config for the cache instance
  * @return cache_abstract The instance
  */
 public static function getInstance(array $cfg = array())
 {
     if (!self::$cfg) {
         self::$cfg = new config(factory::loadCfg(__CLASS__));
     }
     return factory::get('cache_' . self::$cfg->use, $cfg);
 }
    public function query($options = [])
    {
        $model = factory::model($options['model']);
        $db = $model->db_object();
        $where = '';
        if (!empty($options['where'])) {
            $where = 'AND ' . $db->prepare_condition($options['where']);
        }
        $ts = $db->full_text_search_query($options['fields'], $options['search_text'] . '');
        $fields = $options['fields'];
        $sql_pk = '';
        // we automatically include main pk into a query
        if (!in_array($options['pk'], $options['fields'])) {
            // in_array($options['pk'], $model->pk) &&
            $fields[] = $options['pk'];
            // we need to include integer types to the query
            $temp = intval($options['search_text']);
            if ($model->columns[$options['pk']]['php_type'] == 'integer' && $temp != 0) {
                $sql_pk .= " OR {$options['pk']} = " . (int) $options['search_text'];
            }
        }
        $fields[] = $ts['rank'];
        $fields = implode(', ', $fields);
        $tmp = <<<TTT
\t\t\tSELECT
\t\t\t\t{$fields}
\t\t\tFROM [table[{$options['model']}]] a
\t\t\tWHERE 1=1
\t\t\t\t\t{$where}
\t\t\t\t\tAND (({$ts['where']}){$sql_pk})
\t\t\tORDER BY {$ts['orderby']} DESC, {$options['fields'][0]}
\t\t\tLIMIT 11
TTT;
        return $tmp;
    }
 public static function example_postcode()
 {
     $election_id = get_election_id($election_id);
     $search = factory::create('search');
     $result = $search->search("australian_postcode", array(array('election_id', '=', $election_id)), null, null, null, 1);
     return $result[0]->postcode;
 }
Esempio n. 7
0
 /**
  * Constructing crypt object
  *
  * @param string $db_link
  * @param string $class
  */
 public function __construct($crypt_link = null, $class = null, $options = [])
 {
     // if we need to use default link from application
     if ($crypt_link == null) {
         $crypt_link = application::get(['flag', 'global', 'crypt', 'default_crypt_link']);
         if (empty($crypt_link)) {
             throw new Exception('You must specify crypt link!');
         }
     }
     // get object from factory
     $temp = factory::get(['crypt', $crypt_link]);
     // if we have class
     if (!empty($class) && !empty($crypt_link)) {
         // replaces in case we have it as submodule
         $class = str_replace('.', '_', trim($class));
         // creating new class
         unset($this->object);
         $this->object = new $class($crypt_link, $options);
         factory::set(['crypt', $crypt_link], ['object' => $this->object, 'class' => $class]);
     } else {
         if (!empty($temp['object'])) {
             $this->object = $temp['object'];
         } else {
             throw new Exception('You must specify crypt link and/or class!');
         }
     }
 }
Esempio n. 8
0
 private function lookup_constituency($postcode)
 {
     $cache = cache::factory();
     $cached = $cache->get('twfy' . $postcode);
     if (isset($cached) && $cached !== false && $cached != '') {
         return $cached;
     } else {
         if (COUNTRY_CODE_TLD == "uk") {
             $twfy = factory::create('twfy');
             $twfy_constituency = $twfy->query('getConstituency', array('output' => 'php', 'postcode' => $postcode, 'future' => 'yes_please'));
             $twfy_constituency = unserialize($twfy_constituency);
             $success = $cache->set('twfy' . $postcode, $twfy_constituency);
             $twfy_constituency = array($twfy_constituency["name"]);
         } else {
             if (COUNTRY_CODE_TLD == "au") {
                 $australian_postcode = factory::create("australian_postcode");
                 return $australian_postcode->lookup_constituency_names($postcode);
             } else {
                 $success = false;
             }
         }
         if ($success && isset($twfy_constituency) && $twfy_constituency != '' && $twfy_constituency != false) {
             return $twfy_constituency;
         } else {
             return false;
         }
     }
 }
Esempio n. 9
0
function get_leaflets($email_alert)
{
    if (ALERT_DEBUG > 0) {
        print $email_alert->type . "\n";
        print "frequency : " . $email_alert->frequency_hours . "\n";
    }
    $results = array();
    $search = factory::create('search');
    $time = time() - 60 * 60 * $email_alert->frequency_hours;
    $time = mysql_date($time);
    //do we have any matching leaflets?
    if ($email_alert->type == 'attack') {
        $results = $search->search('leaflet', array(array('leaflet_party_attack.party_id', '=', $email_alert->parent_id), array('leaflet.date_uploaded', '>=', $time), array('leaflet.live', '=', 1)), 'AND', array(array('leaflet_party_attack', 'inner')));
    } else {
        if ($email_alert->type == 'party') {
            $results = $search->search('leaflet', array(array('leaflet.publisher_party_id', '=', $email_alert->parent_id), array('leaflet.date_uploaded', '>=', $time), array('leaflet.live', '=', 1)));
        } else {
            if ($email_alert->type == 'constituency') {
                $results = $search->search('leaflet', array(array('leaflet_constituency.constituency_id', '=', $email_alert->parent_id), array('leaflet.date_uploaded', '>=', $time), array('leaflet.live', '=', 1)), 'AND', array(array('leaflet_constituency', 'inner')));
            } else {
                if ($email_alert->type == 'category') {
                    $results = $search->search('leaflet', array(array('leaflet_category.category_id', '=', $email_alert->parent_id), array('leaflet.date_uploaded', '>=', $time), array('leaflet.live', '=', 1)), 'AND', array(array('leaflet_category', 'inner')));
                }
            }
        }
    }
    return $results;
}
Esempio n. 10
0
 public function __construct()
 {
     require_once _CORE_ROOT . 'factory.class.php';
     require_once _CORE_ROOT . 'cexception.class.php';
     //require_once(_CORE_ROOT.'error.class.php');
     $this->benchmark = factory::createBenchmarkObject();
     $this->db = factory::createDbObject();
     $this->tpl = factory::createTplObject($this->benchmark);
     $this->input = factory::createInputObject();
     $this->log = factory::createLogger();
     factory::createUtil();
     if (_MEMCACHE_ENABLE) {
         $this->memcache = factory::createMemcacheObject();
     }
     if (_DEBUG === 'Y') {
         ini_set('display_errors', 1);
         error_reporting(E_ALL);
         $this->debug = factory::createDebugObject($this->benchmark);
     } else {
         if (_DEBUG === 'N') {
             ini_set('display_errors', 0);
             error_reporting(E_ALL ^ E_NOTICE);
             $this->debug = factory::createNoDebugObject();
         } else {
             //nothing todo ;
         }
     }
 }
Esempio n. 11
0
 function bind()
 {
     //get the leaflet
     $search = factory::create("search");
     $result = $search->search("leaflet", array(array("leaflet_id", "=", $this->leaflet_id), array('live', '=', 1)), 'AND', array(array("party", "inner")));
     $leaflet = null;
     if (count($result) != 1) {
         throw_404();
     } else {
         $leaflet = $result[0];
     }
     //get images
     $leaflet_images = $search->search("leaflet_image", array(array("leaflet_id", "=", $this->leaflet_id)), 'AND', null, array(array("sequence", "ASC")));
     //get categories
     $leaflet_categories = $search->search("category", array(array("leaflet_category.leaflet_id", "=", $this->leaflet_id)), 'AND', array(array("leaflet_category", 'inner')));
     //get tags
     $leaflet_tags = $search->search("tag", array(array("leaflet_tag.leaflet_id", "=", $this->leaflet_id)), 'AND', array(array("leaflet_tag", 'inner')));
     //get parties attacked
     $leaflet_parties_attacked = $search->search("party", array(array("leaflet_party_attack.leaflet_id", "=", $this->leaflet_id)), 'AND', array(array("leaflet_party_attack", 'inner')));
     //get constituencies
     $leaflet_constituencies = $search->search("constituency", array(array("leaflet_constituency.leaflet_id", "=", $this->leaflet_id)), 'AND', array(array("leaflet_constituency", 'inner')));
     //js
     $this->onloadscript = "showMap('" . MAP_PROVIDER . "', " . number_format($leaflet->lng, 2) . ", " . number_format($leaflet->lat, 2) . ");";
     //assign
     $this->page_title = $leaflet->title . " (an election leaflet published by " . $leaflet->party_name . ")";
     $this->has_map = true;
     $this->assign("leaflet", $leaflet);
     $this->assign("leaflet_images", $leaflet_images);
     $this->assign("leaflet_categories", $leaflet_categories);
     $this->assign("leaflet_tags", $leaflet_tags);
     $this->assign("constituency", $leaflet_constituencies[0]);
     $this->assign("leaflet_parties_attacked", $leaflet_parties_attacked);
 }
 private function set_application()
 {
     $application = session_read('application');
     if (!isset($application)) {
         $application = factory::create('application');
     }
     $this->application = $application;
 }
Esempio n. 13
0
 /**
  * Call validator method
  *
  * @param string $method
  * @param array $params
  * @param array $options
  * @param array $neighbouring_values
  * @return array
  */
 public static function method($method, $value, $params = [], $options = [], $neighbouring_values = [])
 {
     $method = factory::method($method);
     $params = $params ?? [];
     $params['options'] = $options;
     $params['neighbouring_values'] = $neighbouring_values;
     return factory::model($method[0], true)->{$method[1]}($value, $params);
 }
Esempio n. 14
0
 function bind()
 {
     $this->page_title = "Election leaflets by category";
     $search = factory::create('search');
     //get top parties
     $categories = $search->search_cached("category", array(array("1", "=", "1")), "AND", null, array(array("name", "ASC")));
     $this->assign("categories", $categories);
 }
Esempio n. 15
0
 /**
  * Add library to the application
  * 
  * @param string $library
  */
 public static function add($library)
 {
     $connected = application::get('flag.global.library.' . $library . '.connected');
     if (!$connected) {
         factory::submodule('flag.global.library.' . $library . '.submodule')->add();
         application::set('flag.global.library.' . $library . '.connected', true);
     }
 }
Esempio n. 16
0
 function bind()
 {
     $this->page_title = "Election leaflets by category";
     $search = factory::create('search');
     $election_id = get_election_id();
     // Get categories
     $categories = $search->search_cached("category", array(array("category_election.election_id", "=", $election_id)), 'AND', array(array("category_election", "inner")), array(array('name', "ASC")));
     $this->assign("categories", $categories);
 }
Esempio n. 17
0
	/**
	 * Get the response object according to the requested out
	 *
	 * @return response_abstract
	 */
	public static function getInstance() {
		if (self::$proxy)
			return self::$proxy;
		if (!self::$inst) {
			self::$inst = factory::get('response_'.request::getResponseName());
			self::$inst->setContentType(request::get('out'));
		}
		return self::$inst;
	}
Esempio n. 18
0
 function bind()
 {
     $this->page_title = "Election leaflets by tag";
     $search = factory::create('search');
     $tag = factory::create("tag");
     $tag_count = 250;
     $weighted_tags = $tag->get_weighted_tags($tag_count);
     $this->assign("weighted_tags", $weighted_tags);
 }
Esempio n. 19
0
 function bind()
 {
     $this->page_title = "Election leaflets by party";
     $search = factory::create('search');
     //get top parties
     $election_id = get_election_id();
     $parties = $search->search_cached("party", array(array("party_election.election_id", "=", $election_id)), "AND", array(array("party_election", "inner")), array(array("name", "ASC")));
     $this->assign("parties", $parties);
 }
Esempio n. 20
0
 /**
  * Mysql构造函数
  *
  * @param string $host
  * @param string $user
  * @param string $password
  * @param string $db_name
  * @param string $charset
  */
 public function __construct($host, $port, $user, $password, $db_name, $charset)
 {
     $this->host = $host;
     $this->port = $port;
     $this->user = $user;
     $this->db_name = $db_name;
     $this->charset = $charset;
     $this->password = $password;
     $this->dbdebug = factory::createDBDebugObject();
 }
 public static function lookup_constituency_names($postcode)
 {
     $search = factory::create('search');
     $constituencies = $search->search("australian_postcode", array(array('postcode', '=', $postcode)), 'AND', null, array(array('constituency', "ASC")));
     $result = array();
     foreach ($constituencies as $c) {
         $result[] = $c->constituency;
     }
     return $result;
 }
function get_constituency_type()
{
    $return = false;
    $search = factory::create('search');
    $results = $search->search('constituency_type', array(array("name", "=", 'UK Parliament Constituency')));
    if (count($results) == 1) {
        $return = $results[0];
    }
    return $return;
}
 function process()
 {
     // Start transaction
     $db = new DB_DataObject();
     $db->query('BEGIN');
     // Get existing constituencies
     $search = factory::create('search');
     $results = $search->search("constituency", array(array("election_id", "=", $this->election_id)), 'AND', array(array("constituency_election", "inner")), array(array('name', "ASC")));
     // Delete existing constituencies
     foreach ($results as $result) {
         if (!$result->delete()) {
             $db->query('ROLLBACK');
             die("Unable to delete constituency. Transaction rolled back.");
         }
     }
     // Delete many-to-many joins
     $query_string = 'DELETE FROM `constituency_election`
                      WHERE `election_id`=' . $this->election_id;
     if ($db->query($query_string) === false) {
         $db->query('ROLLBACK');
         die("Unable to delete constituency links. Transaction rolled back.");
     }
     // Add user supplied constituencies
     $supplied_constituencies = explode("\n", $this->data['txtConstituencies']);
     foreach ($supplied_constituencies as $constituency_name) {
         $constituency_name = trim($constituency_name);
         if ($constituency_name == '') {
             continue;
         }
         // Check for an existing constituency (from another election)
         $existing_constituency = $search->search("constituency", array(array("name", "=", $constituency_name)));
         if (count($existing_constituency) == 1) {
             $constituency = $existing_constituency[0];
         } else {
             // Create constituency
             $constituency = factory::create('constituency');
             $constituency->name = $constituency_name;
             if (!$constituency->insert()) {
                 $db->query('ROLLBACK');
                 die("Unable to add constituency. Transaction rolled back.");
             }
         }
         // Create join
         $constituency_election = factory::create('constituency_election');
         $constituency_election->constituency_id = $constituency->constituency_id;
         $constituency_election->election_id = $this->election_id;
         if (!$constituency_election->insert()) {
             $db->query('ROLLBACK');
             die("Unable to add constituency. Transaction rolled back.");
         }
     }
     $db->query('COMMIT');
     $this->bind();
     $this->render();
 }
Esempio n. 24
0
 function bind()
 {
     $this->page_title = "Election leaflets stats by party";
     $this->assign("date_since", $this->date_since);
     $search = factory::create('search');
     $parties = $search->search("party", array(array("major", "=", 1)));
     $party_rates = array();
     foreach ($parties as $party) {
         $this->assign($party->url_id . "_party_rates", $party->get_rate_values($this->date_since));
     }
 }
Esempio n. 25
0
 protected function afterInit()
 {
     parent::afterInit();
     $this->form = factory::get('form_db', array_merge($this->cfg->formOpts, array('table' => $this->cfg->table)));
     $this->replaceName = str_replace('[]', '', $this->name) . '_fields[' . $this->cfg->replaceKey . '][[name]]';
     foreach ($this->cfg->fields as $f) {
         $f['name'] = str_replace('[name]', $f['name'], $this->replaceName);
         $this->form->addFromField($f);
     }
     $this->prepareValuesForValid();
     $this->valid->getCfg()->setRef('value', $this->valuesForValid);
 }
Esempio n. 26
0
 /**
  * Constructor
  *
  * @param \phpbb\cache\driver\driver_interface $cache
  * @param string $cache_dir Path to the cache dir
  * @param string $key Cache key
  * @param factory $factory
  * @param \phpbb\event\dispatcher_interface $dispatcher
  */
 public function __construct(\phpbb\cache\driver\driver_interface $cache, $cache_dir, $key, factory $factory, \phpbb\event\dispatcher_interface $dispatcher)
 {
     $renderer_data = $cache->get($key);
     if ($renderer_data) {
         $class = $renderer_data['class'];
         if (!class_exists($class, false)) {
             // Try to load the renderer class from its cache file
             $cache_file = $cache_dir . $class . '.php';
             if (file_exists($cache_file)) {
                 include $cache_file;
             }
         }
         if (class_exists($class, false)) {
             $renderer = new $class();
         }
         if (isset($renderer_data['censor'])) {
             $censor = $renderer_data['censor'];
         }
     }
     if (!isset($renderer)) {
         $objects = $factory->regenerate();
         $renderer = $objects['renderer'];
     }
     if (isset($censor)) {
         $this->censor = $censor;
     }
     $this->dispatcher = $dispatcher;
     $this->renderer = $renderer;
     $renderer = $this;
     /**
      * Configure the renderer service
      *
      * @event core.text_formatter_s9e_renderer_setup
      * @var \phpbb\textformatter\s9e\renderer renderer This renderer service
      * @since 3.2.0-a1
      */
     $vars = array('renderer');
     extract($dispatcher->trigger_event('core.text_formatter_s9e_renderer_setup', compact($vars)));
 }
Esempio n. 27
0
 function process()
 {
     // TODO: Duplicate detection
     if ($this->data['txtCategoryName']) {
         $category = factory::create('category');
         $category->name = $this->data['txtCategoryName'];
         if (!$category->insert()) {
             trigger_error("Unable to save category");
         }
     }
     $this->bind();
     $this->render();
 }
Esempio n. 28
0
 private function get_leaflet_count()
 {
     $return = 0;
     $cache = cache::factory();
     $cached = $cache->get("total_leaflet_count");
     if ($cached !== false && isset($cached)) {
         $return = $cached;
     } else {
         $leaflet = factory::create('leaflet');
         $return = $leaflet->count();
         $cache->set("total_leaflet_count", $return);
     }
     return $return;
 }
Esempio n. 29
0
 /**
  * Set up the valid object
  */
 protected function afterInit()
 {
     if (!$this->label && !is_bool($this->label)) {
         $this->label = ucfirst($this->name);
     }
     if (!is_object($this->cfg->value)) {
         $this->cfg->value = utils::htmlOut($this->cfg->value);
     }
     $this->id = $this->makeId($this->name);
     $val =& $this->cfg->getRef('value');
     $this->valid = factory::get($this->cfg->validType, array('value' => &$val, 'label' => $this->label, 'validEltArray' => $this->cfg->getInArray('valid', 'validEltArray')));
     $this->cfg->delInArray('valid', 'validEltArray');
     $this->initValid();
 }
Esempio n. 30
0
 public function query($options = [])
 {
     $model = factory::model($options['model']);
     $db = $model->db_object();
     $where = null;
     if (!empty($options['where'])) {
         $where = 'AND ' . $db->prepare_condition($options['where']);
     }
     $columns = [];
     foreach ($model->columns as $k => $v) {
         $columns[] = 'a.' . $k . ' ' . str_replace($model->column_prefix, '', $k);
     }
     return "SELECT " . implode(', ', $columns) . ", b.em_entity_name FROM [table[{$options['model']}]] a LEFT JOIN [table[numbers_data_entities_entities_model_entities]] b ON a.{$model->column_prefix}who_entity_id = b.em_entity_id WHERE 1=1 {$where} ORDER BY {$model->column_prefix}inserted DESC";
 }